Skip to content

Commit

Permalink
wip tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tt-cll committed Jan 6, 2025
1 parent 807472b commit 534dc6e
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 62 deletions.
16 changes: 10 additions & 6 deletions deployment/ccip/changeset/cs_ccip_home_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ func Test_SetCandidate(t *testing.T) {
MinDelay: 0,
}
}
tokenConfig := NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds)
tokenConfig := NewTestTokenConfig(
state.Chains[tenv.FeedChainSel].USDFeeds[LinkSymbol].Address().String(),
state.Chains[tenv.FeedChainSel].USDFeeds[WethSymbol].Address().String())
_, err = commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*proposalutils.TimelockExecutionContracts{
tenv.HomeChainSel: {
Timelock: state.Chains[tenv.HomeChainSel].Timelock,
Expand All @@ -186,7 +188,7 @@ func Test_SetCandidate(t *testing.T) {
OCRConfigPerRemoteChainSelector: map[uint64]CCIPOCRParams{
dest: DefaultOCRParams(
tenv.FeedChainSel,
tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9),
tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken.Address().String(), state.Chains[dest].Weth9.Address().String()),
nil,
),
},
Expand All @@ -204,7 +206,7 @@ func Test_SetCandidate(t *testing.T) {
OCRConfigPerRemoteChainSelector: map[uint64]CCIPOCRParams{
dest: DefaultOCRParams(
tenv.FeedChainSel,
tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9),
tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken.Address().String(), state.Chains[dest].Weth9.Address().String()),
nil,
),
},
Expand Down Expand Up @@ -291,7 +293,9 @@ func Test_RevokeCandidate(t *testing.T) {
MinDelay: 0,
}
}
tokenConfig := NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds)
tokenConfig := NewTestTokenConfig(
state.Chains[tenv.FeedChainSel].USDFeeds[LinkSymbol].Address().String(),
state.Chains[tenv.FeedChainSel].USDFeeds[WethSymbol].Address().String())
_, err = commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*proposalutils.TimelockExecutionContracts{
tenv.HomeChainSel: {
Timelock: state.Chains[tenv.HomeChainSel].Timelock,
Expand All @@ -307,7 +311,7 @@ func Test_RevokeCandidate(t *testing.T) {
OCRConfigPerRemoteChainSelector: map[uint64]CCIPOCRParams{
dest: DefaultOCRParams(
tenv.FeedChainSel,
tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9),
tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken.Address().String(), state.Chains[dest].Weth9.Address().String()),
nil,
),
},
Expand All @@ -325,7 +329,7 @@ func Test_RevokeCandidate(t *testing.T) {
OCRConfigPerRemoteChainSelector: map[uint64]CCIPOCRParams{
dest: DefaultOCRParams(
tenv.FeedChainSel,
tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9),
tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken.Address().String(), state.Chains[dest].Weth9.Address().String()),
nil,
),
},
Expand Down
78 changes: 74 additions & 4 deletions deployment/ccip/changeset/cs_chain_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/logger"

chain_selectors "github.com/smartcontractkit/chain-selectors"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal"
commoncs "github.com/smartcontractkit/chainlink/deployment/common/changeset"
Expand Down Expand Up @@ -238,6 +240,48 @@ func (cfg UpdateOnRampDestsConfig) Validate(e deployment.Environment) error {
}
supportedChains := state.SupportedChains()
for chainSel, updates := range cfg.UpdatesByChain {
if err := cfg.validateRemoteChain(&e, &state, supportedChains, chainSel, updates); err != nil {
return err
}
}
return nil
}

