Skip to content

e2e: Add test of platform.getValidatorsAt across nodes #2664

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

Merged
merged 4 commits into from
Jan 26, 2024
Merged
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
113 changes: 113 additions & 0 deletions tests/e2e/p/validator_sets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package p

import (
"fmt"
"time"

ginkgo "github.com/onsi/ginkgo/v2"

"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/genesis"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/tests"
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
"github.com/ava-labs/avalanchego/vms/platformvm"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
)

var _ = e2e.DescribePChain("[Validator Sets]", func() {
require := require.New(ginkgo.GinkgoT())

ginkgo.It("should be identical for every height for all nodes in the network", func() {
network := e2e.Env.GetNetwork()

ginkgo.By("creating wallet with a funded key to source delegated funds from")
keychain := e2e.Env.NewKeychain(1)
nodeURI := e2e.Env.GetRandomNodeURI()
baseWallet := e2e.NewWallet(keychain, nodeURI)
pWallet := baseWallet.P()

const delegatorCount = 15
ginkgo.By(fmt.Sprintf("adding %d delegators", delegatorCount), func() {
rewardKey, err := secp256k1.NewPrivateKey()
require.NoError(err)
avaxAssetID := pWallet.AVAXAssetID()
startTime := time.Now().Add(tmpnet.DefaultValidatorStartTimeDiff)
endTime := startTime.Add(time.Second * 360)
// This is the default flag value for MinDelegatorStake.
weight := genesis.LocalParams.StakingConfig.MinDelegatorStake

for i := 0; i < delegatorCount; i++ {
_, err = pWallet.IssueAddPermissionlessDelegatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: nodeURI.NodeID,
Start: uint64(startTime.Unix()),
End: uint64(endTime.Unix()),
Wght: weight,
},
Subnet: constants.PrimaryNetworkID,
},
avaxAssetID,
&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{rewardKey.Address()},
},
e2e.WithDefaultContext(),
)
require.NoError(err)
}
})

ginkgo.By("getting the current P-Chain height from the wallet")
currentPChainHeight, err := platformvm.NewClient(nodeURI.URI).GetHeight(e2e.DefaultContext())
require.NoError(err)

ginkgo.By("checking that validator sets are equal across all heights for all nodes", func() {
pvmClients := make([]platformvm.Client, len(e2e.Env.URIs))
for i, nodeURI := range e2e.Env.URIs {
pvmClients[i] = platformvm.NewClient(nodeURI.URI)
// Ensure that the height of the target node is at least the expected height
e2e.Eventually(
func() bool {
pChainHeight, err := pvmClients[i].GetHeight(e2e.DefaultContext())
require.NoError(err)
return pChainHeight >= currentPChainHeight
},
e2e.DefaultTimeout,
e2e.DefaultPollingInterval,
fmt.Sprintf("failed to see expected height %d for %s before timeout", currentPChainHeight, nodeURI.NodeID),
)
}

for height := uint64(0); height <= currentPChainHeight; height++ {
tests.Outf(" checked validator sets for height %d\n", height)
var observedValidatorSet map[ids.NodeID]*validators.GetValidatorOutput
for _, pvmClient := range pvmClients {
validatorSet, err := pvmClient.GetValidatorsAt(
e2e.DefaultContext(),
constants.PrimaryNetworkID,
height,
)
require.NoError(err)
if observedValidatorSet == nil {
observedValidatorSet = validatorSet
continue
}
require.Equal(observedValidatorSet, validatorSet)
}
}
})

e2e.CheckBootstrapIsPossible(network)
})
})