OSDN Git Service

Add BlockWitness (#54)
[bytom/vapor.git] / protocol / bc / types / block_header_test.go
index 6bbd5b4..4a9237a 100644 (file)
@@ -24,6 +24,7 @@ func TestBlockHeader(t *testing.T) {
                        TransactionStatusHash:  testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
                        TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
                },
+               BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}},
        }
 
        wantHex := strings.Join([]string{
@@ -35,6 +36,7 @@ func TestBlockHeader(t *testing.T) {
                "40",         // commitment extensible field length
                "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
                "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
+               "040102beef", //BlockWitness
        }, "")
 
        gotHex := testutil.Serialize(t, blockHeader)
@@ -73,6 +75,7 @@ func TestMarshalBlockHeader(t *testing.T) {
                                        TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
                                        TransactionStatusHash:  testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
                                },
+                               BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}},
                        },
                        wantHex: strings.Join([]string{
                                "01",   // serialization flags
@@ -83,6 +86,7 @@ func TestMarshalBlockHeader(t *testing.T) {
                                "40",         // commitment extensible field length
                                "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
                                "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
+                               "040102beef", //BlockWitness
                        }, ""),
                },
                {
@@ -95,6 +99,7 @@ func TestMarshalBlockHeader(t *testing.T) {
                                        TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
                                        TransactionStatusHash:  testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
                                },
+                               BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}},
                        },
                        wantError: blockchain.ErrRange,
                },
@@ -108,6 +113,7 @@ func TestMarshalBlockHeader(t *testing.T) {
                                        TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
                                        TransactionStatusHash:  testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
                                },
+                               BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}},
                        },
                        wantError: blockchain.ErrRange,
                },
@@ -117,6 +123,7 @@ func TestMarshalBlockHeader(t *testing.T) {
                                Height:            9223372036854775807, // MaxInt64(9223372036854775807)
                                PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
                                Timestamp:         1528945000,
+                               BlockWitness:      BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}},
                        },
                        wantHex: strings.Join([]string{
                                "01",                 // serialization flags
@@ -127,6 +134,87 @@ func TestMarshalBlockHeader(t *testing.T) {
                                "40",         // commitment extensible field length
                                "0000000000000000000000000000000000000000000000000000000000000000", // transactions merkle root
                                "0000000000000000000000000000000000000000000000000000000000000000", // tx status hash
+                               "040102beef", //BlockWitness
+                       }, ""),
+               },
+               {
+                       blockHeader: &BlockHeader{
+                               Version:           1,
+                               Height:            9223372036854775807, // MaxInt64(9223372036854775807)
+                               PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
+                               Timestamp:         1528945000,
+                               BlockWitness:      BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}, []byte{0xab, 0xcd}, []byte{0xcd, 0x68}}},
+                       },
+                       wantHex: strings.Join([]string{
+                               "01",                 // serialization flags
+                               "01",                 // version
+                               "ffffffffffffffff7f", // block height
+                               "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
+                               "e8b287d905", // timestamp
+                               "40",         // commitment extensible field length
+                               "0000000000000000000000000000000000000000000000000000000000000000", // transactions merkle root
+                               "0000000000000000000000000000000000000000000000000000000000000000", // tx status hash
+                               "0a0302beef02abcd02cd68", //BlockWitness
+                       }, ""),
+               },
+               {
+                       blockHeader: &BlockHeader{
+                               Version:           1,
+                               Height:            9223372036854775807, // MaxInt64(9223372036854775807)
+                               PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
+                               Timestamp:         1528945000,
+                               BlockWitness:      BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}, nil, []byte{0xcd, 0x68}}},
+                       },
+                       wantHex: strings.Join([]string{
+                               "01",                 // serialization flags
+                               "01",                 // version
+                               "ffffffffffffffff7f", // block height
+                               "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
+                               "e8b287d905", // timestamp
+                               "40",         // commitment extensible field length
+                               "0000000000000000000000000000000000000000000000000000000000000000", // transactions merkle root
+                               "0000000000000000000000000000000000000000000000000000000000000000", // tx status hash
+                               "080302beef0002cd68", //BlockWitness
+                       }, ""),
+               },
+               {
+                       blockHeader: &BlockHeader{
+                               Version:           1,
+                               Height:            9223372036854775807, // MaxInt64(9223372036854775807)
+                               PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
+                               Timestamp:         1528945000,
+                               BlockWitness:      BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}, []byte{}, []byte{0xcd, 0x68}}},
+                       },
+                       wantHex: strings.Join([]string{
+                               "01",                 // serialization flags
+                               "01",                 // version
+                               "ffffffffffffffff7f", // block height
+                               "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
+                               "e8b287d905", // timestamp
+                               "40",         // commitment extensible field length
+                               "0000000000000000000000000000000000000000000000000000000000000000", // transactions merkle root
+                               "0000000000000000000000000000000000000000000000000000000000000000", // tx status hash
+                               "080302beef0002cd68", //BlockWitness
+                       }, ""),
+               },
+               {
+                       blockHeader: &BlockHeader{
+                               Version:           1,
+                               Height:            9223372036854775807, // MaxInt64(9223372036854775807)
+                               PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"),
+                               Timestamp:         1528945000,
+                               BlockWitness:      BlockWitness{Witness: [][]byte{}},
+                       },
+                       wantHex: strings.Join([]string{
+                               "01",                 // serialization flags
+                               "01",                 // version
+                               "ffffffffffffffff7f", // block height
+                               "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash
+                               "e8b287d905", // timestamp
+                               "40",         // commitment extensible field length
+                               "0000000000000000000000000000000000000000000000000000000000000000", // transactions merkle root
+                               "0000000000000000000000000000000000000000000000000000000000000000", // tx status hash
+                               "0100", //BlockWitness
                        }, ""),
                },
        }
