|
|
|
@ -57,7 +57,7 @@ func newTestBlockChain(fake bool) *BlockChain { |
|
|
|
|
// Test fork of length N starting from block i
|
|
|
|
|
func testFork(t *testing.T, blockchain *BlockChain, i, n int, full bool, comparator func(td1, td2 *big.Int)) { |
|
|
|
|
// Copy old chain up to #i into a new db
|
|
|
|
|
db, blockchain2, err := newCanonical(i, full) |
|
|
|
|
db, blockchain2, err := newCanonical(ethash.NewFaker(), i, full) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatal("could not make new canonical in testFork", err) |
|
|
|
|
} |
|
|
|
@ -81,12 +81,12 @@ func testFork(t *testing.T, blockchain *BlockChain, i, n int, full bool, compara |
|
|
|
|
headerChainB []*types.Header |
|
|
|
|
) |
|
|
|
|
if full { |
|
|
|
|
blockChainB = makeBlockChain(blockchain2.CurrentBlock(), n, db, forkSeed) |
|
|
|
|
blockChainB = makeBlockChain(blockchain2.CurrentBlock(), n, ethash.NewFaker(), db, forkSeed) |
|
|
|
|
if _, err := blockchain2.InsertChain(blockChainB); err != nil { |
|
|
|
|
t.Fatalf("failed to insert forking chain: %v", err) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
headerChainB = makeHeaderChain(blockchain2.CurrentHeader(), n, db, forkSeed) |
|
|
|
|
headerChainB = makeHeaderChain(blockchain2.CurrentHeader(), n, ethash.NewFaker(), db, forkSeed) |
|
|
|
|
if _, err := blockchain2.InsertHeaderChain(headerChainB, 1); err != nil { |
|
|
|
|
t.Fatalf("failed to insert forking chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -186,7 +186,7 @@ func TestLastBlock(t *testing.T) { |
|
|
|
|
bchain := newTestBlockChain(false) |
|
|
|
|
defer bchain.Stop() |
|
|
|
|
|
|
|
|
|
block := makeBlockChain(bchain.CurrentBlock(), 1, bchain.chainDb, 0)[0] |
|
|
|
|
block := makeBlockChain(bchain.CurrentBlock(), 1, ethash.NewFaker(), bchain.chainDb, 0)[0] |
|
|
|
|
bchain.insert(block) |
|
|
|
|
if block.Hash() != GetHeadBlockHash(bchain.chainDb) { |
|
|
|
|
t.Errorf("Write/Get HeadBlockHash failed") |
|
|
|
@ -202,7 +202,7 @@ func testExtendCanonical(t *testing.T, full bool) { |
|
|
|
|
length := 5 |
|
|
|
|
|
|
|
|
|
// Make first chain starting from genesis
|
|
|
|
|
_, processor, err := newCanonical(length, full) |
|
|
|
|
_, processor, err := newCanonical(ethash.NewFaker(), length, full) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to make new canonical chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -230,7 +230,7 @@ func testShorterFork(t *testing.T, full bool) { |
|
|
|
|
length := 10 |
|
|
|
|
|
|
|
|
|
// Make first chain starting from genesis
|
|
|
|
|
_, processor, err := newCanonical(length, full) |
|
|
|
|
_, processor, err := newCanonical(ethash.NewFaker(), length, full) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to make new canonical chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -260,7 +260,7 @@ func testLongerFork(t *testing.T, full bool) { |
|
|
|
|
length := 10 |
|
|
|
|
|
|
|
|
|
// Make first chain starting from genesis
|
|
|
|
|
_, processor, err := newCanonical(length, full) |
|
|
|
|
_, processor, err := newCanonical(ethash.NewFaker(), length, full) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to make new canonical chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -290,7 +290,7 @@ func testEqualFork(t *testing.T, full bool) { |
|
|
|
|
length := 10 |
|
|
|
|
|
|
|
|
|
// Make first chain starting from genesis
|
|
|
|
|
_, processor, err := newCanonical(length, full) |
|
|
|
|
_, processor, err := newCanonical(ethash.NewFaker(), length, full) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to make new canonical chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -317,7 +317,7 @@ func TestBrokenBlockChain(t *testing.T) { testBrokenChain(t, true) } |
|
|
|
|
|
|
|
|
|
func testBrokenChain(t *testing.T, full bool) { |
|
|
|
|
// Make chain starting from genesis
|
|
|
|
|
db, blockchain, err := newCanonical(10, full) |
|
|
|
|
db, blockchain, err := newCanonical(ethash.NewFaker(), 10, full) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to make new canonical chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -325,12 +325,12 @@ func testBrokenChain(t *testing.T, full bool) { |
|
|
|
|
|
|
|
|
|
// Create a forked chain, and try to insert with a missing link
|
|
|
|
|
if full { |
|
|
|
|
chain := makeBlockChain(blockchain.CurrentBlock(), 5, db, forkSeed)[1:] |
|
|
|
|
chain := makeBlockChain(blockchain.CurrentBlock(), 5, ethash.NewFaker(), db, forkSeed)[1:] |
|
|
|
|
if err := testBlockChainImport(chain, blockchain); err == nil { |
|
|
|
|
t.Errorf("broken block chain not reported") |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
chain := makeHeaderChain(blockchain.CurrentHeader(), 5, db, forkSeed)[1:] |
|
|
|
|
chain := makeHeaderChain(blockchain.CurrentHeader(), 5, ethash.NewFaker(), db, forkSeed)[1:] |
|
|
|
|
if err := testHeaderChainImport(chain, blockchain); err == nil { |
|
|
|
|
t.Errorf("broken header chain not reported") |
|
|
|
|
} |
|
|
|
@ -523,7 +523,7 @@ func TestBlocksInsertNonceError(t *testing.T) { testInsertNonceError(t, true) } |
|
|
|
|
func testInsertNonceError(t *testing.T, full bool) { |
|
|
|
|
for i := 1; i < 25 && !t.Failed(); i++ { |
|
|
|
|
// Create a pristine chain and database
|
|
|
|
|
db, blockchain, err := newCanonical(0, full) |
|
|
|
|
db, blockchain, err := newCanonical(ethash.NewFaker(), 0, full) |
|
|
|
|
if err != nil { |
|
|
|
|
t.Fatalf("failed to create pristine chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -536,7 +536,7 @@ func testInsertNonceError(t *testing.T, full bool) { |
|
|
|
|
failNum uint64 |
|
|
|
|
) |
|
|
|
|
if full { |
|
|
|
|
blocks := makeBlockChain(blockchain.CurrentBlock(), i, db, 0) |
|
|
|
|
blocks := makeBlockChain(blockchain.CurrentBlock(), i, ethash.NewFaker(), db, 0) |
|
|
|
|
|
|
|
|
|
failAt = rand.Int() % len(blocks) |
|
|
|
|
failNum = blocks[failAt].NumberU64() |
|
|
|
@ -544,7 +544,7 @@ func testInsertNonceError(t *testing.T, full bool) { |
|
|
|
|
blockchain.engine = ethash.NewFakeFailer(failNum) |
|
|
|
|
failRes, err = blockchain.InsertChain(blocks) |
|
|
|
|
} else { |
|
|
|
|
headers := makeHeaderChain(blockchain.CurrentHeader(), i, db, 0) |
|
|
|
|
headers := makeHeaderChain(blockchain.CurrentHeader(), i, ethash.NewFaker(), db, 0) |
|
|
|
|
|
|
|
|
|
failAt = rand.Int() % len(headers) |
|
|
|
|
failNum = headers[failAt].Number.Uint64() |
|
|
|
@ -588,7 +588,7 @@ func TestFastVsFullChains(t *testing.T) { |
|
|
|
|
genesis = gspec.MustCommit(gendb) |
|
|
|
|
signer = types.NewEIP155Signer(gspec.Config.ChainId) |
|
|
|
|
) |
|
|
|
|
blocks, receipts := GenerateChain(gspec.Config, genesis, gendb, 1024, func(i int, block *BlockGen) { |
|
|
|
|
blocks, receipts := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), gendb, 1024, func(i int, block *BlockGen) { |
|
|
|
|
block.SetCoinbase(common.Address{0x00}) |
|
|
|
|
|
|
|
|
|
// If the block number is multiple of 3, send a few bonus transactions to the miner
|
|
|
|
@ -673,7 +673,7 @@ func TestLightVsFastVsFullChainHeads(t *testing.T) { |
|
|
|
|
genesis = gspec.MustCommit(gendb) |
|
|
|
|
) |
|
|
|
|
height := uint64(1024) |
|
|
|
|
blocks, receipts := GenerateChain(gspec.Config, genesis, gendb, int(height), nil) |
|
|
|
|
blocks, receipts := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), gendb, int(height), nil) |
|
|
|
|
|
|
|
|
|
// Configure a subchain to roll back
|
|
|
|
|
remove := []common.Hash{} |
|
|
|
@ -781,7 +781,7 @@ func TestChainTxReorgs(t *testing.T) { |
|
|
|
|
// - futureAdd: transaction added after the reorg has already finished
|
|
|
|
|
var pastAdd, freshAdd, futureAdd *types.Transaction |
|
|
|
|
|
|
|
|
|
chain, _ := GenerateChain(gspec.Config, genesis, db, 3, func(i int, gen *BlockGen) { |
|
|
|
|
chain, _ := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 3, func(i int, gen *BlockGen) { |
|
|
|
|
switch i { |
|
|
|
|
case 0: |
|
|
|
|
pastDrop, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr2), addr2, big.NewInt(1000), bigTxGas, nil, nil), signer, key2) |
|
|
|
@ -806,7 +806,7 @@ func TestChainTxReorgs(t *testing.T) { |
|
|
|
|
defer blockchain.Stop() |
|
|
|
|
|
|
|
|
|
// overwrite the old chain
|
|
|
|
|
chain, _ = GenerateChain(gspec.Config, genesis, db, 5, func(i int, gen *BlockGen) { |
|
|
|
|
chain, _ = GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 5, func(i int, gen *BlockGen) { |
|
|
|
|
switch i { |
|
|
|
|
case 0: |
|
|
|
|
pastAdd, _ = types.SignTx(types.NewTransaction(gen.TxNonce(addr3), addr3, big.NewInt(1000), bigTxGas, nil, nil), signer, key3) |
|
|
|
@ -875,7 +875,7 @@ func TestLogReorgs(t *testing.T) { |
|
|
|
|
|
|
|
|
|
rmLogsCh := make(chan RemovedLogsEvent) |
|
|
|
|
blockchain.SubscribeRemovedLogsEvent(rmLogsCh) |
|
|
|
|
chain, _ := GenerateChain(params.TestChainConfig, genesis, db, 2, func(i int, gen *BlockGen) { |
|
|
|
|
chain, _ := GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 2, func(i int, gen *BlockGen) { |
|
|
|
|
if i == 1 { |
|
|
|
|
tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), big.NewInt(1000000), new(big.Int), code), signer, key1) |
|
|
|
|
if err != nil { |
|
|
|
@ -888,7 +888,7 @@ func TestLogReorgs(t *testing.T) { |
|
|
|
|
t.Fatalf("failed to insert chain: %v", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
chain, _ = GenerateChain(params.TestChainConfig, genesis, db, 3, func(i int, gen *BlockGen) {}) |
|
|
|
|
chain, _ = GenerateChain(params.TestChainConfig, genesis, ethash.NewFaker(), db, 3, func(i int, gen *BlockGen) {}) |
|
|
|
|
if _, err := blockchain.InsertChain(chain); err != nil { |
|
|
|
|
t.Fatalf("failed to insert forked chain: %v", err) |
|
|
|
|
} |
|
|
|
@ -920,12 +920,12 @@ func TestReorgSideEvent(t *testing.T) { |
|
|
|
|
blockchain, _ := NewBlockChain(db, gspec.Config, ethash.NewFaker(), vm.Config{}) |
|
|
|
|
defer blockchain.Stop() |
|
|
|
|
|
|
|
|
|
chain, _ := GenerateChain(gspec.Config, genesis, db, 3, func(i int, gen *BlockGen) {}) |
|
|
|
|
chain, _ := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 3, func(i int, gen *BlockGen) {}) |
|
|
|
|
if _, err := blockchain.InsertChain(chain); err != nil { |
|
|
|
|
t.Fatalf("failed to insert chain: %v", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
replacementBlocks, _ := GenerateChain(gspec.Config, genesis, db, 4, func(i int, gen *BlockGen) { |
|
|
|
|
replacementBlocks, _ := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 4, func(i int, gen *BlockGen) { |
|
|
|
|
tx, err := types.SignTx(types.NewContractCreation(gen.TxNonce(addr1), new(big.Int), big.NewInt(1000000), new(big.Int), nil), signer, key1) |
|
|
|
|
if i == 2 { |
|
|
|
|
gen.OffsetTime(-9) |
|
|
|
@ -992,7 +992,7 @@ func TestCanonicalBlockRetrieval(t *testing.T) { |
|
|
|
|
bc := newTestBlockChain(true) |
|
|
|
|
defer bc.Stop() |
|
|
|
|
|
|
|
|
|
chain, _ := GenerateChain(bc.config, bc.genesisBlock, bc.chainDb, 10, func(i int, gen *BlockGen) {}) |
|
|
|
|
chain, _ := GenerateChain(bc.config, bc.genesisBlock, ethash.NewFaker(), bc.chainDb, 10, func(i int, gen *BlockGen) {}) |
|
|
|
|
|
|
|
|
|
var pend sync.WaitGroup |
|
|
|
|
pend.Add(len(chain)) |
|
|
|
@ -1046,7 +1046,7 @@ func TestEIP155Transition(t *testing.T) { |
|
|
|
|
blockchain, _ := NewBlockChain(db, gspec.Config, ethash.NewFaker(), vm.Config{}) |
|
|
|
|
defer blockchain.Stop() |
|
|
|
|
|
|
|
|
|
blocks, _ := GenerateChain(gspec.Config, genesis, db, 4, func(i int, block *BlockGen) { |
|
|
|
|
blocks, _ := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 4, func(i int, block *BlockGen) { |
|
|
|
|
var ( |
|
|
|
|
tx *types.Transaction |
|
|
|
|
err error |
|
|
|
@ -1109,7 +1109,7 @@ func TestEIP155Transition(t *testing.T) { |
|
|
|
|
|
|
|
|
|
// generate an invalid chain id transaction
|
|
|
|
|
config := ¶ms.ChainConfig{ChainId: big.NewInt(2), EIP155Block: big.NewInt(2), HomesteadBlock: new(big.Int)} |
|
|
|
|
blocks, _ = GenerateChain(config, blocks[len(blocks)-1], db, 4, func(i int, block *BlockGen) { |
|
|
|
|
blocks, _ = GenerateChain(config, blocks[len(blocks)-1], ethash.NewFaker(), db, 4, func(i int, block *BlockGen) { |
|
|
|
|
var ( |
|
|
|
|
tx *types.Transaction |
|
|
|
|
err error |
|
|
|
@ -1154,7 +1154,7 @@ func TestEIP161AccountRemoval(t *testing.T) { |
|
|
|
|
blockchain, _ := NewBlockChain(db, gspec.Config, ethash.NewFaker(), vm.Config{}) |
|
|
|
|
defer blockchain.Stop() |
|
|
|
|
|
|
|
|
|
blocks, _ := GenerateChain(gspec.Config, genesis, db, 3, func(i int, block *BlockGen) { |
|
|
|
|
blocks, _ := GenerateChain(gspec.Config, genesis, ethash.NewFaker(), db, 3, func(i int, block *BlockGen) { |
|
|
|
|
var ( |
|
|
|
|
tx *types.Transaction |
|
|
|
|
err error |
|
|
|
|