Skip to content

Commit

Permalink
Similar common helper for memeroy
Browse files Browse the repository at this point in the history
  • Loading branch information
connorwstein committed Nov 18, 2024
1 parent 727b9e4 commit edf7c1a
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 172 deletions.
24 changes: 1 addition & 23 deletions deployment/ccip/add_lane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,15 @@ import (
func TestAddLane(t *testing.T) {
t.Parallel()
// We add more chains to the chainlink nodes than the number of chains where CCIP is deployed.
e := NewMemoryEnvironmentWithJobs(t, logger.TestLogger(t), 4, 4)
e := NewMemoryEnvironmentWithJobsAndContracts(t, logger.TestLogger(t), 2, 4)
// Here we have CR + nodes set up, but no CCIP contracts deployed.
state, err := LoadOnchainState(e.Env)
require.NoError(t, err)

selectors := e.Env.AllChainSelectors()
// deploy CCIP contracts on two chains
chain1, chain2 := selectors[0], selectors[1]

feeds := state.Chains[e.FeedChainSel].USDFeeds
tokenConfig := NewTestTokenConfig(feeds)
newAddresses := deployment.NewMemoryAddressBook()
err = DeployPrerequisiteChainContracts(e.Env, newAddresses, e.Env.AllChainSelectors())
require.NoError(t, err)
require.NoError(t, e.Env.ExistingAddresses.Merge(newAddresses))

// Set up CCIP contracts and a DON per chain.
newAddresses = deployment.NewMemoryAddressBook()
err = DeployCCIPContracts(e.Env, newAddresses, DeployCCIPContractConfig{
HomeChainSel: e.HomeChainSel,
FeedChainSel: e.FeedChainSel,
TokenConfig: tokenConfig,
ChainsToDeploy: []uint64{chain1, chain2},
OCRSecrets: deployment.XXXGenerateTestOCRSecrets(),
})
require.NoError(t, err)
require.NoError(t, e.Env.ExistingAddresses.Merge(newAddresses))

// We expect no lanes available on any chain.
state, err = LoadOnchainState(e.Env)
require.NoError(t, err)
for _, sel := range []uint64{chain1, chain2} {
chain := state.Chains[sel]
offRamps, err := chain.Router.GetOffRamps(nil)
Expand Down
103 changes: 33 additions & 70 deletions deployment/ccip/changeset/active_candidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (

"github.com/stretchr/testify/require"

jobv1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/job"

ccdeploy "github.com/smartcontractkit/chainlink/deployment/ccip"
commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset"

Expand All @@ -28,46 +26,10 @@ func TestActiveCandidate(t *testing.T) {
t.Skipf("to be enabled after latest cl-ccip is compatible")

lggr := logger.TestLogger(t)
ctx := ccdeploy.Context(t)
tenv := ccdeploy.NewMemoryEnvironment(t, lggr, 3, 5, ccdeploy.MockLinkPrice, ccdeploy.MockWethPrice)
tenv := ccdeploy.NewMemoryEnvironmentWithJobsAndContracts(t, lggr, 3, 5)
e := tenv.Env

state, err := ccdeploy.LoadOnchainState(tenv.Env)
require.NoError(t, err)
require.NotNil(t, state.Chains[tenv.HomeChainSel].LinkToken)

feeds := state.Chains[tenv.FeedChainSel].USDFeeds
tokenConfig := ccdeploy.NewTestTokenConfig(feeds)

output, err := InitialDeploy(tenv.Env, ccdeploy.DeployCCIPContractConfig{
HomeChainSel: tenv.HomeChainSel,
FeedChainSel: tenv.FeedChainSel,
ChainsToDeploy: tenv.Env.AllChainSelectors(),
TokenConfig: tokenConfig,
OCRSecrets: deployment.XXXGenerateTestOCRSecrets(),
})
require.NoError(t, err)
// Get new state after migration.
require.NoError(t, tenv.Env.ExistingAddresses.Merge(output.AddressBook))
state, err = ccdeploy.LoadOnchainState(tenv.Env)
require.NoError(t, err)
homeCS, destCS := tenv.HomeChainSel, tenv.FeedChainSel

// Ensure capreg logs are up to date.
ccdeploy.ReplayLogs(t, e.Offchain, tenv.ReplayBlocks)

// Apply the jobs.
for nodeID, jobs := range output.JobSpecs {
for _, job := range jobs {
// Note these auto-accept
_, err := e.Offchain.ProposeJob(ctx,
&jobv1.ProposeJobRequest{
NodeId: nodeID,
Spec: job,
})
require.NoError(t, err)
}
}

// Add all lanes
require.NoError(t, ccdeploy.AddLanesForAll(e, state))
Expand Down Expand Up @@ -111,23 +73,23 @@ func TestActiveCandidate(t *testing.T) {
ccdeploy.ConfirmExecWithSeqNrForAll(t, e, state, expectedSeqNum, startBlocks)

// transfer ownership
ccdeploy.TransferAllOwnership(t, state, homeCS, e)
acceptOwnershipProposal, err := ccdeploy.GenerateAcceptOwnershipProposal(state, homeCS, e.AllChainSelectors())
ccdeploy.TransferAllOwnership(t, state, tenv.HomeChainSel, e)
acceptOwnershipProposal, err := ccdeploy.GenerateAcceptOwnershipProposal(state, tenv.HomeChainSel, e.AllChainSelectors())
require.NoError(t, err)
acceptOwnershipExec := commonchangeset.SignProposal(t, e, acceptOwnershipProposal)
for _, sel := range e.AllChainSelectors() {
commonchangeset.ExecuteProposal(t, e, acceptOwnershipExec, state.Chains[sel].Timelock, sel)
}
// Apply the accept ownership proposal to all the chains.

err = ccdeploy.ConfirmRequestOnSourceAndDest(t, e, state, homeCS, destCS, 2)
err = ccdeploy.ConfirmRequestOnSourceAndDest(t, e, state, tenv.HomeChainSel, tenv.FeedChainSel, 2)
require.NoError(t, err)

// [ACTIVE, CANDIDATE] setup by setting candidate through cap reg
capReg, ccipHome := state.Chains[homeCS].CapabilityRegistry, state.Chains[homeCS].CCIPHome
donID, err := ccdeploy.DonIDForChain(capReg, ccipHome, destCS)
capReg, ccipHome := state.Chains[tenv.HomeChainSel].CapabilityRegistry, state.Chains[tenv.HomeChainSel].CCIPHome
donID, err := ccdeploy.DonIDForChain(capReg, ccipHome, tenv.FeedChainSel)
require.NoError(t, err)
donInfo, err := state.Chains[homeCS].CapabilityRegistry.GetDON(nil, donID)
donInfo, err := state.Chains[tenv.HomeChainSel].CapabilityRegistry.GetDON(nil, donID)
require.NoError(t, err)
require.Equal(t, 5, len(donInfo.NodeP2PIds))
require.Equal(t, uint32(4), donInfo.ConfigCount)
Expand All @@ -151,13 +113,14 @@ func TestActiveCandidate(t *testing.T) {

// this will construct ocr3 configurations for the
// commit and exec plugin we will be using
rmnHomeAddress := state.Chains[homeCS].RMNHome.Address()
rmnHomeAddress := state.Chains[tenv.HomeChainSel].RMNHome.Address()
tokenConfig := ccdeploy.NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds)
ocr3ConfigMap, err := ccdeploy.BuildOCR3ConfigForCCIPHome(
deployment.XXXGenerateTestOCRSecrets(),
state.Chains[destCS].OffRamp,
e.Chains[destCS],
destCS,
tokenConfig.GetTokenInfo(e.Logger, state.Chains[destCS].LinkToken, state.Chains[destCS].Weth9),
state.Chains[tenv.FeedChainSel].OffRamp,
e.Chains[tenv.FeedChainSel],
tenv.FeedChainSel,
tokenConfig.GetTokenInfo(e.Logger, state.Chains[tenv.FeedChainSel].LinkToken, state.Chains[tenv.FeedChainSel].Weth9),
nodes.NonBootstraps(),
rmnHomeAddress,
nil,
Expand All @@ -166,82 +129,82 @@ func TestActiveCandidate(t *testing.T) {

setCommitCandidateOp, err := ccdeploy.SetCandidateOnExistingDon(
ocr3ConfigMap[cctypes.PluginTypeCCIPCommit],
state.Chains[homeCS].CapabilityRegistry,
state.Chains[homeCS].CCIPHome,
destCS,
state.Chains[tenv.HomeChainSel].CapabilityRegistry,
state.Chains[tenv.HomeChainSel].CCIPHome,
tenv.FeedChainSel,
nodes.NonBootstraps(),
)
require.NoError(t, err)
setCommitCandidateProposal, err := ccdeploy.BuildProposalFromBatches(state, []timelock.BatchChainOperation{{
ChainIdentifier: mcms.ChainIdentifier(homeCS),
ChainIdentifier: mcms.ChainIdentifier(tenv.HomeChainSel),
Batch: setCommitCandidateOp,
}}, "set new candidates on commit plugin", 0)
require.NoError(t, err)
setCommitCandidateSigned := commonchangeset.SignProposal(t, e, setCommitCandidateProposal)
commonchangeset.ExecuteProposal(t, e, setCommitCandidateSigned, state.Chains[homeCS].Timelock, homeCS)
commonchangeset.ExecuteProposal(t, e, setCommitCandidateSigned, state.Chains[tenv.HomeChainSel].Timelock, tenv.HomeChainSel)

// create the op for the commit plugin as well
setExecCandidateOp, err := ccdeploy.SetCandidateOnExistingDon(
ocr3ConfigMap[cctypes.PluginTypeCCIPExec],
state.Chains[homeCS].CapabilityRegistry,
state.Chains[homeCS].CCIPHome,
destCS,
state.Chains[tenv.HomeChainSel].CapabilityRegistry,
state.Chains[tenv.HomeChainSel].CCIPHome,
tenv.FeedChainSel,
nodes.NonBootstraps(),
)
require.NoError(t, err)

setExecCandidateProposal, err := ccdeploy.BuildProposalFromBatches(state, []timelock.BatchChainOperation{{
ChainIdentifier: mcms.ChainIdentifier(homeCS),
ChainIdentifier: mcms.ChainIdentifier(tenv.HomeChainSel),
Batch: setExecCandidateOp,
}}, "set new candidates on commit and exec plugins", 0)
require.NoError(t, err)
setExecCandidateSigned := commonchangeset.SignProposal(t, e, setExecCandidateProposal)
commonchangeset.ExecuteProposal(t, e, setExecCandidateSigned, state.Chains[homeCS].Timelock, homeCS)
commonchangeset.ExecuteProposal(t, e, setExecCandidateSigned, state.Chains[tenv.HomeChainSel].Timelock, tenv.HomeChainSel)

// check setup was successful by confirming number of nodes from cap reg
donInfo, err = state.Chains[homeCS].CapabilityRegistry.GetDON(nil, donID)
donInfo, err = state.Chains[tenv.HomeChainSel].CapabilityRegistry.GetDON(nil, donID)
require.NoError(t, err)
require.Equal(t, 4, len(donInfo.NodeP2PIds))
require.Equal(t, uint32(6), donInfo.ConfigCount)
// [ACTIVE, CANDIDATE] done setup

// [ACTIVE, CANDIDATE] make sure we can still send successful transaction without updating job specs
err = ccdeploy.ConfirmRequestOnSourceAndDest(t, e, state, homeCS, destCS, 3)
err = ccdeploy.ConfirmRequestOnSourceAndDest(t, e, state, tenv.HomeChainSel, tenv.FeedChainSel, 3)
require.NoError(t, err)
// [ACTIVE, CANDIDATE] done send successful transaction on active

// [NEW ACTIVE, NO CANDIDATE] promote to active
// confirm by getting old candidate digest and making sure new active matches
oldCandidateDigest, err := state.Chains[homeCS].CCIPHome.GetCandidateDigest(nil, donID, uint8(cctypes.PluginTypeCCIPExec))
oldCandidateDigest, err := state.Chains[tenv.HomeChainSel].CCIPHome.GetCandidateDigest(nil, donID, uint8(cctypes.PluginTypeCCIPExec))
require.NoError(t, err)

promoteOps, err := ccdeploy.PromoteAllCandidatesForChainOps(state.Chains[homeCS].CapabilityRegistry, state.Chains[homeCS].CCIPHome, destCS, nodes.NonBootstraps())
promoteOps, err := ccdeploy.PromoteAllCandidatesForChainOps(state.Chains[tenv.HomeChainSel].CapabilityRegistry, state.Chains[tenv.HomeChainSel].CCIPHome, tenv.FeedChainSel, nodes.NonBootstraps())
require.NoError(t, err)
promoteProposal, err := ccdeploy.BuildProposalFromBatches(state, []timelock.BatchChainOperation{{
ChainIdentifier: mcms.ChainIdentifier(homeCS),
ChainIdentifier: mcms.ChainIdentifier(tenv.HomeChainSel),
Batch: promoteOps,
}}, "promote candidates and revoke actives", 0)
require.NoError(t, err)
promoteSigned := commonchangeset.SignProposal(t, e, promoteProposal)
commonchangeset.ExecuteProposal(t, e, promoteSigned, state.Chains[homeCS].Timelock, homeCS)
commonchangeset.ExecuteProposal(t, e, promoteSigned, state.Chains[tenv.HomeChainSel].Timelock, tenv.HomeChainSel)
// [NEW ACTIVE, NO CANDIDATE] done promoting

// [NEW ACTIVE, NO CANDIDATE] check onchain state
newActiveDigest, err := state.Chains[homeCS].CCIPHome.GetActiveDigest(nil, donID, uint8(cctypes.PluginTypeCCIPExec))
newActiveDigest, err := state.Chains[tenv.HomeChainSel].CCIPHome.GetActiveDigest(nil, donID, uint8(cctypes.PluginTypeCCIPExec))
require.NoError(t, err)
require.Equal(t, oldCandidateDigest, newActiveDigest)

newCandidateDigest, err := state.Chains[homeCS].CCIPHome.GetCandidateDigest(nil, donID, uint8(cctypes.PluginTypeCCIPCommit))
newCandidateDigest, err := state.Chains[tenv.HomeChainSel].CCIPHome.GetCandidateDigest(nil, donID, uint8(cctypes.PluginTypeCCIPCommit))
require.NoError(t, err)
require.Equal(t, newCandidateDigest, [32]byte{})
// [NEW ACTIVE, NO CANDIDATE] done checking on chain state

// [NEW ACTIVE, NO CANDIDATE] send successful request on new active
donInfo, err = state.Chains[homeCS].CapabilityRegistry.GetDON(nil, donID)
donInfo, err = state.Chains[tenv.HomeChainSel].CapabilityRegistry.GetDON(nil, donID)
require.NoError(t, err)
require.Equal(t, uint32(8), donInfo.ConfigCount)

err = ccdeploy.ConfirmRequestOnSourceAndDest(t, e, state, homeCS, destCS, 4)
err = ccdeploy.ConfirmRequestOnSourceAndDest(t, e, state, tenv.HomeChainSel, tenv.FeedChainSel, 4)
require.NoError(t, err)
// [NEW ACTIVE, NO CANDIDATE] done sending successful request
}
51 changes: 6 additions & 45 deletions deployment/ccip/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,20 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/environment/memory"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)

func TestDeployCCIPContracts(t *testing.T) {
lggr := logger.TestLogger(t)
e := memory.NewMemoryEnvironment(t, lggr, zapcore.InfoLevel, memory.MemoryEnvironmentConfig{
Bootstraps: 1,
Chains: 2,
Nodes: 4,
})
// Deploy all the CCIP contracts.
homeChainSel, feedChainSel := allocateCCIPChainSelectors(e.Chains)
_ = DeployTestContracts(t, lggr, e.ExistingAddresses, homeChainSel, feedChainSel, e.Chains, MockLinkPrice, MockWethPrice)

nodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain)
require.NoError(t, err)

_, err = DeployHomeChain(lggr, e, e.ExistingAddresses, e.Chains[homeChainSel],
NewTestRMNStaticConfig(),
NewTestRMNDynamicConfig(),
NewTestNodeOperator(e.Chains[homeChainSel].DeployerKey.From),
map[string][][32]byte{
"NodeOperator": nodes.NonBootstraps().PeerIDs(),
},
e := NewMemoryEnvironmentWithJobsAndContracts(t, lggr,
2,
4,
)
// Deploy all the CCIP contracts.
state, err := LoadOnchainState(e.Env)
require.NoError(t, err)
// Load the state after deploying the cap reg and feeds.
s, err := LoadOnchainState(e)
require.NoError(t, err)
require.NotNil(t, s.Chains[homeChainSel].CapabilityRegistry)
require.NotNil(t, s.Chains[homeChainSel].CCIPHome)
require.NotNil(t, s.Chains[feedChainSel].USDFeeds)

newAddresses := deployment.NewMemoryAddressBook()
err = DeployPrerequisiteChainContracts(e, newAddresses, e.AllChainSelectors())
require.NoError(t, err)
require.NoError(t, e.ExistingAddresses.Merge(newAddresses))

newAddresses = deployment.NewMemoryAddressBook()
err = DeployCCIPContracts(e, newAddresses, DeployCCIPContractConfig{
HomeChainSel: homeChainSel,
FeedChainSel: feedChainSel,
ChainsToDeploy: e.AllChainSelectors(),
TokenConfig: NewTokenConfig(),
OCRSecrets: deployment.XXXGenerateTestOCRSecrets(),
})
require.NoError(t, err)
require.NoError(t, e.ExistingAddresses.Merge(newAddresses))
state, err := LoadOnchainState(e)
require.NoError(t, err)
snap, err := state.View(e.AllChainSelectors())
snap, err := state.View(e.Env.AllChainSelectors())
require.NoError(t, err)

// Assert expect every deployed address to be in the address book.
Expand Down
Loading

0 comments on commit edf7c1a

Please sign in to comment.