9 "github.com/davecgh/go-spew/spew"
11 "github.com/vapor/encoding/blockchain"
12 "github.com/vapor/testutil"
15 func TestBlockHeader(t *testing.T) {
16 blockHeader := &BlockHeader{
19 PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
20 Timestamp: 1522908275,
22 Bits: 2305843009222082559,
23 BlockCommitment: BlockCommitment{
24 TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
25 TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
29 wantHex := strings.Join([]string{
30 "01", // serialization flags
32 "eab01a", // block height
33 "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
34 "f3f896d605", // timestamp
35 "40", // commitment extensible field length
36 "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
37 "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
39 "ffffff838080808020", // bits
42 gotHex := testutil.Serialize(t, blockHeader)
43 want, err := hex.DecodeString(wantHex)
48 if !bytes.Equal(gotHex, want) {
49 t.Errorf("empty block header bytes = %x want %x", gotHex, want)
52 gotBlockHeader := BlockHeader{}
53 if _, err := gotBlockHeader.readFrom(blockchain.NewReader(want)); err != nil {
57 if !testutil.DeepEqual(gotBlockHeader, *blockHeader) {
58 t.Errorf("got:\n%s\nwant:\n%s", spew.Sdump(gotBlockHeader), spew.Sdump(*blockHeader))