Skip to content

Commit

Permalink
Always use chain selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-sekara committed Aug 17, 2023
1 parent ace2d87 commit 7377bc9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
22 changes: 10 additions & 12 deletions integration-tests/actions/ccip_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,12 @@ type CCIPTOMLEnv struct {
Networks []blockchain.EVMNetwork
}

var EvmChainIdToChainSelector = func(chainId uint64, simulated bool) (uint64, error) {
if simulated {
return chainId, nil
}
var EvmChainIdToChainSelector = func(chainId uint64) (uint64, error) {
mapSelector := map[uint64]uint64{
// Testnets
420: 2664363617261496610, // Optimism Goerli
1337: 3379446385462418246, // Quorem
1337: 3379446385462418246, // Tests
2337: 12922642891491394802, // Tests
43113: 14767482510784806043, // Avax Fuji
80001: 12532609583862916517, // Polygon Mumbai
421613: 6101244977088475029, // Arbitrum Goerli
Expand Down Expand Up @@ -519,11 +517,11 @@ func (sourceCCIP *SourceCCIPModule) DeployContracts(lane *laneconfig.LaneConfig)
if len(sourceCCIP.TransferAmount) != len(sourceCCIP.Common.BridgeTokens) {
sourceCCIP.TransferAmount = sourceCCIP.TransferAmount[:len(sourceCCIP.Common.BridgeTokens)]
}
sourceChainSelector, err := EvmChainIdToChainSelector(sourceCCIP.Common.ChainClient.GetChainID().Uint64(), sourceCCIP.Common.ChainClient.NetworkSimulated())
sourceChainSelector, err := EvmChainIdToChainSelector(sourceCCIP.Common.ChainClient.GetChainID().Uint64())
if err != nil {
return errors.WithStack(err)
}
destChainSelector, err := EvmChainIdToChainSelector(sourceCCIP.DestinationChainId, sourceCCIP.Common.ChainClient.NetworkSimulated())
destChainSelector, err := EvmChainIdToChainSelector(sourceCCIP.DestinationChainId)
if err != nil {
return errors.WithStack(err)
}
Expand Down Expand Up @@ -635,7 +633,7 @@ func (sourceCCIP *SourceCCIPModule) DeployContracts(lane *laneconfig.LaneConfig)
}

// update source Router with OnRamp address
err = sourceCCIP.Common.Router.SetOnRamp(sourceCCIP.DestinationChainId, sourceCCIP.OnRamp.EthAddress)
err = sourceCCIP.Common.Router.SetOnRamp(destChainSelector, sourceCCIP.OnRamp.EthAddress)
if err != nil {
return fmt.Errorf("setting onramp on the router shouldn't fail %+v", err)
}
Expand Down Expand Up @@ -849,7 +847,7 @@ func (sourceCCIP *SourceCCIPModule) SendRequest(
if err != nil {
return common.Hash{}, d, nil, fmt.Errorf("failed encoding the options field: %+v", err)
}
destChainSelector, err := EvmChainIdToChainSelector(sourceCCIP.DestinationChainId, sourceCCIP.Common.ChainClient.NetworkSimulated())
destChainSelector, err := EvmChainIdToChainSelector(sourceCCIP.DestinationChainId)
if err != nil {
return common.Hash{}, d, nil, fmt.Errorf("failed getting the chain selector: %+v", err)
}
Expand Down Expand Up @@ -966,11 +964,11 @@ func (destCCIP *DestCCIPModule) DeployContracts(
}

destCCIP.LoadContracts(lane)
sourceChainSelector, err := EvmChainIdToChainSelector(destCCIP.SourceChainId, sourceCCIP.Common.ChainClient.NetworkSimulated())
sourceChainSelector, err := EvmChainIdToChainSelector(destCCIP.SourceChainId)
if err != nil {
return errors.WithStack(err)
}
destChainSelector, err := EvmChainIdToChainSelector(destCCIP.Common.ChainClient.GetChainID().Uint64(), destCCIP.Common.ChainClient.NetworkSimulated())
destChainSelector, err := EvmChainIdToChainSelector(destCCIP.Common.ChainClient.GetChainID().Uint64())
if err != nil {
return errors.WithStack(err)
}
Expand Down Expand Up @@ -1098,7 +1096,7 @@ func (destCCIP *DestCCIPModule) DeployContracts(
}

// apply offramp updates
_, err = destCCIP.Common.Router.AddOffRamp(destCCIP.OffRamp.EthAddress, destCCIP.SourceChainId)
_, err = destCCIP.Common.Router.AddOffRamp(destCCIP.OffRamp.EthAddress, sourceChainSelector)
if err != nil {
return fmt.Errorf("setting offramp as fee updater shouldn't fail %+v", err)
}
Expand Down
7 changes: 5 additions & 2 deletions integration-tests/contracts/ccip/contract_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ccip
import (
"context"
"math/big"
"strconv"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -427,16 +428,17 @@ func (r *Router) Address() string {
return r.EthAddress.Hex()
}

func (r *Router) SetOnRamp(chainID uint64, onRamp common.Address) error {
func (r *Router) SetOnRamp(chainSelector uint64, onRamp common.Address) error {
opts, err := r.client.TransactionOpts(r.client.GetDefaultWallet())
if err != nil {
return err
}
log.Info().
Str("Router", r.Address()).
Str("ChainSelector", strconv.FormatUint(chainSelector, 10)).
Msg("Setting on ramp for r")

tx, err := r.Instance.ApplyRampUpdates(opts, []router.RouterOnRamp{{DestChainSelector: chainID, OnRamp: onRamp}}, nil, nil)
tx, err := r.Instance.ApplyRampUpdates(opts, []router.RouterOnRamp{{DestChainSelector: chainSelector, OnRamp: onRamp}}, nil, nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -464,6 +466,7 @@ func (r *Router) CCIPSend(destChainSelector uint64, msg router.ClientEVM2AnyMess
Str("router", r.Address()).
Str("txHash", tx.Hash().Hex()).
Str("Network Name", r.client.GetNetworkConfig().Name).
Str("chain selector", strconv.FormatUint(destChainSelector, 10)).
Msg("msg is sent")
return tx, r.client.ProcessTransaction(tx)
}
Expand Down

0 comments on commit 7377bc9

Please sign in to comment.