aboutsummaryrefslogtreecommitdiffstats
path: root/state
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2014-11-11 19:52:43 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2014-11-11 19:52:43 +0800
commit8f3a03c0cc8ef15f561b47ef1c11b02e4f043634 (patch)
tree57e209fc06d80dbb93bfa7031953a865dc95bb77 /state
parent0a3a148ed4d2fbe29ec7a62f5b15a25f908d7f23 (diff)
downloaddexon-8f3a03c0cc8ef15f561b47ef1c11b02e4f043634.tar.gz
dexon-8f3a03c0cc8ef15f561b47ef1c11b02e4f043634.tar.zst
dexon-8f3a03c0cc8ef15f561b47ef1c11b02e4f043634.zip
Update state tests to use gocheck
Diffstat (limited to 'state')
-rw-r--r--state/state_test.go45
1 files changed, 29 insertions, 16 deletions
diff --git a/state/state_test.go b/state/state_test.go
index 737815e90..b15233336 100644
--- a/state/state_test.go
+++ b/state/state_test.go
@@ -1,6 +1,7 @@
package state
import (
+ . "gopkg.in/check.v1"
"testing"
"github.com/ethereum/go-ethereum/ethdb"
@@ -8,29 +9,41 @@ import (
"github.com/ethereum/go-ethereum/trie"
)
-var ZeroHash256 = make([]byte, 32)
+func Test(t *testing.T) { TestingT(t) }
-func TestSnapshot(t *testing.T) {
+type StateSuite struct {
+ state *State
+}
+
+var _ = Suite(&StateSuite{})
+
+const expectedasbytes = "Expected % x Got % x"
+
+// var ZeroHash256 = make([]byte, 32)
+
+func (s *StateSuite) SetUpTest(c *C) {
db, _ := ethdb.NewMemDatabase()
ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
ethutil.Config.Db = db
+ s.state = New(trie.New(db, ""))
+}
- state := New(trie.New(db, ""))
-
- stateObject := state.GetOrNewStateObject([]byte("aa"))
-
- stateObject.SetStorage(ethutil.Big("0"), ethutil.NewValue(42))
+func (s *StateSuite) TestSnapshot(c *C) {
+ data1 := ethutil.NewValue(42)
+ data2 := ethutil.NewValue(43)
+ storageaddr := ethutil.Big("0")
+ stateobjaddr := []byte("aa")
- snapshot := state.Copy()
+ stateObject := s.state.GetOrNewStateObject(stateobjaddr)
+ stateObject.SetStorage(storageaddr, data1)
+ snapshot := s.state.Copy()
- stateObject = state.GetStateObject([]byte("aa"))
- stateObject.SetStorage(ethutil.Big("0"), ethutil.NewValue(43))
+ stateObject = s.state.GetStateObject(stateobjaddr)
+ stateObject.SetStorage(storageaddr, data2)
+ s.state.Set(snapshot)
- state.Set(snapshot)
+ stateObject = s.state.GetStateObject(stateobjaddr)
+ res := stateObject.GetStorage(storageaddr)
- stateObject = state.GetStateObject([]byte("aa"))
- res := stateObject.GetStorage(ethutil.Big("0"))
- if !res.Cmp(ethutil.NewValue(42)) {
- t.Error("Expected storage 0 to be 42", res)
- }
+ c.Assert(data1, DeepEquals, res, Commentf(expectedasbytes, data1, res))
}