-
Notifications
You must be signed in to change notification settings - Fork 668
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
e2e: Migrate staking rewards e2e from kurtosis
- Loading branch information
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package p | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
ginkgo "github.com/onsi/ginkgo/v2" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ava-labs/avalanchego/api/info" | ||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/tests/e2e" | ||
"github.com/ava-labs/avalanchego/tests/fixture/testnet" | ||
"github.com/ava-labs/avalanchego/utils/units" | ||
"github.com/ava-labs/avalanchego/vms/platformvm" | ||
"github.com/ava-labs/avalanchego/vms/platformvm/reward" | ||
"github.com/ava-labs/avalanchego/vms/platformvm/txs" | ||
"github.com/ava-labs/avalanchego/vms/secp256k1fx" | ||
) | ||
|
||
var _ = ginkgo.Describe("[Staking Rewards]", func() { | ||
require := require.New(ginkgo.GinkgoT()) | ||
|
||
// TODO(marun) Need to set the MinStakeDurationKey of the default | ||
// network to a level that can support this test. Also this test | ||
// should assert that the network's minimum stake duration is | ||
// compatible with its requirements. | ||
|
||
ginkgo.It("should ensure that validator node uptime determines whether a staking reward is issued", func() { | ||
network := e2e.Env.GetNetwork() | ||
|
||
// TODO(marun) Avoid checking for health until after both nodes have | ||
// started to minimize the required runtime | ||
ginkgo.By("creating a node whose uptime should result in a staking reward") | ||
goodValidator := e2e.AddTemporaryNode(network, testnet.FlagsMap{}) | ||
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultBootstrapTimeout) | ||
defer cancel() | ||
require.NoError(goodValidator.WaitForHealth(ctx)) | ||
|
||
ginkgo.By("creating a node whose update should not result in a staking reward") | ||
_ = e2e.AddTemporaryNode(network, testnet.FlagsMap{}) | ||
|
||
keychain := e2e.Env.NewKeychain(2) | ||
baseWallet := e2e.Env.NewWallet(keychain) | ||
pWallet := baseWallet.P() | ||
|
||
infoClient := info.NewClient(goodValidator.GetRuntimeState().URI) | ||
goodNodeID, nodePOP, err := infoClient.GetNodeID(context.Background()) | ||
require.NoError(err) | ||
|
||
stakeDuration := 10 * time.Second | ||
delegationFee := uint32(reward.PercentDenominator / 2) // 50% | ||
weight := 2_000 * units.Avax | ||
|
||
goodValidatorAddress := keychain.Keys[0].Address() | ||
|
||
// TODO(marun) Use a constant for the start time diff | ||
goodNodeStartTime := time.Now().Add(5 * time.Second) | ||
|
||
_, err = pWallet.IssueAddPermissionlessValidatorTx( | ||
&txs.SubnetValidator{Validator: txs.Validator{ | ||
NodeID: goodNodeID, | ||
Start: uint64(goodNodeStartTime.Unix()), | ||
End: uint64(goodNodeStartTime.Add(stakeDuration).Unix()), | ||
Wght: weight, | ||
}}, | ||
nodePOP, | ||
pWallet.AVAXAssetID(), | ||
&secp256k1fx.OutputOwners{ | ||
Threshold: 1, | ||
Addrs: []ids.ShortID{goodValidatorAddress}, | ||
}, | ||
&secp256k1fx.OutputOwners{ | ||
Threshold: 1, | ||
Addrs: []ids.ShortID{goodValidatorAddress}, | ||
}, | ||
delegationFee, | ||
) | ||
require.NoError(err) | ||
|
||
// TODO(marun) Define constants for timeout and poll duration | ||
pvmClient := platformvm.NewClient(goodValidator.GetRuntimeState().URI) | ||
require.Eventually(func() bool { | ||
validators, err := pvmClient.GetCurrentValidators(context.Background(), ids.Empty, nil) | ||
require.NoError(err) | ||
for _, validator := range validators { | ||
if validator.NodeID == goodNodeID { | ||
return true | ||
} | ||
} | ||
return false | ||
}, 10*time.Second, 2*time.Second, "node failed to become a validator before timeout ") | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters