From 038d76b10ca924cb3a8f4553ca7d238afdbfcba3 Mon Sep 17 00:00:00 2001 From: John Saigle <4022790+johnsaigle@users.noreply.github.com> Date: Tue, 30 Jul 2024 10:26:46 -0400 Subject: [PATCH] node/cleanup: Add some documentation and an ignore-list to mainnet_chains_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 --- node/pkg/governor/mainnet_tokens_test.go | 35 ++++++++++++++++++------ 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/node/pkg/governor/mainnet_tokens_test.go b/node/pkg/governor/mainnet_tokens_test.go index 8b5972f955..b4a1d351f6 100644 --- a/node/pkg/governor/mainnet_tokens_test.go +++ b/node/pkg/governor/mainnet_tokens_test.go @@ -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" ) @@ -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 { @@ -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") }) } }