Skip to content
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
10 changes: 2 additions & 8 deletions tests/e2e/p/staking_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,8 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
deltaDelegationRewardKey,
}

keychain = secp256k1fx.NewKeychain(rewardKeys...)
)

fundedKey := env.AllocatePreFundedKey()
keychain.Add(fundedKey)

var (
nodeURI = tmpnet.NodeURI{
keychain = env.NewKeychain(1)
nodeURI = tmpnet.NodeURI{
NodeID: alphaNodeID,
URI: alphaNode.URI,
}
Expand Down
14 changes: 9 additions & 5 deletions tests/e2e/p/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ var _ = e2e.DescribePChain("[Workflow]", func() {

baseWallet = e2e.NewWallet(tc, keychain, nodeURI)

pWallet = baseWallet.P()
pBuilder = pWallet.Builder()
pContext = pBuilder.Context()
pWallet = baseWallet.P()
pBuilder = pWallet.Builder()
pContext = pBuilder.Context()
pFeeCalculator = e2e.NewPChainFeeCalculatorFromContext(pContext)

xWallet = baseWallet.X()
xBuilder = xWallet.Builder()
Expand Down Expand Up @@ -131,7 +132,7 @@ var _ = e2e.DescribePChain("[Workflow]", func() {
initialAVAXBalance := balances[avaxAssetID]
tc.Outf("{{blue}} P-chain balance before P->X export: %d {{/}}\n", initialAVAXBalance)

_, err = pWallet.IssueExportTx(
exportTx, err := pWallet.IssueExportTx(
xContext.BlockchainID,
[]*avax.TransferableOutput{
{
Expand All @@ -148,13 +149,16 @@ var _ = e2e.DescribePChain("[Workflow]", func() {
)
require.NoError(err)

exportFee, err := pFeeCalculator.CalculateFee(exportTx.Unsigned)
require.NoError(err)

balances, err = pBuilder.GetBalance()
require.NoError(err)

finalAVAXBalance := balances[avaxAssetID]
tc.Outf("{{blue}} P-chain balance after P->X export: %d {{/}}\n", finalAVAXBalance)

require.Equal(initialAVAXBalance-toTransfer-pContext.StaticFeeConfig.TxFee, finalAVAXBalance)
require.Equal(initialAVAXBalance-toTransfer-exportFee, finalAVAXBalance)
})

tc.By("issuing an ImportTx on the X-Chain", func() {
Expand Down
11 changes: 11 additions & 0 deletions tests/fixture/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (
"github.com/ava-labs/avalanchego/tests"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
"github.com/ava-labs/avalanchego/vms/platformvm/txs/fee"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
"github.com/ava-labs/avalanchego/wallet/chain/p/builder"
"github.com/ava-labs/avalanchego/wallet/subnet/primary"
"github.com/ava-labs/avalanchego/wallet/subnet/primary/common"
)
Expand Down Expand Up @@ -242,3 +244,12 @@ func StartNetwork(
require.NoError(network.Stop(ctx))
})
}

// NewPChainFeeCalculatorFromContext returns either a static or dynamic fee
// calculator depending on the provided context.
func NewPChainFeeCalculatorFromContext(context *builder.Context) fee.Calculator {
if context.GasPrice != 0 {
return fee.NewDynamicCalculator(context.ComplexityWeights, context.GasPrice)
}
return fee.NewStaticCalculator(context.StaticFeeConfig)
}