-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BP: release/v6 <- #202]
refactor: remove the ability to take a fee…
… for each forwarded packet (#206) * 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 <[email protected]> (cherry picked from commit 26d8080) # Conflicts: # 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 * refactor: backport changes to remove the ability to take a fee that is sent to the community pool * chore: fix linter errors --------- Co-authored-by: Justin Tieri <[email protected]>
- Loading branch information
1 parent
8e503d4
commit 6e1d3ea
Showing
23 changed files
with
3,676 additions
and
1,378 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,7 +144,6 @@ cosmovisor: | |
mocks: $(MOCKS_DIR) | ||
go install go.uber.org/mock/[email protected] | ||
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/v6/modules/core/05-port/types ICS4Wrapper | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
middleware/packet-forward-middleware/e2e/upgrade_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.