Skip to content

Commit

Permalink
dedupe perChainTestName
Browse files Browse the repository at this point in the history
  • Loading branch information
geoknee committed Aug 29, 2024
1 parent 4ebaafc commit 4cbf389
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
12 changes: 12 additions & 0 deletions validation/common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package common

import (
"fmt"
. "github.com/ethereum-optimism/superchain-registry/superchain"
)


// PerChainTestName ensures test can easily be filtered by chain name or chain id using the -run=regex testflag.
func PerChainTestName(chain *ChainConfig) string {
return chain.Name + fmt.Sprintf(" (%d)", chain.ChainID)
}
11 changes: 3 additions & 8 deletions validation/genesis/genesis-predeploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,14 @@ import (
"strings"
"testing"

"github.com/ethereum-optimism/superchain-registry/superchain"
. "github.com/ethereum-optimism/superchain-registry/superchain"
. "github.com/ethereum-optimism/superchain-registry/validation/common"
"github.com/ethereum/go-ethereum/common"

"github.com/ethereum/go-ethereum/core"
"github.com/stretchr/testify/require"
)

// TODO deduplicate this
// perChainTestName ensures test can easily be filtered by chain name or chain id using the -run=regex testflag.
func perChainTestName(chain *superchain.ChainConfig) string {
return chain.Name + fmt.Sprintf(" (%d)", chain.ChainID)
}

var temporaryOptimismDir string

func TestGenesisPredeploys(t *testing.T) {
Expand All @@ -47,7 +42,7 @@ func TestGenesisPredeploys(t *testing.T) {

for _, chain := range OPChains {
if chain.SuperchainLevel == Standard || chain.StandardChainCandidate {
t.Run(perChainTestName(chain), func(t *testing.T) {
t.Run(PerChainTestName(chain), func(t *testing.T) {
// Do not run in parallel
testGenesisPredeploys(t, chain)
})
Expand Down
3 changes: 2 additions & 1 deletion validation/promotion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"testing"

. "github.com/ethereum-optimism/superchain-registry/superchain"
"github.com/ethereum-optimism/superchain-registry/validation/common"
)

// WARNING: this test must not run along side any other tests, because it mutates global objects.
// It should be strictly isolated.
func TestPromotion(t *testing.T) {
for _, chain := range OPChains {
chain := chain
t.Run(perChainTestName(chain), func(t *testing.T) {
t.Run(common.PerChainTestName(chain), func(t *testing.T) {
t.Parallel()
if chain.StandardChainCandidate {
// do not allow any test exclusions
Expand Down
6 changes: 0 additions & 6 deletions validation/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ import (
"math/big"
"testing"

"github.com/ethereum-optimism/superchain-registry/superchain"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// perChainTestName ensures test can easily be filtered by chain name or chain id using the -run=regex testflag.
func perChainTestName(chain *superchain.ChainConfig) string {
return chain.Name + fmt.Sprintf(" (%d)", chain.ChainID)
}

// isBigIntWithinBounds returns true if actual is within bounds, where the bounds are [lower bound, upper bound] and are inclusive.
var isBigIntWithinBounds = func(actual *big.Int, bounds [2]*big.Int) bool {
if (bounds[1].Cmp(bounds[0])) < 0 {
Expand Down
3 changes: 2 additions & 1 deletion validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"testing"

. "github.com/ethereum-optimism/superchain-registry/superchain"
"github.com/ethereum-optimism/superchain-registry/validation/common"
)

func TestValidation(t *testing.T) {
// Entry point for validation checks which run
// on each OP chain.
for _, chain := range OPChains {
chain := chain
t.Run(perChainTestName(chain), func(t *testing.T) {
t.Run(common.PerChainTestName(chain), func(t *testing.T) {
t.Parallel()
testValidation(t, chain)
})
Expand Down

0 comments on commit 4cbf389

Please sign in to comment.