Skip to content

Commit

Permalink
wait for number of blocks instead of seconds and check successful votes
Browse files Browse the repository at this point in the history
  • Loading branch information
MalteHerrmann committed May 7, 2024
1 parent 47d59a8 commit 55aeb90
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
15 changes: 13 additions & 2 deletions gov/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@ func SubmitAllVotesForProposal(bin *utils.Binary, proposalID int) error {
return errors.New("no accounts with delegations found")
}

utils.Wait(1)
if err := utils.WaitNBlocks(bin, 1); err != nil {
return err

Check failure on line 34 in gov/vote.go

View workflow job for this annotation

GitHub Actions / lint

error returned from external package is unwrapped: sig: func github.com/MalteHerrmann/evmos-utils/utils.WaitNBlocks(bin *github.com/MalteHerrmann/evmos-utils/utils.Binary, n int) error (wrapcheck)
}

bin.Logger.Info().Msgf("voting for proposal %d", proposalID)

var out string
var (
out string
successfulVotes int
)

for _, acc := range accsWithDelegations {
out, err = VoteForProposal(bin, proposalID, acc.Name)
Expand All @@ -49,9 +55,14 @@ func SubmitAllVotesForProposal(bin *utils.Binary, proposalID int) error {
bin.Logger.Error().Msgf("could not vote using key %s: %v", acc.Name, err)
} else {
bin.Logger.Info().Msgf("voted using key %s", acc.Name)
successfulVotes += 1

Check warning on line 58 in gov/vote.go

View workflow job for this annotation

GitHub Actions / lint

increment-decrement: should replace successfulVotes += 1 with successfulVotes++ (revive)
}
}

if successfulVotes == 0 {
return errors.New("there were no successful votes for the proposal, please check logs")
}

return nil
}

Expand Down
22 changes: 19 additions & 3 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,23 @@ func GetTxHashFromTxResponse(cdc *codec.ProtoCodec, out string) (string, error)
return txHash.TxHash, nil
}

// Wait waits for the specified amount of seconds.
func Wait(seconds int) {
time.Sleep(time.Duration(seconds) * time.Second)
// WaitNBlocks waits for the specified amount of blocks being produced
// on the connected network.
func WaitNBlocks(bin *Binary, n int) error {

Check failure on line 192 in utils/utils.go

View workflow job for this annotation

GitHub Actions / lint

parameter name 'n' is too short for the scope of its usage (varnamelen)
currentBlockRes, err := ExecuteQuery(bin, QueryArgs{
Subcommand: []string{"q", "block"},
})
if err != nil {
return err
}

fmt.Printf("block res: \n%s\n", currentBlockRes)

Check failure on line 200 in utils/utils.go

View workflow job for this annotation

GitHub Actions / lint

use of `fmt.Printf` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
panic("")

for {

Check failure on line 203 in utils/utils.go

View workflow job for this annotation

GitHub Actions / lint

unreachable: unreachable code (govet)
bin.Logger.Debug().Msgf("waiting for %d blocks\n", n)
break

Check failure on line 205 in utils/utils.go

View workflow job for this annotation

GitHub Actions / lint

break with no blank line before (nlreturn)
}

return nil
}

0 comments on commit 55aeb90

Please sign in to comment.