Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[testing] Remove dep on gomega #1198

Merged
merged 1 commit into from
May 30, 2024
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
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ require (
github.com/mattn/go-isatty v0.0.17
github.com/olekukonko/tablewriter v0.0.5
github.com/onsi/ginkgo/v2 v2.13.1
github.com/onsi/gomega v1.29.0
github.com/prometheus/client_golang v1.16.0
github.com/prometheus/client_model v0.3.0
github.com/shirou/gopsutil v3.21.11+incompatible
Expand Down Expand Up @@ -84,7 +83,6 @@ require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20230207041349-798e818bf904 // indirect
github.com/google/renameio/v2 v2.0.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
Expand Down
3 changes: 0 additions & 3 deletions tests/load/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (

ginkgo "github.com/onsi/ginkgo/v2"

"github.com/onsi/gomega"

"github.com/stretchr/testify/require"

"github.com/ethereum/go-ethereum/log"
Expand Down Expand Up @@ -46,7 +44,6 @@ func init() {
}

func TestE2E(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "subnet-evm small load simulator test suite")
}

Expand Down
2 changes: 0 additions & 2 deletions tests/precompile/precompile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"testing"

ginkgo "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"

// Import the solidity package, so that ginkgo maps out the tests declared within the package
"github.com/ava-labs/subnet-evm/tests/precompile/solidity"
Expand All @@ -18,7 +17,6 @@ func TestE2E(t *testing.T) {
if basePath := os.Getenv("TEST_SOURCE_ROOT"); basePath != "" {
os.Chdir(basePath)
}
gomega.RegisterFailHandler(ginkgo.Fail)
solidity.RegisterAsyncTests()
ginkgo.RunSpecs(t, "subnet-evm precompile ginkgo test suite")
}
28 changes: 17 additions & 11 deletions tests/utils/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/go-cmd/cmd"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/stretchr/testify/require"
)

// RunCommand starts the command [bin] with the given [args] and returns the command to the caller
Expand Down Expand Up @@ -51,41 +51,45 @@ func RunCommand(bin string, args ...string) (*cmd.Cmd, error) {
}

func RegisterPingTest() {
require := require.New(ginkgo.GinkgoT())

ginkgo.It("ping the network", ginkgo.Label("ping"), func() {
client := health.NewClient(DefaultLocalNodeURI)
healthy, err := client.Readiness(context.Background(), nil)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(healthy.Healthy).Should(gomega.BeTrue())
require.NoError(err)
require.True(healthy.Healthy)
})
}

// RegisterNodeRun registers a before suite that starts an AvalancheGo process to use for the e2e tests
// and an after suite that stops the AvalancheGo process
func RegisterNodeRun() {
require := require.New(ginkgo.GinkgoT())

// BeforeSuite starts an AvalancheGo process to use for the e2e tests
var startCmd *cmd.Cmd
_ = ginkgo.BeforeSuite(func() {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

wd, err := os.Getwd()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
log.Info("Starting AvalancheGo node", "wd", wd)
cmd, err := RunCommand("./scripts/run.sh")
startCmd = cmd
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)

// Assumes that startCmd will launch a node with HTTP Port at [utils.DefaultLocalNodeURI]
healthClient := health.NewClient(DefaultLocalNodeURI)
healthy, err := health.AwaitReady(ctx, healthClient, HealthCheckTimeout, nil)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(healthy).Should(gomega.BeTrue())
require.NoError(err)
require.True(healthy)
log.Info("AvalancheGo node is healthy")
})

ginkgo.AfterSuite(func() {
gomega.Expect(startCmd).ShouldNot(gomega.BeNil())
gomega.Expect(startCmd.Stop()).Should(gomega.BeNil())
require.NotNil(startCmd)
require.NoError(startCmd.Stop())
// TODO add a new node to bootstrap off of the existing node and ensure it can bootstrap all subnets
// created during the test
})
Expand All @@ -99,6 +103,8 @@ func RunHardhatTests(ctx context.Context, blockchainID string, execPath string,
}

