-
Notifications
You must be signed in to change notification settings - Fork 741
e2e: Ensure interchain workflow coverage for X-Chain and C-Chain #1871
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
799057c
e2e: Ensure pre-funded test keys are also funded on the C-Chain
maru-ava 17e16c9
e2e: Ensure interchain workflow coverage equivalent to kurtosis testing
maru-ava 595b470
fixup: Wait for C-Chain balance to avoid racing in CI
maru-ava 7419cca
fixup: respond to review comments
maru-ava 6dfadc6
fixup: Ensure eth client and wallet use the same node URI to avoid ra…
maru-ava 70d2e47
Update tests/e2e/c/interchain_workflow.go
maru-ava 1b7fe7d
Update tests/fixture/testnet/config.go
maru-ava b489a6c
Update tests/fixture/testnet/config.go
maru-ava ce46c17
fixup: Remove superflous init and fix cchain amount reference
maru-ava File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package c | ||
|
||
import ( | ||
"math/big" | ||
|
||
ginkgo "github.com/onsi/ginkgo/v2" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ava-labs/coreth/core/types" | ||
"github.com/ava-labs/coreth/plugin/evm" | ||
|
||
"github.com/ava-labs/avalanchego/ids" | ||
"github.com/ava-labs/avalanchego/tests/e2e" | ||
"github.com/ava-labs/avalanchego/utils/constants" | ||
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1" | ||
"github.com/ava-labs/avalanchego/utils/set" | ||
"github.com/ava-labs/avalanchego/utils/units" | ||
"github.com/ava-labs/avalanchego/vms/secp256k1fx" | ||
"github.com/ava-labs/avalanchego/wallet/subnet/primary/common" | ||
) | ||
|
||
var _ = e2e.DescribeCChain("[Interchain Workflow]", func() { | ||
require := require.New(ginkgo.GinkgoT()) | ||
|
||
const ( | ||
txAmount = 10 * units.Avax // Arbitrary amount to send and transfer | ||
gasLimit = uint64(21000) // Standard gas limit | ||
) | ||
|
||
ginkgo.It("should ensure that funds can be transferred from the C-Chain to the X-Chain and the P-Chain", func() { | ||
ginkgo.By("allocating a pre-funded key to send from and a recipient key to deliver to") | ||
senderKey := e2e.Env.AllocateFundedKey() | ||
senderEthAddress := evm.GetEthAddress(senderKey) | ||
factory := secp256k1.Factory{} | ||
recipientKey, err := factory.NewPrivateKey() | ||
require.NoError(err) | ||
recipientEthAddress := evm.GetEthAddress(recipientKey) | ||
|
||
// Select a random node URI to use for both the eth client and | ||
// 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.NewEthClientForURI(nodeURI) | ||
|
||
ginkgo.By("sending funds from one address to another on the C-Chain", func() { | ||
// Create transaction | ||
acceptedNonce, err := ethClient.AcceptedNonceAt(e2e.DefaultContext(), senderEthAddress) | ||
require.NoError(err) | ||
gasPrice, err := ethClient.SuggestGasPrice(e2e.DefaultContext()) | ||
require.NoError(err) | ||
tx := types.NewTransaction( | ||
acceptedNonce, | ||
recipientEthAddress, | ||
big.NewInt(int64(txAmount)), | ||
gasLimit, | ||
gasPrice, | ||
nil, | ||
) | ||
|
||
// Sign transaction | ||
cChainID, err := ethClient.ChainID(e2e.DefaultContext()) | ||
require.NoError(err) | ||
signer := types.NewEIP155Signer(cChainID) | ||
signedTx, err := types.SignTx(tx, signer, senderKey.ToECDSA()) | ||
require.NoError(err) | ||
|
||
require.NoError(ethClient.SendTransaction(e2e.DefaultContext(), signedTx)) | ||
|
||
ginkgo.By("waiting for the C-Chain recipient address to have received the sent funds") | ||
e2e.Eventually(func() bool { | ||
balance, err := ethClient.BalanceAt(e2e.DefaultContext(), recipientEthAddress, nil) | ||
require.NoError(err) | ||
return balance.Cmp(big.NewInt(0)) > 0 | ||
}, e2e.DefaultTimeout, e2e.DefaultPollingInterval, "failed to see funds delivered before timeout") | ||
}) | ||
|
||
// Wallet must be initialized after sending funds on the | ||
// C-Chain with the same node URI to ensure wallet state | ||
// matches on-chain state. | ||
ginkgo.By("initializing a keychain and associated wallet") | ||
keychain := secp256k1fx.NewKeychain(senderKey, recipientKey) | ||
baseWallet := e2e.Env.NewWalletForURI(keychain, nodeURI) | ||
xWallet := baseWallet.X() | ||
cWallet := baseWallet.C() | ||
pWallet := baseWallet.P() | ||
hexfusion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
ginkgo.By("defining common configuration") | ||
avaxAssetID := xWallet.AVAXAssetID() | ||
// Use the same owner for import funds to X-Chain and P-Chain | ||
recipientOwner := secp256k1fx.OutputOwners{ | ||
Threshold: 1, | ||
Addrs: []ids.ShortID{ | ||
recipientKey.Address(), | ||
}, | ||
} | ||
// Use the same outputs for both X-Chain and P-Chain exports | ||
exportOutputs := []*secp256k1fx.TransferOutput{ | ||
{ | ||
Amt: txAmount, | ||
OutputOwners: secp256k1fx.OutputOwners{ | ||
Threshold: 1, | ||
Addrs: []ids.ShortID{ | ||
keychain.Keys[0].Address(), | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
ginkgo.By("exporting AVAX from the C-Chain to the X-Chain", func() { | ||
_, err := cWallet.IssueExportTx( | ||
xWallet.BlockchainID(), | ||
exportOutputs, | ||
e2e.WithDefaultContext(), | ||
) | ||
require.NoError(err) | ||
}) | ||
|
||
ginkgo.By("importing AVAX from the C-Chain to the X-Chain", func() { | ||
_, err := xWallet.IssueImportTx( | ||
cWallet.BlockchainID(), | ||
&recipientOwner, | ||
e2e.WithDefaultContext(), | ||
) | ||
require.NoError(err) | ||
}) | ||
|
||
ginkgo.By("checking that the recipient address has received imported funds on the X-Chain", func() { | ||
balances, err := xWallet.Builder().GetFTBalance(common.WithCustomAddresses(set.Of( | ||
recipientKey.Address(), | ||
))) | ||
require.NoError(err) | ||
require.Positive(balances[avaxAssetID]) | ||
}) | ||
|
||
ginkgo.By("exporting AVAX from the C-Chain to the P-Chain", func() { | ||
_, err := cWallet.IssueExportTx( | ||
constants.PlatformChainID, | ||
exportOutputs, | ||
e2e.WithDefaultContext(), | ||
) | ||
require.NoError(err) | ||
}) | ||
|
||
ginkgo.By("importing AVAX from the C-Chain to the P-Chain", func() { | ||
_, err = pWallet.IssueImportTx( | ||
cWallet.BlockchainID(), | ||
&recipientOwner, | ||
e2e.WithDefaultContext(), | ||
) | ||
require.NoError(err) | ||
}) | ||
|
||
ginkgo.By("checking that the recipient address has received imported funds on the P-Chain", func() { | ||
balances, err := pWallet.Builder().GetBalance(common.WithCustomAddresses(set.Of( | ||
recipientKey.Address(), | ||
))) | ||
require.NoError(err) | ||
require.Greater(balances[avaxAssetID], uint64(0)) | ||
}) | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Someone who knows the EVM better than I do should comment as to whether this is the signer we want to use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I'm copying what we used in snow-machine: https://github.com/ava-labs/snow-machine/blob/cchain-send/c/c.go#L37