func (cfg UpdateOnRampDestsConfig) validateRemoteChain(e *deployment.Environment, state *CCIPOnChainState, supportedChains map[uint64]struct{}, chainSel uint64, updates map[uint64]OnRampDestinationUpdate) error {
family, err := chain_selectors.GetSelectorFamily(chainSel)
if err != nil {
return err
}
switch family {
case chain_selectors.FamilySolana:
chainState, ok := state.SolChains[chainSel]
if !ok {
return fmt.Errorf("chain %d not found in onchain state", chainSel)
}
if chainState.CcipRouter.IsZero() {
return fmt.Errorf("missing router for chain %d", chainSel)
}
if err := commoncs.ValidateOwnershipSolana(e.GetContext(), cfg.MCMS != nil, e.SolChains[chainSel].DeployerKey.PublicKey(), chainState.Timelock, chainState.CcipRouter); err != nil {
return err
}
for destination := range updates {
// Destination cannot be an unknown destination.
if _, ok := supportedChains[destination]; !ok {
return fmt.Errorf("destination chain %d is not a supported %s", destination, chainState.CcipRouter)
}
// TODO SOLANA_CCIP
// sc, err := chainState.OnRamp.GetStaticConfig(&bind.CallOpts{Context: e.GetContext()})
// if err != nil {
// return fmt.Errorf("failed to get onramp static config %s: %w", chainState.CcipRouter, err)
// }
// if destination == sc.ChainSelector {
// return fmt.Errorf("cannot update onramp destination to the same chain")
// }
}
case chain_selectors.FamilyEVM:
// EVM is the default case
fallthrough
default:
chainState, ok := state.Chains[chainSel]
if !ok {
return fmt.Errorf("chain %d not found in onchain state", chainSel)
Expand All @@ -254,7 +298,6 @@ func (cfg UpdateOnRampDestsConfig) Validate(e deployment.Environment) error {
if err := commoncs.ValidateOwnership(e.GetContext(), cfg.MCMS != nil, e.Chains[chainSel].DeployerKey.From, chainState.Timelock.Address(), chainState.OnRamp); err != nil {
return err
}

for destination := range updates {
// Destination cannot be an unknown destination.
if _, ok := supportedChains[destination]; !ok {
Expand All @@ -269,6 +312,7 @@ func (cfg UpdateOnRampDestsConfig) Validate(e deployment.Environment) error {
}
}
}

return nil
}

Expand Down Expand Up @@ -948,11 +992,37 @@ func (c SetOCR3OffRampConfig) Validate(e deployment.Environment) error {
return fmt.Errorf("home chain %d not found in onchain state", c.HomeChainSel)
}
for _, remote := range c.RemoteChainSels {
chainState, ok := state.Chains[remote]
if err := c.validateRemoteChain(&e, &state, remote); err != nil {
return err
}
}
return nil
}

func (c SetOCR3OffRampConfig) validateRemoteChain(e *deployment.Environment, state *CCIPOnChainState, chainSelector uint64) error {
family, err := chain_selectors.GetSelectorFamily(chainSelector)
if err != nil {
return err
}
switch family {
case chain_selectors.FamilySolana:
chainState, ok := state.SolChains[chainSelector]
if !ok {
return fmt.Errorf("remote chain %d not found in onchain state", chainSelector)
}

if err := commoncs.ValidateOwnershipSolana(e.GetContext(), c.MCMS != nil, e.SolChains[chainSelector].DeployerKey.PublicKey(), chainState.Timelock, chainState.CcipRouter); err != nil {
return err
}
case chain_selectors.FamilyEVM:
// EVM is the default case
fallthrough
default:
chainState, ok := state.Chains[chainSelector]
if !ok {
return fmt.Errorf("remote chain %d not found in onchain state", remote)
return fmt.Errorf("remote chain %d not found in onchain state", chainSelector)
}
if err := commoncs.ValidateOwnership(e.GetContext(), c.MCMS != nil, e.Chains[remote].DeployerKey.From, chainState.Timelock.Address(), chainState.OffRamp); err != nil {
if err := commoncs.ValidateOwnership(e.GetContext(), c.MCMS != nil, e.Chains[chainSelector].DeployerKey.From, chainState.Timelock.Address(), chainState.OffRamp); err != nil {
return err
}
}
Expand Down
15 changes: 7 additions & 8 deletions deployment/ccip/changeset/cs_chain_contracts_solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ import (
// in the chains specified. Multichain support is important - consider when we add a new chain
// and need to update the onramp destinations for all chains to support the new chain.
func UpdateOnRampsDestsSolana(e deployment.Environment, cfg UpdateOnRampDestsConfig) (deployment.ChangesetOutput, error) {

if err := cfg.Validate(e); err != nil {
return deployment.ChangesetOutput{}, err
}
s, err := LoadOnchainStateSolana(e)
if err != nil {
return deployment.ChangesetOutput{}, err
Expand Down Expand Up @@ -130,18 +132,15 @@ func btoi(b bool) uint8 {
// Multichain is especially helpful for NOP rotations where we have
// to touch all the chain to change signers.
func SetOCR3ConfigSolana(e deployment.Environment, cfg SetOCR3OffRampConfig) (deployment.ChangesetOutput, error) {
// if err := cfg.Validate(e); err != nil {
// return deployment.ChangesetOutput{}, err
// }

solState, err := LoadOnchainStateSolana(e)
if err != nil {
if err := cfg.Validate(e); err != nil {
return deployment.ChangesetOutput{}, err
}

state, err := LoadOnchainState(e)
if err != nil {
return deployment.ChangesetOutput{}, err
}
solChains := state.SolChains

// cfg.RemoteChainSels will be a bunch of solana chains
// can add this in validate
Expand All @@ -166,7 +165,7 @@ func SetOCR3ConfigSolana(e deployment.Environment, cfg SetOCR3OffRampConfig) (de
// continue
// }
var instructions []solana.Instruction
ccipRouterId := solState.SolChains[remote].CcipRouter
ccipRouterId := solChains[remote].CcipRouter

Check failure on line 168 in deployment/ccip/changeset/cs_chain_contracts_solana.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (deployment)

var-naming: var ccipRouterId should be ccipRouterID (revive)
for _, arg := range args {
instruction, err := ccip_router.NewSetOcrConfigInstruction(
uint8(arg.OcrPluginType),
Expand Down
Loading

0 comments on commit 534dc6e

Please sign in to comment.