Skip to content

Commit

Permalink
Remove ForEachStorage test, clear docs
Browse files Browse the repository at this point in the history
  • Loading branch information
drklee3 committed Apr 26, 2024
1 parent 2c29bb1 commit aa5aa5f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
5 changes: 2 additions & 3 deletions x/evm/statedb/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ func (s *StateDB) Empty(addr common.Address) bool {

// GetBalance retrieves the balance from the given address or 0 if object not found
func (s *StateDB) GetBalance(addr common.Address) *big.Int {
// TODO: This should use the active ctx balance

stateObject := s.getStateObject(addr)
if stateObject != nil {
return stateObject.Balance()
Expand Down Expand Up @@ -297,7 +295,8 @@ func (s *StateDB) ForEachStorage(addr common.Address, cb func(key, value common.
return nil
}

// TODO: InitialCtx or CurrentCtx? Neither will include new keys
// Note: ForEachStorage is not used by geth and is removed in later versions.
// InitialCtx vs CurrentCtx is undetermined and neither includes new keys.
s.keeper.ForEachStorage(s.ctx.CurrentCtx(), addr, func(key, value common.Hash) bool {
if value, dirty := so.dirtyStorage[key]; dirty {
return cb(key, value)
Expand Down
26 changes: 4 additions & 22 deletions x/evm/statedb/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,24 +155,6 @@ func (suite *HybridStateDBTestSuite) TestForEachStorage_Committed() {
suite.Require().Equal(common.BytesToHash([]byte("key")), keys[0], "expected key to be found")
}

func (suite *HybridStateDBTestSuite) TestForEachStorage_Dirty() {
suite.T().Skip("TODO: identify if ForEachStorage should return new keys")

db := statedb.New(suite.Ctx, suite.App.EvmKeeper, emptyTxConfig)
// Set some storage
db.SetState(address, common.BytesToHash([]byte("key")), common.BytesToHash([]byte("value")))

// Iterate over storage
var keys []common.Hash
db.ForEachStorage(address, func(key, value common.Hash) bool {
keys = append(keys, key)
return false
})

suite.Require().Len(keys, 1, "expected 1 key")
suite.Require().Equal(common.BytesToHash([]byte("key")), keys[0], "expected key to be found")
}

func (suite *HybridStateDBTestSuite) TestAccount() {
key1 := common.BigToHash(big.NewInt(1))
value1 := common.BigToHash(big.NewInt(2))
Expand All @@ -183,8 +165,8 @@ func (suite *HybridStateDBTestSuite) TestAccount() {
malleate func(*statedb.StateDB)
}{
{"non-exist account", func(db *statedb.StateDB) {
suite.Require().Equal(false, db.Exist(address))
suite.Require().Equal(true, db.Empty(address))
suite.Require().False(db.Exist(address))
suite.Require().True(db.Empty(address))
suite.Require().Equal(big.NewInt(0), db.GetBalance(address))
suite.Require().Equal([]byte(nil), db.GetCode(address))
suite.Require().Equal(common.Hash{}, db.GetCodeHash(address))
Expand All @@ -211,8 +193,8 @@ func (suite *HybridStateDBTestSuite) TestAccount() {
suite.Require().Empty(states)

db = statedb.New(suite.Ctx, keeper, emptyTxConfig)
suite.Require().Equal(true, db.Exist(address))
suite.Require().Equal(true, db.Empty(address))
suite.Require().True(db.Exist(address))
suite.Require().True(db.Empty(address))
suite.Require().Equal(big.NewInt(0), db.GetBalance(address))
suite.Require().Equal([]byte(nil), db.GetCode(address))
suite.Require().Equal(common.BytesToHash(emptyCodeHash), db.GetCodeHash(address))
Expand Down

0 comments on commit aa5aa5f

Please sign in to comment.