Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: mem keys is not tested in native action #363

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions x/evm/statedb/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -608,6 +609,7 @@ func (suite *StateDBTestSuite) TestNativeAction() {
_, ctx, keeper := setupTestEnv(suite.T())
storeKey := testStoreKeys["testnative"]
transientKey := testTransientKeys[evmtypes.TransientKey]
memKey := testMemKeys[capabilitytypes.MemStoreKey]

eventConverter := func(event sdk.Event) (*ethtypes.Log, error) {
converters := map[string]statedb.EventConverter{
Expand All @@ -633,7 +635,10 @@ func (suite *StateDBTestSuite) TestNativeAction() {
store.Set([]byte("success1"), []byte("value"))
ctx.EventManager().EmitEvent(sdk.NewEvent("success1"))

mem := ctx.KVStore(transientKey)
transient := ctx.KVStore(transientKey)
transient.Set([]byte("transient"), []byte("value"))

mem := ctx.KVStore(memKey)
mem.Set([]byte("mem"), []byte("value"))

return nil
Expand All @@ -643,7 +648,10 @@ func (suite *StateDBTestSuite) TestNativeAction() {
store.Set([]byte("failure1"), []byte("value"))
ctx.EventManager().EmitEvent(sdk.NewEvent("failure1"))

mem := ctx.KVStore(transientKey)
transient := ctx.KVStore(transientKey)
suite.Require().Equal([]byte("value"), transient.Get([]byte("transient")))

mem := ctx.KVStore(memKey)
suite.Require().Equal([]byte("value"), mem.Get([]byte("mem")))
return errors.New("failure")
})
Expand Down Expand Up @@ -751,6 +759,7 @@ func CollectContractStorage(db vm.StateDB, address common.Address) statedb.Stora
var (
testStoreKeys = sdk.NewKVStoreKeys(authtypes.StoreKey, banktypes.StoreKey, evmtypes.StoreKey, "testnative")
testTransientKeys = sdk.NewTransientStoreKeys(evmtypes.TransientKey)
testMemKeys = sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
)

func cloneRawState(t *testing.T, cms sdk.MultiStore) map[string]map[string][]byte {
Expand Down Expand Up @@ -791,13 +800,16 @@ func newTestKeeper(t *testing.T, cms sdk.MultiStore) (sdk.Context, *evmkeeper.Ke
map[string]bool{},
authAddr,
)
allKeys := make(map[string]storetypes.StoreKey, len(testStoreKeys)+len(testTransientKeys))
allKeys := make(map[string]storetypes.StoreKey, len(testStoreKeys)+len(testTransientKeys)+len(testMemKeys))
for k, v := range testStoreKeys {
allKeys[k] = v
}
for k, v := range testTransientKeys {
allKeys[k] = v
}
for k, v := range testMemKeys {
allKeys[k] = v
}
evmKeeper := evmkeeper.NewKeeper(
appCodec, testStoreKeys[evmtypes.StoreKey], testTransientKeys[evmtypes.TransientKey], authtypes.NewModuleAddress(govtypes.ModuleName),
accountKeeper, bankKeeper, nil, nil,
Expand All @@ -819,6 +831,9 @@ func setupTestEnv(t *testing.T) (sdk.MultiStore, sdk.Context, *evmkeeper.Keeper)
for _, key := range testTransientKeys {
cms.MountStoreWithDB(key, storetypes.StoreTypeTransient, nil)
}
for _, key := range testMemKeys {
cms.MountStoreWithDB(key, storetypes.StoreTypeMemory, nil)
}
require.NoError(t, cms.LoadLatestVersion())

ctx, keeper := newTestKeeper(t, cms)
Expand Down
Loading