Skip to content

Commit

Permalink
Fix TestProperty_DifferentVotingPower by providing randomized stake…
Browse files Browse the repository at this point in the history
… amounts (#1507)

* Fix test by providing randomized stake amount to different validators

* Provide count flag instead of timeout

* Provide rapid.checks flag
  • Loading branch information
Stefan-Ethernal authored May 16, 2023
1 parent 56eea51 commit 72fee88
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ test-e2e-polybft:
test-property-polybft:
# We can not build with race because of a bug in boltdb dependency
go build -o artifacts/polygon-edge .
env EDGE_BINARY=${PWD}/artifacts/polygon-edge E2E_TESTS=true E2E_LOGS=true go test -v -timeout=30m ./e2e-polybft/property/...
env EDGE_BINARY=${PWD}/artifacts/polygon-edge E2E_TESTS=true E2E_LOGS=true go test -v -timeout=30m ./e2e-polybft/property/... \
-rapid.checks=10

.PHONY: compile-core-contracts
compile-core-contracts:
Expand Down
19 changes: 10 additions & 9 deletions e2e-polybft/property/property_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ import (
"testing"
"time"

"github.com/0xPolygon/polygon-edge/e2e-polybft/framework"
"github.com/0xPolygon/polygon-edge/types"
"github.com/stretchr/testify/require"
"pgregory.net/rapid"

"github.com/0xPolygon/polygon-edge/e2e-polybft/framework"
"github.com/0xPolygon/polygon-edge/types"
)

func TestProperty_DifferentVotingPower(t *testing.T) {
t.Parallel()

const (
blockTime = time.Second * 6
maxPremine = math.MaxUint64
blockTime = time.Second * 6
maxStake = math.MaxUint64
)

rapid.Check(t, func(tt *rapid.T) {
Expand All @@ -28,18 +29,18 @@ func TestProperty_DifferentVotingPower(t *testing.T) {
numBlocks = rapid.Uint64Range(2, 5).Draw(tt, "number of blocks the cluster should mine")
)

premine := make([]uint64, numNodes)
stakes := make([]uint64, numNodes)

// premined amount will determine validator's stake and therefore voting power
for i := range premine {
premine[i] = rapid.Uint64Range(1, maxPremine).Draw(tt, fmt.Sprintf("stake for node %d", i+1))
// stake amount will determine validator's stake and therefore voting power
for i := range stakes {
stakes[i] = rapid.Uint64Range(1, maxStake).Draw(tt, fmt.Sprintf("stake for node %d", i+1))
}

cluster := framework.NewPropertyTestCluster(t, int(numNodes),
framework.WithEpochSize(epochSize),
framework.WithSecretsCallback(func(adresses []types.Address, config *framework.TestClusterConfig) {
for i, a := range adresses {
config.Premine = append(config.Premine, fmt.Sprintf("%s:%d", a, premine[i]))
config.StakeAmounts = append(config.StakeAmounts, fmt.Sprintf("%s:%d", a, stakes[i]))
}
}))
defer cluster.Stop()
Expand Down

0 comments on commit 72fee88

Please sign in to comment.