Skip to content

Commit

Permalink
e2e: Switch to using default timed context everywhere
Browse files Browse the repository at this point in the history
Simplifies test code and the long default timeout should avoid
unnecessary flaking.
  • Loading branch information
maru-ava committed Aug 26, 2023
1 parent 7a216fd commit 970b84d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 74 deletions.
15 changes: 13 additions & 2 deletions tests/e2e/banff/suites.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var _ = ginkgo.Describe("[Banff]", func() {
},
},
},
e2e.WithDefaultContext(),
)
gomega.Expect(err).Should(gomega.BeNil())
assetID = assetTx.ID()
Expand All @@ -76,14 +77,19 @@ var _ = ginkgo.Describe("[Banff]", func() {
},
},
},
e2e.WithDefaultContext(),
)
gomega.Expect(err).Should(gomega.BeNil())

tests.Outf("{{green}}issued X-chain export{{/}}: %s\n", tx.ID())
})

ginkgo.By("import new asset from X-chain on the P-chain", func() {
tx, err := pWallet.IssueImportTx(xChainID, owner)
tx, err := pWallet.IssueImportTx(
xChainID,
owner,
e2e.WithDefaultContext(),
)
gomega.Expect(err).Should(gomega.BeNil())

tests.Outf("{{green}}issued P-chain import{{/}}: %s\n", tx.ID())
Expand All @@ -103,14 +109,19 @@ var _ = ginkgo.Describe("[Banff]", func() {
},
},
},
e2e.WithDefaultContext(),
)
gomega.Expect(err).Should(gomega.BeNil())

tests.Outf("{{green}}issued P-chain export{{/}}: %s\n", tx.ID())
})

ginkgo.By("import asset from P-chain on the X-chain", func() {
tx, err := xWallet.IssueImportTx(constants.PlatformChainID, owner)
tx, err := xWallet.IssueImportTx(
constants.PlatformChainID,
owner,
e2e.WithDefaultContext(),
)
gomega.Expect(err).Should(gomega.BeNil())

tests.Outf("{{green}}issued X-chain import{{/}}: %s\n", tx.ID())
Expand Down
7 changes: 0 additions & 7 deletions tests/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ const (
PChainLabel = "p"
CChainLabel = "c"

// Enough for primary.NewWallet to fetch initial UTXOs.
DefaultWalletCreationTimeout = 5 * time.Second

// Defines default tx confirmation timeout.
// Enough for test/custom networks.
DefaultConfirmTxTimeout = 20 * time.Second

// A long default timeout used to timeout failed operations but
// unlikely to induce flaking due to unexpected resource
// contention.
Expand Down
34 changes: 8 additions & 26 deletions tests/e2e/p/permissionless_subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package p

import (
"context"
"fmt"
"time"

Expand All @@ -23,7 +22,6 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
"github.com/ava-labs/avalanchego/wallet/subnet/primary/common"
)

var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
Expand All @@ -39,9 +37,7 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
var validatorID ids.NodeID
ginkgo.By("retrieving the node ID of a primary network validator", func() {
pChainClient := platformvm.NewClient(nodeURI)
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultTimeout)
validatorIDs, err := pChainClient.SampleValidators(ctx, constants.PrimaryNetworkID, 1)
cancel()
validatorIDs, err := pChainClient.SampleValidators(e2e.DefaultContext(), constants.PrimaryNetworkID, 1)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(validatorIDs).Should(gomega.HaveLen(1))
validatorID = validatorIDs[0]
Expand All @@ -56,20 +52,17 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {

var subnetID ids.ID
ginkgo.By("create a permissioned subnet", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultTimeout)
subnetTx, err := pWallet.IssueCreateSubnetTx(
owner,
common.WithContext(ctx),
e2e.WithDefaultContext(),
)
cancel()

subnetID = subnetTx.ID()
gomega.Expect(subnetID, err).Should(gomega.Not(gomega.Equal(constants.PrimaryNetworkID)))
})

var subnetAssetID ids.ID
ginkgo.By("create a custom asset for the permissionless subnet", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultTimeout)
subnetAssetTx, err := xWallet.IssueCreateAssetTx(
"RnM",
"RNM",
Expand All @@ -82,15 +75,13 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
},
},
},
common.WithContext(ctx),
e2e.WithDefaultContext(),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
subnetAssetID = subnetAssetTx.ID()
})

