Skip to content

Commit

Permalink
fix all errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tac0turtle committed Sep 8, 2024
1 parent a0bf113 commit 5a331ed
Show file tree
Hide file tree
Showing 22 changed files with 181 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

"github.com/cosmos/ibc-go/v9/internal/logging"
icatypes "github.com/cosmos/ibc-go/v9/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
Expand Down Expand Up @@ -84,12 +83,6 @@ func (k Keeper) registerInterchainAccount(ctx context.Context, connectionID, por
return "", err
}

events := sdkCtx.EventManager().Events()
k.Logger(ctx).Debug("emitting interchain account registration events", logging.SdkEventsToLogArguments(events))

// NOTE: The sdk msg handler creates a new EventManager, so events must be correctly propagated back to the current context
sdkCtx.EventManager().EmitEvents(events)

firstMsgResponse := res.MsgResponses[0]
channelOpenInitResponse, ok := firstMsgResponse.GetCachedValue().(*channeltypes.MsgChannelOpenInitResponse)
if !ok {
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
14 changes: 8 additions & 6 deletions modules/apps/27-interchain-accounts/simulation/proposals.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package simulation

import (
"context"
"math/rand"

coreaddress "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"
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 {
func SimulateHostMsgUpdateParams(ctx context.Context, _ *rand.Rand, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) {
var signer sdk.AccAddress = address.Module("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 {
func SimulateControllerMsgUpdateParams(ctx context.Context, _ *rand.Rand, _ []simtypes.Account, _ coreaddress.Codec) (sdk.Msg, error) {
var signer sdk.AccAddress = address.Module("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)
require.NoError(t, err)

if msgUpdateHostParams, ok := msg.(*hosttypes.MsgUpdateParams); ok {
require.Equal(t, tc.expMsgs[idx], msgUpdateHostParams)
Expand Down
36 changes: 18 additions & 18 deletions modules/apps/29-fee/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"

Expand All @@ -23,18 +22,18 @@ import (
)

var (
_ module.AppModule = (*AppModule)(nil)
_ module.AppModuleBasic = (*AppModuleBasic)(nil)
_ module.AppModuleSimulation = (*AppModule)(nil)
_ module.HasGenesis = (*AppModule)(nil)
_ module.HasName = (*AppModule)(nil)
_ module.HasConsensusVersion = (*AppModule)(nil)
_ module.HasServices = (*AppModule)(nil)
_ appmodule.AppModule = (*AppModule)(nil)
_ module.AppModule = (*AppModule)(nil)
_ module.AppModuleSimulation = (*AppModule)(nil)
_ module.HasGenesis = (*AppModule)(nil)
_ appmodule.HasConsensusVersion = (*AppModule)(nil)
_ module.HasServices = (*AppModule)(nil)
_ appmodule.AppModule = (*AppModule)(nil)
)

// AppModuleBasic is the 29-fee AppModuleBasic
type AppModuleBasic struct{}
type AppModuleBasic struct {
cdc codec.Codec
}

// Name implements AppModuleBasic interface
func (AppModuleBasic) Name() string {
Expand All @@ -59,14 +58,14 @@ func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry)

// DefaultGenesis returns default genesis state as raw bytes for the ibc
// 29-fee module.
func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(types.DefaultGenesisState())
func (am AppModuleBasic) DefaultGenesis() json.RawMessage {
return am.cdc.MustMarshalJSON(types.DefaultGenesisState())
}

// ValidateGenesis performs genesis state validation for the 29-fee module.
func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error {
func (am AppModuleBasic) ValidateGenesis(bz json.RawMessage) error {
var gs types.GenesisState
if err := cdc.UnmarshalJSON(bz, &gs); err != nil {
if err := am.cdc.UnmarshalJSON(bz, &gs); err != nil {
return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err)
}

Expand Down Expand Up @@ -117,17 +116,18 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {

// InitGenesis performs genesis initialization for the ibc-29-fee module. It returns
// no validator updates.
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) {
func (am AppModule) InitGenesis(ctx context.Context, data json.RawMessage) error {
var genesisState types.GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
am.cdc.MustUnmarshalJSON(data, &genesisState)
am.keeper.InitGenesis(ctx, genesisState)
return nil
}

// ExportGenesis returns the exported genesis state as raw bytes for the ibc-29-fee
// module.
func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage {
func (am AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error) {
gs := am.keeper.ExportGenesis(ctx)
return cdc.MustMarshalJSON(gs)
return am.cdc.MarshalJSON(gs)
}

// ConsensusVersion implements AppModule/ConsensusVersion.
Expand Down
8 changes: 4 additions & 4 deletions modules/apps/29-fee/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestRegisterPayeeGetSigners(t *testing.T) {
msg := types.NewMsgRegisterPayee(ibctesting.MockPort, ibctesting.FirstChannelID, accAddress.String(), defaultAccAddress)

encodingCfg := moduletestutil.MakeTestEncodingConfig(testutil.CodecOptions{}, modulefee.AppModule{})
signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg)
signers, _, err := encodingCfg.Codec.GetMsgSigners(msg)
require.NoError(t, err)
require.Equal(t, accAddress.Bytes(), signers[0])
}
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestRegisterCountepartyAddressGetSigners(t *testing.T) {
msg := types.NewMsgRegisterCounterpartyPayee(ibctesting.MockPort, ibctesting.FirstChannelID, accAddress.String(), defaultAccAddress)

encodingCfg := moduletestutil.MakeTestEncodingConfig(testutil.CodecOptions{}, modulefee.AppModule{})
signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg)
signers, _, err := encodingCfg.Codec.GetMsgSigners(msg)
require.NoError(t, err)
require.Equal(t, accAddress.Bytes(), signers[0])
}
Expand Down Expand Up @@ -265,7 +265,7 @@ func TestPayPacketFeeGetSigners(t *testing.T) {
msg := types.NewMsgPayPacketFee(fee, ibctesting.MockFeePort, ibctesting.FirstChannelID, refundAddr.String(), nil)

encodingCfg := moduletestutil.MakeTestEncodingConfig(testutil.CodecOptions{}, modulefee.AppModule{})
signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg)
signers, _, err := encodingCfg.Codec.GetMsgSigners(msg)
require.NoError(t, err)
require.Equal(t, refundAddr.Bytes(), signers[0])
}
Expand Down Expand Up @@ -404,7 +404,7 @@ func TestPayPacketFeeAsyncGetSigners(t *testing.T) {
msg := types.NewMsgPayPacketFeeAsync(packetID, packetFee)

encodingCfg := moduletestutil.MakeTestEncodingConfig(testutil.CodecOptions{}, modulefee.AppModule{})
signers, _, err := encodingCfg.Codec.GetMsgV1Signers(msg)
signers, _, err := encodingCfg.Codec.GetMsgSigners(msg)
require.NoError(t, err)
require.Equal(t, refundAddr.Bytes(), signers[0])
}
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/forwarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (k Keeper) revertForwardedPacket(ctx context.Context, forwardedPacket chann
// given that the packet is being reversed, we check the DestinationChannel and DestinationPort
// of the forwardedPacket to see if a hop was added to the trace during the receive step
if token.Denom.HasPrefix(forwardedPacket.DestinationPort, forwardedPacket.DestinationChannel) {
if err := k.bankKeeper.BurnCoins(ctx, types.ModuleName, sdk.NewCoins(coin)); err != nil {
if err := k.bankKeeper.BurnCoins(ctx, forwardingAddr, sdk.NewCoins(coin)); err != nil {
return err
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions modules/apps/transfer/keeper/genesis.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"context"

"github.com/cosmos/ibc-go/v9/modules/apps/transfer/types"
)

// InitGenesis initializes the ibc-transfer state and binds to PortID.
func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) {
func (k Keeper) InitGenesis(ctx context.Context, state types.GenesisState) {
k.SetPort(ctx, state.PortId)

for _, denom := range state.Denoms {
Expand All @@ -31,7 +31,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) {
}

// ExportGenesis exports ibc-transfer module's portID and denom trace info into its genesis state.
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
func (k Keeper) ExportGenesis(ctx context.Context) *types.GenesisState {
return &types.GenesisState{
PortId: k.GetPort(ctx),
Denoms: k.GetAllDenoms(ctx),
Expand Down
22 changes: 13 additions & 9 deletions modules/apps/transfer/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (

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

"cosmossdk.io/math"
sdkmath "cosmossdk.io/math"
storetypes "cosmossdk.io/store/types"

minttypes "cosmossdk.io/x/mint/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
Expand Down Expand Up @@ -192,7 +192,6 @@ func (suite *KeeperTestSuite) TestSetGetTotalEscrowForDenom() {
func (suite *KeeperTestSuite) TestGetAllDenomEscrows() {
var (
store storetypes.KVStore
cdc codec.Codec
expDenomEscrows sdk.Coins
)

Expand All @@ -208,7 +207,8 @@ func (suite *KeeperTestSuite) TestGetAllDenomEscrows() {
amount := sdkmath.NewInt(100)
expDenomEscrows = append(expDenomEscrows, sdk.NewCoin(denom, amount))

bz := cdc.MustMarshal(&sdk.IntProto{Int: amount})
bz, err := math.Int(amount).Marshal()
suite.Require().NoError(err)
store.Set(types.TotalEscrowForDenomKey(denom), bz)
},
true,
Expand All @@ -220,14 +220,16 @@ func (suite *KeeperTestSuite) TestGetAllDenomEscrows() {
amount := sdkmath.NewInt(100)
expDenomEscrows = append(expDenomEscrows, sdk.NewCoin(denom, amount))

bz := cdc.MustMarshal(&sdk.IntProto{Int: amount})
bz, err := math.Int(amount).Marshal()
suite.Require().NoError(err)
store.Set(types.TotalEscrowForDenomKey(denom), bz)

denom = "bar/foo"
amount = sdkmath.NewInt(50)
expDenomEscrows = append(expDenomEscrows, sdk.NewCoin(denom, amount))

bz = cdc.MustMarshal(&sdk.IntProto{Int: amount})
bz, err = math.Int(amount).Marshal()
suite.Require().NoError(err)
store.Set(types.TotalEscrowForDenomKey(denom), bz)
},
true,
Expand All @@ -239,7 +241,8 @@ func (suite *KeeperTestSuite) TestGetAllDenomEscrows() {
amount := sdkmath.NewInt(100)
expDenomEscrows = append(expDenomEscrows, sdk.NewCoin(denom, amount))

bz := cdc.MustMarshal(&sdk.IntProto{Int: amount})
bz, err := math.Int(amount).Marshal()
suite.Require().NoError(err)
store.Set(types.TotalEscrowForDenomKey(denom), bz)
},
true,
Expand All @@ -250,7 +253,8 @@ func (suite *KeeperTestSuite) TestGetAllDenomEscrows() {
denom := ""
amount := sdkmath.ZeroInt()

bz := cdc.MustMarshal(&sdk.IntProto{Int: amount})
bz, err := math.Int(amount).Marshal()
suite.Require().NoError(err)
store.Set(types.TotalEscrowForDenomKey(denom), bz)
},
false,
Expand All @@ -261,7 +265,8 @@ func (suite *KeeperTestSuite) TestGetAllDenomEscrows() {
denom := "uatom"
amount := sdkmath.ZeroInt()

bz := cdc.MustMarshal(&sdk.IntProto{Int: amount})
bz, err := math.Int(amount).Marshal()
suite.Require().NoError(err)
store.Set([]byte(fmt.Sprintf("wrong-prefix/%s", denom)), bz)
},
false,
Expand All @@ -279,7 +284,6 @@ func (suite *KeeperTestSuite) TestGetAllDenomEscrows() {

storeKey := suite.chainA.GetSimApp().GetKey(types.ModuleName)
store = ctx.KVStore(storeKey)
cdc = suite.chainA.App.AppCodec()

tc.malleate()

Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (k Keeper) sendTransfer(
}

if err := k.bankKeeper.BurnCoins(
ctx, types.ModuleName, sdk.NewCoins(coin),
ctx, k.authKeeper.GetModuleAddress(types.ModuleName), sdk.NewCoins(coin),
); err != nil {
// NOTE: should not happen as the module account was
// retrieved on the step above and it has enough balance
Expand Down
Loading

0 comments on commit 5a331ed

Please sign in to comment.