Skip to content

Commit

Permalink
Assert SendRequested Event was emitted
Browse files Browse the repository at this point in the history
  • Loading branch information
asoliman92 committed Jul 10, 2024
1 parent c0ec0cb commit a09cf07
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
34 changes: 33 additions & 1 deletion core/services/ocr3/plugins/ccip_integration_tests/helpers.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package ccip_integration_tests

import (
"context"
"math/big"
"testing"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
Expand All @@ -11,6 +13,8 @@ import (
"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/chains/evm/client"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller"
"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 @@ -23,6 +27,8 @@ import (
kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/link_token"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ocr2key"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -51,6 +57,7 @@ type homeChain struct {

type onchainUniverse struct {
backend *backends.SimulatedBackend
logPoller logpoller.LogPollerTest
chainID uint64
linkToken *link_token.LinkToken
weth *weth9.WETH9
Expand All @@ -64,7 +71,7 @@ type onchainUniverse struct {
nonceManager *nonce_manager.NonceManager
}

func deployContracts(
func setupUniverses(
t *testing.T,
owner *bind.TransactOpts,
chains map[uint64]*backends.SimulatedBackend,
Expand All @@ -82,13 +89,28 @@ func deployContracts(
capabilityRegistry, err := kcr.NewCapabilitiesRegistry(addr, homeChainBackend)
require.NoError(t, err)

db := pgtest.NewSqlxDB(t)
// deploy the ccip contracts on the non-home-chain chains (total of 3).
universes = make(map[uint64]onchainUniverse)
for chainID, backend := range chains {
if chainID == homeChainID {
continue
}

lpOpts := logpoller.Opts{
PollPeriod: time.Millisecond,
FinalityDepth: 0,
BackfillBatchSize: 10,
RpcBatchSize: 10,
KeepFinalizedBlocksDepth: 100000,
}
lggr := logger.TestLogger(t)
chainIDBigInt := new(big.Int).SetUint64(chainID)
cl := client.NewSimulatedBackendClient(t, backend, chainIDBigInt)
lp := logpoller.NewLogPoller(logpoller.NewORM(chainIDBigInt, db, lggr), cl, logger.NullLogger, lpOpts)

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

View workflow job for this annotation

GitHub Actions / lint

not enough arguments in call to logpoller.NewLogPoller

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

View workflow job for this annotation

GitHub Actions / Core Tests (go_core_tests)

not enough arguments in call to logpoller.NewLogPoller

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

View workflow job for this annotation

GitHub Actions / Core Tests (go_core_tests)

not enough arguments in call to logpoller.NewLogPoller

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

View workflow job for this annotation

GitHub Actions / Core Tests (go_core_race_tests)

not enough arguments in call to logpoller.NewLogPoller

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

View workflow job for this annotation

GitHub Actions / Core Tests (go_core_race_tests)

not enough arguments in call to logpoller.NewLogPoller
require.NoError(t, lp.Start(context.Background()))
t.Cleanup(func() { require.NoError(t, lp.Close()) })

// contracts to deploy:
// 0. link token
// 1. onramp
Expand Down Expand Up @@ -196,6 +218,15 @@ func deployContracts(
require.NoError(t, err)
backend.Commit()

err = lp.RegisterFilter(testutils.Context(t),
logpoller.Filter{
Name: "CCIPSendRequested",
EventSigs: []common.Hash{
evm_2_evm_multi_onramp.EVM2EVMMultiOnRampCCIPSendRequested{}.Topic(),
}, Addresses: []common.Address{onrampAddr},
})
require.NoError(t, err)

offrampAddr, _, _, err := evm_2_evm_multi_offramp.DeployEVM2EVMMultiOffRamp(
owner,
backend,
Expand All @@ -217,6 +248,7 @@ func deployContracts(
universes[chainID] = onchainUniverse{
backend: backend,
chainID: chainID,
logPoller: lp,
linkToken: linkToken,
weth: weth,
router: rout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (

"github.com/ethereum/go-ethereum/accounts/abi/bind"
chainsel "github.com/smartcontractkit/chain-selectors"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_multi_onramp"
kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"

Expand All @@ -20,7 +22,7 @@ var (
func TestPingPong(t *testing.T) {
owner, chains := createChains(t, 4)

homeChainUni, universes := deployContracts(t, owner, chains)
homeChainUni, universes := setupUniverses(t, owner, chains)
fullyConnectCCIPContracts(t, owner, universes)
_, err := homeChainUni.capabilityRegistry.AddCapabilities(owner, []kcr.CapabilitiesRegistryCapability{
{
Expand All @@ -37,10 +39,20 @@ func TestPingPong(t *testing.T) {
pingPongs := initializePingPongContracts(t, owner, universes)
for chainID, universe := range universes {
for otherChain, pingPong := range pingPongs[chainID] {
println(otherChain)
println("From: ", chainID, " To: ", otherChain)
_, err = pingPong.StartPingPong(owner)
require.NoError(t, err)
universe.backend.Commit()
nCommits := 100
// Give time for the logPoller to catch up
for i := 0; i < nCommits; i++ {
universe.backend.Commit()
}
block, err := universe.logPoller.LatestBlock(testutils.Context(t))
require.NoError(t, err)
logs, err := universe.logPoller.Logs(testutils.Context(t), block.BlockNumber-int64(nCommits), block.BlockNumber,
evm_2_evm_multi_onramp.EVM2EVMMultiOnRampCCIPSendRequested{}.Topic(), universe.onramp.Address())
require.NoError(t, err)
require.Len(t, logs, 1)
}
}
}
Expand Down Expand Up @@ -79,7 +91,6 @@ func initializePingPongContracts(
// Connect each ping pong contract to its counterpart on the other chain
for chainID, universe := range chainUniverses {
for chainToConnect, pingPong := range pingPongs[chainID] {
println("Setting counterpart ping pong contract on chain", chainID, "to chain", chainToConnect)
_, err := pingPong.SetCounterpart(
owner,
chainUniverses[chainToConnect].chainID,
Expand Down

0 comments on commit a09cf07

Please sign in to comment.