Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions graft/subnet-evm/tests/antithesis/gencomposeconfig/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ package main

import (
"log"
"os"
"path/filepath"

"github.com/ava-labs/avalanchego/graft/subnet-evm/tests"
"github.com/ava-labs/avalanchego/graft/subnet-evm/tests/utils"
"github.com/ava-labs/avalanchego/tests/antithesis"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
Expand All @@ -17,18 +16,10 @@ const baseImageName = "antithesis-subnet-evm"

// Creates docker-compose.yml and its associated volumes in the target path.
func main() {
// Assume the working directory is the root of the repository
cwd, err := os.Getwd()
if err != nil {
log.Fatalf("failed to get current working directory: %s", err)
}

genesisPath := filepath.Join(cwd, "tests/load/genesis.json")

// Create a network with a subnet-evm subnet
network := tmpnet.LocalNetworkOrPanic()
network.Subnets = []*tmpnet.Subnet{
utils.NewTmpnetSubnet("subnet-evm", genesisPath, utils.DefaultChainConfig, network.Nodes...),
utils.NewTmpnetSubnet("subnet-evm", tests.Genesis, utils.DefaultChainConfig, network.Nodes...),
}

if err := antithesis.GenerateComposeConfig(network, baseImageName); err != nil {
Expand Down
7 changes: 2 additions & 5 deletions graft/subnet-evm/tests/antithesis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"crypto/rand"
"fmt"
"math/big"
"path/filepath"
"runtime"
"time"

"github.com/antithesishq/antithesis-sdk-go/assert"
Expand All @@ -23,6 +21,7 @@ import (

"github.com/ava-labs/avalanchego/graft/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/avalanchego/graft/subnet-evm/ethclient"
"github.com/ava-labs/avalanchego/graft/subnet-evm/tests"
"github.com/ava-labs/avalanchego/graft/subnet-evm/tests/utils"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests/antithesis"
Expand Down Expand Up @@ -51,10 +50,8 @@ func main() {
tmpnet.FlagsMap{},
),
func(nodes ...*tmpnet.Node) []*tmpnet.Subnet {
_, thisFile, _, _ := runtime.Caller(0)
genesisPath := filepath.Join(filepath.Dir(thisFile), "..", "load", "genesis.json")
return []*tmpnet.Subnet{
utils.NewTmpnetSubnet("subnet-evm", genesisPath, utils.DefaultChainConfig, nodes...),
utils.NewTmpnetSubnet("subnet-evm", tests.Genesis, utils.DefaultChainConfig, nodes...),
}
},
)
Expand Down
13 changes: 13 additions & 0 deletions graft/subnet-evm/tests/genesis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (C) 2019-2026, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package tests

import (
_ "embed"
)

// Genesis contains the embedded genesis.json file used by tests.
//
//go:embed load/genesis.json
var Genesis []byte
19 changes: 11 additions & 8 deletions graft/subnet-evm/tests/load/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"testing"

"github.com/ava-labs/libevm/log"
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/graft/subnet-evm/tests"
"github.com/ava-labs/avalanchego/graft/subnet-evm/tests/utils"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
Expand Down Expand Up @@ -45,13 +44,17 @@ func TestE2E(t *testing.T) {
var _ = ginkgo.Describe("[Load Simulator]", ginkgo.Ordered, func() {
require := require.New(ginkgo.GinkgoT())

var env *e2e.TestEnvironment
_, thisFile, _, _ := runtime.Caller(0)
testDir := filepath.Dir(thisFile)
var (
env *e2e.TestEnvironment
repoRoot string
)

ginkgo.BeforeAll(func() {
tc := e2e.NewTestContext()
genesisPath := filepath.Join(testDir, "genesis.json")

var err error
repoRoot, err = e2e.GetRepoRootPath("tests/load")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with continuing to use GetRepoRootPath for now, but ideally we remove the need for it going forward (i.e. by checking for the run_simulator.sh script via a relative path and if missing require an absolute path to be provided by a flag).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do a follow up PR to accomplish this! and remove the function entirely so no one else can use it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the PR #4813

require.NoError(err)

nodes := utils.NewTmpnetNodes(nodeCount)
env = e2e.NewTestEnvironment(
Expand All @@ -61,7 +64,7 @@ var _ = ginkgo.Describe("[Load Simulator]", ginkgo.Ordered, func() {
"subnet-evm-small-load",
nodes,
tmpnet.FlagsMap{},
utils.NewTmpnetSubnet(subnetAName, genesisPath, utils.DefaultChainConfig, nodes...),
utils.NewTmpnetSubnet(subnetAName, tests.Genesis, utils.DefaultChainConfig, nodes...),
),
)
})
Expand All @@ -88,7 +91,7 @@ var _ = ginkgo.Describe("[Load Simulator]", ginkgo.Ordered, func() {

log.Info("Running load simulator...", "rpcEndpoints", commaSeparatedRPCEndpoints)
cmd := exec.Command("./scripts/run_simulator.sh")
cmd.Dir = filepath.Join(testDir, "../..")
cmd.Dir = repoRoot
log.Info("Running load simulator script", "cmd", cmd.String())

out, err := cmd.CombinedOutput()
Expand Down
10 changes: 2 additions & 8 deletions graft/subnet-evm/tests/utils/tmpnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package utils

import (
"encoding/json"
"os"

"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/graft/subnet-evm/plugin/evm"
Expand Down Expand Up @@ -45,7 +44,7 @@ func NewTmpnetNetwork(owner string, nodes []*tmpnet.Node, flags tmpnet.FlagsMap,

// Create the configuration that will enable creation and access to a
// subnet created on a temporary network.
func NewTmpnetSubnet(name string, genesisPath string, chainConfig map[string]any, nodes ...*tmpnet.Node) *tmpnet.Subnet {
func NewTmpnetSubnet(name string, genesis []byte, chainConfig map[string]any, nodes ...*tmpnet.Node) *tmpnet.Subnet {
if len(nodes) == 0 {
panic("a subnet must be validated by at least one node")
}
Expand All @@ -55,11 +54,6 @@ func NewTmpnetSubnet(name string, genesisPath string, chainConfig map[string]any
validatorIDs[i] = node.NodeID
}

genesisBytes, err := os.ReadFile(genesisPath)
if err != nil {
panic(err)
}

chainConfigBytes, err := json.Marshal(chainConfig)
if err != nil {
panic(err)
Expand All @@ -70,7 +64,7 @@ func NewTmpnetSubnet(name string, genesisPath string, chainConfig map[string]any
Chains: []*tmpnet.Chain{
{
VMID: evm.ID,
Genesis: genesisBytes,
Genesis: genesis,
Config: string(chainConfigBytes),
PreFundedKey: tmpnet.HardhatKey,
},
Expand Down
13 changes: 7 additions & 6 deletions graft/subnet-evm/tests/warp/warp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"crypto/ecdsa"
"fmt"
"math/big"
"path/filepath"
"runtime"
"strings"
"testing"
"time"
Expand All @@ -21,6 +19,8 @@ import (
"github.com/ava-labs/libevm/log"
"github.com/stretchr/testify/require"

_ "embed"

"github.com/ava-labs/avalanchego/api/info"
"github.com/ava-labs/avalanchego/graft/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/avalanchego/graft/subnet-evm/cmd/simulator/key"
Expand Down Expand Up @@ -55,6 +55,9 @@ const (
)

var (
//go:embed genesis.json
genesis []byte

flagVars *e2e.FlagVars

subnetA, subnetB, cChainSubnetDetails *Subnet
Expand Down Expand Up @@ -88,8 +91,6 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {

tc := e2e.NewTestContext()
nodes := utils.NewTmpnetNodes(tmpnet.DefaultNodeCount)
_, thisFile, _, _ := runtime.Caller(0)
genesisPath := filepath.Join(filepath.Dir(thisFile), "genesis.json")

env := e2e.NewTestEnvironment(
tc,
Expand All @@ -98,8 +99,8 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte {
"subnet-evm-warp-e2e",
nodes,
tmpnet.FlagsMap{},
utils.NewTmpnetSubnet(subnetAName, genesisPath, utils.DefaultChainConfig, nodes...),
utils.NewTmpnetSubnet(subnetBName, genesisPath, utils.DefaultChainConfig, nodes...),
utils.NewTmpnetSubnet(subnetAName, genesis, utils.DefaultChainConfig, nodes...),
utils.NewTmpnetSubnet(subnetBName, genesis, utils.DefaultChainConfig, nodes...),
),
)

Expand Down