Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TestProperty_DifferentVotingPower by providing randomized stake amounts #1507

Merged
merged 3 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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