func RunHardhatTestsCustomURI(ctx context.Context, chainURI string, execPath string, testPath string) {
require := require.New(ginkgo.GinkgoT())

log.Info(
"Executing HardHat tests on blockchain",
"testPath", testPath,
Expand All @@ -110,10 +116,10 @@ func RunHardhatTestsCustomURI(ctx context.Context, chainURI string, execPath str

log.Info("Sleeping to wait for test ping", "rpcURI", chainURI)
err := os.Setenv("RPC_URI", chainURI)
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
log.Info("Running test command", "cmd", cmd.String())

out, err := cmd.CombinedOutput()
fmt.Printf("\nCombined output:\n\n%s\n", string(out))
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
}
39 changes: 21 additions & 18 deletions tests/utils/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/go-cmd/cmd"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"github.com/stretchr/testify/require"
)

type SubnetSuite struct {
Expand All @@ -47,6 +47,8 @@ func (s *SubnetSuite) SetBlockchainIDs(blockchainIDs map[string]string) {
// CreateSubnetsSuite creates subnets for given [genesisFiles], and registers a before suite that starts an AvalancheGo process to use for the e2e tests.
// genesisFiles is a map of test aliases to genesis file paths.
func CreateSubnetsSuite(genesisFiles map[string]string) *SubnetSuite {
require := require.New(ginkgo.GinkgoT())

// Keep track of the AvalancheGo external bash script, it is null for most
// processes except the first process that starts AvalancheGo
var startCmd *cmd.Cmd
Expand All @@ -67,32 +69,31 @@ func CreateSubnetsSuite(genesisFiles map[string]string) *SubnetSuite {
defer cancel()

wd, err := os.Getwd()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
log.Info("Starting AvalancheGo node", "wd", wd)
cmd, err := RunCommand("./scripts/run.sh")
require.NoError(err)
startCmd = cmd
gomega.Expect(err).Should(gomega.BeNil())

// Assumes that startCmd will launch a node with HTTP Port at [utils.DefaultLocalNodeURI]
healthClient := health.NewClient(DefaultLocalNodeURI)
healthy, err := health.AwaitReady(ctx, healthClient, HealthCheckTimeout, nil)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(healthy).Should(gomega.BeTrue())
require.NoError(err)
require.True(healthy)
log.Info("AvalancheGo node is healthy")

gomega.Expect(err).NotTo(gomega.HaveOccurred())
blockchainIDs := make(map[string]string)
for alias, file := range genesisFiles {
blockchainIDs[alias] = CreateNewSubnet(ctx, file)
}

blockchainIDsBytes, err := json.Marshal(blockchainIDs)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
require.NoError(err)
return blockchainIDsBytes
}, func(ctx ginkgo.SpecContext, data []byte) {
blockchainIDs := make(map[string]string)
err := json.Unmarshal(data, &blockchainIDs)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
require.NoError(err)

globalSuite.SetBlockchainIDs(blockchainIDs)
})
Expand All @@ -101,8 +102,8 @@ func CreateSubnetsSuite(genesisFiles map[string]string) *SubnetSuite {
// function is executed once when all the tests are done. This function is used
// to gracefully shutdown the AvalancheGo node.
var _ = ginkgo.SynchronizedAfterSuite(func() {}, func() {
gomega.Expect(startCmd).ShouldNot(gomega.BeNil())
gomega.Expect(startCmd.Stop()).Should(gomega.BeNil())
require.NotNil(startCmd)
require.NoError(startCmd.Stop())
})

return &globalSuite
Expand All @@ -111,6 +112,8 @@ func CreateSubnetsSuite(genesisFiles map[string]string) *SubnetSuite {
// CreateNewSubnet creates a new subnet and Subnet-EVM blockchain with the given genesis file.
// returns the ID of the new created blockchain.
func CreateNewSubnet(ctx context.Context, genesisFilePath string) string {
require := require.New(ginkgo.GinkgoT())

kc := secp256k1fx.NewKeychain(genesis.EWOQKey)

// MakeWallet fetches the available UTXOs owned by [kc] on the network
Expand All @@ -120,7 +123,7 @@ func CreateNewSubnet(ctx context.Context, genesisFilePath string) string {
AVAXKeychain: kc,
EthKeychain: kc,
})
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)

pWallet := wallet.P()

Expand All @@ -132,18 +135,18 @@ func CreateNewSubnet(ctx context.Context, genesisFilePath string) string {
}

wd, err := os.Getwd()
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
log.Info("Reading genesis file", "filePath", genesisFilePath, "wd", wd)
genesisBytes, err := os.ReadFile(genesisFilePath)
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)

log.Info("Creating new subnet")
createSubnetTx, err := pWallet.IssueCreateSubnetTx(owner)
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)

genesis := &core.Genesis{}
err = json.Unmarshal(genesisBytes, genesis)
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)

log.Info("Creating new Subnet-EVM blockchain", "genesis", genesis)
createChainTx, err := pWallet.IssueCreateChainTx(
Expand All @@ -153,14 +156,14 @@ func CreateNewSubnet(ctx context.Context, genesisFilePath string) string {
nil,
"testChain",
)
gomega.Expect(err).Should(gomega.BeNil())
require.NoError(err)
createChainTxID := createChainTx.ID()

// Confirm the new blockchain is ready by waiting for the readiness endpoint
infoClient := info.NewClient(DefaultLocalNodeURI)
bootstrapped, err := info.AwaitBootstrapped(ctx, infoClient, createChainTxID.String(), 2*time.Second)
gomega.Expect(err).Should(gomega.BeNil())
gomega.Expect(bootstrapped).Should(gomega.BeTrue())
require.NoError(err)
require.True(bootstrapped)

// Return the blockchainID of the newly created blockchain
return createChainTxID.String()
Expand Down
3 changes: 0 additions & 3 deletions tests/warp/warp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (

ginkgo "github.com/onsi/ginkgo/v2"

"github.com/onsi/gomega"

"github.com/stretchr/testify/require"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -87,7 +85,6 @@ type Subnet struct {
}

func TestE2E(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)
ginkgo.RunSpecs(t, "subnet-evm warp e2e test")
}

Expand Down
Loading