From 80ada294244b5139b7a758c0ce10be3cb06cc520 Mon Sep 17 00:00:00 2001 From: asoliman Date: Tue, 19 Nov 2024 21:08:04 +0200 Subject: [PATCH 1/2] Test_GetWrappedNativeTokenPriceUSD --- .../ccipreader/ccipreader_test.go | 58 ++++++++++++++++++- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/core/capabilities/ccip/ccip_integration_tests/ccipreader/ccipreader_test.go b/core/capabilities/ccip/ccip_integration_tests/ccipreader/ccipreader_test.go index a76dfc29e7d..2000524b9d9 100644 --- a/core/capabilities/ccip/ccip_integration_tests/ccipreader/ccipreader_test.go +++ b/core/capabilities/ccip/ccip_integration_tests/ccipreader/ccipreader_test.go @@ -3,6 +3,7 @@ package ccipreader import ( "context" "encoding/hex" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" "math/big" "sort" "testing" @@ -56,6 +57,8 @@ var ( defaultGasPrice = assets.GWei(10) InitialLinkPrice = E18Mult(20) InitialWethPrice = E18Mult(4000) + linkAddress = utils.RandomAddress() + wethAddress = utils.RandomAddress() ) func TestCCIPReader_CommitReportsGTETimestamp(t *testing.T) { @@ -520,7 +523,8 @@ func Test_GetChainFeePriceUpdates(t *testing.T) { auth, ) - updates := s.reader.GetChainFeePriceUpdate(ctx, []cciptypes.ChainSelector{chainS1}) + updates := s.reader.GetChainFeePriceUpdate(ctx, []cciptypes.ChainSelector{chainS1, chainS2}) + // only chainS1 has a bound contract require.Len(t, updates, 1) require.Equal(t, defaultGasPrice.ToInt(), updates[chainS1].Value.Int) } @@ -615,9 +619,57 @@ func Test_GetMedianDataAvailabilityGasConfig(t *testing.T) { require.Equal(t, uint16(2), daConfig.DestDataAvailabilityMultiplierBps) } +func Test_GetWrappedNativeTokenPriceUSD(t *testing.T) { + ctx := testutils.Context(t) + sb, auth := setupSimulatedBackendAndAuth(t) + feeQuoter := deployFeeQuoterWithPrices(t, auth, sb, chainS1) + + // Mock the routerContract to return a native token address + routerContract := deployRouterWithNativeToken(t, auth, sb) + + s := testSetup(ctx, t, chainD, chainD, nil, evmconfig.DestReaderConfig, + map[cciptypes.ChainSelector][]types.BoundContract{ + chainD: { + { + Address: feeQuoter.Address().String(), + Name: consts.ContractNameFeeQuoter, + }, + { + Address: routerContract.Address().String(), + Name: consts.ContractNameRouter, + }, + }, + }, + nil, + false, + sb, + auth, + ) + + prices := s.reader.GetWrappedNativeTokenPriceUSD(ctx, []cciptypes.ChainSelector{chainD, chainS1}) + + // Only chainD has reader contracts bound + require.Len(t, prices, 1) + require.Equal(t, InitialWethPrice, prices[chainD].Int) +} + +func deployRouterWithNativeToken(t *testing.T, auth *bind.TransactOpts, sb *simulated.Backend) *router.Router { + address, _, _, err := router.DeployRouter( + auth, + sb.Client(), + wethAddress, + utils.RandomAddress(), // armProxy address + ) + require.NoError(t, err) + sb.Commit() + + routerContract, err := router.NewRouter(address, sb.Client()) + require.NoError(t, err) + + return routerContract +} + func deployFeeQuoterWithPrices(t *testing.T, auth *bind.TransactOpts, sb *simulated.Backend, destChain cciptypes.ChainSelector) *fee_quoter.FeeQuoter { - linkAddress := utils.RandomAddress() - wethAddress := utils.RandomAddress() address, _, _, err := fee_quoter.DeployFeeQuoter( auth, sb.Client(), From 4700031ad406c34c6afcaac26a4e2a8323e11d86 Mon Sep 17 00:00:00 2001 From: asoliman Date: Wed, 20 Nov 2024 14:36:53 +0200 Subject: [PATCH 2/2] linting --- .../ccip/ccip_integration_tests/ccipreader/ccipreader_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/capabilities/ccip/ccip_integration_tests/ccipreader/ccipreader_test.go b/core/capabilities/ccip/ccip_integration_tests/ccipreader/ccipreader_test.go index 2000524b9d9..e333a5e37ae 100644 --- a/core/capabilities/ccip/ccip_integration_tests/ccipreader/ccipreader_test.go +++ b/core/capabilities/ccip/ccip_integration_tests/ccipreader/ccipreader_test.go @@ -3,7 +3,6 @@ package ccipreader import ( "context" "encoding/hex" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" "math/big" "sort" "testing" @@ -34,6 +33,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_reader_tester" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest" "github.com/smartcontractkit/chainlink/v2/core/logger"