|
|
@ -49,14 +49,14 @@ func TestGeneration(t *testing.T) { |
|
|
|
// a fake one manually. We're going with a small account trie of 3 accounts,
|
|
|
|
// a fake one manually. We're going with a small account trie of 3 accounts,
|
|
|
|
// two of which also has the same 3-slot storage trie attached.
|
|
|
|
// two of which also has the same 3-slot storage trie attached.
|
|
|
|
var helper = newHelper() |
|
|
|
var helper = newHelper() |
|
|
|
stRoot := helper.makeStorageTrie(common.Hash{}, common.Hash{}, []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, false) |
|
|
|
stRoot := helper.makeStorageTrie(common.Hash{}, []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, false) |
|
|
|
|
|
|
|
|
|
|
|
helper.addTrieAccount("acc-1", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-1", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-2", &Account{Balance: big.NewInt(2), Root: types.EmptyRootHash.Bytes(), CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-2", &Account{Balance: big.NewInt(2), Root: types.EmptyRootHash.Bytes(), CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-3", &Account{Balance: big.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-3", &Account{Balance: big.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
|
|
|
|
|
|
|
|
helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
|
|
|
|
|
|
|
|
root, snap := helper.CommitAndGenerate() |
|
|
|
root, snap := helper.CommitAndGenerate() |
|
|
|
if have, want := root, common.HexToHash("0xe3712f1a226f3782caca78ca770ccc19ee000552813a9f59d479f8611db9b1fd"); have != want { |
|
|
|
if have, want := root, common.HexToHash("0xe3712f1a226f3782caca78ca770ccc19ee000552813a9f59d479f8611db9b1fd"); have != want { |
|
|
@ -84,7 +84,7 @@ func TestGenerateExistentState(t *testing.T) { |
|
|
|
// two of which also has the same 3-slot storage trie attached.
|
|
|
|
// two of which also has the same 3-slot storage trie attached.
|
|
|
|
var helper = newHelper() |
|
|
|
var helper = newHelper() |
|
|
|
|
|
|
|
|
|
|
|
stRoot := helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addTrieAccount("acc-1", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-1", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapAccount("acc-1", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapAccount("acc-1", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}) |
|
|
@ -92,7 +92,7 @@ func TestGenerateExistentState(t *testing.T) { |
|
|
|
helper.addTrieAccount("acc-2", &Account{Balance: big.NewInt(2), Root: types.EmptyRootHash.Bytes(), CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-2", &Account{Balance: big.NewInt(2), Root: types.EmptyRootHash.Bytes(), CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapAccount("acc-2", &Account{Balance: big.NewInt(2), Root: types.EmptyRootHash.Bytes(), CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapAccount("acc-2", &Account{Balance: big.NewInt(2), Root: types.EmptyRootHash.Bytes(), CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
|
|
|
|
|
|
|
|
stRoot = helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot = helper.makeStorageTrie(hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addTrieAccount("acc-3", &Account{Balance: big.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-3", &Account{Balance: big.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapAccount("acc-3", &Account{Balance: big.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapAccount("acc-3", &Account{Balance: big.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-3", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-3", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}) |
|
|
@ -151,7 +151,7 @@ type testHelper struct { |
|
|
|
func newHelper() *testHelper { |
|
|
|
func newHelper() *testHelper { |
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
diskdb := rawdb.NewMemoryDatabase() |
|
|
|
triedb := trie.NewDatabase(diskdb) |
|
|
|
triedb := trie.NewDatabase(diskdb) |
|
|
|
accTrie, _ := trie.NewStateTrie(trie.StateTrieID(common.Hash{}), triedb) |
|
|
|
accTrie, _ := trie.NewStateTrie(trie.StateTrieID(types.EmptyRootHash), triedb) |
|
|
|
return &testHelper{ |
|
|
|
return &testHelper{ |
|
|
|
diskdb: diskdb, |
|
|
|
diskdb: diskdb, |
|
|
|
triedb: triedb, |
|
|
|
triedb: triedb, |
|
|
@ -183,8 +183,8 @@ func (t *testHelper) addSnapStorage(accKey string, keys []string, vals []string) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (t *testHelper) makeStorageTrie(stateRoot, owner common.Hash, keys []string, vals []string, commit bool) []byte { |
|
|
|
func (t *testHelper) makeStorageTrie(owner common.Hash, keys []string, vals []string, commit bool) []byte { |
|
|
|
id := trie.StorageTrieID(stateRoot, owner, common.Hash{}) |
|
|
|
id := trie.StorageTrieID(types.EmptyRootHash, owner, types.EmptyRootHash) |
|
|
|
stTrie, _ := trie.NewStateTrie(id, t.triedb) |
|
|
|
stTrie, _ := trie.NewStateTrie(id, t.triedb) |
|
|
|
for i, k := range keys { |
|
|
|
for i, k := range keys { |
|
|
|
stTrie.MustUpdate([]byte(k), []byte(vals[i])) |
|
|
|
stTrie.MustUpdate([]byte(k), []byte(vals[i])) |
|
|
@ -241,23 +241,23 @@ func TestGenerateExistentStateWithWrongStorage(t *testing.T) { |
|
|
|
helper.addSnapStorage("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}) |
|
|
|
|
|
|
|
|
|
|
|
// Account two, non empty root but empty database
|
|
|
|
// Account two, non empty root but empty database
|
|
|
|
stRoot := helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-2")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-2")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-2", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-2", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
|
|
|
|
|
|
|
|
// Miss slots
|
|
|
|
// Miss slots
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// Account three, non empty root but misses slots in the beginning
|
|
|
|
// Account three, non empty root but misses slots in the beginning
|
|
|
|
helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-3", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-3", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-3", []string{"key-2", "key-3"}, []string{"val-2", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-3", []string{"key-2", "key-3"}, []string{"val-2", "val-3"}) |
|
|
|
|
|
|
|
|
|
|
|
// Account four, non empty root but misses slots in the middle
|
|
|
|
// Account four, non empty root but misses slots in the middle
|
|
|
|
helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-4")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-4")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-4", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-4", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-4", []string{"key-1", "key-3"}, []string{"val-1", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-4", []string{"key-1", "key-3"}, []string{"val-1", "val-3"}) |
|
|
|
|
|
|
|
|
|
|
|
// Account five, non empty root but misses slots in the end
|
|
|
|
// Account five, non empty root but misses slots in the end
|
|
|
|
helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-5")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-5")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-5", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-5", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-5", []string{"key-1", "key-2"}, []string{"val-1", "val-2"}) |
|
|
|
helper.addSnapStorage("acc-5", []string{"key-1", "key-2"}, []string{"val-1", "val-2"}) |
|
|
|
} |
|
|
|
} |
|
|
@ -265,22 +265,22 @@ func TestGenerateExistentStateWithWrongStorage(t *testing.T) { |
|
|
|
// Wrong storage slots
|
|
|
|
// Wrong storage slots
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// Account six, non empty root but wrong slots in the beginning
|
|
|
|
// Account six, non empty root but wrong slots in the beginning
|
|
|
|
helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-6")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-6")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-6", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-6", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-6", []string{"key-1", "key-2", "key-3"}, []string{"badval-1", "val-2", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-6", []string{"key-1", "key-2", "key-3"}, []string{"badval-1", "val-2", "val-3"}) |
|
|
|
|
|
|
|
|
|
|
|
// Account seven, non empty root but wrong slots in the middle
|
|
|
|
// Account seven, non empty root but wrong slots in the middle
|
|
|
|
helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-7")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-7")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-7", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-7", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-7", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "badval-2", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-7", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "badval-2", "val-3"}) |
|
|
|
|
|
|
|
|
|
|
|
// Account eight, non empty root but wrong slots in the end
|
|
|
|
// Account eight, non empty root but wrong slots in the end
|
|
|
|
helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-8")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-8")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-8", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-8", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-8", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "badval-3"}) |
|
|
|
helper.addSnapStorage("acc-8", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "badval-3"}) |
|
|
|
|
|
|
|
|
|
|
|
// Account 9, non empty root but rotated slots
|
|
|
|
// Account 9, non empty root but rotated slots
|
|
|
|
helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-9")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-9")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-9", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-9", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-9", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-3", "val-2"}) |
|
|
|
helper.addSnapStorage("acc-9", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-3", "val-2"}) |
|
|
|
} |
|
|
|
} |
|
|
@ -288,17 +288,17 @@ func TestGenerateExistentStateWithWrongStorage(t *testing.T) { |
|
|
|
// Extra storage slots
|
|
|
|
// Extra storage slots
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// Account 10, non empty root but extra slots in the beginning
|
|
|
|
// Account 10, non empty root but extra slots in the beginning
|
|
|
|
helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-10")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-10")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-10", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-10", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-10", []string{"key-0", "key-1", "key-2", "key-3"}, []string{"val-0", "val-1", "val-2", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-10", []string{"key-0", "key-1", "key-2", "key-3"}, []string{"val-0", "val-1", "val-2", "val-3"}) |
|
|
|
|
|
|
|
|
|
|
|
// Account 11, non empty root but extra slots in the middle
|
|
|
|
// Account 11, non empty root but extra slots in the middle
|
|
|
|
helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-11")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-11")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-11", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-11", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-11", []string{"key-1", "key-2", "key-2-1", "key-3"}, []string{"val-1", "val-2", "val-2-1", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-11", []string{"key-1", "key-2", "key-2-1", "key-3"}, []string{"val-1", "val-2", "val-2-1", "val-3"}) |
|
|
|
|
|
|
|
|
|
|
|
// Account 12, non empty root but extra slots in the end
|
|
|
|
// Account 12, non empty root but extra slots in the end
|
|
|
|
helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-12")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-12")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-12", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-12", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addSnapStorage("acc-12", []string{"key-1", "key-2", "key-3", "key-4"}, []string{"val-1", "val-2", "val-3", "val-4"}) |
|
|
|
helper.addSnapStorage("acc-12", []string{"key-1", "key-2", "key-3", "key-4"}, []string{"val-1", "val-2", "val-3", "val-4"}) |
|
|
|
} |
|
|
|
} |
|
|
@ -328,11 +328,11 @@ func TestGenerateExistentStateWithWrongStorage(t *testing.T) { |
|
|
|
func TestGenerateExistentStateWithWrongAccounts(t *testing.T) { |
|
|
|
func TestGenerateExistentStateWithWrongAccounts(t *testing.T) { |
|
|
|
helper := newHelper() |
|
|
|
helper := newHelper() |
|
|
|
|
|
|
|
|
|
|
|
helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-2")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-2")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-4")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-4")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot := helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-6")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-6")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
|
|
|
|
|
|
|
|
// Trie accounts [acc-1, acc-2, acc-3, acc-4, acc-6]
|
|
|
|
// Trie accounts [acc-1, acc-2, acc-3, acc-4, acc-6]
|
|
|
|
// Extra accounts [acc-0, acc-5, acc-7]
|
|
|
|
// Extra accounts [acc-0, acc-5, acc-7]
|
|
|
@ -420,10 +420,10 @@ func TestGenerateMissingStorageTrie(t *testing.T) { |
|
|
|
// two of which also has the same 3-slot storage trie attached.
|
|
|
|
// two of which also has the same 3-slot storage trie attached.
|
|
|
|
helper := newHelper() |
|
|
|
helper := newHelper() |
|
|
|
|
|
|
|
|
|
|
|
stRoot := helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) // 0xddefcd9376dd029653ef384bd2f0a126bb755fe84fdcc9e7cf421ba454f2bc67
|
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) // 0xddefcd9376dd029653ef384bd2f0a126bb755fe84fdcc9e7cf421ba454f2bc67
|
|
|
|
helper.addTrieAccount("acc-1", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x9250573b9c18c664139f3b6a7a8081b7d8f8916a8fcc5d94feec6c29f5fd4e9e
|
|
|
|
helper.addTrieAccount("acc-1", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x9250573b9c18c664139f3b6a7a8081b7d8f8916a8fcc5d94feec6c29f5fd4e9e
|
|
|
|
helper.addTrieAccount("acc-2", &Account{Balance: big.NewInt(2), Root: types.EmptyRootHash.Bytes(), CodeHash: types.EmptyCodeHash.Bytes()}) // 0x65145f923027566669a1ae5ccac66f945b55ff6eaeb17d2ea8e048b7d381f2d7
|
|
|
|
helper.addTrieAccount("acc-2", &Account{Balance: big.NewInt(2), Root: types.EmptyRootHash.Bytes(), CodeHash: types.EmptyCodeHash.Bytes()}) // 0x65145f923027566669a1ae5ccac66f945b55ff6eaeb17d2ea8e048b7d381f2d7
|
|
|
|
stRoot = helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot = helper.makeStorageTrie(hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addTrieAccount("acc-3", &Account{Balance: big.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x50815097425d000edfc8b3a4a13e175fc2bdcfee8bdfbf2d1ff61041d3c235b2
|
|
|
|
helper.addTrieAccount("acc-3", &Account{Balance: big.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x50815097425d000edfc8b3a4a13e175fc2bdcfee8bdfbf2d1ff61041d3c235b2
|
|
|
|
|
|
|
|
|
|
|
|
root := helper.Commit() |
|
|
|
root := helper.Commit() |
|
|
@ -454,10 +454,10 @@ func TestGenerateCorruptStorageTrie(t *testing.T) { |
|
|
|
// two of which also has the same 3-slot storage trie attached.
|
|
|
|
// two of which also has the same 3-slot storage trie attached.
|
|
|
|
helper := newHelper() |
|
|
|
helper := newHelper() |
|
|
|
|
|
|
|
|
|
|
|
stRoot := helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) // 0xddefcd9376dd029653ef384bd2f0a126bb755fe84fdcc9e7cf421ba454f2bc67
|
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) // 0xddefcd9376dd029653ef384bd2f0a126bb755fe84fdcc9e7cf421ba454f2bc67
|
|
|
|
helper.addTrieAccount("acc-1", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x9250573b9c18c664139f3b6a7a8081b7d8f8916a8fcc5d94feec6c29f5fd4e9e
|
|
|
|
helper.addTrieAccount("acc-1", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x9250573b9c18c664139f3b6a7a8081b7d8f8916a8fcc5d94feec6c29f5fd4e9e
|
|
|
|
helper.addTrieAccount("acc-2", &Account{Balance: big.NewInt(2), Root: types.EmptyRootHash.Bytes(), CodeHash: types.EmptyCodeHash.Bytes()}) // 0x65145f923027566669a1ae5ccac66f945b55ff6eaeb17d2ea8e048b7d381f2d7
|
|
|
|
helper.addTrieAccount("acc-2", &Account{Balance: big.NewInt(2), Root: types.EmptyRootHash.Bytes(), CodeHash: types.EmptyCodeHash.Bytes()}) // 0x65145f923027566669a1ae5ccac66f945b55ff6eaeb17d2ea8e048b7d381f2d7
|
|
|
|
stRoot = helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot = helper.makeStorageTrie(hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addTrieAccount("acc-3", &Account{Balance: big.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x50815097425d000edfc8b3a4a13e175fc2bdcfee8bdfbf2d1ff61041d3c235b2
|
|
|
|
helper.addTrieAccount("acc-3", &Account{Balance: big.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) // 0x50815097425d000edfc8b3a4a13e175fc2bdcfee8bdfbf2d1ff61041d3c235b2
|
|
|
|
|
|
|
|
|
|
|
|
root := helper.Commit() |
|
|
|
root := helper.Commit() |
|
|
@ -485,7 +485,7 @@ func TestGenerateWithExtraAccounts(t *testing.T) { |
|
|
|
helper := newHelper() |
|
|
|
helper := newHelper() |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Account one in the trie
|
|
|
|
// Account one in the trie
|
|
|
|
stRoot := helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-1")), |
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-1")), |
|
|
|
[]string{"key-1", "key-2", "key-3", "key-4", "key-5"}, |
|
|
|
[]string{"key-1", "key-2", "key-3", "key-4", "key-5"}, |
|
|
|
[]string{"val-1", "val-2", "val-3", "val-4", "val-5"}, |
|
|
|
[]string{"val-1", "val-2", "val-3", "val-4", "val-5"}, |
|
|
|
true, |
|
|
|
true, |
|
|
@ -505,7 +505,7 @@ func TestGenerateWithExtraAccounts(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Account two exists only in the snapshot
|
|
|
|
// Account two exists only in the snapshot
|
|
|
|
stRoot := helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-2")), |
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-2")), |
|
|
|
[]string{"key-1", "key-2", "key-3", "key-4", "key-5"}, |
|
|
|
[]string{"key-1", "key-2", "key-3", "key-4", "key-5"}, |
|
|
|
[]string{"val-1", "val-2", "val-3", "val-4", "val-5"}, |
|
|
|
[]string{"val-1", "val-2", "val-3", "val-4", "val-5"}, |
|
|
|
true, |
|
|
|
true, |
|
|
@ -556,7 +556,7 @@ func TestGenerateWithManyExtraAccounts(t *testing.T) { |
|
|
|
helper := newHelper() |
|
|
|
helper := newHelper() |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Account one in the trie
|
|
|
|
// Account one in the trie
|
|
|
|
stRoot := helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-1")), |
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-1")), |
|
|
|
[]string{"key-1", "key-2", "key-3"}, |
|
|
|
[]string{"key-1", "key-2", "key-3"}, |
|
|
|
[]string{"val-1", "val-2", "val-3"}, |
|
|
|
[]string{"val-1", "val-2", "val-3"}, |
|
|
|
true, |
|
|
|
true, |
|
|
@ -686,7 +686,7 @@ func TestGenerateFromEmptySnap(t *testing.T) { |
|
|
|
helper := newHelper() |
|
|
|
helper := newHelper() |
|
|
|
// Add 1K accounts to the trie
|
|
|
|
// Add 1K accounts to the trie
|
|
|
|
for i := 0; i < 400; i++ { |
|
|
|
for i := 0; i < 400; i++ { |
|
|
|
stRoot := helper.makeStorageTrie(common.Hash{}, hashData([]byte(fmt.Sprintf("acc-%d", i))), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte(fmt.Sprintf("acc-%d", i))), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addTrieAccount(fmt.Sprintf("acc-%d", i), |
|
|
|
helper.addTrieAccount(fmt.Sprintf("acc-%d", i), |
|
|
|
&Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
&Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
} |
|
|
|
} |
|
|
@ -724,7 +724,7 @@ func TestGenerateWithIncompleteStorage(t *testing.T) { |
|
|
|
// on the sensitive spots at the boundaries
|
|
|
|
// on the sensitive spots at the boundaries
|
|
|
|
for i := 0; i < 8; i++ { |
|
|
|
for i := 0; i < 8; i++ { |
|
|
|
accKey := fmt.Sprintf("acc-%d", i) |
|
|
|
accKey := fmt.Sprintf("acc-%d", i) |
|
|
|
stRoot := helper.makeStorageTrie(common.Hash{}, hashData([]byte(accKey)), stKeys, stVals, true) |
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte(accKey)), stKeys, stVals, true) |
|
|
|
helper.addAccount(accKey, &Account{Balance: big.NewInt(int64(i)), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount(accKey, &Account{Balance: big.NewInt(int64(i)), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
var moddedKeys []string |
|
|
|
var moddedKeys []string |
|
|
|
var moddedVals []string |
|
|
|
var moddedVals []string |
|
|
@ -816,11 +816,11 @@ func populateDangling(disk ethdb.KeyValueStore) { |
|
|
|
func TestGenerateCompleteSnapshotWithDanglingStorage(t *testing.T) { |
|
|
|
func TestGenerateCompleteSnapshotWithDanglingStorage(t *testing.T) { |
|
|
|
var helper = newHelper() |
|
|
|
var helper = newHelper() |
|
|
|
|
|
|
|
|
|
|
|
stRoot := helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-1", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-1", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-2", &Account{Balance: big.NewInt(1), Root: types.EmptyRootHash.Bytes(), CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-2", &Account{Balance: big.NewInt(1), Root: types.EmptyRootHash.Bytes(), CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
|
|
|
|
|
|
|
|
helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addAccount("acc-3", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addAccount("acc-3", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
|
|
|
|
|
|
|
|
helper.addSnapStorage("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}) |
|
|
|
helper.addSnapStorage("acc-1", []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}) |
|
|
@ -851,11 +851,11 @@ func TestGenerateCompleteSnapshotWithDanglingStorage(t *testing.T) { |
|
|
|
func TestGenerateBrokenSnapshotWithDanglingStorage(t *testing.T) { |
|
|
|
func TestGenerateBrokenSnapshotWithDanglingStorage(t *testing.T) { |
|
|
|
var helper = newHelper() |
|
|
|
var helper = newHelper() |
|
|
|
|
|
|
|
|
|
|
|
stRoot := helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
stRoot := helper.makeStorageTrie(hashData([]byte("acc-1")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addTrieAccount("acc-1", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-1", &Account{Balance: big.NewInt(1), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-2", &Account{Balance: big.NewInt(2), Root: types.EmptyRootHash.Bytes(), CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-2", &Account{Balance: big.NewInt(2), Root: types.EmptyRootHash.Bytes(), CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
|
|
|
|
|
|
|
|
helper.makeStorageTrie(common.Hash{}, hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.makeStorageTrie(hashData([]byte("acc-3")), []string{"key-1", "key-2", "key-3"}, []string{"val-1", "val-2", "val-3"}, true) |
|
|
|
helper.addTrieAccount("acc-3", &Account{Balance: big.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
helper.addTrieAccount("acc-3", &Account{Balance: big.NewInt(3), Root: stRoot, CodeHash: types.EmptyCodeHash.Bytes()}) |
|
|
|
|
|
|
|
|
|
|
|
populateDangling(helper.diskdb) |
|
|
|
populateDangling(helper.diskdb) |
|
|
|