Skip to content

Commit

Permalink
Cleaning and simplification round 2
Browse files Browse the repository at this point in the history
  • Loading branch information
asoliman92 committed Jul 11, 2024
1 parent b98ce47 commit e037726
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 76 deletions.
147 changes: 74 additions & 73 deletions core/services/ocr3/plugins/ccip_integration_tests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -71,81 +72,15 @@ 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(),
}

}

// setupUniverses does the following:
// createUniverses 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")
Expand Down Expand Up @@ -261,6 +196,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,
Expand Down Expand Up @@ -338,7 +339,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
}
Expand All @@ -360,7 +361,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
}
Expand Down Expand Up @@ -396,7 +397,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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down

0 comments on commit e037726

Please sign in to comment.