Official Go implementation of the Bytom protocol
Revision | 19af3b90bc66aa91161fbd95d73dd61d49d501ea (tree) |
---|---|
Time | 2021-04-08 16:54:59 |
Author | mingjingc <2595400537@qq.c...> |
Commiter | mingjingc |
fix(remove pow):after merge btm2.0
@@ -10,6 +10,7 @@ import ( | ||
10 | 10 | "github.com/davecgh/go-spew/spew" |
11 | 11 | |
12 | 12 | "github.com/bytom/bytom/encoding/blockchain" |
13 | + "github.com/bytom/bytom/errors" | |
13 | 14 | "github.com/bytom/bytom/testutil" |
14 | 15 | ) |
15 | 16 |
@@ -231,49 +232,21 @@ func TestUnmarshalBlockHeader(t *testing.T) { | ||
231 | 232 | "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash |
232 | 233 | }, ""), |
233 | 234 | wantError: hex.ErrLength, |
234 | - }, //---- | |
235 | - //{ // below test cases should be modified | |
236 | - // hexBlockHeader: strings.Join([]string{ | |
237 | - // "01", // serialization flags | |
238 | - // "01", // version | |
239 | - // "ffffffffffffffff7f", // block height | |
240 | - // "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash | |
241 | - // "e8b287d905", // timestamp | |
242 | - // "40", // commitment extensible field length | |
243 | - // "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root | |
244 | - // "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash | |
245 | - // }, ""), | |
246 | - // wantError: errors.New("binary: varint overflows a 64-bit integer"), | |
247 | - //}, | |
248 | - //{ | |
249 | - // hexBlockHeader: strings.Join([]string{ | |
250 | - // "01", // serialization flags | |
251 | - // "01", // version | |
252 | - // "ffffffffffffffff7f", // block height | |
253 | - // "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash | |
254 | - // "e8b287d905", // timestamp | |
255 | - // "40", // commitment extensible field length | |
256 | - // "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root | |
257 | - // "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash | |
258 | - // //"e19f8080a88d02", // nonce | |
259 | - // //"ffffffffffffffff80", // bits | |
260 | - // }, ""), | |
261 | - // wantError: fmt.Errorf("EOF"), | |
262 | - //}, | |
263 | - //{ | |
264 | - // hexBlockHeader: strings.Join([]string{ | |
265 | - // "01", // serialization flags | |
266 | - // "01", // version | |
267 | - // "ffffffffffffffff7f", // block height | |
268 | - // "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash | |
269 | - // "e8b287d905", // timestamp | |
270 | - // "40", // commitment extensible field length | |
271 | - // "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root | |
272 | - // "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status ha sh | |
273 | - // }, ""), | |
274 | - // wantError: blockchain.ErrRange, | |
275 | - //}, | |
276 | - { // --- | |
235 | + }, | |
236 | + { | |
237 | + hexBlockHeader: strings.Join([]string{ | |
238 | + "01", // serialization flags | |
239 | + "01", // version | |
240 | + "ffffffffffffffffff", // block height | |
241 | + "c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0", // prev block hash | |
242 | + "e8b287d905", // timestamp | |
243 | + "40", // commitment extensible field length | |
244 | + "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root | |
245 | + "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash | |
246 | + }, ""), | |
247 | + wantError: errors.New("binary: varint overflows a 64-bit integer"), | |
248 | + }, | |
249 | + { | |
277 | 250 | hexBlockHeader: strings.Join([]string{ |
278 | 251 | "01", // serialization flags |
279 | 252 | "01", // version |
@@ -283,16 +256,12 @@ func TestUnmarshalBlockHeader(t *testing.T) { | ||
283 | 256 | "40", // commitment extensible field length |
284 | 257 | "ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03", // transactions merkle root |
285 | 258 | "b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470", // tx status hash |
286 | - //"e19f8080a88d02", // nonce | |
287 | - //"cc99b3808080808020", // bits | |
288 | 259 | }, ""), |
289 | 260 | wantBlockHeader: &BlockHeader{ |
290 | 261 | Version: 1, |
291 | 262 | Height: 9223372036854775807, // MaxInt64(9223372036854775807) |
292 | 263 | PreviousBlockHash: testutil.MustDecodeHash("c34048bd60c4c13144fd34f408627d1be68f6cb4fdd34e879d6d791060ea73a0"), |
293 | 264 | Timestamp: 1528945000, |
294 | - //Nonce: 9253507043297, | |
295 | - //Bits: 2305843009214532812, | |
296 | 265 | BlockCommitment: BlockCommitment{ |
297 | 266 | TransactionsMerkleRoot: testutil.MustDecodeHash("ad9ac003d08ff305181a345d64fe0b02311cc1a6ec04ab73f3318d90139bfe03"), |
298 | 267 | TransactionStatusHash: testutil.MustDecodeHash("b94301ea4e316bee00109f68d25beaca90aeff08e9bf439a37d91d7a3b5a1470"), |
@@ -3,9 +3,9 @@ package test | ||
3 | 3 | import ( |
4 | 4 | "fmt" |
5 | 5 | |
6 | + dbm "github.com/bytom/bytom/database/leveldb" | |
6 | 7 | "github.com/bytom/bytom/protocol" |
7 | 8 | "github.com/bytom/bytom/protocol/bc/types" |
8 | - dbm "github.com/bytom/bytom/database/leveldb" | |
9 | 9 | ) |
10 | 10 | |
11 | 11 | func declChain(name string, baseChain *protocol.Chain, baseHeight uint64, height uint64) (*protocol.Chain, error) { |
@@ -23,7 +23,13 @@ func declChain(name string, baseChain *protocol.Chain, baseHeight uint64, height | ||
23 | 23 | } |
24 | 24 | |
25 | 25 | for i := uint64(1); i <= baseHeight; i++ { |
26 | - | |
26 | + block, err := baseChain.GetBlockByHeight(i) | |
27 | + if err != nil { | |
28 | + return nil, err | |
29 | + } | |
30 | + if _, err := chain.ProcessBlock(block); err != nil { | |
31 | + return nil, err | |
32 | + } | |
27 | 33 | } |
28 | 34 | |
29 | 35 | err = AppendBlocks(chain, height-baseHeight) |