From a09cf07d19cb3b683ab21e89c846082e44efa241 Mon Sep 17 00:00:00 2001 From: asoliman Date: Wed, 10 Jul 2024 10:11:15 +0400 Subject: [PATCH] Assert SendRequested Event was emitted --- .../plugins/ccip_integration_tests/helpers.go | 34 ++++++++++++++++++- .../ccip_integration_tests/ping_pong_test.go | 19 ++++++++--- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/core/services/ocr3/plugins/ccip_integration_tests/helpers.go b/core/services/ocr3/plugins/ccip_integration_tests/helpers.go index 932283cb5a..5e1af5d5b0 100644 --- a/core/services/ocr3/plugins/ccip_integration_tests/helpers.go +++ b/core/services/ocr3/plugins/ccip_integration_tests/helpers.go @@ -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" @@ -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" @@ -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" @@ -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 @@ -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, @@ -82,6 +89,7 @@ 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 { @@ -89,6 +97,20 @@ func deployContracts( 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) + require.NoError(t, lp.Start(context.Background())) + t.Cleanup(func() { require.NoError(t, lp.Close()) }) + // contracts to deploy: // 0. link token // 1. onramp @@ -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, @@ -217,6 +248,7 @@ func deployContracts( universes[chainID] = onchainUniverse{ backend: backend, chainID: chainID, + logPoller: lp, linkToken: linkToken, weth: weth, router: rout, 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 638002ab14..f1b0944d41 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 @@ -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" @@ -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{ { @@ -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) } } } @@ -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,