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

[e2e] Add wallet balance logging to staking rewards test #3426

Merged
merged 1 commit into from
Sep 27, 2024
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
18 changes: 2 additions & 16 deletions tests/antithesis/avalanchego/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests"
"github.com/ava-labs/avalanchego/tests/antithesis"
"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"
Expand Down Expand Up @@ -152,22 +153,7 @@ func (w *workload) run(ctx context.Context) {
defer tc.Cleanup()
require := require.New(tc)

var (
xWallet = w.wallet.X()
xBuilder = xWallet.Builder()
pWallet = w.wallet.P()
pBuilder = pWallet.Builder()
)
xBalances, err := xBuilder.GetFTBalance()
require.NoError(err, "failed to fetch X-chain balances")
pBalances, err := pBuilder.GetBalance()
require.NoError(err, "failed to fetch P-chain balances")
var (
xContext = xBuilder.Context()
avaxAssetID = xContext.AVAXAssetID
xAVAX = xBalances[avaxAssetID]
pAVAX = pBalances[avaxAssetID]
)
xAVAX, pAVAX := e2e.GetWalletBalances(tc, w.wallet)
log.Printf("wallet starting with %d X-chain nAVAX and %d P-chain nAVAX", xAVAX, pAVAX)
assert.Reachable("wallet starting", map[string]any{
"worker": w.id,
Expand Down
8 changes: 8 additions & 0 deletions tests/e2e/p/staking_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
require.NoError(err)

tc.By("adding alpha node as a validator", func() {
e2e.OutputWalletBalances(tc, baseWallet)

endTime := time.Now().Add(targetValidationPeriod)
tc.Outf("validation period ending at: %v\n", endTime)

Expand Down Expand Up @@ -143,6 +145,8 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
tc.Outf("beta node validation period ending at: %v\n", betaValidatorEndTime)

tc.By("adding beta node as a validator", func() {
e2e.OutputWalletBalances(tc, baseWallet)

_, err := pWallet.IssueAddPermissionlessValidatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
Expand Down Expand Up @@ -173,6 +177,8 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
require.NoError(err)

tc.By("adding gamma as a delegator to the alpha node", func() {
e2e.OutputWalletBalances(tc, baseWallet)

endTime := time.Now().Add(targetDelegationPeriod)
tc.Outf("delegation period ending at: %v\n", endTime)

Expand All @@ -196,6 +202,8 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
})

tc.By("adding delta as delegator to the beta node", func() {
e2e.OutputWalletBalances(tc, baseWallet)

endTime := time.Now().Add(targetDelegationPeriod)
tc.Outf("delegation period ending at: %v\n", endTime)

Expand Down
33 changes: 32 additions & 1 deletion tests/fixture/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,45 @@ func NewWallet(tc tests.TestContext, keychain *secp256k1fx.Keychain, nodeURI tmp
EthKeychain: keychain,
})
require.NoError(tc, err)
return primary.NewWalletWithOptions(
wallet := primary.NewWalletWithOptions(
baseWallet,
common.WithPostIssuanceFunc(
func(id ids.ID) {
tc.Outf(" issued transaction with ID: %s\n", id)
},
),
)
xAVAX, pAVAX := GetWalletBalances(tc, wallet)
tc.Outf("{{blue}} wallet starting with %d X-chain nAVAX and %d P-chain nAVAX{{/}}\n", xAVAX, pAVAX)
return wallet
}

// OutputWalletBalances outputs the X-Chain and P-Chain balances of the provided wallet.
func OutputWalletBalances(tc tests.TestContext, wallet primary.Wallet) {
xAVAX, pAVAX := GetWalletBalances(tc, wallet)
tc.Outf("{{blue}} wallet has %d X-chain nAVAX and %d P-chain nAVAX{{/}}\n", xAVAX, pAVAX)
}

// GetWalletBalances retrieves the X-Chain and P-Chain balances of the provided wallet.
func GetWalletBalances(tc tests.TestContext, wallet primary.Wallet) (uint64, uint64) {
require := require.New(tc)
var (
xWallet = wallet.X()
xBuilder = xWallet.Builder()
pWallet = wallet.P()
pBuilder = pWallet.Builder()
)
xBalances, err := xBuilder.GetFTBalance()
require.NoError(err, "failed to fetch X-chain balances")
pBalances, err := pBuilder.GetBalance()
require.NoError(err, "failed to fetch P-chain balances")
var (
xContext = xBuilder.Context()
avaxAssetID = xContext.AVAXAssetID
xAVAX = xBalances[avaxAssetID]
pAVAX = pBalances[avaxAssetID]
)
return xAVAX, pAVAX
}

// Create a new eth client targeting the specified node URI.
Expand Down
Loading