Skip to content

Commit

Permalink
chore: improve logging in getValPower (#1211)
Browse files Browse the repository at this point in the history
* Add more waits

* Add debug setup for CometMock

* Add extra output for errors in getValPower

* Revert changes to actions.go

* Remove utility script for making tests fail

* Remove unnecessary log after curlJsonRPCRequest

* Remove extra output after waitBlocks

* Revert extraneous change to waitBlocks

* Revert change to verbosity level of curlJsonRPC

* Fix linter

* Add pretty-printed chainstate and set log message to only execute when verbose

* Add pretty printed valset to error message

* Pretty-print the validator set in more error messages
  • Loading branch information
p-offtermatt authored Aug 25, 2023
1 parent b18a317 commit d137d39
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions tests/e2e/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/kylelemons/godebug/pretty"
"github.com/tidwall/gjson"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -111,6 +112,7 @@ type Param struct {
func (tr TestRun) getState(modelState State) State {
systemState := State{}
for k, modelState := range modelState {
log.Println("Getting model state for chain: ", k)
systemState[k] = tr.getChainState(k, modelState)
}

Expand Down Expand Up @@ -184,6 +186,10 @@ func (tr TestRun) getChainState(chain chainID, modelState ChainState) ChainState
chainState.RegisteredConsumerRewardDenoms = &registeredConsumerRewardDenoms
}

if *verbose {
log.Println("Done getting chain state:\n" + pretty.Sprint(chainState))
}

return chainState
}

Expand Down Expand Up @@ -492,32 +498,36 @@ type ValPubKey struct {
}

func (tr TestRun) getValPower(chain chainID, validator validatorID) uint {
if *verbose {
log.Println("getting validator power for chain: ", chain, " validator: ", validator)
}
//#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments.
bz, err := exec.Command("docker", "exec", tr.containerConfig.instanceName, tr.chainConfigs[chain].binaryName,
command := exec.Command("docker", "exec", tr.containerConfig.instanceName, tr.chainConfigs[chain].binaryName,

"query", "tendermint-validator-set",

`--node`, tr.getQueryNode(chain),
).CombinedOutput()
)
bz, err := command.CombinedOutput()
if err != nil {
log.Fatalf("error: %v", err)
log.Fatalf("encountered an error when executing command '%s': %v, output: %s", command.String(), err, string(bz))
}

valset := TmValidatorSetYaml{}

err = yaml.Unmarshal(bz, &valset)
if err != nil {
log.Fatalf("error: %v", err)
log.Fatalf("yaml.Unmarshal returned an error while unmarshalling validator set: %v, input: %s", err, string(bz))
}

total, err := strconv.Atoi(valset.Total)
if err != nil {
log.Fatalf("error: %v", err)
log.Fatalf("strconv.Atoi returned an error while coonverting total for validator set: %v, input: %s, validator set: %s", err, valset.Total, pretty.Sprint(valset))
}

if total != len(valset.Validators) {
log.Fatalf("Total number of validators %v does not match number of validators in list %v. Probably a query pagination issue.",
valset.Total, uint(len(valset.Validators)))
log.Fatalf("Total number of validators %v does not match number of validators in list %v. Probably a query pagination issue. Validator set: %v",
valset.Total, uint(len(valset.Validators)), pretty.Sprint(valset))
}

for _, val := range valset.Validators {
Expand All @@ -526,7 +536,7 @@ func (tr TestRun) getValPower(chain chainID, validator validatorID) uint {

votingPower, err := strconv.Atoi(val.VotingPower)
if err != nil {
log.Fatalf("error: %v", err)
log.Fatalf("strconv.Atoi returned an error while convering validator voting power: %v, voting power string: %s, validator set: %s", err, val.VotingPower, pretty.Sprint(valset))
}

return uint(votingPower)
Expand Down

0 comments on commit d137d39

Please sign in to comment.