Skip to content

Commit

Permalink
add test for unique chainID and family
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhen1997 committed Nov 4, 2024
1 parent eda4cb5 commit 3c0ed77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
9 changes: 0 additions & 9 deletions selectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,6 @@ func ChainSelectorToChainDetails() map[uint64]ChainDetails {
return copyMap
}

func TestChainSelectorToChainDetails() map[uint64]ChainDetails {
copyMap := make(map[uint64]ChainDetails, len(selectorsMap))
for k, v := range testSelectorsMap {
copyMap[k] = v
}

return copyMap
}

func GetSelectorFamily(selector uint64) (string, error) {
// previously selector_families.yml includes both real and test chains, therefore we check both maps
details, exist := chainIdToChainSelector[selector]
Expand Down
15 changes: 13 additions & 2 deletions selectors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,24 @@ import (
func TestNoSameChainSelectorsAreGenerated(t *testing.T) {
chainSelectors := map[uint64]struct{}{}

for selector := range selectorsMap {
for selector := range chainIdToChainSelector {
_, exist := chainSelectors[selector]
assert.False(t, exist, "Chain Selectors should be unique. Selector %d is duplicated for chain %d", selector)
chainSelectors[selector] = struct{}{}
}
}

func TestNoSameChainIDAndFamilyAreGenerated(t *testing.T) {
chainIDAndFamily := map[string]struct{}{}

for _, details := range chainIdToChainSelector {
key := fmt.Sprintf("%s:%s", details.ChainID, details.Family)
_, exist := chainIDAndFamily[key]
assert.False(t, exist, "ChainID within single family should be unique. chainID %s is duplicated for family", details.ChainID, details.Family)
chainIDAndFamily[key] = struct{}{}
}
}

func TestNoOverlapBetweenRealAndTestChains(t *testing.T) {
for k, _ := range selectorsMap {
_, exist := testSelectorsMap[k]
Expand Down Expand Up @@ -166,7 +177,7 @@ func Test_ChainNames(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
chainId, err1 := ChainIdFromNameAndFamily(test.chainName, "")
chainId, err1 := ChainIdFromName(test.chainName)
selector, err2 := SelectorFromChainIdAndFamily(chainId, "")
if test.expectErr {
require.Error(t, err1)
Expand Down

0 comments on commit 3c0ed77

Please sign in to comment.