|
| 1 | +package deployment_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "math/big" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/Masterminds/semver/v3" |
| 8 | + "github.com/aws/smithy-go/ptr" |
| 9 | + "github.com/ethereum/go-ethereum/common" |
| 10 | + chainsel "github.com/smartcontractkit/chain-selectors" |
| 11 | + "github.com/smartcontractkit/chainlink-deployments-framework/datastore" |
| 12 | + "github.com/smartcontractkit/chainlink-deployments-framework/deployment" |
| 13 | + "github.com/smartcontractkit/chainlink-evm/pkg/utils" |
| 14 | + |
| 15 | + "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_0_0/adapters" |
| 16 | + "github.com/smartcontractkit/chainlink-ccip/deployment/deploy" |
| 17 | + "github.com/smartcontractkit/chainlink-ccip/deployment/testhelpers" |
| 18 | + |
| 19 | + "github.com/smartcontractkit/chainlink-deployments-framework/engine/test/environment" |
| 20 | + cldf_ops "github.com/smartcontractkit/chainlink-deployments-framework/operations" |
| 21 | + "github.com/stretchr/testify/require" |
| 22 | + |
| 23 | + "github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_5_0/rmn_contract" |
| 24 | + |
| 25 | + "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/utils/operations/contract" |
| 26 | + routerops1_2 "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_2_0/operations/router" |
| 27 | + rmnops1_5 "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_5_0/operations/rmn" |
| 28 | + rmnremoteops1_6 "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/v1_6_0/operations/rmn_remote" |
| 29 | +) |
| 30 | + |
| 31 | +func TestFastCurse(t *testing.T) { |
| 32 | + chain1 := chainsel.TEST_90000001.Selector |
| 33 | + chain2 := chainsel.TEST_90000002.Selector |
| 34 | + env, err := environment.New(t.Context(), |
| 35 | + environment.WithEVMSimulated(t, []uint64{chain1, chain2}), |
| 36 | + ) |
| 37 | + require.NoError(t, err) |
| 38 | + bundle := env.OperationsBundle |
| 39 | + // deploy RMN 1.5 on chain1 and RMN 1.6 on chain2, set up routers, etc. |
| 40 | + chain := env.BlockChains.EVMChains()[chain1] |
| 41 | + deployRMNOp, err := cldf_ops.ExecuteOperation(bundle, rmnops1_5.Deploy, chain, contract.DeployInput[rmnops1_5.ConstructorArgs]{ |
| 42 | + TypeAndVersion: deployment.NewTypeAndVersion(rmnops1_5.ContractType, *semver.MustParse("1.5.0")), |
| 43 | + ChainSelector: chain.Selector, |
| 44 | + Args: rmnops1_5.ConstructorArgs{ |
| 45 | + RMNConfig: rmn_contract.RMNConfig{ |
| 46 | + BlessWeightThreshold: 2, |
| 47 | + CurseWeightThreshold: 2, |
| 48 | + // setting dummy voters |
| 49 | + Voters: []rmn_contract.RMNVoter{ |
| 50 | + { |
| 51 | + BlessWeight: 2, |
| 52 | + CurseWeight: 2, |
| 53 | + BlessVoteAddr: utils.RandomAddress(), |
| 54 | + CurseVoteAddr: utils.RandomAddress(), |
| 55 | + }, |
| 56 | + }, |
| 57 | + }, |
| 58 | + }, |
| 59 | + }) |
| 60 | + require.NoError(t, err) |
| 61 | + ds := datastore.NewMemoryDataStore() |
| 62 | + require.NoError(t, ds.Addresses().Add(datastore.AddressRef{ |
| 63 | + Type: datastore.ContractType(rmnops1_5.ContractType), |
| 64 | + Version: semver.MustParse("1.5.0"), |
| 65 | + ChainSelector: chain1, |
| 66 | + Address: deployRMNOp.Output.Address, |
| 67 | + })) |
| 68 | + // deploy RMNRemote 1.6 on chain2 |
| 69 | + chain = env.BlockChains.EVMChains()[chain2] |
| 70 | + deployRMNRemoteOp, err := cldf_ops.ExecuteOperation(bundle, rmnremoteops1_6.Deploy, chain, contract.DeployInput[rmnremoteops1_6.ConstructorArgs]{ |
| 71 | + TypeAndVersion: deployment.NewTypeAndVersion(rmnremoteops1_6.ContractType, *semver.MustParse("1.6.0")), |
| 72 | + ChainSelector: chain.Selector, |
| 73 | + Args: rmnremoteops1_6.ConstructorArgs{ |
| 74 | + LocalChainSelector: chain.Selector, |
| 75 | + LegacyRMN: utils.RandomAddress(), |
| 76 | + }, |
| 77 | + }) |
| 78 | + require.NoError(t, err) |
| 79 | + require.NoError(t, ds.Addresses().Add(datastore.AddressRef{ |
| 80 | + Type: datastore.ContractType(rmnremoteops1_6.ContractType), |
| 81 | + Version: semver.MustParse("1.6.0"), |
| 82 | + ChainSelector: chain2, |
| 83 | + Address: deployRMNRemoteOp.Output.Address, |
| 84 | + })) |
| 85 | + // deploy router in both chains |
| 86 | + for _, sel := range []uint64{chain1, chain2} { |
| 87 | + evmChain := env.BlockChains.EVMChains()[sel] |
| 88 | + // mock wrapped native and rmnproxy address |
| 89 | + wNative := utils.RandomAddress() |
| 90 | + rmnProxy := utils.RandomAddress() |
| 91 | + |
| 92 | + deployRouterOp, err := cldf_ops.ExecuteOperation(bundle, routerops1_2.Deploy, evmChain, contract.DeployInput[routerops1_2.ConstructorArgs]{ |
| 93 | + ChainSelector: evmChain.Selector, |
| 94 | + TypeAndVersion: deployment.NewTypeAndVersion(routerops1_2.ContractType, *semver.MustParse("1.2.0")), |
| 95 | + Args: routerops1_2.ConstructorArgs{ |
| 96 | + WrappedNative: wNative, |
| 97 | + RMNProxy: rmnProxy, |
| 98 | + }, |
| 99 | + }) |
| 100 | + require.NoError(t, err) |
| 101 | + require.NoError(t, ds.Addresses().Add(datastore.AddressRef{ |
| 102 | + Type: datastore.ContractType(routerops1_2.ContractType), |
| 103 | + Version: semver.MustParse("1.2.0"), |
| 104 | + ChainSelector: sel, |
| 105 | + Address: deployRouterOp.Output.Address, |
| 106 | + })) |
| 107 | + routerAddr := deployRouterOp.Output.Address |
| 108 | + // add some dummy onramps to the router so that chain is supported, |
| 109 | + // on chain1, add chain2 as supported dest chain and vice versa |
| 110 | + onRamp := utils.RandomAddress() |
| 111 | + offRamp := utils.RandomAddress() |
| 112 | + var destChainSelector uint64 |
| 113 | + if sel == chain1 { |
| 114 | + destChainSelector = chain2 |
| 115 | + } else { |
| 116 | + destChainSelector = chain1 |
| 117 | + } |
| 118 | + _, err = cldf_ops.ExecuteOperation(bundle, routerops1_2.ApplyRampUpdates, evmChain, contract.FunctionInput[routerops1_2.ApplyRampsUpdatesArgs]{ |
| 119 | + Address: common.HexToAddress(routerAddr), |
| 120 | + ChainSelector: evmChain.Selector, |
| 121 | + Args: routerops1_2.ApplyRampsUpdatesArgs{ |
| 122 | + OnRampUpdates: []routerops1_2.OnRamp{ |
| 123 | + { |
| 124 | + DestChainSelector: destChainSelector, |
| 125 | + OnRamp: onRamp, |
| 126 | + }, |
| 127 | + }, |
| 128 | + OffRampAdds: []routerops1_2.OffRamp{ |
| 129 | + { |
| 130 | + SourceChainSelector: destChainSelector, |
| 131 | + OffRamp: offRamp, |
| 132 | + }, |
| 133 | + }, |
| 134 | + }, |
| 135 | + }) |
| 136 | + require.NoError(t, err) |
| 137 | + } |
| 138 | + |
| 139 | + // deploy mcms |
| 140 | + evmDeployer := &adapters.EVMDeployer{} |
| 141 | + dReg := deploy.GetRegistry() |
| 142 | + dReg.RegisterDeployer(chainsel.FamilyEVM, deploy.MCMSVersion, evmDeployer) |
| 143 | + cs := deploy.DeployMCMS(dReg) |
| 144 | + evmChain1 := env.BlockChains.EVMChains()[chain1] |
| 145 | + evmChain2 := env.BlockChains.EVMChains()[chain2] |
| 146 | + output, err := cs.Apply(*env, deploy.MCMSDeploymentConfig{ |
| 147 | + Version: semver.MustParse("1.0.0"), |
| 148 | + Chains: map[uint64]deploy.MCMSDeploymentConfigPerChain{ |
| 149 | + chain1: { |
| 150 | + Canceller: testhelpers.SingleGroupMCMS(), |
| 151 | + Bypasser: testhelpers.SingleGroupMCMS(), |
| 152 | + Proposer: testhelpers.SingleGroupMCMS(), |
| 153 | + TimelockMinDelay: big.NewInt(0), |
| 154 | + Qualifier: ptr.String("test"), |
| 155 | + TimelockAdmin: evmChain1.DeployerKey.From, |
| 156 | + }, |
| 157 | + chain2: { |
| 158 | + Canceller: testhelpers.SingleGroupMCMS(), |
| 159 | + Bypasser: testhelpers.SingleGroupMCMS(), |
| 160 | + Proposer: testhelpers.SingleGroupMCMS(), |
| 161 | + TimelockMinDelay: big.NewInt(0), |
| 162 | + Qualifier: ptr.String("test"), |
| 163 | + TimelockAdmin: evmChain2.DeployerKey.From, |
| 164 | + }, |
| 165 | + }, |
| 166 | + }) |
| 167 | + require.NoError(t, err) |
| 168 | + // store addresses in ds |
| 169 | + allAddrRefs, err := output.DataStore.Addresses().Fetch() |
| 170 | + require.NoError(t, err) |
| 171 | + for _, addrRef := range allAddrRefs { |
| 172 | + require.NoError(t, ds.Addresses().Add(addrRef)) |
| 173 | + } |
| 174 | + |
| 175 | + env.DataStore = ds.Seal() |
| 176 | +} |
0 commit comments