diff options
author | Gustav Simonsson <gustav.simonsson@gmail.com> | 2015-10-06 22:35:55 +0800 |
---|---|---|
committer | Gustav Simonsson <gustav.simonsson@gmail.com> | 2015-10-16 08:22:06 +0800 |
commit | 1b1f293082044c43d8d1c5df9ac40aab8fdb2ae8 (patch) | |
tree | fefd9cfe28ce5b409d58c70b03cf4a6d6dc84873 /tests/block_test_util.go | |
parent | f466243417f60531998e8b500f2bb043af5b3d2a (diff) | |
download | dexon-1b1f293082044c43d8d1c5df9ac40aab8fdb2ae8.tar dexon-1b1f293082044c43d8d1c5df9ac40aab8fdb2ae8.tar.gz dexon-1b1f293082044c43d8d1c5df9ac40aab8fdb2ae8.tar.bz2 dexon-1b1f293082044c43d8d1c5df9ac40aab8fdb2ae8.tar.lz dexon-1b1f293082044c43d8d1c5df9ac40aab8fdb2ae8.tar.xz dexon-1b1f293082044c43d8d1c5df9ac40aab8fdb2ae8.tar.zst dexon-1b1f293082044c43d8d1c5df9ac40aab8fdb2ae8.zip |
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.go | 51 |
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 := ð.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 ð.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 } |