Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph committed Feb 27, 2025
1 parent 5a7e044 commit 3b4be16
Show file tree
Hide file tree
Showing 6 changed files with 305 additions and 4 deletions.
25 changes: 23 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: fuzz_test
shell: bash
run: ./scripts/build_fuzz.sh 10 # Run each fuzz test 10 seconds
e2e:
e2e_pre_etna:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -72,7 +72,28 @@ jobs:
uses: ./.github/actions/upload-tmpnet-artifact
if: always()
with:
name: e2e-tmpnet-data
name: e2e-pre-etna-tmpnet-data
e2e_post_etna:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-go-for-project
- name: Build AvalancheGo Binary
shell: bash
run: ./scripts/build.sh -r
- name: Run e2e tests
uses: ./.github/actions/run-monitored-tmpnet-cmd
with:
run: E2E_SERIAL=1 ./scripts/tests.e2e.sh --delay-network-shutdown --activate-etna
prometheus_id: ${{ secrets.PROMETHEUS_ID || '' }}
prometheus_password: ${{ secrets.PROMETHEUS_PASSWORD || '' }}
loki_id: ${{ secrets.LOKI_ID || '' }}
loki_password: ${{ secrets.LOKI_PASSWORD || '' }}
- name: Upload tmpnet network dir
uses: ./.github/actions/upload-tmpnet-artifact
if: always()
with:
name: e2e-post-etna-tmpnet-data
e2e_existing_network:
runs-on: ubuntu-latest
steps:
Expand Down
27 changes: 25 additions & 2 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,27 @@
package e2e_test

import (
"encoding/base64"
"encoding/json"
"testing"

"github.com/onsi/ginkgo/v2"
"github.com/stretchr/testify/require"

// ensure test packages are scanned by ginkgo
_ "github.com/ava-labs/avalanchego/tests/e2e/banff"
_ "github.com/ava-labs/avalanchego/tests/e2e/c"
_ "github.com/ava-labs/avalanchego/tests/e2e/etna"
_ "github.com/ava-labs/avalanchego/tests/e2e/faultinjection"
_ "github.com/ava-labs/avalanchego/tests/e2e/p"
_ "github.com/ava-labs/avalanchego/tests/e2e/x"
_ "github.com/ava-labs/avalanchego/tests/e2e/x/transfer"

"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/tests/e2e/vms"
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
"github.com/ava-labs/avalanchego/upgrade"
)

