Skip to content

Commit

Permalink
Merge pull request #1099 from scrtlabs/lior-ibc-tests
Browse files Browse the repository at this point in the history
Lior ibc tests
  • Loading branch information
liorbond authored Aug 30, 2022
2 parents 819352f + b9312c1 commit 30a4318
Showing 3 changed files with 90 additions and 56 deletions.
17 changes: 11 additions & 6 deletions x/compute/internal/keeper/msg_server.go
Original file line number Diff line number Diff line change
@@ -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
111 changes: 70 additions & 41 deletions x/compute/internal/keeper/test_common.go
Original file line number Diff line number Diff line change
@@ -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,
18 changes: 9 additions & 9 deletions x/compute/internal/keeper/testdata/ibc/src/contract.rs
Original file line number Diff line number Diff line change
@@ -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<IbcBasicResponse> {
// 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<IbcBasicResponse> {
count(deps.storage).save(&(msg.packet.sequence + 9))?;
get_resp_based_on_num(env, msg.packet.sequence)
}

0 comments on commit 30a4318

Please sign in to comment.