aboutsummaryrefslogtreecommitdiffstats
path: root/tests/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'tests/util.go')
-rw-r--r--tests/util.go49
1 files changed, 33 insertions, 16 deletions
diff --git a/tests/util.go b/tests/util.go
index 08fac2dd1..8359e46fd 100644
--- a/tests/util.go
+++ b/tests/util.go
@@ -30,6 +30,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/params"
)
var (
@@ -103,18 +104,25 @@ func (self Log) Topics() [][]byte {
return t
}
-func StateObjectFromAccount(db ethdb.Database, addr string, account Account, onDirty func(common.Address)) *state.StateObject {
+func makePreState(db ethdb.Database, accounts map[string]Account) *state.StateDB {
+ statedb, _ := state.New(common.Hash{}, db)
+ for addr, account := range accounts {
+ insertAccount(statedb, addr, account)
+ }
+ return statedb
+}
+
+func insertAccount(state *state.StateDB, saddr string, account Account) {
if common.IsHex(account.Code) {
account.Code = account.Code[2:]
}
- code := common.Hex2Bytes(account.Code)
- obj := state.NewObject(common.HexToAddress(addr), state.Account{
- Balance: common.Big(account.Balance),
- CodeHash: crypto.Keccak256(code),
- Nonce: common.Big(account.Nonce).Uint64(),
- }, onDirty)
- obj.SetCode(code)
- return obj
+ addr := common.HexToAddress(saddr)
+ state.SetCode(addr, common.Hex2Bytes(account.Code))
+ state.SetNonce(addr, common.Big(account.Nonce).Uint64())
+ state.SetBalance(addr, common.Big(account.Balance))
+ for a, v := range account.Storage {
+ state.SetState(addr, common.HexToHash(a), common.HexToHash(v))
+ }
}
type VmEnv struct {
@@ -141,15 +149,24 @@ type VmTest struct {
}
type RuleSet struct {
- HomesteadBlock *big.Int
- DAOForkBlock *big.Int
- DAOForkSupport bool
+ HomesteadBlock *big.Int
+ DAOForkBlock *big.Int
+ DAOForkSupport bool
+ HomesteadGasRepriceBlock *big.Int
}
func (r RuleSet) IsHomestead(n *big.Int) bool {
return n.Cmp(r.HomesteadBlock) >= 0
}
+func (r RuleSet) GasTable(num *big.Int) params.GasTable {
+ if r.HomesteadGasRepriceBlock == nil || num == nil || num.Cmp(r.HomesteadGasRepriceBlock) < 0 {
+ return params.GasTableHomestead
+ }
+
+ return params.GasTableHomesteadGasRepriceFork
+}
+
type Env struct {
ruleSet RuleSet
depth int
@@ -228,11 +245,11 @@ func (self *Env) CanTransfer(from common.Address, balance *big.Int) bool {
return self.state.GetBalance(from).Cmp(balance) >= 0
}
-func (self *Env) MakeSnapshot() vm.Database {
- return self.state.Copy()
+func (self *Env) SnapshotDatabase() int {
+ return self.state.Snapshot()
}
-func (self *Env) SetSnapshot(copy vm.Database) {
- self.state.Set(copy.(*state.StateDB))
+func (self *Env) RevertToSnapshot(snapshot int) {
+ self.state.RevertToSnapshot(snapshot)
}
func (self *Env) Transfer(from, to vm.Account, amount *big.Int) {