Skip to content

Commit

Permalink
fix compatibility tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bermuell committed Aug 7, 2024
1 parent 6c92999 commit 942910f
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nightly-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
# Run compatibility tests for different consumer (-cv) and provider (-pv) versions.
# Combination of all provider versions with consumer versions are tested.
# For new versions to be tested add/modify -pc/-cv parameters.
run: go run ./tests/e2e/... --tc compatibility -pv latest -pv v4.3.0-lsm -pv v3.3.3-lsm -cv latest -cv v4.3.0 -cv v3.3.0
run: go run ./tests/e2e/... --tc compatibility -pv latest -pv v4.3.1-lsm -pv v3.3.3-lsm -cv latest -cv v4.4.0 -cv v3.3.0
happy-path-test:
runs-on: ubuntu-latest
timeout-minutes: 20
Expand Down
247 changes: 247 additions & 0 deletions tests/e2e/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"golang.org/x/mod/semver"

e2e "github.com/cosmos/interchain-security/v5/tests/e2e/testlib"
"github.com/cosmos/interchain-security/v5/x/ccv/provider/client"
"github.com/cosmos/interchain-security/v5/x/ccv/provider/types"
ccvtypes "github.com/cosmos/interchain-security/v5/x/ccv/types"
)

Expand Down Expand Up @@ -366,6 +368,89 @@ func (tr Chain) submitConsumerAdditionProposal(
tr.waitBlocks(action.Chain, 2, 10*time.Second)
}

