aboutsummaryrefslogtreecommitdiffstats
path: root/core/state/state_test.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@users.noreply.github.com>2017-06-27 21:57:06 +0800
committerGitHub <noreply@github.com>2017-06-27 21:57:06 +0800
commit9e5f03b6c487175cc5aa1224e5e12fd573f483a7 (patch)
tree475e573ff6c7e77cd069a2f6238afdb27d4bce43 /core/state/state_test.go
parentbb366271fe33cf87b462dc5a25ac6c448ac6d2e1 (diff)
downloadgo-tangerine-9e5f03b6c487175cc5aa1224e5e12fd573f483a7.tar
go-tangerine-9e5f03b6c487175cc5aa1224e5e12fd573f483a7.tar.gz
go-tangerine-9e5f03b6c487175cc5aa1224e5e12fd573f483a7.tar.bz2
go-tangerine-9e5f03b6c487175cc5aa1224e5e12fd573f483a7.tar.lz
go-tangerine-9e5f03b6c487175cc5aa1224e5e12fd573f483a7.tar.xz
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/state_test.go')
-rw-r--r--core/state/state_test.go39
1 files changed, 17 insertions, 22 deletions
diff --git a/core/state/state_test.go b/core/state/state_test.go
index 3bc63c148..bbae3685b 100644
--- a/core/state/state_test.go
+++ b/core/state/state_test.go
@@ -21,14 +21,14 @@ import (
"math/big"
"testing"
- checker "gopkg.in/check.v1"
-
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
+ checker "gopkg.in/check.v1"
)
type StateSuite struct {
+ db *ethdb.MemDatabase
state *StateDB
}
@@ -48,7 +48,7 @@ func (s *StateSuite) TestDump(c *checker.C) {
// write some of them to the trie
s.state.updateStateObject(obj1)
s.state.updateStateObject(obj2)
- s.state.Commit(false)
+ s.state.CommitTo(s.db, false)
// check that dump contains the state objects that are in trie
got := string(s.state.Dump())
@@ -87,23 +87,20 @@ func (s *StateSuite) TestDump(c *checker.C) {
}
func (s *StateSuite) SetUpTest(c *checker.C) {
- db, _ := ethdb.NewMemDatabase()
- s.state, _ = New(common.Hash{}, db)
+ s.db, _ = ethdb.NewMemDatabase()
+ s.state, _ = New(common.Hash{}, NewDatabase(s.db))
}
-func TestNull(t *testing.T) {
- db, _ := ethdb.NewMemDatabase()
- state, _ := New(common.Hash{}, db)
-
+func (s *StateSuite) TestNull(c *checker.C) {
address := common.HexToAddress("0x823140710bf13990e4500136726d8b55")
- state.CreateAccount(address)
+ s.state.CreateAccount(address)
//value := common.FromHex("0x823140710bf13990e4500136726d8b55")
var value common.Hash
- state.SetState(address, common.Hash{}, value)
- state.Commit(false)
- value = state.GetState(address, common.Hash{})
+ s.state.SetState(address, common.Hash{}, value)
+ s.state.CommitTo(s.db, false)
+ value = s.state.GetState(address, common.Hash{})
if !common.EmptyHash(value) {
- t.Errorf("expected empty hash. got %x", value)
+ c.Errorf("expected empty hash. got %x", value)
}
}
@@ -129,17 +126,15 @@ func (s *StateSuite) TestSnapshot(c *checker.C) {
c.Assert(data1, checker.DeepEquals, res)
}
-func TestSnapshotEmpty(t *testing.T) {
- db, _ := ethdb.NewMemDatabase()
- state, _ := New(common.Hash{}, db)
- state.RevertToSnapshot(state.Snapshot())
+func (s *StateSuite) TestSnapshotEmpty(c *checker.C) {
+ s.state.RevertToSnapshot(s.state.Snapshot())
}
// use testing instead of checker because checker does not support
// printing/logging in tests (-check.vv does not work)
func TestSnapshot2(t *testing.T) {
db, _ := ethdb.NewMemDatabase()
- state, _ := New(common.Hash{}, db)
+ state, _ := New(common.Hash{}, NewDatabase(db))
stateobjaddr0 := toAddr([]byte("so0"))
stateobjaddr1 := toAddr([]byte("so1"))
@@ -160,7 +155,7 @@ func TestSnapshot2(t *testing.T) {
so0.deleted = false
state.setStateObject(so0)
- root, _ := state.Commit(false)
+ root, _ := state.CommitTo(db, false)
state.Reset(root)
// and one with deleted == true
@@ -182,8 +177,8 @@ func TestSnapshot2(t *testing.T) {
so0Restored := state.getStateObject(stateobjaddr0)
// Update lazily-loaded values before comparing.
- so0Restored.GetState(db, storageaddr)
- so0Restored.Code(db)
+ so0Restored.GetState(state.db, storageaddr)
+ so0Restored.Code(state.db)
// non-deleted is equal (restored)
compareStateObjects(so0Restored, so0, t)