Skip to content

Commit

Permalink
address new comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bermuell committed Sep 2, 2024
1 parent c3cb9a9 commit bc8b6f0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 33 deletions.
47 changes: 24 additions & 23 deletions tests/e2e/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,13 @@ func (tr Chain) updateConsumerChain(action UpdateConsumerChainAction, verbose bo
}

consumerId := tr.testConfig.chainConfigs[action.ConsumerChain].ConsumerId
update := types.MsgUpdateConsumer{
msg := types.MsgUpdateConsumer{
ConsumerId: string(consumerId),
NewOwnerAddress: action.NewOwner,
InitializationParameters: &initParams,
PowerShapingParameters: &powerShapingParams,
}
tr.UpdateConsumer(action.Chain, action.From, update)
tr.UpdateConsumer(action.Chain, action.From, msg)
}

type CreateConsumerChainAction struct {
Expand Down Expand Up @@ -396,7 +396,7 @@ func (tr Chain) UpdateConsumer(providerChain ChainID, validator ValidatorID, upd
if err != nil {
log.Fatal("failed marshalling MsgUpdateConsumer: ", err.Error())
}
jsonFile := "/update_consumer.json"
jsonFile := "/update-consumer.json"
bz, err := tr.target.ExecCommand(
"/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, content, jsonFile),
).CombinedOutput()
Expand Down Expand Up @@ -440,18 +440,18 @@ func (tr Chain) UpdateConsumer(providerChain ChainID, validator ValidatorID, upd
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)
rec := types.MsgCreateConsumer{
msg := types.MsgCreateConsumer{
ChainId: chainID,
Metadata: metadata,
InitializationParameters: initParams,
PowerShapingParameters: powerShapingParams,
}

content, err := json.Marshal(rec)
content, err := json.Marshal(msg)
if err != nil {
log.Fatalf("failed marshalling MsgCreateConsumer: %s", err.Error())
}
jsonFile := "/create_consumer.json"
jsonFile := "/create-consumer.json"
bz, err := tr.target.ExecCommand(
"/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, content, jsonFile),

Check failure

Code scanning / CodeQL

Potentially unsafe quoting Critical test

If this
JSON value
contains a single quote, it could break out of the enclosing quotes.
).CombinedOutput()
Expand Down Expand Up @@ -500,7 +500,8 @@ func (tr Chain) CreateConsumer(providerChain, consumerChain ChainID, validator V
)
bz, err = cmd.CombinedOutput()
if err != nil {
log.Fatal("not able to query tx containing creation-consumer: cmd:", cmd, "err:", err.Error(), "out:", string(bz))
log.Fatalf("not able to query tx containing creation-consumer: tx: %s, err: %s, out: %s",
txResponse.TxHash, err.Error(), string(bz))
}

err = json.Unmarshal(bz, txResponse)
Expand Down Expand Up @@ -528,7 +529,7 @@ func (tr Chain) CreateConsumer(providerChain, consumerChain ChainID, validator V
log.Fatal("no chain config found for consumer chain", chainID)
}
if cfg.ConsumerId != "" && cfg.ConsumerId != e2e.ConsumerID(consumerId) {
log.Fatal("chain ", chainID, " registered already with a different consumer ID", 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
Expand Down Expand Up @@ -605,7 +606,7 @@ func (tr Chain) submitConsumerAdditionProposal(
jsonStr := e2e.GenerateGovProposalContent(title, summary, metadata, deposit, description, expedited, update)

// #nosec G204 -- bypass unsafe quoting warning (no production code)
proposalFile := "/consumer-addition.proposal"
proposalFile := "/update-consumer-proposal.json"
bz, err := tr.target.ExecCommand(
"/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, jsonStr, proposalFile),

Check failure

Code scanning / CodeQL

Potentially unsafe quoting Critical test

If this
JSON value
contains a single quote, it could break out of the enclosing quotes.
).CombinedOutput()
Expand Down Expand Up @@ -749,7 +750,7 @@ func (tr Chain) submitConsumerRemovalProposal(
action SubmitConsumerRemovalProposalAction,
verbose bool,
) {
consumerID := string(tr.testConfig.chainConfigs[action.ConsumerChain].ConsumerId)
consumerId := string(tr.testConfig.chainConfigs[action.ConsumerChain].ConsumerId)
title := fmt.Sprintf("Stop the %v chain", action.ConsumerChain)
description := "stop consumer chain"
summary := "It was a great chain"
Expand All @@ -758,16 +759,16 @@ func (tr Chain) submitConsumerRemovalProposal(
deposit := fmt.Sprintf("%dstake", action.Deposit)
authority := "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn"

msgRemoveConsumer := types.MsgRemoveConsumer{
ConsumerId: consumerID,
msg := types.MsgRemoveConsumer{
ConsumerId: consumerId,
StopTime: tr.testConfig.containerConfig.Now.Add(action.StopTimeOffset),
Signer: authority,
}

jsonStr := e2e.GenerateGovProposalContent(title, summary, metadata, deposit, description, expedited, &msgRemoveConsumer)
jsonStr := e2e.GenerateGovProposalContent(title, summary, metadata, deposit, description, expedited, &msg)

// #nosec G204 -- bypass unsafe quoting warning (no production code)
proposalFile := "/consumer-removal.proposal"
proposalFile := "/remove-consumer-proposal.json"
bz, err := tr.target.ExecCommand(
"/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, jsonStr, proposalFile),

Check failure

Code scanning / CodeQL

Potentially unsafe quoting Critical test

If this
JSON value
contains a single quote, it could break out of the enclosing quotes.
).CombinedOutput()
Expand Down Expand Up @@ -882,7 +883,7 @@ func (tr Chain) submitConsumerModificationProposal(
deposit := fmt.Sprintf("%dstake", action.Deposit)
authority := "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn"

msgConsMod := types.MsgUpdateConsumer{
msg := types.MsgUpdateConsumer{
Signer: authority,
ConsumerId: consumerId,
PowerShapingParameters: &types.PowerShapingParameters{
Expand All @@ -894,9 +895,9 @@ func (tr Chain) submitConsumerModificationProposal(
},
}

jsonStr := e2e.GenerateGovProposalContent(title, summary, metadata, deposit, description, expedited, &msgConsMod)
jsonStr := e2e.GenerateGovProposalContent(title, summary, metadata, deposit, description, expedited, &msg)
// #nosec G204 -- bypass unsafe quoting warning (no production code)
proposalFile := "/consumer-mod.proposal"
proposalFile := "/update-consumer-proposal.json"
bz, err := tr.target.ExecCommand(
"/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, jsonStr, proposalFile),

Check failure

Code scanning / CodeQL

Potentially unsafe quoting Critical test

If this
JSON value
contains a single quote, it could break out of the enclosing quotes.
).CombinedOutput()
Expand Down Expand Up @@ -1132,7 +1133,7 @@ func (tr *Chain) startConsumerChain(
func (tr *Chain) getConsumerGenesis(providerChain, consumerChain ChainID) string {
fmt.Println("Exporting consumer genesis from provider")
providerBinaryName := tr.testConfig.chainConfigs[providerChain].BinaryName
consumerID := string(tr.testConfig.chainConfigs[consumerChain].ConsumerId)
consumerId := string(tr.testConfig.chainConfigs[consumerChain].ConsumerId)

now := time.Now()
timeout := now.Add(30 * time.Second)
Expand All @@ -1142,7 +1143,7 @@ func (tr *Chain) getConsumerGenesis(providerChain, consumerChain ChainID) string
cmd := tr.target.ExecCommand(
providerBinaryName,

"query", "provider", "consumer-genesis", consumerID,
"query", "provider", "consumer-genesis", consumerId,

`--node`, tr.target.GetQueryNode(providerChain),
`-o`, `json`,
Expand Down Expand Up @@ -2490,7 +2491,7 @@ func (tr Chain) submitChangeRewardDenomsProposal(action SubmitChangeRewardDenoms
jsonStr := e2e.GenerateGovProposalContent(title, summary, metadata, deposit, description, expedited, &changeRewMsg)

//#nosec G204 -- bypass unsafe quoting warning (no production code)
proposalFile := "/change-rewards.proposal"
proposalFile := "/change-rewards-proposal.json"
bz, err := tr.target.ExecCommand(
"/bin/bash", "-c", fmt.Sprintf(`echo '%s' > %s`, jsonStr, proposalFile),

Check failure

Code scanning / CodeQL

Potentially unsafe quoting Critical test

If this
JSON value
contains a single quote, it could break out of the enclosing quotes.
).CombinedOutput()
Expand Down Expand Up @@ -3013,16 +3014,16 @@ func (tr Chain) setConsumerCommissionRate(action SetConsumerCommissionRateAction
gas = "9000000"
}

consumerID := string(tr.testConfig.chainConfigs[action.Chain].ConsumerId)
consumerId := string(tr.testConfig.chainConfigs[action.Chain].ConsumerId)
if action.ConsumerID != "" {
consumerID = string(action.ConsumerID)
consumerId = string(action.ConsumerID)
}

// Use: "set-consumer-commission-rate [consumer-chain-id] [commission-rate]"
setCommissionRate := fmt.Sprintf(
`%s tx provider set-consumer-commission-rate %s %f --from validator%s --chain-id %s --home %s --node %s --gas %s --keyring-backend test -y -o json`,
tr.testConfig.chainConfigs[ChainID("provi")].BinaryName,
consumerID,
consumerId,
action.CommissionRate,
action.Validator,
tr.testConfig.chainConfigs[ChainID("provi")].ChainId,
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,6 @@ func main() {
log.Fatalf("Error parsing command arguments %s\n", err)
}

//SetupLogger()
testCases := getTestCases(selectedTests, selectedTestfiles, providerVersions, consumerVersions)
testRunners := createTestRunners(testCases)
defer deleteTargets(testRunners)
Expand Down
20 changes: 11 additions & 9 deletions tests/e2e/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ func (tr Commands) GetProposal(chain ChainID, proposal uint) Proposal {
for _, chainCfg := range tr.chainConfigs {
if chainCfg.ConsumerId == e2e.ConsumerID(consumerId) {
consumerChainId = chainCfg.ChainId
break
}
}

Check warning

Code scanning / CodeQL

Iteration over map Warning test

Iteration over map may be a possible source of non-determinism

Expand All @@ -481,7 +482,7 @@ func (tr Commands) GetProposal(chain ChainID, proposal uint) Proposal {
Chain: consumerChainId,
Status: status,
}
if rawContent.Get("initialization_parameter").Exists() {
if rawContent.Get("initialization_parameters").Exists() {
spawnTime := rawContent.Get("initialization_parameters.spawn_time").Time().Sub(tr.containerConfig.Now)
updateProposal.SpawnTime = int(spawnTime.Milliseconds())
updateProposal.InitialHeight = clienttypes.Height{
Expand Down Expand Up @@ -524,12 +525,12 @@ func (tr Commands) GetProposal(chain ChainID, proposal uint) Proposal {
Type: "/cosmos.upgrade.v1beta1.SoftwareUpgradeProposal",
}
case "/interchain_security.ccv.provider.v1.MsgRemoveConsumer":
consumerID := rawContent.Get("consumer_id").String()
consumerId := rawContent.Get("consumer_id").String()
stopTime := rawContent.Get("stop_time").Time().Sub(tr.containerConfig.Now)

var chain ChainID
for i, conf := range tr.chainConfigs {
if string(conf.ConsumerId) == consumerID {
if string(conf.ConsumerId) == consumerId {
chain = i
break
}
Expand Down Expand Up @@ -785,11 +786,11 @@ func (tr Commands) GetConsumerChains(chain ChainID) map[ChainID]bool {

func (tr Commands) GetConsumerAddress(consumerChain ChainID, validator ValidatorID) string {
binaryName := tr.chainConfigs[ChainID("provi")].BinaryName
consumer_id := tr.chainConfigs[ChainID(consumerChain)].ConsumerId
consumerId := tr.chainConfigs[ChainID(consumerChain)].ConsumerId
cmd := tr.target.ExecCommand(binaryName,

"query", "provider", "validator-consumer-key",
string(consumer_id), tr.validatorConfigs[validator].ValconsAddress,
string(consumerId), tr.validatorConfigs[validator].ValconsAddress,
`--node`, tr.GetQueryNode(ChainID("provi")),
`-o`, `json`,
)
Expand All @@ -804,12 +805,12 @@ func (tr Commands) GetConsumerAddress(consumerChain ChainID, validator Validator

func (tr Commands) GetProviderAddressFromConsumer(consumerChain ChainID, validator ValidatorID) string {
binaryName := tr.chainConfigs[ChainID("provi")].BinaryName
consumer_id := tr.chainConfigs[ChainID(consumerChain)].ConsumerId
consumerId := tr.chainConfigs[ChainID(consumerChain)].ConsumerId

cmd := tr.target.ExecCommand(binaryName,

"query", "provider", "validator-provider-key",
string(consumer_id), tr.validatorConfigs[validator].ConsumerValconsAddressOnProvider,
string(consumerId), tr.validatorConfigs[validator].ConsumerValconsAddressOnProvider,
`--node`, tr.GetQueryNode(ChainID("provi")),
`-o`, `json`,
)
Expand Down Expand Up @@ -934,6 +935,7 @@ func (tr Commands) GetHasToValidate(
for _, chain := range tr.chainConfigs {
if chain.ConsumerId == ConsumerID(c.String()) {
chains = append(chains, chain.ChainId)
break
}
}

Check warning

Code scanning / CodeQL

Iteration over map Warning test

Iteration over map may be a possible source of non-determinism
}
Expand Down Expand Up @@ -1055,11 +1057,11 @@ func (tr Commands) GetQueryNodeIP(chain ChainID) string {
// GetConsumerCommissionRate returns the commission rate of the given validator on the given consumerChain
func (tr Commands) GetConsumerCommissionRate(consumerChain ChainID, validator ValidatorID) float64 {
binaryName := tr.chainConfigs[ChainID("provi")].BinaryName
consumerID := tr.chainConfigs[consumerChain].ConsumerId
consumerId := tr.chainConfigs[consumerChain].ConsumerId

cmd := tr.target.ExecCommand(binaryName,
"query", "provider", "validator-consumer-commission-rate",
string(consumerID), tr.validatorConfigs[validator].ValconsAddress,
string(consumerId), tr.validatorConfigs[validator].ValconsAddress,
`--node`, tr.GetQueryNode(ChainID("provi")),
`-o`, `json`,
)
Expand Down

0 comments on commit bc8b6f0

Please sign in to comment.