-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* changes * changes * add prerequisite changeset * comments * fix test * more test fix * go mod * fix tests * fix more tests * fix * optimize test run * changes * add parallel test * review comments * fixes * another fix * fix tests
- Loading branch information
Showing
16 changed files
with
769 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package changeset | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/pkg/errors" | ||
"github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" | ||
chain_selectors "github.com/smartcontractkit/chain-selectors" | ||
|
||
"github.com/smartcontractkit/chainlink/deployment" | ||
ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip" | ||
) | ||
|
||
var ( | ||
_ deployment.ChangeSet[DeployPrerequisiteConfig] = DeployPrerequisites | ||
) | ||
|
||
// DeployPrerequisites deploys the pre-requisite contracts for CCIP | ||
// pre-requisite contracts are the contracts which can be reused from previous versions of CCIP | ||
func DeployPrerequisites(env deployment.Environment, cfg DeployPrerequisiteConfig) (deployment.ChangesetOutput, error) { | ||
err := cfg.Validate() | ||
if err != nil { | ||
return deployment.ChangesetOutput{}, errors.Wrapf(deployment.ErrInvalidConfig, "%v", err) | ||
} | ||
ab := deployment.NewMemoryAddressBook() | ||
err = ccipdeployment.DeployPrerequisiteChainContracts(env, ab, cfg.ChainSelectors) | ||
if err != nil { | ||
env.Logger.Errorw("Failed to deploy prerequisite contracts", "err", err, "addressBook", ab) | ||
return deployment.ChangesetOutput{}, fmt.Errorf("failed to deploy prerequisite contracts: %w", err) | ||
} | ||
return deployment.ChangesetOutput{ | ||
Proposals: []timelock.MCMSWithTimelockProposal{}, | ||
AddressBook: ab, | ||
JobSpecs: nil, | ||
}, nil | ||
} | ||
|
||
type DeployPrerequisiteConfig struct { | ||
ChainSelectors []uint64 | ||
// TODO handle tokens and feeds in prerequisite config | ||
Tokens map[ccipdeployment.TokenSymbol]common.Address | ||
Feeds map[ccipdeployment.TokenSymbol]common.Address | ||
} | ||
|
||
func (c DeployPrerequisiteConfig) Validate() error { | ||
for _, cs := range c.ChainSelectors { | ||
if cs == 0 { | ||
return fmt.Errorf("chain selector must be set") | ||
} | ||
_, err := chain_selectors.ChainIdFromSelector(cs) | ||
if err != nil { | ||
return fmt.Errorf("invalid chain selector: %d - %w", cs, err) | ||
} | ||
|
||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package changeset | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap/zapcore" | ||
|
||
ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip" | ||
"github.com/smartcontractkit/chainlink/deployment/environment/memory" | ||
"github.com/smartcontractkit/chainlink/v2/core/logger" | ||
) | ||
|
||
func TestDeployPrerequisites(t *testing.T) { | ||
t.Parallel() | ||
lggr := logger.TestLogger(t) | ||
e := memory.NewMemoryEnvironment(t, lggr, zapcore.InfoLevel, memory.MemoryEnvironmentConfig{ | ||
Bootstraps: 1, | ||
Chains: 2, | ||
Nodes: 4, | ||
}) | ||
newChain := e.AllChainSelectors()[0] | ||
cfg := DeployPrerequisiteConfig{ | ||
ChainSelectors: []uint64{newChain}, | ||
} | ||
output, err := DeployPrerequisites(e, cfg) | ||
require.NoError(t, err) | ||
err = e.ExistingAddresses.Merge(output.AddressBook) | ||
require.NoError(t, err) | ||
state, err := ccipdeployment.LoadOnchainState(e) | ||
require.NoError(t, err) | ||
require.NotNil(t, state.Chains[newChain].LinkToken) | ||
require.NotNil(t, state.Chains[newChain].Weth9) | ||
require.NotNil(t, state.Chains[newChain].TokenAdminRegistry) | ||
require.NotNil(t, state.Chains[newChain].RegistryModule) | ||
require.NotNil(t, state.Chains[newChain].Router) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package changeset | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/pkg/errors" | ||
"github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" | ||
chain_selectors "github.com/smartcontractkit/chain-selectors" | ||
|
||
"github.com/smartcontractkit/chainlink/deployment" | ||
) | ||
|
||
var ( | ||
_ deployment.ChangeSet[ExistingContractsConfig] = SaveExistingContracts | ||
) | ||
|
||
type Contract struct { | ||
Address common.Address | ||
TypeAndVersion deployment.TypeAndVersion | ||
ChainSelector uint64 | ||
} | ||
|
||
type ExistingContractsConfig struct { | ||
ExistingContracts []Contract | ||
} | ||
|
||
func (cfg ExistingContractsConfig) Validate() error { | ||
for _, ec := range cfg.ExistingContracts { | ||
if ec.ChainSelector == 0 { | ||
return fmt.Errorf("chain selectors must be set") | ||
} | ||
_, err := chain_selectors.ChainIdFromSelector(ec.ChainSelector) | ||
if err != nil { | ||
return fmt.Errorf("invalid chain selector: %d - %w", ec.ChainSelector, err) | ||
} | ||
if ec.Address == (common.Address{}) { | ||
return fmt.Errorf("address must be set") | ||
} | ||
if ec.TypeAndVersion.Type == "" { | ||
return fmt.Errorf("type must be set") | ||
} | ||
if val, err := ec.TypeAndVersion.Version.Value(); err != nil || val == "" { | ||
return fmt.Errorf("version must be set") | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func SaveExistingContracts(env deployment.Environment, cfg ExistingContractsConfig) (deployment.ChangesetOutput, error) { | ||
err := cfg.Validate() | ||
if err != nil { | ||
return deployment.ChangesetOutput{}, errors.Wrapf(deployment.ErrInvalidConfig, "%v", err) | ||
} | ||
ab := deployment.NewMemoryAddressBook() | ||
for _, ec := range cfg.ExistingContracts { | ||
err = ab.Save(ec.ChainSelector, ec.Address.String(), ec.TypeAndVersion) | ||
if err != nil { | ||
env.Logger.Errorw("Failed to save existing contract", "err", err, "addressBook", ab) | ||
return deployment.ChangesetOutput{}, fmt.Errorf("failed to save existing contract: %w", err) | ||
} | ||
} | ||
return deployment.ChangesetOutput{ | ||
Proposals: []timelock.MCMSWithTimelockProposal{}, | ||
AddressBook: ab, | ||
JobSpecs: nil, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package changeset | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/require" | ||
"go.uber.org/zap/zapcore" | ||
|
||
"github.com/smartcontractkit/chainlink/deployment" | ||
ccipdeployment "github.com/smartcontractkit/chainlink/deployment/ccip" | ||
"github.com/smartcontractkit/chainlink/deployment/environment/memory" | ||
"github.com/smartcontractkit/chainlink/v2/core/logger" | ||
) | ||
|
||
func TestSaveExisting(t *testing.T) { | ||
t.Parallel() | ||
lggr := logger.TestLogger(t) | ||
e := memory.NewMemoryEnvironment(t, lggr, zapcore.InfoLevel, memory.MemoryEnvironmentConfig{ | ||
Bootstraps: 1, | ||
Chains: 2, | ||
Nodes: 4, | ||
}) | ||
chains := e.AllChainSelectors() | ||
chain1 := chains[0] | ||
chain2 := chains[1] | ||
cfg := ExistingContractsConfig{ | ||
ExistingContracts: []Contract{ | ||
{ | ||
Address: common.BigToAddress(big.NewInt(1)), | ||
TypeAndVersion: deployment.NewTypeAndVersion(ccipdeployment.LinkToken, deployment.Version1_0_0), | ||
ChainSelector: chain1, | ||
}, | ||
{ | ||
Address: common.BigToAddress(big.NewInt(2)), | ||
TypeAndVersion: deployment.NewTypeAndVersion(ccipdeployment.WETH9, deployment.Version1_0_0), | ||
ChainSelector: chain1, | ||
}, | ||
{ | ||
Address: common.BigToAddress(big.NewInt(3)), | ||
TypeAndVersion: deployment.NewTypeAndVersion(ccipdeployment.TokenAdminRegistry, deployment.Version1_5_0), | ||
ChainSelector: chain1, | ||
}, | ||
{ | ||
Address: common.BigToAddress(big.NewInt(4)), | ||
TypeAndVersion: deployment.NewTypeAndVersion(ccipdeployment.RegistryModule, deployment.Version1_5_0), | ||
ChainSelector: chain2, | ||
}, | ||
{ | ||
Address: common.BigToAddress(big.NewInt(5)), | ||
TypeAndVersion: deployment.NewTypeAndVersion(ccipdeployment.Router, deployment.Version1_2_0), | ||
ChainSelector: chain2, | ||
}, | ||
}, | ||
} | ||
|
||
output, err := SaveExistingContracts(e, cfg) | ||
require.NoError(t, err) | ||
err = e.ExistingAddresses.Merge(output.AddressBook) | ||
require.NoError(t, err) | ||
state, err := ccipdeployment.LoadOnchainState(e) | ||
require.NoError(t, err) | ||
require.Equal(t, state.Chains[chain1].LinkToken.Address(), common.BigToAddress(big.NewInt(1))) | ||
require.Equal(t, state.Chains[chain1].Weth9.Address(), common.BigToAddress(big.NewInt(2))) | ||
require.Equal(t, state.Chains[chain1].TokenAdminRegistry.Address(), common.BigToAddress(big.NewInt(3))) | ||
require.Equal(t, state.Chains[chain2].RegistryModule.Address(), common.BigToAddress(big.NewInt(4))) | ||
require.Equal(t, state.Chains[chain2].Router.Address(), common.BigToAddress(big.NewInt(5))) | ||
} |
Oops, something went wrong.