ginkgo.By(fmt.Sprintf("Send 100 MegaAvax of asset %s to the P-chain", subnetAssetID), func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultTimeout)
_, err := xWallet.IssueExportTx(
constants.PlatformChainID,
[]*avax.TransferableOutput{
Expand All @@ -104,25 +95,21 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
},
},
},
common.WithContext(ctx),
e2e.WithDefaultContext(),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
})

ginkgo.By(fmt.Sprintf("Import the 100 MegaAvax of asset %s from the X-chain into the P-chain", subnetAssetID), func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultTimeout)
_, err := pWallet.IssueImportTx(
xChainID,
owner,
common.WithContext(ctx),
e2e.WithDefaultContext(),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
})

ginkgo.By("make subnet permissionless", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultTimeout)
_, err := pWallet.IssueTransformSubnetTx(
subnetID,
subnetAssetID,
Expand All @@ -138,15 +125,13 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
1,
5,
.80*reward.PercentDenominator,
common.WithContext(ctx),
e2e.WithDefaultContext(),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
})

validatorStartTime := time.Now().Add(time.Minute)
ginkgo.By("add permissionless validator", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultTimeout)
_, err := pWallet.IssueAddPermissionlessValidatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
Expand All @@ -162,15 +147,13 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
&secp256k1fx.OutputOwners{},
&secp256k1fx.OutputOwners{},
reward.PercentDenominator,
common.WithContext(ctx),
e2e.WithDefaultContext(),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
})

delegatorStartTime := validatorStartTime
ginkgo.By("add permissionless delegator", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultTimeout)
_, err := pWallet.IssueAddPermissionlessDelegatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
Expand All @@ -183,9 +166,8 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
},
subnetAssetID,
&secp256k1fx.OutputOwners{},
common.WithContext(ctx),
e2e.WithDefaultContext(),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
})
})
Expand Down
25 changes: 6 additions & 19 deletions tests/e2e/p/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/ava-labs/avalanchego/vms/platformvm"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
"github.com/ava-labs/avalanchego/wallet/subnet/primary/common"
)

