Skip to content

Commit

Permalink
Start adding e2e test
Browse files Browse the repository at this point in the history
p-offtermatt committed May 23, 2024
1 parent 519a329 commit 0285039
Showing 7 changed files with 451 additions and 6 deletions.
14 changes: 14 additions & 0 deletions tests/e2e/config.go
Original file line number Diff line number Diff line change
@@ -87,6 +87,7 @@ const (
MulticonsumerTestCfg TestConfigType = "multi-consumer"
ConsumerMisbehaviourTestCfg TestConfigType = "consumer-misbehaviour"
CompatibilityTestCfg TestConfigType = "compatibility"
InactiveValsCfg TestConfigType = "inactive-vals"
)

// Attributes that are unique to a validator. Allows us to map (part of)
@@ -264,6 +265,8 @@ func GetTestConfig(cfgType TestConfigType, providerVersion, consumerVersion stri
testCfg = ConsumerMisbehaviourTestConfig()
case CompatibilityTestCfg:
testCfg = CompatibilityTestConfig(pv, cv)
case InactiveValsCfg:
testCfg = InactiveValsConfig()
default:
panic(fmt.Sprintf("Invalid test config: %s", cfgType))
}
@@ -500,6 +503,17 @@ func CompatibilityTestConfig(providerVersion, consumerVersion string) TestConfig
return testCfg
}

func InactiveValsConfig() TestConfig {
tr := DefaultTestConfig()
tr.name = "InactiveValsConfig"
// set the MaxProviderConsensusValidators param to 2
proviConfig := tr.chainConfigs[ChainID("provi")]
proviConfig.GenesisChanges += " | .app_state.provider.params.max_provider_consensus_validators = \"2\""
tr.chainConfigs[ChainID("provi")] = proviConfig

return tr
}

func DefaultTestConfig() TestConfig {
tr := TestConfig{
name: string(DefaultTestCfg),
6 changes: 6 additions & 0 deletions tests/e2e/main.go
Original file line number Diff line number Diff line change
@@ -168,6 +168,12 @@ var stepChoices = map[string]StepChoice{
description: "test partial set security for a Top-N chain",
testConfig: DefaultTestCfg,
},
"inactive-validators-on-consumer": {
name: "inactive-validators-on-consumer",
steps: stepsInactiveValidatorsOnConsumer(),
description: "test inactive validators on consumer",
testConfig: InactiveValsCfg,
},
}

func getTestCaseUsageString() string {
13 changes: 9 additions & 4 deletions tests/e2e/state.go
Original file line number Diff line number Diff line change
@@ -328,22 +328,22 @@ func (tr TestConfig) getRewards(chain ChainID, modelState Rewards) Rewards {

func (tr TestConfig) getReward(chain ChainID, validator ValidatorID, blockHeight uint, isNativeDenom bool) float64 {
valCfg := tr.validatorConfigs[validator]
delAddresss := valCfg.DelAddress
delAddress := valCfg.DelAddress
if chain != ChainID("provi") {
// use binary with Bech32Prefix set to ConsumerAccountPrefix
if valCfg.UseConsumerKey {
delAddresss = valCfg.ConsumerDelAddress
delAddress = valCfg.ConsumerDelAddress
} else {
// use the same address as on the provider but with different prefix
delAddresss = valCfg.DelAddressOnConsumer
delAddress = valCfg.DelAddressOnConsumer
}
}

//#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments.
bz, err := exec.Command("docker", "exec", tr.containerConfig.InstanceName, tr.chainConfigs[chain].BinaryName,

"query", "distribution", "rewards",
delAddresss,
delAddress,

`--height`, fmt.Sprint(blockHeight),
`--node`, tr.getQueryNode(chain),
@@ -358,6 +358,11 @@ func (tr TestConfig) getReward(chain ChainID, validator ValidatorID, blockHeight
denomCondition = `total.#(denom=="stake").amount`
}

if *verbose {
log.Println("Getting reward for chain: ", chain, " validator: ", validator, " block: ", blockHeight)
log.Println("Reward response: ", string(bz))
}

return gjson.Get(string(bz), denomCondition).Float()
}

Loading

0 comments on commit 0285039

Please sign in to comment.