decred.org/dcrdex@v1.0.5/dex/networks/ltc/tx_test.go (about) 1 // This code is available on the terms of the project LICENSE.md file, 2 // also available online at https://blueoakcouncil.org 3 4 package ltc 5 6 import ( 7 "bytes" 8 _ "embed" 9 "testing" 10 ) 11 12 var ( 13 // peg-in txn 8b8343978dbef95d54da796977e9a254565c0dc9ce54917d9111267547fcde03 14 // MEMPOOL, not in block, 2203 bytes, version 2 15 // with: 16 // - flag 0x9 17 // - 1 regular input / 1 regular output 18 // - 0 mw inputs / 2 mw outputs 19 // - 1 kernel with peg-in amt and fee amt and stealth pubkey 20 //go:embed test-data/tx8b8343978dbef95d54da796977e9a254565c0dc9ce54917d9111267547fcde03_mp.dat 21 tx8b83439mp []byte 22 23 // peg-in txn 8b8343978dbef95d54da796977e9a254565c0dc9ce54917d9111267547fcde03 24 // This is the same tx as above, but now in the block stripped of mw tx 25 // data and with the flag with the mw bit unset. 26 // IN BLOCK, 203 bytes, version 2 27 // with: 28 // - flag 0x1 (mw removed) 29 // - 1 regular input / 1 regular output 30 //go:embed test-data/tx8b8343978dbef95d54da796977e9a254565c0dc9ce54917d9111267547fcde03.dat 31 tx8b83439 []byte 32 33 // Pure MW-only txn (no canonical inputs or outputs). 34 // MEMPOOL, not in block, 2203 bytes, version 2 35 // with: 36 // - flag 0x8 37 // - 0 regular inputs / 0 regular outputs 38 // - 1 mw input / 2 mw outputs 39 // - 1 kernel with fee amt and stealth pubkey 40 //go:embed test-data/txe6f8fdb15b27e603adcfa5aa4107a0e7a7b07e6dc76d2ba95a33710db02a0049_mp.dat 41 txe6f8fdbmp []byte 42 43 // Pure MW-only txn (no canonical inputs or outputs). 44 // MEMPOOL, not in block, 2987 bytes, version 2 45 // with: 46 // - flag 0x8 47 // - 0 regular inputs / 0 regular outputs 48 // - 5 mw inputs / 2 mw outputs 49 // - 1 kernel with fee amt and stealth pubkey 50 //go:embed test-data/tx62e17562a697e3167e2b68bce5a927ac355249ef5751800c4dd927ddf57d9db2_mp.dat 51 tx62e1756mp []byte 52 53 // Pure MW-only txn (no canonical inputs or outputs). 54 // MEMPOOL, not in block, 1333 bytes, version 2 55 // with: 56 // - flag 0x8 57 // - 0 regular inputs / 0 regular outputs 58 // - 1 mw inputs / 1 mw outputs 59 // - 1 kernel with fee amt and pegouts and stealth pubkey 60 //go:embed test-data/txcc202c44db4d6faec57f42566c6b1e03139f924eaf685ae964b3076594d65349_mp.dat 61 txcc202c4mp []byte 62 63 // HogEx with multiple inputs and outputs, IN BLOCK 2269979. 64 // Flag 0x8 (omit witness data), null mw tx (but not omitted), 169 bytes. 65 //go:embed test-data/txde22f4de7116b8482a691cc5e552c4212f0ae77e3c8d92c9cb85c29f4dc1f47c.dat 66 txde22f4d []byte 67 ) 68 69 func TestDeserializeTx(t *testing.T) { 70 tests := []struct { 71 name string 72 tx []byte 73 wantHash string 74 wantLockTime uint32 // last field after any mw tx data is the ideal check 75 }{ 76 { 77 "mempool peg-in tx 8b8343978dbef95d54da796977e9a254565c0dc9ce54917d9111267547fcde03", 78 tx8b83439mp, 79 "8b8343978dbef95d54da796977e9a254565c0dc9ce54917d9111267547fcde03", 80 2269978, 81 }, 82 { 83 "block peg-in tx 8b8343978dbef95d54da796977e9a254565c0dc9ce54917d9111267547fcde03", 84 tx8b83439, 85 "8b8343978dbef95d54da796977e9a254565c0dc9ce54917d9111267547fcde03", 86 2269978, 87 }, 88 { 89 "mempool MW tx e6f8fdb15b27e603adcfa5aa4107a0e7a7b07e6dc76d2ba95a33710db02a0049", 90 txe6f8fdbmp, 91 "e6f8fdb15b27e603adcfa5aa4107a0e7a7b07e6dc76d2ba95a33710db02a0049", 92 2269917, 93 }, 94 { 95 "mempool MW tx 62e17562a697e3167e2b68bce5a927ac355249ef5751800c4dd927ddf57d9db2", 96 tx62e1756mp, 97 "62e17562a697e3167e2b68bce5a927ac355249ef5751800c4dd927ddf57d9db2", 98 2269919, 99 }, 100 { 101 "mempool MW tx cc202c44db4d6faec57f42566c6b1e03139f924eaf685ae964b3076594d65349", 102 txcc202c4mp, 103 "cc202c44db4d6faec57f42566c6b1e03139f924eaf685ae964b3076594d65349", 104 2269977, 105 }, 106 { 107 "HogEx tx de22f4de7116b8482a691cc5e552c4212f0ae77e3c8d92c9cb85c29f4dc1f47c", 108 txde22f4d, 109 "de22f4de7116b8482a691cc5e552c4212f0ae77e3c8d92c9cb85c29f4dc1f47c", 110 0, 111 }, 112 } 113 114 for _, tt := range tests { 115 t.Run(tt.name, func(t *testing.T) { 116 msgTx, err := DeserializeTx(bytes.NewReader(tt.tx)) 117 if err != nil { 118 t.Fatal(err) 119 } 120 if msgTx.LockTime != tt.wantLockTime { 121 t.Errorf("want locktime %d, got %d", tt.wantLockTime, msgTx.LockTime) 122 } 123 124 txHash := msgTx.TxHash() 125 if txHash.String() != tt.wantHash { 126 t.Errorf("Wanted tx hash %v, got %v", tt.wantHash, txHash) 127 } 128 }) 129 } 130 }