Skip to content

Commit

Permalink
node/cleanup: Add some documentation and an ignore-list to mainnet_ch…
Browse files Browse the repository at this point in the history
…ains_test.go (#4038)

* node: Add test to ensure that governed chains also have governed assets

* node: Update test that checks if governed chains have governed assets

- Verify tokens against the Governor's mainnet chains rather than
  querying against the values configured in the SDK. (These should be
  the same but it avoid a package import and ties in more closely to the
  Governor's functionality.)
- Add test message on failure to help with debugging
- Remove outdated exceptions to existing the unit test
- Merge test from previous commit into a similar unit test that already
  existed

* node: Revert chainList() so that its scope is private
  • Loading branch information
johnsaigle authored Jul 30, 2024
1 parent 30e4042 commit 038d76b
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions node/pkg/governor/mainnet_tokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package governor

import (
"fmt"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/wormhole-foundation/wormhole/sdk"
"github.com/wormhole-foundation/wormhole/sdk/vaa"
)

Expand Down Expand Up @@ -33,11 +33,33 @@ func TestTokenListAddressSize(t *testing.T) {
}
}

func TestTokenListChainTokensPresent(t *testing.T) {
// Flag a situation where a Governed chain does not have any governed assets. Often times when adding a mainnet chain,
// a list of tokens will be added so that they can be governed. (These tokens are sourced by CoinGecko or manually
// populated.) While this is not a hard requirement, it may represent that a developer has forgotten to take the step
// of configuring tokens when deploying the chain. This test helps to remind them.
func TestGovernedChainHasGovernedAssets(t *testing.T) {

// Add a chain ID to this set if it genuinely has no native assets that should be governed.
ignoredChains := map[vaa.ChainID]bool{
// Wormchain is an abstraction over IBC-connected chains so no assets are "native" to it
vaa.ChainIDWormchain: true,
}
if len(ignoredChains) > 0 {
ignoredOutput := []string{}
for id := range ignoredChains {
ignoredOutput = append(ignoredOutput, id.String())
}

t.Logf("This test ignored the following chains: %s\n", strings.Join(ignoredOutput, "\n"))
}

tokenConfigEntries := tokenList()

/* Assume that all chains within a token bridge will have governed tokens */
for e := range sdk.KnownTokenbridgeEmitters {
for _, chainConfigEntry := range chainList() {
e := chainConfigEntry.emitterChainID
if _, ignored := ignoredChains[e]; ignored {
return
}
t.Run(e.String(), func(t *testing.T) {
found := false
for _, tokenConfigEntry := range tokenConfigEntries {
Expand All @@ -46,10 +68,7 @@ func TestTokenListChainTokensPresent(t *testing.T) {
break
}
}

if e != vaa.ChainIDXpla && e != vaa.ChainIDAptos && e != vaa.ChainIDArbitrum && e != vaa.ChainIDWormchain {
assert.Equal(t, found, true)
}
assert.True(t, found, "Chain is governed but has no governed native assets configured")
})
}
}
Expand Down

0 comments on commit 038d76b

Please sign in to comment.