Skip to content

Commit

Permalink
[e2e] Add wallet balance logging to staking rewards test (#3426)
Browse files Browse the repository at this point in the history
  • Loading branch information
maru-ava authored Sep 27, 2024
1 parent f11da2f commit 89cd240
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
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

0 comments on commit 89cd240

Please # to comment.