MCPcopy Create free account
hub / github.com/chain/Core / sample

Function sample

protocol/validation/validation_test.go:452–536  ·  view source on GitHub ↗

Produces a sample transaction in a txFixture object (see above). A separate input txFixture can be used to alter the transaction that's created. The output of this function can be used as the input to a subsequent call to make iterative refinements to a test object. The default transaction produce

(tb testing.TB, in *txFixture)

Source from the content-addressed store, hash-verified

450//
451// The min and max times for the transaction are now +/- one minute.
452func sample(tb testing.TB, in *txFixture) *txFixture {
453 var result txFixture
454 if in != nil {
455 result = *in
456 }
457
458 if result.initialBlockID.IsZero() {
459 result.initialBlockID = *newHash(1)
460 }
461 if testutil.DeepEqual(result.issuanceProg, bc.Program{}) {
462 prog, err := vm.Assemble("ADD 5 NUMEQUAL")
463 if err != nil {
464 tb.Fatal(err)
465 }
466 result.issuanceProg = bc.Program{VmVersion: 1, Code: prog}
467 }
468 if len(result.issuanceArgs) == 0 {
469 result.issuanceArgs = [][]byte{[]byte{2}, []byte{3}}
470 }
471 if len(result.assetDef) == 0 {
472 result.assetDef = []byte{2}
473 }
474 if result.assetID.IsZero() {
475 refdatahash := hashData(result.assetDef)
476 result.assetID = bc.ComputeAssetID(result.issuanceProg.Code, &result.initialBlockID, result.issuanceProg.VmVersion, &refdatahash)
477 }
478
479 if result.txVersion == 0 {
480 result.txVersion = 1
481 }
482 if len(result.txInputs) == 0 {
483 cp1, err := vm.Assemble("ADD 9 NUMEQUAL")
484 if err != nil {
485 tb.Fatal(err)
486 }
487 args1 := [][]byte{[]byte{4}, []byte{5}}
488
489 cp2, err := vm.Assemble("ADD 13 NUMEQUAL")
490 if err != nil {
491 tb.Fatal(err)
492 }
493 args2 := [][]byte{[]byte{6}, []byte{7}}
494
495 result.txInputs = []*legacy.TxInput{
496 legacy.NewIssuanceInput([]byte{3}, 10, []byte{4}, result.initialBlockID, result.issuanceProg.Code, result.issuanceArgs, result.assetDef),
497 legacy.NewSpendInput(args1, *newHash(5), result.assetID, 20, 0, cp1, *newHash(6), []byte{7}),
498 legacy.NewSpendInput(args2, *newHash(8), result.assetID, 40, 0, cp2, *newHash(9), []byte{10}),
499 }
500 }
501 if len(result.txOutputs) == 0 {
502 cp1, err := vm.Assemble("ADD 17 NUMEQUAL")
503 if err != nil {
504 tb.Fatal(err)
505 }
506 cp2, err := vm.Assemble("ADD 21 NUMEQUAL")
507 if err != nil {
508 tb.Fatal(err)
509 }

Callers 2

TestTxValidationFunction · 0.85
stringifyMethod · 0.85

Calls 5

newHashFunction · 0.85
ComputeAssetIDMethod · 0.80
hashDataFunction · 0.70
IsZeroMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected