Skip to content

Commit 01ce066

Browse files
committed
state: improve TestDump
1 parent 4ab7a29 commit 01ce066

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

state/state_test.go

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package state
22

33
import (
4+
"math/big"
5+
46
checker "gopkg.in/check.v1"
57

68
"github.com/ethereum/go-ethereum/ethdb"
@@ -16,11 +18,42 @@ var _ = checker.Suite(&StateSuite{})
1618
// var ZeroHash256 = make([]byte, 32)
1719

1820
func (s *StateSuite) TestDump(c *checker.C) {
19-
key := []byte{0x01}
20-
value := []byte("foo")
21-
s.state.trie.Update(key, value)
22-
dump := s.state.Dump()
23-
c.Assert(dump, checker.NotNil)
21+
// generate a few entries
22+
obj1 := s.state.GetOrNewStateObject([]byte{0x01})
23+
obj1.AddBalance(big.NewInt(22))
24+
obj2 := s.state.GetOrNewStateObject([]byte{0x01, 0x02})
25+
obj2.SetCode([]byte{3, 3, 3, 3, 3, 3, 3})
26+
obj3 := s.state.GetOrNewStateObject([]byte{0x02})
27+
obj3.SetBalance(big.NewInt(44))
28+
29+
// write some of them to the trie
30+
s.state.UpdateStateObject(obj1)
31+
s.state.UpdateStateObject(obj2)
32+
33+
// check that dump contains the state objects that are in trie
34+
got := string(s.state.Dump())
35+
want := `{
36+
"root": "4e3a59299745ba6752247c8b91d0f716dac9ec235861c91f5ac1894a361d87ba",
37+
"accounts": {
38+
"0000000000000000000000000000000000000001": {
39+
"balance": "22",
40+
"nonce": 0,
41+
"root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
42+
"codeHash": "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
43+
"storage": {}
44+
},
45+
"0000000000000000000000000000000000000102": {
46+
"balance": "0",
47+
"nonce": 0,
48+
"root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
49+
"codeHash": "87874902497a5bb968da31a2998d8f22e949d1ef6214bcdedd8bae24cca4b9e3",
50+
"storage": {}
51+
}
52+
}
53+
}`
54+
if got != want {
55+
c.Errorf("dump mismatch:\ngot: %s\nwant: %s\n", got, want)
56+
}
2457
}
2558

2659
func (s *StateSuite) SetUpTest(c *checker.C) {

0 commit comments

Comments
 (0)