Skip to content

Commit

Permalink
Add Mercury v0.3 contract wrappers for E2E tests (#10823)
Browse files Browse the repository at this point in the history
* wip

* wip 2

* Add go wrapper for werc20 mock

* Add wrapper function

* fix

* Add new functions for werc20 wrapper

* Fix werc20 wrapper location
  • Loading branch information
lukaszcl authored Sep 29, 2023
1 parent f935479 commit eff698d
Show file tree
Hide file tree
Showing 9 changed files with 1,421 additions and 15 deletions.
1 change: 1 addition & 0 deletions contracts/scripts/native_solc_compile_all_shared
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ compileContract () {

compileContract shared/token/ERC677/BurnMintERC677.sol
compileContract shared/token/ERC677/LinkToken.sol
compileContract shared/mocks/WERC20Mock.sol
compileContract vendor/openzeppelin-solidity/v4.8.0/contracts/token/ERC20/ERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ llo_feeds_test: ../../../contracts/solc/v0.8.16/ExposedVerifier.abi ../../../con
reward_manager: ../../../contracts/solc/v0.8.16/RewardManager.abi ../../../contracts/solc/v0.8.16/RewardManager.bin db73e9062b17a1d5aa14c06881fe2be49bd95b00b7f1a8943910c5e4ded5b221
verifier: ../../../contracts/solc/v0.8.16/Verifier.abi ../../../contracts/solc/v0.8.16/Verifier.bin df12786bbeccf3a8f3389479cf93c055b4efd5904b9f99a4835f81af43fe62bf
verifier_proxy: ../../../contracts/solc/v0.8.16/VerifierProxy.abi ../../../contracts/solc/v0.8.16/VerifierProxy.bin 6393443d0a323f2dbe9687dc30fd77f8dfa918944b61c651759746ff2d76e4e5
werc20_mock: ../../../contracts/solc/v0.8.19/WERC20Mock.abi ../../../contracts/solc/v0.8.19/WERC20Mock.bin ff2ca3928b2aa9c412c892cb8226c4d754c73eeb291bb7481c32c48791b2aa94
1,052 changes: 1,052 additions & 0 deletions core/gethwrappers/shared/generated/werc20_mock/werc20_mock.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ GETH_VERSION: 1.12.0
burn_mint_erc677: ../../../contracts/solc/v0.8.19/BurnMintERC677.abi ../../../contracts/solc/v0.8.19/BurnMintERC677.bin 405c9016171e614b17e10588653ef8d33dcea21dd569c3fddc596a46fcff68a3
erc20: ../../../contracts/solc/v0.8.19/ERC20.abi ../../../contracts/solc/v0.8.19/ERC20.bin 5b1a93d9b24f250e49a730c96335a8113c3f7010365cba578f313b483001d4fc
link_token: ../../../contracts/solc/v0.8.19/LinkToken.abi ../../../contracts/solc/v0.8.19/LinkToken.bin c0ef9b507103aae541ebc31d87d051c2764ba9d843076b30ec505d37cdfffaba
werc20_mock: ../../../contracts/solc/v0.8.19/WERC20Mock.abi ../../../contracts/solc/v0.8.19/WERC20Mock.bin ff2ca3928b2aa9c412c892cb8226c4d754c73eeb291bb7481c32c48791b2aa94
1 change: 1 addition & 0 deletions core/gethwrappers/shared/go_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ package gethwrappers
//go:generate go run ../generation/generate/wrap.go ../../../contracts/solc/v0.8.19/BurnMintERC677.abi ../../../contracts/solc/v0.8.19/BurnMintERC677.bin BurnMintERC677 burn_mint_erc677
//go:generate go run ../generation/generate/wrap.go ../../../contracts/solc/v0.8.19/LinkToken.abi ../../../contracts/solc/v0.8.19/LinkToken.bin LinkToken link_token
//go:generate go run ../generation/generate/wrap.go ../../../contracts/solc/v0.8.19/ERC20.abi ../../../contracts/solc/v0.8.19/ERC20.bin ERC20 erc20
//go:generate go run ../generation/generate/wrap.go ../../../contracts/solc/v0.8.19/WERC20Mock.abi ../../../contracts/solc/v0.8.19/WERC20Mock.bin WERC20Mock werc20_mock
100 changes: 100 additions & 0 deletions integration-tests/contracts/contract_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/oracle_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/test_api_consumer_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/upkeep_transcoder"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/fee_manager"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/reward_manager"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/verifier"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/verifier_proxy"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/werc20_mock"
)

// ContractDeployer is an interface for abstracting the contract deployment methods across network implementations
Expand All @@ -60,6 +65,7 @@ type ContractDeployer interface {
DeployFlags(rac string) (Flags, error)
DeployFluxAggregatorContract(linkAddr string, fluxOptions FluxAggregatorOptions) (FluxAggregator, error)
DeployLinkTokenContract() (LinkToken, error)
DeployWERC20Mock() (WERC20Mock, error)
LoadLinkToken(address common.Address) (LinkToken, error)
DeployOffChainAggregator(linkAddr string, offchainOptions OffchainOptions) (OffchainAggregator, error)
LoadOffChainAggregator(address *common.Address) (OffchainAggregator, error)
Expand Down Expand Up @@ -117,6 +123,10 @@ type ContractDeployer interface {
DeployKeeperRegistry11Mock() (KeeperRegistry11Mock, error)
DeployKeeperRegistrar12Mock() (KeeperRegistrar12Mock, error)
DeployKeeperGasWrapperMock() (KeeperGasWrapperMock, error)
DeployMercuryVerifierContract(verifierProxyAddr common.Address) (MercuryVerifier, error)
DeployMercuryVerifierProxyContract(accessControllerAddr common.Address) (MercuryVerifierProxy, error)
DeployMercuryFeeManager(linkAddress common.Address, nativeAddress common.Address, proxyAddress common.Address, rewardManagerAddress common.Address) (MercuryFeeManager, error)
DeployMercuryRewardManager(linkAddress common.Address) (MercuryRewardManager, error)
}

// NewContractDeployer returns an instance of a contract deployer based on the client type
Expand Down Expand Up @@ -1436,3 +1446,93 @@ func (e *EthereumContractDeployer) DeployOffchainAggregatorV2(
l: e.l,
}, err
}

func (e *EthereumContractDeployer) DeployMercuryVerifierContract(verifierProxyAddr common.Address) (MercuryVerifier, error) {
address, _, instance, err := e.client.DeployContract("Mercury Verifier", func(
auth *bind.TransactOpts,
backend bind.ContractBackend,
) (common.Address, *types.Transaction, interface{}, error) {
return verifier.DeployVerifier(auth, backend, verifierProxyAddr)
})
if err != nil {
return nil, err
}
return &EthereumMercuryVerifier{
client: e.client,
instance: instance.(*verifier.Verifier),
address: *address,
l: e.l,
}, err
}

func (e *EthereumContractDeployer) DeployMercuryVerifierProxyContract(accessControllerAddr common.Address) (MercuryVerifierProxy, error) {
address, _, instance, err := e.client.DeployContract("Mercury Verifier Proxy", func(
auth *bind.TransactOpts,
backend bind.ContractBackend,
) (common.Address, *types.Transaction, interface{}, error) {
return verifier_proxy.DeployVerifierProxy(auth, backend, accessControllerAddr)
})
if err != nil {
return nil, err
}
return &EthereumMercuryVerifierProxy{
client: e.client,
instance: instance.(*verifier_proxy.VerifierProxy),
address: *address,
l: e.l,
}, err
}

func (e *EthereumContractDeployer) DeployMercuryFeeManager(linkAddress common.Address, nativeAddress common.Address, proxyAddress common.Address, rewardManagerAddress common.Address) (MercuryFeeManager, error) {
address, _, instance, err := e.client.DeployContract("Mercury Fee Manager", func(
auth *bind.TransactOpts,
backend bind.ContractBackend,
) (common.Address, *types.Transaction, interface{}, error) {
return fee_manager.DeployFeeManager(auth, backend, linkAddress, nativeAddress, proxyAddress, rewardManagerAddress)
})
if err != nil {
return nil, err
}
return &EthereumMercuryFeeManager{
client: e.client,
instance: instance.(*fee_manager.FeeManager),
address: *address,
l: e.l,
}, err
}

func (e *EthereumContractDeployer) DeployMercuryRewardManager(linkAddress common.Address) (MercuryRewardManager, error) {
address, _, instance, err := e.client.DeployContract("Mercury Reward Manager", func(
auth *bind.TransactOpts,
backend bind.ContractBackend,
) (common.Address, *types.Transaction, interface{}, error) {
return reward_manager.DeployRewardManager(auth, backend, linkAddress)
})
if err != nil {
return nil, err
}
return &EthereumMercuryRewardManager{
client: e.client,
instance: instance.(*reward_manager.RewardManager),
address: *address,
l: e.l,
}, err
}

func (e *EthereumContractDeployer) DeployWERC20Mock() (WERC20Mock, error) {
address, _, instance, err := e.client.DeployContract("WERC20 Mock", func(
auth *bind.TransactOpts,
backend bind.ContractBackend,
) (common.Address, *types.Transaction, interface{}, error) {
return werc20_mock.DeployWERC20Mock(auth, backend)
})
if err != nil {
return nil, err
}
return &EthereumWERC20Mock{
client: e.client,
instance: instance.(*werc20_mock.WERC20Mock),
address: *address,
l: e.l,
}, err
}
74 changes: 66 additions & 8 deletions integration-tests/contracts/contract_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/authorized_forwarder"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/link_token_interface"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/operator_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/fee_manager"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/reward_manager"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/verifier"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/verifier_proxy"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/werc20_mock"
)

