Skip to content

Commit

Permalink
use Seth's contract loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofel committed Jul 3, 2024
1 parent 86537d7 commit 7b17467
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 112 deletions.
39 changes: 16 additions & 23 deletions integration-tests/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,34 @@ import (
"testing"
"time"

"github.com/pelletier/go-toml/v2"

geth "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
gethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rpc"
"github.com/google/uuid"
"github.com/pelletier/go-toml/v2"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"github.com/smartcontractkit/seth"
"github.com/test-go/testify/require"
"go.uber.org/zap/zapcore"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
ctfconfig "github.com/smartcontractkit/chainlink-testing-framework/config"
"github.com/smartcontractkit/chainlink-testing-framework/k8s/environment"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink-testing-framework/testreporters"
"github.com/smartcontractkit/chainlink-testing-framework/utils/conversions"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
"github.com/smartcontractkit/chainlink/integration-tests/testconfig/ocr"
ethContracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum"

"github.com/ethereum/go-ethereum/accounts/abi"

"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"

"github.com/rs/zerolog"

"github.com/ethereum/go-ethereum/common"
"github.com/google/uuid"
"github.com/smartcontractkit/seth"

gethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/pkg/errors"
"github.com/test-go/testify/require"

ctfconfig "github.com/smartcontractkit/chainlink-testing-framework/config"
"github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext"

"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
ethContracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum"
"github.com/smartcontractkit/chainlink/integration-tests/testconfig/ocr"
"github.com/smartcontractkit/chainlink/integration-tests/types/config/node"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/link_token_interface"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/operator_factory"
Expand Down Expand Up @@ -879,7 +872,7 @@ func setupAnyOCRv1Contracts(
} else {
// Load contract wrappers
for _, address := range ocrContractsConfig.GetOffChainAggregatorsContractsAddresses() {
ocrInstance, err := contracts.LoadOffchainAggregator(logger, seth, address)
ocrInstance, err := contracts.LoadOffChainAggregator(logger, seth, address)
if err != nil {
return nil, fmt.Errorf("OCR instance loading have failed: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/actions/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package actions

import (
"github.com/rs/zerolog"
"github.com/smartcontractkit/seth"

"github.com/smartcontractkit/chainlink/integration-tests/contracts"
tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig"
"github.com/smartcontractkit/seth"
)

func GetLinkTokenContract(l zerolog.Logger, sethClient *seth.Client, configWithLinkToken tc.LinkTokenContractConfig) (*contracts.EthereumLinkToken, error) {
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/chaos/ocr_chaos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ func TestOCRChaos(t *testing.T) {
ms, err := ctfClient.ConnectMockServer(testEnvironment)
require.NoError(t, err, "Creating mockserver clients shouldn't fail")

linkContract, err := contracts.DeployLinkTokenContract(l, seth)
linkContract, err := actions.GetLinkTokenContract(l, seth, config.OCR)
require.NoError(t, err, "Error deploying link token contract")

err = actions.FundChainlinkNodesFromRootAddress(l, seth, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(chainlinkNodes), big.NewFloat(10))
require.NoError(t, err)

ocrInstances, err := actions.SetupOCRv1Contracts(l, seth, 1, common.HexToAddress(linkContract.Address()), contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(workerNodes))
ocrInstances, err := actions.SetupOCRv1Contracts(l, seth, config.OCR, common.HexToAddress(linkContract.Address()), contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(workerNodes))
require.NoError(t, err)
err = actions.CreateOCRJobs(ocrInstances, bootstrapNode, workerNodes, 5, ms, fmt.Sprint(seth.ChainID))
require.NoError(t, err)
Expand Down
64 changes: 16 additions & 48 deletions integration-tests/contracts/ethereum_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,22 +206,17 @@ type EthereumOffchainAggregator struct {
l zerolog.Logger
}

func LoadOffchainAggregator(l zerolog.Logger, seth *seth.Client, contractAddress common.Address) (EthereumOffchainAggregator, error) {
abi, err := offchainaggregator.OffchainAggregatorMetaData.GetAbi()
if err != nil {
return EthereumOffchainAggregator{}, fmt.Errorf("failed to get OffChain Aggregator ABI: %w", err)
}
seth.ContractStore.AddABI("OffChainAggregator", *abi)
seth.ContractStore.AddBIN("OffChainAggregator", common.FromHex(offchainaggregator.OffchainAggregatorMetaData.Bin))
func LoadOffChainAggregator(l zerolog.Logger, sethClient *seth.Client, contractAddress common.Address) (EthereumOffchainAggregator, error) {
loader := seth.NewContractLoader[offchainaggregator.OffchainAggregator](sethClient)
instance, err := loader.LoadContract("LinkToken", contractAddress, offchainaggregator.OffchainAggregatorMetaData.GetAbi, offchainaggregator.NewOffchainAggregator)

ocr, err := offchainaggregator.NewOffchainAggregator(contractAddress, wrappers.MustNewWrappedContractBackend(nil, seth))
if err != nil {
return EthereumOffchainAggregator{}, fmt.Errorf("failed to instantiate OCR instance: %w", err)
return EthereumOffchainAggregator{}, fmt.Errorf("failed to instantiate OCR v2 instance: %w", err)
}

return EthereumOffchainAggregator{
client: seth,
ocr: ocr,
client: sethClient,
ocr: instance,
address: &contractAddress,
l: l,
}, nil
Expand Down Expand Up @@ -582,23 +577,23 @@ type EthereumOffchainAggregatorV2 struct {
l zerolog.Logger
}

func LoadOffChainAggregatorV2(l zerolog.Logger, seth *seth.Client, contractAddress common.Address) (EthereumOffchainAggregatorV2, error) {
oAbi, err := ocr2aggregator.OCR2AggregatorMetaData.GetAbi()
func LoadOffchainAggregatorV2(l zerolog.Logger, seth *seth.Client, address common.Address) (EthereumOffchainAggregatorV2, error) {
contractAbi, err := ocr2aggregator.OCR2AggregatorMetaData.GetAbi()
if err != nil {
return EthereumOffchainAggregatorV2{}, fmt.Errorf("failed to get OffChain Aggregator ABI: %w", err)
return EthereumOffchainAggregatorV2{}, fmt.Errorf("failed to get OffChain Aggregator v2 ABI: %w", err)
}
seth.ContractStore.AddABI("OffChainAggregatorV2", *oAbi)
seth.ContractStore.AddABI("OffChainAggregatorV2", *contractAbi)
seth.ContractStore.AddBIN("OffChainAggregatorV2", common.FromHex(ocr2aggregator.OCR2AggregatorMetaData.Bin))

ocr2, err := ocr2aggregator.NewOCR2Aggregator(contractAddress, seth.Client)
ocr2, err := ocr2aggregator.NewOCR2Aggregator(address, seth.Client)
if err != nil {
return EthereumOffchainAggregatorV2{}, fmt.Errorf("failed to instantiate OCR instance: %w", err)
return EthereumOffchainAggregatorV2{}, fmt.Errorf("failed to instantiate OCRv2 instance: %w", err)
}

return EthereumOffchainAggregatorV2{
client: seth,
contract: ocr2,
address: &contractAddress,
address: &address,
l: l,
}, nil
}
Expand Down Expand Up @@ -638,27 +633,6 @@ func DeployOffchainAggregatorV2(l zerolog.Logger, seth *seth.Client, linkTokenAd
}, nil
}

func LoadOffchainAggregatorV2(l zerolog.Logger, seth *seth.Client, address common.Address) (EthereumOffchainAggregatorV2, error) {
contractAbi, err := ocr2aggregator.OCR2AggregatorMetaData.GetAbi()
if err != nil {
return EthereumOffchainAggregatorV2{}, fmt.Errorf("failed to get OffChain Aggregator v2 ABI: %w", err)
}
seth.ContractStore.AddABI("OffChainAggregatorV2", *contractAbi)
seth.ContractStore.AddBIN("OffChainAggregatorV2", common.FromHex(ocr2aggregator.OCR2AggregatorMetaData.Bin))

ocr2, err := ocr2aggregator.NewOCR2Aggregator(address, seth.Client)
if err != nil {
return EthereumOffchainAggregatorV2{}, fmt.Errorf("failed to instantiate OCRv2 instance: %w", err)
}

return EthereumOffchainAggregatorV2{
client: seth,
contract: ocr2,
address: &address,
l: l,
}, nil
}

func (e *EthereumOffchainAggregatorV2) Address() string {
return e.address.Hex()
}
Expand Down Expand Up @@ -791,22 +765,16 @@ func DeployLinkTokenContract(l zerolog.Logger, client *seth.Client) (*EthereumLi
}

func LoadLinkTokenContract(l zerolog.Logger, client *seth.Client, address common.Address) (*EthereumLinkToken, error) {
abi, err := link_token_interface.LinkTokenMetaData.GetAbi()
if err != nil {
return &EthereumLinkToken{}, fmt.Errorf("failed to get LinkToken ABI: %w", err)
}

client.ContractStore.AddABI("LinkToken", *abi)
client.ContractStore.AddBIN("LinkToken", common.FromHex(link_token_interface.LinkTokenMetaData.Bin))
loader := seth.NewContractLoader[link_token_interface.LinkToken](client)
instance, err := loader.LoadContract("LinkToken", address, link_token_interface.LinkTokenMetaData.GetAbi, link_token_interface.NewLinkToken)

linkToken, err := link_token_interface.NewLinkToken(address, wrappers.MustNewWrappedContractBackend(nil, client))
if err != nil {
return &EthereumLinkToken{}, fmt.Errorf("failed to instantiate LinkToken instance: %w", err)
}

return &EthereumLinkToken{
client: client,
instance: linkToken,
instance: instance,
address: address,
l: l,
}, nil
Expand Down
5 changes: 3 additions & 2 deletions integration-tests/load/ocr/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/rs/zerolog"

"github.com/smartcontractkit/seth"

client2 "github.com/smartcontractkit/chainlink-testing-framework/client"
"github.com/smartcontractkit/chainlink/integration-tests/actions"
"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig"
)

func SetupCluster(
Expand All @@ -36,12 +36,13 @@ func SetupCluster(
func SetupFeed(
l zerolog.Logger,
seth *seth.Client,
config *tc.TestConfig,
lta common.Address,
msClient *client2.MockserverClient,
bootstrapNode *client.ChainlinkK8sClient,
workerNodes []*client.ChainlinkK8sClient,
) ([]contracts.OffchainAggregator, error) {
ocrInstances, err := actions.SetupOCRv1Contracts(l, seth, 1, lta, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(workerNodes))
ocrInstances, err := actions.SetupOCRv1Contracts(l, seth, config.OCR, lta, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(workerNodes))
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/load/ocr/ocr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestOCRLoad(t *testing.T) {

lta, err := SetupCluster(l, seth, workerNodes)
require.NoError(t, err)
ocrInstances, err := SetupFeed(l, seth, lta, msClient, bootstrapNode, workerNodes)
ocrInstances, err := SetupFeed(l, seth, &config, lta, msClient, bootstrapNode, workerNodes)
require.NoError(t, err)

cfg := config.OCR
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestOCRVolume(t *testing.T) {
LoadType: wasp.VU,
CallTimeout: cfg.Volume.VerificationTimeout.Duration,
Schedule: wasp.Plain(*cfg.Volume.Rate, cfg.Volume.TestDuration.Duration),
VU: NewVU(l, seth, *cfg.Volume.VURequestsPerUnit, cfg.Volume.RateLimitUnitDuration.Duration, lta, bootstrapNode, workerNodes, msClient),
VU: NewVU(l, seth, cfg, *cfg.Volume.VURequestsPerUnit, cfg.Volume.RateLimitUnitDuration.Duration, lta, bootstrapNode, workerNodes, msClient),
Labels: CommonTestLabels,
LokiConfig: wasp.NewLokiConfig(cfgl.Endpoint, cfgl.TenantId, cfgl.BasicAuth, cfgl.BearerToken),
}))
Expand Down
9 changes: 6 additions & 3 deletions integration-tests/load/ocr/vu.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/rs/zerolog"

"github.com/smartcontractkit/seth"

"github.com/smartcontractkit/wasp"
"go.uber.org/ratelimit"

Expand All @@ -19,6 +17,7 @@ import (
"github.com/smartcontractkit/chainlink/integration-tests/actions"
"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
"github.com/smartcontractkit/chainlink/integration-tests/testconfig/ocr"
)

// VU is a virtual user for the OCR load test
Expand All @@ -36,11 +35,13 @@ type VU struct {
msClient *client2.MockserverClient
l zerolog.Logger
ocrInstances []contracts.OffchainAggregator
config ocr.OffChainAggregatorsConfig
}

func NewVU(
l zerolog.Logger,
seth *seth.Client,
config ocr.OffChainAggregatorsConfig,
rate int,
rateUnit time.Duration,
lta common.Address,
Expand All @@ -59,6 +60,7 @@ func NewVU(
msClient: msClient,
bootstrapNode: bootstrapNode,
workerNodes: workerNodes,
config: config,
}
}

Expand All @@ -74,11 +76,12 @@ func (m *VU) Clone(_ *wasp.Generator) wasp.VirtualUser {
msClient: m.msClient,
bootstrapNode: m.bootstrapNode,
workerNodes: m.workerNodes,
config: m.config,
}
}

func (m *VU) Setup(_ *wasp.Generator) error {
ocrInstances, err := actions.SetupOCRv1Contracts(m.l, m.seth, 1, m.lta, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(m.workerNodes))
ocrInstances, err := actions.SetupOCRv1Contracts(m.l, m.seth, m.config, m.lta, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(m.workerNodes))
if err != nil {
return err
}
Expand Down
5 changes: 0 additions & 5 deletions integration-tests/smoke/forwarder_ocr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ func TestForwarderOCRBasic(t *testing.T) {
actions.TrackForwarder(t, sethClient, authorizedForwarders[i], workerNodes[i])
}

var ocrInstanceAddresses []common.Address
for _, address := range config.OCR.Contracts.OffchainAggregatorAddresses {
ocrInstanceAddresses = append(ocrInstanceAddresses, common.HexToAddress(address))
}

ocrInstances, err := actions.DeployOCRContractsForwarderFlow(
l,
sethClient,
Expand Down
1 change: 1 addition & 0 deletions integration-tests/testconfig/ocr/ocr.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ocr
import (
"errors"
"fmt"

"github.com/ethereum/go-ethereum/common"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
Expand Down
5 changes: 2 additions & 3 deletions integration-tests/testconfig/testconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ import (
"embed"
"encoding/base64"
"fmt"
"github.com/ethereum/go-ethereum/common"
"math/big"
"os"
"slices"
"strings"

"github.com/barkimedes/go-deepcopy"
"github.com/ethereum/go-ethereum/common"
"github.com/google/uuid"
"github.com/pelletier/go-toml/v2"
"github.com/pkg/errors"
"github.com/smartcontractkit/seth"
"golang.org/x/text/cases"
"golang.org/x/text/language"

"github.com/smartcontractkit/seth"

ctf_config "github.com/smartcontractkit/chainlink-testing-framework/config"
k8s_config "github.com/smartcontractkit/chainlink-testing-framework/k8s/config"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
Expand Down
Loading

0 comments on commit 7b17467

Please sign in to comment.