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: Make NewWallet and NewEthclient regular functions #2262

Merged
merged 1 commit into from
Nov 6, 2023
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
2 changes: 1 addition & 1 deletion tests/e2e/banff/suites.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var _ = ginkgo.Describe("[Banff]", func() {
ginkgo.It("can send custom assets X->P and P->X",
func() {
keychain := e2e.Env.NewKeychain(1)
wallet := e2e.Env.NewWallet(keychain, e2e.Env.GetRandomNodeURI())
wallet := e2e.NewWallet(keychain, e2e.Env.GetRandomNodeURI())

// Get the P-chain and the X-chain wallets
pWallet := wallet.P()
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/c/dynamic_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var _ = e2e.DescribeCChain("[Dynamic Fees]", func() {
NodeID: node.GetID(),
URI: node.GetProcessContext().URI,
}
ethClient := e2e.Env.NewEthClient(nodeURI)
ethClient := e2e.NewEthClient(nodeURI)

ginkgo.By("initializing a transaction signer")
cChainID, err := ethClient.ChainID(e2e.DefaultContext())
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/c/interchain_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var _ = e2e.DescribeCChain("[Interchain Workflow]", func() {
// the wallet to avoid having to verify that all nodes are at
// the same height before initializing the wallet.
nodeURI := e2e.Env.GetRandomNodeURI()
ethClient := e2e.Env.NewEthClient(nodeURI)
ethClient := e2e.NewEthClient(nodeURI)

ginkgo.By("allocating a pre-funded key to send from and a recipient key to deliver to")
senderKey := e2e.Env.AllocateFundedKey()
Expand Down Expand Up @@ -79,7 +79,7 @@ var _ = e2e.DescribeCChain("[Interchain Workflow]", func() {
// matches on-chain state.
ginkgo.By("initializing a keychain and associated wallet")
keychain := secp256k1fx.NewKeychain(senderKey, recipientKey)
baseWallet := e2e.Env.NewWallet(keychain, nodeURI)
baseWallet := e2e.NewWallet(keychain, nodeURI)
xWallet := baseWallet.X()
cWallet := baseWallet.C()
pWallet := baseWallet.P()
Expand Down
38 changes: 18 additions & 20 deletions tests/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,29 @@ func (te *TestEnvironment) NewKeychain(count int) *secp256k1fx.Keychain {
return secp256k1fx.NewKeychain(keys...)
}

// Create a new private network that is not shared with other tests.
func (te *TestEnvironment) NewPrivateNetwork() testnet.Network {
// Load the shared network to retrieve its path and exec path
sharedNetwork, err := local.ReadNetwork(te.NetworkDir)
te.require.NoError(err)

// The private networks dir is under the shared network dir to ensure it
// will be included in the artifact uploaded in CI.
privateNetworksDir := filepath.Join(sharedNetwork.Dir, PrivateNetworksDirName)
te.require.NoError(os.MkdirAll(privateNetworksDir, perms.ReadWriteExecute))

return StartLocalNetwork(sharedNetwork.ExecPath, privateNetworksDir)
}

// Create a new wallet for the provided keychain against the specified node URI.
// TODO(marun) Make this a regular function.
func (te *TestEnvironment) NewWallet(keychain *secp256k1fx.Keychain, nodeURI testnet.NodeURI) primary.Wallet {
func NewWallet(keychain *secp256k1fx.Keychain, nodeURI testnet.NodeURI) primary.Wallet {
tests.Outf("{{blue}} initializing a new wallet for node %s with URI: %s {{/}}\n", nodeURI.NodeID, nodeURI.URI)
baseWallet, err := primary.MakeWallet(DefaultContext(), &primary.WalletConfig{
URI: nodeURI.URI,
AVAXKeychain: keychain,
EthKeychain: keychain,
})
te.require.NoError(err)
require.NoError(ginkgo.GinkgoT(), err)
return primary.NewWalletWithOptions(
baseWallet,
common.WithPostIssuanceFunc(
Expand All @@ -148,30 +161,15 @@ func (te *TestEnvironment) NewWallet(keychain *secp256k1fx.Keychain, nodeURI tes
}

// Create a new eth client targeting the specified node URI.
// TODO(marun) Make this a regular function.
func (te *TestEnvironment) NewEthClient(nodeURI testnet.NodeURI) ethclient.Client {
func NewEthClient(nodeURI testnet.NodeURI) ethclient.Client {
tests.Outf("{{blue}} initializing a new eth client for node %s with URI: %s {{/}}\n", nodeURI.NodeID, nodeURI.URI)
nodeAddress := strings.Split(nodeURI.URI, "//")[1]
uri := fmt.Sprintf("ws://%s/ext/bc/C/ws", nodeAddress)
client, err := ethclient.Dial(uri)
te.require.NoError(err)
require.NoError(ginkgo.GinkgoT(), err)
return client
}

// Create a new private network that is not shared with other tests.
func (te *TestEnvironment) NewPrivateNetwork() testnet.Network {
// Load the shared network to retrieve its path and exec path
sharedNetwork, err := local.ReadNetwork(te.NetworkDir)
te.require.NoError(err)

// The private networks dir is under the shared network dir to ensure it
// will be included in the artifact uploaded in CI.
privateNetworksDir := filepath.Join(sharedNetwork.Dir, PrivateNetworksDirName)
te.require.NoError(os.MkdirAll(privateNetworksDir, perms.ReadWriteExecute))

return StartLocalNetwork(sharedNetwork.ExecPath, privateNetworksDir)
}

// Helper simplifying use of a timed context by canceling the context on ginkgo teardown.
func ContextWithTimeout(duration time.Duration) context.Context {
ctx, cancel := context.WithTimeout(context.Background(), duration)
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/p/interchain_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL
keychain := e2e.Env.NewKeychain(1)
keychain.Add(recipientKey)
nodeURI := e2e.Env.GetRandomNodeURI()
baseWallet := e2e.Env.NewWallet(keychain, nodeURI)
baseWallet := e2e.NewWallet(keychain, nodeURI)
xWallet := baseWallet.X()
cWallet := baseWallet.C()
pWallet := baseWallet.P()
Expand Down Expand Up @@ -202,7 +202,7 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL
})

ginkgo.By("initializing a new eth client")
ethClient := e2e.Env.NewEthClient(nodeURI)
ethClient := e2e.NewEthClient(nodeURI)

ginkgo.By("importing AVAX from the P-Chain to the C-Chain", func() {
_, err := cWallet.IssueImportTx(
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/p/permissionless_subnets.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var _ = e2e.DescribePChain("[Permissionless Subnets]", func() {
nodeURI := e2e.Env.GetRandomNodeURI()

keychain := e2e.Env.NewKeychain(1)
baseWallet := e2e.Env.NewWallet(keychain, nodeURI)
baseWallet := e2e.NewWallet(keychain, nodeURI)

pWallet := baseWallet.P()
xWallet := baseWallet.X()
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/p/staking_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
fundedKey := e2e.Env.AllocateFundedKey()
keychain.Add(fundedKey)
nodeURI := e2e.Env.GetRandomNodeURI()
baseWallet := e2e.Env.NewWallet(keychain, nodeURI)
baseWallet := e2e.NewWallet(keychain, nodeURI)
pWallet := baseWallet.P()

ginkgo.By("retrieving alpha node id and pop")
Expand Down Expand Up @@ -261,7 +261,7 @@ var _ = ginkgo.Describe("[Staking Rewards]", func() {
rewardBalances := make(map[ids.ShortID]uint64, len(rewardKeys))
for _, rewardKey := range rewardKeys {
keychain := secp256k1fx.NewKeychain(rewardKey)
baseWallet := e2e.Env.NewWallet(keychain, nodeURI)
baseWallet := e2e.NewWallet(keychain, nodeURI)
pWallet := baseWallet.P()
balances, err := pWallet.Builder().GetBalance()
require.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/p/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var _ = e2e.DescribePChain("[Workflow]", func() {
func() {
nodeURI := e2e.Env.GetRandomNodeURI()
keychain := e2e.Env.NewKeychain(2)
baseWallet := e2e.Env.NewWallet(keychain, nodeURI)
baseWallet := e2e.NewWallet(keychain, nodeURI)

pWallet := baseWallet.P()
avaxAssetID := baseWallet.P().AVAXAssetID()
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/x/interchain_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var _ = e2e.DescribeXChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL
require.NoError(err)
keychain := e2e.Env.NewKeychain(1)
keychain.Add(recipientKey)
baseWallet := e2e.Env.NewWallet(keychain, nodeURI)
baseWallet := e2e.NewWallet(keychain, nodeURI)
xWallet := baseWallet.X()
cWallet := baseWallet.C()
pWallet := baseWallet.P()
Expand Down Expand Up @@ -103,7 +103,7 @@ var _ = e2e.DescribeXChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL
})

ginkgo.By("initializing a new eth client")
ethClient := e2e.Env.NewEthClient(nodeURI)
ethClient := e2e.NewEthClient(nodeURI)

ginkgo.By("importing AVAX from the X-Chain to the C-Chain", func() {
_, err := cWallet.IssueImportTx(
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/x/transfer/virtuous.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ var _ = e2e.DescribeXChainSerial("[Virtuous Transfer Tx AVAX]", func() {
}

keychain := secp256k1fx.NewKeychain(testKeys...)
baseWallet := e2e.Env.NewWallet(keychain, e2e.Env.GetRandomNodeURI())
baseWallet := e2e.NewWallet(keychain, e2e.Env.GetRandomNodeURI())
avaxAssetID := baseWallet.X().AVAXAssetID()

wallets := make([]primary.Wallet, len(testKeys))
Expand Down
Loading