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

All testnet chain selectors must have a corresponding mainnet chain selector. #39

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
49 changes: 49 additions & 0 deletions selectors_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package chain_selectors

import (
"fmt"
"math/rand"
"regexp"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -214,3 +216,50 @@ func Test_IsEvm(t *testing.T) {
assert.False(t, isEvm)
})
}

func Test_MainnetAndTestnetAreSynchronized(t *testing.T) {
re := regexp.MustCompile(`^([a-zA-Z0-9-]+)-(mainnet|testnet)`)
parseName := func(str string) (chain string, isMainnet bool, err error) {
matches := re.FindStringSubmatch(str)

if matches == nil {
return "", false, fmt.Errorf("no matches found")
}

return matches[1], matches[2] == "mainnet", nil
}

type chainDetails struct {
mainnet []string
testnet []string
}

var chainMap = make(map[string]chainDetails)
for _, chain := range ALL {
name, isMainnet, err := parseName(chain.Name)
if err == nil {
details := chainMap[name]
if isMainnet {
details.mainnet = append(details.mainnet, chain.Name)
} else {
details.testnet = append(details.testnet, chain.Name)
}
chainMap[name] = details
}
}

// Skip legacy testnet only chains
delete(chainMap, "bitcoin")
delete(chainMap, "geth")
delete(chainMap, "hedera")
delete(chainMap, "berachain")
delete(chainMap, "cronos")
delete(chainMap, "fantom")

// analyze results
for chain, details := range chainMap {
if len(details.mainnet) == 0 && len(details.testnet) != 0 {
assert.Fail(t, "Chain %s has testnet chains but no mainnet chains. If this is intentional add an exception to this test with a comment explaining why.", chain)
}
}
}
Loading