From 7b58b8701beebc3641891d814d2964368bd801df Mon Sep 17 00:00:00 2001 From: Justin Tieri <37750742+jtieri@users.noreply.github.com> Date: Tue, 23 Jul 2024 18:41:34 -0500 Subject: [PATCH] refactor: remove the ability to take a fee for each forwarded packet (#202) * refactor: remove the ability to take a fee that is sent to the community pool * fix: mocks * fix: remove WithFee unit test (no longer used due to fee refactor) * fix(e2e): upgrade test --------- Co-authored-by: Reece Williams (cherry picked from commit 26d8080d75662ea2f1155fce446ebda7a915d521) # Conflicts: # middleware/packet-forward-middleware/e2e/forward_timeout_test.go # middleware/packet-forward-middleware/e2e/upgrade_test.go # middleware/packet-forward-middleware/go.mod # middleware/packet-forward-middleware/packetforward/client/cli/cli.go # middleware/packet-forward-middleware/packetforward/keeper/genesis.go # middleware/packet-forward-middleware/packetforward/keeper/grpc_query.go # middleware/packet-forward-middleware/packetforward/keeper/keeper.go # middleware/packet-forward-middleware/packetforward/keeper/params.go # middleware/packet-forward-middleware/packetforward/module.go # middleware/packet-forward-middleware/packetforward/module_test.go # middleware/packet-forward-middleware/packetforward/types/codec.go # middleware/packet-forward-middleware/packetforward/types/expected_keepers.go # middleware/packet-forward-middleware/packetforward/types/genesis.pb.go # middleware/packet-forward-middleware/packetforward/types/params.go # middleware/packet-forward-middleware/packetforward/types/query.pb.go # middleware/packet-forward-middleware/packetforward/types/query.pb.gw.go # middleware/packet-forward-middleware/proto/packetforward/v1/genesis.proto # middleware/packet-forward-middleware/proto/packetforward/v1/query.proto # middleware/packet-forward-middleware/test/mock/bank_keeper.go # middleware/packet-forward-middleware/test/mock/channel_keeper.go # middleware/packet-forward-middleware/test/mock/distribution_keeper.go # middleware/packet-forward-middleware/test/mock/ibc_module.go # middleware/packet-forward-middleware/test/mock/ics4_wrapper.go # middleware/packet-forward-middleware/test/mock/transfer_keeper.go # middleware/packet-forward-middleware/test/setup.go # middleware/packet-forward-middleware/testing/simapp/app.go # middleware/packet-forward-middleware/testing/simapp/upgrades/upgrades.go --- middleware/packet-forward-middleware/Makefile | 3 +- .../e2e/forward_timeout_test.go | 287 +++++ .../e2e/upgrade_test.go | 174 +++ middleware/packet-forward-middleware/go.mod | 80 ++ .../packetforward/keeper/genesis.go | 5 +- .../packetforward/keeper/keeper.go | 26 +- .../packetforward/module.go | 15 +- .../packetforward/module_test.go | 3 + .../packetforward/types/codec.go | 28 + .../packetforward/types/expected_keepers.go | 3 + .../packetforward/types/genesis.go | 17 +- .../packetforward/types/genesis.pb.go | 227 +--- .../packetforward/types/keys.go | 5 +- .../proto/packetforward/v1/genesis.proto | 6 + .../test/mock/bank_keeper.go | 20 +- .../test/mock/channel_keeper.go | 17 +- .../test/mock/ibc_module.go | 27 +- .../test/mock/ics4_wrapper.go | 17 +- .../test/mock/transfer_keeper.go | 42 +- .../packet-forward-middleware/test/setup.go | 29 +- .../testing/simapp/app.go | 1029 +++++++++++++++++ .../testing/simapp/upgrades/upgrades.go | 52 + 22 files changed, 1870 insertions(+), 242 deletions(-) create mode 100644 middleware/packet-forward-middleware/e2e/upgrade_test.go create mode 100644 middleware/packet-forward-middleware/packetforward/types/codec.go create mode 100644 middleware/packet-forward-middleware/testing/simapp/app.go create mode 100644 middleware/packet-forward-middleware/testing/simapp/upgrades/upgrades.go diff --git a/middleware/packet-forward-middleware/Makefile b/middleware/packet-forward-middleware/Makefile index ea5808cf..801be065 100644 --- a/middleware/packet-forward-middleware/Makefile +++ b/middleware/packet-forward-middleware/Makefile @@ -142,9 +142,8 @@ cosmovisor: .PHONY: build build-linux build-simd-all build-simd-linux cosmovisor mocks: $(MOCKS_DIR) - go install go.uber.org/mock/mockgen@v0.2.0 + go install go.uber.org/mock/mockgen@v0.4.0 mockgen -package=mock -destination=./test/mock/transfer_keeper.go $(GOMOD)/packetforward/types TransferKeeper - mockgen -package=mock -destination=./test/mock/distribution_keeper.go $(GOMOD)/packetforward/types DistributionKeeper mockgen -package=mock -destination=./test/mock/bank_keeper.go $(GOMOD)/packetforward/types BankKeeper mockgen -package=mock -destination=./test/mock/channel_keeper.go $(GOMOD)/packetforward/types ChannelKeeper mockgen -package=mock -destination=./test/mock/ics4_wrapper.go github.com/cosmos/ibc-go/v5/modules/core/05-port/types ICS4Wrapper diff --git a/middleware/packet-forward-middleware/e2e/forward_timeout_test.go b/middleware/packet-forward-middleware/e2e/forward_timeout_test.go index d71ae64d..5ee19f19 100644 --- a/middleware/packet-forward-middleware/e2e/forward_timeout_test.go +++ b/middleware/packet-forward-middleware/e2e/forward_timeout_test.go @@ -249,4 +249,291 @@ func TestTimeoutOnForward(t *testing.T) { require.True(t, firstHopEscrowBalance.Equal(zeroBal)) require.True(t, secondHopEscrowBalance.Equal(zeroBal)) require.True(t, thirdHopEscrowBalance.Equal(zeroBal)) +<<<<<<< HEAD +======= + + // Send IBC transfer from ChainA -> ChainB -> ChainC -> ChainD that will succeed + secondHopMetadata = &PacketMetadata{ + Forward: &ForwardMetadata{ + Receiver: userD.FormattedAddress(), + Channel: cdChan.ChannelID, + Port: cdChan.PortID, + }, + } + nextBz, err = json.Marshal(secondHopMetadata) + require.NoError(t, err) + next = string(nextBz) + + firstHopMetadata = &PacketMetadata{ + Forward: &ForwardMetadata{ + Receiver: userC.FormattedAddress(), + Channel: bcChan.ChannelID, + Port: bcChan.PortID, + Next: &next, + }, + } + + memo, err = json.Marshal(firstHopMetadata) + require.NoError(t, err) + + opts = ibc.TransferOptions{ + Memo: string(memo), + } + + chainAHeight, err = chainA.Height(ctx) + require.NoError(t, err) + + transferTx, err = chainA.SendIBCTransfer(ctx, abChan.ChannelID, userA.KeyName(), transfer, opts) + require.NoError(t, err) + + _, err = testutil.PollForAck(ctx, chainA, chainAHeight, chainAHeight+30, transferTx.Packet) + require.NoError(t, err) + + err = testutil.WaitForBlocks(ctx, 10, chainA) + require.NoError(t, err) + + // Assert balances are updated to reflect tokens now being on ChainD + chainABalance, err = chainA.GetBalance(ctx, userA.FormattedAddress(), chainA.Config().Denom) + require.NoError(t, err) + + chainBBalance, err = chainB.GetBalance(ctx, userB.FormattedAddress(), firstHopIBCDenom) + require.NoError(t, err) + + chainCBalance, err = chainC.GetBalance(ctx, userC.FormattedAddress(), secondHopIBCDenom) + require.NoError(t, err) + + chainDBalance, err = chainD.GetBalance(ctx, userD.FormattedAddress(), thirdHopIBCDenom) + require.NoError(t, err) + + require.True(t, chainABalance.Equal(initBal.Sub(transferAmount))) + require.True(t, chainBBalance.Equal(zeroBal)) + require.True(t, chainCBalance.Equal(zeroBal)) + require.True(t, chainDBalance.Equal(transferAmount)) + + firstHopEscrowBalance, err = chainA.GetBalance(ctx, firstHopEscrowAccount, chainA.Config().Denom) + require.NoError(t, err) + + secondHopEscrowBalance, err = chainB.GetBalance(ctx, secondHopEscrowAccount, firstHopIBCDenom) + require.NoError(t, err) + + thirdHopEscrowBalance, err = chainC.GetBalance(ctx, thirdHopEscrowAccount, secondHopIBCDenom) + require.NoError(t, err) + + require.True(t, firstHopEscrowBalance.Equal(transferAmount)) + require.True(t, secondHopEscrowBalance.Equal(transferAmount)) + require.True(t, thirdHopEscrowBalance.Equal(transferAmount)) + + // Compose IBC tx that will attempt to go from ChainD -> ChainC -> ChainB -> ChainA but timeout between ChainB->ChainA + transfer = ibc.WalletAmount{ + Address: userC.FormattedAddress(), + Denom: thirdHopDenom, + Amount: transferAmount, + } + + secondHopMetadata = &PacketMetadata{ + Forward: &ForwardMetadata{ + Receiver: userA.FormattedAddress(), + Channel: baChan.ChannelID, + Port: baChan.PortID, + Timeout: 1 * time.Second, + }, + } + nextBz, err = json.Marshal(secondHopMetadata) + require.NoError(t, err) + next = string(nextBz) + + firstHopMetadata = &PacketMetadata{ + Forward: &ForwardMetadata{ + Receiver: userB.FormattedAddress(), + Channel: cbChan.ChannelID, + Port: cbChan.PortID, + Next: &next, + }, + } + + memo, err = json.Marshal(firstHopMetadata) + require.NoError(t, err) + + chainDHeight, err := chainD.Height(ctx) + require.NoError(t, err) + + transferTx, err = chainD.SendIBCTransfer(ctx, dcChan.ChannelID, userD.KeyName(), transfer, ibc.TransferOptions{Memo: string(memo)}) + require.NoError(t, err) + + _, err = testutil.PollForAck(ctx, chainD, chainDHeight, chainDHeight+25, transferTx.Packet) + require.NoError(t, err) + + err = testutil.WaitForBlocks(ctx, 5, chainD) + require.NoError(t, err) + + // Assert balances to ensure timeout happened and user funds are still present on ChainD + chainABalance, err = chainA.GetBalance(ctx, userA.FormattedAddress(), chainA.Config().Denom) + require.NoError(t, err) + + chainBBalance, err = chainB.GetBalance(ctx, userB.FormattedAddress(), firstHopIBCDenom) + require.NoError(t, err) + + chainCBalance, err = chainC.GetBalance(ctx, userC.FormattedAddress(), secondHopIBCDenom) + require.NoError(t, err) + + chainDBalance, err = chainD.GetBalance(ctx, userD.FormattedAddress(), thirdHopIBCDenom) + require.NoError(t, err) + + require.True(t, chainABalance.Equal(initBal.Sub(transferAmount))) + require.True(t, chainBBalance.Equal(zeroBal)) + require.True(t, chainCBalance.Equal(zeroBal)) + require.True(t, chainDBalance.Equal(transferAmount)) + + firstHopEscrowBalance, err = chainA.GetBalance(ctx, firstHopEscrowAccount, chainA.Config().Denom) + require.NoError(t, err) + + secondHopEscrowBalance, err = chainB.GetBalance(ctx, secondHopEscrowAccount, firstHopIBCDenom) + require.NoError(t, err) + + thirdHopEscrowBalance, err = chainC.GetBalance(ctx, thirdHopEscrowAccount, secondHopIBCDenom) + require.NoError(t, err) + + require.True(t, firstHopEscrowBalance.Equal(transferAmount)) + require.True(t, secondHopEscrowBalance.Equal(transferAmount)) + require.True(t, thirdHopEscrowBalance.Equal(transferAmount)) + + // --- + + // Compose IBC tx that will go from ChainD -> ChainC -> ChainB -> ChainA and succeed. + transfer = ibc.WalletAmount{ + Address: userC.FormattedAddress(), + Denom: thirdHopDenom, + Amount: transferAmount, + } + + secondHopMetadata = &PacketMetadata{ + Forward: &ForwardMetadata{ + Receiver: userA.FormattedAddress(), + Channel: baChan.ChannelID, + Port: baChan.PortID, + }, + } + nextBz, err = json.Marshal(secondHopMetadata) + require.NoError(t, err) + next = string(nextBz) + + firstHopMetadata = &PacketMetadata{ + Forward: &ForwardMetadata{ + Receiver: userB.FormattedAddress(), + Channel: cbChan.ChannelID, + Port: cbChan.PortID, + Next: &next, + }, + } + + memo, err = json.Marshal(firstHopMetadata) + require.NoError(t, err) + + chainDHeight, err = chainD.Height(ctx) + require.NoError(t, err) + + transferTx, err = chainD.SendIBCTransfer(ctx, dcChan.ChannelID, userD.KeyName(), transfer, ibc.TransferOptions{Memo: string(memo)}) + require.NoError(t, err) + + _, err = testutil.PollForAck(ctx, chainD, chainDHeight, chainDHeight+25, transferTx.Packet) + require.NoError(t, err) + + err = testutil.WaitForBlocks(ctx, 5, chainD) + require.NoError(t, err) + + // Assert balances to ensure timeout happened and user funds are still present on ChainD + chainABalance, err = chainA.GetBalance(ctx, userA.FormattedAddress(), chainA.Config().Denom) + require.NoError(t, err) + + chainBBalance, err = chainB.GetBalance(ctx, userB.FormattedAddress(), firstHopIBCDenom) + require.NoError(t, err) + + chainCBalance, err = chainC.GetBalance(ctx, userC.FormattedAddress(), secondHopIBCDenom) + require.NoError(t, err) + + chainDBalance, err = chainD.GetBalance(ctx, userD.FormattedAddress(), thirdHopIBCDenom) + require.NoError(t, err) + + require.True(t, chainABalance.Equal(initBal)) + require.True(t, chainBBalance.Equal(zeroBal)) + require.True(t, chainCBalance.Equal(zeroBal)) + require.True(t, chainDBalance.Equal(zeroBal)) + + firstHopEscrowBalance, err = chainA.GetBalance(ctx, firstHopEscrowAccount, chainA.Config().Denom) + require.NoError(t, err) + + secondHopEscrowBalance, err = chainB.GetBalance(ctx, secondHopEscrowAccount, firstHopIBCDenom) + require.NoError(t, err) + + thirdHopEscrowBalance, err = chainC.GetBalance(ctx, thirdHopEscrowAccount, secondHopIBCDenom) + require.NoError(t, err) + + require.True(t, firstHopEscrowBalance.Equal(zeroBal)) + require.True(t, secondHopEscrowBalance.Equal(zeroBal)) + require.True(t, thirdHopEscrowBalance.Equal(zeroBal)) + + // ----- 2 + + // Compose IBC tx that will go from ChainD -> ChainC -> ChainB -> ChainA and succeed. + transfer = ibc.WalletAmount{ + Address: userB.FormattedAddress(), + Denom: chainA.Config().Denom, + Amount: transferAmount, + } + + firstHopMetadata = &PacketMetadata{ + Forward: &ForwardMetadata{ + Receiver: userA.FormattedAddress(), + Channel: baChan.ChannelID, + Port: baChan.PortID, + Timeout: 1 * time.Second, + }, + } + + memo, err = json.Marshal(firstHopMetadata) + require.NoError(t, err) + + chainAHeight, err = chainA.Height(ctx) + require.NoError(t, err) + + transferTx, err = chainA.SendIBCTransfer(ctx, abChan.ChannelID, userA.KeyName(), transfer, ibc.TransferOptions{Memo: string(memo)}) + require.NoError(t, err) + + _, err = testutil.PollForAck(ctx, chainA, chainAHeight, chainAHeight+25, transferTx.Packet) + require.NoError(t, err) + + err = testutil.WaitForBlocks(ctx, 5, chainA) + require.NoError(t, err) + + // Assert balances to ensure timeout happened and user funds are still present on ChainD + chainABalance, err = chainA.GetBalance(ctx, userA.FormattedAddress(), chainA.Config().Denom) + require.NoError(t, err) + + chainBBalance, err = chainB.GetBalance(ctx, userB.FormattedAddress(), firstHopIBCDenom) + require.NoError(t, err) + + chainCBalance, err = chainC.GetBalance(ctx, userC.FormattedAddress(), secondHopIBCDenom) + require.NoError(t, err) + + chainDBalance, err = chainD.GetBalance(ctx, userD.FormattedAddress(), thirdHopIBCDenom) + require.NoError(t, err) + + require.True(t, chainABalance.Equal(initBal)) + require.True(t, chainBBalance.Equal(zeroBal)) + require.True(t, chainCBalance.Equal(zeroBal)) + require.True(t, chainDBalance.Equal(zeroBal)) + + firstHopEscrowBalance, err = chainA.GetBalance(ctx, firstHopEscrowAccount, chainA.Config().Denom) + require.NoError(t, err) + + secondHopEscrowBalance, err = chainB.GetBalance(ctx, secondHopEscrowAccount, firstHopIBCDenom) + require.NoError(t, err) + + thirdHopEscrowBalance, err = chainC.GetBalance(ctx, thirdHopEscrowAccount, secondHopIBCDenom) + require.NoError(t, err) + + require.True(t, firstHopEscrowBalance.Equal(zeroBal)) + require.True(t, secondHopEscrowBalance.Equal(zeroBal)) + require.True(t, thirdHopEscrowBalance.Equal(zeroBal)) +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) } diff --git a/middleware/packet-forward-middleware/e2e/upgrade_test.go b/middleware/packet-forward-middleware/e2e/upgrade_test.go new file mode 100644 index 00000000..77ea90ef --- /dev/null +++ b/middleware/packet-forward-middleware/e2e/upgrade_test.go @@ -0,0 +1,174 @@ +package e2e + +import ( + "context" + "fmt" + "testing" + "time" + + sdkmath "cosmossdk.io/math" + upgradetypes "cosmossdk.io/x/upgrade/types" + cosmosproto "github.com/cosmos/gogoproto/proto" + "github.com/docker/docker/client" + "github.com/strangelove-ventures/interchaintest/v8" + "github.com/strangelove-ventures/interchaintest/v8/chain/cosmos" + "github.com/strangelove-ventures/interchaintest/v8/ibc" + "github.com/strangelove-ventures/interchaintest/v8/testutil" + "github.com/stretchr/testify/require" +) + +const ( + chainName = "simapp" + upgradeName = "v2" // x/params migration + + haltHeightDelta = uint64(9) // will propose upgrade this many blocks in the future + blocksAfterUpgrade = uint64(7) + + VotingPeriod = "15s" + MaxDepositPeriod = "10s" +) + +var ( + // baseChain is the current version of the chain that will be upgraded from + // docker image load -i ../prev_builds/pfm_7_0_1.tar + baseChain = ibc.DockerImage{ + Repository: "pfm", + Version: "v7.0.1", + UidGid: "1025:1025", + } + + // make local-image + upgradeTo = ibc.DockerImage{ + Repository: "pfm", + Version: "local", + } +) + +func TestPFMUpgrade(t *testing.T) { + CosmosChainUpgradeTest(t, chainName, upgradeTo.Repository, upgradeTo.Version, upgradeName) +} + +func CosmosChainUpgradeTest(t *testing.T, chainName, upgradeRepo, upgradeDockerTag, upgradeName string) { + if testing.Short() { + t.Skip("skipping in short mode") + } + + t.Parallel() + + previousVersionGenesis := []cosmos.GenesisKV{ + { + Key: "app_state.gov.params.voting_period", + Value: VotingPeriod, + }, + { + Key: "app_state.gov.params.max_deposit_period", + Value: MaxDepositPeriod, + }, + { + Key: "app_state.gov.params.min_deposit.0.denom", + Value: Denom, + }, + } + + // Upgrade default to use the base chain image + cfg := DefaultConfig + cfg.ModifyGenesis = cosmos.ModifyGenesis(previousVersionGenesis) + cfg.Images = []ibc.DockerImage{baseChain} + + numVals, numNodes := 2, 0 + chains := interchaintest.CreateChainWithConfig(t, numVals, numNodes, chainName, upgradeDockerTag, cfg) + chain := chains[0].(*cosmos.CosmosChain) + + ctx, ic, client, _ := interchaintest.BuildInitialChain(t, chains, false) + t.Cleanup(func() { + ic.Close() + }) + + var userFunds = sdkmath.NewInt(10_000_000_000) + users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds, chain) + chainUser := users[0] + + // upgrade + height, err := chain.Height(ctx) + require.NoError(t, err, "error fetching height before submit upgrade proposal") + + haltHeight := height + haltHeightDelta + proposalID := SubmitUpgradeProposal(t, ctx, chain, chainUser, upgradeName, haltHeight) + + ValidatorVoting(t, ctx, chain, proposalID, height, haltHeight) + UpgradeNodes(t, ctx, chain, client, haltHeight, upgradeRepo, upgradeDockerTag) +} + +func SubmitUpgradeProposal(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, user ibc.Wallet, upgradeName string, haltHeight uint64) string { + upgradeMsg := []cosmosproto.Message{ + &upgradetypes.MsgSoftwareUpgrade{ + // Gov Module account + Authority: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", + Plan: upgradetypes.Plan{ + Name: upgradeName, + Height: int64(haltHeight), + }, + }, + } + + proposal, err := chain.BuildProposal(upgradeMsg, "Chain Upgrade "+upgradeName, "Summary desc", "ipfs://CID", fmt.Sprintf(`500000000%s`, chain.Config().Denom), user.KeyName(), false) + require.NoError(t, err, "error building proposal") + + txProp, err := chain.SubmitProposal(ctx, user.KeyName(), proposal) + require.NoError(t, err, "error submitting proposal") + + t.Log("txProp", txProp) + return txProp.ProposalID +} + +func UpgradeNodes(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, client *client.Client, haltHeight uint64, upgradeRepo, upgradeBranchVersion string) { + // bring down nodes to prepare for upgrade + t.Log("stopping node(s)") + err := chain.StopAllNodes(ctx) + require.NoError(t, err, "error stopping node(s)") + + // upgrade version on all nodes + t.Log("upgrading node(s)") + chain.UpgradeVersion(ctx, client, upgradeRepo, upgradeBranchVersion) + + // start all nodes back up. + // validators reach consensus on first block after upgrade height + // and chain block production resumes. + t.Log("starting node(s)") + err = chain.StartAllNodes(ctx) + require.NoError(t, err, "error starting upgraded node(s)") + + timeoutCtx, timeoutCtxCancel := context.WithTimeout(ctx, time.Second*60) + defer timeoutCtxCancel() + + err = testutil.WaitForBlocks(timeoutCtx, int(blocksAfterUpgrade), chain) + require.NoError(t, err, "chain did not produce blocks after upgrade") + + height, err := chain.Height(ctx) + require.NoError(t, err, "error fetching height after upgrade") + + require.GreaterOrEqual(t, height, haltHeight+blocksAfterUpgrade, "height did not increment enough after upgrade") +} + +func ValidatorVoting(t *testing.T, ctx context.Context, chain *cosmos.CosmosChain, proposalID string, height uint64, haltHeight uint64) { + err := chain.VoteOnProposalAllValidators(ctx, proposalID, cosmos.ProposalVoteYes) + require.NoError(t, err, "failed to submit votes") + + _, err = cosmos.PollForProposalStatusV8(ctx, chain, height, height+haltHeightDelta, proposalID, cosmos.ProposalStatusPassedV8) + require.NoError(t, err, "proposal status did not change to passed in expected number of blocks") + + timeoutCtx, timeoutCtxCancel := context.WithTimeout(ctx, time.Second*45) + defer timeoutCtxCancel() + + height, err = chain.Height(ctx) + require.NoError(t, err, "error fetching height before upgrade") + + // this should timeout due to chain halt at upgrade height. + _ = testutil.WaitForBlocks(timeoutCtx, int(haltHeight-height), chain) + + height, err = chain.Height(ctx) + require.NoError(t, err, "error fetching height after chain should have halted") + + // make sure that chain is halted + require.Equal(t, haltHeight, height, "height is not equal to halt height") +} diff --git a/middleware/packet-forward-middleware/go.mod b/middleware/packet-forward-middleware/go.mod index 66be9cdc..47df43ff 100644 --- a/middleware/packet-forward-middleware/go.mod +++ b/middleware/packet-forward-middleware/go.mod @@ -1,5 +1,6 @@ go 1.18 +<<<<<<< HEAD module github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v5 require ( @@ -19,6 +20,41 @@ require ( go.uber.org/mock v0.2.0 google.golang.org/genproto/googleapis/api v0.0.0-20230629202037-9506855d4529 google.golang.org/grpc v1.56.2 +======= +toolchain go1.22.5 + +module github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8 + +require ( + cosmossdk.io/api v0.7.3 + cosmossdk.io/client/v2 v2.0.0-beta.1 + cosmossdk.io/core v0.11.0 + cosmossdk.io/errors v1.0.1 + cosmossdk.io/log v1.3.1 + cosmossdk.io/math v1.3.0 + cosmossdk.io/store v1.0.2 + cosmossdk.io/tools/confix v0.1.0 + cosmossdk.io/x/evidence v0.1.0 + cosmossdk.io/x/feegrant v0.1.0 + cosmossdk.io/x/tx v0.13.1 + cosmossdk.io/x/upgrade v0.1.1 + github.com/cometbft/cometbft v0.38.6 + github.com/cosmos/cosmos-db v1.0.2 + github.com/cosmos/cosmos-sdk v0.50.5 + github.com/cosmos/gogoproto v1.4.11 + github.com/cosmos/ibc-go/modules/capability v1.0.0 + github.com/cosmos/ibc-go/v8 v8.1.1 + github.com/gorilla/mux v1.8.1 + github.com/grpc-ecosystem/grpc-gateway v1.16.0 + github.com/hashicorp/go-metrics v0.5.2 + github.com/iancoleman/orderedmap v0.3.0 + github.com/rakyll/statik v0.1.7 + github.com/spf13/cast v1.6.0 + github.com/spf13/cobra v1.8.0 + github.com/spf13/viper v1.18.2 + github.com/stretchr/testify v1.9.0 + go.uber.org/mock v0.4.0 +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) ) require ( @@ -35,7 +71,11 @@ require ( github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect github.com/confio/ics23/go v0.9.0 // indirect github.com/cosmos/btcutil v1.0.5 // indirect +<<<<<<< HEAD github.com/cosmos/cosmos-proto v1.0.0-alpha7 // indirect +======= + github.com/cosmos/cosmos-proto v1.0.0-beta.4 // indirect +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gorocksdb v1.2.0 // indirect github.com/cosmos/iavl v0.19.6 // indirect @@ -53,7 +93,16 @@ require ( github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.5.1 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect +<<<<<<< HEAD github.com/golang/glog v1.1.0 // indirect +======= + github.com/gogo/googleapis v1.4.1 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang/glog v1.2.0 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/golang/mock v1.6.0 // indirect + github.com/golang/protobuf v1.5.4 // indirect +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) github.com/golang/snappy v0.0.4 // indirect github.com/google/btree v1.1.2 // indirect github.com/google/gofuzz v1.2.0 // indirect @@ -97,6 +146,7 @@ require ( github.com/subosito/gotenv v1.4.1 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect github.com/tendermint/go-amino v0.16.0 // indirect +<<<<<<< HEAD github.com/tidwall/btree v1.5.0 // indirect github.com/zondax/hid v0.9.1 // indirect github.com/zondax/ledger-go v0.14.1 // indirect @@ -110,6 +160,36 @@ require ( google.golang.org/genproto v0.0.0-20230525234025-438c736192d0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect google.golang.org/protobuf v1.30.0 // indirect +======= + github.com/tidwall/btree v1.7.0 // indirect + github.com/ulikunitz/xz v0.5.11 // indirect + github.com/zondax/hid v0.9.2 // indirect + github.com/zondax/ledger-go v0.14.3 // indirect + go.etcd.io/bbolt v1.3.8 // indirect + go.opencensus.io v0.24.0 // indirect + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.47.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.47.0 // indirect + go.opentelemetry.io/otel v1.22.0 // indirect + go.opentelemetry.io/otel/metric v1.22.0 // indirect + go.opentelemetry.io/otel/trace v1.22.0 // indirect + go.uber.org/multierr v1.10.0 // indirect + golang.org/x/crypto v0.19.0 // indirect + golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect + golang.org/x/net v0.21.0 // indirect + golang.org/x/oauth2 v0.16.0 // indirect + golang.org/x/sync v0.6.0 // indirect + golang.org/x/sys v0.17.0 // indirect + golang.org/x/term v0.17.0 // indirect + golang.org/x/text v0.14.0 // indirect + golang.org/x/time v0.5.0 // indirect + google.golang.org/api v0.162.0 // indirect + google.golang.org/appengine v1.6.8 // indirect + google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240221002015-b0ce06bbee7c // indirect + google.golang.org/grpc v1.62.0 // indirect + google.golang.org/protobuf v1.33.0 // indirect +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/middleware/packet-forward-middleware/packetforward/keeper/genesis.go b/middleware/packet-forward-middleware/packetforward/keeper/genesis.go index 6b41e485..f9e5de39 100644 --- a/middleware/packet-forward-middleware/packetforward/keeper/genesis.go +++ b/middleware/packet-forward-middleware/packetforward/keeper/genesis.go @@ -8,8 +8,11 @@ import ( // InitGenesis func (k Keeper) InitGenesis(ctx sdk.Context, state types.GenesisState) { +<<<<<<< HEAD k.SetParams(ctx, state.Params) +======= +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) // Initialize store refund path for forwarded packets in genesis state that have not yet been acked. store := ctx.KVStore(k.storeKey) for key, value := range state.InFlightPackets { @@ -32,5 +35,5 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { k.cdc.MustUnmarshal(itr.Value(), &inFlightPacket) inFlightPackets[string(itr.Key())] = inFlightPacket } - return &types.GenesisState{Params: k.GetParams(ctx), InFlightPackets: inFlightPackets} + return &types.GenesisState{InFlightPackets: inFlightPackets} } diff --git a/middleware/packet-forward-middleware/packetforward/keeper/keeper.go b/middleware/packet-forward-middleware/packetforward/keeper/keeper.go index 20374688..fc516159 100644 --- a/middleware/packet-forward-middleware/packetforward/keeper/keeper.go +++ b/middleware/packet-forward-middleware/packetforward/keeper/keeper.go @@ -51,7 +51,6 @@ type Keeper struct { transferKeeper types.TransferKeeper channelKeeper types.ChannelKeeper - distrKeeper types.DistributionKeeper bankKeeper types.BankKeeper ics4Wrapper porttypes.ICS4Wrapper } @@ -63,7 +62,6 @@ func NewKeeper( paramSpace paramtypes.Subspace, transferKeeper types.TransferKeeper, channelKeeper types.ChannelKeeper, - distrKeeper types.DistributionKeeper, bankKeeper types.BankKeeper, ics4Wrapper porttypes.ICS4Wrapper, ) *Keeper { @@ -79,7 +77,6 @@ func NewKeeper( transferKeeper: transferKeeper, channelKeeper: channelKeeper, - distrKeeper: distrKeeper, bankKeeper: bankKeeper, ics4Wrapper: ics4Wrapper, } @@ -220,6 +217,7 @@ func (k *Keeper) ForwardTransferPacket( labels []metrics.Label, nonrefundable bool, ) error { +<<<<<<< HEAD var err error feeAmount := sdk.NewDecFromInt(token.Amount).Mul(k.GetFeePercentage(ctx)).RoundInt() packetAmount := token.Amount.Sub(feeAmount) @@ -250,6 +248,9 @@ func (k *Keeper) ForwardTransferPacket( DefaultTransferPacketTimeoutHeight, uint64(ctx.BlockTime().UnixNano())+uint64(timeout.Nanoseconds()), ) +======= + memo := "" +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) // set memo for next transfer with next from this transfer. if metadata.Next != nil { @@ -263,10 +264,24 @@ func (k *Keeper) ForwardTransferPacket( msgTransfer.Memo = string(memoBz) } +<<<<<<< HEAD +======= + msgTransfer := transfertypes.NewMsgTransfer( + metadata.Port, + metadata.Channel, + token, + receiver, + metadata.Receiver, + DefaultTransferPacketTimeoutHeight, + uint64(ctx.BlockTime().UnixNano())+uint64(timeout.Nanoseconds()), + memo, + ) + +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) k.Logger(ctx).Debug("packetForwardMiddleware ForwardTransferPacket", "port", metadata.Port, "channel", metadata.Channel, "sender", receiver, "receiver", metadata.Receiver, - "amount", packetCoin.Amount.String(), "denom", packetCoin.Denom, + "amount", token.Amount.String(), "denom", token.Denom, ) // send tokens to destination @@ -278,7 +293,7 @@ func (k *Keeper) ForwardTransferPacket( k.Logger(ctx).Error("packetForwardMiddleware ForwardTransferPacket error", "port", metadata.Port, "channel", metadata.Channel, "sender", receiver, "receiver", metadata.Receiver, - "amount", packetCoin.Amount.String(), "denom", packetCoin.Denom, + "amount", token.Amount.String(), "denom", token.Denom, "error", err, ) return errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error()) @@ -287,7 +302,6 @@ func (k *Keeper) ForwardTransferPacket( // Store the following information in keeper: // key - information about forwarded packet: src_channel (parsedReceiver.Channel), src_port (parsedReceiver.Port), sequence // value - information about original packet for refunding if necessary: retries, srcPacketSender, srcPacket.DestinationChannel, srcPacket.DestinationPort - if inFlightPacket == nil { inFlightPacket = &types.InFlightPacket{ PacketData: srcPacket.Data, diff --git a/middleware/packet-forward-middleware/packetforward/module.go b/middleware/packet-forward-middleware/packetforward/module.go index 56d5b02e..30e460b2 100644 --- a/middleware/packet-forward-middleware/packetforward/module.go +++ b/middleware/packet-forward-middleware/packetforward/module.go @@ -1,15 +1,20 @@ package packetforward import ( - "context" "encoding/json" "fmt" "math/rand" +<<<<<<< HEAD "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v5/packetforward/client/cli" "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v5/packetforward/keeper" "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v5/packetforward/types" "github.com/gorilla/mux" +======= + "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/exported" + "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/keeper" + "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types" +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -63,17 +68,16 @@ func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {} // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the packetforward module. func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { - _ = types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) } // GetTxCmd implements AppModuleBasic interface func (AppModuleBasic) GetTxCmd() *cobra.Command { - return cli.NewTxCmd() + return nil } // GetQueryCmd implements AppModuleBasic interface func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd() + return nil } // AppModule represents the AppModule for this module @@ -109,7 +113,10 @@ func (am AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier { // RegisterServices registers module services. func (am AppModule) RegisterServices(cfg module.Configurator) { +<<<<<<< HEAD types.RegisterQueryServer(cfg.QueryServer(), am.keeper) +======= +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) } // InitGenesis performs genesis initialization for the packetforward module. It returns diff --git a/middleware/packet-forward-middleware/packetforward/module_test.go b/middleware/packet-forward-middleware/packetforward/module_test.go index 0eec12a5..1365a395 100644 --- a/middleware/packet-forward-middleware/packetforward/module_test.go +++ b/middleware/packet-forward-middleware/packetforward/module_test.go @@ -360,6 +360,7 @@ func TestOnRecvPacket_ForwardAmountInt256(t *testing.T) { require.NoError(t, err) } +<<<<<<< HEAD func TestOnRecvPacket_ForwardWithFee(t *testing.T) { var err error ctl := gomock.NewController(t) @@ -425,6 +426,8 @@ func TestOnRecvPacket_ForwardWithFee(t *testing.T) { require.NoError(t, err) } +======= +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) func TestOnRecvPacket_ForwardMultihopStringNext(t *testing.T) { var err error ctl := gomock.NewController(t) diff --git a/middleware/packet-forward-middleware/packetforward/types/codec.go b/middleware/packet-forward-middleware/packetforward/types/codec.go new file mode 100644 index 00000000..3a4f6648 --- /dev/null +++ b/middleware/packet-forward-middleware/packetforward/types/codec.go @@ -0,0 +1,28 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var amino = codec.NewLegacyAmino() + +func init() { + RegisterLegacyAminoCodec(amino) + cryptocodec.RegisterCrypto(amino) + sdk.RegisterLegacyAminoCodec(amino) + + // Register all Amino interfaces and concrete types on the authz Amino codec + // so that this can later be used to properly serialize MsgGrant and MsgExec + // instances. + // RegisterLegacyAminoCodec(authzcodec.Amino) // TODO(bez): Investigate this. +} + +// RegisterLegacyAminoCodec registers concrete types on the LegacyAmino codec +func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { +} + +func RegisterInterfaces(registry types.InterfaceRegistry) { +} diff --git a/middleware/packet-forward-middleware/packetforward/types/expected_keepers.go b/middleware/packet-forward-middleware/packetforward/types/expected_keepers.go index 5bb154d0..29205782 100644 --- a/middleware/packet-forward-middleware/packetforward/types/expected_keepers.go +++ b/middleware/packet-forward-middleware/packetforward/types/expected_keepers.go @@ -24,11 +24,14 @@ type ChannelKeeper interface { LookupModuleByChannel(ctx sdk.Context, portID, channelID string) (string, *capabilitytypes.Capability, error) } +<<<<<<< HEAD // DistributionKeeper defines the expected distribution keeper type DistributionKeeper interface { FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error } +======= +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) // BankKeeper defines the expected bank keeper type BankKeeper interface { SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error diff --git a/middleware/packet-forward-middleware/packetforward/types/genesis.go b/middleware/packet-forward-middleware/packetforward/types/genesis.go index a6f39848..41d18f3e 100644 --- a/middleware/packet-forward-middleware/packetforward/types/genesis.go +++ b/middleware/packet-forward-middleware/packetforward/types/genesis.go @@ -1,22 +1,19 @@ package types -// NewGenesisState creates a pfm GenesisState instance. -func NewGenesisState(params Params, inFlightPackets map[string]InFlightPacket) *GenesisState { - return &GenesisState{ - Params: params, - InFlightPackets: inFlightPackets, - } -} +import "errors" -// DefaultGenesisState returns a GenesisState with a default fee percentage of 0. +// DefaultGenesisState returns a GenesisState with an empty map of in-flight packets. func DefaultGenesisState() *GenesisState { return &GenesisState{ - Params: DefaultParams(), InFlightPackets: make(map[string]InFlightPacket), } } // Validate performs basic genesis state validation returning an error upon any failure. func (gs GenesisState) Validate() error { - return gs.Params.Validate() + if gs.InFlightPackets == nil { + return errors.New("in-flight packets cannot be nil") + } + + return nil } diff --git a/middleware/packet-forward-middleware/packetforward/types/genesis.pb.go b/middleware/packet-forward-middleware/packetforward/types/genesis.pb.go index 26614e00..c4fdd20c 100644 --- a/middleware/packet-forward-middleware/packetforward/types/genesis.pb.go +++ b/middleware/packet-forward-middleware/packetforward/types/genesis.pb.go @@ -26,7 +26,6 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the packetforward genesis state type GenesisState struct { - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` // key - information about forwarded packet: src_channel // (parsedReceiver.Channel), src_port (parsedReceiver.Port), sequence value - // information about original packet for refunding if necessary: retries, @@ -67,13 +66,6 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo -func (m *GenesisState) GetParams() Params { - if m != nil { - return m.Params - } - return Params{} -} - func (m *GenesisState) GetInFlightPackets() map[string]InFlightPacket { if m != nil { return m.InFlightPackets @@ -81,6 +73,7 @@ func (m *GenesisState) GetInFlightPackets() map[string]InFlightPacket { return nil } +<<<<<<< HEAD // Params defines the set of packetforward parameters. type Params struct { FeePercentage github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=fee_percentage,json=feePercentage,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"fee_percentage" yaml:"fee_percentage"` @@ -119,6 +112,8 @@ func (m *Params) XXX_DiscardUnknown() { var xxx_messageInfo_Params proto.InternalMessageInfo +======= +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) // InFlightPacket contains information about original packet for // writing the acknowledgement and refunding if necessary. type InFlightPacket struct { @@ -140,7 +135,7 @@ func (m *InFlightPacket) Reset() { *m = InFlightPacket{} } func (m *InFlightPacket) String() string { return proto.CompactTextString(m) } func (*InFlightPacket) ProtoMessage() {} func (*InFlightPacket) Descriptor() ([]byte, []int) { - return fileDescriptor_afd4e56ea31af982, []int{2} + return fileDescriptor_afd4e56ea31af982, []int{1} } func (m *InFlightPacket) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -256,13 +251,13 @@ func (m *InFlightPacket) GetNonrefundable() bool { func init() { proto.RegisterType((*GenesisState)(nil), "packetforward.v1.GenesisState") proto.RegisterMapType((map[string]InFlightPacket)(nil), "packetforward.v1.GenesisState.InFlightPacketsEntry") - proto.RegisterType((*Params)(nil), "packetforward.v1.Params") proto.RegisterType((*InFlightPacket)(nil), "packetforward.v1.InFlightPacket") } func init() { proto.RegisterFile("packetforward/v1/genesis.proto", fileDescriptor_afd4e56ea31af982) } var fileDescriptor_afd4e56ea31af982 = []byte{ +<<<<<<< HEAD // 645 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x54, 0xcd, 0x4e, 0x1b, 0x3b, 0x14, 0xce, 0x84, 0x10, 0xc0, 0x09, 0x7f, 0xbe, 0x70, 0xaf, 0xc5, 0x22, 0x19, 0x45, 0xe8, 0x36, @@ -305,6 +300,45 @@ var fileDescriptor_afd4e56ea31af982 = []byte{ 0xa8, 0x00, 0xc7, 0x4c, 0xd8, 0x48, 0x7f, 0x84, 0xc6, 0x1c, 0x32, 0x7a, 0xe5, 0x64, 0xdf, 0x1c, 0x7d, 0x7f, 0xbb, 0x45, 0xfd, 0x8e, 0x1c, 0xff, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xe8, 0x91, 0x7a, 0x42, 0x91, 0x04, 0x00, 0x00, +======= + // 574 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x93, 0xcb, 0x4e, 0xdc, 0x3e, + 0x14, 0xc6, 0xc7, 0xdc, 0xf1, 0xcc, 0x9f, 0x8b, 0xff, 0xd0, 0x5a, 0x2c, 0x42, 0x34, 0x42, 0x6a, + 0x54, 0x44, 0x22, 0x40, 0x42, 0x88, 0x5d, 0xe9, 0x95, 0x1d, 0xca, 0xa0, 0x2e, 0xba, 0x89, 0x3c, + 0xb1, 0xc9, 0x58, 0x24, 0x76, 0x6a, 0x7b, 0x06, 0xcd, 0xb2, 0x6f, 0xd0, 0x37, 0xe8, 0xeb, 0xb0, + 0x64, 0xd9, 0x15, 0xaa, 0xe0, 0x0d, 0xba, 0xea, 0xb2, 0x1a, 0x3b, 0xa1, 0x93, 0xd2, 0x4d, 0xe2, + 0x9c, 0xdf, 0xf7, 0x7d, 0x3e, 0x3e, 0x8a, 0xa1, 0x57, 0x92, 0xf4, 0x8a, 0x99, 0x4b, 0xa9, 0xae, + 0x89, 0xa2, 0xd1, 0x68, 0x3f, 0xca, 0x98, 0x60, 0x9a, 0xeb, 0xb0, 0x54, 0xd2, 0x48, 0xb4, 0xd6, + 0xe0, 0xe1, 0x68, 0x7f, 0x6b, 0x23, 0x93, 0x99, 0xb4, 0x30, 0x9a, 0xac, 0x9c, 0x6e, 0x6b, 0x9d, + 0x14, 0x5c, 0xc8, 0xc8, 0x3e, 0x5d, 0xa9, 0xfb, 0x0b, 0xc0, 0xce, 0x7b, 0x17, 0xd6, 0x33, 0xc4, + 0x30, 0xf4, 0x05, 0xc0, 0x75, 0x2e, 0x92, 0xcb, 0x9c, 0x67, 0x03, 0x93, 0xb8, 0x60, 0x8d, 0x67, + 0xfc, 0xd9, 0xa0, 0x7d, 0x70, 0x18, 0xfe, 0xbd, 0x51, 0x38, 0xed, 0x0d, 0xcf, 0xc4, 0x3b, 0x6b, + 0x3b, 0x77, 0xae, 0xb7, 0xc2, 0xa8, 0xf1, 0xa9, 0x7f, 0x73, 0xb7, 0xdd, 0xfa, 0x79, 0xb7, 0x8d, + 0xc7, 0xa4, 0xc8, 0x4f, 0xba, 0x4f, 0xb2, 0xbb, 0xf1, 0x2a, 0x6f, 0xfa, 0xb6, 0x28, 0xdc, 0xf8, + 0x57, 0x14, 0x5a, 0x83, 0xb3, 0x57, 0x6c, 0x8c, 0x81, 0x0f, 0x82, 0xe5, 0x78, 0xb2, 0x44, 0x47, + 0x70, 0x7e, 0x44, 0xf2, 0x21, 0xc3, 0x33, 0x3e, 0x08, 0xda, 0x07, 0xfe, 0xd3, 0x06, 0x9b, 0x41, + 0xb1, 0x93, 0x9f, 0xcc, 0x1c, 0x83, 0xee, 0xb7, 0x39, 0xb8, 0xd2, 0xa4, 0xe8, 0x08, 0x3e, 0x97, + 0x8a, 0x67, 0x5c, 0x90, 0x3c, 0xd1, 0x4c, 0x50, 0xa6, 0x12, 0x42, 0xa9, 0x62, 0x5a, 0x57, 0x9b, + 0x6e, 0xd6, 0xb8, 0x67, 0xe9, 0x2b, 0x07, 0xd1, 0x4b, 0xb8, 0xae, 0xd8, 0xe5, 0x50, 0xd0, 0x24, + 0x1d, 0x10, 0x21, 0x58, 0x9e, 0x70, 0x6a, 0x5b, 0x5a, 0x8e, 0x57, 0x1d, 0x78, 0xed, 0xea, 0x67, + 0x14, 0xed, 0xc0, 0x95, 0x4a, 0x5b, 0x4a, 0x65, 0x26, 0xc2, 0x59, 0x2b, 0xec, 0xb8, 0xea, 0xb9, + 0x54, 0xe6, 0x8c, 0xa2, 0x7d, 0xb8, 0xe9, 0x8e, 0x92, 0x68, 0x95, 0x4e, 0xa7, 0xce, 0x59, 0x31, + 0x72, 0xb0, 0xa7, 0xd2, 0x3f, 0xc1, 0xbb, 0x10, 0x4d, 0x59, 0xea, 0xf0, 0x79, 0xd7, 0xc5, 0xa3, + 0xbe, 0xca, 0x3f, 0x86, 0xb8, 0x12, 0x1b, 0x5e, 0x30, 0x39, 0x74, 0x6f, 0x6d, 0x48, 0x51, 0xe2, + 0x05, 0x1f, 0x04, 0x73, 0xf1, 0x33, 0xc7, 0x2f, 0x1c, 0xbe, 0xa8, 0x29, 0x3a, 0x78, 0xec, 0xac, + 0x76, 0x0e, 0xd8, 0x64, 0x84, 0x78, 0xd1, 0xee, 0xf4, 0x7f, 0xc3, 0xf6, 0xc1, 0x22, 0xb4, 0x0d, + 0xdb, 0x95, 0x87, 0x12, 0x43, 0xf0, 0x92, 0x0f, 0x82, 0x4e, 0x0c, 0x5d, 0xe9, 0x0d, 0x31, 0x04, + 0xbd, 0x80, 0xd5, 0x9c, 0x12, 0xcd, 0x3e, 0x0f, 0x99, 0x48, 0x19, 0x5e, 0xb6, 0x5d, 0x54, 0xb3, + 0xea, 0x55, 0x55, 0xb4, 0x3b, 0x99, 0xb4, 0x51, 0x9c, 0xe9, 0x44, 0xb1, 0x82, 0x70, 0xc1, 0x45, + 0x86, 0xa1, 0x0f, 0x82, 0xf9, 0x78, 0xad, 0x02, 0x71, 0x5d, 0x47, 0x18, 0x2e, 0x56, 0x3d, 0xe2, + 0xb6, 0x4d, 0xab, 0x3f, 0xd1, 0x0e, 0xfc, 0x4f, 0x48, 0xe1, 0xb2, 0x49, 0x3f, 0x67, 0xb8, 0xe3, + 0x83, 0x60, 0x29, 0x6e, 0x16, 0x4f, 0xcb, 0x9b, 0x7b, 0x0f, 0xdc, 0xde, 0x7b, 0xe0, 0xc7, 0xbd, + 0x07, 0xbe, 0x3e, 0x78, 0xad, 0xdb, 0x07, 0xaf, 0xf5, 0xfd, 0xc1, 0x6b, 0x7d, 0xfa, 0x98, 0x71, + 0x33, 0x18, 0xf6, 0xc3, 0x54, 0x16, 0x51, 0x2a, 0x75, 0x21, 0x75, 0xc4, 0xfb, 0xe9, 0x1e, 0x29, + 0x4b, 0x1d, 0x15, 0x9c, 0xd2, 0x9c, 0x5d, 0x13, 0xc5, 0x22, 0x77, 0xc2, 0xbd, 0xea, 0x77, 0xdc, + 0x9b, 0x22, 0xa3, 0xe3, 0xa8, 0x79, 0xa9, 0xcd, 0xb8, 0x64, 0xba, 0xbf, 0x60, 0x6f, 0xe5, 0xe1, + 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0xa5, 0x8e, 0x69, 0x25, 0xf2, 0x03, 0x00, 0x00, +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -351,49 +385,6 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x12 } } - { - size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - -func (m *Params) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Params) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size := m.FeePercentage.Size() - i -= size - if _, err := m.FeePercentage.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -516,8 +507,6 @@ func (m *GenesisState) Size() (n int) { } var l int _ = l - l = m.Params.Size() - n += 1 + l + sovGenesis(uint64(l)) if len(m.InFlightPackets) > 0 { for k, v := range m.InFlightPackets { _ = k @@ -530,17 +519,6 @@ func (m *GenesisState) Size() (n int) { return n } -func (m *Params) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.FeePercentage.Size() - n += 1 + l + sovGenesis(uint64(l)) - return n -} - func (m *InFlightPacket) Size() (n int) { if m == nil { return 0 @@ -628,39 +606,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field InFlightPackets", wireType) @@ -811,90 +756,6 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } return nil } -func (m *Params) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Params: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field FeePercentage", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.FeePercentage.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipGenesis(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthGenesis - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *InFlightPacket) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/middleware/packet-forward-middleware/packetforward/types/keys.go b/middleware/packet-forward-middleware/packetforward/types/keys.go index 3634eb63..13449c9c 100644 --- a/middleware/packet-forward-middleware/packetforward/types/keys.go +++ b/middleware/packet-forward-middleware/packetforward/types/keys.go @@ -1,6 +1,6 @@ package types -import fmt "fmt" +import "fmt" const ( // ModuleName defines the 29-fee name @@ -9,9 +9,6 @@ const ( // StoreKey is the store key string for IBC transfer StoreKey = ModuleName - // RouterKey is the message route for IBC transfer - RouterKey = ModuleName - // QuerierRoute is the querier route for IBC transfer QuerierRoute = ModuleName ) diff --git a/middleware/packet-forward-middleware/proto/packetforward/v1/genesis.proto b/middleware/packet-forward-middleware/proto/packetforward/v1/genesis.proto index 4ac20aa3..8d300131 100644 --- a/middleware/packet-forward-middleware/proto/packetforward/v1/genesis.proto +++ b/middleware/packet-forward-middleware/proto/packetforward/v1/genesis.proto @@ -6,8 +6,11 @@ option go_package = "github.com/cosmos/ibc-apps/middleware/packet-forward-middle // GenesisState defines the packetforward genesis state message GenesisState { +<<<<<<< HEAD Params params = 1 [ (gogoproto.nullable) = false ]; +======= +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) // key - information about forwarded packet: src_channel // (parsedReceiver.Channel), src_port (parsedReceiver.Port), sequence value - // information about original packet for refunding if necessary: retries, @@ -18,6 +21,7 @@ message GenesisState { ]; } +<<<<<<< HEAD // Params defines the set of packetforward parameters. message Params { string fee_percentage = 1 [ @@ -27,6 +31,8 @@ message Params { ]; } +======= +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) // InFlightPacket contains information about original packet for // writing the acknowledgement and refunding if necessary. message InFlightPacket { diff --git a/middleware/packet-forward-middleware/test/mock/bank_keeper.go b/middleware/packet-forward-middleware/test/mock/bank_keeper.go index c0391f38..181c0f2d 100644 --- a/middleware/packet-forward-middleware/test/mock/bank_keeper.go +++ b/middleware/packet-forward-middleware/test/mock/bank_keeper.go @@ -1,10 +1,20 @@ // Code generated by MockGen. DO NOT EDIT. +<<<<<<< HEAD // Source: github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v5/packetforward/types (interfaces: BankKeeper) +======= +// Source: github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types (interfaces: BankKeeper) +// +// Generated by this command: +// +// mockgen -package=mock -destination=./test/mock/bank_keeper.go github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types BankKeeper +// +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) // Package mock is a generated GoMock package. package mock import ( + context "context" reflect "reflect" types "github.com/cosmos/cosmos-sdk/types" @@ -43,7 +53,7 @@ func (m *MockBankKeeper) BurnCoins(arg0 types.Context, arg1 string, arg2 types.C } // BurnCoins indicates an expected call of BurnCoins. -func (mr *MockBankKeeperMockRecorder) BurnCoins(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockBankKeeperMockRecorder) BurnCoins(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BurnCoins", reflect.TypeOf((*MockBankKeeper)(nil).BurnCoins), arg0, arg1, arg2) } @@ -57,7 +67,7 @@ func (m *MockBankKeeper) MintCoins(arg0 types.Context, arg1 string, arg2 types.C } // MintCoins indicates an expected call of MintCoins. -func (mr *MockBankKeeperMockRecorder) MintCoins(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockBankKeeperMockRecorder) MintCoins(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "MintCoins", reflect.TypeOf((*MockBankKeeper)(nil).MintCoins), arg0, arg1, arg2) } @@ -71,7 +81,7 @@ func (m *MockBankKeeper) SendCoins(arg0 types.Context, arg1, arg2 types.AccAddre } // SendCoins indicates an expected call of SendCoins. -func (mr *MockBankKeeperMockRecorder) SendCoins(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +func (mr *MockBankKeeperMockRecorder) SendCoins(arg0, arg1, arg2, arg3 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoins", reflect.TypeOf((*MockBankKeeper)(nil).SendCoins), arg0, arg1, arg2, arg3) } @@ -85,7 +95,7 @@ func (m *MockBankKeeper) SendCoinsFromAccountToModule(arg0 types.Context, arg1 t } // SendCoinsFromAccountToModule indicates an expected call of SendCoinsFromAccountToModule. -func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +func (mr *MockBankKeeperMockRecorder) SendCoinsFromAccountToModule(arg0, arg1, arg2, arg3 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromAccountToModule", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromAccountToModule), arg0, arg1, arg2, arg3) } @@ -99,7 +109,7 @@ func (m *MockBankKeeper) SendCoinsFromModuleToAccount(arg0 types.Context, arg1 s } // SendCoinsFromModuleToAccount indicates an expected call of SendCoinsFromModuleToAccount. -func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToAccount(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +func (mr *MockBankKeeperMockRecorder) SendCoinsFromModuleToAccount(arg0, arg1, arg2, arg3 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendCoinsFromModuleToAccount", reflect.TypeOf((*MockBankKeeper)(nil).SendCoinsFromModuleToAccount), arg0, arg1, arg2, arg3) } diff --git a/middleware/packet-forward-middleware/test/mock/channel_keeper.go b/middleware/packet-forward-middleware/test/mock/channel_keeper.go index ee4971f2..35e27078 100644 --- a/middleware/packet-forward-middleware/test/mock/channel_keeper.go +++ b/middleware/packet-forward-middleware/test/mock/channel_keeper.go @@ -1,5 +1,14 @@ // Code generated by MockGen. DO NOT EDIT. +<<<<<<< HEAD // Source: github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v5/packetforward/types (interfaces: ChannelKeeper) +======= +// Source: github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types (interfaces: ChannelKeeper) +// +// Generated by this command: +// +// mockgen -package=mock -destination=./test/mock/channel_keeper.go github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types ChannelKeeper +// +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) // Package mock is a generated GoMock package. package mock @@ -46,7 +55,7 @@ func (m *MockChannelKeeper) GetChannel(arg0 types.Context, arg1, arg2 string) (t } // GetChannel indicates an expected call of GetChannel. -func (mr *MockChannelKeeperMockRecorder) GetChannel(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockChannelKeeperMockRecorder) GetChannel(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChannel", reflect.TypeOf((*MockChannelKeeper)(nil).GetChannel), arg0, arg1, arg2) } @@ -61,7 +70,7 @@ func (m *MockChannelKeeper) GetNextSequenceSend(arg0 types.Context, arg1, arg2 s } // GetNextSequenceSend indicates an expected call of GetNextSequenceSend. -func (mr *MockChannelKeeperMockRecorder) GetNextSequenceSend(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockChannelKeeperMockRecorder) GetNextSequenceSend(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNextSequenceSend", reflect.TypeOf((*MockChannelKeeper)(nil).GetNextSequenceSend), arg0, arg1, arg2) } @@ -75,7 +84,7 @@ func (m *MockChannelKeeper) GetPacketCommitment(arg0 types.Context, arg1, arg2 s } // GetPacketCommitment indicates an expected call of GetPacketCommitment. -func (mr *MockChannelKeeperMockRecorder) GetPacketCommitment(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +func (mr *MockChannelKeeperMockRecorder) GetPacketCommitment(arg0, arg1, arg2, arg3 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPacketCommitment", reflect.TypeOf((*MockChannelKeeper)(nil).GetPacketCommitment), arg0, arg1, arg2, arg3) } @@ -91,7 +100,7 @@ func (m *MockChannelKeeper) LookupModuleByChannel(arg0 types.Context, arg1, arg2 } // LookupModuleByChannel indicates an expected call of LookupModuleByChannel. -func (mr *MockChannelKeeperMockRecorder) LookupModuleByChannel(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockChannelKeeperMockRecorder) LookupModuleByChannel(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LookupModuleByChannel", reflect.TypeOf((*MockChannelKeeper)(nil).LookupModuleByChannel), arg0, arg1, arg2) } diff --git a/middleware/packet-forward-middleware/test/mock/ibc_module.go b/middleware/packet-forward-middleware/test/mock/ibc_module.go index e4b5e96d..9137cf55 100644 --- a/middleware/packet-forward-middleware/test/mock/ibc_module.go +++ b/middleware/packet-forward-middleware/test/mock/ibc_module.go @@ -1,5 +1,14 @@ // Code generated by MockGen. DO NOT EDIT. +<<<<<<< HEAD // Source: github.com/cosmos/ibc-go/v5/modules/core/05-port/types (interfaces: IBCModule) +======= +// Source: github.com/cosmos/ibc-go/v8/modules/core/05-port/types (interfaces: IBCModule) +// +// Generated by this command: +// +// mockgen -package=mock -destination=./test/mock/ibc_module.go github.com/cosmos/ibc-go/v8/modules/core/05-port/types IBCModule +// +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) // Package mock is a generated GoMock package. package mock @@ -46,7 +55,7 @@ func (m *MockIBCModule) OnAcknowledgementPacket(arg0 types.Context, arg1 types1. } // OnAcknowledgementPacket indicates an expected call of OnAcknowledgementPacket. -func (mr *MockIBCModuleMockRecorder) OnAcknowledgementPacket(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +func (mr *MockIBCModuleMockRecorder) OnAcknowledgementPacket(arg0, arg1, arg2, arg3 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnAcknowledgementPacket", reflect.TypeOf((*MockIBCModule)(nil).OnAcknowledgementPacket), arg0, arg1, arg2, arg3) } @@ -60,7 +69,7 @@ func (m *MockIBCModule) OnChanCloseConfirm(arg0 types.Context, arg1, arg2 string } // OnChanCloseConfirm indicates an expected call of OnChanCloseConfirm. -func (mr *MockIBCModuleMockRecorder) OnChanCloseConfirm(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockIBCModuleMockRecorder) OnChanCloseConfirm(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnChanCloseConfirm", reflect.TypeOf((*MockIBCModule)(nil).OnChanCloseConfirm), arg0, arg1, arg2) } @@ -74,7 +83,7 @@ func (m *MockIBCModule) OnChanCloseInit(arg0 types.Context, arg1, arg2 string) e } // OnChanCloseInit indicates an expected call of OnChanCloseInit. -func (mr *MockIBCModuleMockRecorder) OnChanCloseInit(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockIBCModuleMockRecorder) OnChanCloseInit(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnChanCloseInit", reflect.TypeOf((*MockIBCModule)(nil).OnChanCloseInit), arg0, arg1, arg2) } @@ -88,7 +97,7 @@ func (m *MockIBCModule) OnChanOpenAck(arg0 types.Context, arg1, arg2, arg3, arg4 } // OnChanOpenAck indicates an expected call of OnChanOpenAck. -func (mr *MockIBCModuleMockRecorder) OnChanOpenAck(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { +func (mr *MockIBCModuleMockRecorder) OnChanOpenAck(arg0, arg1, arg2, arg3, arg4 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnChanOpenAck", reflect.TypeOf((*MockIBCModule)(nil).OnChanOpenAck), arg0, arg1, arg2, arg3, arg4) } @@ -102,7 +111,7 @@ func (m *MockIBCModule) OnChanOpenConfirm(arg0 types.Context, arg1, arg2 string) } // OnChanOpenConfirm indicates an expected call of OnChanOpenConfirm. -func (mr *MockIBCModuleMockRecorder) OnChanOpenConfirm(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockIBCModuleMockRecorder) OnChanOpenConfirm(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnChanOpenConfirm", reflect.TypeOf((*MockIBCModule)(nil).OnChanOpenConfirm), arg0, arg1, arg2) } @@ -117,7 +126,7 @@ func (m *MockIBCModule) OnChanOpenInit(arg0 types.Context, arg1 types1.Order, ar } // OnChanOpenInit indicates an expected call of OnChanOpenInit. -func (mr *MockIBCModuleMockRecorder) OnChanOpenInit(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 interface{}) *gomock.Call { +func (mr *MockIBCModuleMockRecorder) OnChanOpenInit(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnChanOpenInit", reflect.TypeOf((*MockIBCModule)(nil).OnChanOpenInit), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) } @@ -132,7 +141,7 @@ func (m *MockIBCModule) OnChanOpenTry(arg0 types.Context, arg1 types1.Order, arg } // OnChanOpenTry indicates an expected call of OnChanOpenTry. -func (mr *MockIBCModuleMockRecorder) OnChanOpenTry(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 interface{}) *gomock.Call { +func (mr *MockIBCModuleMockRecorder) OnChanOpenTry(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnChanOpenTry", reflect.TypeOf((*MockIBCModule)(nil).OnChanOpenTry), arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) } @@ -146,7 +155,7 @@ func (m *MockIBCModule) OnRecvPacket(arg0 types.Context, arg1 types1.Packet, arg } // OnRecvPacket indicates an expected call of OnRecvPacket. -func (mr *MockIBCModuleMockRecorder) OnRecvPacket(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockIBCModuleMockRecorder) OnRecvPacket(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnRecvPacket", reflect.TypeOf((*MockIBCModule)(nil).OnRecvPacket), arg0, arg1, arg2) } @@ -160,7 +169,7 @@ func (m *MockIBCModule) OnTimeoutPacket(arg0 types.Context, arg1 types1.Packet, } // OnTimeoutPacket indicates an expected call of OnTimeoutPacket. -func (mr *MockIBCModuleMockRecorder) OnTimeoutPacket(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockIBCModuleMockRecorder) OnTimeoutPacket(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "OnTimeoutPacket", reflect.TypeOf((*MockIBCModule)(nil).OnTimeoutPacket), arg0, arg1, arg2) } diff --git a/middleware/packet-forward-middleware/test/mock/ics4_wrapper.go b/middleware/packet-forward-middleware/test/mock/ics4_wrapper.go index 434951c0..d66e2920 100644 --- a/middleware/packet-forward-middleware/test/mock/ics4_wrapper.go +++ b/middleware/packet-forward-middleware/test/mock/ics4_wrapper.go @@ -1,5 +1,14 @@ // Code generated by MockGen. DO NOT EDIT. +<<<<<<< HEAD // Source: github.com/cosmos/ibc-go/v5/modules/core/05-port/types (interfaces: ICS4Wrapper) +======= +// Source: github.com/cosmos/ibc-go/v8/modules/core/05-port/types (interfaces: ICS4Wrapper) +// +// Generated by this command: +// +// mockgen -package=mock -destination=./test/mock/ics4_wrapper.go github.com/cosmos/ibc-go/v8/modules/core/05-port/types ICS4Wrapper +// +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) // Package mock is a generated GoMock package. package mock @@ -46,7 +55,7 @@ func (m *MockICS4Wrapper) GetAppVersion(arg0 types.Context, arg1, arg2 string) ( } // GetAppVersion indicates an expected call of GetAppVersion. -func (mr *MockICS4WrapperMockRecorder) GetAppVersion(arg0, arg1, arg2 interface{}) *gomock.Call { +func (mr *MockICS4WrapperMockRecorder) GetAppVersion(arg0, arg1, arg2 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAppVersion", reflect.TypeOf((*MockICS4Wrapper)(nil).GetAppVersion), arg0, arg1, arg2) } @@ -60,7 +69,11 @@ func (m *MockICS4Wrapper) SendPacket(arg0 types.Context, arg1 *types0.Capability } // SendPacket indicates an expected call of SendPacket. +<<<<<<< HEAD func (mr *MockICS4WrapperMockRecorder) SendPacket(arg0, arg1, arg2 interface{}) *gomock.Call { +======= +func (mr *MockICS4WrapperMockRecorder) SendPacket(arg0, arg1, arg2, arg3, arg4, arg5, arg6 any) *gomock.Call { +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendPacket", reflect.TypeOf((*MockICS4Wrapper)(nil).SendPacket), arg0, arg1, arg2) } @@ -74,7 +87,7 @@ func (m *MockICS4Wrapper) WriteAcknowledgement(arg0 types.Context, arg1 *types0. } // WriteAcknowledgement indicates an expected call of WriteAcknowledgement. -func (mr *MockICS4WrapperMockRecorder) WriteAcknowledgement(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { +func (mr *MockICS4WrapperMockRecorder) WriteAcknowledgement(arg0, arg1, arg2, arg3 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WriteAcknowledgement", reflect.TypeOf((*MockICS4Wrapper)(nil).WriteAcknowledgement), arg0, arg1, arg2, arg3) } diff --git a/middleware/packet-forward-middleware/test/mock/transfer_keeper.go b/middleware/packet-forward-middleware/test/mock/transfer_keeper.go index e297b63b..9287d8f8 100644 --- a/middleware/packet-forward-middleware/test/mock/transfer_keeper.go +++ b/middleware/packet-forward-middleware/test/mock/transfer_keeper.go @@ -1,5 +1,14 @@ // Code generated by MockGen. DO NOT EDIT. +<<<<<<< HEAD // Source: github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v5/packetforward/types (interfaces: TransferKeeper) +======= +// Source: github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types (interfaces: TransferKeeper) +// +// Generated by this command: +// +// mockgen -package=mock -destination=./test/mock/transfer_keeper.go github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types TransferKeeper +// +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) // Package mock is a generated GoMock package. package mock @@ -46,11 +55,40 @@ func (m *MockTransferKeeper) DenomPathFromHash(arg0 types.Context, arg1 string) } // DenomPathFromHash indicates an expected call of DenomPathFromHash. -func (mr *MockTransferKeeperMockRecorder) DenomPathFromHash(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockTransferKeeperMockRecorder) DenomPathFromHash(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DenomPathFromHash", reflect.TypeOf((*MockTransferKeeper)(nil).DenomPathFromHash), arg0, arg1) } +<<<<<<< HEAD +======= +// GetTotalEscrowForDenom mocks base method. +func (m *MockTransferKeeper) GetTotalEscrowForDenom(arg0 types.Context, arg1 string) types.Coin { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetTotalEscrowForDenom", arg0, arg1) + ret0, _ := ret[0].(types.Coin) + return ret0 +} + +// GetTotalEscrowForDenom indicates an expected call of GetTotalEscrowForDenom. +func (mr *MockTransferKeeperMockRecorder) GetTotalEscrowForDenom(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTotalEscrowForDenom", reflect.TypeOf((*MockTransferKeeper)(nil).GetTotalEscrowForDenom), arg0, arg1) +} + +// SetTotalEscrowForDenom mocks base method. +func (m *MockTransferKeeper) SetTotalEscrowForDenom(arg0 types.Context, arg1 types.Coin) { + m.ctrl.T.Helper() + m.ctrl.Call(m, "SetTotalEscrowForDenom", arg0, arg1) +} + +// SetTotalEscrowForDenom indicates an expected call of SetTotalEscrowForDenom. +func (mr *MockTransferKeeperMockRecorder) SetTotalEscrowForDenom(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetTotalEscrowForDenom", reflect.TypeOf((*MockTransferKeeper)(nil).SetTotalEscrowForDenom), arg0, arg1) +} + +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) // Transfer mocks base method. func (m *MockTransferKeeper) Transfer(arg0 context.Context, arg1 *types0.MsgTransfer) (*types0.MsgTransferResponse, error) { m.ctrl.T.Helper() @@ -61,7 +99,7 @@ func (m *MockTransferKeeper) Transfer(arg0 context.Context, arg1 *types0.MsgTran } // Transfer indicates an expected call of Transfer. -func (mr *MockTransferKeeperMockRecorder) Transfer(arg0, arg1 interface{}) *gomock.Call { +func (mr *MockTransferKeeperMockRecorder) Transfer(arg0, arg1 any) *gomock.Call { mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Transfer", reflect.TypeOf((*MockTransferKeeper)(nil).Transfer), arg0, arg1) } diff --git a/middleware/packet-forward-middleware/test/setup.go b/middleware/packet-forward-middleware/test/setup.go index d3cb11c5..f9676f82 100644 --- a/middleware/packet-forward-middleware/test/setup.go +++ b/middleware/packet-forward-middleware/test/setup.go @@ -19,8 +19,6 @@ import ( "github.com/cosmos/cosmos-sdk/store" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" - paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" porttypes "github.com/cosmos/ibc-go/v5/modules/core/05-port/types" ) @@ -32,32 +30,38 @@ func NewTestSetup(t *testing.T, ctl *gomock.Controller) *Setup { transferKeeperMock := mock.NewMockTransferKeeper(ctl) channelKeeperMock := mock.NewMockChannelKeeper(ctl) - distributionKeeperMock := mock.NewMockDistributionKeeper(ctl) bankKeeperMock := mock.NewMockBankKeeper(ctl) ibcModuleMock := mock.NewMockIBCModule(ctl) ics4WrapperMock := mock.NewMockICS4Wrapper(ctl) - paramsKeeper := initializer.paramsKeeper() - packetforwardKeeper := initializer.packetforwardKeeper(paramsKeeper, transferKeeperMock, channelKeeperMock, distributionKeeperMock, bankKeeperMock, ics4WrapperMock) + packetforwardKeeper := initializer.packetforwardKeeper(transferKeeperMock, channelKeeperMock, bankKeeperMock, ics4WrapperMock) require.NoError(t, initializer.StateStore.LoadLatestVersion()) +<<<<<<< HEAD packetforwardKeeper.SetParams(initializer.Ctx, types.DefaultParams()) +======= +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) return &Setup{ Initializer: initializer, Keepers: &testKeepers{ - ParamsKeeper: ¶msKeeper, PacketForwardKeeper: packetforwardKeeper, }, Mocks: &testMocks{ +<<<<<<< HEAD TransferKeeperMock: transferKeeperMock, ChannelKeeperMock: channelKeeperMock, DistributionKeeperMock: distributionKeeperMock, IBCModuleMock: ibcModuleMock, ICS4WrapperMock: ics4WrapperMock, +======= + TransferKeeperMock: transferKeeperMock, + IBCModuleMock: ibcModuleMock, + ICS4WrapperMock: ics4WrapperMock, +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) }, ForwardMiddleware: initializer.forwardMiddleware(ibcModuleMock, packetforwardKeeper, 0, keeper.DefaultForwardTransferPacketTimeoutTimestamp, keeper.DefaultRefundTransferPacketTimeoutTimestamp), @@ -74,16 +78,21 @@ type Setup struct { } type testKeepers struct { - ParamsKeeper *paramskeeper.Keeper PacketForwardKeeper *keeper.Keeper } type testMocks struct { +<<<<<<< HEAD TransferKeeperMock *mock.MockTransferKeeper ChannelKeeperMock *mock.MockChannelKeeper DistributionKeeperMock *mock.MockDistributionKeeper IBCModuleMock *mock.MockIBCModule ICS4WrapperMock *mock.MockICS4Wrapper +======= + TransferKeeperMock *mock.MockTransferKeeper + IBCModuleMock *mock.MockIBCModule + ICS4WrapperMock *mock.MockICS4Wrapper +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) } type initializer struct { @@ -116,6 +125,7 @@ func newInitializer() initializer { } } +<<<<<<< HEAD func (i initializer) paramsKeeper() paramskeeper.Keeper { storeKey := sdk.NewKVStoreKey(paramstypes.StoreKey) transientStoreKey := sdk.NewTransientStoreKey(paramstypes.TStoreKey) @@ -127,11 +137,11 @@ func (i initializer) paramsKeeper() paramskeeper.Keeper { return paramsKeeper } +======= +>>>>>>> 26d8080 (refactor: remove the ability to take a fee for each forwarded packet (#202)) func (i initializer) packetforwardKeeper( - paramsKeeper paramskeeper.Keeper, transferKeeper types.TransferKeeper, channelKeeper types.ChannelKeeper, - distributionKeeper types.DistributionKeeper, bankKeeper types.BankKeeper, ics4Wrapper porttypes.ICS4Wrapper, ) *keeper.Keeper { @@ -145,7 +155,6 @@ func (i initializer) packetforwardKeeper( subspace, transferKeeper, channelKeeper, - distributionKeeper, bankKeeper, ics4Wrapper, ) diff --git a/middleware/packet-forward-middleware/testing/simapp/app.go b/middleware/packet-forward-middleware/testing/simapp/app.go new file mode 100644 index 00000000..a00e367a --- /dev/null +++ b/middleware/packet-forward-middleware/testing/simapp/app.go @@ -0,0 +1,1029 @@ +package simapp + +import ( + "encoding/json" + "io" + "net/http" + "os" + "path/filepath" + + dbm "github.com/cosmos/cosmos-db" + "github.com/cosmos/gogoproto/proto" + "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward" + packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/keeper" + packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/types" + "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/testing/simapp/upgrades" + "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/testing/simapp/x/dummyware" + "github.com/gorilla/mux" + "github.com/rakyll/statik/fs" + "github.com/spf13/cast" + "github.com/stretchr/testify/require" + + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" + "cosmossdk.io/client/v2/autocli" + "cosmossdk.io/core/appmodule" + "cosmossdk.io/log" + storetypes "cosmossdk.io/store/types" + "cosmossdk.io/x/evidence" + evidencekeeper "cosmossdk.io/x/evidence/keeper" + evidencetypes "cosmossdk.io/x/evidence/types" + "cosmossdk.io/x/feegrant" + feegrantkeeper "cosmossdk.io/x/feegrant/keeper" + feegrantmodule "cosmossdk.io/x/feegrant/module" + "cosmossdk.io/x/tx/signing" + "cosmossdk.io/x/upgrade" + upgradekeeper "cosmossdk.io/x/upgrade/keeper" + upgradetypes "cosmossdk.io/x/upgrade/types" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/grpc/cmtservice" + nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/address" + "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/runtime" + runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services" + "github.com/cosmos/cosmos-sdk/server" + "github.com/cosmos/cosmos-sdk/server/api" + "github.com/cosmos/cosmos-sdk/server/config" + servertypes "github.com/cosmos/cosmos-sdk/server/types" + "github.com/cosmos/cosmos-sdk/std" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + "github.com/cosmos/cosmos-sdk/version" + "github.com/cosmos/cosmos-sdk/x/auth" + "github.com/cosmos/cosmos-sdk/x/auth/ante" + authcodec "github.com/cosmos/cosmos-sdk/x/auth/codec" + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" + authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/auth/vesting" + vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" + "github.com/cosmos/cosmos-sdk/x/authz" + authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" + authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" + "github.com/cosmos/cosmos-sdk/x/bank" + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/consensus" + consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" + consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" + "github.com/cosmos/cosmos-sdk/x/crisis" + crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" + distr "github.com/cosmos/cosmos-sdk/x/distribution" + distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/cosmos/cosmos-sdk/x/genutil" + genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + "github.com/cosmos/cosmos-sdk/x/gov" + govclient "github.com/cosmos/cosmos-sdk/x/gov/client" + govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" + "github.com/cosmos/cosmos-sdk/x/group" + groupkeeper "github.com/cosmos/cosmos-sdk/x/group/keeper" + groupmodule "github.com/cosmos/cosmos-sdk/x/group/module" + "github.com/cosmos/cosmos-sdk/x/mint" + mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" + minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" + "github.com/cosmos/cosmos-sdk/x/params" + paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal" + "github.com/cosmos/cosmos-sdk/x/slashing" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" + "github.com/cosmos/cosmos-sdk/x/staking" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + + abci "github.com/cometbft/cometbft/abci/types" + tmos "github.com/cometbft/cometbft/libs/os" + + "github.com/cosmos/ibc-go/modules/capability" + capabilitykeeper "github.com/cosmos/ibc-go/modules/capability/keeper" + capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" + ibcfee "github.com/cosmos/ibc-go/v8/modules/apps/29-fee" + ibcfeekeeper "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/keeper" + ibcfeetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types" + "github.com/cosmos/ibc-go/v8/modules/apps/transfer" + ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper" + ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" + ibc "github.com/cosmos/ibc-go/v8/modules/core" + ibcporttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types" + ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" + ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper" + solomachine "github.com/cosmos/ibc-go/v8/modules/light-clients/06-solomachine" + ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" + ibctesting "github.com/cosmos/ibc-go/v8/testing" + ibcmock "github.com/cosmos/ibc-go/v8/testing/mock" + ibctestingtypes "github.com/cosmos/ibc-go/v8/testing/types" +) + +// IBC application testing ports +const ( + appName = "SimApp" + + MockFeePort string = ibcmock.ModuleName + ibcfeetypes.ModuleName +) + +var ( + // DefaultNodeHome default home directories for the application daemon + DefaultNodeHome string + + // ModuleBasics defines the module BasicManager is in charge of setting up basic, + // non-dependant module elements, such as codec registration + // and genesis verification. + ModuleBasics = module.NewBasicManager( + auth.AppModuleBasic{}, + genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), + bank.AppModuleBasic{}, + capability.AppModuleBasic{}, + staking.AppModuleBasic{}, + mint.AppModuleBasic{}, + distr.AppModuleBasic{}, + gov.NewAppModuleBasic( + []govclient.ProposalHandler{ + paramsclient.ProposalHandler, + }, + ), + groupmodule.AppModuleBasic{}, + params.AppModuleBasic{}, + crisis.AppModuleBasic{}, + slashing.AppModuleBasic{}, + feegrantmodule.AppModuleBasic{}, + upgrade.AppModuleBasic{}, + evidence.AppModuleBasic{}, + authzmodule.AppModuleBasic{}, + vesting.AppModuleBasic{}, + consensus.AppModuleBasic{}, + + // non standard + ibc.AppModuleBasic{}, + ibctm.AppModuleBasic{}, + solomachine.AppModuleBasic{}, + packetforward.AppModuleBasic{}, + transfer.AppModuleBasic{}, + ) + + // module account permissions + maccPerms = map[string][]string{ + authtypes.FeeCollectorName: nil, + distrtypes.ModuleName: nil, + ibcfeetypes.ModuleName: nil, + minttypes.ModuleName: {authtypes.Minter}, + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + govtypes.ModuleName: {authtypes.Burner}, + ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + } +) + +var ( + _ servertypes.Application = (*SimApp)(nil) + _ runtime.AppI = (*SimApp)(nil) +) + +// SimApp extends an ABCI application, but with most of its parameters exported. +// They are exported for convenience in creating helper functions, as object +// capabilities aren't needed for testing. +type SimApp struct { + *baseapp.BaseApp + legacyAmino *codec.LegacyAmino + appCodec codec.Codec + txConfig client.TxConfig + interfaceRegistry types.InterfaceRegistry + + invCheckPeriod uint + + // keys to access the substores + keys map[string]*storetypes.KVStoreKey + tkeys map[string]*storetypes.TransientStoreKey + memKeys map[string]*storetypes.MemoryStoreKey + + // keepers + AccountKeeper authkeeper.AccountKeeper + BankKeeper bankkeeper.Keeper + CapabilityKeeper *capabilitykeeper.Keeper + StakingKeeper *stakingkeeper.Keeper + SlashingKeeper slashingkeeper.Keeper + MintKeeper mintkeeper.Keeper + DistrKeeper distrkeeper.Keeper + GovKeeper govkeeper.Keeper + GroupKeeper groupkeeper.Keeper + CrisisKeeper *crisiskeeper.Keeper + UpgradeKeeper *upgradekeeper.Keeper + ParamsKeeper paramskeeper.Keeper + AuthzKeeper authzkeeper.Keeper + IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly + IBCFeeKeeper ibcfeekeeper.Keeper + PacketForwardKeeper *packetforwardkeeper.Keeper + EvidenceKeeper evidencekeeper.Keeper + TransferKeeper ibctransferkeeper.Keeper + FeeGrantKeeper feegrantkeeper.Keeper + ConsensusParamsKeeper consensusparamkeeper.Keeper + + // make scoped keepers public for test purposes + ScopedIBCKeeper capabilitykeeper.ScopedKeeper + ScopedTransferKeeper capabilitykeeper.ScopedKeeper + + // the module manager + mm *module.Manager + BasicModuleManager module.BasicManager + + // simulation manager + sm *module.SimulationManager + + // the configurator + configurator module.Configurator +} + +func init() { + userHomeDir, err := os.UserHomeDir() + if err != nil { + panic(err) + } + + DefaultNodeHome = filepath.Join(userHomeDir, ".simapp") +} + +// NewSimApp returns a reference to an initialized SimApp. +func NewSimApp( + logger log.Logger, + db dbm.DB, + traceStore io.Writer, + loadLatest bool, + appOpts servertypes.AppOptions, + baseAppOptions ...func(*baseapp.BaseApp), +) *SimApp { + interfaceRegistry, _ := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{ + ProtoFiles: proto.HybridResolver, + SigningOptions: signing.Options{ + AddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32AccountAddrPrefix(), + }, + ValidatorAddressCodec: address.Bech32Codec{ + Bech32Prefix: sdk.GetConfig().GetBech32ValidatorAddrPrefix(), + }, + }, + }) + appCodec := codec.NewProtoCodec(interfaceRegistry) + legacyAmino := codec.NewLegacyAmino() + txConfig := authtx.NewTxConfig(appCodec, authtx.DefaultSignModes) + + std.RegisterLegacyAminoCodec(legacyAmino) + std.RegisterInterfaces(interfaceRegistry) + + // Below we could construct and set an application specific mempool and ABCI 1.0 Prepare and Process Proposal + // handlers. These defaults are already set in the SDK's BaseApp, this shows an example of how to override + // them. + // + // nonceMempool := mempool.NewSenderNonceMempool() + // mempoolOpt := baseapp.SetMempool(nonceMempool) + // prepareOpt := func(app *baseapp.BaseApp) { + // app.SetPrepareProposal(app.DefaultPrepareProposal()) + // } + // processOpt := func(app *baseapp.BaseApp) { + // app.SetProcessProposal(app.DefaultProcessProposal()) + // } + // + // Further down we'd set the options in the AppBuilder like below. + // baseAppOptions = append(baseAppOptions, mempoolOpt, prepareOpt, processOpt) + + authority := authtypes.NewModuleAddress(govtypes.ModuleName).String() + + bApp := baseapp.NewBaseApp(appName, logger, db, txConfig.TxDecoder(), baseAppOptions...) + bApp.SetCommitMultiStoreTracer(traceStore) + bApp.SetVersion(version.Version) + bApp.SetInterfaceRegistry(interfaceRegistry) + bApp.SetTxEncoder(txConfig.TxEncoder()) + + keys := storetypes.NewKVStoreKeys( + authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, crisistypes.StoreKey, + minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey, + govtypes.StoreKey, group.StoreKey, paramstypes.StoreKey, consensusparamtypes.StoreKey, ibcexported.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey, + evidencetypes.StoreKey, ibcfeetypes.StoreKey, packetforwardtypes.StoreKey, ibctransfertypes.StoreKey, authzkeeper.StoreKey, capabilitytypes.StoreKey, + ) + tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey) + // NOTE: The testingkey is just mounted for testing purposes. Actual applications should + // not include this key. + memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) + + // load state streaming if enabled + if err := bApp.RegisterStreamingServices(appOpts, keys); err != nil { + panic(err) + } + + homePath := cast.ToString(appOpts.Get(flags.FlagHome)) + invCheckPeriod := cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)) + + skipUpgradeHeights := map[int64]bool{} + for _, h := range cast.ToIntSlice(appOpts.Get(server.FlagUnsafeSkipUpgrades)) { + skipUpgradeHeights[int64(h)] = true + } + + app := &SimApp{ + BaseApp: bApp, + legacyAmino: legacyAmino, + appCodec: appCodec, + txConfig: txConfig, + interfaceRegistry: interfaceRegistry, + invCheckPeriod: invCheckPeriod, + keys: keys, + tkeys: tkeys, + memKeys: memKeys, + } + + app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) + + // set the BaseApp's parameter store + app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper( + appCodec, + runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + runtime.EventService{}, + ) + bApp.SetParamStore(app.ConsensusParamsKeeper.ParamsStore) + + // add capability keeper and ScopeToModule for ibc module + app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey]) + scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName) + scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) + + // seal capability keeper after scoping modules + app.CapabilityKeeper.Seal() + + // SDK module keepers + + app.AccountKeeper = authkeeper.NewAccountKeeper( + appCodec, + runtime.NewKVStoreService(keys[authtypes.StoreKey]), + authtypes.ProtoBaseAccount, + maccPerms, + authcodec.NewBech32Codec(sdk.Bech32MainPrefix), + sdk.Bech32MainPrefix, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + app.BankKeeper = bankkeeper.NewBaseKeeper( + appCodec, + runtime.NewKVStoreService(keys[banktypes.StoreKey]), + app.AccountKeeper, + app.ModuleAccountAddrs(), + authority, + logger, + ) + app.StakingKeeper = stakingkeeper.NewKeeper( + appCodec, + runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), + app.AccountKeeper, + app.BankKeeper, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + authcodec.NewBech32Codec(sdk.Bech32PrefixValAddr), + authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), + ) + app.MintKeeper = mintkeeper.NewKeeper( + appCodec, + runtime.NewKVStoreService(keys[minttypes.StoreKey]), + app.StakingKeeper, + app.AccountKeeper, + app.BankKeeper, + authtypes.FeeCollectorName, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + app.DistrKeeper = distrkeeper.NewKeeper( + appCodec, + runtime.NewKVStoreService(keys[distrtypes.StoreKey]), + app.AccountKeeper, + app.BankKeeper, + app.StakingKeeper, + authtypes.FeeCollectorName, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + app.SlashingKeeper = slashingkeeper.NewKeeper( + appCodec, + legacyAmino, + runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), + app.StakingKeeper, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + app.CrisisKeeper = crisiskeeper.NewKeeper( + appCodec, + runtime.NewKVStoreService(keys[crisistypes.StoreKey]), + invCheckPeriod, + app.BankKeeper, + authtypes.FeeCollectorName, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + app.AccountKeeper.AddressCodec(), + ) + app.FeeGrantKeeper = feegrantkeeper.NewKeeper( + appCodec, + runtime.NewKVStoreService(keys[feegrant.StoreKey]), + app.AccountKeeper, + ) + app.UpgradeKeeper = upgradekeeper.NewKeeper( + skipUpgradeHeights, + runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), + appCodec, + homePath, + app.BaseApp, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + + // register the staking hooks + // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks + app.StakingKeeper.SetHooks( + stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()), + ) + + app.AuthzKeeper = authzkeeper.NewKeeper(runtime.NewKVStoreService(keys[authzkeeper.StoreKey]), appCodec, app.MsgServiceRouter(), app.AccountKeeper) + + // IBC Keepers + app.IBCKeeper = ibckeeper.NewKeeper( + appCodec, keys[ibcexported.StoreKey], + app.GetSubspace(ibcexported.ModuleName), + app.StakingKeeper, + app.UpgradeKeeper, + scopedIBCKeeper, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + + // Register the proposal types + // Deprecated: Avoid adding new handlers, instead use the new proposal flow + // by granting the governance module the right to execute the message. + // See: https://docs.cosmos.network/main/modules/gov#proposal-messages + govRouter := govv1beta1.NewRouter() + govRouter.AddRoute(govtypes.RouterKey, govv1beta1.ProposalHandler). + AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)) + govConfig := govtypes.DefaultConfig() + /* + Example of setting gov params: + govConfig.MaxMetadataLen = 10000 + */ + govKeeper := govkeeper.NewKeeper( + appCodec, + runtime.NewKVStoreService(keys[govtypes.StoreKey]), + app.AccountKeeper, + app.BankKeeper, + app.StakingKeeper, + app.DistrKeeper, + app.MsgServiceRouter(), + govConfig, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + + // Set legacy router for backwards compatibility with gov v1beta1 + govKeeper.SetLegacyRouter(govRouter) + + app.GovKeeper = *govKeeper.SetHooks( + govtypes.NewMultiGovHooks( + // register the governance hooks + ), + ) + + groupConfig := group.DefaultConfig() + groupConfig.MaxMetadataLen = 1000 + app.GroupKeeper = groupkeeper.NewKeeper(keys[group.StoreKey], appCodec, app.MsgServiceRouter(), app.AccountKeeper, groupConfig) + + // Create the packet forward middleware keeper + app.PacketForwardKeeper = packetforwardkeeper.NewKeeper( + appCodec, + app.keys[packetforwardtypes.StoreKey], + nil, // Will be zero-value here. Reference is set later on with SetTransferKeeper. + app.IBCKeeper.ChannelKeeper, + app.BankKeeper, + app.IBCKeeper.ChannelKeeper, + authority, + ) + + // create the IBC Router + ibcRouter := ibcporttypes.NewRouter() + + // IBC Fee Module keeper + app.IBCFeeKeeper = ibcfeekeeper.NewKeeper( + appCodec, + keys[ibcfeetypes.StoreKey], + app.IBCKeeper.ChannelKeeper, // may be replaced with IBC middleware + app.IBCKeeper.ChannelKeeper, + app.IBCKeeper.PortKeeper, + app.AccountKeeper, + app.BankKeeper, + ) + + // Transfer Keeper + app.TransferKeeper = ibctransferkeeper.NewKeeper( + appCodec, + keys[ibctransfertypes.StoreKey], + app.GetSubspace(ibctransfertypes.ModuleName), + app.IBCFeeKeeper, // ISC4 Wrapper: fee IBC middleware + app.IBCKeeper.ChannelKeeper, + app.IBCKeeper.PortKeeper, + app.AccountKeeper, + app.BankKeeper, + scopedTransferKeeper, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) + + app.PacketForwardKeeper.SetTransferKeeper(app.TransferKeeper) + + // Create Transfer Stack + var transferStack ibcporttypes.IBCModule + transferStack = transfer.NewIBCModule(app.TransferKeeper) + transferStack = ibcfee.NewIBCMiddleware(transferStack, app.IBCFeeKeeper) + + transferStack = packetforward.NewIBCMiddleware( + transferStack, + app.PacketForwardKeeper, + 0, // retries on timeout + packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp, // forward timeout + ) + + if os.Getenv("NON_REFUNDABLE_TEST") != "" { + transferStack = dummyware.NewIBCMiddleware(transferStack) + } + + // Add IBC Router + ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack) + + // Seal the IBC Router + app.IBCKeeper.SetRouter(ibcRouter) + + // create evidence keeper with router + evidenceKeeper := evidencekeeper.NewKeeper( + appCodec, + runtime.NewKVStoreService(keys[evidencetypes.StoreKey]), + app.StakingKeeper, + app.SlashingKeeper, + app.AccountKeeper.AddressCodec(), + runtime.ProvideCometInfoService(), + ) + // If evidence needs to be handled for the app, set routes in router here and seal + app.EvidenceKeeper = *evidenceKeeper + + /**** Module Options ****/ + + // NOTE: we may consider parsing `appOpts` inside module constructors. For the moment + // we prefer to be more strict in what arguments the modules expect. + skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)) + + // NOTE: Any module instantiated in the module manager that is later modified + // must be passed by reference here. + app.mm = module.NewManager( + // SDK app modules + genutil.NewAppModule(app.AccountKeeper, app.StakingKeeper, app, txConfig), + auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)), + vesting.NewAppModule(app.AccountKeeper, app.BankKeeper), + bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)), + capability.NewAppModule(appCodec, *app.CapabilityKeeper, false), + crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), + feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry), + gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)), + groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), + mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)), + slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName), app.interfaceRegistry), + distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)), + staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)), + upgrade.NewAppModule(app.UpgradeKeeper, app.AccountKeeper.AddressCodec()), + evidence.NewAppModule(app.EvidenceKeeper), + params.NewAppModule(app.ParamsKeeper), + authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), + consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper), + + // IBC modules + ibc.NewAppModule(app.IBCKeeper), + ibctm.NewAppModule(), + ibcfee.NewAppModule(app.IBCFeeKeeper), + packetforward.NewAppModule(app.PacketForwardKeeper, app.GetSubspace(packetforwardtypes.ModuleName)), + transfer.NewAppModule(app.TransferKeeper), + ) + + // BasicModuleManager defines the module BasicManager is in charge of setting up basic, + // non-dependant module elements, such as codec registration and genesis verification. + // By default it is composed of all the module from the module manager. + // Additionally, app module basics can be overwritten by passing them as argument. + app.BasicModuleManager = module.NewBasicManagerFromManager( + app.mm, + map[string]module.AppModuleBasic{ + genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), + govtypes.ModuleName: gov.NewAppModuleBasic( + []govclient.ProposalHandler{ + paramsclient.ProposalHandler, + }, + ), + }) + app.BasicModuleManager.RegisterLegacyAminoCodec(legacyAmino) + app.BasicModuleManager.RegisterInterfaces(interfaceRegistry) + + // During begin block slashing happens after distr.BeginBlocker so that + // there is nothing left over in the validator fee pool, so as to keep the + // CanWithdrawInvariant invariant. + // NOTE: staking module is required if HistoricalEntries param > 0 + // NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC) + app.mm.SetOrderBeginBlockers( + upgradetypes.ModuleName, + capabilitytypes.ModuleName, + minttypes.ModuleName, + distrtypes.ModuleName, + slashingtypes.ModuleName, + evidencetypes.ModuleName, + stakingtypes.ModuleName, + ibcexported.ModuleName, + packetforwardtypes.ModuleName, + ibctransfertypes.StoreKey, + authtypes.ModuleName, + banktypes.ModuleName, + govtypes.ModuleName, + crisistypes.ModuleName, + genutiltypes.ModuleName, + authz.ModuleName, + feegrant.ModuleName, + paramstypes.ModuleName, + vestingtypes.ModuleName, + ibcfeetypes.ModuleName, + group.ModuleName, + consensusparamtypes.ModuleName, + ) + app.mm.SetOrderEndBlockers( + crisistypes.ModuleName, + govtypes.ModuleName, + stakingtypes.ModuleName, + ibcexported.ModuleName, + packetforwardtypes.ModuleName, + ibctransfertypes.StoreKey, + capabilitytypes.ModuleName, + authtypes.ModuleName, + banktypes.ModuleName, + distrtypes.ModuleName, + slashingtypes.ModuleName, + minttypes.ModuleName, + genutiltypes.ModuleName, + evidencetypes.ModuleName, + authz.ModuleName, + feegrant.ModuleName, + paramstypes.ModuleName, + upgradetypes.ModuleName, + vestingtypes.ModuleName, + group.ModuleName, + ibcfeetypes.ModuleName, + consensusparamtypes.ModuleName, + ) + + // NOTE: The genutils module must occur after staking so that pools are + // properly initialized with tokens from genesis accounts. + // NOTE: The genutils module must also occur after auth so that it can access the params from auth. + // NOTE: Capability module must occur first so that it can initialize any capabilities + // so that other modules that want to create or claim capabilities afterwards in InitChain + // can do so safely. + genesisModuleOrder := []string{ + capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, distrtypes.ModuleName, stakingtypes.ModuleName, ibcexported.ModuleName, + slashingtypes.ModuleName, govtypes.ModuleName, minttypes.ModuleName, crisistypes.ModuleName, + genutiltypes.ModuleName, evidencetypes.ModuleName, authz.ModuleName, + packetforwardtypes.ModuleName, ibcfeetypes.ModuleName, ibctransfertypes.StoreKey, feegrant.ModuleName, paramstypes.ModuleName, upgradetypes.ModuleName, + vestingtypes.ModuleName, group.ModuleName, consensusparamtypes.ModuleName, + } + + app.mm.SetOrderInitGenesis(genesisModuleOrder...) + app.mm.SetOrderExportGenesis(genesisModuleOrder...) + + app.mm.RegisterInvariants(app.CrisisKeeper) + app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) + + if err := app.mm.RegisterServices(app.configurator); err != nil { + panic(err) + } + + // add test gRPC service for testing gRPC queries in isolation + autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.mm.Modules)) + + reflectionSvc, err := runtimeservices.NewReflectionService() + if err != nil { + panic(err) + } + reflectionv1.RegisterReflectionServiceServer(app.GRPCQueryRouter(), reflectionSvc) + + // create the simulation manager and define the order of the modules for deterministic simulations + // + // NOTE: this is not required apps that don't use the simulator for fuzz testing + // transactions + overrideModules := map[string]module.AppModuleSimulation{ + authtypes.ModuleName: auth.NewAppModule(app.appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)), + } + app.sm = module.NewSimulationManagerFromAppModules(app.mm.Modules, overrideModules) + + app.sm.RegisterStoreDecoders() + + // initialize stores + app.MountKVStores(keys) + app.MountTransientStores(tkeys) + app.MountMemoryStores(memKeys) + + // register upgrade + app.setupUpgradeHandlers() + app.setupUpgradeStoreLoaders() + + // initialize BaseApp + app.SetInitChainer(app.InitChainer) + app.SetBeginBlocker(app.BeginBlocker) + anteHandler, err := NewAnteHandler( + HandlerOptions{ + HandlerOptions: ante.HandlerOptions{ + AccountKeeper: app.AccountKeeper, + BankKeeper: app.BankKeeper, + SignModeHandler: txConfig.SignModeHandler(), + FeegrantKeeper: app.FeeGrantKeeper, + SigGasConsumer: ante.DefaultSigVerificationGasConsumer, + }, + IBCKeeper: app.IBCKeeper, + }, + ) + if err != nil { + panic(err) + } + + app.SetAnteHandler(anteHandler) + + app.SetEndBlocker(app.EndBlocker) + + if loadLatest { + if err := app.LoadLatestVersion(); err != nil { + tmos.Exit(err.Error()) + } + } + + app.ScopedIBCKeeper = scopedIBCKeeper + app.ScopedTransferKeeper = scopedTransferKeeper + + return app +} + +// Name returns the name of the App +func (app *SimApp) Name() string { return app.BaseApp.Name() } + +// BeginBlocker application updates every begin block +func (app *SimApp) BeginBlocker(ctx sdk.Context) (sdk.BeginBlock, error) { + return app.mm.BeginBlock(ctx) +} + +// EndBlocker application updates every end block +func (app *SimApp) EndBlocker(ctx sdk.Context) (sdk.EndBlock, error) { + return app.mm.EndBlock(ctx) +} + +// InitChainer application update at chain initialization +func (app *SimApp) InitChainer(ctx sdk.Context, req *abci.RequestInitChain) (*abci.ResponseInitChain, error) { + var genesisState GenesisState + if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil { + panic(err) + } + + if err := app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap()); err != nil { + panic(err) + } + + return app.mm.InitGenesis(ctx, app.appCodec, genesisState) +} + +// LoadHeight loads a particular height +func (app *SimApp) LoadHeight(height int64) error { + return app.LoadVersion(height) +} + +// ModuleAccountAddrs returns all the app's module account addresses. +func (app *SimApp) ModuleAccountAddrs() map[string]bool { + modAccAddrs := make(map[string]bool) + for acc := range maccPerms { + modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true + } + + return modAccAddrs +} + +// GetModuleManager returns the app module manager +// NOTE: used for testing purposes +func (app *SimApp) GetModuleManager() *module.Manager { + return app.mm +} + +// LegacyAmino returns SimApp's amino codec. +// +// NOTE: This is solely to be used for testing purposes as it may be desirable +// for modules to register their own custom testing types. +func (app *SimApp) LegacyAmino() *codec.LegacyAmino { + return app.legacyAmino +} + +// AppCodec returns SimApp's app codec. +// +// NOTE: This is solely to be used for testing purposes as it may be desirable +// for modules to register their own custom testing types. +func (app *SimApp) AppCodec() codec.Codec { + return app.appCodec +} + +func (app *SimApp) TxConfig() client.TxConfig { + return app.txConfig +} + +// InterfaceRegistry returns SimApp's InterfaceRegistry +func (app *SimApp) InterfaceRegistry() types.InterfaceRegistry { + return app.interfaceRegistry +} + +// GetKey returns the KVStoreKey for the provided store key. +// +// NOTE: This is solely to be used for testing purposes. +func (app *SimApp) GetKey(storeKey string) *storetypes.KVStoreKey { + return app.keys[storeKey] +} + +// GetTKey returns the TransientStoreKey for the provided store key. +// +// NOTE: This is solely to be used for testing purposes. +func (app *SimApp) GetTKey(storeKey string) *storetypes.TransientStoreKey { + return app.tkeys[storeKey] +} + +// GetMemKey returns the MemStoreKey for the provided mem key. +// +// NOTE: This is solely used for testing purposes. +func (app *SimApp) GetMemKey(storeKey string) *storetypes.MemoryStoreKey { + return app.memKeys[storeKey] +} + +// GetSubspace returns a param subspace for a given module name. +// +// NOTE: This is solely to be used for testing purposes. +func (app *SimApp) GetSubspace(moduleName string) paramstypes.Subspace { + subspace, _ := app.ParamsKeeper.GetSubspace(moduleName) + return subspace +} + +// TestingApp functions + +// GetBaseApp implements the TestingApp interface. +func (app *SimApp) GetBaseApp() *baseapp.BaseApp { + return app.BaseApp +} + +// GetStakingKeeper implements the TestingApp interface. +func (app *SimApp) GetStakingKeeper() ibctestingtypes.StakingKeeper { + return app.StakingKeeper +} + +// GetIBCKeeper implements the TestingApp interface. +func (app *SimApp) GetIBCKeeper() *ibckeeper.Keeper { + return app.IBCKeeper +} + +// GetScopedIBCKeeper implements the TestingApp interface. +func (app *SimApp) GetScopedIBCKeeper() capabilitykeeper.ScopedKeeper { + return app.ScopedIBCKeeper +} + +// GetTxConfig implements the TestingApp interface. +func (app *SimApp) GetTxConfig() client.TxConfig { + return app.txConfig +} + +// SimulationManager implements the SimulationApp interface +func (app *SimApp) SimulationManager() *module.SimulationManager { + return app.sm +} + +func (app *SimApp) setupUpgradeHandlers() { + app.UpgradeKeeper.SetUpgradeHandler( + upgrades.V2, + upgrades.CreateV2UpgradeHandler(app.mm, app.configurator, app.ParamsKeeper, app.ConsensusParamsKeeper, app.PacketForwardKeeper), + ) +} + +// setupUpgradeStoreLoaders sets all necessary store loaders required by upgrades. +func (app *SimApp) setupUpgradeStoreLoaders() { + // upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk() + // if err != nil { + // tmos.Exit(fmt.Sprintf("failed to read upgrade info from disk %s", err)) + // } + + // // Future: if we want to fix the module name, we can do it here. + // if upgradeInfo.Name == upgrades.V2 && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) { + // storeUpgrades := storetypes.StoreUpgrades{ + // Renamed: []storetypes.StoreRename{{ + // OldKey: "packetfoward", // previous misspelling + // NewKey: packetforwardtypes.ModuleName, + // }}, + // } + + // // configure store loader that checks if version == upgradeHeight and applies store upgrades + // app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades)) + // } +} + +// RegisterAPIRoutes registers all application module routes with the provided +// API server. +func (app *SimApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) { + clientCtx := apiSvr.ClientCtx + // Register new tx routes from grpc-gateway. + authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) + + // Register new CometBFT queries routes from grpc-gateway. + cmtservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) + + // Register node gRPC service for grpc-gateway. + nodeservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) + + // Register grpc-gateway routes for all modules. + app.BasicModuleManager.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter) + + // register swagger API from root so that other applications can override easily + if err := server.RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger); err != nil { + panic(err) + } +} + +// RegisterTxService implements the Application.RegisterTxService method. +func (app *SimApp) RegisterTxService(clientCtx client.Context) { + authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry) +} + +// RegisterTendermintService implements the Application.RegisterTendermintService method. +func (app *SimApp) RegisterTendermintService(clientCtx client.Context) { + cmtservice.RegisterTendermintService( + clientCtx, + app.BaseApp.GRPCQueryRouter(), + app.interfaceRegistry, + app.Query, + ) +} + +// RegisterSwaggerAPI registers swagger route with API Server +func RegisterSwaggerAPI(_ client.Context, rtr *mux.Router) { + statikFS, err := fs.New() + if err != nil { + panic(err) + } + + staticServer := http.FileServer(statikFS) + rtr.PathPrefix("/swagger/").Handler(http.StripPrefix("/swagger/", staticServer)) +} + +func (app *SimApp) RegisterNodeService(clientCtx client.Context, cfg config.Config) { + nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter(), cfg) +} + +// initParamsKeeper init params keeper and its subspaces +func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper { + paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey) + + paramsKeeper.Subspace(authtypes.ModuleName) + paramsKeeper.Subspace(banktypes.ModuleName) + paramsKeeper.Subspace(stakingtypes.ModuleName) + paramsKeeper.Subspace(minttypes.ModuleName) + paramsKeeper.Subspace(distrtypes.ModuleName) + paramsKeeper.Subspace(slashingtypes.ModuleName) + paramsKeeper.Subspace(govtypes.ModuleName) + paramsKeeper.Subspace(crisistypes.ModuleName) + paramsKeeper.Subspace(ibcexported.ModuleName) + paramsKeeper.Subspace(ibctransfertypes.ModuleName) + + return paramsKeeper +} + +func (app *SimApp) AutoCliOpts() autocli.AppOptions { + modules := make(map[string]appmodule.AppModule, 0) + for _, m := range app.mm.Modules { + if moduleWithName, ok := m.(module.HasName); ok { + moduleName := moduleWithName.Name() + if appModule, ok := moduleWithName.(appmodule.AppModule); ok { + modules[moduleName] = appModule + } + } + } + + return autocli.AppOptions{ + Modules: modules, + ModuleOptions: runtimeservices.ExtractAutoCLIOptions(app.mm.Modules), + AddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), + ValidatorAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), + ConsensusAddressCodec: authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()), + } +} + +// EmptyAppOptions is a stub implementing AppOptions +type EmptyAppOptions struct{} + +// Get implements AppOptions +func (ao EmptyAppOptions) Get(_ string) interface{} { + return nil +} + +func GetSimApp(chain *ibctesting.TestChain) *SimApp { + app, ok := chain.App.(*SimApp) + require.True(chain.TB, ok) + + return app +} diff --git a/middleware/packet-forward-middleware/testing/simapp/upgrades/upgrades.go b/middleware/packet-forward-middleware/testing/simapp/upgrades/upgrades.go new file mode 100644 index 00000000..00f35a36 --- /dev/null +++ b/middleware/packet-forward-middleware/testing/simapp/upgrades/upgrades.go @@ -0,0 +1,52 @@ +package upgrades + +import ( + "context" + + "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v8/packetforward/keeper" + + upgradetypes "cosmossdk.io/x/upgrade/types" + + "github.com/cosmos/cosmos-sdk/baseapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + consensusparamskeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +const ( + V2 = "v2" +) + +// CreateDefaultUpgradeHandler creates a simple migration upgrade handler. +// func CreateDefaultUpgradeHandler(mm *module.Manager, cfg module.Configurator) upgradetypes.UpgradeHandler { +// func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { +// return mm.RunMigrations(ctx, cfg, fromVM) +// } +// } + +// We will have to import every one here +func CreateV2UpgradeHandler( + mm *module.Manager, + cfg module.Configurator, + paramskeeper paramskeeper.Keeper, + consensusparamskeeper consensusparamskeeper.Keeper, + packetforwardkeeper *keeper.Keeper, +) upgradetypes.UpgradeHandler { + return func(ctx context.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { + // Migrate Tendermint consensus parameters from x/params module to a deprecated x/consensus module. + // The old params module is required to still be imported in your app.go in order to handle this migration. + baseAppLegacySS := paramskeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramstypes.ConsensusParamsKeyTable()) + if err := baseapp.MigrateParams(sdk.UnwrapSDKContext(ctx), baseAppLegacySS, &consensusparamskeeper.ParamsStore); err != nil { + return nil, err + } + + versionMap, err := mm.RunMigrations(ctx, cfg, fromVM) + if err != nil { + return nil, err + } + + return versionMap, err + } +}