mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-27 05:57:28 +00:00
Update state tests to use gocheck
This commit is contained in:
parent
0a3a148ed4
commit
8f3a03c0cc
@ -1,6 +1,7 @@
|
|||||||
package state
|
package state
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
. "gopkg.in/check.v1"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
@ -8,29 +9,41 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/trie"
|
"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()
|
db, _ := ethdb.NewMemDatabase()
|
||||||
ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
|
ethutil.ReadConfig(".ethtest", "/tmp/ethtest", "")
|
||||||
ethutil.Config.Db = db
|
ethutil.Config.Db = db
|
||||||
|
s.state = New(trie.New(db, ""))
|
||||||
state := New(trie.New(db, ""))
|
}
|
||||||
|
|
||||||
stateObject := state.GetOrNewStateObject([]byte("aa"))
|
func (s *StateSuite) TestSnapshot(c *C) {
|
||||||
|
data1 := ethutil.NewValue(42)
|
||||||
stateObject.SetStorage(ethutil.Big("0"), ethutil.NewValue(42))
|
data2 := ethutil.NewValue(43)
|
||||||
|
storageaddr := ethutil.Big("0")
|
||||||
snapshot := state.Copy()
|
stateobjaddr := []byte("aa")
|
||||||
|
|
||||||
stateObject = state.GetStateObject([]byte("aa"))
|
stateObject := s.state.GetOrNewStateObject(stateobjaddr)
|
||||||
stateObject.SetStorage(ethutil.Big("0"), ethutil.NewValue(43))
|
stateObject.SetStorage(storageaddr, data1)
|
||||||
|
snapshot := s.state.Copy()
|
||||||
state.Set(snapshot)
|
|
||||||
|
stateObject = s.state.GetStateObject(stateobjaddr)
|
||||||
stateObject = state.GetStateObject([]byte("aa"))
|
stateObject.SetStorage(storageaddr, data2)
|
||||||
res := stateObject.GetStorage(ethutil.Big("0"))
|
s.state.Set(snapshot)
|
||||||
if !res.Cmp(ethutil.NewValue(42)) {
|
|
||||||
t.Error("Expected storage 0 to be 42", res)
|
stateObject = s.state.GetStateObject(stateobjaddr)
|
||||||
}
|
res := stateObject.GetStorage(storageaddr)
|
||||||
|
|
||||||
|
c.Assert(data1, DeepEquals, res, Commentf(expectedasbytes, data1, res))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user