aboutsummaryrefslogtreecommitdiffstats
path: root/core/blockchain_test.go
diff options
context:
space:
mode:
authorWenbiao Zheng <delweng@gmail.com>2018-06-19 19:41:13 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-06-19 19:41:13 +0800
commit9b1536b26a78341008c5efe962f916d12220e720 (patch)
tree4668e7f4f57ba810a06e3054ff36c1828f3279f3 /core/blockchain_test.go
parent3e57c33147bf05329dd9ef9868c04e301ac8bb58 (diff)
downloadgo-tangerine-9b1536b26a78341008c5efe962f916d12220e720.tar
go-tangerine-9b1536b26a78341008c5efe962f916d12220e720.tar.gz
go-tangerine-9b1536b26a78341008c5efe962f916d12220e720.tar.bz2
go-tangerine-9b1536b26a78341008c5efe962f916d12220e720.tar.lz
go-tangerine-9b1536b26a78341008c5efe962f916d12220e720.tar.xz
go-tangerine-9b1536b26a78341008c5efe962f916d12220e720.tar.zst
go-tangerine-9b1536b26a78341008c5efe962f916d12220e720.zip
core: remove dead code, limit test code scope (#17006)
* core: move test util var/func to test file * core: remove useless func
Diffstat (limited to 'core/blockchain_test.go')
-rw-r--r--core/blockchain_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/core/blockchain_test.go b/core/blockchain_test.go
index 5dbf63d1d..f409bb7b0 100644
--- a/core/blockchain_test.go
+++ b/core/blockchain_test.go
@@ -25,6 +25,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
@@ -35,6 +36,39 @@ import (
"github.com/ethereum/go-ethereum/params"
)
+// So we can deterministically seed different blockchains
+var (
+ canonicalSeed = 1
+ forkSeed = 2
+)
+
+// newCanonical creates a chain database, and injects a deterministic canonical
+// chain. Depending on the full flag, if creates either a full block chain or a
+// header only chain.
+func newCanonical(engine consensus.Engine, n int, full bool) (ethdb.Database, *BlockChain, error) {
+ var (
+ db = ethdb.NewMemDatabase()
+ genesis = new(Genesis).MustCommit(db)
+ )
+
+ // Initialize a fresh chain with only a genesis block
+ blockchain, _ := NewBlockChain(db, nil, params.AllEthashProtocolChanges, engine, vm.Config{})
+ // Create and inject the requested chain
+ if n == 0 {
+ return db, blockchain, nil
+ }
+ if full {
+ // Full block-chain requested
+ blocks := makeBlockChain(genesis, n, engine, db, canonicalSeed)
+ _, err := blockchain.InsertChain(blocks)
+ return db, blockchain, err
+ }
+ // Header-only chain requested
+ headers := makeHeaderChain(genesis.Header(), n, engine, db, canonicalSeed)
+ _, err := blockchain.InsertHeaderChain(headers, 1)
+ return db, blockchain, err
+}
+
// 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