diff options
author | Péter Szilágyi <peterke@gmail.com> | 2018-09-21 19:16:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-21 19:16:18 +0800 |
commit | ee92bc537f159c2202058a33e015684cc2bca04c (patch) | |
tree | 8f89d2e71d98f26024069be193023ef5da2a0d3f /core/state/state_test.go | |
parent | 81080bf8cb7f60f59a68cf48998a29a1a2e10cb9 (diff) | |
parent | 360a72d54e9ea6fbf8ddb4872cc514d241ea2042 (diff) | |
download | go-tangerine-ee92bc537f159c2202058a33e015684cc2bca04c.tar go-tangerine-ee92bc537f159c2202058a33e015684cc2bca04c.tar.gz go-tangerine-ee92bc537f159c2202058a33e015684cc2bca04c.tar.bz2 go-tangerine-ee92bc537f159c2202058a33e015684cc2bca04c.tar.lz go-tangerine-ee92bc537f159c2202058a33e015684cc2bca04c.tar.xz go-tangerine-ee92bc537f159c2202058a33e015684cc2bca04c.tar.zst go-tangerine-ee92bc537f159c2202058a33e015684cc2bca04c.zip |
Merge pull request #17383 from holiman/eip1283
Eip1283
Diffstat (limited to 'core/state/state_test.go')
-rw-r--r-- | core/state/state_test.go | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/core/state/state_test.go b/core/state/state_test.go index 123559ea9..a09273f3b 100644 --- a/core/state/state_test.go +++ b/core/state/state_test.go @@ -96,11 +96,15 @@ func (s *StateSuite) TestNull(c *checker.C) { s.state.CreateAccount(address) //value := common.FromHex("0x823140710bf13990e4500136726d8b55") var value common.Hash + s.state.SetState(address, common.Hash{}, value) s.state.Commit(false) - value = s.state.GetState(address, common.Hash{}) - if value != (common.Hash{}) { - c.Errorf("expected empty hash. got %x", value) + + if value := s.state.GetState(address, common.Hash{}); value != (common.Hash{}) { + c.Errorf("expected empty current value, got %x", value) + } + if value := s.state.GetCommittedState(address, common.Hash{}); value != (common.Hash{}) { + c.Errorf("expected empty committed value, got %x", value) } } @@ -110,20 +114,24 @@ func (s *StateSuite) TestSnapshot(c *checker.C) { data1 := common.BytesToHash([]byte{42}) data2 := common.BytesToHash([]byte{43}) + // snapshot the genesis state + genesis := s.state.Snapshot() + // set initial state object value s.state.SetState(stateobjaddr, storageaddr, data1) - // get snapshot of current state snapshot := s.state.Snapshot() - // set new state object value + // set a new state object value, revert it and ensure correct content s.state.SetState(stateobjaddr, storageaddr, data2) - // restore snapshot s.state.RevertToSnapshot(snapshot) - // get state storage value - res := s.state.GetState(stateobjaddr, storageaddr) + c.Assert(s.state.GetState(stateobjaddr, storageaddr), checker.DeepEquals, data1) + c.Assert(s.state.GetCommittedState(stateobjaddr, storageaddr), checker.DeepEquals, common.Hash{}) - c.Assert(data1, checker.DeepEquals, res) + // revert up to the genesis state and ensure correct content + s.state.RevertToSnapshot(genesis) + c.Assert(s.state.GetState(stateobjaddr, storageaddr), checker.DeepEquals, common.Hash{}) + c.Assert(s.state.GetCommittedState(stateobjaddr, storageaddr), checker.DeepEquals, common.Hash{}) } func (s *StateSuite) TestSnapshotEmpty(c *checker.C) { @@ -208,24 +216,30 @@ func compareStateObjects(so0, so1 *stateObject, t *testing.T) { t.Fatalf("Code mismatch: have %v, want %v", so0.code, so1.code) } - if len(so1.cachedStorage) != len(so0.cachedStorage) { - t.Errorf("Storage size mismatch: have %d, want %d", len(so1.cachedStorage), len(so0.cachedStorage)) + if len(so1.dirtyStorage) != len(so0.dirtyStorage) { + t.Errorf("Dirty storage size mismatch: have %d, want %d", len(so1.dirtyStorage), len(so0.dirtyStorage)) } - for k, v := range so1.cachedStorage { - if so0.cachedStorage[k] != v { - t.Errorf("Storage key %x mismatch: have %v, want %v", k, so0.cachedStorage[k], v) + for k, v := range so1.dirtyStorage { + if so0.dirtyStorage[k] != v { + t.Errorf("Dirty storage key %x mismatch: have %v, want %v", k, so0.dirtyStorage[k], v) } } - for k, v := range so0.cachedStorage { - if so1.cachedStorage[k] != v { - t.Errorf("Storage key %x mismatch: have %v, want none.", k, v) + for k, v := range so0.dirtyStorage { + if so1.dirtyStorage[k] != v { + t.Errorf("Dirty storage key %x mismatch: have %v, want none.", k, v) } } - - if so0.suicided != so1.suicided { - t.Fatalf("suicided mismatch: have %v, want %v", so0.suicided, so1.suicided) + if len(so1.originStorage) != len(so0.originStorage) { + t.Errorf("Origin storage size mismatch: have %d, want %d", len(so1.originStorage), len(so0.originStorage)) + } + for k, v := range so1.originStorage { + if so0.originStorage[k] != v { + t.Errorf("Origin storage key %x mismatch: have %v, want %v", k, so0.originStorage[k], v) + } } - if so0.deleted != so1.deleted { - t.Fatalf("Deleted mismatch: have %v, want %v", so0.deleted, so1.deleted) + for k, v := range so0.originStorage { + if so1.originStorage[k] != v { + t.Errorf("Origin storage key %x mismatch: have %v, want none.", k, v) + } } } |