6 "github.com/bytom/protocol/bc"
8 "github.com/davecgh/go-spew/spew"
11 func TestTxHashes(t *testing.T) {
18 hash: mustDecodeHash("221ed254e69ffaefc0c52baff161392001f8c3ce5c120e4d2cba26eef0bf9500"),
22 hash: mustDecodeHash("0fd4368e2348690af748eb1b4d5a661dd7ee2cf3b6555ce788aea391d9c10718"), // todo: verify this value,
26 for i, c := range cases {
27 txEntries := MapTx(c.txdata)
28 if len(txEntries.InputIDs) != len(c.txdata.Inputs) {
29 t.Errorf("case %d: len(txEntries.InputIDs) = %d, want %d", i, len(txEntries.InputIDs), len(c.txdata.Inputs))
31 if c.hash != txEntries.ID {
32 t.Errorf("case %d: got txid %x, want %x. txEntries is:\n%s", i, txEntries.ID.Bytes(), c.hash.Bytes(), spew.Sdump(txEntries))
37 func BenchmarkHashEmptyTx(b *testing.B) {
39 for i := 0; i < b.N; i++ {
44 func BenchmarkHashNonemptyTx(b *testing.B) {
46 for i := 0; i < b.N; i++ {
51 func sampleTx() *TxData {
52 initialBlockHash := mustDecodeHash("03deff1d4319d67baa10a6d26c1fea9c3e8d30e33474efee1a610a9bb49d758d")
53 assetID := bc.ComputeAssetID([]byte{1}, &initialBlockHash, 1, &bc.EmptyStringHash)
58 NewSpendInput(nil, mustDecodeHash("dd385f6fe25d91d8c1bd0fa58951ad56b0c5229dcc01f61d9f9e8b9eb92d3292"), assetID, 1000000000000, 1, []byte{1}, bc.Hash{}, []byte("input")),
59 NewSpendInput(nil, bc.NewHash([32]byte{0x11}), assetID, 1, 1, []byte{2}, bc.Hash{}, []byte("input2")),
62 NewTxOutput(assetID, 600000000000, []byte{1}, nil),
63 NewTxOutput(assetID, 400000000000, []byte{2}, nil),
65 ReferenceData: []byte("distribution"),