diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2016-10-06 22:14:22 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-06 22:14:22 +0800 |
commit | 7335a70a020517cc9cebe7ae82c0e49ba133abf1 (patch) | |
tree | cc63625fa07bf3fb28326a01d5c8255a83a83bd1 /tests/util.go | |
parent | 07caa3fccdfe11bbee084c043ac11e7cfae9a6b7 (diff) | |
parent | 3c836dd71b192de24774b1848173a4eb0ca9a63b (diff) | |
download | dexon-7335a70a020517cc9cebe7ae82c0e49ba133abf1.tar dexon-7335a70a020517cc9cebe7ae82c0e49ba133abf1.tar.gz dexon-7335a70a020517cc9cebe7ae82c0e49ba133abf1.tar.bz2 dexon-7335a70a020517cc9cebe7ae82c0e49ba133abf1.tar.lz dexon-7335a70a020517cc9cebe7ae82c0e49ba133abf1.tar.xz dexon-7335a70a020517cc9cebe7ae82c0e49ba133abf1.tar.zst dexon-7335a70a020517cc9cebe7ae82c0e49ba133abf1.zip |
Merge pull request #3092 from fjl/state-journal
core/state: implement reverts by journaling all changes
Diffstat (limited to 'tests/util.go')
-rw-r--r-- | tests/util.go | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/tests/util.go b/tests/util.go index ffbcb9d56..8a9d09213 100644 --- a/tests/util.go +++ b/tests/util.go @@ -103,19 +103,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) - codeHash := crypto.Keccak256Hash(code) - obj := state.NewObject(common.HexToAddress(addr), state.Account{ - Balance: common.Big(account.Balance), - CodeHash: codeHash[:], - Nonce: common.Big(account.Nonce).Uint64(), - }, onDirty) - obj.SetCode(codeHash, 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 { @@ -229,11 +235,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) { |