Skip to content

Commit

Permalink
Simplify initial configs loop and document it
Browse files Browse the repository at this point in the history
  • Loading branch information
asoliman92 committed Jul 10, 2024
1 parent 92b12f5 commit fffb568
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
35 changes: 19 additions & 16 deletions core/services/ocr3/plugins/ccip_integration_tests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ func setupUniverses(
return homeChainUniverse, universes
}

// setupInitialConfigs sets up the initial configurations for the CCIP contracts for all chains.
// This function has 2 main purposes:
// 1. Set up the capability registry and capability config on the home chain
// 2. Set up the initial configurations for the contracts on the non-home chains
// - configurations involve connecting each chain to all other chains by updating the onRamp, offRamp, Router contracts
// - setting up the price registry with gas prices and token prices
// - setting up the premium multiplier for each token
// - setting up the dynamic config for each onRamp
// - setting up the source chain config for each offRamp
// - setting up the authorized callers for the nonce manager
func setupInitialConfigs(
t *testing.T,
owner *bind.TransactOpts,
Expand All @@ -213,17 +223,7 @@ func setupInitialConfigs(
// Initial configs for contracts on non-home chain
chainIDs := maps.Keys(universes)
for sourceChainID, uni := range universes {
chainsToConnectTo := filter(chainIDs, func(chainIDArg uint64) bool {
return chainIDArg != sourceChainID
})

// we are forming a fully-connected graph, so in each iteration we connect
// the current chain (referenced by sourceChainID) to all other chains that are not
// ourselves.
// To be fully connected we need to update:
// each onRamp with the destChainConfigs for all other chains
// each offRamp with the sourceChainConfigs for all other chains
// the router with the onRamp and offRamp addresses

var (
onrampDestChainConfigArgs []evm_2_evm_multi_onramp.EVM2EVMMultiOnRampDestChainConfigArgs
routerOnrampUpdates []router.RouterOnRamp
Expand All @@ -232,7 +232,10 @@ func setupInitialConfigs(
premiumMultiplierWeiPerEthUpdatesArgs []evm_2_evm_multi_onramp.EVM2EVMMultiOnRampPremiumMultiplierWeiPerEthArgs
priceUpdates price_registry.InternalPriceUpdates
)
for _, destChainID := range chainsToConnectTo {
for _, destChainID := range chainIDs {
if destChainID == sourceChainID {
continue
}
onrampDestChainConfigArgs = append(onrampDestChainConfigArgs, evm_2_evm_multi_onramp.EVM2EVMMultiOnRampDestChainConfigArgs{
DestChainSelector: destChainID,
DynamicConfig: defaultOnRampDynamicConfig(t),
Expand All @@ -242,7 +245,7 @@ func setupInitialConfigs(
require.Truef(t, ok, "could not find universe for chain id %d", destChainID)

offrampSourceChainConfigArgs = append(offrampSourceChainConfigArgs, evm_2_evm_multi_offramp.EVM2EVMMultiOffRampSourceChainConfigArgs{
SourceChainSelector: sourceChainID,
SourceChainSelector: destChainID, // for each destination chain, add a source chain config
IsEnabled: true,
OnRamp: remoteUni.onramp.Address().Bytes(),
})
Expand All @@ -265,8 +268,8 @@ func setupInitialConfigs(
OnRamp: remoteUni.onramp.Address(),
})
routerOfframpUpdates = append(routerOfframpUpdates, router.RouterOffRamp{
SourceChainSelector: sourceChainID,
OffRamp: uni.offramp.Address(),
SourceChainSelector: destChainID,
OffRamp: remoteUni.offramp.Address(),
})

priceUpdates.GasPriceUpdates = append(priceUpdates.GasPriceUpdates,
Expand Down Expand Up @@ -343,7 +346,7 @@ func setupInitialConfigs(
}

func defaultOnRampDynamicConfig(t *testing.T) evm_2_evm_multi_onramp.EVM2EVMMultiOnRampDestChainDynamicConfig {
// https://github.com/smartcontractkit/ccip/blob/integration_test%2Fnew_contracts/contracts/src/v0.8/ccip/libraries/Internal.sol#L337-L337
// https://github.com/smartcontractkit/ccip/blob/c4856b64bd766f1ddbaf5d13b42d3c4b12efde3a/contracts/src/v0.8/ccip/libraries/Internal.sol#L337-L337
/*
```Solidity
// bytes4(keccak256("CCIP ChainFamilySelector EVM"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ func initializePingPongContracts(
backend.Commit()
pingPong, err := pp.NewPingPongDemo(pingPongAddr, backend)
require.NoError(t, err)
universe.backend.Commit()
backend.Commit()
// Fund the ping pong contract with LINK
_, err = universe.linkToken.Transfer(owner, pingPong.Address(), e18Mult(10))
universe.backend.Commit()
backend.Commit()
require.NoError(t, err)
pingPongs[chainID][chainToConnect] = pingPong
}
Expand Down

0 comments on commit fffb568

Please sign in to comment.