// PChainWorkflow is an integration test for normal P-Chain operations
Expand All @@ -44,18 +43,14 @@ var _ = e2e.DescribePChain("[Workflow]", func() {
pChainClient := platformvm.NewClient(nodeURI)

tests.Outf("{{blue}} fetching minimal stake amounts {{/}}\n")
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultWalletCreationTimeout)
minValStake, minDelStake, err := pChainClient.GetMinStake(ctx, constants.PlatformChainID)
cancel()
minValStake, minDelStake, err := pChainClient.GetMinStake(e2e.DefaultContext(), constants.PlatformChainID)
gomega.Expect(err).Should(gomega.BeNil())
tests.Outf("{{green}} minimal validator stake: %d {{/}}\n", minValStake)
tests.Outf("{{green}} minimal delegator stake: %d {{/}}\n", minDelStake)

tests.Outf("{{blue}} fetching tx fee {{/}}\n")
infoClient := info.NewClient(nodeURI)
ctx, cancel = context.WithTimeout(context.Background(), e2e.DefaultWalletCreationTimeout)
fees, err := infoClient.GetTxFee(ctx)
cancel()
fees, err := infoClient.GetTxFee(e2e.DefaultContext())
gomega.Expect(err).Should(gomega.BeNil())
txFees := uint64(fees.TxFee)
tests.Outf("{{green}} txFee: %d {{/}}\n", txFees)
Expand Down Expand Up @@ -93,25 +88,21 @@ var _ = e2e.DescribePChain("[Workflow]", func() {
shares := uint32(20000) // TODO: retrieve programmatically

ginkgo.By("issue add validator tx", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultConfirmTxTimeout)
_, err := pWallet.IssueAddValidatorTx(
vdr,
rewardOwner,
shares,
common.WithContext(ctx),
e2e.WithDefaultContext(),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
})

ginkgo.By("issue add delegator tx", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultConfirmTxTimeout)
_, err := pWallet.IssueAddDelegatorTx(
vdr,
rewardOwner,
common.WithContext(ctx),
e2e.WithDefaultContext(),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
})

Expand All @@ -138,7 +129,6 @@ var _ = e2e.DescribePChain("[Workflow]", func() {
}

ginkgo.By("export avax from P to X chain", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultConfirmTxTimeout)
_, err := pWallet.IssueExportTx(
xWallet.BlockchainID(),
[]*avax.TransferableOutput{
Expand All @@ -149,9 +139,8 @@ var _ = e2e.DescribePChain("[Workflow]", func() {
Out: output,
},
},
common.WithContext(ctx),
e2e.WithDefaultContext(),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())
})

Expand All @@ -170,13 +159,11 @@ var _ = e2e.DescribePChain("[Workflow]", func() {
gomega.Expect(pPreImportBalance).To(gomega.Equal(pStartBalance - toTransfer - txFees))

ginkgo.By("import avax from P into X chain", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultConfirmTxTimeout)
_, err := xWallet.IssueImportTx(
constants.PlatformChainID,
&outputOwner,
common.WithContext(ctx),
e2e.WithDefaultContext(),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil(), "is context.DeadlineExceeded: %v", errors.Is(err, context.DeadlineExceeded))
})

Expand Down
9 changes: 2 additions & 7 deletions tests/e2e/static-handlers/suites.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package statichandlers

import (
"context"
"time"

"github.com/ava-labs/avalanchego/ids"
Expand Down Expand Up @@ -105,9 +104,7 @@ var _ = ginkgo.Describe("[StaticHandlers]", func() {
},
}
staticClient := avm.NewStaticClient(e2e.Env.GetRandomNodeURI())
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
resp, err := staticClient.BuildGenesis(ctx, &avmArgs)
cancel()
resp, err := staticClient.BuildGenesis(e2e.DefaultContext(), &avmArgs)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(resp.Bytes).Should(gomega.Equal("0x0000000000030006617373657431000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f6d794669786564436170417373657400044d4643410800000001000000000000000400000007000000000000c350000000000000000000000001000000013f78e510df62bc48b0829ec06d6a6b98062d695300000007000000000000c35000000000000000000000000100000001c54903de5177a16f7811771ef2f4659d9e8646710000000700000000000186a0000000000000000000000001000000013f58fda2e9ea8d9e4b181832a07b26dae286f2cb0000000700000000000186a000000000000000000000000100000001645938bb7ae2193270e6ffef009e3664d11e07c10006617373657432000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000d6d79566172436170417373657400044d5643410000000001000000000000000200000006000000000000000000000001000000023f58fda2e9ea8d9e4b181832a07b26dae286f2cb645938bb7ae2193270e6ffef009e3664d11e07c100000006000000000000000000000001000000023f78e510df62bc48b0829ec06d6a6b98062d6953c54903de5177a16f7811771ef2f4659d9e864671000661737365743300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000126d794f7468657256617243617041737365740000000000000100000000000000010000000600000000000000000000000100000001645938bb7ae2193270e6ffef009e3664d11e07c1279fa028"))
})
Expand Down Expand Up @@ -176,9 +173,7 @@ var _ = ginkgo.Describe("[StaticHandlers]", func() {
}

staticClient := api.NewStaticClient(e2e.Env.GetRandomNodeURI())
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
resp, err := staticClient.BuildGenesis(ctx, &buildGenesisArgs)
cancel()
resp, err := staticClient.BuildGenesis(e2e.DefaultContext(), &buildGenesisArgs)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(resp.Bytes).Should(gomega.Equal("0x0000000000050000000000000000000000000000000000000000000000000000000000000000000000006176617800000000000000000000000000000000000000000000000000000000000000070000000ba43b740000000000000000000000000100000001fceda8f90fcb5d30614b99d79fc4baa293077626000000000000000000000000000000000000000000000000000000000000000000000000000000016176617800000000000000000000000000000000000000000000000000000000000000070000000ba43b7400000000000000000000000001000000016ead693c17abb1be422bb50b30b9711ff98d667e000000000000000000000000000000000000000000000000000000000000000000000000000000026176617800000000000000000000000000000000000000000000000000000000000000070000000ba43b740000000000000000000000000100000001f2420846876e69f473dda256172967e992f0ee31000000000000000000000000000000000000000000000000000000000000000000000000000000036176617800000000000000000000000000000000000000000000000000000000000000070000000ba43b7400000000000000000000000001000000013cb7d3842e8cee6a0ebd09f1fe884f6861e1b29c000000000000000000000000000000000000000000000000000000000000000000000000000000046176617800000000000000000000000000000000000000000000000000000000000000070000000ba43b74000000000000000000000000010000000187c4ec0736fdad03fd9ec8c3ba609de958601a7b00000000000000050000000c0000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000fceda8f90fcb5d30614b99d79fc4baa2930776260000000032c9a9000000000032efe480000000000000271000000001617661780000000000000000000000000000000000000000000000000000000000000007000000000000271000000000000000000000000100000001fceda8f90fcb5d30614b99d79fc4baa2930776260000000b00000000000000000000000100000001fceda8f90fcb5d30614b99d79fc4baa29307762600000000000000000000000c0000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000006ead693c17abb1be422bb50b30b9711ff98d667e0000000032c9a9000000000032efe4800000000000002710000000016176617800000000000000000000000000000000000000000000000000000000000000070000000000002710000000000000000000000001000000016ead693c17abb1be422bb50b30b9711ff98d667e0000000b000000000000000000000001000000016ead693c17abb1be422bb50b30b9711ff98d667e00000000000000000000000c0000000a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f2420846876e69f473dda256172967e992f0ee310000000032c9a9000000000032efe480000000000000271000000001617661780000000000000000000000000000000000000000000000000000000000000007000000000000271000000000000000000000000100000001f2420846876e69f473dda256172967e992f0ee310000000b00000000000000000000000100000001f2420846876e69f473dda256172967e992f0ee3100000000000000000000000c0000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000003cb7d3842e8cee6a0ebd09f1fe884f6861e1b29c0000000032c9a9000000000032efe4800000000000002710000000016176617800000000000000000000000000000000000000000000000000000000000000070000000000002710000000000000000000000001000000013cb7d3842e8cee6a0ebd09f1fe884f6861e1b29c0000000b000000000000000000000001000000013cb7d3842e8cee6a0ebd09f1fe884f6861e1b29c00000000000000000000000c0000000a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000087c4ec0736fdad03fd9ec8c3ba609de958601a7b0000000032c9a9000000000032efe48000000000000027100000000161766178000000000000000000000000000000000000000000000000000000000000000700000000000027100000000000000000000000010000000187c4ec0736fdad03fd9ec8c3ba609de958601a7b0000000b0000000000000000000000010000000187c4ec0736fdad03fd9ec8c3ba609de958601a7b0000000000000000000000000000000032c9a90004fefa17b724000000008e96cbef"))
})
Expand Down
17 changes: 4 additions & 13 deletions tests/e2e/x/transfer/virtuous.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package transfer

