Skip to content

Commit 68c755a

Browse files
committed
core/state: fix TestDump
Lazy "I'll just put return here instead of fixing the test" found by go vet.
1 parent ebf3cf8 commit 68c755a

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

core/state/dump.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,19 @@ func (self *StateDB) RawDump() World {
4646
it := self.trie.Iterator()
4747
for it.Next() {
4848
addr := self.trie.GetKey(it.Key)
49-
stateObject, _ := DecodeObject(common.BytesToAddress(addr), self.db, it.Value)
50-
51-
account := Account{Balance: stateObject.balance.String(), Nonce: stateObject.nonce, Root: common.Bytes2Hex(stateObject.Root()), CodeHash: common.Bytes2Hex(stateObject.codeHash), Code: common.Bytes2Hex(stateObject.Code())}
52-
account.Storage = make(map[string]string)
49+
stateObject, err := DecodeObject(common.BytesToAddress(addr), self.db, it.Value)
50+
if err != nil {
51+
panic(err)
52+
}
5353

54+
account := Account{
55+
Balance: stateObject.balance.String(),
56+
Nonce: stateObject.nonce,
57+
Root: common.Bytes2Hex(stateObject.Root()),
58+
CodeHash: common.Bytes2Hex(stateObject.codeHash),
59+
Code: common.Bytes2Hex(stateObject.Code()),
60+
Storage: make(map[string]string),
61+
}
5462
storageIt := stateObject.trie.Iterator()
5563
for storageIt.Next() {
5664
account.Storage[common.Bytes2Hex(self.trie.GetKey(storageIt.Key))] = common.Bytes2Hex(storageIt.Value)

core/state/state_object.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func DecodeObject(address common.Address, db trie.Database, data []byte) (*State
287287
}
288288
if !bytes.Equal(ext.CodeHash, emptyCodeHash) {
289289
if obj.code, err = db.Get(ext.CodeHash); err != nil {
290-
return nil, fmt.Errorf("can't find code for hash %x: %v", ext.CodeHash, err)
290+
return nil, fmt.Errorf("can't get code for hash %x: %v", ext.CodeHash, err)
291291
}
292292
}
293293
obj.nonce = ext.Nonce

core/state/state_test.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ var _ = checker.Suite(&StateSuite{})
3636
var toAddr = common.BytesToAddress
3737

3838
func (s *StateSuite) TestDump(c *checker.C) {
39-
return
4039
// generate a few entries
4140
obj1 := s.state.GetOrNewStateObject(toAddr([]byte{0x01}))
4241
obj1.AddBalance(big.NewInt(22))
@@ -48,24 +47,35 @@ func (s *StateSuite) TestDump(c *checker.C) {
4847
// write some of them to the trie
4948
s.state.UpdateStateObject(obj1)
5049
s.state.UpdateStateObject(obj2)
50+
s.state.Commit()
5151

5252
// check that dump contains the state objects that are in trie
5353
got := string(s.state.Dump())
5454
want := `{
55-
"root": "6e277ae8357d013e50f74eedb66a991f6922f93ae03714de58b3d0c5e9eee53f",
55+
"root": "71edff0130dd2385947095001c73d9e28d862fc286fca2b922ca6f6f3cddfdd2",
5656
"accounts": {
57-
"1468288056310c82aa4c01a7e12a10f8111a0560e72b700555479031b86c357d": {
57+
"0000000000000000000000000000000000000001": {
5858
"balance": "22",
5959
"nonce": 0,
6060
"root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
6161
"codeHash": "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
62+
"code": "",
6263
"storage": {}
6364
},
64-
"a17eacbc25cda025e81db9c5c62868822c73ce097cee2a63e33a2e41268358a1": {
65+
"0000000000000000000000000000000000000002": {
66+
"balance": "44",
67+
"nonce": 0,
68+
"root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
69+
"codeHash": "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
70+
"code": "",
71+
"storage": {}
72+
},
73+
"0000000000000000000000000000000000000102": {
6574
"balance": "0",
6675
"nonce": 0,
6776
"root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
6877
"codeHash": "87874902497a5bb968da31a2998d8f22e949d1ef6214bcdedd8bae24cca4b9e3",
78+
"code": "03030303030303",
6979
"storage": {}
7080
}
7181
}

0 commit comments

Comments
 (0)