From b51d94b9d13cceaf9a98138249854ddc12504820 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Tue, 5 Nov 2024 17:36:16 -0500 Subject: [PATCH] ACP-77: Refactor e2e test (#3522) Co-authored-by: marun --- tests/e2e/p/l1.go | 146 ++++++++++++++++++++++++ tests/e2e/p/permissionless_layer_one.go | 102 ----------------- 2 files changed, 146 insertions(+), 102 deletions(-) create mode 100644 tests/e2e/p/l1.go delete mode 100644 tests/e2e/p/permissionless_layer_one.go diff --git a/tests/e2e/p/l1.go b/tests/e2e/p/l1.go new file mode 100644 index 000000000000..544f970f4f8f --- /dev/null +++ b/tests/e2e/p/l1.go @@ -0,0 +1,146 @@ +// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. +// See the file LICENSE for licensing terms. + +package p + +import ( + "math" + "time" + + "github.com/onsi/ginkgo/v2" + "github.com/stretchr/testify/require" + + "github.com/ava-labs/avalanchego/api/info" + "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/vms/example/xsvm/genesis" + "github.com/ava-labs/avalanchego/vms/platformvm" + "github.com/ava-labs/avalanchego/vms/secp256k1fx" +) + +var _ = e2e.DescribePChain("[L1]", func() { + tc := e2e.NewTestContext() + require := require.New(tc) + + ginkgo.It("creates and updates L1 validators", func() { + env := e2e.GetEnv(tc) + nodeURI := env.GetRandomNodeURI() + + tc.By("verifying Etna is activated", func() { + infoClient := info.NewClient(nodeURI.URI) + upgrades, err := infoClient.Upgrades(tc.DefaultContext()) + require.NoError(err) + + now := time.Now() + if !upgrades.IsEtnaActivated(now) { + ginkgo.Skip("Etna is not activated. L1s are enabled post-Etna, skipping test.") + } + }) + + tc.By("loading the wallet") + var ( + keychain = env.NewKeychain() + baseWallet = e2e.NewWallet(tc, keychain, nodeURI) + pWallet = baseWallet.P() + pClient = platformvm.NewClient(nodeURI.URI) + owner = &secp256k1fx.OutputOwners{ + Threshold: 1, + Addrs: []ids.ShortID{ + keychain.Keys[0].Address(), + }, + } + ) + + tc.By("creating the chain genesis") + genesisKey, err := secp256k1.NewPrivateKey() + require.NoError(err) + + genesisBytes, err := genesis.Codec.Marshal(genesis.CodecVersion, &genesis.Genesis{ + Timestamp: time.Now().Unix(), + Allocations: []genesis.Allocation{ + { + Address: genesisKey.Address(), + Balance: math.MaxUint64, + }, + }, + }) + require.NoError(err) + + var subnetID ids.ID + tc.By("issuing a CreateSubnetTx", func() { + subnetTx, err := pWallet.IssueCreateSubnetTx( + owner, + tc.WithDefaultContext(), + ) + require.NoError(err) + + subnetID = subnetTx.ID() + }) + + tc.By("verifying a Permissioned Subnet was successfully created", func() { + require.NotEqual(constants.PrimaryNetworkID, subnetID) + + subnet, err := pClient.GetSubnet(tc.DefaultContext(), subnetID) + require.NoError(err) + require.Equal( + platformvm.GetSubnetClientResponse{ + IsPermissioned: true, + ControlKeys: []ids.ShortID{ + keychain.Keys[0].Address(), + }, + Threshold: 1, + }, + subnet, + ) + }) + + var chainID ids.ID + tc.By("issuing a CreateChainTx", func() { + chainTx, err := pWallet.IssueCreateChainTx( + subnetID, + genesisBytes, + constants.XSVMID, + nil, + "No Permissions", + tc.WithDefaultContext(), + ) + require.NoError(err) + + chainID = chainTx.ID() + }) + + address := []byte{} + tc.By("issuing a ConvertSubnetTx", func() { + _, err := pWallet.IssueConvertSubnetTx( + subnetID, + chainID, + address, + tc.WithDefaultContext(), + ) + require.NoError(err) + }) + + tc.By("verifying the Permissioned Subnet was converted to an L1", func() { + tc.By("verifying the subnet reports as being converted", func() { + subnet, err := pClient.GetSubnet(tc.DefaultContext(), subnetID) + require.NoError(err) + require.Equal( + platformvm.GetSubnetClientResponse{ + IsPermissioned: false, + ControlKeys: []ids.ShortID{ + keychain.Keys[0].Address(), + }, + Threshold: 1, + ManagerChainID: chainID, + ManagerAddress: address, + }, + subnet, + ) + }) + }) + + _ = e2e.CheckBootstrapIsPossible(tc, env.GetNetwork()) + }) +}) diff --git a/tests/e2e/p/permissionless_layer_one.go b/tests/e2e/p/permissionless_layer_one.go deleted file mode 100644 index edd1dbf7f9e4..000000000000 --- a/tests/e2e/p/permissionless_layer_one.go +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. -// See the file LICENSE for licensing terms. - -package p - -import ( - "time" - - "github.com/onsi/ginkgo/v2" - "github.com/stretchr/testify/require" - - "github.com/ava-labs/avalanchego/api/info" - "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/vms/platformvm" - "github.com/ava-labs/avalanchego/vms/secp256k1fx" -) - -var _ = e2e.DescribePChain("[Permissionless L1]", func() { - tc := e2e.NewTestContext() - require := require.New(tc) - - ginkgo.It("creates a Permissionless L1", func() { - env := e2e.GetEnv(tc) - nodeURI := env.GetRandomNodeURI() - infoClient := info.NewClient(nodeURI.URI) - - tc.By("fetching upgrade config") - upgrades, err := infoClient.Upgrades(tc.DefaultContext()) - require.NoError(err) - - tc.By("verifying Etna is activated") - now := time.Now() - if !upgrades.IsEtnaActivated(now) { - ginkgo.Skip("Etna is not activated. Permissionless L1s are enabled post-Etna, skipping test.") - } - - keychain := env.NewKeychain() - baseWallet := e2e.NewWallet(tc, keychain, nodeURI) - - pWallet := baseWallet.P() - pClient := platformvm.NewClient(nodeURI.URI) - - owner := &secp256k1fx.OutputOwners{ - Threshold: 1, - Addrs: []ids.ShortID{ - keychain.Keys[0].Address(), - }, - } - - tc.By("issuing a CreateSubnetTx") - subnetTx, err := pWallet.IssueCreateSubnetTx( - owner, - tc.WithDefaultContext(), - ) - require.NoError(err) - - tc.By("verifying a Permissioned Subnet was successfully created") - subnetID := subnetTx.ID() - require.NotEqual(subnetID, constants.PrimaryNetworkID) - - res, err := pClient.GetSubnet(tc.DefaultContext(), subnetID) - require.NoError(err) - - require.Equal(platformvm.GetSubnetClientResponse{ - IsPermissioned: true, - ControlKeys: []ids.ShortID{ - keychain.Keys[0].Address(), - }, - Threshold: 1, - }, res) - - chainID := ids.GenerateTestID() - address := []byte{'a', 'd', 'd', 'r', 'e', 's', 's'} - - tc.By("issuing a ConvertSubnetTx") - _, err = pWallet.IssueConvertSubnetTx( - subnetID, - chainID, - address, - tc.WithDefaultContext(), - ) - require.NoError(err) - - tc.By("verifying the Permissioned Subnet was converted to a Permissionless L1") - res, err = pClient.GetSubnet(tc.DefaultContext(), subnetID) - require.NoError(err) - - require.Equal(platformvm.GetSubnetClientResponse{ - IsPermissioned: false, - ControlKeys: []ids.ShortID{ - keychain.Keys[0].Address(), - }, - Threshold: 1, - ManagerChainID: chainID, - ManagerAddress: address, - }, res) - - _ = e2e.CheckBootstrapIsPossible(tc, env.GetNetwork()) - }) -})