Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TT-1007] VRFV1 smoke tests migrated to Seth #12513

Merged
merged 7 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions integration-tests/actions/seth/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa
func DeployForwarderContracts(
t *testing.T,
seth *seth.Client,
linkTokenData seth.DeploymentData,
linkTokenAddress common.Address,
numberOfOperatorForwarderPairs int,
) (operators []common.Address, authorizedForwarders []common.Address, operatorFactoryInstance contracts.OperatorFactory) {
instance, err := contracts.DeployEthereumOperatorFactory(seth, linkTokenData.Address)
instance, err := contracts.DeployEthereumOperatorFactory(seth, linkTokenAddress)
require.NoError(t, err, "failed to create new instance of operator factory")
operatorFactoryInstance = &instance

Expand Down
14 changes: 6 additions & 8 deletions integration-tests/actions/vrf/vrfv1/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package vrfv1
import (
"fmt"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/seth"

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

Expand All @@ -19,21 +20,18 @@ type Contracts struct {
Consumer contracts.VRFConsumer
}

func DeployVRFContracts(cd contracts.ContractDeployer, bc blockchain.EVMClient, lt contracts.LinkToken) (*Contracts, error) {
bhs, err := cd.DeployBlockhashStore()
func DeployVRFContracts(client *seth.Client, linkTokenAddress string) (*Contracts, error) {
bhs, err := contracts.DeployBlockhashStore(client)
if err != nil {
return nil, fmt.Errorf("%s, err %w", ErrDeployBHSV1, err)
}
coordinator, err := cd.DeployVRFCoordinator(lt.Address(), bhs.Address())
coordinator, err := contracts.DeployVRFCoordinator(client, linkTokenAddress, bhs.Address())
if err != nil {
return nil, fmt.Errorf("%s, err %w", ErrDeployVRFCootrinatorV1, err)
}
consumer, err := cd.DeployVRFConsumer(lt.Address(), coordinator.Address())
consumer, err := contracts.DeployVRFConsumer(client, linkTokenAddress, coordinator.Address())
if err != nil {
return nil, fmt.Errorf("%s, err %w", ErrDeployVRFConsumerV1, err)
}
if err := bc.WaitForEvents(); err != nil {
return nil, err
}
return &Contracts{bhs, coordinator, consumer}, nil
}
5 changes: 3 additions & 2 deletions integration-tests/chaos/ocr_chaos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math/big"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/onsi/gomega"
"github.com/smartcontractkit/seth"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -187,13 +188,13 @@ func TestOCRChaos(t *testing.T) {
ms, err := ctfClient.ConnectMockServer(testEnvironment)
require.NoError(t, err, "Creating mockserver clients shouldn't fail")

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

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

ocrInstances, err := actions_seth.DeployOCRv1Contracts(l, seth, 1, linkDeploymentData.Address, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(workerNodes))
ocrInstances, err := actions_seth.DeployOCRv1Contracts(l, seth, 1, 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
4 changes: 2 additions & 2 deletions integration-tests/contracts/contract_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ func (e *EthereumContractDeployer) DeployLinkTokenContract() (LinkToken, error)
return nil, err
}

return &EthereumLinkToken{
return &LegacyEthereumLinkToken{
client: e.client,
instance: instance.(*link_token_interface.LinkToken),
address: *linkTokenAddress,
Expand All @@ -558,7 +558,7 @@ func (e *EthereumContractDeployer) LoadLinkToken(address common.Address) (LinkTo
if err != nil {
return nil, err
}
return &EthereumLinkToken{
return &LegacyEthereumLinkToken{
address: address,
client: e.client,
instance: instance.(*link_token_interface.LinkToken),
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/contracts/contract_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (e *EthereumContractLoader) LoadLINKToken(addr string) (LinkToken, error) {
if err != nil {
return nil, err
}
return &EthereumLinkToken{
return &LegacyEthereumLinkToken{
client: e.client,
instance: instance.(*link_token_interface.LinkToken),
address: common.HexToAddress(addr),
Expand Down
18 changes: 9 additions & 9 deletions integration-tests/contracts/ethereum_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -1192,16 +1192,16 @@ func (f *FluxAggregatorRoundConfirmer) Complete() bool {
return f.complete
}

// EthereumLinkToken represents a LinkToken address
type EthereumLinkToken struct {
// LegacyEthereumLinkToken represents a LinkToken address
type LegacyEthereumLinkToken struct {
client blockchain.EVMClient
instance *link_token_interface.LinkToken
address common.Address
l zerolog.Logger
}

// Fund the LINK Token contract with ETH to distribute the token
func (l *EthereumLinkToken) Fund(ethAmount *big.Float) error {
func (l *LegacyEthereumLinkToken) Fund(ethAmount *big.Float) error {
gasEstimates, err := l.client.EstimateGas(ethereum.CallMsg{
To: &l.address,
})
Expand All @@ -1211,7 +1211,7 @@ func (l *EthereumLinkToken) Fund(ethAmount *big.Float) error {
return l.client.Fund(l.address.Hex(), ethAmount, gasEstimates)
}

func (l *EthereumLinkToken) BalanceOf(ctx context.Context, addr string) (*big.Int, error) {
func (l *LegacyEthereumLinkToken) BalanceOf(ctx context.Context, addr string) (*big.Int, error) {
opts := &bind.CallOpts{
From: common.HexToAddress(l.client.GetDefaultWallet().Address()),
Context: ctx,
Expand All @@ -1224,19 +1224,19 @@ func (l *EthereumLinkToken) BalanceOf(ctx context.Context, addr string) (*big.In
}

// Name returns the name of the link token
func (l *EthereumLinkToken) Name(ctxt context.Context) (string, error) {
func (l *LegacyEthereumLinkToken) Name(ctxt context.Context) (string, error) {
opts := &bind.CallOpts{
From: common.HexToAddress(l.client.GetDefaultWallet().Address()),
Context: ctxt,
}
return l.instance.Name(opts)
}

func (l *EthereumLinkToken) Address() string {
func (l *LegacyEthereumLinkToken) Address() string {
return l.address.Hex()
}

func (l *EthereumLinkToken) Approve(to string, amount *big.Int) error {
func (l *LegacyEthereumLinkToken) Approve(to string, amount *big.Int) error {
opts, err := l.client.TransactionOpts(l.client.GetDefaultWallet())
if err != nil {
return err
Expand All @@ -1254,7 +1254,7 @@ func (l *EthereumLinkToken) Approve(to string, amount *big.Int) error {
return l.client.ProcessTransaction(tx)
}

func (l *EthereumLinkToken) Transfer(to string, amount *big.Int) error {
func (l *LegacyEthereumLinkToken) Transfer(to string, amount *big.Int) error {
opts, err := l.client.TransactionOpts(l.client.GetDefaultWallet())
if err != nil {
return err
Expand All @@ -1272,7 +1272,7 @@ func (l *EthereumLinkToken) Transfer(to string, amount *big.Int) error {
return l.client.ProcessTransaction(tx)
}

func (l *EthereumLinkToken) TransferAndCall(to string, amount *big.Int, data []byte) (*types.Transaction, error) {
func (l *LegacyEthereumLinkToken) TransferAndCall(to string, amount *big.Int, data []byte) (*types.Transaction, error) {
opts, err := l.client.TransactionOpts(l.client.GetDefaultWallet())
if err != nil {
return nil, err
Expand Down
90 changes: 83 additions & 7 deletions integration-tests/contracts/ethereum_contracts_seth.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (

"github.com/smartcontractkit/chainlink/integration-tests/wrappers"
"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_factory"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/operator_wrapper"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/link_token"
)

// EthereumOffchainAggregator represents the offchain aggregation contract
Expand Down Expand Up @@ -568,15 +568,91 @@ func (e *EthereumOffchainAggregatorV2) ParseEventAnswerUpdated(log types.Log) (*
return e.contract.ParseAnswerUpdated(log)
}

func DeployLinkTokenContract(client *seth.Client) (seth.DeploymentData, error) {
linkTokenAbi, err := link_token.LinkTokenMetaData.GetAbi()
// EthereumLinkToken represents a LinkToken address
type EthereumLinkToken struct {
client *seth.Client
instance *link_token_interface.LinkToken
address common.Address
l zerolog.Logger
}

func DeployLinkTokenContract(l zerolog.Logger, client *seth.Client) (*EthereumLinkToken, error) {
linkTokenAbi, err := link_token_interface.LinkTokenMetaData.GetAbi()
if err != nil {
return seth.DeploymentData{}, fmt.Errorf("failed to get LinkToken ABI: %w", err)
return &EthereumLinkToken{}, fmt.Errorf("failed to get LinkToken ABI: %w", err)
}
linkDeploymentData, err := client.DeployContract(client.NewTXOpts(), "LinkToken", *linkTokenAbi, common.FromHex(link_token.LinkTokenMetaData.Bin))
linkDeploymentData, err := client.DeployContract(client.NewTXOpts(), "LinkToken", *linkTokenAbi, common.FromHex(link_token_interface.LinkTokenMetaData.Bin))
if err != nil {
return seth.DeploymentData{}, fmt.Errorf("LinkToken instance deployment have failed: %w", err)
return &EthereumLinkToken{}, fmt.Errorf("LinkToken instance deployment have failed: %w", err)
}

return linkDeploymentData, nil
linkToken, err := link_token_interface.NewLinkToken(linkDeploymentData.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,
address: linkDeploymentData.Address,
l: l,
}, nil
}

// Fund the LINK Token contract with ETH to distribute the token
func (l *EthereumLinkToken) Fund(_ *big.Float) error {
panic("do not use this function, use actions_seth.SendFunds instead")
}

func (l *EthereumLinkToken) BalanceOf(ctx context.Context, addr string) (*big.Int, error) {
return l.instance.BalanceOf(&bind.CallOpts{
From: l.client.Addresses[0],
Context: ctx,
}, common.HexToAddress(addr))

}

// Name returns the name of the link token
func (l *EthereumLinkToken) Name(ctx context.Context) (string, error) {
return l.instance.Name(&bind.CallOpts{
From: l.client.Addresses[0],
Context: ctx,
})
}

func (l *EthereumLinkToken) Address() string {
return l.address.Hex()
}

func (l *EthereumLinkToken) Approve(to string, amount *big.Int) error {
l.l.Info().
Str("From", l.client.Addresses[0].Hex()).
Str("To", to).
Str("Amount", amount.String()).
Msg("Approving LINK Transfer")
_, err := l.client.Decode(l.instance.Approve(l.client.NewTXOpts(), common.HexToAddress(to), amount))
return err
}

func (l *EthereumLinkToken) Transfer(to string, amount *big.Int) error {
l.l.Info().
Str("From", l.client.Addresses[0].Hex()).
Str("To", to).
Str("Amount", amount.String()).
Msg("Transferring LINK")
_, err := l.client.Decode(l.instance.Transfer(l.client.NewTXOpts(), common.HexToAddress(to), amount))
return err
}

func (l *EthereumLinkToken) TransferAndCall(to string, amount *big.Int, data []byte) (*types.Transaction, error) {
l.l.Info().
Str("From", l.client.Addresses[0].Hex()).
Str("To", to).
Str("Amount", amount.String()).
Msg("Transferring and Calling LINK")
decodedTx, err := l.client.Decode(l.instance.TransferAndCall(l.client.NewTXOpts(), common.HexToAddress(to), amount, data))
if err != nil {
return nil, err
}
return decodedTx.Transaction, nil
}
6 changes: 3 additions & 3 deletions integration-tests/contracts/ethereum_ocr2vrf_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ type EthereumVRFBeaconConsumer struct {
vrfBeaconConsumer *vrf_beacon_consumer.BeaconVRFConsumer
}

// EthereumVRFCoordinator represents VRF coordinator contract
type EthereumVRFCoordinator struct {
// LegacyEthereumVRFCoordinator represents VRF coordinator contract
type LegacyEthereumVRFCoordinator struct {
address *common.Address
client blockchain.EVMClient
coordinator *solidity_vrf_coordinator_interface.VRFCoordinator
Expand Down Expand Up @@ -125,7 +125,7 @@ func (e *EthereumContractDeployer) DeployBatchBlockhashStore(blockhashStoreAddr
if err != nil {
return nil, err
}
return &EthereumBatchBlockhashStore{
return &LegacyEthereumBatchBlockhashStore{
client: e.client,
batchBlockhashStore: instance.(*batch_blockhash_store.BatchBlockhashStore),
address: address,
Expand Down
Loading
Loading