aboutsummaryrefslogtreecommitdiffstats
path: root/core/dao_test.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2017-03-02 21:03:33 +0800
committerFelix Lange <fjl@twurst.com>2017-03-23 22:58:43 +0800
commit37dd9086ec491900311fc39837f4a62ef5fd3a4a (patch)
tree0d2c7bb99ad1cd2ffa6d014e44288452a537aba5 /core/dao_test.go
parent67c47459f283842bbf0063d9a1dc078251d6f433 (diff)
downloadgo-tangerine-37dd9086ec491900311fc39837f4a62ef5fd3a4a.tar.gz
go-tangerine-37dd9086ec491900311fc39837f4a62ef5fd3a4a.tar.zst
go-tangerine-37dd9086ec491900311fc39837f4a62ef5fd3a4a.zip
core: refactor genesis handling
This commit solves several issues concerning the genesis block: * Genesis/ChainConfig loading was handled by cmd/geth code. This left library users in the cold. They could specify a JSON-encoded string and overwrite the config, but didn't get any of the additional checks performed by geth. * Decoding and writing of genesis JSON was conflated in WriteGenesisBlock. This made it a lot harder to embed the genesis block into the forthcoming config file loader. This commit changes things so there is a single Genesis type that represents genesis blocks. All uses of Write*Genesis* are changed to use the new type instead. * If the chain config supplied by the user was incompatible with the current chain (i.e. the chain had already advanced beyond a scheduled fork), it got overwritten. This is not an issue in practice because previous forks have always had the highest total difficulty. It might matter in the future though. The new code reverts the local chain to the point of the fork when upgrading configuration. The change to genesis block data removes compression library dependencies from package core.
Diffstat (limited to 'core/dao_test.go')
-rw-r--r--core/dao_test.go15
1 files changed, 8 insertions, 7 deletions
diff --git a/core/dao_test.go b/core/dao_test.go
index 45b3235c7..c0d482630 100644
--- a/core/dao_test.go
+++ b/core/dao_test.go
@@ -34,17 +34,18 @@ func TestDAOForkRangeExtradata(t *testing.T) {
// Generate a common prefix for both pro-forkers and non-forkers
db, _ := ethdb.NewMemDatabase()
- genesis := WriteGenesisBlockForTesting(db)
+ gspec := new(Genesis)
+ genesis := gspec.MustCommit(db)
prefix, _ := GenerateChain(params.TestChainConfig, genesis, db, int(forkBlock.Int64()-1), func(i int, gen *BlockGen) {})
// Create the concurrent, conflicting two nodes
proDb, _ := ethdb.NewMemDatabase()
- WriteGenesisBlockForTesting(proDb)
+ gspec.MustCommit(proDb)
proConf := &params.ChainConfig{HomesteadBlock: big.NewInt(0), DAOForkBlock: forkBlock, DAOForkSupport: true}
proBc, _ := NewBlockChain(proDb, proConf, new(pow.FakePow), new(event.TypeMux), vm.Config{})
conDb, _ := ethdb.NewMemDatabase()
- WriteGenesisBlockForTesting(conDb)
+ gspec.MustCommit(conDb)
conConf := &params.ChainConfig{HomesteadBlock: big.NewInt(0), DAOForkBlock: forkBlock, DAOForkSupport: false}
conBc, _ := NewBlockChain(conDb, conConf, new(pow.FakePow), new(event.TypeMux), vm.Config{})
@@ -58,7 +59,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
for i := int64(0); i < params.DAOForkExtraRange.Int64(); i++ {
// Create a pro-fork block, and try to feed into the no-fork chain
db, _ = ethdb.NewMemDatabase()
- WriteGenesisBlockForTesting(db)
+ gspec.MustCommit(db)
bc, _ := NewBlockChain(db, conConf, new(pow.FakePow), new(event.TypeMux), vm.Config{})
blocks := conBc.GetBlocksFromHash(conBc.CurrentBlock().Hash(), int(conBc.CurrentBlock().NumberU64()+1))
@@ -79,7 +80,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
}
// Create a no-fork block, and try to feed into the pro-fork chain
db, _ = ethdb.NewMemDatabase()
- WriteGenesisBlockForTesting(db)
+ gspec.MustCommit(db)
bc, _ = NewBlockChain(db, proConf, new(pow.FakePow), new(event.TypeMux), vm.Config{})
blocks = proBc.GetBlocksFromHash(proBc.CurrentBlock().Hash(), int(proBc.CurrentBlock().NumberU64()+1))
@@ -101,7 +102,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
}
// Verify that contra-forkers accept pro-fork extra-datas after forking finishes
db, _ = ethdb.NewMemDatabase()
- WriteGenesisBlockForTesting(db)
+ gspec.MustCommit(db)
bc, _ := NewBlockChain(db, conConf, new(pow.FakePow), new(event.TypeMux), vm.Config{})
blocks := conBc.GetBlocksFromHash(conBc.CurrentBlock().Hash(), int(conBc.CurrentBlock().NumberU64()+1))
@@ -117,7 +118,7 @@ func TestDAOForkRangeExtradata(t *testing.T) {
}
// Verify that pro-forkers accept contra-fork extra-datas after forking finishes
db, _ = ethdb.NewMemDatabase()
- WriteGenesisBlockForTesting(db)
+ gspec.MustCommit(db)
bc, _ = NewBlockChain(db, proConf, new(pow.FakePow), new(event.TypeMux), vm.Config{})
blocks = proBc.GetBlocksFromHash(proBc.CurrentBlock().Hash(), int(proBc.CurrentBlock().NumberU64()+1))