From 37d6bdaa0f28e1bb0682ee7061e3eab2ef4a4b62 Mon Sep 17 00:00:00 2001 From: krehermann Date: Thu, 31 Aug 2023 12:03:58 -0600 Subject: [PATCH] fix test & linter issue with loop variable. (#10426) * fix test & linter issue with loop variable. Change make command be cross platform and remove colons from file names * typo fixes --- GNUmakefile | 2 +- .../relayer_chain_interoperators_test.go | 34 ++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 6ee81eb5036..8b6fd2d2ac4 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -146,7 +146,7 @@ config-docs: ## Generate core node configuration documentation .PHONY: golangci-lint golangci-lint: ## Run golangci-lint for all issues. [ -d "./golangci-lint" ] || mkdir ./golangci-lint && \ - docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.53.2 golangci-lint run --max-issues-per-linter 0 --max-same-issues 0 > ./golangci-lint/$(shell date --iso=seconds).txt + docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.53.2 golangci-lint run --max-issues-per-linter 0 --max-same-issues 0 > ./golangci-lint/$(shell date +%Y-%m-%d_%s).txt GORELEASER_CONFIG ?= .goreleaser.yaml diff --git a/core/services/chainlink/relayer_chain_interoperators_test.go b/core/services/chainlink/relayer_chain_interoperators_test.go index 3a0ce0c7c7d..29dffd1df19 100644 --- a/core/services/chainlink/relayer_chain_interoperators_test.go +++ b/core/services/chainlink/relayer_chain_interoperators_test.go @@ -183,8 +183,9 @@ func TestCoreRelayerChainInteroperators(t *testing.T) { testctx := testutils.Context(t) tests := []struct { - name string - initFuncs []chainlink.CoreRelayerChainInitFunc + name string + initFuncs []chainlink.CoreRelayerChainInitFunc + expectedRelayerNetworks map[relay.Network]struct{} expectedEVMChainCnt int expectedEVMNodeCnt int @@ -220,6 +221,7 @@ func TestCoreRelayerChainInteroperators(t *testing.T) { {Network: relay.EVM, ChainID: relay.ChainID(evmChainID1.String())}, {Network: relay.EVM, ChainID: relay.ChainID(evmChainID2.String())}, }, + expectedRelayerNetworks: map[relay.Network]struct{}{relay.EVM: {}}, }, {name: "2 solana chain with 2 node", @@ -235,6 +237,7 @@ func TestCoreRelayerChainInteroperators(t *testing.T) { {Network: relay.Solana, ChainID: relay.ChainID(solanaChainID1)}, {Network: relay.Solana, ChainID: relay.ChainID(solanaChainID2)}, }, + expectedRelayerNetworks: map[relay.Network]struct{}{relay.Solana: {}}, }, {name: "2 starknet chain with 4 nodes", @@ -250,6 +253,7 @@ func TestCoreRelayerChainInteroperators(t *testing.T) { {Network: relay.StarkNet, ChainID: relay.ChainID(starknetChainID1)}, {Network: relay.StarkNet, ChainID: relay.ChainID(starknetChainID2)}, }, + expectedRelayerNetworks: map[relay.Network]struct{}{relay.StarkNet: {}}, }, { @@ -266,6 +270,7 @@ func TestCoreRelayerChainInteroperators(t *testing.T) { {Network: relay.Cosmos, ChainID: relay.ChainID(cosmosChainID1)}, {Network: relay.Cosmos, ChainID: relay.ChainID(cosmosChainID2)}, }, + expectedRelayerNetworks: map[relay.Network]struct{}{relay.Cosmos: {}}, }, {name: "all chains", @@ -317,9 +322,12 @@ func TestCoreRelayerChainInteroperators(t *testing.T) { {Network: relay.Cosmos, ChainID: relay.ChainID(cosmosChainID1)}, {Network: relay.Cosmos, ChainID: relay.ChainID(cosmosChainID2)}, }, + + expectedRelayerNetworks: map[relay.Network]struct{}{relay.EVM: {}, relay.Cosmos: {}, relay.Solana: {}, relay.StarkNet: {}}, }, } for _, tt := range tests { + tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() cr, err := chainlink.NewCoreRelayerChainInteroperators(tt.initFuncs...) @@ -342,6 +350,7 @@ func TestCoreRelayerChainInteroperators(t *testing.T) { assert.Len(t, allNodeStats, expectedNodeCnt) assert.Equal(t, cnt, len(allNodeStats)) + gotRelayerNetworks := make(map[relay.Network]struct{}) for relayNetwork := range relay.SupportedRelays { var expectedChainCnt, expectedNodeCnt int switch relayNetwork { @@ -359,11 +368,26 @@ func TestCoreRelayerChainInteroperators(t *testing.T) { interops := cr.List(chainlink.FilterRelayersByType(relayNetwork)) assert.Len(t, cr.List(chainlink.FilterRelayersByType(relayNetwork)).Slice(), expectedChainCnt) + if len(interops.Slice()) > 0 { + gotRelayerNetworks[relayNetwork] = struct{}{} + } + + // check legacy chains for those that haven't migrated fully to the loop relayer interface if relayNetwork == relay.EVM { - assert.Len(t, cr.LegacyEVMChains().Slice(), expectedChainCnt) + _, wantEVM := tt.expectedRelayerNetworks[relay.EVM] + if wantEVM { + assert.Len(t, cr.LegacyEVMChains().Slice(), expectedChainCnt) + } else { + assert.Nil(t, cr.LegacyEVMChains()) + } } if relayNetwork == relay.Cosmos { - assert.Len(t, cr.LegacyCosmosChains().Slice(), expectedChainCnt) + _, wantCosmos := tt.expectedRelayerNetworks[relay.Cosmos] + if wantCosmos { + assert.Len(t, cr.LegacyCosmosChains().Slice(), expectedChainCnt) + } else { + assert.Nil(t, cr.LegacyCosmosChains()) + } } nodesStats, cnt, err := interops.NodeStatuses(testctx, 0, 0) @@ -372,6 +396,7 @@ func TestCoreRelayerChainInteroperators(t *testing.T) { assert.Equal(t, cnt, len(nodesStats)) } + assert.EqualValues(t, gotRelayerNetworks, tt.expectedRelayerNetworks) allRelayerIds := [][]relay.ID{ tt.expectedEVMRelayerIds, @@ -410,6 +435,7 @@ func TestCoreRelayerChainInteroperators(t *testing.T) { assert.ErrorIs(t, err, chainlink.ErrNoSuchRelayer) }) + } t.Run("bad init func", func(t *testing.T) {