import (
"context"
"fmt"
"math/rand"
"time"
Expand Down Expand Up @@ -146,7 +145,6 @@ var _ = e2e.DescribeXChainSerial("[Virtuous Transfer Tx AVAX]", func() {
receiverNewBal := receiverOrigBal + amountToTransfer

ginkgo.By("X-Chain transfer with wrong amount must fail", func() {
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultConfirmTxTimeout)
_, err := wallets[fromIdx].X().IssueBaseTx(
[]*avax.TransferableOutput{{
Asset: avax.Asset{
Expand All @@ -160,9 +158,8 @@ var _ = e2e.DescribeXChainSerial("[Virtuous Transfer Tx AVAX]", func() {
},
},
}},
common.WithContext(ctx),
e2e.WithDefaultContext(),
)
cancel()
gomega.Expect(err.Error()).Should(gomega.ContainSubstring("insufficient funds"))
})

Expand All @@ -189,7 +186,6 @@ RECEIVER NEW BALANCE (AFTER) : %21d AVAX
receiverNewBal,
)

ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultConfirmTxTimeout)
tx, err := wallets[fromIdx].X().IssueBaseTx(
[]*avax.TransferableOutput{{
Asset: avax.Asset{
Expand All @@ -203,9 +199,8 @@ RECEIVER NEW BALANCE (AFTER) : %21d AVAX
},
},
}},
common.WithContext(ctx),
e2e.WithDefaultContext(),
)
cancel()
gomega.Expect(err).Should(gomega.BeNil())

balances, err := wallets[fromIdx].X().Builder().GetFTBalance()
Expand All @@ -224,18 +219,14 @@ RECEIVER NEW BALANCE (AFTER) : %21d AVAX
txID := tx.ID()
for _, u := range rpcEps {
xc := avm.NewClient(u, "X")
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultConfirmTxTimeout)
status, err := xc.ConfirmTx(ctx, txID, 2*time.Second)
cancel()
status, err := xc.ConfirmTx(e2e.DefaultContext(), txID, 2*time.Second)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(status).Should(gomega.Equal(choices.Accepted))
}

for _, u := range rpcEps {
xc := avm.NewClient(u, "X")
ctx, cancel := context.WithTimeout(context.Background(), e2e.DefaultConfirmTxTimeout)
status, err := xc.ConfirmTx(ctx, txID, 2*time.Second)
cancel()
status, err := xc.ConfirmTx(e2e.DefaultContext(), txID, 2*time.Second)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(status).Should(gomega.Equal(choices.Accepted))

Expand Down

0 comments on commit 970b84d

Please sign in to comment.