aboutsummaryrefslogtreecommitdiffstats
path: root/tests/block_test_util.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-10-16 21:18:41 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-10-16 21:18:41 +0800
commitb74775400906cc582bdbb98bf5067c5258ee491f (patch)
treefefd9cfe28ce5b409d58c70b03cf4a6d6dc84873 /tests/block_test_util.go
parentf466243417f60531998e8b500f2bb043af5b3d2a (diff)
parent1b1f293082044c43d8d1c5df9ac40aab8fdb2ae8 (diff)
downloaddexon-b74775400906cc582bdbb98bf5067c5258ee491f.tar.gz
dexon-b74775400906cc582bdbb98bf5067c5258ee491f.tar.zst
dexon-b74775400906cc582bdbb98bf5067c5258ee491f.zip
Merge pull request #1881 from Gustav-Simonsson/state_new_error
core/state, core, miner: handle missing root error from state.New
Diffstat (limited to 'tests/block_test_util.go')
-rw-r--r--tests/block_test_util.go51
1 files changed, 27 insertions, 24 deletions
diff --git a/tests/block_test_util.go b/tests/block_test_util.go
index fb9ca16e6..4c329631a 100644
--- a/tests/block_test_util.go
+++ b/tests/block_test_util.go
@@ -162,23 +162,33 @@ func runBlockTests(bt map[string]*BlockTest, skipTests []string) error {
}
func runBlockTest(test *BlockTest) error {
- cfg := test.makeEthConfig()
+ ks := crypto.NewKeyStorePassphrase(filepath.Join(common.DefaultDataDir(), "keystore"))
+ am := accounts.NewManager(ks)
+ db, _ := ethdb.NewMemDatabase()
+ cfg := &eth.Config{
+ DataDir: common.DefaultDataDir(),
+ Verbosity: 5,
+ Etherbase: common.Address{},
+ AccountManager: am,
+ NewDB: func(path string) (ethdb.Database, error) { return db, nil },
+ }
+
cfg.GenesisBlock = test.Genesis
- ethereum, err := eth.New(cfg)
+ // import pre accounts & construct test genesis block & state root
+ _, err := test.InsertPreState(db, am)
if err != nil {
- return err
+ return fmt.Errorf("InsertPreState: %v", err)
}
- err = ethereum.Start()
+ ethereum, err := eth.New(cfg)
if err != nil {
return err
}
- // import pre accounts
- _, err = test.InsertPreState(ethereum)
+ err = ethereum.Start()
if err != nil {
- return fmt.Errorf("InsertPreState: %v", err)
+ return err
}
cm := ethereum.BlockChain()
@@ -193,7 +203,10 @@ func runBlockTest(test *BlockTest) error {
return fmt.Errorf("lastblockhash validation mismatch: want: %x, have: %x", lastblockhash, cmlast)
}
- newDB := cm.State()
+ newDB, err := cm.State()
+ if err != nil {
+ return err
+ }
if err = test.ValidatePostState(newDB); err != nil {
return fmt.Errorf("post state validation failed: %v", err)
}
@@ -201,23 +214,13 @@ func runBlockTest(test *BlockTest) error {
return test.ValidateImportedHeaders(cm, validBlocks)
}
-func (test *BlockTest) makeEthConfig() *eth.Config {
- ks := crypto.NewKeyStorePassphrase(filepath.Join(common.DefaultDataDir(), "keystore"))
-
- return &eth.Config{
- DataDir: common.DefaultDataDir(),
- Verbosity: 5,
- Etherbase: common.Address{},
- AccountManager: accounts.NewManager(ks),
- NewDB: func(path string) (ethdb.Database, error) { return ethdb.NewMemDatabase() },
- }
-}
-
// InsertPreState populates the given database with the genesis
// accounts defined by the test.
-func (t *BlockTest) InsertPreState(ethereum *eth.Ethereum) (*state.StateDB, error) {
- db := ethereum.ChainDb()
- statedb := state.New(common.Hash{}, db)
+func (t *BlockTest) InsertPreState(db ethdb.Database, am *accounts.Manager) (*state.StateDB, error) {
+ statedb, err := state.New(common.Hash{}, db)
+ if err != nil {
+ return nil, err
+ }
for addrString, acct := range t.preAccounts {
addr, err := hex.DecodeString(addrString)
if err != nil {
@@ -239,7 +242,7 @@ func (t *BlockTest) InsertPreState(ethereum *eth.Ethereum) (*state.StateDB, erro
if acct.PrivateKey != "" {
privkey, err := hex.DecodeString(strings.TrimPrefix(acct.PrivateKey, "0x"))
err = crypto.ImportBlockTestKey(privkey)
- err = ethereum.AccountManager().TimedUnlock(common.BytesToAddress(addr), "", 999999*time.Second)
+ err = am.TimedUnlock(common.BytesToAddress(addr), "", 999999*time.Second)
if err != nil {
return nil, err
}