@@ -170,6 +258,7 @@ func TestUnmarshalBlockHeader(t *testing.T) {
                                "40",         // commitment extensible field length
                                "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
                                "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
+                               "040102beef", //BlockWitness
                        }, ""),
                        wantBlockHeader: &BlockHeader{
                                Version:           1,
@@ -180,6 +269,7 @@ func TestUnmarshalBlockHeader(t *testing.T) {
                                        TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
                                        TransactionStatusHash:  testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
                                },
+                               BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}},
                        },
                },
                {
@@ -192,6 +282,7 @@ func TestUnmarshalBlockHeader(t *testing.T) {
                                "40",         // commitment extensible field length
                                "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
                                "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
+                               "040102beef", //BlockWitness
                        }, ""),
                        wantBlockHeader: &BlockHeader{
                                Version:           1,
@@ -202,6 +293,7 @@ func TestUnmarshalBlockHeader(t *testing.T) {
                                        TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
                                        TransactionStatusHash:  testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
                                },
+                               BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}},
                        },
                },
                {
@@ -240,6 +332,7 @@ func TestUnmarshalBlockHeader(t *testing.T) {
                                "40",         // commitment extensible field length
                                "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
                                "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
+                               "040102beef", //BlockWitness
                        }, ""),
                        wantError: errors.New("binary: varint overflows a 64-bit integer"),
                },
@@ -266,6 +359,7 @@ func TestUnmarshalBlockHeader(t *testing.T) {
                                "40",         // commitment extensible field length
                                "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root
                                "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash
+                               "040102beef", //BlockWitness
                        }, ""),
                        wantBlockHeader: &BlockHeader{
                                Version:           1,
@@ -276,6 +370,7 @@ func TestUnmarshalBlockHeader(t *testing.T) {
                                        TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"),
                                        TransactionStatusHash:  testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"),
                                },
+                               BlockWitness: BlockWitness{Witness: [][]byte{[]byte{0xbe, 0xef}}},
                        },
                },
        }