Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
asoliman92 committed Jul 8, 2024
1 parent 2f702cc commit 0fd5d5e
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 213 deletions.
72 changes: 48 additions & 24 deletions core/services/ocr3/plugins/ccip_integration_tests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/jmoiron/sqlx"
chainsel "github.com/smartcontractkit/chain-selectors"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/arm_proxy_contract"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_multi_offramp"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_multi_onramp"
Expand All @@ -28,13 +30,13 @@ import (
)

var (
homeChainID = int64(chainsel.GETH_TESTNET.EvmChainID)
homeChainID = chainsel.GETH_TESTNET.EvmChainID
)

type ocr3Node struct {
app chainlink.Application
peerID string
transmitters map[int64]common.Address
transmitters map[uint64]common.Address
keybundle ocr2key.KeyBundle
db *sqlx.DB
}
Expand Down Expand Up @@ -63,8 +65,8 @@ type onchainUniverse struct {
func deployContracts(
t *testing.T,
owner *bind.TransactOpts,
chains map[int64]*backends.SimulatedBackend,
) (homeChainUni homeChain, universes map[int64]onchainUniverse) {
chains map[uint64]*backends.SimulatedBackend,
) (homeChainUni homeChain, universes map[uint64]onchainUniverse) {
require.Len(t, chains, 4, "must have 4 chains total, 1 home chain and 3 non-home-chains")

// deploy the capability registry on the home chain
Expand All @@ -79,7 +81,7 @@ func deployContracts(
require.NoError(t, err)

// deploy the ccip contracts on the non-home-chain chains (total of 3).
universes = make(map[int64]onchainUniverse)
universes = make(map[uint64]onchainUniverse)
for chainID, backend := range chains {
if chainID == homeChainID {
continue
Expand Down Expand Up @@ -220,36 +222,34 @@ func deployContracts(

return homeChain{
backend: homeChainBackend,
chainID: uint64(homeChainID),
chainID: homeChainID,
capabilityRegistry: capabilityRegistry,
}, universes
}

func fullyConnectCCIPContracts(
t *testing.T,
owner *bind.TransactOpts,
universes map[int64]onchainUniverse,
universes map[uint64]onchainUniverse,
) {
chainIDs := maps.Keys(universes)
for chainID, uni := range universes {
chainsToConnectTo := filter(chainIDs, func(chainIDArg int64) bool {
return chainIDArg != chainID
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 chainID) to all other chains that are not
// the current chain (referenced by sourceChainID) to all other chains that are not
// ourselves.
var (
onrampDestChainConfigArgs []evm_2_evm_multi_onramp.EVM2EVMMultiOnRampDestChainConfigArgs
routerOnrampUpdates []router.RouterOnRamp
routerOfframpUpdates []router.RouterOffRamp
offrampSourceChainConfigArgs []evm_2_evm_multi_offramp.EVM2EVMMultiOffRampSourceChainConfigArgs
)
for _, chainToConnect := range chainsToConnectTo {
chainSelector, ok := chainsel.EvmChainIdToChainSelector()[uint64(chainToConnect)]
require.Truef(t, ok, "chain selector not found for chain id %d", chainToConnect)
for _, destChainID := range chainsToConnectTo {
onrampDestChainConfigArgs = append(onrampDestChainConfigArgs, evm_2_evm_multi_onramp.EVM2EVMMultiOnRampDestChainConfigArgs{
DestChainSelector: chainSelector,
DestChainSelector: destChainID,
DynamicConfig: evm_2_evm_multi_onramp.EVM2EVMMultiOnRampDestChainDynamicConfig{
IsEnabled: true,
MaxNumberOfTokensPerMsg: 10,
Expand All @@ -269,37 +269,37 @@ func fullyConnectCCIPContracts(
},
})

remoteUni, ok := universes[chainID]
require.Truef(t, ok, "could not find universe for chain id %d", chainID)
remoteUni, ok := universes[destChainID]
require.Truef(t, ok, "could not find universe for chain id %d", destChainID)

offrampSourceChainConfigArgs = append(offrampSourceChainConfigArgs, evm_2_evm_multi_offramp.EVM2EVMMultiOffRampSourceChainConfigArgs{
SourceChainSelector: chainSelector,
SourceChainSelector: sourceChainID,
IsEnabled: true,
OnRamp: remoteUni.onramp.Address(),

Check failure on line 278 in core/services/ocr3/plugins/ccip_integration_tests/helpers.go

View workflow job for this annotation

GitHub Actions / lint

cannot use remoteUni.onramp.Address() (value of type "github.com/ethereum/go-ethereum/common".Address) as []byte value in struct literal

Check failure on line 278 in core/services/ocr3/plugins/ccip_integration_tests/helpers.go

View workflow job for this annotation

GitHub Actions / Core Tests (go_core_tests)

cannot use remoteUni.onramp.Address() (value of type "github.com/ethereum/go-ethereum/common".Address) as []byte value in struct literal

Check failure on line 278 in core/services/ocr3/plugins/ccip_integration_tests/helpers.go

View workflow job for this annotation

GitHub Actions / Core Tests (go_core_tests)

cannot use remoteUni.onramp.Address() (value of type "github.com/ethereum/go-ethereum/common".Address) as []byte value in struct literal

Check failure on line 278 in core/services/ocr3/plugins/ccip_integration_tests/helpers.go

View workflow job for this annotation

GitHub Actions / Core Tests (go_core_race_tests)

cannot use remoteUni.onramp.Address() (value of type "github.com/ethereum/go-ethereum/common".Address) as []byte value in struct literal

Check failure on line 278 in core/services/ocr3/plugins/ccip_integration_tests/helpers.go

View workflow job for this annotation

GitHub Actions / Core Tests (go_core_race_tests)

cannot use remoteUni.onramp.Address() (value of type "github.com/ethereum/go-ethereum/common".Address) as []byte value in struct literal
})

// onramps are multi-dest and offramps are multi-source.
// so set the same ramp for all the chain selectors.
routerOnrampUpdates = append(routerOnrampUpdates, router.RouterOnRamp{
DestChainSelector: chainSelector,
OnRamp: uni.onramp.Address(),
DestChainSelector: destChainID,
OnRamp: remoteUni.onramp.Address(),
})
routerOfframpUpdates = append(routerOfframpUpdates, router.RouterOffRamp{
SourceChainSelector: chainSelector,
SourceChainSelector: sourceChainID,
OffRamp: uni.offramp.Address(),
})
}

_, err := uni.onramp.ApplyDestChainConfigUpdates(owner, onrampDestChainConfigArgs)
require.NoErrorf(t, err, "failed to apply dest chain config updates on onramp on chain id %d", chainID)
require.NoErrorf(t, err, "failed to apply dest chain config updates on onramp on chain id %d", sourceChainID)
uni.backend.Commit()

_, err = uni.offramp.ApplySourceChainConfigUpdates(owner, offrampSourceChainConfigArgs)
require.NoErrorf(t, err, "failed to apply source chain config updates on offramp on chain id %d", chainID)
require.NoErrorf(t, err, "failed to apply source chain config updates on offramp on chain id %d", sourceChainID)
uni.backend.Commit()

_, err = uni.router.ApplyRampUpdates(owner, routerOnrampUpdates, []router.RouterOffRamp{}, routerOfframpUpdates)
require.NoErrorf(t, err, "failed to apply ramp updates on router on chain id %d", chainID)
require.NoErrorf(t, err, "failed to apply ramp updates on router on chain id %d", sourceChainID)
uni.backend.Commit()
}
}
Expand All @@ -312,3 +312,27 @@ func filter[T any](s []T, cond func(arg T) bool) (r []T) {
}
return
}

func createChains(t *testing.T, numChains int) (owner *bind.TransactOpts, chains map[uint64]*backends.SimulatedBackend) {
owner = testutils.MustNewSimTransactor(t)
chains = make(map[uint64]*backends.SimulatedBackend)

chains[homeChainID] = backends.NewSimulatedBackend(core.GenesisAlloc{
owner.From: core.GenesisAccount{
Balance: assets.Ether(10_000).ToInt(),
},
}, 30e6)

for chainID := uint64(chainsel.TEST_90000001.EvmChainID); chainID < uint64(chainsel.TEST_90000020.EvmChainID); chainID++ {
chains[chainID] = backends.NewSimulatedBackend(core.GenesisAlloc{
owner.From: core.GenesisAccount{
Balance: assets.Ether(10000).ToInt(),
},
}, 30e6)

if len(chains) == numChains {
break
}
}
return
}
47 changes: 13 additions & 34 deletions core/services/ocr3/plugins/ccip_integration_tests/helpers_old.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
gethtypes "github.com/ethereum/go-ethereum/core/types"
chainsel "github.com/smartcontractkit/chain-selectors"
"github.com/smartcontractkit/chainlink-common/pkg/config"
Expand Down Expand Up @@ -44,7 +43,7 @@ func setupNodeOCR3(
t *testing.T,
owner *bind.TransactOpts,
port int,
chainIDToBackend map[int64]*backends.SimulatedBackend,
chainIDToBackend map[uint64]*backends.SimulatedBackend,
) *ocr3Node {
// Do not want to load fixtures as they contain a dummy chainID.
config, db := heavyweight.FullTestDBNoFixturesV2(t, func(c *chainlink.Config, s *chainlink.Secrets) {
Expand All @@ -70,7 +69,7 @@ func setupNodeOCR3(

var chains v2toml.EVMConfigs
for chainID := range chainIDToBackend {
chains = append(chains, createConfigV2Chain(big.NewInt(chainID)))
chains = append(chains, createConfigV2Chain(big.NewInt(int64(chainID))))
}
c.EVM = chains
c.OCR2.ContractPollInterval = config.MustNewDuration(5 * time.Second)
Expand All @@ -79,10 +78,12 @@ func setupNodeOCR3(
lggr := logger.TestLogger(t)
lggr.SetLogLevel(zapcore.InfoLevel)
ctx := testutils.Context(t)
clients := make(map[int64]client.Client)
clients := make(map[uint64]client.Client)

for chainID, backend := range chainIDToBackend {
clients[chainID] = client.NewSimulatedBackendClient(t, backend, big.NewInt(chainID))
cID := big.Int{}
cID.SetUint64(chainID)
clients[chainID] = client.NewSimulatedBackendClient(t, backend, &cID)
}

master := keystore.New(db, utils.FastScryptParams, lggr)
Expand All @@ -100,7 +101,7 @@ func setupNodeOCR3(
AppConfig: config,
GenEthClient: func(i *big.Int) client.Client {
t.Log("genning eth client for chain id:", i.String())
client, ok := clients[i.Int64()]
client, ok := clients[i.Uint64()]
if !ok {
t.Fatal("no backend for chainID", i)
}
Expand Down Expand Up @@ -145,19 +146,21 @@ func setupNodeOCR3(
peerID := p2pIDs[0].PeerID()

// create a transmitter for each chain
transmitters := make(map[int64]common.Address)
transmitters := make(map[uint64]common.Address)
for chainID, backend := range chainIDToBackend {
addrs, err2 := app.GetKeyStore().Eth().EnabledAddressesForChain(testutils.Context(t), big.NewInt(chainID))
var cID big.Int
cID.SetUint64(chainID)
addrs, err2 := app.GetKeyStore().Eth().EnabledAddressesForChain(testutils.Context(t), &cID)
require.NoError(t, err2)
if len(addrs) == 1 {
// just fund the address
fundAddress(t, owner, addrs[0], assets.Ether(10).ToInt(), backend)
transmitters[chainID] = addrs[0]
} else {
// create key and fund it
_, err3 := app.GetKeyStore().Eth().Create(testutils.Context(t), big.NewInt(chainID))
_, err3 := app.GetKeyStore().Eth().Create(testutils.Context(t), &cID)
require.NoError(t, err3, "failed to create key for chain", chainID)
sendingKeys, err3 := app.GetKeyStore().Eth().EnabledAddressesForChain(testutils.Context(t), big.NewInt(chainID))
sendingKeys, err3 := app.GetKeyStore().Eth().EnabledAddressesForChain(testutils.Context(t), &cID)
require.NoError(t, err3)
require.Len(t, sendingKeys, 1)
fundAddress(t, owner, sendingKeys[0], assets.Ether(10).ToInt(), backend)
Expand All @@ -180,30 +183,6 @@ func setupNodeOCR3(
}
}

func createChains(t *testing.T, numChains int) (owner *bind.TransactOpts, chains map[int64]*backends.SimulatedBackend) {
owner = testutils.MustNewSimTransactor(t)
chains = make(map[int64]*backends.SimulatedBackend)

chains[homeChainID] = backends.NewSimulatedBackend(core.GenesisAlloc{
owner.From: core.GenesisAccount{
Balance: assets.Ether(10_000).ToInt(),
},
}, 30e6)

for chainID := int64(chainsel.TEST_90000001.EvmChainID); chainID < int64(chainsel.TEST_90000020.EvmChainID); chainID++ {
chains[chainID] = backends.NewSimulatedBackend(core.GenesisAlloc{
owner.From: core.GenesisAccount{
Balance: assets.Ether(10000).ToInt(),
},
}, 30e6)

if len(chains) == numChains {
break
}
}
return
}

func ptr[T any](v T) *T { return &v }

var _ keystore.Eth = &EthKeystoreSim{}
Expand Down
Loading

0 comments on commit 0fd5d5e

Please sign in to comment.