github.com/decred/dcrlnd@v0.7.6/input/txout_test.go (about) 1 package input 2 3 import ( 4 "bytes" 5 "reflect" 6 "testing" 7 8 "github.com/decred/dcrd/wire" 9 ) 10 11 func TestTxOutSerialization(t *testing.T) { 12 txo := wire.TxOut{ 13 Value: 1e7, 14 PkScript: []byte{ 15 0x41, // OP_DATA_65 16 0x04, 0xd6, 0x4b, 0xdf, 0xd0, 0x9e, 0xb1, 0xc5, 17 0xfe, 0x29, 0x5a, 0xbd, 0xeb, 0x1d, 0xca, 0x42, 18 0x81, 0xbe, 0x98, 0x8e, 0x2d, 0xa0, 0xb6, 0xc1, 19 0xc6, 0xa5, 0x9d, 0xc2, 0x26, 0xc2, 0x86, 0x24, 20 0xe1, 0x81, 0x75, 0xe8, 0x51, 0xc9, 0x6b, 0x97, 21 0x3d, 0x81, 0xb0, 0x1c, 0xc3, 0x1f, 0x04, 0x78, 22 0x34, 0xbc, 0x06, 0xd6, 0xd6, 0xed, 0xf6, 0x20, 23 0xd1, 0x84, 0x24, 0x1a, 0x6a, 0xed, 0x8b, 0x63, 24 0xa6, // 65-byte signature 25 0xac, // OP_CHECKSIG 26 }, 27 } 28 29 var buf bytes.Buffer 30 31 if err := writeTxOut(&buf, &txo); err != nil { 32 t.Fatalf("unable to serialize txout: %v", err) 33 } 34 35 var deserializedTxo wire.TxOut 36 if err := readTxOut(&buf, &deserializedTxo); err != nil { 37 t.Fatalf("unable to deserialize txout: %v", err) 38 } 39 40 if !reflect.DeepEqual(txo, deserializedTxo) { 41 t.Fatalf("original and deserialized txouts are different:\n"+ 42 "original : %+v\n"+ 43 "deserialized : %+v\n", 44 txo, deserializedTxo) 45 } 46 }