aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/block_test_util.go59
-rw-r--r--tests/state_test_util.go8
-rw-r--r--tests/util.go51
-rw-r--r--tests/vm_test.go4
-rw-r--r--tests/vm_test_util.go8
5 files changed, 64 insertions, 66 deletions
diff --git a/tests/block_test_util.go b/tests/block_test_util.go
index 33577cf55..4c329631a 100644
--- a/tests/block_test_util.go
+++ b/tests/block_test_util.go
@@ -162,26 +162,36 @@ 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.ChainManager()
+ cm := ethereum.BlockChain()
validBlocks, err := test.TryBlocksInsert(cm)
if err != nil {
return err
@@ -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
}
@@ -276,7 +279,7 @@ func (t *BlockTest) InsertPreState(ethereum *eth.Ethereum) (*state.StateDB, erro
expected we are expected to ignore it and continue processing and then validate the
post state.
*/
-func (t *BlockTest) TryBlocksInsert(chainManager *core.ChainManager) ([]btBlock, error) {
+func (t *BlockTest) TryBlocksInsert(blockchain *core.BlockChain) ([]btBlock, error) {
validBlocks := make([]btBlock, 0)
// insert the test blocks, which will execute all transactions
for _, b := range t.Json.Blocks {
@@ -289,7 +292,7 @@ func (t *BlockTest) TryBlocksInsert(chainManager *core.ChainManager) ([]btBlock,
}
}
// RLP decoding worked, try to insert into chain:
- _, err = chainManager.InsertChain(types.Blocks{cb})
+ _, err = blockchain.InsertChain(types.Blocks{cb})
if err != nil {
if b.BlockHeader == nil {
continue // OK - block is supposed to be invalid, continue with next block
@@ -426,7 +429,7 @@ func (t *BlockTest) ValidatePostState(statedb *state.StateDB) error {
return nil
}
-func (test *BlockTest) ValidateImportedHeaders(cm *core.ChainManager, validBlocks []btBlock) error {
+func (test *BlockTest) ValidateImportedHeaders(cm *core.BlockChain, validBlocks []btBlock) error {
// to get constant lookup when verifying block headers by hash (some tests have many blocks)
bmap := make(map[string]btBlock, len(test.Json.Blocks))
for _, b := range validBlocks {
diff --git a/tests/state_test_util.go b/tests/state_test_util.go
index 3d8dfca31..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)
@@ -168,7 +168,7 @@ func runStateTest(test VmTest) error {
ret []byte
// gas *big.Int
// err error
- logs state.Logs
+ logs vm.Logs
)
ret, logs, _, _ = RunState(statedb, env, test.Transaction)
@@ -216,7 +216,7 @@ func runStateTest(test VmTest) error {
return nil
}
-func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, state.Logs, *big.Int, error) {
+func RunState(statedb *state.StateDB, env, tx map[string]string) ([]byte, vm.Logs, *big.Int, error) {
var (
data = common.FromHex(tx["data"])
gas = common.Big(tx["gasLimit"])
diff --git a/tests/util.go b/tests/util.go
index 72d927ada..bbc671169 100644
--- a/tests/util.go
+++ b/tests/util.go
@@ -30,7 +30,7 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
)
-func checkLogs(tlog []Log, logs state.Logs) error {
+func checkLogs(tlog []Log, logs vm.Logs) error {
if len(tlog) != len(logs) {
return fmt.Errorf("log length mismatch. Expected %d, got %d", len(tlog), len(logs))
@@ -53,7 +53,7 @@ func checkLogs(tlog []Log, logs state.Logs) error {
}
}
}
- genBloom := common.LeftPadBytes(types.LogsBloom(state.Logs{logs[i]}).Bytes(), 256)
+ genBloom := common.LeftPadBytes(types.LogsBloom(vm.Logs{logs[i]}).Bytes(), 256)
if !bytes.Equal(genBloom, common.Hex2Bytes(log.BloomF)) {
return fmt.Errorf("bloom mismatch")
@@ -181,18 +181,18 @@ func (self *Env) BlockNumber() *big.Int { return self.number }
func (self *Env) Coinbase() common.Address { return self.coinbase }
func (self *Env) Time() *big.Int { return self.time }
func (self *Env) Difficulty() *big.Int { return self.difficulty }
-func (self *Env) State() *state.StateDB { return self.state }
+func (self *Env) Db() vm.Database { return self.state }
func (self *Env) GasLimit() *big.Int { return self.gasLimit }
func (self *Env) VmType() vm.Type { return vm.StdVmTy }
func (self *Env) GetHash(n uint64) common.Hash {
return common.BytesToHash(crypto.Sha3([]byte(big.NewInt(int64(n)).String())))
}
-func (self *Env) AddLog(log *state.Log) {
+func (self *Env) AddLog(log *vm.Log) {
self.state.AddLog(log)
}
func (self *Env) Depth() int { return self.depth }
func (self *Env) SetDepth(i int) { self.depth = i }
-func (self *Env) CanTransfer(from vm.Account, balance *big.Int) bool {
+func (self *Env) CanTransfer(from common.Address, balance *big.Int) bool {
if self.skipTransfer {
if self.initial {
self.initial = false
@@ -200,58 +200,53 @@ func (self *Env) CanTransfer(from vm.Account, balance *big.Int) bool {
}
}
- return from.Balance().Cmp(balance) >= 0
+ return self.state.GetBalance(from).Cmp(balance) >= 0
+}
+func (self *Env) MakeSnapshot() vm.Database {
+ return self.state.Copy()
+}
+func (self *Env) SetSnapshot(copy vm.Database) {
+ self.state.Set(copy.(*state.StateDB))
}
-func (self *Env) Transfer(from, to vm.Account, amount *big.Int) error {
+func (self *Env) Transfer(from, to vm.Account, amount *big.Int) {
if self.skipTransfer {
- return nil
+ return
}
- return vm.Transfer(from, to, amount)
-}
-
-func (self *Env) vm(addr *common.Address, data []byte, gas, price, value *big.Int) *core.Execution {
- exec := core.NewExecution(self, addr, data, gas, price, value)
-
- return exec
+ core.Transfer(from, to, amount)
}
-func (self *Env) Call(caller vm.ContextRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) {
+func (self *Env) Call(caller vm.ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) {
if self.vmTest && self.depth > 0 {
caller.ReturnGas(gas, price)
return nil, nil
}
- exe := self.vm(&addr, data, gas, price, value)
- ret, err := exe.Call(addr, caller)
- self.Gas = exe.Gas
+ ret, err := core.Call(self, caller, addr, data, gas, price, value)
+ self.Gas = gas
return ret, err
}
-func (self *Env) CallCode(caller vm.ContextRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) {
+func (self *Env) CallCode(caller vm.ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) {
if self.vmTest && self.depth > 0 {
caller.ReturnGas(gas, price)
return nil, nil
}
-
- caddr := caller.Address()
- exe := self.vm(&caddr, data, gas, price, value)
- return exe.Call(addr, caller)
+ return core.CallCode(self, caller, addr, data, gas, price, value)
}
-func (self *Env) Create(caller vm.ContextRef, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ContextRef) {
- exe := self.vm(nil, data, gas, price, value)
+func (self *Env) Create(caller vm.ContractRef, data []byte, gas, price, value *big.Int) ([]byte, common.Address, error) {
if self.vmTest {
caller.ReturnGas(gas, price)
nonce := self.state.GetNonce(caller.Address())
obj := self.state.GetOrNewStateObject(crypto.CreateAddress(caller.Address(), nonce))
- return nil, nil, obj
+ return nil, obj.Address(), nil
} else {
- return exe.Create(caller)
+ return core.Create(self, caller, data, gas, price, value)
}
}
diff --git a/tests/vm_test.go b/tests/vm_test.go
index 96718db3c..34beb85e5 100644
--- a/tests/vm_test.go
+++ b/tests/vm_test.go
@@ -24,14 +24,14 @@ import (
func BenchmarkVmAckermann32Tests(b *testing.B) {
fn := filepath.Join(vmTestDir, "vmPerformanceTest.json")
- if err := BenchVmTest(fn, bconf{"ackermann32", true, os.Getenv("JITVM") == "true"}, b); err != nil {
+ if err := BenchVmTest(fn, bconf{"ackermann32", os.Getenv("JITFORCE") == "true", os.Getenv("JITVM") == "true"}, b); err != nil {
b.Error(err)
}
}
func BenchmarkVmFibonacci16Tests(b *testing.B) {
fn := filepath.Join(vmTestDir, "vmPerformanceTest.json")
- if err := BenchVmTest(fn, bconf{"fibonacci16", true, os.Getenv("JITVM") == "true"}, b); err != nil {
+ if err := BenchVmTest(fn, bconf{"fibonacci16", os.Getenv("JITFORCE") == "true", os.Getenv("JITVM") == "true"}, b); err != nil {
b.Error(err)
}
}
diff --git a/tests/vm_test_util.go b/tests/vm_test_util.go
index 71a4f5e33..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)
@@ -185,7 +185,7 @@ func runVmTest(test VmTest) error {
ret []byte
gas *big.Int
err error
- logs state.Logs
+ logs vm.Logs
)
ret, logs, gas, err = RunVm(statedb, env, test.Exec)
@@ -234,7 +234,7 @@ func runVmTest(test VmTest) error {
return nil
}
-func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, state.Logs, *big.Int, error) {
+func RunVm(state *state.StateDB, env, exec map[string]string) ([]byte, vm.Logs, *big.Int, error) {
var (
to = common.HexToAddress(exec["address"])
from = common.HexToAddress(exec["caller"])