Skip to content

Commit

Permalink
[TT-619] zkEVM Integration and Gas Fixes (#10898)
Browse files Browse the repository at this point in the history
* Fix imports

* Fix more imports

* Fix gas estimations

* Fix version

* Fix To address
  • Loading branch information
kalverra authored Oct 10, 2023
1 parent f512ca5 commit 7b926c8
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 46 deletions.
15 changes: 12 additions & 3 deletions integration-tests/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ func FundChainlinkNodesAddress(
if err != nil {
return err
}
gasEstimates, err := client.EstimateGas(ethereum.CallMsg{})
toAddr := common.HexToAddress(toAddress[keyIndex])
gasEstimates, err := client.EstimateGas(ethereum.CallMsg{
To: &toAddr,
})
if err != nil {
return err
}
Expand All @@ -96,7 +99,10 @@ func FundChainlinkNodesAddresses(
return err
}
for _, addr := range toAddress {
gasEstimates, err := client.EstimateGas(ethereum.CallMsg{})
toAddr := common.HexToAddress(addr)
gasEstimates, err := client.EstimateGas(ethereum.CallMsg{
To: &toAddr,
})
if err != nil {
return err
}
Expand Down Expand Up @@ -379,7 +385,10 @@ func ReturnFunds(chainlinkNodes []*client.ChainlinkK8sClient, blockchainClient b
// FundAddresses will fund a list of addresses with an amount of native currency
func FundAddresses(blockchain blockchain.EVMClient, amount *big.Float, addresses ...string) error {
for _, address := range addresses {
gasEstimates, err := blockchain.EstimateGas(ethereum.CallMsg{})
toAddr := common.HexToAddress(address)
gasEstimates, err := blockchain.EstimateGas(ethereum.CallMsg{
To: &toAddr,
})
if err != nil {
return err
}
Expand Down
5 changes: 4 additions & 1 deletion integration-tests/actions/ocr_helpers_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ func FundChainlinkNodesLocal(
if err != nil {
return err
}
gasEstimates, err := client.EstimateGas(ethereum.CallMsg{})
toAddr := common.HexToAddress(toAddress)
gasEstimates, err := client.EstimateGas(ethereum.CallMsg{
To: &toAddr,
})
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/contracts/contract_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/smartcontractkit/libocr/gethwrappers/offchainaggregator"
"github.com/smartcontractkit/libocr/gethwrappers2/ocr2aggregator"
ocrConfigHelper "github.com/smartcontractkit/libocr/offchainreporting/confighelper"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/functions/generated/functions_load_test_client"
Expand Down Expand Up @@ -55,6 +52,9 @@ import (
"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"
"github.com/smartcontractkit/libocr/gethwrappers/offchainaggregator"
"github.com/smartcontractkit/libocr/gethwrappers2/ocr2aggregator"
ocrConfigHelper "github.com/smartcontractkit/libocr/offchainreporting/confighelper"

eth_contracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum"
)
Expand Down
5 changes: 5 additions & 0 deletions integration-tests/contracts/contract_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ type PolygonZkEvmContractLoader struct {
*EthereumContractLoader
}

// PolygonZKEVMContractLoader wraps for Polygon zkEVM
type PolygonZKEVMContractLoader struct {
*EthereumContractLoader
}

// NewEthereumContractLoader returns an instantiated instance of the ETH contract Loader
func NewEthereumContractLoader(ethClient blockchain.EVMClient, logger zerolog.Logger) *EthereumContractLoader {
return &EthereumContractLoader{
Expand Down
73 changes: 42 additions & 31 deletions integration-tests/contracts/ethereum_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ func (e *EthereumOracle) Address() string {
}

func (e *EthereumOracle) Fund(ethAmount *big.Float) error {
gasEstimates, err := e.client.EstimateGas(ethereum.CallMsg{})
gasEstimates, err := e.client.EstimateGas(ethereum.CallMsg{
To: e.address,
})
if err != nil {
return err
}
Expand Down Expand Up @@ -105,7 +107,9 @@ func (e *EthereumAPIConsumer) RoundID(ctx context.Context) (*big.Int, error) {
}

func (e *EthereumAPIConsumer) Fund(ethAmount *big.Float) error {
gasEstimates, err := e.client.EstimateGas(ethereum.CallMsg{})
gasEstimates, err := e.client.EstimateGas(ethereum.CallMsg{
To: e.address,
})
if err != nil {
return err
}
Expand Down Expand Up @@ -157,7 +161,9 @@ func (f *EthereumStaking) Address() string {

// Fund sends specified currencies to the contract
func (f *EthereumStaking) Fund(ethAmount *big.Float) error {
gasEstimates, err := f.client.EstimateGas(ethereum.CallMsg{})
gasEstimates, err := f.client.EstimateGas(ethereum.CallMsg{
To: f.address,
})
if err != nil {
return err
}
Expand Down Expand Up @@ -901,7 +907,9 @@ func (f *EthereumFluxAggregator) Address() string {

// Fund sends specified currencies to the contract
func (f *EthereumFluxAggregator) Fund(ethAmount *big.Float) error {
gasEstimates, err := f.client.EstimateGas(ethereum.CallMsg{})
gasEstimates, err := f.client.EstimateGas(ethereum.CallMsg{
To: f.address,
})
if err != nil {
return err
}
Expand Down Expand Up @@ -1192,7 +1200,9 @@ type EthereumLinkToken struct {

// Fund the LINK Token contract with ETH to distribute the token
func (l *EthereumLinkToken) Fund(ethAmount *big.Float) error {
gasEstimates, err := l.client.EstimateGas(ethereum.CallMsg{})
gasEstimates, err := l.client.EstimateGas(ethereum.CallMsg{
To: &l.address,
})
if err != nil {
return err
}
Expand Down Expand Up @@ -1289,7 +1299,9 @@ type EthereumOffchainAggregator struct {

// Fund sends specified currencies to the contract
func (o *EthereumOffchainAggregator) Fund(ethAmount *big.Float) error {
gasEstimates, err := o.client.EstimateGas(ethereum.CallMsg{})
gasEstimates, err := o.client.EstimateGas(ethereum.CallMsg{
To: o.address,
})
if err != nil {
return err
}
Expand Down Expand Up @@ -1959,7 +1971,9 @@ func (e *EthereumOffchainAggregatorV2) Address() string {
}

func (e *EthereumOffchainAggregatorV2) Fund(nativeAmount *big.Float) error {
gasEstimates, err := e.client.EstimateGas(ethereum.CallMsg{})
gasEstimates, err := e.client.EstimateGas(ethereum.CallMsg{
To: e.address,
})
if err != nil {
return err
}
Expand Down Expand Up @@ -2237,10 +2251,7 @@ func (e *EthereumFunctionsLoadTestClient) ResetStats() error {
if err != nil {
return err
}
if err := e.client.ProcessTransaction(tx); err != nil {
return err
}
return nil
return e.client.ProcessTransaction(tx)
}

func (e *EthereumFunctionsLoadTestClient) SendRequest(times uint32, source string, encryptedSecretsReferences []byte, args []string, subscriptionId uint64, jobId [32]byte) error {
Expand Down Expand Up @@ -2432,66 +2443,66 @@ func (e *EthereumWERC20Mock) Address() common.Address {
return e.address
}

func (l *EthereumWERC20Mock) Approve(to string, amount *big.Int) error {
opts, err := l.client.TransactionOpts(l.client.GetDefaultWallet())
func (e *EthereumWERC20Mock) Approve(to string, amount *big.Int) error {
opts, err := e.client.TransactionOpts(e.client.GetDefaultWallet())
if err != nil {
return err
}
l.l.Info().
Str("From", l.client.GetDefaultWallet().Address()).
e.l.Info().
Str("From", e.client.GetDefaultWallet().Address()).
Str("To", to).
Str("Amount", amount.String()).
Uint64("Nonce", opts.Nonce.Uint64()).
Msg("Approving LINK Transfer")
tx, err := l.instance.Approve(opts, common.HexToAddress(to), amount)
tx, err := e.instance.Approve(opts, common.HexToAddress(to), amount)
if err != nil {
return err
}
return l.client.ProcessTransaction(tx)
return e.client.ProcessTransaction(tx)
}

func (l *EthereumWERC20Mock) BalanceOf(ctx context.Context, addr string) (*big.Int, error) {
func (e *EthereumWERC20Mock) BalanceOf(ctx context.Context, addr string) (*big.Int, error) {
opts := &bind.CallOpts{
From: common.HexToAddress(l.client.GetDefaultWallet().Address()),
From: common.HexToAddress(e.client.GetDefaultWallet().Address()),
Context: ctx,
}
balance, err := l.instance.BalanceOf(opts, common.HexToAddress(addr))
balance, err := e.instance.BalanceOf(opts, common.HexToAddress(addr))
if err != nil {
return nil, err
}
return balance, nil
}

func (l *EthereumWERC20Mock) Transfer(to string, amount *big.Int) error {
opts, err := l.client.TransactionOpts(l.client.GetDefaultWallet())
func (e *EthereumWERC20Mock) Transfer(to string, amount *big.Int) error {
opts, err := e.client.TransactionOpts(e.client.GetDefaultWallet())
if err != nil {
return err
}
l.l.Info().
Str("From", l.client.GetDefaultWallet().Address()).
e.l.Info().
Str("From", e.client.GetDefaultWallet().Address()).
Str("To", to).
Str("Amount", amount.String()).
Uint64("Nonce", opts.Nonce.Uint64()).
Msg("EthereumWERC20Mock.Transfer()")
tx, err := l.instance.Transfer(opts, common.HexToAddress(to), amount)
tx, err := e.instance.Transfer(opts, common.HexToAddress(to), amount)
if err != nil {
return err
}
return l.client.ProcessTransaction(tx)
return e.client.ProcessTransaction(tx)
}

func (l *EthereumWERC20Mock) Mint(account common.Address, amount *big.Int) (*types.Transaction, error) {
opts, err := l.client.TransactionOpts(l.client.GetDefaultWallet())
func (e *EthereumWERC20Mock) Mint(account common.Address, amount *big.Int) (*types.Transaction, error) {
opts, err := e.client.TransactionOpts(e.client.GetDefaultWallet())
if err != nil {
return nil, err
}
l.l.Info().
e.l.Info().
Str("account", account.Hex()).
Str("amount", amount.String()).
Msg("EthereumWERC20Mock.Mint()")
tx, err := l.instance.Mint(opts, account, amount)
tx, err := e.instance.Mint(opts, account, amount)
if err != nil {
return tx, err
}
return tx, l.client.ProcessTransaction(tx)
return tx, e.client.ProcessTransaction(tx)
}
2 changes: 1 addition & 1 deletion integration-tests/contracts/ethereum_keeper_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/rs/zerolog"
goabi "github.com/umbracle/ethgo/abi"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
cltypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
Expand All @@ -32,7 +33,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/log_upkeep_counter_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/upkeep_transcoder"
"github.com/smartcontractkit/chainlink/v2/core/utils"
goabi "github.com/umbracle/ethgo/abi"

"github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum"
"github.com/smartcontractkit/chainlink/integration-tests/testreporters"
Expand Down
8 changes: 6 additions & 2 deletions integration-tests/contracts/ethereum_vrf_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ func (v *EthereumVRFConsumer) Address() string {
}

func (v *EthereumVRFConsumer) Fund(ethAmount *big.Float) error {
gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{})
gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{
To: v.address,
})
if err != nil {
return err
}
Expand Down Expand Up @@ -277,7 +279,9 @@ func (f *VRFConsumerRoundConfirmer) Wait() error {

// Fund sends specified currencies to the contract
func (v *EthereumVRF) Fund(ethAmount *big.Float) error {
gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{})
gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{
To: v.address,
})
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion integration-tests/contracts/ethereum_vrfv2_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ func (v *EthereumVRFConsumerV2) GasAvailable() (*big.Int, error) {
}

func (v *EthereumVRFConsumerV2) Fund(ethAmount *big.Float) error {
gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{})
gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{
To: v.address,
})
if err != nil {
return err
}
Expand Down
4 changes: 3 additions & 1 deletion integration-tests/contracts/ethereum_vrfv2plus_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,9 @@ func (v *EthereumVRFV2PlusWrapper) GetSubID(ctx context.Context) (*big.Int, erro
}

func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) Fund(ethAmount *big.Float) error {
gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{})
gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{
To: v.address,
})
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/rs/zerolog v1.30.0
github.com/slack-go/slack v0.12.2
github.com/smartcontractkit/chainlink-env v0.38.1
github.com/smartcontractkit/chainlink-testing-framework v1.17.7
github.com/smartcontractkit/chainlink-testing-framework v1.17.8
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
github.com/smartcontractkit/libocr v0.0.0-20230922131214-122accb19ea6
github.com/smartcontractkit/ocr2keepers v0.7.27
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2370,8 +2370,8 @@ github.com/smartcontractkit/chainlink-solana v1.0.3-0.20230831134610-680240b97ac
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20230831134610-680240b97aca/go.mod h1:RIUJXn7EVp24TL2p4FW79dYjyno23x5mjt1nKN+5WEk=
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20230901115736-bbabe542a918 h1:ByVauKFXphRlSNG47lNuxZ9aicu+r8AoNp933VRPpCw=
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20230901115736-bbabe542a918/go.mod h1:/yp/sqD8Iz5GU5fcercjrw0ivJF7HDcupYg+Gjr7EPg=
github.com/smartcontractkit/chainlink-testing-framework v1.17.7 h1:VvxVDyj1eC/a5ZdOGa07U8VrfXUL/ecFEyO8KMvLaCw=
github.com/smartcontractkit/chainlink-testing-framework v1.17.7/go.mod h1:rypNxetVFh6bwaoHn05bsd4vCtgdEsF+1Vdyy/AhAR8=
github.com/smartcontractkit/chainlink-testing-framework v1.17.8 h1:/VEMK3biV/Ml8Liswn5M6pVrRoTnHdLvsoqKr/Cq1f8=
github.com/smartcontractkit/chainlink-testing-framework v1.17.8/go.mod h1:rypNxetVFh6bwaoHn05bsd4vCtgdEsF+1Vdyy/AhAR8=
github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306 h1:ko88+ZznniNJZbZPWAvHQU8SwKAdHngdDZ+pvVgB5ss=
github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4=
github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJif132UCdjo8u43i7iPN1/MFnu49hv7lFGFftCHKU=
Expand Down

0 comments on commit 7b926c8

Please sign in to comment.