Skip to content

Commit

Permalink
Add e2e tests for permissionless ICS
Browse files Browse the repository at this point in the history
  • Loading branch information
bermuell committed Sep 5, 2024
1 parent 954f77c commit 22190a4
Show file tree
Hide file tree
Showing 9 changed files with 520 additions and 85 deletions.
82 changes: 51 additions & 31 deletions tests/e2e/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func (tr *Chain) startChain(
cometmockArg = "false"
}

chainHome := string(action.Chain)
startChainScript := tr.target.GetTestScriptPath(action.IsConsumer, "start-chain.sh")
cmd := tr.target.ExecCommand("/bin/bash",
startChainScript, chainConfig.BinaryName, string(vals),
Expand All @@ -182,6 +183,7 @@ func (tr *Chain) startChain(
// with short timeout_commit (eg. timeout_commit = 1s) some nodes may miss blocks causing the test run to fail
tr.testConfig.tendermintConfigOverride,
cometmockArg,
chainHome,
)

cmdReader, err := cmd.StdoutPipe()
Expand Down Expand Up @@ -311,7 +313,7 @@ func (tr Chain) updateConsumerChain(action UpdateConsumerChainAction, verbose bo
InitializationParameters: &initParams,
PowerShapingParameters: &powerShapingParams,
}
tr.UpdateConsumer(action.Chain, action.From, msg)
tr.UpdateConsumer(action.Chain, action.From, msg, verbose)
}

