Skip to content

Commit

Permalink
e2e: Migrate staking rewards e2e from kurtosis
Browse files Browse the repository at this point in the history
  • Loading branch information
marun committed Jul 24, 2023
1 parent cb8685b commit 7511e87
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
97 changes: 97 additions & 0 deletions tests/e2e/p/staking_rewards.go
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 ")
})
})
3 changes: 3 additions & 0 deletions tests/fixture/testnet/local/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func LocalFlags() testnet.FlagsMap {
cfg.IndexEnabledKey: true,
cfg.LogDisplayLevelKey: "INFO",
cfg.LogLevelKey: "DEBUG",

// A short min stake duration enables testing of staking logic.
cfg.MinStakeDurationKey: "1s",
}
}

Expand Down

0 comments on commit 7511e87

Please sign in to comment.