Skip to content

Commit

Permalink
e2e: enable running tests [tests not fully functional]
Browse files Browse the repository at this point in the history
  • Loading branch information
MSalopek committed Nov 3, 2023
1 parent c45b329 commit a2ae629
Show file tree
Hide file tree
Showing 19 changed files with 160 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax=docker/dockerfile:1


FROM golang:1.20-alpine AS is-builder
FROM golang:1.21-alpine AS is-builder

ENV PACKAGES curl make git libc-dev bash gcc linux-headers
RUN apk add --no-cache $PACKAGES
Expand Down
10 changes: 8 additions & 2 deletions cmd/interchain-security-cd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/client/pruning"
"github.com/cosmos/cosmos-sdk/client/rpc"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/server"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
Expand Down Expand Up @@ -86,10 +87,15 @@ func NewRootCmd() *cobra.Command {
}

initRootCmd(rootCmd, encodingConfig)
if err := tempApp.AutoCliOpts().EnhanceRootCommand(rootCmd); err != nil {
// autocli opts
autoCliOpts := tempApp.AutoCliOpts()
initClientCtx, _ = config.ReadFromClientConfig(initClientCtx)
autoCliOpts.Keyring, _ = keyring.NewAutoCLIKeyring(initClientCtx.Keyring)
autoCliOpts.ClientCtx = initClientCtx

if err := autoCliOpts.EnhanceRootCommand(rootCmd); err != nil {
panic(err)
}

return rootCmd
}

