Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Test_GetChainFeePriceUpdates #15240

Open
wants to merge 5 commits into
base: ccipreader-tests
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions contracts/.changeset/odd-maps-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/contracts': minor
---

#added new test utility for gas prices
14 changes: 14 additions & 0 deletions contracts/src/v0.8/ccip/test/helpers/CCIPReaderTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {OnRamp} from "../../onRamp/OnRamp.sol";
/// @dev test contract to test CCIPReader functionality, never deployed to real chains.
contract CCIPReaderTester {
mapping(uint64 sourceChainSelector => OffRamp.SourceChainConfig sourceChainConfig) internal s_sourceChainConfigs;
mapping(uint64 destChainSelector => Internal.TimestampedPackedUint224) internal s_destChainGasPrice;
mapping(uint64 destChainSelector => uint64 sequenceNumber) internal s_destChainSeqNrs;
mapping(uint64 sourceChainSelector => mapping(bytes sender => uint64 nonce)) internal s_senderNonce;

Expand Down Expand Up @@ -52,6 +53,19 @@ contract CCIPReaderTester {
s_sourceChainConfigs[sourceChainSelector] = sourceChainConfig;
}

function getDestinationChainGasPrice(
uint64 destChainSelector
) external view returns (Internal.TimestampedPackedUint224 memory) {
return s_destChainGasPrice[destChainSelector];
}

function setDestinationChainGasPrice(
uint64 destChainSelector,
Internal.TimestampedPackedUint224 memory gasPrice
) external {
s_destChainGasPrice[destChainSelector] = gasPrice;
}

function emitCCIPMessageSent(uint64 destChainSelector, Internal.EVM2AnyRampMessage memory message) external {
emit OnRamp.CCIPMessageSent(destChainSelector, message.header.sequenceNumber, message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"context"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter"
"math/big"
"sort"
"testing"
Expand Down Expand Up @@ -479,6 +480,82 @@
}
}

func Test_GetChainFeePriceUpdates(t *testing.T) {
ctx := testutils.Context(t)
cfg := evmtypes.ChainReaderConfig{
Contracts: map[string]evmtypes.ChainContractReader{
consts.ContractNameFeeQuoter: {
//ContractABI: ccip_reader_tester.CCIPReaderTesterABI,
ContractABI: fee_quoter.FeeQuoterABI,
Configs: map[string]*evmtypes.ChainReaderDefinition{
consts.MethodNameGetFeePriceUpdate: {
ChainSpecificName: "getDestinationChainGasPrice",
ReadType: evmtypes.Method,
},
},
},
},
}

// Notice that the reader chain is the same as the destination chain.
s := testSetup(ctx, t, chainD, chainD, nil, cfg, nil)
linkAddress := utils.RandomAddress()
wethAddress := utils.RandomAddress()
_, _, feeQuoter, err := fee_quoter.DeployFeeQuoter(
s.auth,
s.sb.Client(),
fee_quoter.FeeQuoterStaticConfig{
MaxFeeJuelsPerMsg: big.NewInt(0).Mul(big.NewInt(2e2), big.NewInt(1e18)),
LinkToken: linkAddress,
TokenPriceStalenessThreshold: uint32(24 * 60 * 60),
},
[]common.Address{s.auth.From},
[]common.Address{wethAddress, linkAddress},
[]fee_quoter.FeeQuoterTokenPriceFeedUpdate{},
[]fee_quoter.FeeQuoterTokenTransferFeeConfigArgs{},
[]fee_quoter.FeeQuoterPremiumMultiplierWeiPerEthArgs{
{
PremiumMultiplierWeiPerEth: 9e17, // 0.9 ETH
Token: linkAddress,
},
{
PremiumMultiplierWeiPerEth: 1e18,
Token: wethAddress,
},
},
[]fee_quoter.FeeQuoterDestChainConfigArgs{},
)

require.NoError(t, err)
s.sb.Commit()

_, err = feeQuoter.UpdatePrices(

Check failure on line 532 in core/capabilities/ccip/ccip_integration_tests/ccipreader/ccipreader_test.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)
s.auth, fee_quoter.InternalPriceUpdates{
GasPriceUpdates: []fee_quoter.InternalGasPriceUpdate{
{
DestChainSelector: uint64(chainS1),
UsdPerUnitGas: big.NewInt(100),
},
}},
)

//timestamp := time.Now().Unix()

Check failure on line 542 in core/capabilities/ccip/ccip_integration_tests/ccipreader/ccipreader_test.go

View workflow job for this annotation

GitHub Actions / lint

commentFormatting: put a space between `//` and comment text (gocritic)
//_, err = s.contract.SetDestinationChainGasPrice(
// s.auth,
// uint64(chainS1), // Setting chainS1's gas price
// ccip_reader_tester.InternalTimestampedPackedUint224{
// Value: big.NewInt(100),
// Timestamp: uint32(timestamp),
// })
//require.NoError(t, err)
//s.sb.Commit()

updates := s.reader.GetChainFeePriceUpdate(ctx, []cciptypes.ChainSelector{chainS1})
assert.Len(t, updates, 1)
assert.Equal(t, big.NewInt(100), updates[chainS1].Value.Int)
//assert.Equal(t, time.Unix(timestamp, 0), updates[chainS1].Timestamp)

Check failure on line 556 in core/capabilities/ccip/ccip_integration_tests/ccipreader/ccipreader_test.go

View workflow job for this annotation

GitHub Actions / lint

commentFormatting: put a space between `//` and comment text (gocritic)
}

func testSetup(
ctx context.Context,
t *testing.T,
Expand Down
Loading
Loading