type CreateConsumerChainAction struct {
Expand All @@ -334,6 +336,13 @@ type CreateConsumerChainAction struct {
func (tr Chain) createConsumerChain(action CreateConsumerChainAction, verbose bool) {

spawnTime := tr.testConfig.containerConfig.Now.Add(time.Duration(action.SpawnTime) * time.Millisecond)
consumerChainCfg := tr.testConfig.chainConfigs[action.ConsumerChain]
providerChainCfg := tr.testConfig.chainConfigs[action.Chain]

if consumerChainCfg.ConsumerId != "" {
log.Fatalf("consumer chain already created for '%s'", action.ConsumerChain)
}

params := ccvtypes.DefaultParams()
initParams := types.ConsumerInitializationParameters{
InitialHeight: action.InitialHeight,
Expand Down Expand Up @@ -361,16 +370,20 @@ func (tr Chain) createConsumerChain(action CreateConsumerChainAction, verbose bo
}

metadata := types.ConsumerMetadata{
Name: "chain name of " + string(action.Chain),
Name: "chain name of " + string(consumerChainCfg.ChainId),
Description: "no description",
Metadata: "no metadata",
}

// create consumer to get a consumer-id
consumerId := tr.CreateConsumer(action.Chain, action.ConsumerChain, action.From, metadata, &initParams, &powerShapingParams)
consumerId := tr.CreateConsumer(providerChainCfg.ChainId, consumerChainCfg.ChainId, action.From, metadata, &initParams, &powerShapingParams)
if verbose {
fmt.Println("Create consumer chain", string(action.ConsumerChain), " with consumer-id", string(consumerId))
fmt.Println("Created consumer chain", string(consumerChainCfg.ChainId), " with consumer-id", string(consumerId))
}

// Set the new created consumer-id on the chain's config
consumerChainCfg.ConsumerId = consumerId
tr.testConfig.chainConfigs[action.ConsumerChain] = consumerChainCfg
}

type SubmitConsumerAdditionProposalAction struct {
Expand All @@ -391,7 +404,7 @@ type SubmitConsumerAdditionProposalAction struct {
AllowInactiveVals bool
}

func (tr Chain) UpdateConsumer(providerChain ChainID, validator ValidatorID, update types.MsgUpdateConsumer) {
func (tr Chain) UpdateConsumer(providerChain ChainID, validator ValidatorID, update types.MsgUpdateConsumer, verbose bool) {
content, err := json.Marshal(update)
if err != nil {
log.Fatal("failed marshalling MsgUpdateConsumer: ", err.Error())
Expand Down Expand Up @@ -420,7 +433,8 @@ func (tr Chain) UpdateConsumer(providerChain ChainID, validator ValidatorID, upd

bz, err = cmd.CombinedOutput()
if err != nil {
log.Fatal("update consumer failed ", "error: ", err, "output: ", string(bz))
fmt.Println("command failed: ", cmd)
log.Fatal("update consumer failed error: %w, output: %s", err, string(bz))
}

// Check transaction
Expand All @@ -433,15 +447,19 @@ func (tr Chain) UpdateConsumer(providerChain ChainID, validator ValidatorID, upd
if txResponse.Code != 0 {
log.Fatalf("sending update-consumer transaction failed with error code %d, Log:'%s'", txResponse.Code, txResponse.RawLog)
}

if verbose {
fmt.Println("running 'update-consumer' returned: ", txResponse)
}

tr.waitBlocks(providerChain, 2, 10*time.Second)
}

// CreateConsumer creates a consumer chain and returns its consumer-id
func (tr Chain) CreateConsumer(providerChain, consumerChain ChainID, validator ValidatorID, metadata types.ConsumerMetadata, initParams *types.ConsumerInitializationParameters, powerShapingParams *types.PowerShapingParameters) ConsumerID {

chainID := string(tr.testConfig.chainConfigs[consumerChain].ChainId)
msg := types.MsgCreateConsumer{
ChainId: chainID,
ChainId: string(consumerChain),
Metadata: metadata,
InitializationParameters: initParams,
PowerShapingParameters: powerShapingParams,
Expand Down Expand Up @@ -524,19 +542,7 @@ func (tr Chain) CreateConsumer(providerChain, consumerChain ChainID, validator V
log.Fatalf("no consumer-id found in consumer creation transaction events for chain '%s'. events: %v", consumerChain, txResponse.Events)
}

cfg, exists := tr.testConfig.chainConfigs[e2e.ChainID(chainID)]
if !exists {
log.Fatal("no chain config found for consumer chain", chainID)
}
if cfg.ConsumerId != "" && cfg.ConsumerId != e2e.ConsumerID(consumerId) {
log.Fatalf("chain '%s'registered already with a different consumer ID '%s'", chainID, consumerId)
}

// Set the new created consumer-id on the chain's config
cfg.ConsumerId = e2e.ConsumerID(consumerId)
tr.testConfig.chainConfigs[e2e.ChainID(chainID)] = cfg

return e2e.ConsumerID(consumerId)
return ConsumerID(consumerId)
}

// submitConsumerAdditionProposal initializes a consumer chain and submits a governance proposal
Expand All @@ -546,6 +552,8 @@ func (tr Chain) submitConsumerAdditionProposal(
) {
params := ccvtypes.DefaultParams()
spawnTime := tr.testConfig.containerConfig.Now.Add(time.Duration(action.SpawnTime) * time.Millisecond)
consumerChainCfg := tr.testConfig.chainConfigs[action.ConsumerChain]
providerChainCfg := tr.testConfig.chainConfigs[action.Chain]

Metadata := types.ConsumerMetadata{
Name: "chain " + string(action.Chain),
Expand All @@ -568,8 +576,11 @@ func (tr Chain) submitConsumerAdditionProposal(
DistributionTransmissionChannel: action.DistributionChannel,
}

consumerId := tr.CreateConsumer(action.Chain, action.ConsumerChain, action.From, Metadata, nil, nil)
consumerId := tr.CreateConsumer(providerChainCfg.ChainId, consumerChainCfg.ChainId, action.From, Metadata, nil, nil)
authority := "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn"
// Set the new created consumer-id on the chain's config
consumerChainCfg.ConsumerId = consumerId
tr.testConfig.chainConfigs[action.ConsumerChain] = consumerChainCfg

// Update consumer to change owner to governance before submitting the proposal
update := &types.MsgUpdateConsumer{
Expand All @@ -587,7 +598,7 @@ func (tr Chain) submitConsumerAdditionProposal(
AllowInactiveVals: action.AllowInactiveVals,
}
update.PowerShapingParameters = &powerShapingParameters
tr.UpdateConsumer(action.Chain, action.From, *update)
tr.UpdateConsumer(action.Chain, action.From, *update, verbose)

// - set PowerShaping params TopN > 0 for consumer chain
update.PowerShapingParameters.Top_N = action.TopN
Expand Down Expand Up @@ -620,10 +631,10 @@ func (tr Chain) submitConsumerAdditionProposal(
tr.testConfig.chainConfigs[action.Chain].BinaryName,
"tx", "gov", "submit-proposal", proposalFile,
`--from`, `validator`+fmt.Sprint(action.From),
`--chain-id`, string(tr.testConfig.chainConfigs[action.Chain].ChainId),
`--home`, tr.getValidatorHome(action.Chain, action.From),
`--chain-id`, string(providerChainCfg.ChainId),
`--home`, tr.getValidatorHome(providerChainCfg.ChainId, action.From),
`--gas`, `900000`,
`--node`, tr.getValidatorNode(action.Chain, action.From),
`--node`, tr.getValidatorNode(providerChainCfg.ChainId, action.From),
`--keyring-backend`, `test`,
`-o json`,
`-y`,
Expand Down Expand Up @@ -653,7 +664,7 @@ func (tr Chain) submitConsumerAdditionProposal(
}

// wait for inclusion in a block -> '--broadcast-mode block' is deprecated
tr.waitBlocks(action.Chain, 2, 10*time.Second)
tr.waitBlocks(providerChainCfg.ChainId, 2, 10*time.Second)
}

func (tr Chain) submitConsumerAdditionLegacyProposal(
Expand Down Expand Up @@ -2890,8 +2901,10 @@ func (tr Chain) startConsumerEvidenceDetector(
}

type OptInAction struct {
Chain ChainID
Validator ValidatorID
Chain ChainID
Validator ValidatorID
ExpectError bool
ExpectedError string
}

func (tr Chain) optIn(action OptInAction, verbose bool) {
Expand Down Expand Up @@ -2924,14 +2937,21 @@ func (tr Chain) optIn(action OptInAction, verbose bool) {
}

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

if !tr.testConfig.useCometmock { // error report only works with --gas auto, which does not work with CometMock, so ignore
if action.ExpectError && !tr.testConfig.useCometmock { // error report only works with --gas auto, which does not work with CometMock, so ignore
if err != nil && verbose {
fmt.Printf("got error during opt in | err: %s | output: %s \n", err, string(bz))
}
if err == nil || !strings.Contains(string(bz), action.ExpectedError) {
log.Fatalf("expected error not raised: expected: '%s', got '%s'", action.ExpectedError, (bz))
}

if verbose {
fmt.Printf("got expected error during key assignment | err: %s | output: %s \n", err, string(bz))
}
}

// wait for inclusion in a block -> '--broadcast-mode block' is deprecated
Expand Down
70 changes: 68 additions & 2 deletions tests/e2e/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const (
InactiveValsMintTestCfg TestConfigType = "inactive-vals-mint"
MintTestCfg TestConfigType = "mint"
InactiveValsExtraValsTestCfg TestConfigType = "inactive-vals-extra-vals"
PermissionlessTestCfg TestConfigType = "permissionless-ics"
)

type TestConfig struct {
Expand All @@ -108,6 +109,7 @@ type TestConfig struct {
containerConfig ContainerConfig
validatorConfigs map[ValidatorID]ValidatorConfig
chainConfigs map[ChainID]ChainConfig
consumerChains map[ConsumerID]ChainConfig
providerVersion string
consumerVersion string
// override config.toml parameters
Expand Down Expand Up @@ -209,6 +211,8 @@ func GetTestConfig(cfgType TestConfigType, providerVersion, consumerVersion stri
testCfg = MintTestConfig()
case InactiveValsExtraValsTestCfg:
testCfg = InactiveValsExtraValsTestConfig()
case PermissionlessTestCfg:
testCfg = PermissionlessTestConfig()
default:
panic(fmt.Sprintf("Invalid test config: %s", cfgType))
}
Expand Down Expand Up @@ -593,6 +597,67 @@ func DemocracyTestConfig(allowReward bool) TestConfig {
return tr
}

func PermissionlessTestConfig() TestConfig {
tr := TestConfig{
name: string(DefaultTestCfg),
containerConfig: e2e.ContainerConfig{
ContainerName: "interchain-security-container",
InstanceName: "interchain-security-instance",
CcvVersion: "1",
Now: time.Now(),
},
validatorConfigs: getDefaultValidators(),
chainConfigs: map[ChainID]e2e.ChainConfig{
"provi": {
ChainId: ChainID("provi"),
AccountPrefix: ProviderAccountPrefix,
BinaryName: "interchain-security-pd",
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\" | " +
".app_state.slashing.params.min_signed_per_window = \"0.500000000000000000\" | " +
".app_state.slashing.params.downtime_jail_duration = \"60s\" | " +
".app_state.slashing.params.slash_fraction_downtime = \"0.010000000000000000\" | " +
".app_state.provider.params.slash_meter_replenish_fraction = \"1.0\" | " + // This disables slash packet throttling
".app_state.provider.params.slash_meter_replenish_period = \"3s\" | " +
".app_state.provider.params.blocks_per_epoch = 3",
},
"cons1": {
ChainId: ChainID("consu"),
AccountPrefix: ConsumerAccountPrefix,
BinaryName: "interchain-security-cd",
IpPrefix: "7.7.8",
VotingWaitTime: 20,
GenesisChanges: ".app_state.gov.params.voting_period = \"20s\" | " +
".app_state.slashing.params.signed_blocks_window = \"20\" | " +
".app_state.slashing.params.min_signed_per_window = \"0.500000000000000000\" | " +
".app_state.slashing.params.downtime_jail_duration = \"60s\" | " +
".app_state.slashing.params.slash_fraction_downtime = \"0.010000000000000000\"",
},
// ChainID needs to be "consu" as previous consumer chain
"cons2": {
ChainId: ChainID("consu"),
AccountPrefix: ConsumerAccountPrefix,
BinaryName: "interchain-security-cd",
IpPrefix: "7.7.9",
VotingWaitTime: 20,
GenesisChanges: ".app_state.gov.params.voting_period = \"20s\" | " +
".app_state.slashing.params.signed_blocks_window = \"20\" | " +
".app_state.slashing.params.min_signed_per_window = \"0.500000000000000000\" | " +
".app_state.slashing.params.downtime_jail_duration = \"60s\" | " +
".app_state.slashing.params.slash_fraction_downtime = \"0.010000000000000000\"",
},
},
tendermintConfigOverride: `s/timeout_commit = "5s"/timeout_commit = "1s"/;` +
`s/peer_gossip_sleep_duration = "100ms"/peer_gossip_sleep_duration = "50ms"/;`,
}
tr.Initialize()
return tr
}
func InactiveProviderValsTestConfig() TestConfig {
tr := DefaultTestConfig()
tr.name = "InactiveValsConfig"
Expand Down Expand Up @@ -957,11 +1022,11 @@ func (s *TestConfig) validateStringLiterals() {

for chainID, chainConfig := range s.chainConfigs {
if len(chainID) > 5 {
panic("chain id string literal must be 5 char or less")
panic(fmt.Sprintf("chain id string literal must be 5 char or less: %s", chainID))
}

if chainID != chainConfig.ChainId {
panic("chain config is mapped to a chain id that is different than what's stored in the config")
log.Println("chain config is mapped to a chain id that is different than what's stored in the config")
}
}
}
Expand Down Expand Up @@ -1265,6 +1330,7 @@ func getValidatorConfigFromVersion(providerVersion, consumerVersion string) map[
// If provided version is before v1.6.0 then a configuration based on template for v1.4.x is returned
// otherwise the returned configuration is based on template v1.4.
func GetHermesConfig(hermesVersion, queryNodeIP string, chainCfg ChainConfig, isConsumer bool) string {

ChainId := chainCfg.ChainId
keyName := "query"
rpcAddr := "http://" + queryNodeIP + ":26658"
Expand Down
7 changes: 3 additions & 4 deletions tests/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,12 @@ var stepChoices = map[string]StepChoice{
description: "test minting without inactive validators as a sanity check",
testConfig: MintTestCfg,
},
// TODO PERMISSIONLESS: ADD NEW E2E TEST
/* "permissionless-ics": {
"permissionless-ics": {
name: "permissionless-ics",
steps: stepsPermissionlessICS(),
description: "test permissionless ics",
testConfig: DefaultTestCfg,
}, */
testConfig: PermissionlessTestCfg,
},
"inactive-vals-outside-max-validators": {
name: "inactive-vals-outside-max-validators",
steps: stepsInactiveValsTopNReproduce(),
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func (tr Chain) getValidatorIP(chain ChainID, validator ValidatorID) string {
}

func (tr Chain) getValidatorHome(chain ChainID, validator ValidatorID) string {
return `/` + string(tr.testConfig.chainConfigs[chain].ChainId) + `/validator` + fmt.Sprint(validator)
return `/` + string(chain) + `/validator` + fmt.Sprint(validator)
}

func (tr Chain) curlJsonRPCRequest(method, params, address string) {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/steps_partial_set_security.go
Original file line number Diff line number Diff line change
Expand Up @@ -1752,7 +1752,7 @@ func stepsValidatorsDenylistedChain() []Step {
ChainID("consu"): ChainState{
ValPowers: &map[ValidatorID]uint{
ValidatorID("alice"): 100,
// "bob" is denylisted and hence does not valiate the consumer chain
// "bob" is denylisted and hence does not validate the consumer chain
ValidatorID("bob"): 0,
ValidatorID("carol"): 300,
},
Expand Down
Loading

0 comments on commit 22190a4

Please sign in to comment.