diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/block_test_util.go | 51 | ||||
-rw-r--r-- | tests/state_test_util.go | 4 | ||||
-rw-r--r-- | tests/vm_test_util.go | 4 |
3 files changed, 31 insertions, 28 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 } diff --git a/tests/state_test_util.go b/tests/state_test_util.go index a1c066c82..676d9ed8c 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -103,7 +103,7 @@ func BenchStateTest(p string, conf bconf, b *testing.B) error { func benchStateTest(test VmTest, env map[string]string, b *testing.B) { b.StopTimer() db, _ := ethdb.NewMemDatabase() - statedb := state.New(common.Hash{}, db) + statedb, _ := state.New(common.Hash{}, db) for addr, account := range test.Pre { obj := StateObjectFromAccount(db, addr, account) statedb.SetStateObject(obj) @@ -142,7 +142,7 @@ func runStateTests(tests map[string]VmTest, skipTests []string) error { func runStateTest(test VmTest) error { db, _ := ethdb.NewMemDatabase() - statedb := state.New(common.Hash{}, db) + statedb, _ := state.New(common.Hash{}, db) for addr, account := range test.Pre { obj := StateObjectFromAccount(db, addr, account) statedb.SetStateObject(obj) diff --git a/tests/vm_test_util.go b/tests/vm_test_util.go index b61995e31..ddd14b1a3 100644 --- a/tests/vm_test_util.go +++ b/tests/vm_test_util.go @@ -108,7 +108,7 @@ func BenchVmTest(p string, conf bconf, b *testing.B) error { func benchVmTest(test VmTest, env map[string]string, b *testing.B) { b.StopTimer() db, _ := ethdb.NewMemDatabase() - statedb := state.New(common.Hash{}, db) + statedb, _ := state.New(common.Hash{}, db) for addr, account := range test.Pre { obj := StateObjectFromAccount(db, addr, account) statedb.SetStateObject(obj) @@ -159,7 +159,7 @@ func runVmTests(tests map[string]VmTest, skipTests []string) error { func runVmTest(test VmTest) error { db, _ := ethdb.NewMemDatabase() - statedb := state.New(common.Hash{}, db) + statedb, _ := state.New(common.Hash{}, db) for addr, account := range test.Pre { obj := StateObjectFromAccount(db, addr, account) statedb.SetStateObject(obj) |