aboutsummaryrefslogtreecommitdiffstats
path: root/state/state_test.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-20 09:34:12 +0800
committerobscuren <geffobscura@gmail.com>2014-12-20 09:34:12 +0800
commit3983dd2428137211f84f299f9ce8690c22f50afd (patch)
tree3a2dc53b365e6f377fc82a3514150d1297fe549c /state/state_test.go
parent7daa8c2f6eb25511c6a54ad420709af911fc6748 (diff)
parent0a9dc1536c5d776844d6947a0090ff7e1a7c6ab4 (diff)
downloadgo-tangerine-3983dd2428137211f84f299f9ce8690c22f50afd.tar
go-tangerine-3983dd2428137211f84f299f9ce8690c22f50afd.tar.gz
go-tangerine-3983dd2428137211f84f299f9ce8690c22f50afd.tar.bz2
go-tangerine-3983dd2428137211f84f299f9ce8690c22f50afd.tar.lz
go-tangerine-3983dd2428137211f84f299f9ce8690c22f50afd.tar.xz
go-tangerine-3983dd2428137211f84f299f9ce8690c22f50afd.tar.zst
go-tangerine-3983dd2428137211f84f299f9ce8690c22f50afd.zip
Merge branch 'release/v0.7.10'vv0.7.10
Diffstat (limited to 'state/state_test.go')
-rw-r--r--state/state_test.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/state/state_test.go b/state/state_test.go
new file mode 100644
index 000000000..28e4fc5da
--- /dev/null
+++ b/state/state_test.go
@@ -0,0 +1,61 @@
+package state
+
+import (
+ checker "gopkg.in/check.v1"
+
+ "github.com/ethereum/go-ethereum/ethdb"
+ "github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/trie"
+)
+
+type StateSuite struct {
+ state *StateDB
+}
+
+var _ = checker.Suite(&StateSuite{})
+
+// var ZeroHash256 = make([]byte, 32)
+
+func (s *StateSuite) TestDump(c *checker.C) {
+ key := []byte{0x01}
+ value := "foo"
+ node := []interface{}{key, value}
+ s.state.Trie.Put(node)
+ dump := s.state.Dump()
+ c.Assert(dump, checker.NotNil)
+}
+
+func (s *StateSuite) SetUpTest(c *checker.C) {
+ db, _ := ethdb.NewMemDatabase()
+ ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
+ ethutil.Config.Db = db
+ s.state = New(trie.New(db, ""))
+}
+
+func (s *StateSuite) TestSnapshot(c *checker.C) {
+ stateobjaddr := []byte("aa")
+ storageaddr := ethutil.Big("0")
+ data1 := ethutil.NewValue(42)
+ data2 := ethutil.NewValue(43)
+
+ // get state object
+ stateObject := s.state.GetOrNewStateObject(stateobjaddr)
+ // set inital state object value
+ stateObject.SetStorage(storageaddr, data1)
+ // get snapshot of current state
+ snapshot := s.state.Copy()
+
+ // get state object. is this strictly necessary?
+ stateObject = s.state.GetStateObject(stateobjaddr)
+ // set new state object value
+ stateObject.SetStorage(storageaddr, data2)
+ // restore snapshot
+ s.state.Set(snapshot)
+
+ // get state object
+ stateObject = s.state.GetStateObject(stateobjaddr)
+ // get state storage value
+ res := stateObject.GetStorage(storageaddr)
+
+ c.Assert(data1, checker.DeepEquals, res)
+}