Skip to content

Commit

Permalink
resolved conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Feb 13, 2024
2 parents 2124f35 + 7f24c5a commit f94d423
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
### Tests

* [1584](https://github.com/zeta-chain/node/pull/1584) - allow to run E2E tests on any networks
* [1753](https://github.com/zeta-chain/node/pull/1753) - fix gosec errors on usage of rand package

### CI

Expand Down
48 changes: 30 additions & 18 deletions x/emissions/client/tests/suite.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package querytests

import (
"math/rand"
"crypto/rand"
"math/big"
"strconv"
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
ethcfg "github.com/evmos/ethermint/cmd/config"
Expand Down Expand Up @@ -52,7 +54,7 @@ func (s *CliTestSuite) SetupSuite() {
"zeta1e9fyaulgntkrnqnl0es4nyxghp3petpn2ntu3t",
}
network.SetupZetaGenesisState(s.T(), s.cfg.GenesisState, s.cfg.Codec, observerList, false)
s.ballots = RandomBallotGenerator(20, observerList)
s.ballots = RandomBallotGenerator(s.T(), 20, observerList)
network.AddObserverData(s.T(), 2, s.cfg.GenesisState, s.cfg.Codec, s.ballots)

net, err := network.New(s.T(), app.NodeDir, s.cfg)
Expand All @@ -63,32 +65,42 @@ func (s *CliTestSuite) SetupSuite() {

}

func CreateRandomVoteList(numberOfVotes int) []observerTypes.VoteType {
func CreateRandomVoteList(t *testing.T, numberOfVotes int) []observerTypes.VoteType {
voteOptions := []observerTypes.VoteType{observerTypes.VoteType_SuccessObservation, observerTypes.VoteType_FailureObservation, observerTypes.VoteType_NotYetVoted}
min := 0
max := len(voteOptions) - 1
minVoterOptions := 0
maxBoterOptions := len(voteOptions) - 1

randomVoteOptions, err := rand.Int(rand.Reader, big.NewInt(int64(maxBoterOptions-minVoterOptions)))
if err != nil {
t.Fatal(err)
}

voteList := make([]observerTypes.VoteType, numberOfVotes)
for i := 0; i < numberOfVotes; i++ {
voteList[i] = voteOptions[rand.Intn(max-min)+min] // #nosec G404
voteList[i] = voteOptions[randomVoteOptions.Int64()]
}
return voteList
}
func RandomBallotGenerator(numberOfBallots int, voterList []string) []*observerTypes.Ballot {
func RandomBallotGenerator(t *testing.T, numberOfBallots int, voterList []string) []*observerTypes.Ballot {
ballots := make([]*observerTypes.Ballot, numberOfBallots)
ballotStatus := []observerTypes.BallotStatus{observerTypes.BallotStatus_BallotFinalized_FailureObservation, observerTypes.BallotStatus_BallotFinalized_SuccessObservation}
min := 0
max := len(ballotStatus) - 1
// #nosec G404 randomness is not a security issue here
minBallotStatus := 0
maxBallotStatus := len(ballotStatus) - 1

randomBallotStatus, err := rand.Int(rand.Reader, big.NewInt(int64(maxBallotStatus-minBallotStatus)))
if err != nil {
t.Fatal(err)
}

for i := 0; i < numberOfBallots; i++ {
ballots[i] = &observerTypes.Ballot{
Index: "",
BallotIdentifier: "TestBallot" + strconv.Itoa(i),
VoterList: voterList,
Votes: CreateRandomVoteList(len(voterList)),
ObservationType: observerTypes.ObservationType_InBoundTx,
BallotThreshold: sdk.MustNewDecFromStr("0.66"),
// #nosec G404 randomness used for testing
BallotStatus: ballotStatus[rand.Intn(max-min)+min], // #nosec G404 randomness used for testing
Index: "",
BallotIdentifier: "TestBallot" + strconv.Itoa(i),
VoterList: voterList,
Votes: CreateRandomVoteList(t, len(voterList)),
ObservationType: observerTypes.ObservationType_InBoundTx,
BallotThreshold: sdk.MustNewDecFromStr("0.66"),
BallotStatus: ballotStatus[randomBallotStatus.Int64()],
BallotCreationHeight: 0,
}
}
Expand Down

0 comments on commit f94d423

Please sign in to comment.