Skip to content

Commit

Permalink
Fixing merge changes for family agnostic messages
Browse files Browse the repository at this point in the history
  • Loading branch information
asoliman92 committed Jul 10, 2024
1 parent 9fa9dbd commit 0c6a9a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 57 deletions.
53 changes: 8 additions & 45 deletions core/services/ocr3/plugins/ccip_integration_tests/helpers.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package ccip_integration_tests

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

"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/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 @@ -27,8 +23,6 @@ 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/stretchr/testify/require"
"golang.org/x/exp/maps"
)
Expand All @@ -53,7 +47,6 @@ type homeChain struct {

type onchainUniverse struct {
backend *backends.SimulatedBackend
logPoller logpoller.LogPollerTest
chainID uint64
linkToken *link_token.LinkToken
weth *weth9.WETH9
Expand Down Expand Up @@ -90,7 +83,6 @@ func setupUniverses(
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)

Expand Down Expand Up @@ -161,7 +153,6 @@ func setupUniverses(
universes[chainID] = onchainUniverse{
backend: backend,
chainID: chainID,
logPoller: createLogPoller(t, backend, db, chainID),
linkToken: linkToken,
weth: weth,
router: rout,
Expand Down Expand Up @@ -227,7 +218,7 @@ func setupInitialConfigs(
for _, destChainID := range chainsToConnectTo {
onrampDestChainConfigArgs = append(onrampDestChainConfigArgs, evm_2_evm_multi_onramp.EVM2EVMMultiOnRampDestChainConfigArgs{
DestChainSelector: destChainID,
DynamicConfig: defaultOnRampDynamicConfig(),
DynamicConfig: defaultOnRampDynamicConfig(t),
})

remoteUni, ok := universes[destChainID]
Expand All @@ -236,7 +227,7 @@ func setupInitialConfigs(
offrampSourceChainConfigArgs = append(offrampSourceChainConfigArgs, evm_2_evm_multi_offramp.EVM2EVMMultiOffRampSourceChainConfigArgs{
SourceChainSelector: sourceChainID,
IsEnabled: true,
OnRamp: remoteUni.onramp.Address(),
OnRamp: remoteUni.onramp.Address().Bytes(),
})

// 1e18 Jule = 1 LINK
Expand Down Expand Up @@ -318,13 +309,13 @@ func setupInitialConfigs(
require.NoError(t, err)
uni.backend.Commit()
//=============================================================================
//===========================RegisterPollerFilters============================
registerPollerFilters(t, uni)
//=============================================================================
}
}

func defaultOnRampDynamicConfig() evm_2_evm_multi_onramp.EVM2EVMMultiOnRampDestChainDynamicConfig {
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
evmFamilySelector, err := hex.DecodeString("2812d52c")
require.NoError(t, err)
return evm_2_evm_multi_onramp.EVM2EVMMultiOnRampDestChainDynamicConfig{
IsEnabled: true,
MaxNumberOfTokensPerMsg: 10,
Expand All @@ -341,6 +332,7 @@ func defaultOnRampDynamicConfig() evm_2_evm_multi_onramp.EVM2EVMMultiOnRampDestC
DefaultTxGasLimit: 200_000,
GasMultiplierWeiPerEth: 1,
NetworkFeeUSDCents: 1,
ChainFamilySelector: [4]byte(evmFamilySelector),
}
}

Expand Down Expand Up @@ -377,35 +369,6 @@ func createChains(t *testing.T, numChains int) (owner *bind.TransactOpts, chains
return
}

func createLogPoller(t *testing.T, backend *backends.SimulatedBackend, db *sqlx.DB, chainID uint64) logpoller.LogPollerTest {
lpOpts := logpoller.Opts{
PollPeriod: time.Millisecond,
FinalityDepth: 0,
BackfillBatchSize: 10,
RpcBatchSize: 10,
KeepFinalizedBlocksDepth: 100000,
}
lggr := logger.TestLogger(t)
chainIDBigInt := UintBigInt(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()) })
return lp
}

// We can add as many filters needed for the tests here.
func registerPollerFilters(t *testing.T, universe onchainUniverse) {
err := universe.logPoller.RegisterFilter(testutils.Context(t),
logpoller.Filter{
Name: "CCIPSendRequested",
EventSigs: []common.Hash{
evm_2_evm_multi_onramp.EVM2EVMMultiOnRampCCIPSendRequested{}.Topic(),
}, Addresses: []common.Address{universe.onramp.Address()},
})
require.NoError(t, err)
}

func deployLinkToken(t *testing.T, owner *bind.TransactOpts, backend *backends.SimulatedBackend, chainID uint64) *link_token.LinkToken {
linkAddr, _, _, err := link_token.DeployLinkToken(owner, backend)
require.NoErrorf(t, err, "failed to deploy link token on chain id %d", chainID)
Expand Down
23 changes: 11 additions & 12 deletions core/services/ocr3/plugins/ccip_integration_tests/ping_pong_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package ccip_integration_tests

import (
"bytes"
"testing"

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

Expand All @@ -24,17 +23,17 @@ func TestPingPong(t *testing.T) {
println("PingPong From: ", chainID, " To: ", otherChain)
_, err := pingPong.StartPingPong(owner)
require.NoError(t, err)
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())
universe.backend.Commit()

logIter, err := universe.onramp.FilterCCIPSendRequested(&bind.FilterOpts{Start: 0}, nil)
require.NoError(t, err)
require.Len(t, logs, 1)
// Iterate until latest event
for logIter.Next() {
}
log := logIter.Event
require.Equal(t, log.DestChainSelector, otherChain)
require.Equal(t, log.Message.Sender, pingPong.Address())
require.Equal(t, bytes.TrimLeft(log.Message.Receiver, "\x00"), pingPongs[otherChain][chainID].Address().Bytes())
}
}
}
Expand Down

0 comments on commit 0c6a9a4

Please sign in to comment.