|
|
@ -21,15 +21,12 @@ import ( |
|
|
|
"math/big" |
|
|
|
"math/big" |
|
|
|
"testing" |
|
|
|
"testing" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/core/rawdb" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/core/rawdb" |
|
|
|
"github.com/ethereum/go-ethereum/crypto" |
|
|
|
"github.com/ethereum/go-ethereum/crypto" |
|
|
|
"github.com/ethereum/go-ethereum/ethdb" |
|
|
|
"github.com/ethereum/go-ethereum/ethdb" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
var toAddr = common.BytesToAddress |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type stateTest struct { |
|
|
|
type stateTest struct { |
|
|
|
db ethdb.Database |
|
|
|
db ethdb.Database |
|
|
|
state *DB |
|
|
|
state *DB |
|
|
@ -45,11 +42,11 @@ func TestDump(t *testing.T) { |
|
|
|
s := newStateTest() |
|
|
|
s := newStateTest() |
|
|
|
|
|
|
|
|
|
|
|
// generate a few entries
|
|
|
|
// generate a few entries
|
|
|
|
obj1 := s.state.GetOrNewStateObject(toAddr([]byte{0x01})) |
|
|
|
obj1 := s.state.GetOrNewStateObject(common.BytesToAddress([]byte{0x01})) |
|
|
|
obj1.AddBalance(big.NewInt(22)) |
|
|
|
obj1.AddBalance(big.NewInt(22)) |
|
|
|
obj2 := s.state.GetOrNewStateObject(toAddr([]byte{0x01, 0x02})) |
|
|
|
obj2 := s.state.GetOrNewStateObject(common.BytesToAddress([]byte{0x01, 0x02})) |
|
|
|
obj2.SetCode(crypto.Keccak256Hash([]byte{3, 3, 3, 3, 3, 3, 3}), []byte{3, 3, 3, 3, 3, 3, 3}) |
|
|
|
obj2.SetCode(crypto.Keccak256Hash([]byte{3, 3, 3, 3, 3, 3, 3}), []byte{3, 3, 3, 3, 3, 3, 3}) |
|
|
|
obj3 := s.state.GetOrNewStateObject(toAddr([]byte{0x02})) |
|
|
|
obj3 := s.state.GetOrNewStateObject(common.BytesToAddress([]byte{0x02})) |
|
|
|
obj3.SetBalance(big.NewInt(44)) |
|
|
|
obj3.SetBalance(big.NewInt(44)) |
|
|
|
|
|
|
|
|
|
|
|
// write some of them to the trie
|
|
|
|
// write some of them to the trie
|
|
|
@ -57,34 +54,37 @@ func TestDump(t *testing.T) { |
|
|
|
s.state.updateStateObject(obj2) |
|
|
|
s.state.updateStateObject(obj2) |
|
|
|
s.state.Commit(false) |
|
|
|
s.state.Commit(false) |
|
|
|
|
|
|
|
|
|
|
|
// check that dump contains the state objects that are in trie
|
|
|
|
// check that DumpToCollector contains the state objects that are in trie
|
|
|
|
got := string(s.state.Dump(false, false, true)) |
|
|
|
got := string(s.state.Dump(nil)) |
|
|
|
want := `{ |
|
|
|
want := `{ |
|
|
|
"root": "71edff0130dd2385947095001c73d9e28d862fc286fca2b922ca6f6f3cddfdd2", |
|
|
|
"root": "71edff0130dd2385947095001c73d9e28d862fc286fca2b922ca6f6f3cddfdd2", |
|
|
|
"accounts": { |
|
|
|
"accounts": { |
|
|
|
"0x0000000000000000000000000000000000000001": { |
|
|
|
"0x0000000000000000000000000000000000000001": { |
|
|
|
"balance": "22", |
|
|
|
"balance": "22", |
|
|
|
"nonce": 0, |
|
|
|
"nonce": 0, |
|
|
|
"root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
|
|
|
"root": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
|
|
|
"codeHash": "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" |
|
|
|
"codeHash": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", |
|
|
|
|
|
|
|
"key": "0x1468288056310c82aa4c01a7e12a10f8111a0560e72b700555479031b86c357d" |
|
|
|
}, |
|
|
|
}, |
|
|
|
"0x0000000000000000000000000000000000000002": { |
|
|
|
"0x0000000000000000000000000000000000000002": { |
|
|
|
"balance": "44", |
|
|
|
"balance": "44", |
|
|
|
"nonce": 0, |
|
|
|
"nonce": 0, |
|
|
|
"root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
|
|
|
"root": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
|
|
|
"codeHash": "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" |
|
|
|
"codeHash": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", |
|
|
|
|
|
|
|
"key": "0xd52688a8f926c816ca1e079067caba944f158e764817b83fc43594370ca9cf62" |
|
|
|
}, |
|
|
|
}, |
|
|
|
"0x0000000000000000000000000000000000000102": { |
|
|
|
"0x0000000000000000000000000000000000000102": { |
|
|
|
"balance": "0", |
|
|
|
"balance": "0", |
|
|
|
"nonce": 0, |
|
|
|
"nonce": 0, |
|
|
|
"root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
|
|
|
"root": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
|
|
|
"codeHash": "87874902497a5bb968da31a2998d8f22e949d1ef6214bcdedd8bae24cca4b9e3", |
|
|
|
"codeHash": "0x87874902497a5bb968da31a2998d8f22e949d1ef6214bcdedd8bae24cca4b9e3", |
|
|
|
"code": "03030303030303" |
|
|
|
"code": "0x03030303030303", |
|
|
|
|
|
|
|
"key": "0xa17eacbc25cda025e81db9c5c62868822c73ce097cee2a63e33a2e41268358a1" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}` |
|
|
|
}` |
|
|
|
if got != want { |
|
|
|
if got != want { |
|
|
|
t.Errorf("dump mismatch:\ngot: %s\nwant: %s\n", got, want) |
|
|
|
t.Errorf("DumpToCollector mismatch:\ngot: %s\nwant: %s\n", got, want) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -107,7 +107,7 @@ func TestNull(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestSnapshot(t *testing.T) { |
|
|
|
func TestSnapshot(t *testing.T) { |
|
|
|
stateobjaddr := toAddr([]byte("aa")) |
|
|
|
stateobjaddr := common.BytesToAddress([]byte("aa")) |
|
|
|
var storageaddr common.Hash |
|
|
|
var storageaddr common.Hash |
|
|
|
data1 := common.BytesToHash([]byte{42}) |
|
|
|
data1 := common.BytesToHash([]byte{42}) |
|
|
|
data2 := common.BytesToHash([]byte{43}) |
|
|
|
data2 := common.BytesToHash([]byte{43}) |
|
|
@ -149,8 +149,8 @@ func TestSnapshotEmpty(t *testing.T) { |
|
|
|
func TestSnapshot2(t *testing.T) { |
|
|
|
func TestSnapshot2(t *testing.T) { |
|
|
|
state, _ := New(common.Hash{}, NewDatabase(rawdb.NewMemoryDatabase())) |
|
|
|
state, _ := New(common.Hash{}, NewDatabase(rawdb.NewMemoryDatabase())) |
|
|
|
|
|
|
|
|
|
|
|
stateobjaddr0 := toAddr([]byte("so0")) |
|
|
|
stateobjaddr0 := common.BytesToAddress([]byte("so0")) |
|
|
|
stateobjaddr1 := toAddr([]byte("so1")) |
|
|
|
stateobjaddr1 := common.BytesToAddress([]byte("so1")) |
|
|
|
var storageaddr common.Hash |
|
|
|
var storageaddr common.Hash |
|
|
|
|
|
|
|
|
|
|
|
data0 := common.BytesToHash([]byte{17}) |
|
|
|
data0 := common.BytesToHash([]byte{17}) |
|
|
|