diff options
author | Felix Lange <fjl@users.noreply.github.com> | 2017-06-27 21:57:06 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-27 21:57:06 +0800 |
commit | 9e5f03b6c487175cc5aa1224e5e12fd573f483a7 (patch) | |
tree | 475e573ff6c7e77cd069a2f6238afdb27d4bce43 /core/state/statedb_test.go | |
parent | bb366271fe33cf87b462dc5a25ac6c448ac6d2e1 (diff) | |
download | go-tangerine-9e5f03b6c487175cc5aa1224e5e12fd573f483a7.tar.gz go-tangerine-9e5f03b6c487175cc5aa1224e5e12fd573f483a7.tar.zst go-tangerine-9e5f03b6c487175cc5aa1224e5e12fd573f483a7.zip |
core/state: access trie through Database interface, track errors (#14589)
With this commit, core/state's access to the underlying key/value database is
mediated through an interface. Database errors are tracked in StateDB and
returned by CommitTo or the new Error method.
Motivation for this change: We can remove the light client's duplicated copy of
core/state. The light client now supports node iteration, so tracing and storage
enumeration can work with the light client (not implemented in this commit).
Diffstat (limited to 'core/state/statedb_test.go')
-rw-r--r-- | core/state/statedb_test.go | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go index 72b638f97..b2bd18e65 100644 --- a/core/state/statedb_test.go +++ b/core/state/statedb_test.go @@ -28,6 +28,8 @@ import ( "testing" "testing/quick" + check "gopkg.in/check.v1" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethdb" @@ -38,7 +40,7 @@ import ( func TestUpdateLeaks(t *testing.T) { // Create an empty state database db, _ := ethdb.NewMemDatabase() - state, _ := New(common.Hash{}, db) + state, _ := New(common.Hash{}, NewDatabase(db)) // Update it with some accounts for i := byte(0); i < 255; i++ { @@ -66,8 +68,8 @@ func TestIntermediateLeaks(t *testing.T) { // Create two state databases, one transitioning to the final state, the other final from the beginning transDb, _ := ethdb.NewMemDatabase() finalDb, _ := ethdb.NewMemDatabase() - transState, _ := New(common.Hash{}, transDb) - finalState, _ := New(common.Hash{}, finalDb) + transState, _ := New(common.Hash{}, NewDatabase(transDb)) + finalState, _ := New(common.Hash{}, NewDatabase(finalDb)) modify := func(state *StateDB, addr common.Address, i, tweak byte) { state.SetBalance(addr, big.NewInt(int64(11*i)+int64(tweak))) @@ -95,10 +97,10 @@ func TestIntermediateLeaks(t *testing.T) { } // Commit and cross check the databases. - if _, err := transState.Commit(false); err != nil { + if _, err := transState.CommitTo(transDb, false); err != nil { t.Fatalf("failed to commit transition state: %v", err) } - if _, err := finalState.Commit(false); err != nil { + if _, err := finalState.CommitTo(finalDb, false); err != nil { t.Fatalf("failed to commit final state: %v", err) } for _, key := range finalDb.Keys() { @@ -282,7 +284,7 @@ func (test *snapshotTest) run() bool { // Run all actions and create snapshots. var ( db, _ = ethdb.NewMemDatabase() - state, _ = New(common.Hash{}, db) + state, _ = New(common.Hash{}, NewDatabase(db)) snapshotRevs = make([]int, len(test.snapshots)) sindex = 0 ) @@ -297,7 +299,7 @@ func (test *snapshotTest) run() bool { // Revert all snapshots in reverse order. Each revert must yield a state // that is equivalent to fresh state with all actions up the snapshot applied. for sindex--; sindex >= 0; sindex-- { - checkstate, _ := New(common.Hash{}, db) + checkstate, _ := New(common.Hash{}, NewDatabase(db)) for _, action := range test.actions[:test.snapshots[sindex]] { action.fn(action, checkstate) } @@ -354,21 +356,19 @@ func (test *snapshotTest) checkEqual(state, checkstate *StateDB) error { return nil } -func TestTouchDelete(t *testing.T) { - db, _ := ethdb.NewMemDatabase() - state, _ := New(common.Hash{}, db) - state.GetOrNewStateObject(common.Address{}) - root, _ := state.Commit(false) - state.Reset(root) +func (s *StateSuite) TestTouchDelete(c *check.C) { + s.state.GetOrNewStateObject(common.Address{}) + root, _ := s.state.CommitTo(s.db, false) + s.state.Reset(root) - snapshot := state.Snapshot() - state.AddBalance(common.Address{}, new(big.Int)) - if len(state.stateObjectsDirty) != 1 { - t.Fatal("expected one dirty state object") + snapshot := s.state.Snapshot() + s.state.AddBalance(common.Address{}, new(big.Int)) + if len(s.state.stateObjectsDirty) != 1 { + c.Fatal("expected one dirty state object") } - state.RevertToSnapshot(snapshot) - if len(state.stateObjectsDirty) != 0 { - t.Fatal("expected no dirty state object") + s.state.RevertToSnapshot(snapshot) + if len(s.state.stateObjectsDirty) != 0 { + c.Fatal("expected no dirty state object") } } |