update TODO in the code. remove old changes from the statedb unit tests

This commit is contained in:
Jared Wasinger 2025-10-20 18:02:41 +08:00
parent 068757faea
commit 2994e096c6
2 changed files with 16 additions and 18 deletions

View file

@ -175,10 +175,10 @@ func TestCopy(t *testing.T) {
orig.Finalise(false) orig.Finalise(false)
// Copy the state // Copy the state
copy := orig.Copy().(*StateDB) copy := orig.Copy()
// Copy the copy state // Copy the copy state
ccopy := copy.Copy().(*StateDB) ccopy := copy.Copy()
// modify all in memory // modify all in memory
for i := byte(0); i < 255; i++ { for i := byte(0); i < 255; i++ {
@ -191,7 +191,7 @@ func TestCopy(t *testing.T) {
ccopyObj.AddBalance(uint256.NewInt(4 * uint64(i))) ccopyObj.AddBalance(uint256.NewInt(4 * uint64(i)))
} }
// FinaliseIdxChanges the changes on all concurrently // Finalise the changes on all concurrently
finalise := func(wg *sync.WaitGroup, db *StateDB) { finalise := func(wg *sync.WaitGroup, db *StateDB) {
defer wg.Done() defer wg.Done()
db.Finalise(true) db.Finalise(true)
@ -243,7 +243,7 @@ func TestCopyWithDirtyJournal(t *testing.T) {
amount := uint256.NewInt(uint64(i)) amount := uint256.NewInt(uint64(i))
obj.SetBalance(new(uint256.Int).Sub(obj.Balance(), amount)) obj.SetBalance(new(uint256.Int).Sub(obj.Balance(), amount))
} }
cpy := orig.Copy().(*StateDB) cpy := orig.Copy()
orig.Finalise(true) orig.Finalise(true)
for i := byte(0); i < 255; i++ { for i := byte(0); i < 255; i++ {
@ -278,7 +278,7 @@ func TestCopyObjectState(t *testing.T) {
obj.data.Root = common.HexToHash("0xdeadbeef") obj.data.Root = common.HexToHash("0xdeadbeef")
} }
orig.Finalise(true) orig.Finalise(true)
cpy := orig.Copy().(*StateDB) cpy := orig.Copy()
for _, op := range cpy.mutations { for _, op := range cpy.mutations {
if have, want := op.applied, false; have != want { if have, want := op.applied, false; have != want {
t.Fatalf("Error in test itself, the 'done' flag should not be set before Commit, have %v want %v", have, want) t.Fatalf("Error in test itself, the 'done' flag should not be set before Commit, have %v want %v", have, want)
@ -528,7 +528,7 @@ func (test *snapshotTest) run() bool {
for i, action := range test.actions { for i, action := range test.actions {
if len(test.snapshots) > sindex && i == test.snapshots[sindex] { if len(test.snapshots) > sindex && i == test.snapshots[sindex] {
snapshotRevs[sindex] = state.Snapshot() snapshotRevs[sindex] = state.Snapshot()
checkstates[sindex] = state.Copy().(*StateDB) checkstates[sindex] = state.Copy()
sindex++ sindex++
} }
action.fn(action, state) action.fn(action, state)
@ -747,7 +747,7 @@ func TestCopyCommitCopy(t *testing.T) {
t.Fatalf("initial committed storage slot mismatch: have %x, want %x", val, common.Hash{}) t.Fatalf("initial committed storage slot mismatch: have %x, want %x", val, common.Hash{})
} }
// Copy the non-committed state database and check pre/post commit balance // Copy the non-committed state database and check pre/post commit balance
copyOne := state.Copy().(*StateDB) copyOne := state.Copy()
if balance := copyOne.GetBalance(addr); balance.Cmp(uint256.NewInt(42)) != 0 { if balance := copyOne.GetBalance(addr); balance.Cmp(uint256.NewInt(42)) != 0 {
t.Fatalf("first copy pre-commit balance mismatch: have %v, want %v", balance, 42) t.Fatalf("first copy pre-commit balance mismatch: have %v, want %v", balance, 42)
} }
@ -761,7 +761,7 @@ func TestCopyCommitCopy(t *testing.T) {
t.Fatalf("first copy pre-commit committed storage slot mismatch: have %x, want %x", val, common.Hash{}) t.Fatalf("first copy pre-commit committed storage slot mismatch: have %x, want %x", val, common.Hash{})
} }
// Copy the copy and check the balance once more // Copy the copy and check the balance once more
copyTwo := copyOne.Copy().(*StateDB) copyTwo := copyOne.Copy()
if balance := copyTwo.GetBalance(addr); balance.Cmp(uint256.NewInt(42)) != 0 { if balance := copyTwo.GetBalance(addr); balance.Cmp(uint256.NewInt(42)) != 0 {
t.Fatalf("second copy balance mismatch: have %v, want %v", balance, 42) t.Fatalf("second copy balance mismatch: have %v, want %v", balance, 42)
} }
@ -820,7 +820,7 @@ func TestCopyCopyCommitCopy(t *testing.T) {
t.Fatalf("initial committed storage slot mismatch: have %x, want %x", val, common.Hash{}) t.Fatalf("initial committed storage slot mismatch: have %x, want %x", val, common.Hash{})
} }
// Copy the non-committed state database and check pre/post commit balance // Copy the non-committed state database and check pre/post commit balance
copyOne := state.Copy().(*StateDB) copyOne := state.Copy()
if balance := copyOne.GetBalance(addr); balance.Cmp(uint256.NewInt(42)) != 0 { if balance := copyOne.GetBalance(addr); balance.Cmp(uint256.NewInt(42)) != 0 {
t.Fatalf("first copy balance mismatch: have %v, want %v", balance, 42) t.Fatalf("first copy balance mismatch: have %v, want %v", balance, 42)
} }
@ -834,7 +834,7 @@ func TestCopyCopyCommitCopy(t *testing.T) {
t.Fatalf("first copy committed storage slot mismatch: have %x, want %x", val, common.Hash{}) t.Fatalf("first copy committed storage slot mismatch: have %x, want %x", val, common.Hash{})
} }
// Copy the copy and check the balance once more // Copy the copy and check the balance once more
copyTwo := copyOne.Copy().(*StateDB) copyTwo := copyOne.Copy()
if balance := copyTwo.GetBalance(addr); balance.Cmp(uint256.NewInt(42)) != 0 { if balance := copyTwo.GetBalance(addr); balance.Cmp(uint256.NewInt(42)) != 0 {
t.Fatalf("second copy pre-commit balance mismatch: have %v, want %v", balance, 42) t.Fatalf("second copy pre-commit balance mismatch: have %v, want %v", balance, 42)
} }
@ -848,7 +848,7 @@ func TestCopyCopyCommitCopy(t *testing.T) {
t.Fatalf("second copy pre-commit committed storage slot mismatch: have %x, want %x", val, common.Hash{}) t.Fatalf("second copy pre-commit committed storage slot mismatch: have %x, want %x", val, common.Hash{})
} }
// Copy the copy-copy and check the balance once more // Copy the copy-copy and check the balance once more
copyThree := copyTwo.Copy().(*StateDB) copyThree := copyTwo.Copy()
if balance := copyThree.GetBalance(addr); balance.Cmp(uint256.NewInt(42)) != 0 { if balance := copyThree.GetBalance(addr); balance.Cmp(uint256.NewInt(42)) != 0 {
t.Fatalf("third copy balance mismatch: have %v, want %v", balance, 42) t.Fatalf("third copy balance mismatch: have %v, want %v", balance, 42)
} }
@ -896,7 +896,7 @@ func TestCommitCopy(t *testing.T) {
state.Commit(1, true, false) state.Commit(1, true, false)
// Copy the committed state database, the copied one is not fully functional. // Copy the committed state database, the copied one is not fully functional.
copied := state.Copy().(*StateDB) copied := state.Copy()
if balance := copied.GetBalance(addr); balance.Cmp(uint256.NewInt(42)) != 0 { if balance := copied.GetBalance(addr); balance.Cmp(uint256.NewInt(42)) != 0 {
t.Fatalf("unexpected balance: have %v", balance) t.Fatalf("unexpected balance: have %v", balance)
} }
@ -1098,7 +1098,7 @@ func TestStateDBAccessList(t *testing.T) {
verifySlots("bb", "01", "02") verifySlots("bb", "01", "02")
// Make a copy // Make a copy
stateCopy1 := state.Copy().(*StateDB) stateCopy1 := state.Copy()
if exp, got := 4, state.journal.length(); exp != got { if exp, got := 4, state.journal.length(); exp != got {
t.Fatalf("journal length mismatch: have %d, want %d", got, exp) t.Fatalf("journal length mismatch: have %d, want %d", got, exp)
} }

View file

@ -275,11 +275,9 @@ func (c *AccessListBuilder) FinaliseIdxChanges(idx uint16) {
} }
finalizedAcctChanges.StorageWrites[key][idx] = val finalizedAcctChanges.StorageWrites[key][idx] = val
// TODO: investigate why commenting out the check here, and the corresponding // TODO: commenting this 'if' results in no test failures.
// check under accesses causes GeneralStateTests blockchain tests to fail. // double-check that this edge-case was fixed by a future
// They should only contain one tx per test. // release of the eest BAL tests.
//
// key could have been read in a previous tx, delete it from the read set here
if _, ok := finalizedAcctChanges.StorageReads[key]; ok { if _, ok := finalizedAcctChanges.StorageReads[key]; ok {
delete(finalizedAcctChanges.StorageReads, key) delete(finalizedAcctChanges.StorageReads, key)
} }