Expand Down
5 changes: 5 additions & 0 deletions proto/interchain_security/ccv/provider/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ service Msg {
message MsgAssignConsumerKey {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;
option (cosmos.msg.v1.signer) = "signer";

// The chain id of the consumer chain to assign a consensus public key to
string chain_id = 1;
// The validator address on the provider
Expand All @@ -28,6 +30,9 @@ message MsgAssignConsumerKey {
// in json string format corresponding to proto-any, ex:
// `{"@type":"/cosmos.crypto.ed25519.PubKey","key":"Ui5Gf1+mtWUdH8u3xlmzdKID+F3PK0sfXZ73GZ6q6is="}`
string consumer_key = 3;

// signer address
string signer = 4 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

message MsgAssignConsumerKeyResponse {}
4 changes: 2 additions & 2 deletions tests/e2e/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func (tr *TestRun) voteGovProposal(

wg.Wait()
// wait for inclusion in a block -> '--broadcast-mode block' is deprecated
tr.waitBlocks(action.chain, 1, 10*time.Second)
tr.waitBlocks(action.chain, 2, 10*time.Second)
tr.WaitTime(time.Duration(tr.chainConfigs[action.chain].votingWaitTime) * time.Second)
}

Expand Down Expand Up @@ -1888,7 +1888,7 @@ func (tr TestRun) assignConsumerPubKey(action assignConsumerPubKeyAction, verbos
tr.getValidatorNode(chainID("provi"), action.validator),
gas,
)

fmt.Println(assignKey)
//#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments.
cmd := exec.Command("docker", "exec",
tr.containerConfig.instanceName,
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func SlashThrottleTestRun() TestRun {
ipPrefix: "7.7.7",
votingWaitTime: 20,
genesisChanges: ".app_state.gov.params.voting_period = \"20s\" | " +
".app_state.gov.params.expedited_voting_period = \"10s\" | " +
// Custom slashing parameters for testing validator downtime functionality
// See https://docs.cosmos.network/main/modules/slashing/04_begin_block.html#uptime-tracking
".app_state.slashing.params.signed_blocks_window = \"10\" | " +
Expand Down Expand Up @@ -213,6 +214,7 @@ func DefaultTestRun() TestRun {
ipPrefix: "7.7.7",
votingWaitTime: 20,
genesisChanges: ".app_state.gov.params.voting_period = \"20s\" | " +
".app_state.gov.params.expedited_voting_period = \"10s\" | " +
// Custom slashing parameters for testing validator downtime functionality
// See https://docs.cosmos.network/main/modules/slashing/04_begin_block.html#uptime-tracking
".app_state.slashing.params.signed_blocks_window = \"10\" | " +
Expand Down Expand Up @@ -270,6 +272,7 @@ func DemocracyTestRun(allowReward bool) TestRun {
ipPrefix: "7.7.7",
votingWaitTime: 20,
genesisChanges: ".app_state.gov.params.voting_period = \"20s\" | " +
".app_state.gov.params.expedited_voting_period = \"10s\" | " +
// Custom slashing parameters for testing validator downtime functionality
// See https://docs.cosmos.network/main/modules/slashing/04_begin_block.html#uptime-tracking
".app_state.slashing.params.signed_blocks_window = \"10\" | " +
Expand Down Expand Up @@ -310,6 +313,7 @@ func MultiConsumerTestRun() TestRun {
ipPrefix: "7.7.7",
votingWaitTime: 20,
genesisChanges: ".app_state.gov.params.voting_period = \"30s\" | " +
".app_state.gov.params.expedited_voting_period = \"10s\" | " +
// Custom slashing parameters for testing validator downtime functionality
// See https://docs.cosmos.network/main/modules/slashing/04_begin_block.html#uptime-tracking
".app_state.slashing.params.signed_blocks_window = \"10\" | " +
Expand Down Expand Up @@ -365,6 +369,7 @@ func ChangeoverTestRun() TestRun {
ipPrefix: "7.7.7",
votingWaitTime: 20,
genesisChanges: ".app_state.gov.params.voting_period = \"20s\" | " +
".app_state.gov.params.expedited_voting_period = \"10s\" | " +
// Custom slashing parameters for testing validator downtime functionality
// See https://docs.cosmos.network/main/modules/slashing/04_begin_block.html#uptime-tracking
".app_state.slashing.params.signed_blocks_window = \"10\" | " +
Expand Down
33 changes: 17 additions & 16 deletions tests/e2e/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,15 @@ func (tr TestRun) getProposal(chain chainID, proposal uint) Proposal {
log.Fatal(err, "\n", string(bz))
}

propType := gjson.Get(string(bz), `messages.0.content.@type`).String()
deposit := gjson.Get(string(bz), `total_deposit.#(denom=="stake").amount`).Uint()
status := gjson.Get(string(bz), `status`).String()
propType := gjson.Get(string(bz), `proposal.messages.0.value.content.type`).String()
rawContent := gjson.Get(string(bz), `proposal.messages.0.value.content.value`)
deposit := gjson.Get(string(bz), `proposal.total_deposit.#(denom=="stake").amount`).Uint()
status := gjson.Get(string(bz), `proposal.status`).String()

switch propType {
case "/cosmos.gov.v1beta1.TextProposal":
title := gjson.Get(string(bz), `content.title`).String()
description := gjson.Get(string(bz), `content.description`).String()
title := rawContent.Get("title").String()
description := rawContent.Get("description").String()

return TextProposal{
Deposit: uint(deposit),
Expand All @@ -400,8 +401,8 @@ func (tr TestRun) getProposal(chain chainID, proposal uint) Proposal {
Description: description,
}
case "/interchain_security.ccv.provider.v1.ConsumerAdditionProposal":
chainId := gjson.Get(string(bz), `messages.0.content.chain_id`).String()
spawnTime := gjson.Get(string(bz), `messages.0.content.spawn_time`).Time().Sub(tr.containerConfig.now)
chainId := rawContent.Get("chain_id").String()
spawnTime := rawContent.Get("spawn_time").Time().Sub(tr.containerConfig.now)

var chain chainID
for i, conf := range tr.chainConfigs {
Expand All @@ -417,13 +418,13 @@ func (tr TestRun) getProposal(chain chainID, proposal uint) Proposal {
Chain: chain,
SpawnTime: int(spawnTime.Milliseconds()),
InitialHeight: clienttypes.Height{
RevisionNumber: gjson.Get(string(bz), `messages.0.content.initial_height.revision_number`).Uint(),
RevisionHeight: gjson.Get(string(bz), `messages.0.content.initial_height.revision_height`).Uint(),
RevisionNumber: rawContent.Get("initial_height.revision_number").Uint(),
RevisionHeight: rawContent.Get("initial_height.revision_height").Uint(),
},
}
case "/cosmos.upgrade.v1beta1.SoftwareUpgradeProposal":
height := gjson.Get(string(bz), `messages.0.content.plan.height`).Uint()
title := gjson.Get(string(bz), `messages.0.content.plan.name`).String()
height := rawContent.Get("plan.height").Uint()
title := rawContent.Get("plan.name").String()
return UpgradeProposal{
Deposit: uint(deposit),
Status: status,
Expand All @@ -432,8 +433,8 @@ func (tr TestRun) getProposal(chain chainID, proposal uint) Proposal {
Type: "/cosmos.upgrade.v1beta1.SoftwareUpgradeProposal",
}
case "/interchain_security.ccv.provider.v1.ConsumerRemovalProposal":
chainId := gjson.Get(string(bz), `messages.0.content.chain_id`).String()
stopTime := gjson.Get(string(bz), `messages.0.content.stop_time`).Time().Sub(tr.containerConfig.now)
chainId := rawContent.Get("chain_id").String()
stopTime := rawContent.Get("stop_time").Time().Sub(tr.containerConfig.now)

var chain chainID
for i, conf := range tr.chainConfigs {
Expand All @@ -454,9 +455,9 @@ func (tr TestRun) getProposal(chain chainID, proposal uint) Proposal {
return ParamsProposal{
Deposit: uint(deposit),
Status: status,
Subspace: gjson.Get(string(bz), `messages.0.content.changes.0.subspace`).String(),
Key: gjson.Get(string(bz), `messages.0.content.changes.0.key`).String(),
Value: gjson.Get(string(bz), `messages.0.content.changes.0.value`).String(),
Subspace: rawContent.Get("changes.0.subspace").String(),
Key: rawContent.Get("changes.0.key").String(),
Value: rawContent.Get("changes.0.value").String(),
}
}

Expand Down
8 changes: 7 additions & 1 deletion tests/e2e/steps_democracy.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package main

import (
"strconv"

gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
)

const consumerRewardDenom = "ibc/3C3D7B3BE4ECC85A0E5B52A3AEC3B7DFC2AA9CA47C37821E57020D6807043BE9"

func stepsDemocracy(consumerName string) []Step {
Expand Down Expand Up @@ -80,7 +86,7 @@ func stepsDemocracy(consumerName string) []Step {
Proposals: &map[uint]Proposal{
1: ParamsProposal{
Deposit: 10000001,
Status: "PROPOSAL_STATUS_VOTING_PERIOD",
Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD)),
Subspace: "transfer",
Key: "SendEnabled",
Value: "true",
Expand Down
8 changes: 7 additions & 1 deletion tests/e2e/steps_reward_denom.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package main

import (
"strconv"

gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
)

func stepsRewardDenomConsumer(consumerName string) []Step {
return []Step{
{
Expand Down Expand Up @@ -78,7 +84,7 @@ func stepsRewardDenomConsumer(consumerName string) []Step {
Proposals: &map[uint]Proposal{
1: ParamsProposal{
Deposit: 10000001,
Status: "PROPOSAL_STATUS_VOTING_PERIOD",
Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD)),
Subspace: "transfer",
Key: "SendEnabled",
Value: "true",
Expand Down
15 changes: 10 additions & 5 deletions tests/e2e/steps_sovereign_changeover.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package main

import clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
import (
"strconv"

gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
)

// this creates new clients on both chains and a connection (connection-0) between them
// connection-0 is used to create a transfer channel between the chains
Expand Down Expand Up @@ -61,7 +66,7 @@ func stepsChangeoverToConsumer(consumerName string) []Step {
Chain: chainID(consumerName),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 111},
Status: "PROPOSAL_STATUS_VOTING_PERIOD",
Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD)),
},
},
},
Expand All @@ -82,7 +87,7 @@ func stepsChangeoverToConsumer(consumerName string) []Step {
Chain: chainID(consumerName),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 111},
Status: "PROPOSAL_STATUS_PASSED",
Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD)),
},
},
ValBalances: &map[validatorID]uint{
Expand Down Expand Up @@ -206,7 +211,7 @@ func stepsUpgradeChain() []Step {
UpgradeHeight: 110,
Type: "/cosmos.upgrade.v1beta1.SoftwareUpgradeProposal",
Deposit: 10000000,
Status: "PROPOSAL_STATUS_VOTING_PERIOD",
Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD)),
},
},
},
Expand All @@ -227,7 +232,7 @@ func stepsUpgradeChain() []Step {
UpgradeHeight: 110,
Title: "sovereign-changeover",
Type: "/cosmos.upgrade.v1beta1.SoftwareUpgradeProposal",
Status: "PROPOSAL_STATUS_PASSED",
Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD)),
},
},
},
Expand Down
7 changes: 5 additions & 2 deletions tests/e2e/steps_start_chains.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import (
"strconv"

gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
)

Expand Down Expand Up @@ -51,7 +54,7 @@ func stepsStartConsumerChain(consumerName string, proposalIndex, chainIndex uint
Chain: chainID(consumerName),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
Status: "PROPOSAL_STATUS_VOTING_PERIOD",
Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD)),
},
},
},
Expand Down Expand Up @@ -130,7 +133,7 @@ func stepsStartConsumerChain(consumerName string, proposalIndex, chainIndex uint
Chain: chainID(consumerName),
SpawnTime: 0,
InitialHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 1},
Status: "PROPOSAL_STATUS_PASSED",
Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_PASSED)),
},
},
ValBalances: &map[validatorID]uint{
Expand Down
15 changes: 10 additions & 5 deletions tests/e2e/steps_stop_chain.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package main

import "time"
import (
"strconv"
"time"

gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
)

// start relayer so that all messages are relayed
func stepsStartRelayer() []Step {
Expand Down Expand Up @@ -33,7 +38,7 @@ func stepsStopChain(consumerName string, propNumber uint) []Step {
Deposit: 10000001,
Chain: chainID(consumerName),
StopTime: 0,
Status: "PROPOSAL_STATUS_VOTING_PERIOD",
Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD)),
},
},
ConsumerChains: &map[chainID]bool{"consu": true}, // consumer chain not yet removed
Expand All @@ -54,7 +59,7 @@ func stepsStopChain(consumerName string, propNumber uint) []Step {
Deposit: 10000001,
Chain: chainID(consumerName),
StopTime: 0,
Status: "PROPOSAL_STATUS_PASSED",
Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_PASSED)),
},
},
ValBalances: &map[validatorID]uint{
Expand Down Expand Up @@ -91,7 +96,7 @@ func stepsConsumerRemovalPropNotPassing(consumerName string, propNumber uint) []
Deposit: 10000001,
Chain: chainID(consumerName),
StopTime: 0,
Status: "PROPOSAL_STATUS_VOTING_PERIOD",
Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD)),
},
},
ConsumerChains: &map[chainID]bool{"consu": true}, // consumer chain not removed
Expand All @@ -112,7 +117,7 @@ func stepsConsumerRemovalPropNotPassing(consumerName string, propNumber uint) []
Deposit: 10000001,
Chain: chainID(consumerName),
StopTime: 0,
Status: "PROPOSAL_STATUS_REJECTED",
Status: strconv.Itoa(int(gov.ProposalStatus_PROPOSAL_STATUS_REJECTED)),
},
},
ValBalances: &map[validatorID]uint{
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/testnet-scripts/start-chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,11 @@ fi
# poll for chain start
if [[ "$USE_COMETMOCK" == "true" ]]; then
set +e
until $BIN query block --node "tcp://$CHAIN_IP_PREFIX.$QUERY_IP_SUFFIX:26658"; do sleep 0.3 ; done
until $BIN query block --type=height 0 --node "tcp://$CHAIN_IP_PREFIX.$QUERY_IP_SUFFIX:26658"; do sleep 0.3 ; done
set -e
else
set +e
until $BIN query block --node "tcp://$CHAIN_IP_PREFIX.$QUERY_IP_SUFFIX:26658" | grep -q -v '{"block_id":{"hash":"","parts":{"total":0,"hash":
until $BIN query block --type=height 0 --node "tcp://$CHAIN_IP_PREFIX.$QUERY_IP_SUFFIX:26658" | grep -q -v '{"block_id":{"hash":"","parts":{"total":0,"hash":
""}},"block":null}'; do sleep 0.3 ; done
set -e
fi
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/testnet-scripts/start-changeover.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ QUERY_NODE_SUFFIX=$(echo "$VALIDATORS" | jq -r ".[0].ip_suffix")
echo "NODE SUFFIX: $QUERY_NODE_SUFFIX"
# poll for chain start
set +e
until $BIN query block --node "tcp://$CHAIN_IP_PREFIX.$QUERY_NODE_SUFFIX:26658" | grep -q -v '{"block_id":{"hash":"","parts":{"total":0,"hash":""}},"block":null}'; do sleep 0.3 ; done
until $BIN query block query block --type=height 0 --node "tcp://$CHAIN_IP_PREFIX.$QUERY_NODE_SUFFIX:26658" | grep -q -v '{"block_id":{"hash":"","parts":{"total":0,"hash":""}},"block":null}'; do sleep 0.3 ; done
set -e

echo "done!!!!!!!!"
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/testnet-scripts/start-sovereign.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ ip netns exec $NET_NAMESPACE_NAME $BIN $ARGS start &> /$CHAIN_ID/validator$VAL_I

# poll for chain start
set +e
until $BIN query block --node "tcp://$CHAIN_IP_PREFIX.$VAL_IP_SUFFIX:26658" | grep -q -v '{"block_id":{"hash":"","parts":{"total":0,"hash":""}},"block":null}'; do sleep 0.3 ; done
until $BIN query block --type=height 0 --node "tcp://$CHAIN_IP_PREFIX.$VAL_IP_SUFFIX:26658" | grep -q -v '{"block_id":{"hash":"","parts":{"total":0,"hash":""}},"block":null}'; do sleep 0.3 ; done
set -e

echo "done!!!!!!!!"
Expand Down
Loading

0 comments on commit a2ae629

Please sign in to comment.