From d137d39f01a2e2c85f90e7ea0bc0d1738affb4b1 Mon Sep 17 00:00:00 2001 From: Philip Offtermatt <57488781+p-offtermatt@users.noreply.github.com> Date: Fri, 25 Aug 2023 14:58:57 +0200 Subject: [PATCH] chore: improve logging in getValPower (#1211) * 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 --- tests/e2e/state.go | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/e2e/state.go b/tests/e2e/state.go index 5464b291ac..8cc343ef00 100644 --- a/tests/e2e/state.go +++ b/tests/e2e/state.go @@ -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" ) @@ -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) } @@ -184,6 +186,10 @@ func (tr TestRun) getChainState(chain chainID, modelState ChainState) ChainState chainState.RegisteredConsumerRewardDenoms = ®isteredConsumerRewardDenoms } + if *verbose { + log.Println("Done getting chain state:\n" + pretty.Sprint(chainState)) + } + return chainState } @@ -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 { @@ -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)