Skip to content

Commit

Permalink
test that all testnet chain selectors have a corresponding mainnet ch…
Browse files Browse the repository at this point in the history
…ain selector.
  • Loading branch information
winder committed May 20, 2024
1 parent 2faadbd commit 4b3ebbf
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 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,42 @@ 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
}
}

// 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", chain)
}
}
}

0 comments on commit 4b3ebbf

Please sign in to comment.