Skip to content

Commit

Permalink
ACP-77: Refactor e2e test (#3522)
Browse files Browse the repository at this point in the history
Co-authored-by: marun <[email protected]>
  • Loading branch information
StephenButtolph and marun authored Nov 5, 2024
1 parent cb59182 commit b51d94b
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 102 deletions.
146 changes: 146 additions & 0 deletions tests/e2e/p/l1.go
Original file line number Diff line number Diff line change
@@ -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())
})
})
102 changes: 0 additions & 102 deletions tests/e2e/p/permissionless_layer_one.go

This file was deleted.

0 comments on commit b51d94b

Please sign in to comment.