func (tr Chain) submitConsumerAdditionLegacyProposal(
action SubmitConsumerAdditionProposalAction,
verbose bool,
) {
spawnTime := tr.testConfig.containerConfig.Now.Add(time.Duration(action.SpawnTime) * time.Millisecond)
params := ccvtypes.DefaultParams()
prop := client.ConsumerAdditionProposalJSON{
Title: "Propose the addition of a new chain",
Summary: "Gonna be a great chain",
ChainId: string(tr.testConfig.chainConfigs[action.ConsumerChain].ChainId),
InitialHeight: action.InitialHeight,
GenesisHash: []byte("gen_hash"),
BinaryHash: []byte("bin_hash"),
SpawnTime: spawnTime,
ConsumerRedistributionFraction: params.ConsumerRedistributionFraction,
BlocksPerDistributionTransmission: params.BlocksPerDistributionTransmission,
HistoricalEntries: params.HistoricalEntries,
CcvTimeoutPeriod: params.CcvTimeoutPeriod,
TransferTimeoutPeriod: params.TransferTimeoutPeriod,
UnbondingPeriod: params.UnbondingPeriod,
Deposit: fmt.Sprint(action.Deposit) + `stake`,
DistributionTransmissionChannel: action.DistributionChannel,
TopN: action.TopN,
ValidatorsPowerCap: action.ValidatorsPowerCap,
ValidatorSetCap: action.ValidatorSetCap,
Allowlist: action.Allowlist,
Denylist: action.Denylist,
MinStake: action.MinStake,
AllowInactiveVals: action.AllowInactiveVals,
}

bz, err := json.Marshal(prop)
if err != nil {
log.Fatal(err)
}

jsonStr := string(bz)
if strings.Contains(jsonStr, "'") {
log.Fatal("prop json contains single quote")
}

//#nosec G204 -- bypass unsafe quoting warning (no production code)
cmd := tr.target.ExecCommand(
"/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, jsonStr, "/temp-proposal.json"))
bz, err = cmd.CombinedOutput()
if verbose {
log.Println("submitConsumerAdditionProposal cmd: ", cmd.String())
}

if err != nil {
log.Fatal(err, "\n", string(bz))
}

// CONSUMER ADDITION PROPOSAL
cmd = tr.target.ExecCommand(
tr.testConfig.chainConfigs[action.Chain].BinaryName,
"tx", "gov", "submit-legacy-proposal", "consumer-addition", "/temp-proposal.json",
`--from`, `validator`+fmt.Sprint(action.From),
`--chain-id`, string(tr.testConfig.chainConfigs[action.Chain].ChainId),
`--home`, tr.getValidatorHome(action.Chain, action.From),
`--gas`, `900000`,
`--node`, tr.getValidatorNode(action.Chain, action.From),
`--keyring-backend`, `test`,
`-y`,
)

if verbose {
fmt.Println("submitConsumerAdditionProposal cmd:", cmd.String())
fmt.Println("submitConsumerAdditionProposal json:", jsonStr)
}
bz, err = cmd.CombinedOutput()
if err != nil {
log.Fatal(err, "\n", string(bz))
}

if verbose {
fmt.Println("submitConsumerAdditionProposal output:", string(bz))
}

// wait for inclusion in a block -> '--broadcast-mode block' is deprecated
tr.waitBlocks(ChainID("provi"), 2, 10*time.Second)
}

type SubmitConsumerRemovalProposalAction struct {
Chain ChainID
From ValidatorID
Expand Down Expand Up @@ -443,6 +528,55 @@ func (tr Chain) submitConsumerRemovalProposal(
tr.waitBlocks(ChainID("provi"), 2, 20*time.Second)
}

func (tr Chain) submitConsumerRemovalLegacyProposal(
action SubmitConsumerRemovalProposalAction,
verbose bool,
) {
stopTime := tr.testConfig.containerConfig.Now.Add(action.StopTimeOffset)
prop := client.ConsumerRemovalProposalJSON{
Title: fmt.Sprintf("Stop the %v chain", action.ConsumerChain),
Summary: "It was a great chain",
ChainId: string(tr.testConfig.chainConfigs[action.ConsumerChain].ChainId),
StopTime: stopTime,
Deposit: fmt.Sprint(action.Deposit) + `stake`,
}

bz, err := json.Marshal(prop)
if err != nil {
log.Fatal(err)
}

jsonStr := string(bz)
if strings.Contains(jsonStr, "'") {
log.Fatal("prop json contains single quote")
}

bz, err = tr.target.ExecCommand(
"/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, jsonStr, "/temp-proposal.json")).CombinedOutput()
if err != nil {
log.Fatal(err, "\n", string(bz))
}

bz, err = tr.target.ExecCommand(
tr.testConfig.chainConfigs[action.Chain].BinaryName,
"tx", "gov", "submit-legacy-proposal", "consumer-removal",
"/temp-proposal.json",
`--from`, `validator`+fmt.Sprint(action.From),
`--chain-id`, string(tr.testConfig.chainConfigs[action.Chain].ChainId),
`--home`, tr.getValidatorHome(action.Chain, action.From),
`--node`, tr.getValidatorNode(action.Chain, action.From),
`--gas`, "900000",
`--keyring-backend`, `test`,
`-y`,
).CombinedOutput()
if err != nil {
log.Fatal(err, "\n", string(bz))
}

// wait for inclusion in a block -> '--broadcast-mode block' is deprecated
tr.waitBlocks(ChainID("provi"), 2, 20*time.Second)
}

type SubmitConsumerModificationProposalAction struct {
Chain ChainID
From ValidatorID
Expand Down Expand Up @@ -536,6 +670,70 @@ func (tr Chain) submitConsumerModificationProposal(
tr.waitBlocks(ChainID("provi"), 2, 10*time.Second)
}

func (tr Chain) submitConsumerModificationLegacyProposal(
action SubmitConsumerModificationProposalAction,
verbose bool,
) {
prop := client.ConsumerModificationProposalJSON{
Title: "Propose the modification of the PSS parameters of a chain",
Summary: "summary of a modification proposal",
ChainId: string(tr.testConfig.chainConfigs[action.ConsumerChain].ChainId),
Deposit: fmt.Sprint(action.Deposit) + `stake`,
TopN: action.TopN,
ValidatorsPowerCap: action.ValidatorsPowerCap,
ValidatorSetCap: action.ValidatorSetCap,
Allowlist: action.Allowlist,
Denylist: action.Denylist,
}

bz, err := json.Marshal(prop)
if err != nil {
log.Fatal(err)
}

jsonStr := string(bz)
if strings.Contains(jsonStr, "'") {
log.Fatal("prop json contains single quote")
}

//#nosec G204 -- bypass unsafe quoting warning (no production code)
bz, err = tr.target.ExecCommand(
"/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, jsonStr, "/temp-proposal.json"),
).CombinedOutput()
if err != nil {
log.Fatal(err, "\n", string(bz))
}

// CONSUMER MODIFICATION PROPOSAL
cmd := tr.target.ExecCommand(
tr.testConfig.chainConfigs[action.Chain].BinaryName,
"tx", "gov", "submit-legacy-proposal", "consumer-modification", "/temp-proposal.json",
`--from`, `validator`+fmt.Sprint(action.From),
`--chain-id`, string(tr.testConfig.chainConfigs[action.Chain].ChainId),
`--home`, tr.getValidatorHome(action.Chain, action.From),
`--gas`, `900000`,
`--node`, tr.getValidatorNode(action.Chain, action.From),
`--keyring-backend`, `test`,
`-y`,
)
if verbose {
log.Println("submitConsumerModificationProposal cmd: ", cmd.String())
log.Println("submitConsumerModificationProposal json: ", jsonStr)
}

bz, err = cmd.CombinedOutput()
if err != nil {
log.Fatal(err, "\n", string(bz))
}

if verbose {
log.Println("submitConsumerModificationProposal output: ", string(bz))
}

// wait for inclusion in a block -> '--broadcast-mode block' is deprecated
tr.waitBlocks(ChainID("provi"), 2, 10*time.Second)
}

type SubmitEnableTransfersProposalAction struct {
Chain ChainID
From ValidatorID
Expand Down Expand Up @@ -2087,6 +2285,55 @@ func (tr Chain) submitChangeRewardDenomsProposal(action SubmitChangeRewardDenoms
tr.waitBlocks(ChainID("provi"), 2, 30*time.Second)
}

func (tr Chain) submitChangeRewardDenomsLegacyProposal(action SubmitChangeRewardDenomsProposalAction, verbose bool) {
providerChain := tr.testConfig.chainConfigs[action.Chain]

prop := client.ChangeRewardDenomsProposalJSON{
Summary: "Change reward denoms",
ChangeRewardDenomsProposal: types.ChangeRewardDenomsProposal{
Title: "Change reward denoms",
Description: "Change reward denoms",
DenomsToAdd: []string{action.Denom},
DenomsToRemove: []string{"stake"},
},
Deposit: fmt.Sprint(action.Deposit) + `stake`,
}

bz, err := json.Marshal(prop)
if err != nil {
log.Fatal(err)
}

jsonStr := string(bz)
if strings.Contains(jsonStr, "'") {
log.Fatal("prop json contains single quote")
}

bz, err = tr.target.ExecCommand(
"/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, jsonStr, "/change-reward-denoms-proposal.json")).CombinedOutput()
if err != nil {
log.Fatal(err, "\n", string(bz))
}

// CHANGE REWARDS DENOM PROPOSAL
bz, err = tr.target.ExecCommand(providerChain.BinaryName,
"tx", "gov", "submit-legacy-proposal", "change-reward-denoms", "/change-reward-denoms-proposal.json",
`--from`, `validator`+fmt.Sprint(action.From),
`--chain-id`, string(providerChain.ChainId),
`--home`, tr.getValidatorHome(providerChain.ChainId, action.From),
`--node`, tr.getValidatorNode(providerChain.ChainId, action.From),
`--gas`, "9000000",
`--keyring-backend`, `test`,
`-y`,
).CombinedOutput()
if err != nil {
log.Fatal(err, "\n", string(bz))
}

// wait for inclusion in a block -> '--broadcast-mode block' is deprecated
tr.waitBlocks(ChainID("provi"), 2, 30*time.Second)
}

// Creates an additional node on selected chain
// by copying an existing validator's home folder
//
Expand Down
32 changes: 26 additions & 6 deletions tests/e2e/test_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (td *DefaultDriver) getTargetDriver(chainID ChainID) Chain {
}
icsVersion := td.getIcsVersion(chainID)
switch icsVersion {
case "v4":
case "v3", "v4":
if td.verbose {
fmt.Println("Using 'v4' driver for chain ", chainID)
}
Expand All @@ -101,7 +101,7 @@ func (td *DefaultDriver) getTargetDriver(chainID ChainID) Chain {
target: td.target,
}
if td.verbose {
fmt.Println("Using default driver ", icsVersion, " for chain ", chainID)
fmt.Println("Using default driver for version", icsVersion, " for chain ", chainID)
}
}

Expand Down Expand Up @@ -140,13 +140,28 @@ func (td *DefaultDriver) runAction(action interface{}) error {
case SubmitTextProposalAction:
target.submitTextProposal(action, td.verbose)
case SubmitConsumerAdditionProposalAction:
target.submitConsumerAdditionProposal(action, td.verbose)
target = td.getTargetDriver(action.Chain)
if semver.Compare(semver.Major(target.testConfig.providerVersion), "v5") < 0 {
target.submitConsumerAdditionLegacyProposal(action, td.verbose)
} else {
target.submitConsumerAdditionProposal(action, td.verbose)
}
case SubmitConsumerRemovalProposalAction:
target.submitConsumerRemovalProposal(action, td.verbose)
target = td.getTargetDriver(action.Chain)
if semver.Compare(semver.Major(target.testConfig.providerVersion), "v5") < 0 {
target.submitConsumerRemovalLegacyProposal(action, td.verbose)
} else {
target.submitConsumerRemovalProposal(action, td.verbose)
}
case SubmitEnableTransfersProposalAction:
target.submitEnableTransfersProposalAction(action, td.verbose)
case SubmitConsumerModificationProposalAction:
target.submitConsumerModificationProposal(action, td.verbose)
target = td.getTargetDriver(action.Chain)
if semver.Compare(semver.Major(target.testConfig.providerVersion), "v5") < 0 {
target.submitConsumerModificationLegacyProposal(action, td.verbose)
} else {
target.submitConsumerModificationProposal(action, td.verbose)
}
case VoteGovProposalAction:
target.voteGovProposal(action, td.verbose)
case StartConsumerChainAction:
Expand Down Expand Up @@ -202,7 +217,12 @@ func (td *DefaultDriver) runAction(action interface{}) error {
case StartConsumerEvidenceDetectorAction:
target.startConsumerEvidenceDetector(action, td.verbose)
case SubmitChangeRewardDenomsProposalAction:
target.submitChangeRewardDenomsProposal(action, td.verbose)
target = td.getTargetDriver(action.Chain)
if semver.Compare(semver.Major(target.testConfig.providerVersion), "v5") < 0 {
target.submitChangeRewardDenomsLegacyProposal(action, td.verbose)
} else {
target.submitChangeRewardDenomsProposal(action, td.verbose)
}
case OptInAction:
target.optIn(action, td.target, td.verbose)
case OptOutAction:
Expand Down

0 comments on commit 942910f

Please sign in to comment.