-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Upgrade_chain_test and move interchaintest folder
- Loading branch information
1 parent
c7acdd9
commit 518eaae
Showing
9 changed files
with
204 additions
and
11 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
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
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 |
---|---|---|
|
@@ -2,5 +2,5 @@ go 1.20 | |
|
||
use ( | ||
. | ||
./tests/interchaintest | ||
./interchaintest | ||
) |
File renamed without changes.
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
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
File renamed without changes.
File renamed without changes.
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 interchaintest | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/icza/dyno" | ||
interchaintest "github.com/strangelove-ventures/interchaintest/v5" | ||
"github.com/strangelove-ventures/interchaintest/v5/chain/cosmos" | ||
"github.com/strangelove-ventures/interchaintest/v5/ibc" | ||
"github.com/strangelove-ventures/interchaintest/v5/testutil" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap/zaptest" | ||
) | ||
|
||
const ( | ||
haltHeightDelta = uint64(20) | ||
blocksAfterUpgrade = uint64(10) | ||
heightDelta = uint64(20) | ||
votingPeriod = "30s" | ||
maxDepositPeriod = "10s" | ||
) | ||
|
||
func TestMigalooUpgrade(t *testing.T) { | ||
repo, version := GetDockerImageInfo() | ||
CosmosChainUpgradeTest(t, repo, version, "v3") | ||
} | ||
|
||
func CosmosChainUpgradeTest(t *testing.T, upgradeContainerRepo, upgradeVersion, upgradeName string) { | ||
if testing.Short() { | ||
t.Skip("skipping in short mode") | ||
} | ||
|
||
t.Parallel() | ||
|
||
cf := interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(t), []*interchaintest.ChainSpec{ | ||
{ | ||
ChainConfig: ibc.ChainConfig{ | ||
Type: "cosmos", | ||
Name: "migaloo", | ||
ChainID: "migaloo-2", | ||
Images: []ibc.DockerImage{ | ||
{ | ||
Repository: "ghcr.io/white-whale-defi-platform/migaloo-chain", | ||
Version: "2.2.6", | ||
UidGid: "1025:1025", | ||
}, | ||
}, | ||
Bin: "migalood", | ||
Bech32Prefix: "migaloo", | ||
Denom: "stake", | ||
GasPrices: "0.00stake", | ||
GasAdjustment: 1.3, | ||
TrustingPeriod: "504h", | ||
// EncodingConfig: WasmClientEncoding(), | ||
NoHostMount: true, | ||
ModifyGenesis: modifyGenesisShortProposals(votingPeriod, maxDepositPeriod), | ||
}, | ||
}, | ||
}) | ||
|
||
chains, err := cf.Chains(t.Name()) | ||
require.NoError(t, err) | ||
|
||
chain := chains[0].(*cosmos.CosmosChain) | ||
|
||
ic := interchaintest.NewInterchain(). | ||
AddChain(chain) | ||
|
||
ctx := context.Background() | ||
client, network := interchaintest.DockerSetup(t) | ||
|
||
require.NoError(t, ic.Build(ctx, nil, interchaintest.InterchainBuildOptions{ | ||
TestName: t.Name(), | ||
Client: client, | ||
NetworkID: network, | ||
// BlockDatabaseFile: interchaintest.DefaultBlockDatabaseFilepath(), | ||
SkipPathCreation: true, | ||
})) | ||
t.Cleanup(func() { | ||
_ = ic.Close() | ||
}) | ||
|
||
const userFunds = int64(10_000_000_000) | ||
users := interchaintest.GetAndFundTestUsers(t, ctx, t.Name(), userFunds, chain) | ||
chainUser := users[0] | ||
|
||
height, err := chain.Height(ctx) | ||
require.NoError(t, err, "error fetching height before submit upgrade proposal") | ||
|
||
haltHeight := height + haltHeightDelta | ||
|
||
proposal := cosmos.SoftwareUpgradeProposal{ | ||
Deposit: "500000000" + chain.Config().Denom, // greater than min deposit | ||
Title: "Chain Upgrade 1", | ||
Name: upgradeName, | ||
Description: "First chain software upgrade", | ||
Height: haltHeight, | ||
Info: "UPGRADE", | ||
} | ||
|
||
upgradeTx, err := chain.UpgradeProposal(ctx, chainUser.KeyName(), proposal) | ||
require.NoError(t, err, "error submitting software upgrade proposal tx") | ||
|
||
err = chain.VoteOnProposalAllValidators(ctx, upgradeTx.ProposalID, cosmos.ProposalVoteYes) | ||
require.NoError(t, err, "failed to submit votes") | ||
|
||
_, err = cosmos.PollForProposalStatus(ctx, chain, height, haltHeight, upgradeTx.ProposalID, cosmos.ProposalStatusPassed) | ||
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)+1, 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") | ||
|
||
// bring down nodes to prepare for upgrade | ||
err = chain.StopAllNodes(ctx) | ||
require.NoError(t, err, "error stopping node(s)") | ||
|
||
// upgrade version on all nodes | ||
chain.UpgradeVersion(ctx, client, upgradeContainerRepo, upgradeVersion) | ||
|
||
// start all nodes back up. | ||
// validators reach consensus on first block after upgrade height | ||
// and chain block production resumes. | ||
err = chain.StartAllNodes(ctx) | ||
require.NoError(t, err, "error starting upgraded node(s)") | ||
|
||
timeoutCtx, timeoutCtxCancel = context.WithTimeout(ctx, time.Second*45) | ||
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 modifyGenesisShortProposals(votingPeriod, maxDepositPeriod string) func(ibc.ChainConfig, []byte) ([]byte, error) { | ||
return func(chainConfig ibc.ChainConfig, genbz []byte) ([]byte, error) { | ||
g := make(map[string]interface{}) | ||
if err := json.Unmarshal(genbz, &g); err != nil { | ||
return nil, fmt.Errorf("failed to unmarshal genesis file: %w", err) | ||
} | ||
if err := dyno.Set(g, votingPeriod, "app_state", "gov", "params", "voting_period"); err != nil { | ||
return nil, fmt.Errorf("failed to set voting period in genesis json: %w", err) | ||
} | ||
if err := dyno.Set(g, maxDepositPeriod, "app_state", "gov", "params", "max_deposit_period"); err != nil { | ||
return nil, fmt.Errorf("failed to set voting period in genesis json: %w", err) | ||
} | ||
if err := dyno.Set(g, chainConfig.Denom, "app_state", "gov", "params", "min_deposit", 0, "denom"); err != nil { | ||
return nil, fmt.Errorf("failed to set voting period in genesis json: %w", err) | ||
} | ||
out, err := json.Marshal(g) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to marshal genesis bytes to json: %w", err) | ||
} | ||
return out, nil | ||
} | ||
} |