Skip to content

Commit

Permalink
_WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhwarrier committed Sep 20, 2024
1 parent 9e0b552 commit 4a29a2c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
11 changes: 7 additions & 4 deletions integration-tests/actions/automationv2/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ func (a *AutomationTest) DeployRegistry() error {
return nil
}

func (a *AutomationTest) LoadRegistry(address string) error {
registry, err := contracts.LoadKeeperRegistry(a.Logger, a.ChainClient, common.HexToAddress(address), a.RegistrySettings.RegistryVersion)
func (a *AutomationTest) LoadRegistry(registryAddress, chainModuleAddress string) error {
registry, err := contracts.LoadKeeperRegistry(a.Logger, a.ChainClient, common.HexToAddress(registryAddress), a.RegistrySettings.RegistryVersion, common.HexToAddress(chainModuleAddress))
if err != nil {
return err
}
Expand Down Expand Up @@ -953,11 +953,14 @@ func (a *AutomationTest) setupDeployment(t *testing.T, addJobs bool) {
}

if a.TestConfig.GetAutomationConfig().UseExistingRegistryContract() {
chainModuleAddress, err := a.TestConfig.GetAutomationConfig().ChainModuleContractAddress()
require.NoError(t, err, "Error getting chain module contract address")
registryAddress, err := a.TestConfig.GetAutomationConfig().RegistryContractAddress()
require.NoError(t, err, "Error getting registry contract address")
err = a.LoadRegistry(registryAddress.String())
err = a.LoadRegistry(registryAddress.String(), chainModuleAddress.String())
require.NoError(t, err, "Error loading registry contract")
if a.Registry.RegistryOwnerAddress() != a.ChainClient.MustGetRootKeyAddress() {
if a.Registry.RegistryOwnerAddress().String() != a.ChainClient.MustGetRootKeyAddress().String() {
l.Debug().Str("RootKeyAddress", a.ChainClient.MustGetRootKeyAddress().String()).Str("Registry Owner Address", a.Registry.RegistryOwnerAddress().String()).Msg("Registry owner address is not the root key address")
t.Error("Registry owner address is not the root key address")
t.FailNow()
}
Expand Down
32 changes: 29 additions & 3 deletions integration-tests/contracts/ethereum_contracts_automation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ func deployRegistry23(client *seth.Client, opts *KeeperRegistryOpts) (KeeperRegi
}

// LoadKeeperRegistry returns deployed on given address EthereumKeeperRegistry
func LoadKeeperRegistry(l zerolog.Logger, client *seth.Client, address common.Address, registryVersion eth_contracts.KeeperRegistryVersion) (KeeperRegistry, error) {
func LoadKeeperRegistry(l zerolog.Logger, client *seth.Client, address common.Address, registryVersion eth_contracts.KeeperRegistryVersion, chainModuleAddress common.Address) (KeeperRegistry, error) {
var keeper *EthereumKeeperRegistry
var err error
switch registryVersion {
Expand All @@ -1545,7 +1545,7 @@ func LoadKeeperRegistry(l zerolog.Logger, client *seth.Client, address common.Ad
case eth_contracts.RegistryVersion_2_2: // why the contract name is not the same as the actual contract name?
keeper, err = loadRegistry2_2(client, address)
case eth_contracts.RegistryVersion_2_3:
keeper, err = loadRegistry2_3(client, address)
keeper, err = loadRegistry2_3(client, address, chainModuleAddress)
default:
return nil, fmt.Errorf("keeper registry version %d is not supported", registryVersion)
}
Expand Down Expand Up @@ -1685,7 +1685,7 @@ func loadRegistry2_2(client *seth.Client, address common.Address) (*EthereumKeep
}, nil
}

func loadRegistry2_3(client *seth.Client, address common.Address) (*EthereumKeeperRegistry, error) {
func loadRegistry2_3(client *seth.Client, address, chainModuleAddress common.Address) (*EthereumKeeperRegistry, error) {
abi, err := iregistry23.IAutomationRegistryMaster23MetaData.GetAbi()
if err != nil {
return &EthereumKeeperRegistry{}, fmt.Errorf("failed to get AutomationRegistry2_3 ABI: %w", err)
Expand All @@ -1699,10 +1699,16 @@ func loadRegistry2_3(client *seth.Client, address common.Address) (*EthereumKeep
return &EthereumKeeperRegistry{}, fmt.Errorf("failed to instantiate AutomationRegistry2_3 instance: %w", err)
}

chainModule, err := loadChainModule(client, chainModuleAddress)
if err != nil {
return &EthereumKeeperRegistry{}, fmt.Errorf("failed to load chain module: %w", err)
}

return &EthereumKeeperRegistry{
address: &address,
client: client,
registry2_3: instance,
chainModule: chainModule,
}, nil
}

Expand Down Expand Up @@ -1758,6 +1764,26 @@ func deployOptimismModule(client *seth.Client) (common.Address, error) {
return data.Address, nil
}

func loadChainModule(client *seth.Client, address common.Address) (*i_chain_module.IChainModule, error) {
abi, err := i_chain_module.IChainModuleMetaData.GetAbi()
if err != nil {
return &i_chain_module.IChainModule{}, fmt.Errorf("failed to get IChainModule ABI: %w", err)
}

client.ContractStore.AddABI("IChainModule", *abi)
client.ContractStore.AddBIN("IChainModule", common.FromHex(i_chain_module.IChainModuleMetaData.Bin))

chainModule, err := i_chain_module.NewIChainModule(
address,
wrappers.MustNewWrappedContractBackend(nil, client),
)
if err != nil {
return &i_chain_module.IChainModule{}, fmt.Errorf("failed to instantiate IChainModule instance: %w", err)
}

return chainModule, nil
}

func deployBaseModule(client *seth.Client) (common.Address, error) {
abi, err := chain_module_base.ChainModuleBaseMetaData.GetAbi()
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions integration-tests/testconfig/automation/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ type Contracts struct {
LinkTokenAddress *string `toml:"link_token"`
WethAddress *string `toml:"weth"`
TranscoderAddress *string `toml:"transcoder"`
ChainModuleAddress *string `toml:"chain_module"`
RegistryAddress *string `toml:"registry"`
RegistrarAddress *string `toml:"registrar"`
LinkEthFeedAddress *string `toml:"link_eth_feed"`
Expand All @@ -448,6 +449,9 @@ func (o *Contracts) Validate() error {
if o.TranscoderAddress != nil && !common.IsHexAddress(*o.TranscoderAddress) {
return errors.New("transcoder must be a valid ethereum address")
}
if o.ChainModuleAddress != nil && !common.IsHexAddress(*o.ChainModuleAddress) {
return errors.New("chain_module must be a valid ethereum address")
}
if o.RegistryAddress != nil && !common.IsHexAddress(*o.RegistryAddress) {
return errors.New("registry must be a valid ethereum address")
}
Expand Down Expand Up @@ -539,6 +543,14 @@ func (c *Config) TranscoderContractAddress() (common.Address, error) {
return common.Address{}, errors.New("transcoder address must be set")
}

func (c *Config) ChainModuleContractAddress() (common.Address, error) {
if c.Contracts != nil && c.Contracts.ChainModuleAddress != nil {
return common.HexToAddress(*c.Contracts.ChainModuleAddress), nil
}

return common.Address{}, errors.New("chain module address must be set")
}

func (c *Config) RegistryContractAddress() (common.Address, error) {
if c.Contracts != nil && c.Contracts.RegistryAddress != nil {
return common.HexToAddress(*c.Contracts.RegistryAddress), nil
Expand Down

0 comments on commit 4a29a2c

Please sign in to comment.