MCPcopy Index your code
hub / github.com/chain/Core / TestTransfer

Function TestTransfer

core/api_test.go:201–338  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

199}
200
201func TestTransfer(t *testing.T) {
202 _, db := pgtest.NewDB(t, pgtest.SchemaPath)
203 ctx := context.Background()
204 c := prottest.NewChain(t)
205 g := generator.New(c, nil, db)
206 pinStore := pin.NewStore(db)
207 coretest.CreatePins(ctx, t, pinStore)
208 api := &API{
209 chain: c,
210 submitter: g,
211 assets: asset.NewRegistry(db, c, pinStore),
212 accounts: account.NewManager(db, c, pinStore),
213 indexer: query.NewIndexer(db, c, pinStore),
214 db: db,
215 }
216 api.assets.IndexAssets(api.indexer)
217 api.accounts.IndexAccounts(api.indexer)
218 go api.accounts.ProcessBlocks(ctx)
219 api.indexer.RegisterAnnotator(api.accounts.AnnotateTxs)
220 api.indexer.RegisterAnnotator(api.assets.AnnotateTxs)
221 api.leader = alwaysLeader{}
222
223 assetAlias := "some-asset"
224 account1Alias := "first-account"
225 account2Alias := "second-account"
226
227 assetID := coretest.CreateAsset(ctx, t, api.assets, nil, assetAlias, nil)
228 account1ID := coretest.CreateAccount(ctx, t, api.accounts, account1Alias, nil)
229 account2ID := coretest.CreateAccount(ctx, t, api.accounts, account2Alias, nil)
230
231 assetIDStr := assetID.String()
232
233 // Preface: issue some asset for account1ID to transfer to account2ID
234 issueAssetAmount := bc.AssetAmount{
235 AssetId: &assetID,
236 Amount: 100,
237 }
238 txTemplate, err := txbuilder.Build(ctx, nil, []txbuilder.Action{
239 api.assets.NewIssueAction(issueAssetAmount, nil),
240 api.accounts.NewControlAction(issueAssetAmount, account1ID, nil),
241 }, time.Now().Add(time.Minute))
242 if err != nil {
243 testutil.FatalErr(t, err)
244 }
245
246 coretest.SignTxTemplate(t, ctx, txTemplate, nil)
247
248 err = txbuilder.FinalizeTx(ctx, c, g, txTemplate.Transaction)
249 if err != nil {
250 testutil.FatalErr(t, err)
251 }
252
253 // Make a block so that UTXOs from the above tx are available to spend.
254 prottest.MakeBlock(t, c, g.PendingTxs())
255 <-pinStore.PinWaiter(account.PinName, c.Height())
256
257 // Now transfer
258 buildReqFmt := `

Callers

nothing calls this directly

Calls 15

PinWaiterMethod · 0.95
HeightMethod · 0.95
buildMethod · 0.95
submitSingleMethod · 0.95
inspectTemplateFunction · 0.85
toTxTemplateFunction · 0.85
IndexAssetsMethod · 0.80
IndexAccountsMethod · 0.80
RegisterAnnotatorMethod · 0.80
NewIssueActionMethod · 0.80
NewControlActionMethod · 0.80
PendingTxsMethod · 0.80

Tested by

no test coverage detected