From 03df23355e3b3c2e4ce7bca18661d43cf5b5a7a9 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Tue, 16 Apr 2019 12:53:06 +0800 Subject: [PATCH] core: remove useless --- core/blockchain_test.go | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/core/blockchain_test.go b/core/blockchain_test.go index 6157c58c0b..fe2b6ab017 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -1712,8 +1712,10 @@ func testInsertKnownChainData(t *testing.T, typ string) { genesis := new(Genesis).MustCommit(db) blocks, receipts := GenerateChain(params.TestChainConfig, genesis, engine, db, 32, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{1}) }) - blocks2, receipts2 := GenerateChain(params.TestChainConfig, blocks[len(blocks)-1], engine, db, 32, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{1}) }) - blocks3, receipts3 := GenerateChain(params.TestChainConfig, blocks[len(blocks)-1], engine, db, 33, func(i int, b *BlockGen) { + // A longer chain but total difficulty is lower. + blocks2, receipts2 := GenerateChain(params.TestChainConfig, blocks[len(blocks)-1], engine, db, 65, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{1}) }) + // A shorter chain but total difficulty is higher. + blocks3, receipts3 := GenerateChain(params.TestChainConfig, blocks[len(blocks)-1], engine, db, 64, func(i int, b *BlockGen) { b.SetCoinbase(common.Address{1}) b.OffsetTime(-9) // A higher difficulty }) @@ -1804,11 +1806,29 @@ func testInsertKnownChainData(t *testing.T, typ string) { } asserter(t, blocks2[len(blocks2)-1]) - // Import a heavier forked chain with some known data as prefix. + // Import a heavier shorter but higher total difficulty chain with some known data as prefix. if err := inserter(append(blocks, blocks3...), append(receipts, receipts3...)); err != nil { t.Fatalf("failed to insert chain data: %v", err) } asserter(t, blocks3[len(blocks3)-1]) + + // Import a longer but lower total difficulty chain with some known data as prefix. + if err := inserter(append(blocks, blocks2...), append(receipts, receipts2...)); err != nil { + t.Fatalf("failed to insert chain data: %v", err) + } + // The head shouldn't change. + asserter(t, blocks3[len(blocks3)-1]) + + // Rollback the heavier chain and re-insert the longer chain again + for i := 0; i < len(blocks3); i++ { + rollback = append(rollback, blocks3[i].Hash()) + } + chain.Rollback(rollback) + + if err := inserter(append(blocks, blocks2...), append(receipts, receipts2...)); err != nil { + t.Fatalf("failed to insert chain data: %v", err) + } + asserter(t, blocks2[len(blocks2)-1]) } // Benchmarks large blocks with value transfers to non-existing accounts @@ -1840,7 +1860,6 @@ func benchmarkLargeNumberOfValueToNonexisting(b *testing.B, numTxs, numBlocks in for txi := 0; txi < numTxs; txi++ { uniq := uint64(i*numTxs + txi) recipient := recipientFn(uniq) - //recipient := common.BigToAddress(big.NewInt(0).SetUint64(1337 + uniq)) tx, err := types.SignTx(types.NewTransaction(uniq, recipient, big.NewInt(1), params.TxGas, big.NewInt(1), nil), signer, testBankKey) if err != nil { b.Error(err)