Skip to content

Commit

Permalink
Refactor e2e tests for P-chain tests (#3295)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Aug 15, 2024
1 parent 2eef641 commit 6d89732
Show file tree
Hide file tree
Showing 9 changed files with 371 additions and 357 deletions.
8 changes: 4 additions & 4 deletions tests/e2e/c/dynamic_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

"github.com/ava-labs/avalanchego/tests/fixture/e2e"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"

ginkgo "github.com/onsi/ginkgo/v2"
)
Expand Down Expand Up @@ -142,9 +141,10 @@ var _ = e2e.DescribeCChain("[Dynamic Fees]", func() {

tc.By("sending funds at the current gas price", func() {
// Create a recipient address
recipientKey, err := secp256k1.NewPrivateKey()
require.NoError(err)
recipientEthAddress := evm.GetEthAddress(recipientKey)
var (
recipientKey = e2e.NewPrivateKey(tc)
recipientEthAddress = evm.GetEthAddress(recipientKey)
)

// Create transaction
nonce, err := ethClient.AcceptedNonceAt(tc.DefaultContext(), ethAddress)
Expand Down
14 changes: 7 additions & 7 deletions tests/e2e/c/interchain_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests/fixture/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"
Expand All @@ -39,11 +38,12 @@ var _ = e2e.DescribeCChain("[Interchain Workflow]", func() {
ethClient := e2e.NewEthClient(tc, nodeURI)

tc.By("allocating a pre-funded key to send from and a recipient key to deliver to")
senderKey := env.AllocatePreFundedKey()
senderEthAddress := evm.GetEthAddress(senderKey)
recipientKey, err := secp256k1.NewPrivateKey()
require.NoError(err)
recipientEthAddress := evm.GetEthAddress(recipientKey)
var (
senderKey = env.AllocatePreFundedKey()
senderEthAddress = evm.GetEthAddress(senderKey)
recipientKey = e2e.NewPrivateKey(tc)
recipientEthAddress = evm.GetEthAddress(recipientKey)
)

tc.By("sending funds from one address to another on the C-Chain", func() {
// Create transaction
Expand Down Expand Up @@ -150,7 +150,7 @@ var _ = e2e.DescribeCChain("[Interchain Workflow]", func() {
})

tc.By("importing AVAX from the C-Chain to the P-Chain", func() {
_, err = pWallet.IssueImportTx(
_, err := pWallet.IssueImportTx(
cContext.BlockchainID,
&recipientOwner,
tc.WithDefaultContext(),
Expand Down
75 changes: 43 additions & 32 deletions tests/e2e/p/interchain_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"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"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/vms/components/avax"
Expand All @@ -30,45 +29,53 @@ import (
)

var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainLabel), func() {
tc := e2e.NewTestContext()
require := require.New(tc)

const (
transferAmount = 10 * units.Avax
weight = 2_000 * units.Avax // Used for both validation and delegation
var (
tc = e2e.NewTestContext()
require = require.New(tc)
)

ginkgo.It("should ensure that funds can be transferred from the P-Chain to the X-Chain and the C-Chain", func() {
env := e2e.GetEnv(tc)
const (
transferAmount = 10 * units.Avax
weight = 2_000 * units.Avax // Used for both validation and delegation
)

network := env.GetNetwork()
var (
env = e2e.GetEnv(tc)
network = env.GetNetwork()
)

tc.By("checking that the network has a compatible minimum stake duration", func() {
minStakeDuration := cast.ToDuration(network.DefaultFlags[config.MinStakeDurationKey])
require.Equal(tmpnet.DefaultMinStakeDuration, minStakeDuration)
})

tc.By("creating wallet with a funded key to send from and recipient key to deliver to")
recipientKey, err := secp256k1.NewPrivateKey()
require.NoError(err)
recipientKey := e2e.NewPrivateKey(tc)
keychain := env.NewKeychain(1)
keychain.Add(recipientKey)
nodeURI := env.GetRandomNodeURI()
baseWallet := e2e.NewWallet(tc, keychain, nodeURI)
xWallet := baseWallet.X()
cWallet := baseWallet.C()
pWallet := baseWallet.P()

xBuilder := xWallet.Builder()
xContext := xBuilder.Context()
pBuilder := pWallet.Builder()
pContext := pBuilder.Context()
cBuilder := cWallet.Builder()
cContext := cBuilder.Context()

var (
nodeURI = env.GetRandomNodeURI()
baseWallet = e2e.NewWallet(tc, keychain, nodeURI)

xWallet = baseWallet.X()
xBuilder = xWallet.Builder()
xContext = xBuilder.Context()

pWallet = baseWallet.P()
pBuilder = pWallet.Builder()
pContext = pBuilder.Context()

cWallet = baseWallet.C()
cBuilder = cWallet.Builder()
cContext = cBuilder.Context()

avaxAssetID = xContext.AVAXAssetID
)

tc.By("defining common configuration")
recipientEthAddress := evm.GetEthAddress(recipientKey)
avaxAssetID := xContext.AVAXAssetID
// Use the same owner for sending to X-Chain and importing funds to P-Chain
recipientOwner := secp256k1fx.OutputOwners{
Threshold: 1,
Expand Down Expand Up @@ -106,14 +113,16 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL
// Adding a validator should not break interchain transfer.
endTime := time.Now().Add(30 * time.Second)
tc.By("adding the new node as a validator", func() {
rewardKey, err := secp256k1.NewPrivateKey()
require.NoError(err)

const (
delegationPercent = 0.10 // 10%
delegationShare = reward.PercentDenominator * delegationPercent
)

var (
rewardKey = e2e.NewPrivateKey(tc)
rewardAddr = rewardKey.Address()
)

_, err = pWallet.IssueAddPermissionlessValidatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
Expand All @@ -127,11 +136,11 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL
pContext.AVAXAssetID,
&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{rewardKey.Address()},
Addrs: []ids.ShortID{rewardAddr},
},
&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{rewardKey.Address()},
Addrs: []ids.ShortID{rewardAddr},
},
delegationShare,
tc.WithDefaultContext(),
Expand All @@ -141,8 +150,10 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL

// Adding a delegator should not break interchain transfer.
tc.By("adding a delegator to the new node", func() {
rewardKey, err := secp256k1.NewPrivateKey()
require.NoError(err)
var (
rewardKey = e2e.NewPrivateKey(tc)
rewardAddr = rewardKey.Address()
)

_, err = pWallet.IssueAddPermissionlessDelegatorTx(
&txs.SubnetValidator{
Expand All @@ -156,7 +167,7 @@ var _ = e2e.DescribePChain("[Interchain Workflow]", ginkgo.Label(e2e.UsesCChainL
pContext.AVAXAssetID,
&secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{rewardKey.Address()},
Addrs: []ids.ShortID{rewardAddr},
},
tc.WithDefaultContext(),
)
Expand Down
Loading

0 comments on commit 6d89732

Please sign in to comment.