|
|
|
@ -31,7 +31,10 @@ import ( |
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
|
"github.com/ethereum/go-ethereum/core/rawdb" |
|
|
|
|
"github.com/ethereum/go-ethereum/core/state/snapshot" |
|
|
|
|
"github.com/ethereum/go-ethereum/core/types" |
|
|
|
|
"github.com/ethereum/go-ethereum/crypto" |
|
|
|
|
"github.com/ethereum/go-ethereum/trie" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// Tests that updating a state trie does not leak any database writes prior to
|
|
|
|
@ -998,3 +1001,37 @@ func TestStateDBTransientStorage(t *testing.T) { |
|
|
|
|
t.Fatalf("transient storage mismatch: have %x, want %x", got, value) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func TestResetObject(t *testing.T) { |
|
|
|
|
var ( |
|
|
|
|
disk = rawdb.NewMemoryDatabase() |
|
|
|
|
tdb = trie.NewDatabase(disk) |
|
|
|
|
db = NewDatabaseWithNodeDB(disk, tdb) |
|
|
|
|
snaps, _ = snapshot.New(snapshot.Config{CacheSize: 10}, disk, tdb, types.EmptyRootHash) |
|
|
|
|
state, _ = New(types.EmptyRootHash, db, snaps) |
|
|
|
|
addr = common.HexToAddress("0x1") |
|
|
|
|
slotA = common.HexToHash("0x1") |
|
|
|
|
slotB = common.HexToHash("0x2") |
|
|
|
|
) |
|
|
|
|
// Initialize account with balance and storage in first transaction.
|
|
|
|
|
state.SetBalance(addr, big.NewInt(1)) |
|
|
|
|
state.SetState(addr, slotA, common.BytesToHash([]byte{0x1})) |
|
|
|
|
state.IntermediateRoot(true) |
|
|
|
|
|
|
|
|
|
// Reset account and mutate balance and storages
|
|
|
|
|
state.CreateAccount(addr) |
|
|
|
|
state.SetBalance(addr, big.NewInt(2)) |
|
|
|
|
state.SetState(addr, slotB, common.BytesToHash([]byte{0x2})) |
|
|
|
|
root, _ := state.Commit(true) |
|
|
|
|
|
|
|
|
|
// Ensure the original account is wiped properly
|
|
|
|
|
snap := snaps.Snapshot(root) |
|
|
|
|
slot, _ := snap.Storage(crypto.Keccak256Hash(addr.Bytes()), crypto.Keccak256Hash(slotA.Bytes())) |
|
|
|
|
if len(slot) != 0 { |
|
|
|
|
t.Fatalf("Unexpected storage slot") |
|
|
|
|
} |
|
|
|
|
slot, _ = snap.Storage(crypto.Keccak256Hash(addr.Bytes()), crypto.Keccak256Hash(slotB.Bytes())) |
|
|
|
|
if !bytes.Equal(slot, []byte{0x2}) { |
|
|
|
|
t.Fatalf("Unexpected storage slot value %v", slot) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|