1
1
package state
2
2
3
3
import (
4
+ "math/big"
5
+
4
6
checker "gopkg.in/check.v1"
5
7
6
8
"github.com/ethereum/go-ethereum/ethdb"
@@ -16,11 +18,42 @@ var _ = checker.Suite(&StateSuite{})
16
18
// var ZeroHash256 = make([]byte, 32)
17
19
18
20
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:\n got: %s\n want: %s\n " , got , want )
56
+ }
24
57
}
25
58
26
59
func (s * StateSuite ) SetUpTest (c * checker.C ) {
0 commit comments