// ContractLoader is an interface for abstracting the contract loading methods across network implementations
Expand All @@ -30,8 +33,12 @@ type ContractLoader interface {
LoadFunctionsLoadTestClient(addr string) (FunctionsLoadTestClient, error)

// Mercury
LoadMercuryVerifier(addr string) (MercuryVerifier, error)
LoadMercuryVerifierProxy(addr string) (MercuryVerifierProxy, error)
LoadMercuryVerifier(addr common.Address) (MercuryVerifier, error)
LoadMercuryVerifierProxy(addr common.Address) (MercuryVerifierProxy, error)
LoadMercuryFeeManager(addr common.Address) (MercuryFeeManager, error)
LoadMercuryRewardManager(addr common.Address) (MercuryRewardManager, error)

LoadWERC20Mock(addr common.Address) (WERC20Mock, error)
}

// NewContractLoader returns an instance of a contract Loader based on the client type
Expand Down Expand Up @@ -204,8 +211,8 @@ func (e *EthereumContractLoader) LoadAuthorizedForwarder(address common.Address)
}

// LoadMercuryVerifier returns Verifier contract deployed on given address
func (e *EthereumContractLoader) LoadMercuryVerifier(addr string) (MercuryVerifier, error) {
instance, err := e.client.LoadContract("Mercury Verifier", common.HexToAddress(addr), func(
func (e *EthereumContractLoader) LoadMercuryVerifier(addr common.Address) (MercuryVerifier, error) {
instance, err := e.client.LoadContract("Mercury Verifier", addr, func(
address common.Address,
backend bind.ContractBackend,
) (interface{}, error) {
Expand All @@ -217,13 +224,13 @@ func (e *EthereumContractLoader) LoadMercuryVerifier(addr string) (MercuryVerifi
return &EthereumMercuryVerifier{
client: e.client,
instance: instance.(*verifier.Verifier),
address: common.HexToAddress(addr),
address: addr,
}, err
}

// LoadMercuryVerifierProxy returns VerifierProxy contract deployed on given address
func (e *EthereumContractLoader) LoadMercuryVerifierProxy(addr string) (MercuryVerifierProxy, error) {
instance, err := e.client.LoadContract("Mercury Verifier Proxy", common.HexToAddress(addr), func(
func (e *EthereumContractLoader) LoadMercuryVerifierProxy(addr common.Address) (MercuryVerifierProxy, error) {
instance, err := e.client.LoadContract("Mercury Verifier Proxy", addr, func(
address common.Address,
backend bind.ContractBackend,
) (interface{}, error) {
Expand All @@ -235,6 +242,57 @@ func (e *EthereumContractLoader) LoadMercuryVerifierProxy(addr string) (MercuryV
return &EthereumMercuryVerifierProxy{
client: e.client,
instance: instance.(*verifier_proxy.VerifierProxy),
address: common.HexToAddress(addr),
address: addr,
}, err
}

func (e *EthereumContractLoader) LoadMercuryFeeManager(addr common.Address) (MercuryFeeManager, error) {
instance, err := e.client.LoadContract("Mercury Fee Manager", addr, func(
address common.Address,
backend bind.ContractBackend,
) (interface{}, error) {
return fee_manager.NewFeeManager(address, backend)
})
if err != nil {
return nil, err
}
return &EthereumMercuryFeeManager{
client: e.client,
instance: instance.(*fee_manager.FeeManager),
address: addr,
}, err
}

func (e *EthereumContractLoader) LoadMercuryRewardManager(addr common.Address) (MercuryRewardManager, error) {
instance, err := e.client.LoadContract("Mercury Reward Manager", addr, func(
address common.Address,
backend bind.ContractBackend,
) (interface{}, error) {
return reward_manager.NewRewardManager(address, backend)
})
if err != nil {
return nil, err
}
return &EthereumMercuryRewardManager{
client: e.client,
instance: instance.(*reward_manager.RewardManager),
address: addr,
}, err
}

func (e *EthereumContractLoader) LoadWERC20Mock(addr common.Address) (WERC20Mock, error) {
instance, err := e.client.LoadContract("WERC20 Mock", addr, func(
address common.Address,
backend bind.ContractBackend,
) (interface{}, error) {
return werc20_mock.NewWERC20Mock(address, backend)
})
if err != nil {
return nil, err
}
return &EthereumWERC20Mock{
client: e.client,
instance: instance.(*werc20_mock.WERC20Mock),
address: addr,
}, err
}
26 changes: 24 additions & 2 deletions integration-tests/contracts/contract_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/flux_aggregator_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/functions_billing_registry_events_mock"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/operator_factory"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/verifier"
)

type FluxAggregatorOptions struct {
Expand Down Expand Up @@ -369,12 +370,33 @@ type FunctionsLoadTestClient interface {
}

type MercuryVerifier interface {
Address() string
Address() common.Address
Verify(signedReport []byte, sender common.Address) error
SetConfig(feedId [32]byte, signers []common.Address, offchainTransmitters [][32]byte, f uint8, onchainConfig []byte, offchainConfigVersion uint64, offchainConfig []byte, recipientAddressesAndWeights []verifier.CommonAddressAndWeight) (*types.Transaction, error)
LatestConfigDetails(ctx context.Context, feedId [32]byte) (verifier.LatestConfigDetails, error)
}

type MercuryVerifierProxy interface {
Address() string
Address() common.Address
InitializeVerifier(verifierAddress common.Address) (*types.Transaction, error)
Verify(signedReport []byte, parameterPayload []byte, value *big.Int) (*types.Transaction, error)
VerifyBulk(signedReports [][]byte, parameterPayload []byte, value *big.Int) (*types.Transaction, error)
SetFeeManager(feeManager common.Address) (*types.Transaction, error)
}

type MercuryFeeManager interface {
Address() common.Address
}

type MercuryRewardManager interface {
Address() common.Address
SetFeeManager(feeManager common.Address) (*types.Transaction, error)
}

type WERC20Mock interface {
Address() common.Address
BalanceOf(ctx context.Context, addr string) (*big.Int, error)
Approve(to string, amount *big.Int) error
Transfer(to string, amount *big.Int) error
Mint(account common.Address, amount *big.Int) (*types.Transaction, error)
}
Loading

0 comments on commit eff698d

Please sign in to comment.