func TestE2E(t *testing.T) {
Expand All @@ -34,13 +40,30 @@ func init() {
var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
// Run only once in the first ginkgo process

tc := e2e.NewEventHandlerTestContext()

nodes := tmpnet.NewNodesOrPanic(flagVars.NodeCount())
subnets := vms.XSVMSubnetsOrPanic(nodes...)

upgrades := upgrade.Default
if flagVars.ActivateFortuna() {
upgrades.EtnaTime = upgrade.InitiallyActiveTime
} else {
upgrades.EtnaTime = upgrade.UnscheduledActivationTime
}

upgradeJSON, err := json.Marshal(upgrades)
require.NoError(tc, err)

upgradeBase64 := base64.StdEncoding.EncodeToString(upgradeJSON)
return e2e.NewTestEnvironment(
e2e.NewEventHandlerTestContext(),
tc,
flagVars,
&tmpnet.Network{
Owner: "avalanchego-e2e",
Owner: "avalanchego-e2e",
DefaultFlags: tmpnet.FlagsMap{
config.UpgradeFileContentKey: upgradeBase64,
},
Nodes: nodes,
Subnets: subnets,
},
Expand Down
38 changes: 38 additions & 0 deletions tests/e2e/etna/suites.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

// Implements tests for the etna network upgrade.
package etna

import (
"time"

"github.com/onsi/ginkgo/v2"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"github.com/ava-labs/avalanchego/api/info"
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
)

var _ = ginkgo.Describe("[Etna]", func() {
tc := e2e.NewTestContext()
require := require.New(tc)

ginkgo.It("can detect if Etna is activated",
func() {
env := e2e.GetEnv(tc)
infoClient := info.NewClient(env.GetRandomNodeURI().URI)

tc.By("get upgrade config")
upgrades, err := infoClient.Upgrades(tc.DefaultContext())
require.NoError(err)

now := time.Now()
tc.Log().Info("detected if Etna is activated",
zap.Time("now", now),
zap.Time("etnaTime", upgrades.EtnaTime),
zap.Bool("isEtnaActivated", upgrades.IsEtnaActivated(now)),
)
})
})
196 changes: 196 additions & 0 deletions tests/e2e/p/elastic_subnets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package p

import (
"fmt"
"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/units"
"github.com/ava-labs/avalanchego/vms/components/avax"
"github.com/ava-labs/avalanchego/vms/components/verify"
"github.com/ava-labs/avalanchego/vms/platformvm"
"github.com/ava-labs/avalanchego/vms/platformvm/reward"
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/secp256k1fx"
)

var _ = e2e.DescribePChain("[Elastic Subnets]", func() {
tc := e2e.NewTestContext()
require := require.New(tc)

ginkgo.It("subnets operations",
func() {
env := e2e.GetEnv(tc)

nodeURI := env.GetRandomNodeURI()

infoClient := info.NewClient(nodeURI.URI)

tc.By("get upgrade config")
upgrades, err := infoClient.Upgrades(tc.DefaultContext())
require.NoError(err)

now := time.Now()
if upgrades.IsEtnaActivated(now) {
ginkgo.Skip("Etna is activated. Elastic Subnets are disabled post-Etna, skipping test.")
}

keychain := env.NewKeychain()
baseWallet := e2e.NewWallet(tc, keychain, nodeURI)

pWallet := baseWallet.P()
xWallet := baseWallet.X()
xBuilder := xWallet.Builder()
xContext := xBuilder.Context()
xChainID := xContext.BlockchainID

var validatorID ids.NodeID
tc.By("retrieving the node ID of a primary network validator", func() {
pChainClient := platformvm.NewClient(nodeURI.URI)
validatorIDs, err := pChainClient.SampleValidators(tc.DefaultContext(), constants.PrimaryNetworkID, 1)
require.NoError(err)
validatorID = validatorIDs[0]
})

owner := &secp256k1fx.OutputOwners{
Threshold: 1,
Addrs: []ids.ShortID{
keychain.Keys[0].Address(),
},
}

var subnetID ids.ID
tc.By("create a permissioned subnet", func() {
subnetTx, err := pWallet.IssueCreateSubnetTx(
owner,
tc.WithDefaultContext(),
)
require.NoError(err)
subnetID = subnetTx.ID()
require.NotEqual(subnetID, constants.PrimaryNetworkID)
})

validatorWeight := units.Avax
initialSupply := 2 * validatorWeight
maxSupply := 2 * initialSupply

var subnetAssetID ids.ID
tc.By("create a custom asset for the permissionless subnet", func() {
subnetAssetTx, err := xWallet.IssueCreateAssetTx(
"RnM",
"RNM",
9,
map[uint32][]verify.State{
0: {
&secp256k1fx.TransferOutput{
Amt: maxSupply,
OutputOwners: *owner,
},
},
},
tc.WithDefaultContext(),
)
require.NoError(err)
subnetAssetID = subnetAssetTx.ID()
})

tc.By(fmt.Sprintf("Send %d of asset %s to the P-chain", maxSupply, subnetAssetID), func() {
_, err := xWallet.IssueExportTx(
constants.PlatformChainID,
[]*avax.TransferableOutput{
{
Asset: avax.Asset{
ID: subnetAssetID,
},
Out: &secp256k1fx.TransferOutput{
Amt: maxSupply,
OutputOwners: *owner,
},
},
},
tc.WithDefaultContext(),
)
require.NoError(err)
})

tc.By(fmt.Sprintf("Import the %d of asset %s from the X-chain into the P-chain", maxSupply, subnetAssetID), func() {
_, err := pWallet.IssueImportTx(
xChainID,
owner,
tc.WithDefaultContext(),
)
require.NoError(err)
})

tc.By("make subnet permissionless", func() {
_, err := pWallet.IssueTransformSubnetTx(
subnetID,
subnetAssetID,
initialSupply,
maxSupply,
reward.PercentDenominator,
reward.PercentDenominator,
1,
maxSupply,
time.Second,
365*24*time.Hour,
0,
1,
5,
.80*reward.PercentDenominator,
tc.WithDefaultContext(),
)
require.NoError(err)
})

endTime := time.Now().Add(time.Minute)
tc.By("add permissionless validator", func() {
_, err := pWallet.IssueAddPermissionlessValidatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: validatorID,
End: uint64(endTime.Unix()),
Wght: validatorWeight,
},
Subnet: subnetID,
},
&signer.Empty{},
subnetAssetID,
&secp256k1fx.OutputOwners{},
&secp256k1fx.OutputOwners{},
reward.PercentDenominator,
tc.WithDefaultContext(),
)
require.NoError(err)
})

tc.By("add permissionless delegator", func() {
_, err := pWallet.IssueAddPermissionlessDelegatorTx(
&txs.SubnetValidator{
Validator: txs.Validator{
NodeID: validatorID,
End: uint64(endTime.Unix()),
Wght: validatorWeight,
},
Subnet: subnetID,
},
subnetAssetID,
&secp256k1fx.OutputOwners{},
tc.WithDefaultContext(),
)
require.NoError(err)
})

_ = e2e.CheckBootstrapIsPossible(tc, env.GetNetwork())
})
})
12 changes: 12 additions & 0 deletions tests/e2e/p/l1.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"go.uber.org/zap"
"google.golang.org/protobuf/proto"

"github.com/ava-labs/avalanchego/api/info"
"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/network/peer"
Expand Down Expand Up @@ -70,6 +71,17 @@ var _ = e2e.DescribePChain("[L1]", 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()
Expand Down
11 changes: 11 additions & 0 deletions tests/fixture/e2e/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type FlagVars struct {
stopNetwork bool
restartNetwork bool
nodeCount int
activateFortuna bool
}

func (v *FlagVars) AvalancheGoExecPath() (string, error) {
Expand Down Expand Up @@ -94,6 +95,10 @@ func (v *FlagVars) NodeCount() int {
return v.nodeCount
}

func (v *FlagVars) ActivateFortuna() bool {
return v.activateFortuna
}

func GetEnvWithDefault(envVar, defaultVal string) string {
val := os.Getenv(envVar)
if len(val) == 0 {
Expand Down Expand Up @@ -164,6 +169,12 @@ func RegisterFlags() *FlagVars {
tmpnet.DefaultNodeCount,
"number of nodes the network should initially consist of",
)
flag.BoolVar(
&vars.activateFortuna,
"activate-fortuna",
false,
"[optional] activate the fortuna upgrade",
)

return &vars
}

0 comments on commit 3b4be16

Please sign in to comment.