diff --git a/integration-tests/deployment/ccip/changeset/initial_deploy_test.go b/integration-tests/deployment/ccip/changeset/initial_deploy_test.go index 280147f463c..704481f60ff 100644 --- a/integration-tests/deployment/ccip/changeset/initial_deploy_test.go +++ b/integration-tests/deployment/ccip/changeset/initial_deploy_test.go @@ -99,7 +99,10 @@ func TestInitialDeploy(t *testing.T) { // Wait for all commit reports to land. ccdeploy.ConfirmCommitForAllWithExpectedSeqNums(t, e, state, expectedSeqNum, startBlocks) - // TODO: use proper assertions to check gas and token prices using events + + // Confirm token and gas prices are updated + ccdeploy.ConfirmTokenPriceUpdatedForAll(t, e, state, startBlocks) + ccdeploy.ConfirmGasPriceUpdatedForAll(t, e, state, startBlocks) // Wait for all exec reports to land ccdeploy.ConfirmExecWithSeqNrForAll(t, e, state, expectedSeqNum, startBlocks) diff --git a/integration-tests/deployment/ccip/test_assertions.go b/integration-tests/deployment/ccip/test_assertions.go index 91bd0550545..1f805cbd209 100644 --- a/integration-tests/deployment/ccip/test_assertions.go +++ b/integration-tests/deployment/ccip/test_assertions.go @@ -2,10 +2,14 @@ package ccipdeployment import ( "context" + "fmt" + "math/big" "testing" "time" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" "github.com/stretchr/testify/require" @@ -14,9 +18,128 @@ import ( "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3" "github.com/smartcontractkit/chainlink/integration-tests/deployment" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/offramp" ) +func ConfirmGasPriceUpdatedForAll( + t *testing.T, + e deployment.Environment, + state CCIPOnChainState, + startBlocks map[uint64]*uint64, +) { + var wg errgroup.Group + for src, srcChain := range e.Chains { + for dest, dstChain := range e.Chains { + if src == dest { + continue + } + srcChain := srcChain + dstChain := dstChain + wg.Go(func() error { + var startBlock *uint64 + if startBlocks != nil { + startBlock = startBlocks[srcChain.Selector] + } + return ConfirmGasPriceUpdated( + t, + dstChain, + state.Chains[srcChain.Selector].FeeQuoter, + *startBlock, + ) + }) + } + } + require.NoError(t, wg.Wait()) +} + +func ConfirmGasPriceUpdated( + t *testing.T, + dest deployment.Chain, + srcFeeQuoter *fee_quoter.FeeQuoter, + startBlock uint64, +) error { + it, err := srcFeeQuoter.FilterUsdPerUnitGasUpdated(&bind.FilterOpts{ + Context: context.Background(), + Start: startBlock, + }, []uint64{dest.Selector}) + + require.NoError(t, err) + require.True(t, it.Next()) + require.NotEqual(t, InitialGasPrice, it.Event.Value) + return nil +} + +func ConfirmTokenPriceUpdatedForAll( + t *testing.T, + e deployment.Environment, + state CCIPOnChainState, + startBlocks map[uint64]*uint64, +) { + var wg errgroup.Group + for _, chain := range e.Chains { + chain := chain + wg.Go(func() error { + var startBlock *uint64 + if startBlocks != nil { + startBlock = startBlocks[chain.Selector] + } + linkAddress := state.Chains[chain.Selector].LinkToken.Address() + wethAddress := state.Chains[chain.Selector].Weth9.Address() + tokenToPrice := make(map[common.Address]*big.Int) + tokenToPrice[linkAddress] = InitialLinkPrice + tokenToPrice[wethAddress] = InitialWethPrice + return ConfirmTokenPriceUpdated( + t, + chain, + state.Chains[chain.Selector].FeeQuoter, + *startBlock, + tokenToPrice, + ) + }) + } + require.NoError(t, wg.Wait()) +} + +func ConfirmTokenPriceUpdated( + t *testing.T, + chain deployment.Chain, + feeQuoter *fee_quoter.FeeQuoter, + startBlock uint64, + tokenToInitialPrice map[common.Address]*big.Int, +) error { + tokens := make([]common.Address, 0, len(tokenToInitialPrice)) + for token := range tokenToInitialPrice { + tokens = append(tokens, token) + } + it, err := feeQuoter.FilterUsdPerTokenUpdated(&bind.FilterOpts{ + Context: context.Background(), + Start: startBlock, + }, tokens) + require.NoError(t, err) + for it.Next() { + token := it.Event.Token + initialValue, ok := tokenToInitialPrice[token] + if ok { + require.Contains(t, tokens, token) + // Initial Value should be changed + require.NotEqual(t, initialValue, it.Event.Value) + } + + // Remove the token from the map until we assert all tokens are updated + delete(tokenToInitialPrice, token) + if len(tokenToInitialPrice) == 0 { + return nil + } + } + + if len(tokenToInitialPrice) > 0 { + return fmt.Errorf("Not all tokens updated on chain %d", chain.Selector) + } + + return nil +} + // ConfirmCommitForAllWithExpectedSeqNums waits for all chains in the environment to commit the given expectedSeqNums. // expectedSeqNums is a map of destinationchain selector to expected sequence number // startBlocks is a map of destination chain selector to start block number to start watching from.