Skip to content

Commit

Permalink
fix: use proper appmodule.Environment within suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Sep 16, 2024
1 parent cc155e7 commit 110016a
Show file tree
Hide file tree
Showing 18 changed files with 58 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (im IBCMiddleware) OnRecvPacket(
) ibcexported.Acknowledgement {
err := errorsmod.Wrapf(icatypes.ErrInvalidChannelFlow, "cannot receive packet on controller chain")
ack := channeltypes.NewErrorAcknowledgement(err)
keeper.EmitAcknowledgementEvent(ctx, packet, ack, err, im.keeper)
keeper.EmitAcknowledgementEvent(ctx, packet, ack, err, im.keeper.Environment)
return ack
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper_test

import (
"cosmossdk.io/core/appmodule"
"github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/keeper"
"github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/types"
genesistypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/genesis/types"
Expand All @@ -14,10 +13,6 @@ import (
func (suite *KeeperTestSuite) TestInitGenesis() {
ports := []string{"port1", "port2", "port3"}

env := appmodule.Environment{
Logger: suite.chainA.GetSimApp().Logger(),
}

testCases := []struct {
name string
malleate func()
Expand All @@ -35,7 +30,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() {
},
}

interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), env, ibctesting.FirstConnectionID, TestPortID)
interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), suite.chainB.GetSimApp().ICAControllerKeeper.Environment, ibctesting.FirstConnectionID, TestPortID)
genesisState := genesistypes.ControllerGenesisState{
ActiveChannels: []genesistypes.ActiveChannel{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (

testifysuite "github.com/stretchr/testify/suite"

"cosmossdk.io/core/appmodule"
govtypes "cosmossdk.io/x/gov/types"
"github.com/cosmos/cosmos-sdk/runtime"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

"github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/keeper"
Expand Down Expand Up @@ -111,11 +109,6 @@ func TestKeeperTestSuite(t *testing.T) {
}

func (suite *KeeperTestSuite) TestNewKeeper() {
env := appmodule.Environment{
Logger: suite.chainA.GetSimApp().Logger(),
KVStoreService: runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)),
}

testCases := []struct {
name string
instantiateFn func()
Expand All @@ -124,7 +117,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
{"success", func() {
keeper.NewKeeper(
suite.chainA.GetSimApp().AppCodec(),
env,
suite.chainA.GetSimApp().ICAControllerKeeper.Environment,
suite.chainA.GetSimApp().GetSubspace(types.SubModuleName),
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
Expand All @@ -137,7 +130,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
{"failure: empty authority", func() {
keeper.NewKeeper(
suite.chainA.GetSimApp().AppCodec(),
env,
suite.chainA.GetSimApp().ICAControllerKeeper.Environment,
suite.chainA.GetSimApp().GetSubspace(types.SubModuleName),
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package keeper_test
import (
"fmt"

"github.com/cosmos/cosmos-sdk/runtime"

icacontrollerkeeper "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/types"
)
Expand All @@ -29,7 +27,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() {
func() {
suite.chainA.GetSimApp().ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
suite.chainA.Codec,
runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(icacontrollertypes.StoreKey)),
suite.chainA.GetSimApp().ICAControllerKeeper.Environment,
nil, // assign a nil legacy param subspace
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/stretchr/testify/require"

"cosmossdk.io/core/registry"
banktypes "cosmossdk.io/x/bank/types"
stakingtypes "cosmossdk.io/x/staking/types"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -46,15 +47,15 @@ func TestGeneratePacketData(t *testing.T) {
memo string
expectedPass bool
message string
registerInterfaceFn func(registry codectypes.InterfaceRegistry)
registerInterfaceFn func(registry registry.InterfaceRegistrar)
assertionFn func(t *testing.T, msgs []sdk.Msg)
}{
{
name: "packet data generation succeeds (MsgDelegate & MsgSend)",
memo: "",
expectedPass: true,
message: multiMsg,
registerInterfaceFn: func(registry codectypes.InterfaceRegistry) {
registerInterfaceFn: func(registry registry.InterfaceRegistrar) {
stakingtypes.RegisterInterfaces(registry)
banktypes.RegisterInterfaces(registry)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() {
},
{
"account address generation is block dependent", func() {
icaHostAccount := icatypes.GenerateAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID)
icaHostAccount := icatypes.GenerateAddress(suite.chainB.GetContext(), suite.chainB.GetSimApp().ICAHostKeeper.Environment, path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID)
err := suite.chainB.GetSimApp().BankKeeper.SendCoins(suite.chainB.GetContext(), suite.chainB.SenderAccount.GetAddress(), icaHostAccount, sdk.Coins{sdk.NewCoin("stake", sdkmath.NewInt(1))})
suite.Require().NoError(err)
suite.Require().True(suite.chainB.GetSimApp().AccountKeeper.HasAccount(suite.chainB.GetContext(), icaHostAccount))
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/27-interchain-accounts/host/keeper/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// and block dependent information. An error is returned if an account already exists for the generated account.
// An interchain account type is set in the account keeper and the interchain account address mapping is updated.
func (k Keeper) createInterchainAccount(ctx context.Context, connectionID, controllerPortID string) (sdk.AccAddress, error) {
accAddress := icatypes.GenerateAddress(ctx, connectionID, controllerPortID)
accAddress := icatypes.GenerateAddress(ctx, k.Environment, connectionID, controllerPortID)

if acc := k.accountKeeper.GetAccount(ctx, accAddress); acc != nil {
return nil, errorsmod.Wrapf(icatypes.ErrAccountAlreadyExist, "existing account for newly generated interchain account address %s", accAddress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func (suite *KeeperTestSuite) TestInitGenesis() {
interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, TestPortID)
interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), suite.chainB.GetSimApp().ICAHostKeeper.Environment, ibctesting.FirstConnectionID, TestPortID)
genesisState := genesistypes.HostGenesisState{
ActiveChannels: []genesistypes.ActiveChannel{
{
Expand Down Expand Up @@ -65,7 +65,7 @@ func (suite *KeeperTestSuite) TestGenesisParams() {

suite.Run(tc.name, func() {
suite.SetupTest() // reset
interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, TestPortID)
interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), suite.chainB.GetSimApp().ICAHostKeeper.Environment, ibctesting.FirstConnectionID, TestPortID)
genesisState := genesistypes.HostGenesisState{
ActiveChannels: []genesistypes.ActiveChannel{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() {
{
"account already exists",
func() {
interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID)
interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), suite.chainB.GetSimApp().ICAHostKeeper.Environment, path.EndpointB.ConnectionID, path.EndpointA.ChannelConfig.PortID)
err := suite.chainB.GetSimApp().BankKeeper.SendCoins(suite.chainB.GetContext(), suite.chainB.SenderAccount.GetAddress(), interchainAccAddr, sdk.Coins{sdk.NewCoin("stake", sdkmath.NewInt(1))})
suite.Require().NoError(err)
suite.Require().True(suite.chainB.GetSimApp().AccountKeeper.HasAccount(suite.chainB.GetContext(), interchainAccAddr))
Expand Down
13 changes: 3 additions & 10 deletions modules/apps/27-interchain-accounts/host/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import (
"fmt"
"testing"

"cosmossdk.io/core/appmodule"
testifysuite "github.com/stretchr/testify/suite"

"github.com/cosmos/cosmos-sdk/runtime"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"

genesistypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/genesis/types"
Expand Down Expand Up @@ -135,11 +133,6 @@ func TestKeeperTestSuite(t *testing.T) {
}

func (suite *KeeperTestSuite) TestNewKeeper() {
env := appmodule.Environment{
Logger: suite.chainA.GetSimApp().Logger(),
KVStoreService: runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(types.StoreKey)),
}

testCases := []struct {
name string
instantiateFn func()
Expand All @@ -148,7 +141,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
{"success", func() {
keeper.NewKeeper(
suite.chainA.GetSimApp().AppCodec(),
env,
suite.chainA.GetSimApp().ICAHostKeeper.Environment,
suite.chainA.GetSimApp().GetSubspace(types.SubModuleName),
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
Expand All @@ -163,7 +156,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
{"failure: interchain accounts module account does not exist", func() {
keeper.NewKeeper(
suite.chainA.GetSimApp().AppCodec(),
env,
suite.chainA.GetSimApp().ICAHostKeeper.Environment,
suite.chainA.GetSimApp().GetSubspace(types.SubModuleName),
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
Expand All @@ -178,7 +171,7 @@ func (suite *KeeperTestSuite) TestNewKeeper() {
{"failure: empty mock staking keeper", func() {
keeper.NewKeeper(
suite.chainA.GetSimApp().AppCodec(),
env,
suite.chainA.GetSimApp().ICAHostKeeper.Environment,
suite.chainA.GetSimApp().GetSubspace(types.SubModuleName),
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

govtypes "cosmossdk.io/x/gov/types"
"github.com/cosmos/cosmos-sdk/runtime"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

icahostkeeper "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/host/keeper"
Expand All @@ -31,7 +30,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() {
func() {
suite.chainA.GetSimApp().ICAHostKeeper = icahostkeeper.NewKeeper(
suite.chainA.Codec,
runtime.NewKVStoreService(suite.chainA.GetSimApp().GetKey(icahosttypes.StoreKey)),
suite.chainA.GetSimApp().ICAHostKeeper.Environment,
nil, // assign a nil legacy param subspace
suite.chainA.GetSimApp().IBCFeeKeeper,
suite.chainA.GetSimApp().IBCKeeper.ChannelKeeper,
Expand Down
8 changes: 4 additions & 4 deletions modules/apps/27-interchain-accounts/host/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ func (k Keeper) authenticateTx(ctx context.Context, msgs []sdk.Msg, connectionID
// Attempts to get the message handler from the router and if found will then execute the message.
// If the message execution is successful, the proto marshaled message response will be returned.
func (k Keeper) executeMsg(ctx context.Context, env appmodule.Environment, msg sdk.Msg) (*codectypes.Any, error) { // TODO: https://github.com/cosmos/ibc-go/issues/7223
handler := env.MsgRouterService.CanInvoke(ctx, msg)
if handler == nil {
return nil, icatypes.ErrInvalidRoute
}
// handler := env.MsgRouterService.CanInvoke(ctx, msg)
// if handler == nil {
// return nil, icatypes.ErrInvalidRoute
// }

res, err := env.MsgRouterService.Invoke(ctx, msg)
if err != nil {
Expand Down
20 changes: 11 additions & 9 deletions modules/apps/27-interchain-accounts/simulation/proposals.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package simulation

import (
"context"
"math/rand"

"cosmossdk.io/core/address"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/simulation"

controllerkeeper "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/controller/keeper"
Expand All @@ -25,14 +27,14 @@ const (
func ProposalMsgs(controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkeeper.Keeper) []simtypes.WeightedProposalMsg {
msgs := make([]simtypes.WeightedProposalMsg, 0, 2)
if hostKeeper != nil {
msgs = append(msgs, simulation.NewWeightedProposalMsg(
msgs = append(msgs, simulation.NewWeightedProposalMsgX(
OpWeightMsgUpdateParams,
DefaultWeightMsgUpdateParams,
SimulateHostMsgUpdateParams,
))
}
if controllerKeeper != nil {
msgs = append(msgs, simulation.NewWeightedProposalMsg(
msgs = append(msgs, simulation.NewWeightedProposalMsgX(
OpWeightMsgUpdateParams,
DefaultWeightMsgUpdateParams,
SimulateControllerMsgUpdateParams,
Expand All @@ -42,25 +44,25 @@ func ProposalMsgs(controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkee
}

// SimulateHostMsgUpdateParams returns a MsgUpdateParams for the host module
func SimulateHostMsgUpdateParams(_ *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg {
var signer sdk.AccAddress = address.Module("gov")
func SimulateHostMsgUpdateParams(_ context.Context, r *rand.Rand, _ []simtypes.Account, _ address.Codec) (sdk.Msg, error) {
var signer sdk.AccAddress = authtypes.NewModuleAddress("gov")
params := types.DefaultParams()
params.HostEnabled = false

return &types.MsgUpdateParams{
Signer: signer.String(),
Params: params,
}
}, nil
}

// SimulateControllerMsgUpdateParams returns a MsgUpdateParams for the controller module
func SimulateControllerMsgUpdateParams(_ *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg {
var signer sdk.AccAddress = address.Module("gov")
func SimulateControllerMsgUpdateParams(_ context.Context, r *rand.Rand, _ []simtypes.Account, _ address.Codec) (sdk.Msg, error) {
var signer sdk.AccAddress = authtypes.NewModuleAddress("gov")
params := controllertypes.DefaultParams()
params.ControllerEnabled = false

return &controllertypes.MsgUpdateParams{
Signer: signer.String(),
Params: params,
}
}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ func TestProposalMsgs(t *testing.T) {
require.Equal(t, simulation.OpWeightMsgUpdateParams, weightedMsg.AppParamsKey())
require.Equal(t, simulation.DefaultWeightMsgUpdateParams, weightedMsg.DefaultWeight())

msg := weightedMsg.MsgSimulatorFn()(r, ctx, accounts)
msg, err := weightedMsg.MsgSimulatorFn()(ctx, r, accounts, nil) // TODO: codec
require.NoError(t, err)

if msgUpdateHostParams, ok := msg.(*hosttypes.MsgUpdateParams); ok {
require.Equal(t, tc.expMsgs[idx], msgUpdateHostParams)
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/27-interchain-accounts/types/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestTypesTestSuite(t *testing.T) {
}

func (suite *TypesTestSuite) TestGenerateAddress() {
addr := types.GenerateAddress(suite.chainA.GetContext(), "test-connection-id", "test-port-id")
addr := types.GenerateAddress(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAHostKeeper.Environment, "test-connection-id", "test-port-id")
accAddr, err := sdk.AccAddressFromBech32(addr.String())

suite.Require().NoError(err, "TestGenerateAddress failed")
Expand Down
4 changes: 2 additions & 2 deletions modules/core/02-client/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func BeginBlocker(ctx context.Context, k *keeper.Keeper) {
hi := k.HeaderService.HeaderInfo(ctx)
if err == nil && hi.Height == plan.Height-1 {
upgradedConsState := &ibctm.ConsensusState{
Timestamp: hi.Time,
NextValidatorsHash: hi.NextValidatorsHash, //TODO: need to pass the consensus modules blocked on https://github.com/cosmos/cosmos-sdk/pull/21480
Timestamp: hi.Time,
// NextValidatorsHash: hi.NextValidatorsHash, //TODO: need to pass the consensus modules blocked on https://github.com/cosmos/cosmos-sdk/pull/21480
}
bz := types.MustMarshalConsensusState(k.Codec(), upgradedConsState)

Expand Down
23 changes: 18 additions & 5 deletions modules/core/04-channel/types/acknowledgement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (

errorsmod "cosmossdk.io/errors"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

abci "github.com/cometbft/cometbft/api/cometbft/abci/v1"
cmtstate "github.com/cometbft/cometbft/state"

Expand Down Expand Up @@ -107,13 +105,13 @@ func (suite *TypesTestSuite) TestABCICodeDeterminism() {
// different ABCI error code used
errDifferentABCICode := ibcerrors.ErrNotFound

deliverTx := sdkerrors.ResponseExecTxResultWithEvents(err, gasUsed, gasWanted, []abci.Event{}, false)
deliverTx := responseExecTxResultWithEvents(err, gasUsed, gasWanted, []abci.Event{}, false)
execTxResults := []*abci.ExecTxResult{deliverTx}

deliverTxSameABCICode := sdkerrors.ResponseExecTxResultWithEvents(errSameABCICode, gasUsed, gasWanted, []abci.Event{}, false)
deliverTxSameABCICode := responseExecTxResultWithEvents(errSameABCICode, gasUsed, gasWanted, []abci.Event{}, false)
resultsSameABCICode := []*abci.ExecTxResult{deliverTxSameABCICode}

deliverTxDifferentABCICode := sdkerrors.ResponseExecTxResultWithEvents(errDifferentABCICode, gasUsed, gasWanted, []abci.Event{}, false)
deliverTxDifferentABCICode := responseExecTxResultWithEvents(errDifferentABCICode, gasUsed, gasWanted, []abci.Event{}, false)
resultsDifferentABCICode := []*abci.ExecTxResult{deliverTxDifferentABCICode}

hash := cmtstate.TxResultsHash(execTxResults)
Expand All @@ -124,6 +122,21 @@ func (suite *TypesTestSuite) TestABCICodeDeterminism() {
suite.Require().NotEqual(hash, hashDifferentABCICode)
}

// cosmos-sdk/baseapp/errors.go @ 01c0e9ba35818be56428483222b79f6d9cfaa105
// responseExecTxResultWithEvents returns an ABCI ExecTxResult object with fields
// filled in from the given error, gas values and events.
func responseExecTxResultWithEvents(err error, gw, gu uint64, events []abci.Event, debug bool) *abci.ExecTxResult {
space, code, log := errorsmod.ABCIInfo(err, debug)
return &abci.ExecTxResult{
Codespace: space,
Code: code,
Log: log,
GasWanted: int64(gw),
GasUsed: int64(gu),
Events: events,
}
}

// TestAcknowledgementError will verify that only a constant string and
// ABCI error code are used in constructing the acknowledgement error string
func (suite *TypesTestSuite) TestAcknowledgementError() {
Expand Down
Loading

0 comments on commit 110016a

Please sign in to comment.