Skip to content

Commit

Permalink
btcacc/leaf_test: Add test for serializing and de-serializing leafdata
Browse files Browse the repository at this point in the history
  • Loading branch information
kcalvinalvin committed Feb 18, 2021
1 parent 6bdb889 commit a7ed94d
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions btcacc/leaf_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package btcacc

import (
"bytes"
"fmt"
"testing"
)

func TestLeafDataSerialize(t *testing.T) {
ld := LeafData{
TxHash: Hash{1, 2, 3, 4},
Index: 0,
Height: 2,
Coinbase: false,
Amt: 3000,
PkScript: []byte{1, 2, 3, 4, 5, 6},
}

// Before
writer := &bytes.Buffer{}
ld.Serialize(writer)
beforeBytes := writer.Bytes()

// After
checkLeaf := LeafData{}
checkLeaf.Deserialize(writer)

afterWriter := &bytes.Buffer{}
checkLeaf.Serialize(afterWriter)
afterBytes := afterWriter.Bytes()

if !bytes.Equal(beforeBytes, afterBytes) {
err := fmt.Errorf("Serialize/Deserialize LeafData fail\n"+
"beforeBytes len: %v\n, afterBytes len:%v\n",
len(beforeBytes), len(afterBytes))
t.Fatal(err)
}
}

0 comments on commit a7ed94d

Please sign in to comment.