From 5761eb297ee2a5c2e145314bdfc80b3a3f600fb2 Mon Sep 17 00:00:00 2001 From: asoliman Date: Thu, 11 Jul 2024 15:59:17 +0400 Subject: [PATCH] Cleaning and simplification round 2 --- .../plugins/ccip_integration_tests/helpers.go | 153 +++++++++--------- .../ccip_integration_tests/ping_pong_test.go | 4 +- 2 files changed, 79 insertions(+), 78 deletions(-) diff --git a/core/services/ocr3/plugins/ccip_integration_tests/helpers.go b/core/services/ocr3/plugins/ccip_integration_tests/helpers.go index a1785186d6..a3a7249088 100644 --- a/core/services/ocr3/plugins/ccip_integration_tests/helpers.go +++ b/core/services/ocr3/plugins/ccip_integration_tests/helpers.go @@ -9,6 +9,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_config" @@ -71,81 +72,17 @@ type chainBase struct { owner *bind.TransactOpts } -func createChains(t *testing.T, numChains int) map[uint64]chainBase { - chains := make(map[uint64]chainBase) - - homeChainOwner := testutils.MustNewSimTransactor(t) - chains[homeChainID] = chainBase{ - owner: homeChainOwner, - backend: backends.NewSimulatedBackend(core.GenesisAlloc{ - homeChainOwner.From: core.GenesisAccount{ - Balance: assets.Ether(10_000).ToInt(), - }, - }, 30e6), - } - - for chainID := chainsel.TEST_90000001.EvmChainID; len(chains) < numChains && chainID < chainsel.TEST_90000020.EvmChainID; chainID++ { - owner := testutils.MustNewSimTransactor(t) - chains[chainID] = chainBase{ - owner: owner, - backend: backends.NewSimulatedBackend(core.GenesisAlloc{ - owner.From: core.GenesisAccount{ - Balance: assets.Ether(10_000).ToInt(), - }, - }, 30e6), - } - } - - return chains -} - -func setupHomeChain(t *testing.T, owner *bind.TransactOpts, backend *backends.SimulatedBackend) homeChain { - // deploy the capability registry on the home chain - addr, _, _, err := kcr.DeployCapabilitiesRegistry(owner, backend) - require.NoError(t, err, "failed to deploy capability registry on home chain") - backend.Commit() - - capabilityRegistry, err := kcr.NewCapabilitiesRegistry(addr, backend) - require.NoError(t, err) - - ccAddress, _, _, err := ccip_config.DeployCCIPConfig(owner, backend, addr) - require.NoError(t, err) - backend.Commit() - - capabilityConfig, err := ccip_config.NewCCIPConfig(ccAddress, backend) - require.NoError(t, err) - - _, err = capabilityRegistry.AddCapabilities(owner, []kcr.CapabilitiesRegistryCapability{ - { - LabelledName: "ccip", - Version: "v1.0.0", - CapabilityType: 2, // consensus. not used (?) - ResponseType: 0, // report. not used (?) - ConfigurationContract: ccAddress, - }, - }) - require.NoError(t, err, "failed to add capabilities to the capability registry") - backend.Commit() - - return homeChain{ - backend: backend, - owner: owner, - chainID: homeChainID, - capabilityRegistry: capabilityRegistry, - ccipConfigContract: capabilityConfig.Address(), - } - -} +// createUniverses does the following: +// 1. Creates 1 home chain and `numChains`-1 non-home chains +// 2. Deploys the CCIP contracts on the home chain and the non-home chains. +// 3. Sets up the initial configurations for the contracts on the non-home chains. +// 4. Wires the chains together. -// setupUniverses does the following: -// 1. deploys the CCIP contracts on the home chain and the non-home chains. -// 2. sets up the initial configurations for the contracts on the non-home chains. -// 3. wires the chains together. -func setupUniverses( +func createUniverses( t *testing.T, - chains map[uint64]chainBase, + numUniverses int, ) (homeChainUni homeChain, universes map[uint64]onchainUniverse) { - require.Len(t, chains, 4, "must have 4 chains total, 1 home chain and 3 non-home-chains") + chains := createChains(t, numUniverses) homeChainBase, ok := chains[homeChainID] require.True(t, ok, "home chain backend not available") @@ -261,6 +198,72 @@ func setupUniverses( return homeChainUniverse, universes } +// Creates 1 home chain and `numChains`-1 non-home chains +func createChains(t *testing.T, numChains int) map[uint64]chainBase { + chains := make(map[uint64]chainBase) + + homeChainOwner := testutils.MustNewSimTransactor(t) + chains[homeChainID] = chainBase{ + owner: homeChainOwner, + backend: backends.NewSimulatedBackend(core.GenesisAlloc{ + homeChainOwner.From: core.GenesisAccount{ + Balance: assets.Ether(10_000).ToInt(), + }, + }, 30e6), + } + + for chainID := chainsel.TEST_90000001.EvmChainID; len(chains) < numChains && chainID < chainsel.TEST_90000020.EvmChainID; chainID++ { + owner := testutils.MustNewSimTransactor(t) + chains[chainID] = chainBase{ + owner: owner, + backend: backends.NewSimulatedBackend(core.GenesisAlloc{ + owner.From: core.GenesisAccount{ + Balance: assets.Ether(10_000).ToInt(), + }, + }, 30e6), + } + } + + return chains +} + +func setupHomeChain(t *testing.T, owner *bind.TransactOpts, backend *backends.SimulatedBackend) homeChain { + // deploy the capability registry on the home chain + addr, _, _, err := kcr.DeployCapabilitiesRegistry(owner, backend) + require.NoError(t, err, "failed to deploy capability registry on home chain") + backend.Commit() + + capabilityRegistry, err := kcr.NewCapabilitiesRegistry(addr, backend) + require.NoError(t, err) + + ccAddress, _, _, err := ccip_config.DeployCCIPConfig(owner, backend, addr) + require.NoError(t, err) + backend.Commit() + + capabilityConfig, err := ccip_config.NewCCIPConfig(ccAddress, backend) + require.NoError(t, err) + + _, err = capabilityRegistry.AddCapabilities(owner, []kcr.CapabilitiesRegistryCapability{ + { + LabelledName: "ccip", + Version: "v1.0.0", + CapabilityType: 2, // consensus. not used (?) + ResponseType: 0, // report. not used (?) + ConfigurationContract: ccAddress, + }, + }) + require.NoError(t, err, "failed to add capabilities to the capability registry") + backend.Commit() + + return homeChain{ + backend: backend, + owner: owner, + chainID: homeChainID, + capabilityRegistry: capabilityRegistry, + ccipConfigContract: capabilityConfig.Address(), + } +} + func connectUniverses( t *testing.T, universes map[uint64]onchainUniverse, @@ -338,7 +341,7 @@ func wireRouter(t *testing.T, uni onchainUniverse, universes map[uint64]onchainU routerOnrampUpdates []router.RouterOnRamp routerOfframpUpdates []router.RouterOffRamp ) - for remoteChainID, _ := range universes { + for remoteChainID := range universes { if remoteChainID == uni.chainID { continue } @@ -360,7 +363,7 @@ func wireRouter(t *testing.T, uni onchainUniverse, universes map[uint64]onchainU func wireOnRamp(t *testing.T, uni onchainUniverse, universes map[uint64]onchainUniverse) { owner := uni.owner var onrampDestChainConfigArgs []evm_2_evm_multi_onramp.EVM2EVMMultiOnRampDestChainConfigArgs - for remoteChainID, _ := range universes { + for remoteChainID := range universes { if remoteChainID == uni.chainID { continue } @@ -396,7 +399,7 @@ func wireOffRamp(t *testing.T, uni onchainUniverse, universes map[uint64]onchain // initRemoteChainsGasPrices sets the gas prices for all chains except the local chain in the local price registry func initRemoteChainsGasPrices(t *testing.T, uni onchainUniverse, universes map[uint64]onchainUniverse) { var gasPriceUpdates []price_registry.InternalGasPriceUpdate - for remoteChainID, _ := range universes { + for remoteChainID := range universes { if remoteChainID == uni.chainID { continue } diff --git a/core/services/ocr3/plugins/ccip_integration_tests/ping_pong_test.go b/core/services/ocr3/plugins/ccip_integration_tests/ping_pong_test.go index b8be3261b9..df00e282b1 100644 --- a/core/services/ocr3/plugins/ccip_integration_tests/ping_pong_test.go +++ b/core/services/ocr3/plugins/ccip_integration_tests/ping_pong_test.go @@ -22,9 +22,7 @@ import ( * Test fails if any wiring between contracts is not correct. */ func TestPingPong(t *testing.T) { - chains := createChains(t, 4) - - _, universes := setupUniverses(t, chains) + _, universes := createUniverses(t, 4) pingPongs := initializePingPongContracts(t, universes) for chainID, universe := range universes { for otherChain, pingPong := range pingPongs[chainID] {