From 07d51f4122cb8c6b8b600acbbb5eb4b1c2767f73 Mon Sep 17 00:00:00 2001 From: Lior Bondarevski Date: Tue, 30 Aug 2022 17:09:22 +0300 Subject: [PATCH 1/3] Commented code --- .../keeper/testdata/ibc/src/contract.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/x/compute/internal/keeper/testdata/ibc/src/contract.rs b/x/compute/internal/keeper/testdata/ibc/src/contract.rs index fa827d2e6..3bf55f262 100644 --- a/x/compute/internal/keeper/testdata/ibc/src/contract.rs +++ b/x/compute/internal/keeper/testdata/ibc/src/contract.rs @@ -303,12 +303,12 @@ pub fn ibc_packet_ack( get_resp_based_on_num(env, msg.original_packet.sequence) } -// #[entry_point] -// pub fn ibc_packet_timeout( -// deps: DepsMut, -// env: Env, -// msg: IbcPacketTimeoutMsg, -// ) -> StdResult { -// count(deps.storage).save(&(msg.packet.sequence + 9))?; -// get_resp_based_on_num(env, msg.packet.sequence) -// } +#[entry_point] +pub fn ibc_packet_timeout( + deps: DepsMut, + env: Env, + msg: IbcPacketTimeoutMsg, +) -> StdResult { + count(deps.storage).save(&(msg.packet.sequence + 9))?; + get_resp_based_on_num(env, msg.packet.sequence) +} From 2888b8a04a9fff895533d73b9d0ff11e3b5a803a Mon Sep 17 00:00:00 2001 From: Itzik Date: Tue, 30 Aug 2022 18:10:13 +0300 Subject: [PATCH 2/3] Fix test setup --- x/compute/internal/keeper/test_common.go | 111 ++++++++++++++--------- 1 file changed, 70 insertions(+), 41 deletions(-) diff --git a/x/compute/internal/keeper/test_common.go b/x/compute/internal/keeper/test_common.go index 249e2a37d..386735766 100644 --- a/x/compute/internal/keeper/test_common.go +++ b/x/compute/internal/keeper/test_common.go @@ -15,7 +15,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/feegrant" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - icahosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types" ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host" ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper" @@ -188,27 +187,42 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc require.NoError(t, err) t.Cleanup(func() { os.RemoveAll(tempDir) }) - keyContract := sdk.NewKVStoreKey(wasmtypes.StoreKey) - keyAcc := sdk.NewKVStoreKey(authtypes.StoreKey) - keyStaking := sdk.NewKVStoreKey(stakingtypes.StoreKey) - keyDistro := sdk.NewKVStoreKey(distrtypes.StoreKey) - mintStore := sdk.NewKVStoreKey(minttypes.StoreKey) - keyParams := sdk.NewKVStoreKey(paramstypes.StoreKey) - tkeyParams := sdk.NewTransientStoreKey(paramstypes.TStoreKey) - keyGov := sdk.NewKVStoreKey(govtypes.StoreKey) - keyBank := sdk.NewKVStoreKey(banktypes.StoreKey) + //keyContract := sdk.NewKVStoreKey(wasmtypes.StoreKey) + //keyAcc := sdk.NewKVStoreKey(authtypes.StoreKey) + //keyStaking := sdk.NewKVStoreKey(stakingtypes.StoreKey) + //keyDistro := sdk.NewKVStoreKey(distrtypes.StoreKey) + //mintStore := sdk.NewKVStoreKey(minttypes.StoreKey) + //keyParams := sdk.NewKVStoreKey(paramstypes.StoreKey) + //tkeyParams := sdk.NewTransientStoreKey(paramstypes.TStoreKey) + //keyGov := sdk.NewKVStoreKey(govtypes.StoreKey) + //keyBank := sdk.NewKVStoreKey(banktypes.StoreKey) + + keys := sdk.NewKVStoreKeys( + authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, + minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, + govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, + evidencetypes.StoreKey, ibctransfertypes.StoreKey, + capabilitytypes.StoreKey, feegrant.StoreKey, authzkeeper.StoreKey, + wasmtypes.StoreKey, + ) db := dbm.NewMemDB() + ms := store.NewCommitMultiStore(db) - ms.MountStoreWithDB(keyContract, sdk.StoreTypeIAVL, db) - ms.MountStoreWithDB(keyAcc, sdk.StoreTypeIAVL, db) - ms.MountStoreWithDB(keyParams, sdk.StoreTypeIAVL, db) - ms.MountStoreWithDB(keyStaking, sdk.StoreTypeIAVL, db) - ms.MountStoreWithDB(mintStore, sdk.StoreTypeIAVL, db) - ms.MountStoreWithDB(keyDistro, sdk.StoreTypeIAVL, db) - ms.MountStoreWithDB(tkeyParams, sdk.StoreTypeTransient, db) - ms.MountStoreWithDB(keyGov, sdk.StoreTypeIAVL, db) - ms.MountStoreWithDB(keyBank, sdk.StoreTypeIAVL, db) + for _, v := range keys { + ms.MountStoreWithDB(v, sdk.StoreTypeIAVL, db) + } + + tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) + for _, v := range tkeys { + ms.MountStoreWithDB(v, sdk.StoreTypeTransient, db) + } + + memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) + for _, v := range memKeys { + ms.MountStoreWithDB(v, sdk.StoreTypeMemory, db) + } + require.NoError(t, ms.LoadLatestVersion()) ctx := sdk.NewContext(ms, tmproto.Header{ @@ -217,7 +231,12 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc ChainID: TestConfig.ChainID, }, isCheckTx, log.NewNopLogger()) encodingConfig := MakeEncodingConfig() - paramsKeeper := paramskeeper.NewKeeper(encodingConfig.Marshaler, encodingConfig.Amino, keyParams, tkeyParams) + paramsKeeper := paramskeeper.NewKeeper( + encodingConfig.Marshaler, + encodingConfig.Amino, + keys[paramstypes.StoreKey], + tkeys[paramstypes.TStoreKey], + ) paramsKeeper.Subspace(authtypes.ModuleName) paramsKeeper.Subspace(banktypes.ModuleName) paramsKeeper.Subspace(stakingtypes.ModuleName) @@ -240,7 +259,7 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc authSubsp, _ := paramsKeeper.GetSubspace(authtypes.ModuleName) authKeeper := authkeeper.NewAccountKeeper( encodingConfig.Marshaler, - keyAcc, // target store + keys[authtypes.StoreKey], // target store authSubsp, authtypes.ProtoBaseAccount, // prototype maccPerms, @@ -254,7 +273,7 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc bankSubsp, _ := paramsKeeper.GetSubspace(banktypes.ModuleName) bankKeeper := bankkeeper.NewBaseKeeper( encodingConfig.Marshaler, - keyBank, + keys[banktypes.StoreKey], authKeeper, bankSubsp, blockedAddrs, @@ -264,7 +283,13 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc bankKeeper.SetParams(ctx, banktypes.DefaultParams()) stakingSubsp, _ := paramsKeeper.GetSubspace(stakingtypes.ModuleName) - stakingKeeper := stakingkeeper.NewKeeper(encodingConfig.Marshaler, keyStaking, authKeeper, bankKeeper, stakingSubsp) + stakingKeeper := stakingkeeper.NewKeeper( + encodingConfig.Marshaler, + keys[stakingtypes.StoreKey], + authKeeper, + bankKeeper, + stakingSubsp, + ) stakingKeeper.SetParams(ctx, TestingStakeParams) // mintSubsp, _ := paramsKeeper.GetSubspace(minttypes.ModuleName) @@ -283,7 +308,7 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc distSubsp, _ := paramsKeeper.GetSubspace(distrtypes.ModuleName) distKeeper := distrkeeper.NewKeeper( encodingConfig.Marshaler, - keyDistro, + keys[distrtypes.StoreKey], distSubsp, authKeeper, bankKeeper, @@ -336,14 +361,14 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc // AddRoute(wasmtypes.RouterKey, NewWasmProposalHandler(keeper, wasmtypes.EnableAllProposals)) govKeeper := govkeeper.NewKeeper( - encodingConfig.Marshaler, keyGov, paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable()), authKeeper, bankKeeper, stakingKeeper, govRouter, + encodingConfig.Marshaler, keys[govtypes.StoreKey], paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable()), authKeeper, bankKeeper, stakingKeeper, govRouter, ) // bank := bankKeeper. // bk := bank.Keeper(bankKeeper) mintSubsp, _ := paramsKeeper.GetSubspace(minttypes.ModuleName) - mintKeeper := mintkeeper.NewKeeper(encodingConfig.Marshaler, mintStore, mintSubsp, stakingKeeper, authKeeper, bankKeeper, authtypes.FeeCollectorName) + mintKeeper := mintkeeper.NewKeeper(encodingConfig.Marshaler, keys[minttypes.StoreKey], mintSubsp, stakingKeeper, authKeeper, bankKeeper, authtypes.FeeCollectorName) mintKeeper.SetMinter(ctx, minttypes.DefaultInitialMinter()) // keeper := NewKeeper(cdc, keyContract, accountKeeper, &bk, &govKeeper, &distKeeper, &mintKeeper, &stakingKeeper, router, tempDir, wasmConfig, supportedFeatures, encoders, queriers) @@ -360,18 +385,17 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc // Load default wasm config wasmConfig := wasmtypes.DefaultWasmConfig() - keys := sdk.NewKVStoreKeys( - authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, - minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, - govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, - evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, "compute", - feegrant.StoreKey, authzkeeper.StoreKey, icahosttypes.StoreKey, - ) - - memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) - for _, v := range memKeys { - ms.MountStoreWithDB(v, sdk.StoreTypeMemory, db) - } + //keys := sdk.NewKVStoreKeys( + // authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, + // minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, + // govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, + // evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, "compute", + // feegrant.StoreKey, authzkeeper.StoreKey, icahosttypes.StoreKey, + //) + //memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) + //for _, v := range memKeys { + // ms.MountStoreWithDB(v, sdk.StoreTypeMemory, db) + //} upgradeKeeper := upgradekeeper.NewKeeper( map[int64]bool{}, @@ -388,11 +412,16 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc ) scopedIBCKeeper := capabilityKeeper.ScopeToModule(ibchost.ModuleName) - scopedWasmKeeper := capabilityKeeper.ScopeToModule("compute") + scopedWasmKeeper := capabilityKeeper.ScopeToModule(wasmtypes.ModuleName) ibchostSubSp, _ := paramsKeeper.GetSubspace(ibchost.ModuleName) ibcKeeper := ibckeeper.NewKeeper( - encodingConfig.Marshaler, keys[ibchost.StoreKey], ibchostSubSp, stakingKeeper, upgradeKeeper, scopedIBCKeeper, + encodingConfig.Marshaler, + keys[ibchost.StoreKey], + ibchostSubSp, + stakingKeeper, + upgradeKeeper, + scopedIBCKeeper, ) // todo: new grpc routing @@ -416,7 +445,7 @@ func CreateTestInput(t *testing.T, isCheckTx bool, supportedFeatures string, enc keeper := NewKeeper( encodingConfig.Marshaler, *encodingConfig.Amino, - keyContract, + keys[wasmtypes.StoreKey], authKeeper, bankKeeper, govKeeper, From b9312c197d31fcedf5f0fdd6dab6b845a7306aff Mon Sep 17 00:00:00 2001 From: Lior Bondarevski Date: Tue, 30 Aug 2022 18:39:21 +0300 Subject: [PATCH 3/3] Log with "code_id" when storing contract --- x/compute/internal/keeper/msg_server.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/x/compute/internal/keeper/msg_server.go b/x/compute/internal/keeper/msg_server.go index a74c07025..f5b73d4df 100644 --- a/x/compute/internal/keeper/msg_server.go +++ b/x/compute/internal/keeper/msg_server.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "fmt" sdk "github.com/cosmos/cosmos-sdk/types" @@ -21,14 +22,18 @@ func NewMsgServerImpl(k Keeper) types.MsgServer { func (m msgServer) StoreCode(goCtx context.Context, msg *types.MsgStoreCode) (*types.MsgStoreCodeResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) - ctx.EventManager().EmitEvent(sdk.NewEvent( - sdk.EventTypeMessage, - sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), - sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender.String()), - )) - codeID, err := m.keeper.Create(ctx, msg.Sender, msg.WASMByteCode, msg.Source, msg.Builder) + ctx.EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent( + sdk.EventTypeMessage, + sdk.NewAttribute(sdk.AttributeKeyModule, types.ModuleName), + sdk.NewAttribute(types.AttributeKeySigner, msg.Sender.String()), + sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender.String()), + sdk.NewAttribute(types.AttributeKeyCodeID, fmt.Sprintf("%d", codeID)), + ), + }) + return &types.MsgStoreCodeResponse{ CodeID: codeID, }, err