-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
btcacc/leaf_test: Add test for serializing and de-serializing leafdata
- Loading branch information
1 parent
6bdb889
commit a7ed94d
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |