From f605c0122359c7fc4430627caa7257ae508fdd57 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Wed, 24 Apr 2024 10:59:47 +0200 Subject: [PATCH 01/43] WIP: smoke/vrfv2_test.go --- .../actions/vrf/vrfv2/setup_steps.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/integration-tests/actions/vrf/vrfv2/setup_steps.go b/integration-tests/actions/vrf/vrfv2/setup_steps.go index bd41fb33e4e..fa35eadcbfa 100644 --- a/integration-tests/actions/vrf/vrfv2/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2/setup_steps.go @@ -13,9 +13,11 @@ import ( "github.com/google/uuid" + "github.com/smartcontractkit/chainlink-testing-framework/networks" "github.com/smartcontractkit/chainlink/integration-tests/actions" "github.com/smartcontractkit/chainlink/integration-tests/docker/test_env" testconfig "github.com/smartcontractkit/chainlink/integration-tests/testconfig/vrfv2" + "github.com/smartcontractkit/chainlink/integration-tests/types/config/node" vrfcommon "github.com/smartcontractkit/chainlink/integration-tests/actions/vrf/common" @@ -363,6 +365,7 @@ func SetupVRFV2ForNewEnv( WithCLNodes(len(newEnvConfig.NodesToCreate)). WithFunding(big.NewFloat(*testConfig.Common.ChainlinkNodeFunding)). WithCustomCleanup(cleanupFn). + WithSeth(). Build() if err != nil { @@ -371,19 +374,20 @@ func SetupVRFV2ForNewEnv( env.ParallelTransactions(true) - mockETHLinkFeed, err := env.ContractDeployer.DeployVRFMockETHLINKFeed(big.NewInt(*testConfig.VRFv2.General.LinkNativeFeedResponse)) + n := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0] + sethClient, err := env.GetSethClient(n.ChainID) if err != nil { - return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "error deploying mock ETH/LINK feed", err) + return nil, nil, nil, nil, err } - linkToken, err := actions.DeployLINKToken(env.ContractDeployer) + mockETHLinkFeed, err := env.ContractDeployer.DeployVRFMockETHLINKFeed(big.NewInt(*testConfig.VRFv2.General.LinkNativeFeedResponse)) if err != nil { - return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "error deploying LINK contract", err) + return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "error deploying mock ETH/LINK feed", err) } - evmClient, err := env.GetEVMClient(chainID) + linkToken, err := contracts.DeployLinkTokenContract(l, sethClient) if err != nil { - return nil, nil, nil, nil, err + return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "error deploying LINK contract", err) } vrfContracts, vrfKey, nodeTypeToNode, err := SetupVRFV2Environment( @@ -397,7 +401,7 @@ func SetupVRFV2ForNewEnv( linkToken, mockETHLinkFeed, //register proving key against EOA address in order to return funds to this address - evmClient.GetDefaultWallet().Address(), + sethClient.Addresses[0].Hex(), newEnvConfig.NumberOfTxKeysToCreate, l, ) From c34385f909c9dcbed617be7e367fca35daff5210 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Wed, 24 Apr 2024 11:26:25 +0200 Subject: [PATCH 02/43] wip 2 --- .../actions/vrf/vrfv2/setup_steps.go | 4 +- .../contracts/ethereum_vrf_contracts_seth.go | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/integration-tests/actions/vrf/vrfv2/setup_steps.go b/integration-tests/actions/vrf/vrfv2/setup_steps.go index fa35eadcbfa..e8f288c25cc 100644 --- a/integration-tests/actions/vrf/vrfv2/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2/setup_steps.go @@ -372,15 +372,13 @@ func SetupVRFV2ForNewEnv( return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "error creating test env", err) } - env.ParallelTransactions(true) - n := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0] sethClient, err := env.GetSethClient(n.ChainID) if err != nil { return nil, nil, nil, nil, err } - mockETHLinkFeed, err := env.ContractDeployer.DeployVRFMockETHLINKFeed(big.NewInt(*testConfig.VRFv2.General.LinkNativeFeedResponse)) + mockETHLinkFeed, err := contracts.DeployVRFMockETHLINKFeed(sethClient, big.NewInt(*testConfig.VRFv2.General.LinkNativeFeedResponse)) if err != nil { return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "error deploying mock ETH/LINK feed", err) } diff --git a/integration-tests/contracts/ethereum_vrf_contracts_seth.go b/integration-tests/contracts/ethereum_vrf_contracts_seth.go index f352e901a0c..b2ad42382b5 100644 --- a/integration-tests/contracts/ethereum_vrf_contracts_seth.go +++ b/integration-tests/contracts/ethereum_vrf_contracts_seth.go @@ -14,6 +14,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_consumer_interface" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_coordinator_interface" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_wrapper" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_mock_ethlink_aggregator" ) // EthereumBlockhashStore represents a blockhash store for VRF contract @@ -44,6 +45,37 @@ type EthereumVRF struct { address *common.Address } +type EthereumVRFMockETHLINKAggregator struct { + client *seth.Client + address *common.Address + contract *vrf_mock_ethlink_aggregator.VRFMockETHLINKAggregator +} + +func (a *EthereumVRFMockETHLINKAggregator) Address() string { + return a.address.Hex() +} + +func (a *EthereumVRFMockETHLINKAggregator) LatestRoundData() (*big.Int, error) { + data, err := a.contract.LatestRoundData(a.client.NewCallOpts()) + if err != nil { + return nil, err + } + return data.Ans, nil +} + +func (a *EthereumVRFMockETHLINKAggregator) LatestRoundDataUpdatedAt() (*big.Int, error) { + data, err := a.contract.LatestRoundData(a.client.NewCallOpts()) + if err != nil { + return nil, err + } + return data.UpdatedAt, nil +} + +func (a *EthereumVRFMockETHLINKAggregator) SetBlockTimestampDeduction(blockTimestampDeduction *big.Int) error { + _, err := a.client.Decode(a.contract.SetBlockTimestampDeduction(a.client.NewTXOpts(), blockTimestampDeduction)) + return err +} + // DeployVRFContract deploy VRFv1 contract func DeployVRFv1Contract(seth *seth.Client) (VRF, error) { abi, err := solidity_vrf_wrapper.VRFMetaData.GetAbi() @@ -161,6 +193,35 @@ func DeployVRFConsumer(seth *seth.Client, linkAddr, coordinatorAddr string) (VRF }, err } +func DeployVRFMockETHLINKFeed(seth *seth.Client, answer *big.Int) (VRFMockETHLINKFeed, error) { + abi, err := vrf_mock_ethlink_aggregator.VRFMockETHLINKAggregatorMetaData.GetAbi() + if err != nil { + return &EthereumVRFMockETHLINKAggregator{}, fmt.Errorf("failed to get VRFMockETHLINKAggregator ABI: %w", err) + } + + deployment, err := seth.DeployContract( + seth.NewTXOpts(), + "VRFMockETHLINKAggregator", + *abi, + common.FromHex(solidity_vrf_consumer_interface.VRFConsumerMetaData.Bin), + answer, + ) + if err != nil { + return &EthereumVRFMockETHLINKAggregator{}, fmt.Errorf("VRFMockETHLINKAggregator deployment have failed: %w", err) + } + + contract, err := vrf_mock_ethlink_aggregator.NewVRFMockETHLINKAggregator(deployment.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRFMockETHLINKAggregator{}, fmt.Errorf("failed to instantiate VRFMockETHLINKAggregator instance: %w", err) + } + + return &EthereumVRFMockETHLINKAggregator{ + client: seth, + contract: contract, + address: &deployment.Address, + }, err +} + func (v *EthereumBlockhashStore) Address() string { return v.address.Hex() } From 3e48622e1e5cf9c3a27183cec901b1fc469dd86c Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:32:43 +0200 Subject: [PATCH 03/43] wip 3 --- .../actions/vrf/common/actions.go | 9 +- .../actions/vrf/vrfv2/contract_steps.go | 48 +- .../actions/vrf/vrfv2/setup_steps.go | 55 +- .../contracts/contract_deployer.go | 6 - .../contracts/contract_loader.go | 41 -- .../contracts/contract_vrf_models.go | 2 +- .../contracts/ethereum_ocr2vrf_contracts.go | 8 - .../contracts/ethereum_vrf_common.go | 19 +- .../contracts/ethereum_vrf_contracts_seth.go | 41 ++ .../contracts/ethereum_vrfv2_contracts.go | 510 ++++++++---------- integration-tests/docker/test_env/test_env.go | 6 + 11 files changed, 332 insertions(+), 413 deletions(-) diff --git a/integration-tests/actions/vrf/common/actions.go b/integration-tests/actions/vrf/common/actions.go index 4af9fd05572..854cdb55f63 100644 --- a/integration-tests/actions/vrf/common/actions.go +++ b/integration-tests/actions/vrf/common/actions.go @@ -18,10 +18,11 @@ import ( "github.com/smartcontractkit/chainlink/integration-tests/contracts" "github.com/smartcontractkit/chainlink/integration-tests/docker/test_env" vrf_common_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/common/vrf" + "github.com/smartcontractkit/seth" ) func CreateFundAndGetSendingKeys( - client blockchain.EVMClient, + client *seth.Client, node *VRFNode, chainlinkNodeFunding float64, numberOfTxKeysToCreate int, @@ -44,7 +45,7 @@ func CreateFundAndGetSendingKeys( } func CreateAndFundSendingKeys( - client blockchain.EVMClient, + client *seth.Client, node *VRFNode, chainlinkNodeFunding float64, numberOfNativeTokenAddressesToCreate int, @@ -79,13 +80,13 @@ func SetupBHSNode( l zerolog.Logger, bhsNode *VRFNode, ) error { - evmClient, err := env.GetEVMClient(chainID.Int64()) + sethClient, err := env.GetSethClient(chainID.Int64()) if err != nil { return err } bhsTXKeyAddressStrings, _, err := CreateFundAndGetSendingKeys( - evmClient, + sethClient, bhsNode, txKeyFunding, numberOfTxKeysToCreate, diff --git a/integration-tests/actions/vrf/vrfv2/contract_steps.go b/integration-tests/actions/vrf/vrfv2/contract_steps.go index fef780b695b..a2b2ed4ef51 100644 --- a/integration-tests/actions/vrf/vrfv2/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2/contract_steps.go @@ -22,6 +22,7 @@ import ( chainlinkutils "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_owner" + "github.com/smartcontractkit/seth" ) func DeployVRFV2Contracts( @@ -37,52 +38,39 @@ func DeployVRFV2Contracts( return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrDeployBlockHashStore, err) } - evmClient, err := env.GetEVMClient(chainID) + sethClient, err := env.GetSethClientForSelectedNetwork() + // evmClient, err := env.GetEVMClient(chainID) if err != nil { return nil, err } - err = evmClient.WaitForEvents() - if err != nil { - return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) - } - - var coordinatorAddress string + var coordinatorAddress *common.Address if useTestCoordinator { - testCoordinator, err := env.ContractDeployer.DeployVRFCoordinatorTestV2(linkTokenContract.Address(), bhs.Address(), linkEthFeedContract.Address()) + testCoordinator, err := contracts.DeployVRFCoordinatorTestV2(sethClient, linkTokenContract.Address(), bhs.Address(), linkEthFeedContract.Address()) if err != nil { return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrDeployCoordinator, err) } - err = evmClient.WaitForEvents() if err != nil { return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) } coordinatorAddress = testCoordinator.Address() } else { - coordinator, err := env.ContractDeployer.DeployVRFCoordinatorV2(linkTokenContract.Address(), bhs.Address(), linkEthFeedContract.Address()) + coordinator, err := contracts.DeployVRFCoordinatorV2(linkTokenContract.Address(), bhs.Address(), linkEthFeedContract.Address()) if err != nil { return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrDeployCoordinator, err) } - err = evmClient.WaitForEvents() - if err != nil { - return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) - } coordinatorAddress = coordinator.Address() } - coordinator, err := env.ContractLoader.LoadVRFCoordinatorV2(coordinatorAddress) + coordinator, err := contracts.LoadVRFCoordinatorV2(sethClient, *coordinatorAddress) if err != nil { return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrLoadingCoordinator, err) } if useVRFOwner { - vrfOwner, err := env.ContractDeployer.DeployVRFOwner(coordinatorAddress) + vrfOwner, err := contracts.DeployVRFOwner(sethClient, *coordinatorAddress) if err != nil { return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrDeployCoordinator, err) } - err = evmClient.WaitForEvents() - if err != nil { - return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) - } return &vrfcommon.VRFContracts{ CoordinatorV2: coordinator, VRFOwner: vrfOwner, @@ -114,10 +102,10 @@ func DeployVRFV2Consumers(contractDeployer contracts.ContractDeployer, coordinat return consumers, nil } -func DeployVRFV2WrapperConsumers(contractDeployer contracts.ContractDeployer, linkTokenAddress string, vrfV2Wrapper contracts.VRFV2Wrapper, consumerContractsAmount int) ([]contracts.VRFv2WrapperLoadTestConsumer, error) { +func DeployVRFV2WrapperConsumers(client *seth.Client, linkTokenAddress string, vrfV2Wrapper contracts.VRFV2Wrapper, consumerContractsAmount int) ([]contracts.VRFv2WrapperLoadTestConsumer, error) { var consumers []contracts.VRFv2WrapperLoadTestConsumer for i := 1; i <= consumerContractsAmount; i++ { - loadTestConsumer, err := contractDeployer.DeployVRFV2WrapperLoadTestConsumer(linkTokenAddress, vrfV2Wrapper.Address()) + loadTestConsumer, err := contracts.DeployVRFV2WrapperLoadTestConsumer(client, linkTokenAddress, vrfV2Wrapper.Address()) if err != nil { return nil, fmt.Errorf("%s, err %w", ErrAdvancedConsumer, err) } @@ -127,30 +115,20 @@ func DeployVRFV2WrapperConsumers(contractDeployer contracts.ContractDeployer, li } func DeployVRFV2DirectFundingContracts( - contractDeployer contracts.ContractDeployer, - chainClient blockchain.EVMClient, + client *seth.Client, linkTokenAddress string, linkEthFeedAddress string, coordinator contracts.VRFCoordinatorV2, consumerContractsAmount int, ) (*VRFV2WrapperContracts, error) { - vrfv2Wrapper, err := contractDeployer.DeployVRFV2Wrapper(linkTokenAddress, linkEthFeedAddress, coordinator.Address()) + vrfv2Wrapper, err := contracts.DeployVRFV2Wrapper(client, linkTokenAddress, linkEthFeedAddress, coordinator.Address().Hex()) if err != nil { return nil, fmt.Errorf("%s, err %w", ErrDeployVRFV2Wrapper, err) } - err = chainClient.WaitForEvents() - if err != nil { - return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) - } - - consumers, err := DeployVRFV2WrapperConsumers(contractDeployer, linkTokenAddress, vrfv2Wrapper, consumerContractsAmount) + consumers, err := DeployVRFV2WrapperConsumers(client, linkTokenAddress, vrfv2Wrapper, consumerContractsAmount) if err != nil { return nil, err } - err = chainClient.WaitForEvents() - if err != nil { - return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) - } return &VRFV2WrapperContracts{vrfv2Wrapper, consumers}, nil } diff --git a/integration-tests/actions/vrf/vrfv2/setup_steps.go b/integration-tests/actions/vrf/vrfv2/setup_steps.go index e8f288c25cc..c28e82b645b 100644 --- a/integration-tests/actions/vrf/vrfv2/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2/setup_steps.go @@ -13,7 +13,6 @@ import ( "github.com/google/uuid" - "github.com/smartcontractkit/chainlink-testing-framework/networks" "github.com/smartcontractkit/chainlink/integration-tests/actions" "github.com/smartcontractkit/chainlink/integration-tests/docker/test_env" testconfig "github.com/smartcontractkit/chainlink/integration-tests/testconfig/vrfv2" @@ -115,7 +114,7 @@ func SetupVRFV2Environment( return nil, nil, nil, err } - l.Info().Str("Coordinator", vrfContracts.CoordinatorV2.Address()).Msg("Registering Proving Key") + l.Info().Str("Coordinator", vrfContracts.CoordinatorV2.Address().Hex()).Msg("Registering Proving Key") provingKey, err := VRFV2RegisterProvingKey(vrfKey, registerProvingKeyAgainstAddress, vrfContracts.CoordinatorV2) if err != nil { return nil, nil, nil, fmt.Errorf("%s, err %w", vrfcommon.ErrRegisteringProvingKey, err) @@ -130,8 +129,13 @@ func SetupVRFV2Environment( return nil, nil, nil, err } + sethClient, err := env.GetSethClient(chainID) + if err != nil { + return nil, nil, nil, err + } + vrfTXKeyAddressStrings, vrfTXKeyAddresses, err := vrfcommon.CreateFundAndGetSendingKeys( - evmClient, + sethClient, nodeTypeToNodeMap[vrfcommon.VRF], *vrfv2TestConfig.GetCommonConfig().ChainlinkNodeFunding, numberOfTxKeysToCreate, @@ -170,7 +174,7 @@ func SetupVRFV2Environment( configGeneral.General, numberOfTxKeysToCreate, big.NewInt(chainID), - vrfContracts.CoordinatorV2.Address(), + vrfContracts.CoordinatorV2.Address().Hex(), vrfContracts.BHS.Address(), *vrfv2TestConfig.GetCommonConfig().ChainlinkNodeFunding, l, @@ -201,7 +205,7 @@ func SetupVRFV2Environment( func setupVRFNode(contracts *vrfcommon.VRFContracts, chainID *big.Int, vrfv2Config *testconfig.General, pubKeyCompressed string, vrfOwnerConfig *vrfcommon.VRFOwnerConfig, l zerolog.Logger, vrfNode *vrfcommon.VRFNode) error { vrfJobSpecConfig := vrfcommon.VRFJobSpecConfig{ ForwardingAllowed: *vrfv2Config.VRFJobForwardingAllowed, - CoordinatorAddress: contracts.CoordinatorV2.Address(), + CoordinatorAddress: contracts.CoordinatorV2.Address().Hex(), FromAddresses: vrfNode.TXKeyAddressStrings, EVMChainID: chainID.String(), MinIncomingConfirmations: int(*vrfv2Config.MinimumConfirmations), @@ -251,15 +255,14 @@ func SetupVRFV2WrapperEnvironment( keyHash [32]byte, wrapperConsumerContractsAmount int, ) (*VRFV2WrapperContracts, *uint64, error) { - evmClient, err := env.GetEVMClient(chainID) + sethClient, err := env.GetSethClientForSelectedNetwork() if err != nil { return nil, nil, err } // Deploy VRF v2 direct funding contracts wrapperContracts, err := DeployVRFV2DirectFundingContracts( - env.ContractDeployer, - evmClient, + sethClient, linkToken.Address(), mockNativeLINKFeed.Address(), coordinator, @@ -268,10 +271,6 @@ func SetupVRFV2WrapperEnvironment( if err != nil { return nil, nil, err } - err = evmClient.WaitForEvents() - if err != nil { - return nil, nil, fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) - } vrfv2Config := vrfv2TestConfig.GetVRFv2Config() @@ -286,20 +285,12 @@ func SetupVRFV2WrapperEnvironment( if err != nil { return nil, nil, err } - err = evmClient.WaitForEvents() - if err != nil { - return nil, nil, fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) - } // Fetch wrapper subscription ID wrapperSubID, err := wrapperContracts.VRFV2Wrapper.GetSubID(ctx) if err != nil { return nil, nil, err } - err = evmClient.WaitForEvents() - if err != nil { - return nil, nil, fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) - } // Fund wrapper subscription err = FundSubscriptions(env, chainID, big.NewFloat(*vrfv2Config.General.SubscriptionFundingAmountLink), linkToken, coordinator, []uint64{wrapperSubID}) @@ -315,10 +306,6 @@ func SetupVRFV2WrapperEnvironment( if err != nil { return nil, nil, err } - err = evmClient.WaitForEvents() - if err != nil { - return nil, nil, fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) - } return wrapperContracts, &wrapperSubID, nil } @@ -372,8 +359,7 @@ func SetupVRFV2ForNewEnv( return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "error creating test env", err) } - n := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0] - sethClient, err := env.GetSethClient(n.ChainID) + sethClient, err := env.GetSethClientForSelectedNetwork() if err != nil { return nil, nil, nil, nil, err } @@ -419,11 +405,17 @@ func SetupVRFV2ForExistingEnv(ctx context.Context, t *testing.T, testConfig tc.T if err != nil { return nil, nil, nil, fmt.Errorf("%s, err: %w", "error creating test env", err) } - coordinator, err := env.ContractLoader.LoadVRFCoordinatorV2(*commonExistingEnvConfig.CoordinatorAddress) + client, err := env.GetSethClientForSelectedNetwork() + if err != nil { + return nil, nil, nil, err + } + coordinatorAddr := common.HexToAddress(*commonExistingEnvConfig.ConsumerAddress) + coordinator, err := contracts.LoadVRFCoordinatorV2(client, coordinatorAddr) if err != nil { return nil, nil, nil, fmt.Errorf("%s, err: %w", "error loading VRFCoordinator2", err) } - linkToken, err := env.ContractLoader.LoadLINKToken(*commonExistingEnvConfig.LinkAddress) + linkAddr := common.HexToAddress(*commonExistingEnvConfig.LinkAddress) + linkToken, err := contracts.LoadLinkTokenContract(l, client, linkAddr) if err != nil { return nil, nil, nil, fmt.Errorf("%s, err: %w", "error loading LinkToken", err) } @@ -483,7 +475,12 @@ func SetupSubsAndConsumersForExistingEnv( return nil, nil, fmt.Errorf("err: %w", err) } } else { - consumer, err := env.ContractLoader.LoadVRFv2LoadTestConsumer(*commonExistingEnvConfig.ConsumerAddress) + client, err := env.GetSethClientForSelectedNetwork() + if err != nil { + return nil, nil, err + } + addr := common.HexToAddress(*commonExistingEnvConfig.ConsumerAddress) + consumer, err := contracts.LoadVRFv2LoadTestConsumer(client, addr) if err != nil { return nil, nil, fmt.Errorf("err: %w", err) } diff --git a/integration-tests/contracts/contract_deployer.go b/integration-tests/contracts/contract_deployer.go index c85c927b8d4..6e7a482ec8a 100644 --- a/integration-tests/contracts/contract_deployer.go +++ b/integration-tests/contracts/contract_deployer.go @@ -126,19 +126,13 @@ type ContractDeployer interface { DeployUpkeepCounter(testRange *big.Int, interval *big.Int) (UpkeepCounter, error) DeployUpkeepPerformCounterRestrictive(testRange *big.Int, averageEligibilityCadence *big.Int) (UpkeepPerformCounterRestrictive, error) DeployVRFConsumer(linkAddr string, coordinatorAddr string) (VRFConsumer, error) - DeployVRFOwner(coordinatorAddr string) (VRFOwner, error) - DeployVRFCoordinatorTestV2(linkAddr string, bhsAddr string, linkEthFeedAddr string) (*EthereumVRFCoordinatorTestV2, error) DeployVRFConsumerV2(linkAddr string, coordinatorAddr string) (VRFConsumerV2, error) DeployVRFv2Consumer(coordinatorAddr string) (VRFv2Consumer, error) DeployVRFv2LoadTestConsumer(coordinatorAddr string) (VRFv2LoadTestConsumer, error) - DeployVRFV2WrapperLoadTestConsumer(linkAddr string, vrfV2WrapperAddr string) (VRFv2WrapperLoadTestConsumer, error) DeployVRFv2PlusLoadTestConsumer(coordinatorAddr string) (VRFv2PlusLoadTestConsumer, error) DeployVRFV2PlusWrapperLoadTestConsumer(vrfV2PlusWrapperAddr string) (VRFv2PlusWrapperLoadTestConsumer, error) - DeployVRFCoordinator(linkAddr string, bhsAddr string) (VRFCoordinator, error) - DeployVRFCoordinatorV2(linkAddr string, bhsAddr string, linkEthFeedAddr string) (VRFCoordinatorV2, error) DeployVRFCoordinatorV2_5(bhsAddr string) (VRFCoordinatorV2_5, error) DeployVRFCoordinatorV2PlusUpgradedVersion(bhsAddr string) (VRFCoordinatorV2PlusUpgradedVersion, error) - DeployVRFV2Wrapper(linkAddr string, linkEthFeedAddr string, coordinatorAddr string) (VRFV2Wrapper, error) DeployVRFV2PlusWrapper(linkAddr string, linkEthFeedAddr string, coordinatorAddr string, subId *big.Int) (VRFV2PlusWrapper, error) DeployDKG() (DKG, error) DeployOCR2VRFCoordinator(beaconPeriodBlocksCount *big.Int, linkAddr string) (VRFCoordinatorV3, error) diff --git a/integration-tests/contracts/contract_loader.go b/integration-tests/contracts/contract_loader.go index f492adc3286..9047bce65ba 100644 --- a/integration-tests/contracts/contract_loader.go +++ b/integration-tests/contracts/contract_loader.go @@ -3,7 +3,6 @@ package contracts import ( "errors" - "github.com/smartcontractkit/chainlink/integration-tests/wrappers" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2_5" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_v2plus_load_test_with_metrics" @@ -18,8 +17,6 @@ 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/generated/vrf_coordinator_v2" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_load_test_with_metrics" "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" @@ -47,8 +44,6 @@ type ContractLoader interface { LoadWERC20Mock(addr common.Address) (WERC20Mock, error) // VRF - LoadVRFCoordinatorV2(addr string) (VRFCoordinatorV2, error) - LoadVRFv2LoadTestConsumer(addr string) (VRFv2LoadTestConsumer, error) LoadVRFCoordinatorV2_5(addr string) (VRFCoordinatorV2_5, error) LoadVRFv2PlusLoadTestConsumer(addr string) (VRFv2PlusLoadTestConsumer, error) } @@ -403,39 +398,3 @@ func (e *EthereumContractLoader) LoadVRFv2PlusLoadTestConsumer(addr string) (VRF address: &address, }, err } - -func (e *EthereumContractLoader) LoadVRFCoordinatorV2(addr string) (VRFCoordinatorV2, error) { - address := common.HexToAddress(addr) - instance, err := e.client.LoadContract("VRFCoordinatorV2", address, func( - address common.Address, - backend bind.ContractBackend, - ) (interface{}, error) { - return vrf_coordinator_v2.NewVRFCoordinatorV2(address, wrappers.MustNewWrappedContractBackend(e.client, nil)) - }) - if err != nil { - return nil, err - } - return &EthereumVRFCoordinatorV2{ - address: &address, - client: e.client, - coordinator: instance.(*vrf_coordinator_v2.VRFCoordinatorV2), - }, err -} - -func (e *EthereumContractLoader) LoadVRFv2LoadTestConsumer(addr string) (VRFv2LoadTestConsumer, error) { - address := common.HexToAddress(addr) - instance, err := e.client.LoadContract("VRFV2LoadTestWithMetrics", address, func( - address common.Address, - backend bind.ContractBackend, - ) (interface{}, error) { - return vrf_load_test_with_metrics.NewVRFV2LoadTestWithMetrics(address, backend) - }) - if err != nil { - return nil, err - } - return &EthereumVRFv2LoadTestConsumer{ - client: e.client, - consumer: instance.(*vrf_load_test_with_metrics.VRFV2LoadTestWithMetrics), - address: &address, - }, err -} diff --git a/integration-tests/contracts/contract_vrf_models.go b/integration-tests/contracts/contract_vrf_models.go index aaccbad0602..8f89ddb93fa 100644 --- a/integration-tests/contracts/contract_vrf_models.go +++ b/integration-tests/contracts/contract_vrf_models.go @@ -59,7 +59,7 @@ type VRFCoordinatorV2 interface { HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error) CreateSubscription() (*types.Transaction, error) AddConsumer(subId uint64, consumerAddress string) error - Address() string + Address() *common.Address GetSubscription(ctx context.Context, subID uint64) (Subscription, error) GetOwner(ctx context.Context) (common.Address, error) PendingRequestsExist(ctx context.Context, subID uint64) (bool, error) diff --git a/integration-tests/contracts/ethereum_ocr2vrf_contracts.go b/integration-tests/contracts/ethereum_ocr2vrf_contracts.go index 260af44019f..8ca80380a28 100644 --- a/integration-tests/contracts/ethereum_ocr2vrf_contracts.go +++ b/integration-tests/contracts/ethereum_ocr2vrf_contracts.go @@ -18,7 +18,6 @@ import ( "github.com/smartcontractkit/chainlink-vrf/archive/gethwrappers/vrf_beacon_consumer" "github.com/smartcontractkit/chainlink-vrf/archive/gethwrappers/vrf_coordinator" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/batch_blockhash_store" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_coordinator_interface" ) // EthereumDKG represents DKG contract @@ -49,13 +48,6 @@ type EthereumVRFBeaconConsumer struct { vrfBeaconConsumer *vrf_beacon_consumer.BeaconVRFConsumer } -// LegacyEthereumVRFCoordinator represents VRF coordinator contract -type LegacyEthereumVRFCoordinator struct { - address *common.Address - client blockchain.EVMClient - coordinator *solidity_vrf_coordinator_interface.VRFCoordinator -} - // DeployDKG deploys DKG contract func (e *EthereumContractDeployer) DeployDKG() (DKG, error) { address, _, instance, err := e.client.DeployContract("DKG", func( diff --git a/integration-tests/contracts/ethereum_vrf_common.go b/integration-tests/contracts/ethereum_vrf_common.go index d7eafe42a07..27b60dc76ce 100644 --- a/integration-tests/contracts/ethereum_vrf_common.go +++ b/integration-tests/contracts/ethereum_vrf_common.go @@ -8,9 +8,9 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2_5" + "github.com/smartcontractkit/seth" ) type Coordinator interface { @@ -106,19 +106,6 @@ func parseRequestRandomnessLogs(coordinator Coordinator, logs []*types.Log) (*Co return randomWordsRequestedEvent, nil } -func RetrieveRequestRandomnessLogs(coordinator Coordinator, client blockchain.EVMClient, tx *types.Transaction) (*CoordinatorRandomWordsRequested, error) { - err := client.ProcessTransaction(tx) - if err != nil { - return nil, fmt.Errorf("ProcessTransaction failed, err: %w", err) - } - err = client.WaitForEvents() - if err != nil { - return nil, fmt.Errorf("WaitForEvents failed, err: %w", err) - } - receipt, err := client.GetTxReceipt(tx.Hash()) - if err != nil { - return nil, fmt.Errorf("GetTxReceipt failed, err: %w", err) - } - return parseRequestRandomnessLogs(coordinator, receipt.Logs) - +func RetrieveRequestRandomnessLogs(coordinator Coordinator, client *seth.Client, tx *seth.DecodedTransaction) (*CoordinatorRandomWordsRequested, error) { + return parseRequestRandomnessLogs(coordinator, tx.Receipt.Logs) } diff --git a/integration-tests/contracts/ethereum_vrf_contracts_seth.go b/integration-tests/contracts/ethereum_vrf_contracts_seth.go index b2ad42382b5..81f5648eccb 100644 --- a/integration-tests/contracts/ethereum_vrf_contracts_seth.go +++ b/integration-tests/contracts/ethereum_vrf_contracts_seth.go @@ -14,6 +14,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_consumer_interface" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_coordinator_interface" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_wrapper" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_test_v2" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_mock_ethlink_aggregator" ) @@ -31,6 +32,16 @@ type EthereumVRFCoordinator struct { coordinator *solidity_vrf_coordinator_interface.VRFCoordinator } +type EthereumVRFCoordinatorTestV2 struct { + address *common.Address + client *seth.Client + coordinator *vrf_coordinator_test_v2.VRFCoordinatorTestV2 +} + +func (v *EthereumVRFCoordinatorTestV2) Address() *common.Address { + return v.address +} + // EthereumVRFConsumer represents VRF consumer contract type EthereumVRFConsumer struct { address *common.Address @@ -162,6 +173,36 @@ func DeployVRFCoordinator(seth *seth.Client, linkAddr, bhsAddr string) (VRFCoord }, err } +func DeployVRFCoordinatorTestV2(seth *seth.Client, linkAddr, bhsAddr, linkEthFeedAddr string) (*EthereumVRFCoordinatorTestV2, error) { + abi, err := vrf_coordinator_test_v2.VRFCoordinatorTestV2MetaData.GetAbi() + if err != nil { + return &EthereumVRFCoordinatorTestV2{}, fmt.Errorf("failed to get VRFCoordinatorTestV2 ABI: %w", err) + } + + coordinatorDeploymentData, err := seth.DeployContract( + seth.NewTXOpts(), + "VRFCoordinatorTestV2", + *abi, + common.FromHex(vrf_coordinator_test_v2.VRFCoordinatorTestV2MetaData.Bin), + common.HexToAddress(linkAddr), + common.HexToAddress(bhsAddr), + common.HexToAddress(linkEthFeedAddr)) + if err != nil { + return &EthereumVRFCoordinatorTestV2{}, fmt.Errorf("VRFCoordinatorTestV2 instance deployment have failed: %w", err) + } + + coordinator, err := vrf_coordinator_test_v2.NewVRFCoordinatorTestV2(coordinatorDeploymentData.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRFCoordinatorTestV2{}, fmt.Errorf("failed to instantiate VRFCoordinatorTestV2 instance: %w", err) + } + + return &EthereumVRFCoordinatorTestV2{ + client: seth, + coordinator: coordinator, + address: &coordinatorDeploymentData.Address, + }, err +} + // DeployVRFConsumer deploys VRF consumer contract func DeployVRFConsumer(seth *seth.Client, linkAddr, coordinatorAddr string) (VRFConsumer, error) { abi, err := solidity_vrf_consumer_interface.VRFConsumerMetaData.GetAbi() diff --git a/integration-tests/contracts/ethereum_vrfv2_contracts.go b/integration-tests/contracts/ethereum_vrfv2_contracts.go index c5116856d48..ace5d63bd65 100644 --- a/integration-tests/contracts/ethereum_vrfv2_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2_contracts.go @@ -17,9 +17,9 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink/integration-tests/wrappers" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_test_v2" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_mock_ethlink_aggregator" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_owner" + "github.com/smartcontractkit/seth" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_consumer_v2" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2" @@ -30,23 +30,16 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_v2_consumer_wrapper" ) -// EthereumVRFCoordinatorV2 represents VRFV2 coordinator contract -type EthereumVRFCoordinatorV2 struct { - address *common.Address - client blockchain.EVMClient - coordinator *vrf_coordinator_v2.VRFCoordinatorV2 -} - type EthereumVRFOwner struct { address *common.Address - client blockchain.EVMClient + client *seth.Client vrfOwner *vrf_owner.VRFOwner } -type EthereumVRFCoordinatorTestV2 struct { +type EthereumVRFCoordinatorV2 struct { address *common.Address - client blockchain.EVMClient - coordinator *vrf_coordinator_test_v2.VRFCoordinatorTestV2 + client *seth.Client + coordinator *vrf_coordinator_v2.VRFCoordinatorV2 } // EthereumVRFConsumerV2 represents VRFv2 consumer contract @@ -66,19 +59,19 @@ type EthereumVRFv2Consumer struct { // EthereumVRFv2LoadTestConsumer represents VRFv2 consumer contract for performing Load Tests type EthereumVRFv2LoadTestConsumer struct { address *common.Address - client blockchain.EVMClient + client *seth.Client consumer *vrf_load_test_with_metrics.VRFV2LoadTestWithMetrics } type EthereumVRFV2Wrapper struct { address *common.Address - client blockchain.EVMClient + client *seth.Client wrapper *vrfv2_wrapper.VRFV2Wrapper } type EthereumVRFV2WrapperLoadTestConsumer struct { address *common.Address - client blockchain.EVMClient + client *seth.Client consumer *vrfv2_wrapper_load_test_consumer.VRFV2WrapperLoadTestConsumer } @@ -94,55 +87,81 @@ type EthereumVRFMockETHLINKFeed struct { address *common.Address } -// DeployVRFCoordinatorV2 deploys VRFV2 coordinator contract -func (e *EthereumContractDeployer) DeployVRFCoordinatorV2(linkAddr string, bhsAddr string, linkEthFeedAddr string) (VRFCoordinatorV2, error) { - address, _, instance, err := e.client.DeployContract("VRFCoordinatorV2", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return vrf_coordinator_v2.DeployVRFCoordinatorV2(auth, wrappers.MustNewWrappedContractBackend(e.client, nil), common.HexToAddress(linkAddr), common.HexToAddress(bhsAddr), common.HexToAddress(linkEthFeedAddr)) - }) +func DeployVRFCoordinatorV2(seth *seth.Client, linkAddr, bhsAddr, linkEthFeedAddr string) (VRFCoordinatorV2, error) { + abi, err := vrf_coordinator_v2.VRFCoordinatorV2MetaData.GetAbi() if err != nil { - return nil, err + return &EthereumVRFCoordinatorV2{}, fmt.Errorf("failed to get VRFCoordinatorV2 ABI: %w", err) } + + coordinatorDeploymentData, err := seth.DeployContract( + seth.NewTXOpts(), + "VRFCoordinatorV2", + *abi, + common.FromHex(vrf_coordinator_v2.VRFCoordinatorV2MetaData.Bin), + common.HexToAddress(linkAddr), + common.HexToAddress(bhsAddr), + common.HexToAddress(linkEthFeedAddr)) + if err != nil { + return &EthereumVRFCoordinatorV2{}, fmt.Errorf("VRFCoordinatorV2 instance deployment have failed: %w", err) + } + + coordinator, err := vrf_coordinator_v2.NewVRFCoordinatorV2(coordinatorDeploymentData.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRFCoordinatorV2{}, fmt.Errorf("failed to instantiate VRFCoordinatorV2 instance: %w", err) + } + return &EthereumVRFCoordinatorV2{ - client: e.client, - coordinator: instance.(*vrf_coordinator_v2.VRFCoordinatorV2), - address: address, + client: seth, + coordinator: coordinator, + address: &coordinatorDeploymentData.Address, }, err } -func (e *EthereumContractDeployer) DeployVRFOwner(coordinatorAddr string) (VRFOwner, error) { - address, _, instance, err := e.client.DeployContract("VRFOwner", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return vrf_owner.DeployVRFOwner(auth, wrappers.MustNewWrappedContractBackend(e.client, nil), common.HexToAddress(coordinatorAddr)) - }) +func LoadVRFCoordinatorV2(seth *seth.Client, addr common.Address) (*EthereumVRFCoordinatorV2, error) { + abi, err := vrf_coordinator_v2.VRFCoordinatorV2MetaData.GetAbi() if err != nil { - return nil, err + return &EthereumVRFCoordinatorV2{}, fmt.Errorf("failed to get VRFCoordinatorV2 ABI: %w", err) } - return &EthereumVRFOwner{ - client: e.client, - vrfOwner: instance.(*vrf_owner.VRFOwner), - address: address, - }, err + seth.ContractStore.AddABI("VRFCoordinatorV2", *abi) + seth.ContractStore.AddBIN("VRFCoordinatorV2", common.FromHex(vrf_coordinator_v2.VRFCoordinatorV2MetaData.Bin)) + + contract, err := vrf_coordinator_v2.NewVRFCoordinatorV2(addr, seth.Client) + if err != nil { + return &EthereumVRFCoordinatorV2{}, fmt.Errorf("failed to instantiate VRFCoordinatorV2 instance: %w", err) + } + + return &EthereumVRFCoordinatorV2{ + client: seth, + address: &addr, + coordinator: contract, + }, nil } -func (e *EthereumContractDeployer) DeployVRFCoordinatorTestV2(linkAddr string, bhsAddr string, linkEthFeedAddr string) (*EthereumVRFCoordinatorTestV2, error) { - address, _, instance, err := e.client.DeployContract("VRFCoordinatorTestV2", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return vrf_coordinator_test_v2.DeployVRFCoordinatorTestV2(auth, wrappers.MustNewWrappedContractBackend(e.client, nil), common.HexToAddress(linkAddr), common.HexToAddress(bhsAddr), common.HexToAddress(linkEthFeedAddr)) - }) +func DeployVRFOwner(seth *seth.Client, coordinatorAddr common.Address) (VRFOwner, error) { + abi, err := vrf_owner.VRFOwnerMetaData.GetAbi() if err != nil { - return nil, err + return &EthereumVRFOwner{}, fmt.Errorf("failed to get VRFOwner ABI: %w", err) + } + + data, err := seth.DeployContract( + seth.NewTXOpts(), + "VRFOwner", + *abi, + common.FromHex(vrf_owner.VRFOwnerMetaData.Bin), + coordinatorAddr) + if err != nil { + return &EthereumVRFOwner{}, fmt.Errorf("VRFOwner instance deployment have failed: %w", err) + } + + contract, err := vrf_owner.NewVRFOwner(data.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRFOwner{}, fmt.Errorf("failed to instantiate VRFOwner instance: %w", err) } - return &EthereumVRFCoordinatorTestV2{ - client: e.client, - coordinator: instance.(*vrf_coordinator_test_v2.VRFCoordinatorTestV2), - address: address, + + return &EthereumVRFOwner{ + client: seth, + vrfOwner: contract, + address: &data.Address, }, err } @@ -181,65 +200,119 @@ func (e *EthereumContractDeployer) DeployVRFv2Consumer(coordinatorAddr string) ( }, err } -// DeployVRFv2LoadTestConsumer(coordinatorAddr string) (VRFv2Consumer, error) -func (e *EthereumContractDeployer) DeployVRFv2LoadTestConsumer(coordinatorAddr string) (VRFv2LoadTestConsumer, error) { - address, _, instance, err := e.client.DeployContract("VRFV2LoadTestWithMetrics", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return vrf_load_test_with_metrics.DeployVRFV2LoadTestWithMetrics(auth, wrappers.MustNewWrappedContractBackend(e.client, nil), common.HexToAddress(coordinatorAddr)) - }) +func DeployVRFv2LoadTestConsumer(client *seth.Client, coordinatorAddr string) (VRFv2LoadTestConsumer, error) { + abi, err := vrf_load_test_with_metrics.VRFV2LoadTestWithMetricsMetaData.GetAbi() if err != nil { - return nil, err + return &EthereumVRFv2LoadTestConsumer{}, fmt.Errorf("failed to get VRFV2LoadTestWithMetrics ABI: %w", err) } + + data, err := client.DeployContract( + client.NewTXOpts(), + "VRFV2LoadTestWithMetrics", + *abi, + common.FromHex(vrf_load_test_with_metrics.VRFV2LoadTestWithMetricsMetaData.Bin), + common.HexToAddress(coordinatorAddr)) + if err != nil { + return &EthereumVRFv2LoadTestConsumer{}, fmt.Errorf("VRFV2LoadTestWithMetrics instance deployment have failed: %w", err) + } + + contract, err := vrf_load_test_with_metrics.NewVRFV2LoadTestWithMetrics(data.Address, wrappers.MustNewWrappedContractBackend(nil, client)) + if err != nil { + return &EthereumVRFv2LoadTestConsumer{}, fmt.Errorf("failed to instantiate VRFV2LoadTestWithMetrics instance: %w", err) + } + return &EthereumVRFv2LoadTestConsumer{ - client: e.client, - consumer: instance.(*vrf_load_test_with_metrics.VRFV2LoadTestWithMetrics), - address: address, + client: client, + consumer: contract, + address: &data.Address, }, err } -func (e *EthereumContractDeployer) DeployVRFV2Wrapper(linkAddr string, linkEthFeedAddr string, coordinatorAddr string) (VRFV2Wrapper, error) { - address, _, instance, err := e.client.DeployContract("VRFV2Wrapper", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return vrfv2_wrapper.DeployVRFV2Wrapper(auth, wrappers.MustNewWrappedContractBackend(e.client, nil), common.HexToAddress(linkAddr), common.HexToAddress(linkEthFeedAddr), common.HexToAddress(coordinatorAddr)) - }) +func LoadVRFv2LoadTestConsumer(seth *seth.Client, addr common.Address) (VRFv2LoadTestConsumer, error) { + abi, err := vrf_load_test_with_metrics.VRFV2LoadTestWithMetricsMetaData.GetAbi() if err != nil { - return nil, err + return &EthereumVRFv2LoadTestConsumer{}, fmt.Errorf("failed to get VRFV2LoadTestWithMetrics ABI: %w", err) + } + seth.ContractStore.AddABI("VRFV2LoadTestWithMetrics", *abi) + seth.ContractStore.AddBIN("VRFV2LoadTestWithMetrics", common.FromHex(vrf_load_test_with_metrics.VRFV2LoadTestWithMetricsMetaData.Bin)) + + contract, err := vrf_load_test_with_metrics.NewVRFV2LoadTestWithMetrics(addr, seth.Client) + if err != nil { + return &EthereumVRFv2LoadTestConsumer{}, fmt.Errorf("failed to instantiate VRFV2LoadTestWithMetrics instance: %w", err) + } + + return &EthereumVRFv2LoadTestConsumer{ + client: seth, + address: &addr, + consumer: contract, + }, nil +} + +func DeployVRFV2Wrapper(client *seth.Client, linkAddr string, linkEthFeedAddr string, coordinatorAddr string) (VRFV2Wrapper, error) { + abi, err := vrfv2_wrapper.VRFV2WrapperMetaData.GetAbi() + if err != nil { + return &EthereumVRFV2Wrapper{}, fmt.Errorf("failed to get VRFV2Wrapper ABI: %w", err) } + + data, err := client.DeployContract( + client.NewTXOpts(), + "VRFV2Wrapper", + *abi, + common.FromHex(vrfv2_wrapper.VRFV2WrapperMetaData.Bin), + common.HexToAddress(linkAddr), + common.HexToAddress(linkEthFeedAddr), + common.HexToAddress(coordinatorAddr)) + if err != nil { + return &EthereumVRFV2Wrapper{}, fmt.Errorf("VRFV2Wrapper instance deployment have failed: %w", err) + } + + contract, err := vrfv2_wrapper.NewVRFV2Wrapper(data.Address, wrappers.MustNewWrappedContractBackend(nil, client)) + if err != nil { + return &EthereumVRFV2Wrapper{}, fmt.Errorf("failed to instantiate VRFV2Wrapper instance: %w", err) + } + return &EthereumVRFV2Wrapper{ - address: address, - client: e.client, - wrapper: instance.(*vrfv2_wrapper.VRFV2Wrapper), + client: client, + wrapper: contract, + address: &data.Address, }, err } -func (e *EthereumContractDeployer) DeployVRFV2WrapperLoadTestConsumer(linkAddr string, vrfV2WrapperAddr string) (VRFv2WrapperLoadTestConsumer, error) { - address, _, instance, err := e.client.DeployContract("VRFV2WrapperLoadTestConsumer", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return vrfv2_wrapper_load_test_consumer.DeployVRFV2WrapperLoadTestConsumer(auth, wrappers.MustNewWrappedContractBackend(e.client, nil), common.HexToAddress(linkAddr), common.HexToAddress(vrfV2WrapperAddr)) - }) +func DeployVRFV2WrapperLoadTestConsumer(client *seth.Client, linkAddr string, vrfV2WrapperAddr string) (VRFv2WrapperLoadTestConsumer, error) { + abi, err := vrfv2_wrapper_load_test_consumer.VRFV2WrapperLoadTestConsumerMetaData.GetAbi() if err != nil { - return nil, err + return &EthereumVRFV2WrapperLoadTestConsumer{}, fmt.Errorf("failed to get VRFV2WrapperLoadTestConsumer ABI: %w", err) } + + data, err := client.DeployContract( + client.NewTXOpts(), + "VRFV2WrapperLoadTestConsumer", + *abi, + common.FromHex(vrfv2_wrapper_load_test_consumer.VRFV2WrapperLoadTestConsumerMetaData.Bin), + common.HexToAddress(linkAddr), common.HexToAddress(vrfV2WrapperAddr)) + if err != nil { + return &EthereumVRFV2WrapperLoadTestConsumer{}, fmt.Errorf("VRFV2WrapperLoadTestConsumer instance deployment have failed: %w", err) + } + + contract, err := vrfv2_wrapper_load_test_consumer.NewVRFV2WrapperLoadTestConsumer(data.Address, wrappers.MustNewWrappedContractBackend(nil, client)) + if err != nil { + return &EthereumVRFV2WrapperLoadTestConsumer{}, fmt.Errorf("failed to instantiate VRFV2WrapperLoadTestConsumer instance: %w", err) + } + return &EthereumVRFV2WrapperLoadTestConsumer{ - address: address, - client: e.client, - consumer: instance.(*vrfv2_wrapper_load_test_consumer.VRFV2WrapperLoadTestConsumer), + client: client, + consumer: contract, + address: &data.Address, }, err } -func (v *EthereumVRFCoordinatorV2) Address() string { - return v.address.Hex() +func (v *EthereumVRFCoordinatorV2) Address() *common.Address { + return v.address } func (v *EthereumVRFCoordinatorV2) HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } hash, err := v.coordinator.HashOfKey(opts, pubKey) @@ -251,7 +324,7 @@ func (v *EthereumVRFCoordinatorV2) HashOfKey(ctx context.Context, pubKey [2]*big func (v *EthereumVRFCoordinatorV2) GetSubscription(ctx context.Context, subID uint64) (Subscription, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } subscription, err := v.coordinator.GetSubscription(opts, subID) @@ -269,7 +342,7 @@ func (v *EthereumVRFCoordinatorV2) GetSubscription(ctx context.Context, subID ui func (v *EthereumVRFCoordinatorV2) GetOwner(ctx context.Context) (common.Address, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } coordinatorOwnerAddress, err := v.coordinator.Owner(opts) @@ -281,7 +354,7 @@ func (v *EthereumVRFCoordinatorV2) GetOwner(ctx context.Context) (common.Address func (v *EthereumVRFCoordinatorV2) GetRequestConfig(ctx context.Context) (GetRequestConfig, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } minConfirmations, maxGas, keyHashes, err := v.coordinator.GetRequestConfig(opts) @@ -299,7 +372,7 @@ func (v *EthereumVRFCoordinatorV2) GetRequestConfig(ctx context.Context) (GetReq func (v *EthereumVRFCoordinatorV2) GetConfig(ctx context.Context) (vrf_coordinator_v2.GetConfig, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } config, err := v.coordinator.GetConfig(opts) @@ -311,7 +384,7 @@ func (v *EthereumVRFCoordinatorV2) GetConfig(ctx context.Context) (vrf_coordinat func (v *EthereumVRFCoordinatorV2) GetFallbackWeiPerUnitLink(ctx context.Context) (*big.Int, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } fallbackWeiPerUnitLink, err := v.coordinator.GetFallbackWeiPerUnitLink(opts) @@ -323,7 +396,7 @@ func (v *EthereumVRFCoordinatorV2) GetFallbackWeiPerUnitLink(ctx context.Context func (v *EthereumVRFCoordinatorV2) GetFeeConfig(ctx context.Context) (vrf_coordinator_v2.GetFeeConfig, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } config, err := v.coordinator.GetFeeConfig(opts) @@ -334,83 +407,49 @@ func (v *EthereumVRFCoordinatorV2) GetFeeConfig(ctx context.Context) (vrf_coordi } func (v *EthereumVRFCoordinatorV2) SetConfig(minimumRequestConfirmations uint16, maxGasLimit uint32, stalenessSeconds uint32, gasAfterPaymentCalculation uint32, fallbackWeiPerUnitLink *big.Int, feeConfig vrf_coordinator_v2.VRFCoordinatorV2FeeConfig) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.SetConfig( - opts, + _, err := v.client.Decode(v.coordinator.SetConfig( + v.client.NewTXOpts(), minimumRequestConfirmations, maxGasLimit, stalenessSeconds, gasAfterPaymentCalculation, fallbackWeiPerUnitLink, feeConfig, - ) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + )) + return err } func (v *EthereumVRFCoordinatorV2) RegisterProvingKey( oracleAddr string, publicProvingKey [2]*big.Int, ) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.RegisterProvingKey(opts, common.HexToAddress(oracleAddr), publicProvingKey) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + _, err := v.client.Decode(v.coordinator.RegisterProvingKey(v.client.NewTXOpts(), + common.HexToAddress(oracleAddr), publicProvingKey)) + return err } func (v *EthereumVRFCoordinatorV2) TransferOwnership(to common.Address) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.TransferOwnership(opts, to) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + _, err := v.client.Decode(v.coordinator.TransferOwnership(v.client.NewTXOpts(), to)) + return err } func (v *EthereumVRFCoordinatorV2) CreateSubscription() (*types.Transaction, error) { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return nil, err - } - tx, err := v.coordinator.CreateSubscription(opts) - if err != nil { - return nil, err - } - return tx, v.client.ProcessTransaction(tx) + tx, err := v.client.Decode(v.coordinator.CreateSubscription(v.client.NewTXOpts())) + return tx.Transaction, err } func (v *EthereumVRFCoordinatorV2) AddConsumer(subId uint64, consumerAddress string) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.AddConsumer( - opts, + _, err := v.client.Decode(v.coordinator.AddConsumer( + v.client.NewTXOpts(), subId, common.HexToAddress(consumerAddress), - ) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + )) + return err } func (v *EthereumVRFCoordinatorV2) PendingRequestsExist(ctx context.Context, subID uint64) (bool, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } pendingRequestExists, err := v.coordinator.PendingRequestExists(opts, subID) @@ -421,15 +460,8 @@ func (v *EthereumVRFCoordinatorV2) PendingRequestsExist(ctx context.Context, sub } func (v *EthereumVRFCoordinatorV2) OracleWithdraw(recipient common.Address, amount *big.Int) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.OracleWithdraw(opts, recipient, amount) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + _, err := v.client.Decode(v.coordinator.OracleWithdraw(v.client.NewTXOpts(), recipient, amount)) + return err } // OwnerCancelSubscription cancels subscription, @@ -437,18 +469,11 @@ func (v *EthereumVRFCoordinatorV2) OracleWithdraw(recipient common.Address, amou // down not check if pending requests for a sub exist, // outstanding requests may fail onchain func (v *EthereumVRFCoordinatorV2) OwnerCancelSubscription(subID uint64) (*types.Transaction, error) { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return nil, err - } - tx, err := v.coordinator.OwnerCancelSubscription( - opts, + tx, err := v.client.Decode(v.coordinator.OwnerCancelSubscription( + v.client.NewTXOpts(), subID, - ) - if err != nil { - return nil, err - } - return tx, v.client.ProcessTransaction(tx) + )) + return tx.Transaction, err } func (v *EthereumVRFCoordinatorV2) ParseSubscriptionCanceled(log types.Log) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) { @@ -483,23 +508,16 @@ func (v *EthereumVRFCoordinatorV2) ParseLog(log types.Log) (generated.AbigenLog, // return funds to specified address, // checks if pending requests for a sub exist func (v *EthereumVRFCoordinatorV2) CancelSubscription(subID uint64, to common.Address) (*types.Transaction, error) { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return nil, err - } - tx, err := v.coordinator.CancelSubscription( - opts, + tx, err := v.client.Decode(v.coordinator.CancelSubscription( + v.client.NewTXOpts(), subID, to, - ) - if err != nil { - return nil, err - } - return tx, v.client.ProcessTransaction(tx) + )) + return tx.Transaction, err } func (v *EthereumVRFCoordinatorV2) FindSubscriptionID(subID uint64) (uint64, error) { - owner := v.client.GetDefaultWallet().Address() + owner := v.client.Addresses[0] subscriptionIterator, err := v.coordinator.FilterSubscriptionCreated( nil, []uint64{subID}, @@ -848,15 +866,11 @@ func (v *EthereumVRFv2LoadTestConsumer) RequestRandomness( numWords uint32, requestCount uint16, ) (*CoordinatorRandomWordsRequested, error) { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return nil, err - } - tx, err := v.consumer.RequestRandomWords(opts, subID, requestConfirmations, keyHash, callbackGasLimit, numWords, requestCount) + tx, err := v.client.Decode(v.consumer.RequestRandomWords(v.client.NewTXOpts(), subID, requestConfirmations, keyHash, callbackGasLimit, numWords, requestCount)) if err != nil { return nil, fmt.Errorf("RequestRandomWords failed, err: %w", err) } - randomWordsRequestedEvent, err := RetrieveRequestRandomnessLogs(coordinator, v.client, tx) + randomWordsRequestedEvent, err := parseRequestRandomnessLogs(coordinator, tx.Receipt.Logs) if err != nil { return nil, err } @@ -873,12 +887,8 @@ func (v *EthereumVRFv2LoadTestConsumer) RequestRandomWordsWithForceFulfill( subTopUpAmount *big.Int, linkAddress common.Address, ) (*CoordinatorRandomWordsRequested, error) { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return nil, err - } - tx, err := v.consumer.RequestRandomWordsWithForceFulfill( - opts, + tx, err := v.client.Decode(v.consumer.RequestRandomWordsWithForceFulfill( + v.client.NewTXOpts(), requestConfirmations, keyHash, callbackGasLimit, @@ -886,11 +896,11 @@ func (v *EthereumVRFv2LoadTestConsumer) RequestRandomWordsWithForceFulfill( requestCount, subTopUpAmount, linkAddress, - ) + )) if err != nil { return nil, fmt.Errorf("RequestRandomWords failed, err: %w", err) } - randomWordsRequestedEvent, err := RetrieveRequestRandomnessLogs(coordinator, v.client, tx) + randomWordsRequestedEvent, err := parseRequestRandomnessLogs(coordinator, tx.Receipt.Logs) if err != nil { return nil, err } @@ -913,40 +923,33 @@ func (v *EthereumVRFv2Consumer) GetLastRequestId(ctx context.Context) (*big.Int, func (v *EthereumVRFv2LoadTestConsumer) GetRequestStatus(ctx context.Context, requestID *big.Int) (vrf_load_test_with_metrics.GetRequestStatus, error) { return v.consumer.GetRequestStatus(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }, requestID) } func (v *EthereumVRFv2LoadTestConsumer) GetLastRequestId(ctx context.Context) (*big.Int, error) { return v.consumer.SLastRequestId(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) } func (v *EthereumVRFv2LoadTestConsumer) ResetMetrics() error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.consumer.Reset(opts) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + _, err := v.client.Decode(v.consumer.Reset(v.client.NewTXOpts())) + return err } func (v *EthereumVRFv2LoadTestConsumer) GetLoadTestMetrics(ctx context.Context) (*VRFLoadTestMetrics, error) { requestCount, err := v.consumer.SRequestCount(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) if err != nil { return &VRFLoadTestMetrics{}, err } fulfilmentCount, err := v.consumer.SResponseCount(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) @@ -954,14 +957,14 @@ func (v *EthereumVRFv2LoadTestConsumer) GetLoadTestMetrics(ctx context.Context) return &VRFLoadTestMetrics{}, err } averageFulfillmentInMillions, err := v.consumer.SAverageFulfillmentInMillions(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) if err != nil { return &VRFLoadTestMetrics{}, err } slowestFulfillment, err := v.consumer.SSlowestFulfillment(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) @@ -969,7 +972,7 @@ func (v *EthereumVRFv2LoadTestConsumer) GetLoadTestMetrics(ctx context.Context) return &VRFLoadTestMetrics{}, err } fastestFulfillment, err := v.consumer.SFastestFulfillment(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) if err != nil { @@ -995,27 +998,20 @@ func (v *EthereumVRFV2Wrapper) Address() string { } func (v *EthereumVRFV2Wrapper) SetConfig(wrapperGasOverhead uint32, coordinatorGasOverhead uint32, wrapperPremiumPercentage uint8, keyHash [32]byte, maxNumWords uint8) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.wrapper.SetConfig( - opts, + _, err := v.client.Decode(v.wrapper.SetConfig( + v.client.NewTXOpts(), wrapperGasOverhead, coordinatorGasOverhead, wrapperPremiumPercentage, keyHash, maxNumWords, - ) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + )) + return err } func (v *EthereumVRFV2Wrapper) GetSubID(ctx context.Context) (uint64, error) { return v.wrapper.SUBSCRIPTIONID(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) } @@ -1025,23 +1021,16 @@ func (v *EthereumVRFV2WrapperLoadTestConsumer) Address() string { } func (v *EthereumVRFV2WrapperLoadTestConsumer) Fund(ethAmount *big.Float) error { - gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{}) - if err != nil { - return err - } - return v.client.Fund(v.address.Hex(), ethAmount, gasEstimates) + panic("do not use this function, use actions_seth.SendFunds() instead, otherwise we will have to deal with circular dependencies") } func (v *EthereumVRFV2WrapperLoadTestConsumer) RequestRandomness(coordinator Coordinator, requestConfirmations uint16, callbackGasLimit uint32, numWords uint32, requestCount uint16) (*CoordinatorRandomWordsRequested, error) { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) + tx, err := v.client.Decode(v.consumer.MakeRequests(v.client.NewTXOpts(), + callbackGasLimit, requestConfirmations, numWords, requestCount)) if err != nil { return nil, err } - tx, err := v.consumer.MakeRequests(opts, callbackGasLimit, requestConfirmations, numWords, requestCount) - if err != nil { - return nil, err - } - randomWordsRequestedEvent, err := RetrieveRequestRandomnessLogs(coordinator, v.client, tx) + randomWordsRequestedEvent, err := parseRequestRandomnessLogs(coordinator, tx.Receipt.Logs) if err != nil { return nil, err } @@ -1050,35 +1039,35 @@ func (v *EthereumVRFV2WrapperLoadTestConsumer) RequestRandomness(coordinator Coo func (v *EthereumVRFV2WrapperLoadTestConsumer) GetRequestStatus(ctx context.Context, requestID *big.Int) (vrfv2_wrapper_load_test_consumer.GetRequestStatus, error) { return v.consumer.GetRequestStatus(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }, requestID) } func (v *EthereumVRFV2WrapperLoadTestConsumer) GetLastRequestId(ctx context.Context) (*big.Int, error) { return v.consumer.SLastRequestId(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) } func (v *EthereumVRFV2WrapperLoadTestConsumer) GetWrapper(ctx context.Context) (common.Address, error) { return v.consumer.IVrfV2Wrapper(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) } func (v *EthereumVRFV2WrapperLoadTestConsumer) GetLoadTestMetrics(ctx context.Context) (*VRFLoadTestMetrics, error) { requestCount, err := v.consumer.SRequestCount(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) if err != nil { return nil, err } fulfilmentCount, err := v.consumer.SResponseCount(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) @@ -1086,14 +1075,14 @@ func (v *EthereumVRFV2WrapperLoadTestConsumer) GetLoadTestMetrics(ctx context.Co return nil, err } averageFulfillmentInMillions, err := v.consumer.SAverageFulfillmentInMillions(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) if err != nil { return nil, err } slowestFulfillment, err := v.consumer.SSlowestFulfillment(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) @@ -1101,7 +1090,7 @@ func (v *EthereumVRFV2WrapperLoadTestConsumer) GetLoadTestMetrics(ctx context.Co return nil, err } fastestFulfillment, err := v.consumer.SFastestFulfillment(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) if err != nil { @@ -1127,30 +1116,16 @@ func (v *EthereumVRFOwner) Address() string { } func (v *EthereumVRFOwner) SetAuthorizedSenders(senders []common.Address) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.vrfOwner.SetAuthorizedSenders( - opts, + _, err := v.client.Decode(v.vrfOwner.SetAuthorizedSenders( + v.client.NewTXOpts(), senders, - ) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + )) + return err } func (v *EthereumVRFOwner) AcceptVRFOwnership() error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.vrfOwner.AcceptVRFOwnership(opts) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + _, err := v.client.Decode(v.vrfOwner.AcceptVRFOwnership(v.client.NewTXOpts())) + return err } func (v *EthereumVRFOwner) WaitForRandomWordsForcedEvent(requestIDs []*big.Int, subIds []uint64, senders []common.Address, timeout time.Duration) (*vrf_owner.VRFOwnerRandomWordsForced, error) { @@ -1174,22 +1149,11 @@ func (v *EthereumVRFOwner) WaitForRandomWordsForcedEvent(requestIDs []*big.Int, } func (v *EthereumVRFOwner) OwnerCancelSubscription(subID uint64) (*types.Transaction, error) { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return nil, err - } - tx, err := v.vrfOwner.OwnerCancelSubscription( - opts, + tx, err := v.client.Decode(v.vrfOwner.OwnerCancelSubscription( + v.client.NewTXOpts(), subID, - ) - if err != nil { - return nil, err - } - return tx, v.client.ProcessTransaction(tx) -} - -func (v *EthereumVRFCoordinatorTestV2) Address() string { - return v.address.Hex() + )) + return tx.Transaction, err } func (v *EthereumVRFMockETHLINKFeed) Address() string { diff --git a/integration-tests/docker/test_env/test_env.go b/integration-tests/docker/test_env/test_env.go index d54f51eeea1..08943b87501 100644 --- a/integration-tests/docker/test_env/test_env.go +++ b/integration-tests/docker/test_env/test_env.go @@ -17,6 +17,7 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/docker/test_env" "github.com/smartcontractkit/chainlink-testing-framework/logging" "github.com/smartcontractkit/chainlink-testing-framework/logstream" + "github.com/smartcontractkit/chainlink-testing-framework/networks" "github.com/smartcontractkit/chainlink-testing-framework/utils/runid" "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" @@ -323,6 +324,11 @@ func (te *CLClusterTestEnv) GetSethClient(chainId int64) (*seth.Client, error) { return nil, fmt.Errorf("no Seth client available for chain ID %d", chainId) } +func (te *CLClusterTestEnv) GetSethClientForSelectedNetwork() (*seth.Client, error) { + n := networks.MustGetSelectedNetworkConfig(te.TestConfig.GetNetworkConfig())[0] + return te.GetSethClient(n.ChainID) +} + func (te *CLClusterTestEnv) GetRpcProvider(chainId int64) (*test_env.RpcProvider, error) { if rpc, ok := te.rpcProviders[chainId]; ok { return rpc, nil From 874e0f0acd61273db84a8ce5833001f568948dac Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Wed, 24 Apr 2024 16:04:38 +0200 Subject: [PATCH 04/43] wip 4 --- integration-tests/actions/actions.go | 22 +++++++++---------- .../actions/vrf/common/actions.go | 22 ++++++++++--------- .../actions/vrf/vrfv2/contract_steps.go | 10 ++++----- .../actions/vrf/vrfv2/setup_steps.go | 5 +++-- 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/integration-tests/actions/actions.go b/integration-tests/actions/actions.go index f5c91b63527..8e83d17c77a 100644 --- a/integration-tests/actions/actions.go +++ b/integration-tests/actions/actions.go @@ -21,6 +21,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/common" "github.com/google/uuid" + "github.com/rs/zerolog" "github.com/rs/zerolog/log" "go.uber.org/zap/zapcore" @@ -31,8 +32,10 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/testreporters" "github.com/smartcontractkit/chainlink-testing-framework/utils/conversions" "github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext" + actions_seth "github.com/smartcontractkit/chainlink/integration-tests/actions/seth" "github.com/smartcontractkit/chainlink/integration-tests/client" "github.com/smartcontractkit/chainlink/integration-tests/contracts" + "github.com/smartcontractkit/seth" ) // ContractDeploymentInterval After how many contract actions to wait before starting any more @@ -470,19 +473,14 @@ func GenerateWallet() (common.Address, error) { } // todo - move to CTF -func FundAddress(client blockchain.EVMClient, sendingKey string, fundingToSendEth *big.Float) error { - address := common.HexToAddress(sendingKey) - gasEstimates, err := client.EstimateGas(ethereum.CallMsg{ - To: &address, - }) - if err != nil { - return err - } - err = client.Fund(sendingKey, fundingToSendEth, gasEstimates) - if err != nil { - return err +func FundAddress(l zerolog.Logger, client *seth.Client, sendingKey string, fundingToSendEth *big.Int) error { + payload := actions_seth.FundsToSendPayload{ + ToAddress: common.HexToAddress(sendingKey), + Amount: fundingToSendEth, } - return nil + + _, err := actions_seth.SendFunds(l, client, payload) + return err } // todo - move to CTF diff --git a/integration-tests/actions/vrf/common/actions.go b/integration-tests/actions/vrf/common/actions.go index 854cdb55f63..43d37d49dcd 100644 --- a/integration-tests/actions/vrf/common/actions.go +++ b/integration-tests/actions/vrf/common/actions.go @@ -11,7 +11,6 @@ import ( "github.com/google/uuid" "github.com/rs/zerolog" - "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink-testing-framework/utils/conversions" "github.com/smartcontractkit/chainlink/integration-tests/actions" "github.com/smartcontractkit/chainlink/integration-tests/client" @@ -22,13 +21,14 @@ import ( ) func CreateFundAndGetSendingKeys( + l zerolog.Logger, client *seth.Client, node *VRFNode, chainlinkNodeFunding float64, numberOfTxKeysToCreate int, chainID *big.Int, ) ([]string, []common.Address, error) { - newNativeTokenKeyAddresses, err := CreateAndFundSendingKeys(client, node, chainlinkNodeFunding, numberOfTxKeysToCreate, chainID) + newNativeTokenKeyAddresses, err := CreateAndFundSendingKeys(l, client, node, chainlinkNodeFunding, numberOfTxKeysToCreate, chainID) if err != nil { return nil, nil, err } @@ -45,6 +45,7 @@ func CreateFundAndGetSendingKeys( } func CreateAndFundSendingKeys( + l zerolog.Logger, client *seth.Client, node *VRFNode, chainlinkNodeFunding float64, @@ -61,7 +62,7 @@ func CreateAndFundSendingKeys( return nil, fmt.Errorf("error creating transaction key - response code, err %d", response.StatusCode) } newNativeTokenKeyAddresses = append(newNativeTokenKeyAddresses, newTxKey.Data.Attributes.Address) - err = actions.FundAddress(client, newTxKey.Data.Attributes.Address, big.NewFloat(chainlinkNodeFunding)) + err = actions.FundAddress(l, client, newTxKey.Data.Attributes.Address, conversions.EtherToWei(big.NewFloat(chainlinkNodeFunding))) if err != nil { return nil, err } @@ -86,6 +87,7 @@ func SetupBHSNode( } bhsTXKeyAddressStrings, _, err := CreateFundAndGetSendingKeys( + l, sethClient, bhsNode, txKeyFunding, @@ -159,12 +161,13 @@ func SetupBHFNode( l zerolog.Logger, bhfNode *VRFNode, ) error { - evmClient, err := env.GetEVMClient(chainID.Int64()) + sethClient, err := env.GetSethClient(chainID.Int64()) if err != nil { return err } bhfTXKeyAddressStrings, _, err := CreateFundAndGetSendingKeys( - evmClient, + l, + sethClient, bhfNode, txKeyFunding, numberOfTxKeysToCreate, @@ -307,26 +310,25 @@ func CreateVRFKeyOnVRFNode(vrfNode *VRFNode, l zerolog.Logger) (*client.VRFKey, return vrfKey, pubKeyCompressed, nil } -func FundNodesIfNeeded(ctx context.Context, existingEnvConfig *vrf_common_config.ExistingEnvConfig, client blockchain.EVMClient, l zerolog.Logger) error { +func FundNodesIfNeeded(ctx context.Context, existingEnvConfig *vrf_common_config.ExistingEnvConfig, client *seth.Client, l zerolog.Logger) error { if *existingEnvConfig.NodeSendingKeyFundingMin > 0 { for _, sendingKey := range existingEnvConfig.NodeSendingKeys { address := common.HexToAddress(sendingKey) - sendingKeyBalance, err := client.BalanceAt(ctx, address) + sendingKeyBalance, err := client.Client.BalanceAt(context.Background(), address, nil) if err != nil { return err } fundingAtLeast := conversions.EtherToWei(big.NewFloat(*existingEnvConfig.NodeSendingKeyFundingMin)) fundingToSendWei := new(big.Int).Sub(fundingAtLeast, sendingKeyBalance) - fundingToSendEth := conversions.WeiToEther(fundingToSendWei) log := l.Info(). Str("Sending Key", sendingKey). Str("Sending Key Current Balance", sendingKeyBalance.String()). Str("Should have at least", fundingAtLeast.String()) if fundingToSendWei.Cmp(big.NewInt(0)) == 1 { log. - Str("Funding Amount in ETH", fundingToSendEth.String()). + Str("Funding Amount in ETH", fundingToSendWei.String()). Msg("Funding Node's Sending Key") - err := actions.FundAddress(client, sendingKey, fundingToSendEth) + err := actions.FundAddress(l, client, sendingKey, fundingToSendWei) if err != nil { return err } diff --git a/integration-tests/actions/vrf/vrfv2/contract_steps.go b/integration-tests/actions/vrf/vrfv2/contract_steps.go index a2b2ed4ef51..6dacc8b228d 100644 --- a/integration-tests/actions/vrf/vrfv2/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2/contract_steps.go @@ -55,7 +55,7 @@ func DeployVRFV2Contracts( } coordinatorAddress = testCoordinator.Address() } else { - coordinator, err := contracts.DeployVRFCoordinatorV2(linkTokenContract.Address(), bhs.Address(), linkEthFeedContract.Address()) + coordinator, err := contracts.DeployVRFCoordinatorV2(sethClient, linkTokenContract.Address(), bhs.Address(), linkEthFeedContract.Address()) if err != nil { return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrDeployCoordinator, err) } @@ -185,7 +185,7 @@ func SetupVRFV2Contracts( ReqsForTier4: big.NewInt(*vrfv2Config.ReqsForTier4), ReqsForTier5: big.NewInt(*vrfv2Config.ReqsForTier5)} - l.Info().Str("Coordinator", vrfContracts.CoordinatorV2.Address()).Msg("Setting Coordinator Config") + l.Info().Str("Coordinator", vrfContracts.CoordinatorV2.Address().Hex()).Msg("Setting Coordinator Config") err = vrfContracts.CoordinatorV2.SetConfig( *vrfv2Config.MinimumConfirmations, *vrfv2Config.MaxGasLimitCoordinatorConfig, @@ -213,7 +213,7 @@ func SetupVRFV2Contracts( func setupVRFOwnerContract(env *test_env.CLClusterTestEnv, chainID int64, contracts *vrfcommon.VRFContracts, allNativeTokenKeyAddressStrings []string, allNativeTokenKeyAddresses []common.Address, l zerolog.Logger) error { l.Info().Msg("Setting up VRFOwner contract") l.Info(). - Str("Coordinator", contracts.CoordinatorV2.Address()). + Str("Coordinator", contracts.CoordinatorV2.Address().Hex()). Str("VRFOwner", contracts.VRFOwner.Address()). Msg("Transferring ownership of Coordinator to VRFOwner") err := contracts.CoordinatorV2.TransferOwnership(common.HexToAddress(contracts.VRFOwner.Address())) @@ -421,7 +421,7 @@ func FundVRFCoordinatorV2Subscription( if err != nil { return fmt.Errorf("%s, err %w", vrfcommon.ErrABIEncodingFunding, err) } - _, err = linkToken.TransferAndCall(coordinator.Address(), linkFundingAmountJuels, encodedSubId) + _, err = linkToken.TransferAndCall(coordinator.Address().Hex(), linkFundingAmountJuels, encodedSubId) if err != nil { return fmt.Errorf("%s, err %w", vrfcommon.ErrSendingLinkToken, err) } @@ -697,7 +697,7 @@ func SetupNewConsumersAndSubs( numberOfSubToCreate int, l zerolog.Logger, ) ([]contracts.VRFv2LoadTestConsumer, []uint64, error) { - consumers, err := DeployVRFV2Consumers(env.ContractDeployer, coordinator.Address(), numberOfConsumerContractsToDeployAndAddToSub) + consumers, err := DeployVRFV2Consumers(env.ContractDeployer, coordinator.Address().Hex(), numberOfConsumerContractsToDeployAndAddToSub) if err != nil { return nil, nil, fmt.Errorf("err: %w", err) } diff --git a/integration-tests/actions/vrf/vrfv2/setup_steps.go b/integration-tests/actions/vrf/vrfv2/setup_steps.go index c28e82b645b..f947167bbe8 100644 --- a/integration-tests/actions/vrf/vrfv2/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2/setup_steps.go @@ -135,6 +135,7 @@ func SetupVRFV2Environment( } vrfTXKeyAddressStrings, vrfTXKeyAddresses, err := vrfcommon.CreateFundAndGetSendingKeys( + l, sethClient, nodeTypeToNodeMap[vrfcommon.VRF], *vrfv2TestConfig.GetCommonConfig().ChainlinkNodeFunding, @@ -420,12 +421,12 @@ func SetupVRFV2ForExistingEnv(ctx context.Context, t *testing.T, testConfig tc.T return nil, nil, nil, fmt.Errorf("%s, err: %w", "error loading LinkToken", err) } - evmClient, err := env.GetEVMClient(chainID) + sethClient, err := env.GetSethClient(chainID) if err != nil { return nil, nil, nil, err } - err = vrfcommon.FundNodesIfNeeded(ctx, commonExistingEnvConfig, evmClient, l) + err = vrfcommon.FundNodesIfNeeded(ctx, commonExistingEnvConfig, sethClient, l) if err != nil { return nil, nil, nil, fmt.Errorf("err: %w", err) } From 9a6a278399b670ef5ee7371a4d64f715e25c572a Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Wed, 24 Apr 2024 16:07:45 +0200 Subject: [PATCH 05/43] wip 5 --- integration-tests/actions/actions.go | 14 ------------ .../actions/vrf/common/actions.go | 12 +++++++--- .../contracts/ethereum_contracts_seth.go | 22 +++++++++++++++++++ 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/integration-tests/actions/actions.go b/integration-tests/actions/actions.go index 8e83d17c77a..a0cb01ec19f 100644 --- a/integration-tests/actions/actions.go +++ b/integration-tests/actions/actions.go @@ -21,7 +21,6 @@ import ( "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/common" "github.com/google/uuid" - "github.com/rs/zerolog" "github.com/rs/zerolog/log" "go.uber.org/zap/zapcore" @@ -32,10 +31,8 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/testreporters" "github.com/smartcontractkit/chainlink-testing-framework/utils/conversions" "github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext" - actions_seth "github.com/smartcontractkit/chainlink/integration-tests/actions/seth" "github.com/smartcontractkit/chainlink/integration-tests/client" "github.com/smartcontractkit/chainlink/integration-tests/contracts" - "github.com/smartcontractkit/seth" ) // ContractDeploymentInterval After how many contract actions to wait before starting any more @@ -472,17 +469,6 @@ func GenerateWallet() (common.Address, error) { return crypto.PubkeyToAddress(*publicKeyECDSA), nil } -// todo - move to CTF -func FundAddress(l zerolog.Logger, client *seth.Client, sendingKey string, fundingToSendEth *big.Int) error { - payload := actions_seth.FundsToSendPayload{ - ToAddress: common.HexToAddress(sendingKey), - Amount: fundingToSendEth, - } - - _, err := actions_seth.SendFunds(l, client, payload) - return err -} - // todo - move to CTF func GetTxFromAddress(tx *types.Transaction) (string, error) { from, err := types.Sender(types.LatestSignerForChainID(tx.ChainId()), tx) diff --git a/integration-tests/actions/vrf/common/actions.go b/integration-tests/actions/vrf/common/actions.go index 43d37d49dcd..7ee76d22cd2 100644 --- a/integration-tests/actions/vrf/common/actions.go +++ b/integration-tests/actions/vrf/common/actions.go @@ -12,7 +12,7 @@ import ( "github.com/rs/zerolog" "github.com/smartcontractkit/chainlink-testing-framework/utils/conversions" - "github.com/smartcontractkit/chainlink/integration-tests/actions" + actions_seth "github.com/smartcontractkit/chainlink/integration-tests/actions/seth" "github.com/smartcontractkit/chainlink/integration-tests/client" "github.com/smartcontractkit/chainlink/integration-tests/contracts" "github.com/smartcontractkit/chainlink/integration-tests/docker/test_env" @@ -62,7 +62,10 @@ func CreateAndFundSendingKeys( return nil, fmt.Errorf("error creating transaction key - response code, err %d", response.StatusCode) } newNativeTokenKeyAddresses = append(newNativeTokenKeyAddresses, newTxKey.Data.Attributes.Address) - err = actions.FundAddress(l, client, newTxKey.Data.Attributes.Address, conversions.EtherToWei(big.NewFloat(chainlinkNodeFunding))) + _, err = actions_seth.SendFunds(l, client, actions_seth.FundsToSendPayload{ + ToAddress: common.HexToAddress(newTxKey.Data.Attributes.Address), + Amount: conversions.EtherToWei(big.NewFloat(chainlinkNodeFunding)), + }) if err != nil { return nil, err } @@ -328,7 +331,10 @@ func FundNodesIfNeeded(ctx context.Context, existingEnvConfig *vrf_common_config log. Str("Funding Amount in ETH", fundingToSendWei.String()). Msg("Funding Node's Sending Key") - err := actions.FundAddress(l, client, sendingKey, fundingToSendWei) + _, err := actions_seth.SendFunds(l, client, actions_seth.FundsToSendPayload{ + ToAddress: common.HexToAddress(sendingKey), + Amount: fundingToSendWei, + }) if err != nil { return err } diff --git a/integration-tests/contracts/ethereum_contracts_seth.go b/integration-tests/contracts/ethereum_contracts_seth.go index 1d02c77bbe8..5302854b0ba 100644 --- a/integration-tests/contracts/ethereum_contracts_seth.go +++ b/integration-tests/contracts/ethereum_contracts_seth.go @@ -608,6 +608,28 @@ func DeployLinkTokenContract(l zerolog.Logger, client *seth.Client) (*EthereumLi }, nil } +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)) + + 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, + address: 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") From 3e5d2e36045d8b56df61c16e695d22100f9b8891 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Wed, 24 Apr 2024 16:28:20 +0200 Subject: [PATCH 06/43] wip 6 --- .../actions/vrf/vrfv2plus/contract_steps.go | 36 +-- .../actions/vrf/vrfv2plus/setup_steps.go | 46 +--- .../contracts/contract_deployer.go | 3 - .../contracts/ethereum_vrf_common.go | 5 - .../contracts/ethereum_vrfv2plus_contracts.go | 210 +++++++++--------- 5 files changed, 124 insertions(+), 176 deletions(-) diff --git a/integration-tests/actions/vrf/vrfv2plus/contract_steps.go b/integration-tests/actions/vrf/vrfv2plus/contract_steps.go index 143b1e2cd9b..bc8300f3444 100644 --- a/integration-tests/actions/vrf/vrfv2plus/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/contract_steps.go @@ -20,6 +20,7 @@ import ( tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig" vrfv2plus_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/vrfv2plus" chainlinkutils "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" + "github.com/smartcontractkit/seth" ) func DeployVRFV2_5Contracts( @@ -58,10 +59,10 @@ func DeployVRFV2_5Contracts( }, nil } -func DeployVRFV2PlusConsumers(contractDeployer contracts.ContractDeployer, coordinator contracts.VRFCoordinatorV2_5, consumerContractsAmount int) ([]contracts.VRFv2PlusLoadTestConsumer, error) { +func DeployVRFV2PlusConsumers(client *seth.Client, coordinator contracts.VRFCoordinatorV2_5, consumerContractsAmount int) ([]contracts.VRFv2PlusLoadTestConsumer, error) { var consumers []contracts.VRFv2PlusLoadTestConsumer for i := 1; i <= consumerContractsAmount; i++ { - loadTestConsumer, err := contractDeployer.DeployVRFv2PlusLoadTestConsumer(coordinator.Address()) + loadTestConsumer, err := contracts.DeployVRFv2PlusLoadTestConsumer(client, coordinator.Address()) if err != nil { return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, ErrAdvancedConsumer, err) } @@ -406,32 +407,21 @@ func RequestRandomnessAndWaitForFulfillment( } func DeployVRFV2PlusDirectFundingContracts( - contractDeployer contracts.ContractDeployer, - chainClient blockchain.EVMClient, + sethClient *seth.Client, linkTokenAddress string, linkEthFeedAddress string, coordinator contracts.VRFCoordinatorV2_5, consumerContractsAmount int, wrapperSubId *big.Int, ) (*VRFV2PlusWrapperContracts, error) { - - vrfv2PlusWrapper, err := contractDeployer.DeployVRFV2PlusWrapper(linkTokenAddress, linkEthFeedAddress, coordinator.Address(), wrapperSubId) + vrfv2PlusWrapper, err := contracts.DeployVRFV2PlusWrapper(sethClient, linkTokenAddress, linkEthFeedAddress, coordinator.Address(), wrapperSubId) if err != nil { return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, ErrDeployWrapper, err) } - err = chainClient.WaitForEvents() - if err != nil { - return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitTXsComplete, err) - } - - consumers, err := DeployVRFV2PlusWrapperConsumers(contractDeployer, vrfv2PlusWrapper, consumerContractsAmount) + consumers, err := DeployVRFV2PlusWrapperConsumers(sethClient, vrfv2PlusWrapper, consumerContractsAmount) if err != nil { return nil, err } - err = chainClient.WaitForEvents() - if err != nil { - return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitTXsComplete, err) - } return &VRFV2PlusWrapperContracts{vrfv2PlusWrapper, consumers}, nil } @@ -525,10 +515,10 @@ func WaitRandomWordsFulfilledEvent( return randomWordsFulfilledEvent, err } -func DeployVRFV2PlusWrapperConsumers(contractDeployer contracts.ContractDeployer, vrfV2PlusWrapper contracts.VRFV2PlusWrapper, consumerContractsAmount int) ([]contracts.VRFv2PlusWrapperLoadTestConsumer, error) { +func DeployVRFV2PlusWrapperConsumers(client *seth.Client, vrfV2PlusWrapper contracts.VRFV2PlusWrapper, consumerContractsAmount int) ([]contracts.VRFv2PlusWrapperLoadTestConsumer, error) { var consumers []contracts.VRFv2PlusWrapperLoadTestConsumer for i := 1; i <= consumerContractsAmount; i++ { - loadTestConsumer, err := contractDeployer.DeployVRFV2PlusWrapperLoadTestConsumer(vrfV2PlusWrapper.Address()) + loadTestConsumer, err := contracts.DeployVRFV2PlusWrapperLoadTestConsumer(client, vrfV2PlusWrapper.Address()) if err != nil { return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, ErrAdvancedConsumer, err) } @@ -596,17 +586,13 @@ func SetupNewConsumersAndSubs( numberOfSubToCreate int, l zerolog.Logger, ) ([]contracts.VRFv2PlusLoadTestConsumer, []*big.Int, error) { - consumers, err := DeployVRFV2PlusConsumers(env.ContractDeployer, coordinator, consumerContractsAmount) - if err != nil { - return nil, nil, fmt.Errorf("err: %w", err) - } - evmClient, err := env.GetEVMClient(chainID) + sethClient, err := env.GetSethClient(chainID) if err != nil { return nil, nil, err } - err = evmClient.WaitForEvents() + consumers, err := DeployVRFV2PlusConsumers(sethClient, coordinator, consumerContractsAmount) if err != nil { - return nil, nil, fmt.Errorf("%s, err: %w", vrfcommon.ErrWaitTXsComplete, err) + return nil, nil, fmt.Errorf("err: %w", err) } l.Info(). Str("Coordinator", *testConfig.VRFv2Plus.ExistingEnvConfig.ExistingEnvConfig.CoordinatorAddress). diff --git a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go index 0b7be600cc2..b030a9b9a40 100644 --- a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go @@ -108,13 +108,14 @@ func SetupVRFV2_5Environment( return nil, nil, nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrCreatingProvingKeyHash, err) } - evmClient, err := env.GetEVMClient(chainID) + sethClient, err := env.GetSethClient(chainID) if err != nil { return nil, nil, nil, err } vrfTXKeyAddressStrings, _, err := vrfcommon.CreateFundAndGetSendingKeys( - evmClient, + l, + sethClient, nodeTypeToNodeMap[vrfcommon.VRF], *vrfv2PlusTestConfig.GetCommonConfig().ChainlinkNodeFunding, numberOfTxKeysToCreate, @@ -123,10 +124,6 @@ func SetupVRFV2_5Environment( if err != nil { return nil, nil, nil, err } - err = evmClient.WaitForEvents() - if err != nil { - return nil, nil, nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitTXsComplete, err) - } nodeTypeToNodeMap[vrfcommon.VRF].TXKeyAddressStrings = vrfTXKeyAddressStrings @@ -258,26 +255,19 @@ func SetupVRFV2PlusWrapperEnvironment( vrfv2PlusConfig := vrfv2PlusTestConfig.GetVRFv2PlusConfig().General - evmClient, err := env.GetEVMClient(chainID) + sethClient, err := env.GetSethClient(chainID) if err != nil { return nil, nil, err } wrapperContracts, err := DeployVRFV2PlusDirectFundingContracts( - env.ContractDeployer, - evmClient, + sethClient, linkToken.Address(), mockNativeLINKFeed.Address(), coordinator, wrapperConsumerContractsAmount, wrapperSubId, ) - if err != nil { - return nil, nil, err - } - - err = evmClient.WaitForEvents() - if err != nil { return nil, nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitTXsComplete, err) } @@ -288,10 +278,6 @@ func SetupVRFV2PlusWrapperEnvironment( return nil, nil, err } - err = evmClient.WaitForEvents() - if err != nil { - return nil, nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitTXsComplete, err) - } err = wrapperContracts.VRFV2PlusWrapper.SetConfig( *vrfv2PlusConfig.WrapperGasOverhead, *vrfv2PlusConfig.CoordinatorGasOverheadNative, @@ -310,22 +296,12 @@ func SetupVRFV2PlusWrapperEnvironment( return nil, nil, err } - err = evmClient.WaitForEvents() - if err != nil { - return nil, nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitTXsComplete, err) - } - //fund sub wrapperSubID, err := wrapperContracts.VRFV2PlusWrapper.GetSubID(ctx) if err != nil { return nil, nil, err } - err = evmClient.WaitForEvents() - if err != nil { - return nil, nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitTXsComplete, err) - } - err = FundSubscriptions( env, chainID, @@ -347,20 +323,12 @@ func SetupVRFV2PlusWrapperEnvironment( if err != nil { return nil, nil, err } - err = evmClient.WaitForEvents() - if err != nil { - return nil, nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitTXsComplete, err) - } //fund consumer with Eth err = wrapperContracts.LoadTestConsumers[0].Fund(big.NewFloat(*vrfv2PlusConfig.WrapperConsumerFundingAmountNativeToken)) if err != nil { return nil, nil, err } - err = evmClient.WaitForEvents() - if err != nil { - return nil, nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitTXsComplete, err) - } return wrapperContracts, wrapperSubID, nil } @@ -459,12 +427,12 @@ func SetupVRFV2PlusForExistingEnv(ctx context.Context, t *testing.T, testConfig return nil, nil, nil, fmt.Errorf("%s, err: %w", "error loading LinkToken", err) } - evmClient, err := env.GetEVMClient(chainID) + sethClient, err := env.GetSethClient(chainID) if err != nil { return nil, nil, nil, err } - err = vrfcommon.FundNodesIfNeeded(ctx, commonExistingEnvConfig, evmClient, l) + err = vrfcommon.FundNodesIfNeeded(ctx, commonExistingEnvConfig, sethClient, l) if err != nil { return nil, nil, nil, fmt.Errorf("err: %w", err) } diff --git a/integration-tests/contracts/contract_deployer.go b/integration-tests/contracts/contract_deployer.go index 6e7a482ec8a..9e7ac32b69b 100644 --- a/integration-tests/contracts/contract_deployer.go +++ b/integration-tests/contracts/contract_deployer.go @@ -129,11 +129,8 @@ type ContractDeployer interface { DeployVRFConsumerV2(linkAddr string, coordinatorAddr string) (VRFConsumerV2, error) DeployVRFv2Consumer(coordinatorAddr string) (VRFv2Consumer, error) DeployVRFv2LoadTestConsumer(coordinatorAddr string) (VRFv2LoadTestConsumer, error) - DeployVRFv2PlusLoadTestConsumer(coordinatorAddr string) (VRFv2PlusLoadTestConsumer, error) - DeployVRFV2PlusWrapperLoadTestConsumer(vrfV2PlusWrapperAddr string) (VRFv2PlusWrapperLoadTestConsumer, error) DeployVRFCoordinatorV2_5(bhsAddr string) (VRFCoordinatorV2_5, error) DeployVRFCoordinatorV2PlusUpgradedVersion(bhsAddr string) (VRFCoordinatorV2PlusUpgradedVersion, error) - DeployVRFV2PlusWrapper(linkAddr string, linkEthFeedAddr string, coordinatorAddr string, subId *big.Int) (VRFV2PlusWrapper, error) DeployDKG() (DKG, error) DeployOCR2VRFCoordinator(beaconPeriodBlocksCount *big.Int, linkAddr string) (VRFCoordinatorV3, error) DeployVRFBeacon(vrfCoordinatorAddress string, linkAddress string, dkgAddress string, keyId string) (VRFBeacon, error) diff --git a/integration-tests/contracts/ethereum_vrf_common.go b/integration-tests/contracts/ethereum_vrf_common.go index 27b60dc76ce..a9027113196 100644 --- a/integration-tests/contracts/ethereum_vrf_common.go +++ b/integration-tests/contracts/ethereum_vrf_common.go @@ -10,7 +10,6 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2_5" - "github.com/smartcontractkit/seth" ) type Coordinator interface { @@ -105,7 +104,3 @@ func parseRequestRandomnessLogs(coordinator Coordinator, logs []*types.Log) (*Co } return randomWordsRequestedEvent, nil } - -func RetrieveRequestRandomnessLogs(coordinator Coordinator, client *seth.Client, tx *seth.DecodedTransaction) (*CoordinatorRandomWordsRequested, error) { - return parseRequestRandomnessLogs(coordinator, tx.Receipt.Logs) -} diff --git a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go index 6d4bfcea647..697e4d14852 100644 --- a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go @@ -6,7 +6,6 @@ import ( "math/big" "time" - "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -19,6 +18,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_v2plus_upgraded_version" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrfv2plus_wrapper" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrfv2plus_wrapper_load_test_consumer" + "github.com/smartcontractkit/seth" ) type EthereumVRFCoordinatorV2_5 struct { @@ -36,19 +36,19 @@ type EthereumVRFCoordinatorV2PlusUpgradedVersion struct { // EthereumVRFv2PlusLoadTestConsumer represents VRFv2Plus consumer contract for performing Load Tests type EthereumVRFv2PlusLoadTestConsumer struct { address *common.Address - client blockchain.EVMClient + client *seth.Client consumer *vrf_v2plus_load_test_with_metrics.VRFV2PlusLoadTestWithMetrics } type EthereumVRFV2PlusWrapperLoadTestConsumer struct { address *common.Address - client blockchain.EVMClient + client *seth.Client consumer *vrfv2plus_wrapper_load_test_consumer.VRFV2PlusWrapperLoadTestConsumer } type EthereumVRFV2PlusWrapper struct { address *common.Address - client blockchain.EVMClient + client *seth.Client wrapper *vrfv2plus_wrapper.VRFV2PlusWrapper } @@ -69,12 +69,8 @@ func (v *EthereumVRFV2PlusWrapper) SetConfig(wrapperGasOverhead uint32, fulfillmentFlatFeeNativePPM uint32, fulfillmentFlatFeeLinkDiscountPPM uint32, ) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.wrapper.SetConfig( - opts, + _, err := v.client.Decode(v.wrapper.SetConfig( + v.client.NewTXOpts(), wrapperGasOverhead, coordinatorGasOverheadNative, coordinatorGasOverheadLink, @@ -87,23 +83,20 @@ func (v *EthereumVRFV2PlusWrapper) SetConfig(wrapperGasOverhead uint32, fallbackWeiPerUnitLink, fulfillmentFlatFeeNativePPM, fulfillmentFlatFeeLinkDiscountPPM, - ) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + )) + return err } func (v *EthereumVRFV2PlusWrapper) GetSubID(ctx context.Context) (*big.Int, error) { return v.wrapper.SUBSCRIPTIONID(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) } func (v *EthereumVRFV2PlusWrapper) Coordinator(ctx context.Context) (common.Address, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } return v.wrapper.SVrfCoordinator(opts) @@ -573,15 +566,11 @@ func (v *EthereumVRFv2PlusLoadTestConsumer) RequestRandomness( numWords uint32, requestCount uint16, ) (*CoordinatorRandomWordsRequested, error) { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return nil, err - } - tx, err := v.consumer.RequestRandomWords(opts, subID, requestConfirmations, keyHash, callbackGasLimit, nativePayment, numWords, requestCount) + tx, err := v.client.Decode(v.consumer.RequestRandomWords(v.client.NewTXOpts(), subID, requestConfirmations, keyHash, callbackGasLimit, nativePayment, numWords, requestCount)) if err != nil { return nil, err } - randomWordsRequestedEvent, err := RetrieveRequestRandomnessLogs(coordinator, v.client, tx) + randomWordsRequestedEvent, err := parseRequestRandomnessLogs(coordinator, tx.Receipt.Logs) if err != nil { return nil, err } @@ -589,47 +578,40 @@ func (v *EthereumVRFv2PlusLoadTestConsumer) RequestRandomness( } func (v *EthereumVRFv2PlusLoadTestConsumer) ResetMetrics() error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.consumer.Reset(opts) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + _, err := v.client.Decode(v.consumer.Reset(v.client.NewTXOpts())) + return err } func (v *EthereumVRFv2PlusLoadTestConsumer) GetCoordinator(ctx context.Context) (common.Address, error) { return v.consumer.SVrfCoordinator(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) } func (v *EthereumVRFv2PlusLoadTestConsumer) GetRequestStatus(ctx context.Context, requestID *big.Int) (vrf_v2plus_load_test_with_metrics.GetRequestStatus, error) { return v.consumer.GetRequestStatus(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }, requestID) } func (v *EthereumVRFv2PlusLoadTestConsumer) GetLastRequestId(ctx context.Context) (*big.Int, error) { return v.consumer.SLastRequestId(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) } func (v *EthereumVRFv2PlusLoadTestConsumer) GetLoadTestMetrics(ctx context.Context) (*VRFLoadTestMetrics, error) { requestCount, err := v.consumer.SRequestCount(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) if err != nil { return nil, err } fulfilmentCount, err := v.consumer.SResponseCount(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) @@ -637,14 +619,14 @@ func (v *EthereumVRFv2PlusLoadTestConsumer) GetLoadTestMetrics(ctx context.Conte return nil, err } averageFulfillmentInMillions, err := v.consumer.SAverageResponseTimeInBlocksMillions(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) if err != nil { return nil, err } slowestFulfillment, err := v.consumer.SSlowestResponseTimeInBlocks(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) @@ -652,28 +634,28 @@ func (v *EthereumVRFv2PlusLoadTestConsumer) GetLoadTestMetrics(ctx context.Conte return nil, err } fastestFulfillment, err := v.consumer.SFastestResponseTimeInBlocks(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) if err != nil { return nil, err } averageResponseTimeInSeconds, err := v.consumer.SAverageResponseTimeInSecondsMillions(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) if err != nil { return nil, err } slowestResponseTimeInSeconds, err := v.consumer.SSlowestResponseTimeInSeconds(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) if err != nil { return nil, err } fastestResponseTimeInSeconds, err := v.consumer.SFastestResponseTimeInSeconds(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) if err != nil { @@ -682,7 +664,7 @@ func (v *EthereumVRFv2PlusLoadTestConsumer) GetLoadTestMetrics(ctx context.Conte var responseTimesInBlocks []uint32 for { currentResponseTimesInBlocks, err := v.consumer.GetRequestBlockTimes(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }, big.NewInt(int64(len(responseTimesInBlocks))), big.NewInt(1000)) if err != nil { @@ -1052,54 +1034,88 @@ func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) WaitForConfigSetEvent(time } } -func (e *EthereumContractDeployer) DeployVRFv2PlusLoadTestConsumer(coordinatorAddr string) (VRFv2PlusLoadTestConsumer, error) { - address, _, instance, err := e.client.DeployContract("VRFV2PlusLoadTestWithMetrics", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return vrf_v2plus_load_test_with_metrics.DeployVRFV2PlusLoadTestWithMetrics(auth, wrappers.MustNewWrappedContractBackend(e.client, nil), common.HexToAddress(coordinatorAddr)) - }) +func DeployVRFv2PlusLoadTestConsumer(seth *seth.Client, coordinatorAddr string) (VRFv2PlusLoadTestConsumer, error) { + abi, err := vrf_v2plus_load_test_with_metrics.VRFV2PlusLoadTestWithMetricsMetaData.GetAbi() if err != nil { - return nil, err + return &EthereumVRFv2PlusLoadTestConsumer{}, fmt.Errorf("failed to get VRFV2PlusLoadTestWithMetrics ABI: %w", err) + } + + data, err := seth.DeployContract( + seth.NewTXOpts(), + "VRFV2PlusLoadTestWithMetrics", + *abi, + common.FromHex(vrf_v2plus_load_test_with_metrics.VRFV2PlusLoadTestWithMetricsMetaData.Bin), + common.HexToAddress(coordinatorAddr)) + if err != nil { + return &EthereumVRFv2PlusLoadTestConsumer{}, fmt.Errorf("VRFV2PlusLoadTestWithMetrics instance deployment have failed: %w", err) + } + + contract, err := vrf_v2plus_load_test_with_metrics.NewVRFV2PlusLoadTestWithMetrics(data.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRFv2PlusLoadTestConsumer{}, fmt.Errorf("failed to instantiate VRFV2PlusLoadTestWithMetrics instance: %w", err) } + return &EthereumVRFv2PlusLoadTestConsumer{ - client: e.client, - consumer: instance.(*vrf_v2plus_load_test_with_metrics.VRFV2PlusLoadTestWithMetrics), - address: address, + client: seth, + consumer: contract, + address: &data.Address, }, err } -func (e *EthereumContractDeployer) DeployVRFV2PlusWrapper(linkAddr string, linkEthFeedAddr string, coordinatorAddr string, subId *big.Int) (VRFV2PlusWrapper, error) { - address, _, instance, err := e.client.DeployContract("VRFV2PlusWrapper", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return vrfv2plus_wrapper.DeployVRFV2PlusWrapper(auth, wrappers.MustNewWrappedContractBackend(e.client, nil), common.HexToAddress(linkAddr), common.HexToAddress(linkEthFeedAddr), common.HexToAddress(coordinatorAddr), subId) - }) +func DeployVRFV2PlusWrapper(seth *seth.Client, linkAddr string, linkEthFeedAddr string, coordinatorAddr string, subId *big.Int) (VRFV2PlusWrapper, error) { + abi, err := vrfv2plus_wrapper.VRFV2PlusWrapperMetaData.GetAbi() if err != nil { - return nil, err + return &EthereumVRFV2PlusWrapper{}, fmt.Errorf("failed to get VRFV2PlusWrapper ABI: %w", err) + } + + data, err := seth.DeployContract( + seth.NewTXOpts(), + "VRFV2PlusWrapper", + *abi, + common.FromHex(vrfv2plus_wrapper.VRFV2PlusWrapperMetaData.Bin), + common.HexToAddress(linkAddr), common.HexToAddress(linkEthFeedAddr), + common.HexToAddress(coordinatorAddr), subId) + if err != nil { + return &EthereumVRFV2PlusWrapper{}, fmt.Errorf("VRFV2PlusWrapper instance deployment have failed: %w", err) + } + + contract, err := vrfv2plus_wrapper.NewVRFV2PlusWrapper(data.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRFV2PlusWrapper{}, fmt.Errorf("failed to instantiate VRFV2PlusWrapper instance: %w", err) } + return &EthereumVRFV2PlusWrapper{ - client: e.client, - wrapper: instance.(*vrfv2plus_wrapper.VRFV2PlusWrapper), - address: address, + client: seth, + wrapper: contract, + address: &data.Address, }, err } -func (e *EthereumContractDeployer) DeployVRFV2PlusWrapperLoadTestConsumer(vrfV2PlusWrapperAddr string) (VRFv2PlusWrapperLoadTestConsumer, error) { - address, _, instance, err := e.client.DeployContract("VRFV2PlusWrapperLoadTestConsumer", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return vrfv2plus_wrapper_load_test_consumer.DeployVRFV2PlusWrapperLoadTestConsumer(auth, wrappers.MustNewWrappedContractBackend(e.client, nil), common.HexToAddress(vrfV2PlusWrapperAddr)) - }) +func DeployVRFV2PlusWrapperLoadTestConsumer(seth *seth.Client, vrfV2PlusWrapperAddr string) (VRFv2PlusWrapperLoadTestConsumer, error) { + abi, err := vrfv2plus_wrapper_load_test_consumer.VRFV2PlusWrapperLoadTestConsumerMetaData.GetAbi() if err != nil { - return nil, err + return &EthereumVRFV2PlusWrapperLoadTestConsumer{}, fmt.Errorf("failed to get VRFV2PlusWrapperLoadTestConsumer ABI: %w", err) } + + coordinatorDeploymentData, err := seth.DeployContract( + seth.NewTXOpts(), + "VRFV2PlusWrapperLoadTestConsumer", + *abi, + common.FromHex(vrfv2plus_wrapper_load_test_consumer.VRFV2PlusWrapperLoadTestConsumerMetaData.Bin), + common.HexToAddress(vrfV2PlusWrapperAddr)) + if err != nil { + return &EthereumVRFV2PlusWrapperLoadTestConsumer{}, fmt.Errorf("VRFV2PlusWrapperLoadTestConsumer instance deployment have failed: %w", err) + } + + contract, err := vrfv2plus_wrapper_load_test_consumer.NewVRFV2PlusWrapperLoadTestConsumer(coordinatorDeploymentData.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRFV2PlusWrapperLoadTestConsumer{}, fmt.Errorf("failed to instantiate VRFV2PlusWrapperLoadTestConsumer instance: %w", err) + } + return &EthereumVRFV2PlusWrapperLoadTestConsumer{ - client: e.client, - consumer: instance.(*vrfv2plus_wrapper_load_test_consumer.VRFV2PlusWrapperLoadTestConsumer), - address: address, + client: seth, + consumer: contract, + address: &coordinatorDeploymentData.Address, }, err } @@ -1108,13 +1124,7 @@ func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) Address() string { } func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) Fund(ethAmount *big.Float) error { - gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{ - To: v.address, - }) - if err != nil { - return err - } - return v.client.Fund(v.address.Hex(), ethAmount, gasEstimates) + panic("do not use this function, use actions_seth.SendFunds() instead, otherwise we will have to deal with circular dependencies") } func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) RequestRandomness( @@ -1124,15 +1134,11 @@ func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) RequestRandomness( numWords uint32, requestCount uint16, ) (*CoordinatorRandomWordsRequested, error) { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) + tx, err := v.client.Decode(v.consumer.MakeRequests(v.client.NewTXOpts(), callbackGasLimit, requestConfirmations, numWords, requestCount)) if err != nil { return nil, err } - tx, err := v.consumer.MakeRequests(opts, callbackGasLimit, requestConfirmations, numWords, requestCount) - if err != nil { - return nil, err - } - randomWordsRequestedEvent, err := RetrieveRequestRandomnessLogs(coordinator, v.client, tx) + randomWordsRequestedEvent, err := parseRequestRandomnessLogs(coordinator, tx.Receipt.Logs) if err != nil { return nil, err } @@ -1146,15 +1152,11 @@ func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) RequestRandomnessNative( numWords uint32, requestCount uint16, ) (*CoordinatorRandomWordsRequested, error) { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) + tx, err := v.client.Decode(v.consumer.MakeRequestsNative(v.client.NewTXOpts(), callbackGasLimit, requestConfirmations, numWords, requestCount)) if err != nil { return nil, err } - tx, err := v.consumer.MakeRequestsNative(opts, callbackGasLimit, requestConfirmations, numWords, requestCount) - if err != nil { - return nil, err - } - randomWordsRequestedEvent, err := RetrieveRequestRandomnessLogs(coordinator, v.client, tx) + randomWordsRequestedEvent, err := parseRequestRandomnessLogs(coordinator, tx.Receipt.Logs) if err != nil { return nil, err } @@ -1163,35 +1165,35 @@ func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) RequestRandomnessNative( func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) GetRequestStatus(ctx context.Context, requestID *big.Int) (vrfv2plus_wrapper_load_test_consumer.GetRequestStatus, error) { return v.consumer.GetRequestStatus(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }, requestID) } func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) GetLastRequestId(ctx context.Context) (*big.Int, error) { return v.consumer.SLastRequestId(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) } func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) GetWrapper(ctx context.Context) (common.Address, error) { return v.consumer.IVrfV2PlusWrapper(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) } func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) GetLoadTestMetrics(ctx context.Context) (*VRFLoadTestMetrics, error) { requestCount, err := v.consumer.SRequestCount(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) if err != nil { return nil, err } fulfilmentCount, err := v.consumer.SResponseCount(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) @@ -1199,14 +1201,14 @@ func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) GetLoadTestMetrics(ctx contex return nil, err } averageFulfillmentInMillions, err := v.consumer.SAverageFulfillmentInMillions(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) if err != nil { return nil, err } slowestFulfillment, err := v.consumer.SSlowestFulfillment(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) @@ -1214,7 +1216,7 @@ func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) GetLoadTestMetrics(ctx contex return nil, err } fastestFulfillment, err := v.consumer.SFastestFulfillment(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) if err != nil { From 90fe936c033a3aecfb9dff71db82221af3119b7e Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Thu, 25 Apr 2024 10:45:28 +0200 Subject: [PATCH 07/43] wip 7 --- .../actions/vrf/common/actions.go | 2 +- .../actions/vrf/vrfv2/contract_steps.go | 16 +- .../actions/vrf/vrfv2/setup_steps.go | 9 +- .../actions/vrf/vrfv2plus/logging_helpers.go | 9 +- .../contracts/contract_loader.go | 60 +-- .../contracts/contract_vrf_models.go | 2 +- .../contracts/ethereum_vrf_contracts_seth.go | 4 +- .../contracts/ethereum_vrfv2_contracts.go | 212 +++++----- .../contracts/ethereum_vrfv2plus_contracts.go | 371 +++++++----------- integration-tests/smoke/vrfv2_test.go | 8 +- 10 files changed, 293 insertions(+), 400 deletions(-) diff --git a/integration-tests/actions/vrf/common/actions.go b/integration-tests/actions/vrf/common/actions.go index 7ee76d22cd2..2151cd3094d 100644 --- a/integration-tests/actions/vrf/common/actions.go +++ b/integration-tests/actions/vrf/common/actions.go @@ -329,7 +329,7 @@ func FundNodesIfNeeded(ctx context.Context, existingEnvConfig *vrf_common_config Str("Should have at least", fundingAtLeast.String()) if fundingToSendWei.Cmp(big.NewInt(0)) == 1 { log. - Str("Funding Amount in ETH", fundingToSendWei.String()). + Str("Funding Amount in wei", fundingToSendWei.String()). Msg("Funding Node's Sending Key") _, err := actions_seth.SendFunds(l, client, actions_seth.FundsToSendPayload{ ToAddress: common.HexToAddress(sendingKey), diff --git a/integration-tests/actions/vrf/vrfv2/contract_steps.go b/integration-tests/actions/vrf/vrfv2/contract_steps.go index 6dacc8b228d..348119c41bb 100644 --- a/integration-tests/actions/vrf/vrfv2/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2/contract_steps.go @@ -44,7 +44,7 @@ func DeployVRFV2Contracts( return nil, err } - var coordinatorAddress *common.Address + var coordinatorAddress string if useTestCoordinator { testCoordinator, err := contracts.DeployVRFCoordinatorTestV2(sethClient, linkTokenContract.Address(), bhs.Address(), linkEthFeedContract.Address()) if err != nil { @@ -62,12 +62,12 @@ func DeployVRFV2Contracts( coordinatorAddress = coordinator.Address() } - coordinator, err := contracts.LoadVRFCoordinatorV2(sethClient, *coordinatorAddress) + coordinator, err := contracts.LoadVRFCoordinatorV2(sethClient, coordinatorAddress) if err != nil { return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrLoadingCoordinator, err) } if useVRFOwner { - vrfOwner, err := contracts.DeployVRFOwner(sethClient, *coordinatorAddress) + vrfOwner, err := contracts.DeployVRFOwner(sethClient, coordinatorAddress) if err != nil { return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrDeployCoordinator, err) } @@ -121,7 +121,7 @@ func DeployVRFV2DirectFundingContracts( coordinator contracts.VRFCoordinatorV2, consumerContractsAmount int, ) (*VRFV2WrapperContracts, error) { - vrfv2Wrapper, err := contracts.DeployVRFV2Wrapper(client, linkTokenAddress, linkEthFeedAddress, coordinator.Address().Hex()) + vrfv2Wrapper, err := contracts.DeployVRFV2Wrapper(client, linkTokenAddress, linkEthFeedAddress, coordinator.Address()) if err != nil { return nil, fmt.Errorf("%s, err %w", ErrDeployVRFV2Wrapper, err) } @@ -185,7 +185,7 @@ func SetupVRFV2Contracts( ReqsForTier4: big.NewInt(*vrfv2Config.ReqsForTier4), ReqsForTier5: big.NewInt(*vrfv2Config.ReqsForTier5)} - l.Info().Str("Coordinator", vrfContracts.CoordinatorV2.Address().Hex()).Msg("Setting Coordinator Config") + l.Info().Str("Coordinator", vrfContracts.CoordinatorV2.Address()).Msg("Setting Coordinator Config") err = vrfContracts.CoordinatorV2.SetConfig( *vrfv2Config.MinimumConfirmations, *vrfv2Config.MaxGasLimitCoordinatorConfig, @@ -213,7 +213,7 @@ func SetupVRFV2Contracts( func setupVRFOwnerContract(env *test_env.CLClusterTestEnv, chainID int64, contracts *vrfcommon.VRFContracts, allNativeTokenKeyAddressStrings []string, allNativeTokenKeyAddresses []common.Address, l zerolog.Logger) error { l.Info().Msg("Setting up VRFOwner contract") l.Info(). - Str("Coordinator", contracts.CoordinatorV2.Address().Hex()). + Str("Coordinator", contracts.CoordinatorV2.Address()). Str("VRFOwner", contracts.VRFOwner.Address()). Msg("Transferring ownership of Coordinator to VRFOwner") err := contracts.CoordinatorV2.TransferOwnership(common.HexToAddress(contracts.VRFOwner.Address())) @@ -421,7 +421,7 @@ func FundVRFCoordinatorV2Subscription( if err != nil { return fmt.Errorf("%s, err %w", vrfcommon.ErrABIEncodingFunding, err) } - _, err = linkToken.TransferAndCall(coordinator.Address().Hex(), linkFundingAmountJuels, encodedSubId) + _, err = linkToken.TransferAndCall(coordinator.Address(), linkFundingAmountJuels, encodedSubId) if err != nil { return fmt.Errorf("%s, err %w", vrfcommon.ErrSendingLinkToken, err) } @@ -697,7 +697,7 @@ func SetupNewConsumersAndSubs( numberOfSubToCreate int, l zerolog.Logger, ) ([]contracts.VRFv2LoadTestConsumer, []uint64, error) { - consumers, err := DeployVRFV2Consumers(env.ContractDeployer, coordinator.Address().Hex(), numberOfConsumerContractsToDeployAndAddToSub) + consumers, err := DeployVRFV2Consumers(env.ContractDeployer, coordinator.Address(), numberOfConsumerContractsToDeployAndAddToSub) if err != nil { return nil, nil, fmt.Errorf("err: %w", err) } diff --git a/integration-tests/actions/vrf/vrfv2/setup_steps.go b/integration-tests/actions/vrf/vrfv2/setup_steps.go index f947167bbe8..dd3391979ac 100644 --- a/integration-tests/actions/vrf/vrfv2/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2/setup_steps.go @@ -114,7 +114,7 @@ func SetupVRFV2Environment( return nil, nil, nil, err } - l.Info().Str("Coordinator", vrfContracts.CoordinatorV2.Address().Hex()).Msg("Registering Proving Key") + l.Info().Str("Coordinator", vrfContracts.CoordinatorV2.Address()).Msg("Registering Proving Key") provingKey, err := VRFV2RegisterProvingKey(vrfKey, registerProvingKeyAgainstAddress, vrfContracts.CoordinatorV2) if err != nil { return nil, nil, nil, fmt.Errorf("%s, err %w", vrfcommon.ErrRegisteringProvingKey, err) @@ -175,7 +175,7 @@ func SetupVRFV2Environment( configGeneral.General, numberOfTxKeysToCreate, big.NewInt(chainID), - vrfContracts.CoordinatorV2.Address().Hex(), + vrfContracts.CoordinatorV2.Address(), vrfContracts.BHS.Address(), *vrfv2TestConfig.GetCommonConfig().ChainlinkNodeFunding, l, @@ -206,7 +206,7 @@ func SetupVRFV2Environment( func setupVRFNode(contracts *vrfcommon.VRFContracts, chainID *big.Int, vrfv2Config *testconfig.General, pubKeyCompressed string, vrfOwnerConfig *vrfcommon.VRFOwnerConfig, l zerolog.Logger, vrfNode *vrfcommon.VRFNode) error { vrfJobSpecConfig := vrfcommon.VRFJobSpecConfig{ ForwardingAllowed: *vrfv2Config.VRFJobForwardingAllowed, - CoordinatorAddress: contracts.CoordinatorV2.Address().Hex(), + CoordinatorAddress: contracts.CoordinatorV2.Address(), FromAddresses: vrfNode.TXKeyAddressStrings, EVMChainID: chainID.String(), MinIncomingConfirmations: int(*vrfv2Config.MinimumConfirmations), @@ -410,8 +410,7 @@ func SetupVRFV2ForExistingEnv(ctx context.Context, t *testing.T, testConfig tc.T if err != nil { return nil, nil, nil, err } - coordinatorAddr := common.HexToAddress(*commonExistingEnvConfig.ConsumerAddress) - coordinator, err := contracts.LoadVRFCoordinatorV2(client, coordinatorAddr) + coordinator, err := contracts.LoadVRFCoordinatorV2(client, *commonExistingEnvConfig.ConsumerAddress) if err != nil { return nil, nil, nil, fmt.Errorf("%s, err: %w", "error loading VRFCoordinator2", err) } diff --git a/integration-tests/actions/vrf/vrfv2plus/logging_helpers.go b/integration-tests/actions/vrf/vrfv2plus/logging_helpers.go index b613298f1fd..739772dbc14 100644 --- a/integration-tests/actions/vrf/vrfv2plus/logging_helpers.go +++ b/integration-tests/actions/vrf/vrfv2plus/logging_helpers.go @@ -4,6 +4,7 @@ import ( "fmt" "math/big" + "github.com/ethereum/go-ethereum/common" "github.com/rs/zerolog" "github.com/smartcontractkit/chainlink/integration-tests/contracts" @@ -15,14 +16,14 @@ import ( func LogRandRequest( l zerolog.Logger, consumer string, - coordinator string, + coordinator *common.Address, subID *big.Int, isNativeBilling bool, keyHash [32]byte, config *vrfv2plus_config.General) { l.Info(). Str("Consumer", consumer). - Str("Coordinator", coordinator). + Str("Coordinator", coordinator.Hex()). Str("SubID", subID.String()). Bool("IsNativePayment", isNativeBilling). Uint16("MinimumConfirmations", *config.MinimumConfirmations). @@ -37,14 +38,14 @@ func LogRandRequest( func LogMigrationCompletedEvent(l zerolog.Logger, migrationCompletedEvent *vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted, coordinator contracts.Coordinator) { l.Info(). Str("Subscription ID", migrationCompletedEvent.SubId.String()). - Str("Migrated From Coordinator", coordinator.Address()). + Str("Migrated From Coordinator", coordinator.Address().Hex()). Str("Migrated To Coordinator", migrationCompletedEvent.NewCoordinator.String()). Msg("MigrationCompleted Event") } func LogSubDetailsAfterMigration(l zerolog.Logger, newCoordinator contracts.Coordinator, subID *big.Int, migratedSubscription vrf_v2plus_upgraded_version.GetSubscription) { l.Info(). - Str("New Coordinator", newCoordinator.Address()). + Str("New Coordinator", newCoordinator.Address().Hex()). Str("Subscription ID", subID.String()). Str("Juels Balance", migratedSubscription.Balance.String()). Str("Native Token Balance", migratedSubscription.NativeBalance.String()). diff --git a/integration-tests/contracts/contract_loader.go b/integration-tests/contracts/contract_loader.go index 9047bce65ba..dd72e40e6cc 100644 --- a/integration-tests/contracts/contract_loader.go +++ b/integration-tests/contracts/contract_loader.go @@ -2,9 +2,11 @@ package contracts import ( "errors" + "fmt" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2_5" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_v2plus_load_test_with_metrics" + "github.com/smartcontractkit/seth" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" @@ -42,10 +44,6 @@ type ContractLoader interface { LoadMercuryRewardManager(addr common.Address) (MercuryRewardManager, error) LoadWERC20Mock(addr common.Address) (WERC20Mock, error) - - // VRF - LoadVRFCoordinatorV2_5(addr string) (VRFCoordinatorV2_5, error) - LoadVRFv2PlusLoadTestConsumer(addr string) (VRFv2PlusLoadTestConsumer, error) } // NewContractLoader returns an instance of a contract Loader based on the client type @@ -363,38 +361,44 @@ func (e *EthereumContractLoader) LoadWERC20Mock(addr common.Address) (WERC20Mock }, err } -func (e *EthereumContractLoader) LoadVRFCoordinatorV2_5(addr string) (VRFCoordinatorV2_5, error) { +func LoadVRFCoordinatorV2_5(seth *seth.Client, addr string) (VRFCoordinatorV2_5, error) { address := common.HexToAddress(addr) - instance, err := e.client.LoadContract("VRFCoordinatorV2_5", address, func( - address common.Address, - backend bind.ContractBackend, - ) (interface{}, error) { - return vrf_coordinator_v2_5.NewVRFCoordinatorV25(address, backend) - }) + abi, err := vrf_coordinator_v2_5.VRFCoordinatorV25MetaData.GetAbi() if err != nil { - return nil, err + return &EthereumVRFCoordinatorV2_5{}, fmt.Errorf("failed to get VRFCoordinatorV2_5 ABI: %w", err) } + seth.ContractStore.AddABI("VRFCoordinatorV2_5", *abi) + seth.ContractStore.AddBIN("VRFCoordinatorV2_5", common.FromHex(vrf_coordinator_v2_5.VRFCoordinatorV25MetaData.Bin)) + + contract, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(address, seth.Client) + if err != nil { + return &EthereumVRFCoordinatorV2_5{}, fmt.Errorf("failed to instantiate VRFCoordinatorV2_5 instance: %w", err) + } + return &EthereumVRFCoordinatorV2_5{ - address: &address, - client: e.client, - coordinator: instance.(*vrf_coordinator_v2_5.VRFCoordinatorV25), - }, err + client: seth, + address: address, + coordinator: contract, + }, nil } -func (e *EthereumContractLoader) LoadVRFv2PlusLoadTestConsumer(addr string) (VRFv2PlusLoadTestConsumer, error) { +func LoadVRFv2PlusLoadTestConsumer(seth *seth.Client, addr string) (VRFv2PlusLoadTestConsumer, error) { address := common.HexToAddress(addr) - instance, err := e.client.LoadContract("VRFV2PlusLoadTestWithMetrics", address, func( - address common.Address, - backend bind.ContractBackend, - ) (interface{}, error) { - return vrf_v2plus_load_test_with_metrics.NewVRFV2PlusLoadTestWithMetrics(address, backend) - }) + abi, err := vrf_v2plus_load_test_with_metrics.VRFV2PlusLoadTestWithMetricsMetaData.GetAbi() if err != nil { - return nil, err + return &EthereumVRFv2PlusLoadTestConsumer{}, fmt.Errorf("failed to get VRFV2PlusLoadTestWithMetrics ABI: %w", err) } + seth.ContractStore.AddABI("VRFV2PlusLoadTestWithMetrics", *abi) + seth.ContractStore.AddBIN("VRFV2PlusLoadTestWithMetrics", common.FromHex(vrf_v2plus_load_test_with_metrics.VRFV2PlusLoadTestWithMetricsMetaData.Bin)) + + contract, err := vrf_v2plus_load_test_with_metrics.NewVRFV2PlusLoadTestWithMetrics(address, seth.Client) + if err != nil { + return &EthereumVRFv2PlusLoadTestConsumer{}, fmt.Errorf("failed to instantiate VRFV2PlusLoadTestWithMetrics instance: %w", err) + } + return &EthereumVRFv2PlusLoadTestConsumer{ - client: e.client, - consumer: instance.(*vrf_v2plus_load_test_with_metrics.VRFV2PlusLoadTestWithMetrics), - address: &address, - }, err + client: seth, + address: address, + consumer: contract, + }, nil } diff --git a/integration-tests/contracts/contract_vrf_models.go b/integration-tests/contracts/contract_vrf_models.go index 8f89ddb93fa..aaccbad0602 100644 --- a/integration-tests/contracts/contract_vrf_models.go +++ b/integration-tests/contracts/contract_vrf_models.go @@ -59,7 +59,7 @@ type VRFCoordinatorV2 interface { HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error) CreateSubscription() (*types.Transaction, error) AddConsumer(subId uint64, consumerAddress string) error - Address() *common.Address + Address() string GetSubscription(ctx context.Context, subID uint64) (Subscription, error) GetOwner(ctx context.Context) (common.Address, error) PendingRequestsExist(ctx context.Context, subID uint64) (bool, error) diff --git a/integration-tests/contracts/ethereum_vrf_contracts_seth.go b/integration-tests/contracts/ethereum_vrf_contracts_seth.go index 81f5648eccb..bdc7ee7154c 100644 --- a/integration-tests/contracts/ethereum_vrf_contracts_seth.go +++ b/integration-tests/contracts/ethereum_vrf_contracts_seth.go @@ -38,8 +38,8 @@ type EthereumVRFCoordinatorTestV2 struct { coordinator *vrf_coordinator_test_v2.VRFCoordinatorTestV2 } -func (v *EthereumVRFCoordinatorTestV2) Address() *common.Address { - return v.address +func (v *EthereumVRFCoordinatorTestV2) Address() string { + return v.address.Hex() } // EthereumVRFConsumer represents VRF consumer contract diff --git a/integration-tests/contracts/ethereum_vrfv2_contracts.go b/integration-tests/contracts/ethereum_vrfv2_contracts.go index ace5d63bd65..cf5c19ae431 100644 --- a/integration-tests/contracts/ethereum_vrfv2_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2_contracts.go @@ -8,13 +8,11 @@ import ( "strconv" "time" - "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/rs/zerolog/log" - "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink/integration-tests/wrappers" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_mock_ethlink_aggregator" @@ -31,46 +29,46 @@ import ( ) type EthereumVRFOwner struct { - address *common.Address + address common.Address client *seth.Client vrfOwner *vrf_owner.VRFOwner } type EthereumVRFCoordinatorV2 struct { - address *common.Address + address common.Address client *seth.Client coordinator *vrf_coordinator_v2.VRFCoordinatorV2 } // EthereumVRFConsumerV2 represents VRFv2 consumer contract type EthereumVRFConsumerV2 struct { - address *common.Address - client blockchain.EVMClient + address common.Address + client *seth.Client consumer *vrf_consumer_v2.VRFConsumerV2 } // EthereumVRFv2Consumer represents VRFv2 consumer contract type EthereumVRFv2Consumer struct { - address *common.Address - client blockchain.EVMClient + address common.Address + client *seth.Client consumer *vrf_v2_consumer_wrapper.VRFv2Consumer } // EthereumVRFv2LoadTestConsumer represents VRFv2 consumer contract for performing Load Tests type EthereumVRFv2LoadTestConsumer struct { - address *common.Address + address common.Address client *seth.Client consumer *vrf_load_test_with_metrics.VRFV2LoadTestWithMetrics } type EthereumVRFV2Wrapper struct { - address *common.Address + address common.Address client *seth.Client wrapper *vrfv2_wrapper.VRFV2Wrapper } type EthereumVRFV2WrapperLoadTestConsumer struct { - address *common.Address + address common.Address client *seth.Client consumer *vrfv2_wrapper_load_test_consumer.VRFV2WrapperLoadTestConsumer } @@ -82,9 +80,9 @@ type GetRequestConfig struct { } type EthereumVRFMockETHLINKFeed struct { - client blockchain.EVMClient + client *seth.Client feed *vrf_mock_ethlink_aggregator.VRFMockETHLINKAggregator - address *common.Address + address common.Address } func DeployVRFCoordinatorV2(seth *seth.Client, linkAddr, bhsAddr, linkEthFeedAddr string) (VRFCoordinatorV2, error) { @@ -113,11 +111,11 @@ func DeployVRFCoordinatorV2(seth *seth.Client, linkAddr, bhsAddr, linkEthFeedAdd return &EthereumVRFCoordinatorV2{ client: seth, coordinator: coordinator, - address: &coordinatorDeploymentData.Address, + address: coordinatorDeploymentData.Address, }, err } -func LoadVRFCoordinatorV2(seth *seth.Client, addr common.Address) (*EthereumVRFCoordinatorV2, error) { +func LoadVRFCoordinatorV2(seth *seth.Client, address string) (*EthereumVRFCoordinatorV2, error) { abi, err := vrf_coordinator_v2.VRFCoordinatorV2MetaData.GetAbi() if err != nil { return &EthereumVRFCoordinatorV2{}, fmt.Errorf("failed to get VRFCoordinatorV2 ABI: %w", err) @@ -125,19 +123,19 @@ func LoadVRFCoordinatorV2(seth *seth.Client, addr common.Address) (*EthereumVRFC seth.ContractStore.AddABI("VRFCoordinatorV2", *abi) seth.ContractStore.AddBIN("VRFCoordinatorV2", common.FromHex(vrf_coordinator_v2.VRFCoordinatorV2MetaData.Bin)) - contract, err := vrf_coordinator_v2.NewVRFCoordinatorV2(addr, seth.Client) + contract, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(address), seth.Client) if err != nil { return &EthereumVRFCoordinatorV2{}, fmt.Errorf("failed to instantiate VRFCoordinatorV2 instance: %w", err) } return &EthereumVRFCoordinatorV2{ client: seth, - address: &addr, + address: common.HexToAddress(address), coordinator: contract, }, nil } -func DeployVRFOwner(seth *seth.Client, coordinatorAddr common.Address) (VRFOwner, error) { +func DeployVRFOwner(seth *seth.Client, coordinatorAddress string) (VRFOwner, error) { abi, err := vrf_owner.VRFOwnerMetaData.GetAbi() if err != nil { return &EthereumVRFOwner{}, fmt.Errorf("failed to get VRFOwner ABI: %w", err) @@ -148,7 +146,7 @@ func DeployVRFOwner(seth *seth.Client, coordinatorAddr common.Address) (VRFOwner "VRFOwner", *abi, common.FromHex(vrf_owner.VRFOwnerMetaData.Bin), - coordinatorAddr) + common.HexToAddress(coordinatorAddress)) if err != nil { return &EthereumVRFOwner{}, fmt.Errorf("VRFOwner instance deployment have failed: %w", err) } @@ -161,42 +159,65 @@ func DeployVRFOwner(seth *seth.Client, coordinatorAddr common.Address) (VRFOwner return &EthereumVRFOwner{ client: seth, vrfOwner: contract, - address: &data.Address, + address: data.Address, }, err } // DeployVRFConsumerV2 deploys VRFv@ consumer contract -func (e *EthereumContractDeployer) DeployVRFConsumerV2(linkAddr string, coordinatorAddr string) (VRFConsumerV2, error) { - address, _, instance, err := e.client.DeployContract("VRFConsumerV2", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return vrf_consumer_v2.DeployVRFConsumerV2(auth, backend, common.HexToAddress(coordinatorAddr), common.HexToAddress(linkAddr)) - }) +func DeployVRFConsumerV2(seth *seth.Client, linkAddr, coordinatorAddr common.Address) (VRFConsumerV2, error) { + abi, err := vrf_consumer_v2.VRFConsumerV2MetaData.GetAbi() if err != nil { - return nil, err + return &EthereumVRFConsumerV2{}, fmt.Errorf("failed to get VRFConsumerV2 ABI: %w", err) } + + data, err := seth.DeployContract( + seth.NewTXOpts(), + "VRFConsumerV2", + *abi, + common.FromHex(vrf_consumer_v2.VRFConsumerV2MetaData.Bin), + coordinatorAddr, + linkAddr) + if err != nil { + return &EthereumVRFConsumerV2{}, fmt.Errorf("VRFConsumerV2 instance deployment have failed: %w", err) + } + + contract, err := vrf_consumer_v2.NewVRFConsumerV2(data.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRFConsumerV2{}, fmt.Errorf("failed to instantiate VRFConsumerV2 instance: %w", err) + } + return &EthereumVRFConsumerV2{ - client: e.client, - consumer: instance.(*vrf_consumer_v2.VRFConsumerV2), - address: address, + client: seth, + consumer: contract, + address: data.Address, }, err } -func (e *EthereumContractDeployer) DeployVRFv2Consumer(coordinatorAddr string) (VRFv2Consumer, error) { - address, _, instance, err := e.client.DeployContract("VRFv2Consumer", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return vrf_v2_consumer_wrapper.DeployVRFv2Consumer(auth, backend, common.HexToAddress(coordinatorAddr)) - }) +func DeployVRFv2Consumer(seth *seth.Client, coordinatorAddr common.Address) (VRFv2Consumer, error) { + abi, err := vrf_v2_consumer_wrapper.VRFv2ConsumerMetaData.GetAbi() if err != nil { - return nil, err + return &EthereumVRFv2Consumer{}, fmt.Errorf("failed to get VRFv2Consumer ABI: %w", err) } + + data, err := seth.DeployContract( + seth.NewTXOpts(), + "VRFv2Consumer", + *abi, + common.FromHex(vrf_v2_consumer_wrapper.VRFv2ConsumerMetaData.Bin), + coordinatorAddr) + if err != nil { + return &EthereumVRFv2Consumer{}, fmt.Errorf("VRFv2Consumer instance deployment have failed: %w", err) + } + + contract, err := vrf_v2_consumer_wrapper.NewVRFv2Consumer(data.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRFv2Consumer{}, fmt.Errorf("failed to instantiate VRFv2Consumer instance: %w", err) + } + return &EthereumVRFv2Consumer{ - client: e.client, - consumer: instance.(*vrf_v2_consumer_wrapper.VRFv2Consumer), - address: address, + client: seth, + consumer: contract, + address: data.Address, }, err } @@ -224,7 +245,7 @@ func DeployVRFv2LoadTestConsumer(client *seth.Client, coordinatorAddr string) (V return &EthereumVRFv2LoadTestConsumer{ client: client, consumer: contract, - address: &data.Address, + address: data.Address, }, err } @@ -243,7 +264,7 @@ func LoadVRFv2LoadTestConsumer(seth *seth.Client, addr common.Address) (VRFv2Loa return &EthereumVRFv2LoadTestConsumer{ client: seth, - address: &addr, + address: addr, consumer: contract, }, nil } @@ -274,7 +295,7 @@ func DeployVRFV2Wrapper(client *seth.Client, linkAddr string, linkEthFeedAddr st return &EthereumVRFV2Wrapper{ client: client, wrapper: contract, - address: &data.Address, + address: data.Address, }, err } @@ -302,12 +323,12 @@ func DeployVRFV2WrapperLoadTestConsumer(client *seth.Client, linkAddr string, vr return &EthereumVRFV2WrapperLoadTestConsumer{ client: client, consumer: contract, - address: &data.Address, + address: data.Address, }, err } -func (v *EthereumVRFCoordinatorV2) Address() *common.Address { - return v.address +func (v *EthereumVRFCoordinatorV2) Address() string { + return v.address.Hex() } func (v *EthereumVRFCoordinatorV2) HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error) { @@ -721,7 +742,7 @@ func (v *EthereumVRFConsumerV2) GetAllRandomWords(ctx context.Context, num int) words := make([]*big.Int, 0) for i := 0; i < num; i++ { word, err := v.consumer.SRandomWords(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }, big.NewInt(int64(i))) if err != nil { @@ -733,42 +754,36 @@ func (v *EthereumVRFConsumerV2) GetAllRandomWords(ctx context.Context, num int) } // LoadExistingConsumer loads an EthereumVRFConsumerV2 with a specified address -func (v *EthereumVRFConsumerV2) LoadExistingConsumer(address string, client blockchain.EVMClient) error { - a := common.HexToAddress(address) - consumer, err := vrf_consumer_v2.NewVRFConsumerV2(a, client.(*blockchain.EthereumClient).Client) +func (v *EthereumVRFConsumerV2) LoadExistingConsumer(seth *seth.Client, address common.Address) error { + abi, err := vrf_consumer_v2.VRFConsumerV2MetaData.GetAbi() if err != nil { - return err + return fmt.Errorf("failed to get VRFConsumerV2 ABI: %w", err) + } + seth.ContractStore.AddABI("VRFConsumerV2", *abi) + seth.ContractStore.AddBIN("VRFConsumerV2", common.FromHex(vrf_consumer_v2.VRFConsumerV2MetaData.Bin)) + + contract, err := vrf_consumer_v2.NewVRFConsumerV2(address, seth.Client) + if err != nil { + return fmt.Errorf("failed to instantiate VRFConsumerV2 instance: %w", err) } - v.client = client - v.consumer = consumer - v.address = &a + + v.client = seth + v.consumer = contract + v.address = address + return nil } // CreateFundedSubscription create funded subscription for VRFv2 randomness func (v *EthereumVRFConsumerV2) CreateFundedSubscription(funds *big.Int) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.consumer.CreateSubscriptionAndFund(opts, funds) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + _, err := v.client.Decode(v.consumer.CreateSubscriptionAndFund(v.client.NewTXOpts(), funds)) + return err } // TopUpSubscriptionFunds add funds to a VRFv2 subscription func (v *EthereumVRFConsumerV2) TopUpSubscriptionFunds(funds *big.Int) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.consumer.TopUpSubscription(opts, funds) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + _, err := v.client.Decode(v.consumer.TopUpSubscription(v.client.NewTXOpts(), funds)) + return err } func (v *EthereumVRFConsumerV2) Address() string { @@ -782,7 +797,7 @@ func (v *EthereumVRFv2Consumer) Address() string { // CurrentSubscription get current VRFv2 subscription func (v *EthereumVRFConsumerV2) CurrentSubscription() (uint64, error) { return v.consumer.SSubId(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: context.Background(), }) } @@ -790,28 +805,18 @@ func (v *EthereumVRFConsumerV2) CurrentSubscription() (uint64, error) { // GasAvailable get available gas after randomness fulfilled func (v *EthereumVRFConsumerV2) GasAvailable() (*big.Int, error) { return v.consumer.SGasAvailable(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: context.Background(), }) } func (v *EthereumVRFConsumerV2) Fund(ethAmount *big.Float) error { - gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{ - To: v.address, - }) - if err != nil { - return err - } - return v.client.Fund(v.address.Hex(), ethAmount, gasEstimates) + panic("do not use this function, use actions_seth.SendFunds() instead, otherwise we will have to deal with circular dependencies") } // RequestRandomness request VRFv2 random words func (v *EthereumVRFConsumerV2) RequestRandomness(hash [32]byte, subID uint64, confs uint16, gasLimit uint32, numWords uint32) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.consumer.RequestRandomness(opts, hash, subID, confs, gasLimit, numWords) + _, err := v.client.Decode(v.consumer.RequestRandomness(v.client.NewTXOpts(), hash, subID, confs, gasLimit, numWords)) if err != nil { return err } @@ -822,16 +827,12 @@ func (v *EthereumVRFConsumerV2) RequestRandomness(hash [32]byte, subID uint64, c Interface("KeyHash", hex.EncodeToString(hash[:])). Interface("Consumer Contract", v.address). Msg("RequestRandomness called") - return v.client.ProcessTransaction(tx) + return nil } // RequestRandomness request VRFv2 random words func (v *EthereumVRFv2Consumer) RequestRandomness(hash [32]byte, subID uint64, confs uint16, gasLimit uint32, numWords uint32) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.consumer.RequestRandomWords(opts, subID, gasLimit, confs, numWords, hash) + _, err := v.client.Decode(v.consumer.RequestRandomWords(v.client.NewTXOpts(), subID, gasLimit, confs, numWords, hash)) if err != nil { return err } @@ -842,13 +843,13 @@ func (v *EthereumVRFv2Consumer) RequestRandomness(hash [32]byte, subID uint64, c Interface("KeyHash", hex.EncodeToString(hash[:])). Interface("Consumer Contract", v.address). Msg("RequestRandomness called") - return v.client.ProcessTransaction(tx) + return nil } // RandomnessOutput get VRFv2 randomness output (word) func (v *EthereumVRFConsumerV2) RandomnessOutput(ctx context.Context, arg0 *big.Int) (*big.Int, error) { return v.consumer.SRandomWords(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }, arg0) } @@ -909,14 +910,14 @@ func (v *EthereumVRFv2LoadTestConsumer) RequestRandomWordsWithForceFulfill( func (v *EthereumVRFv2Consumer) GetRequestStatus(ctx context.Context, requestID *big.Int) (vrf_v2_consumer_wrapper.GetRequestStatus, error) { return v.consumer.GetRequestStatus(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }, requestID) } func (v *EthereumVRFv2Consumer) GetLastRequestId(ctx context.Context) (*big.Int, error) { return v.consumer.LastRequestId(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, }) } @@ -1162,7 +1163,7 @@ func (v *EthereumVRFMockETHLINKFeed) Address() string { func (v *EthereumVRFMockETHLINKFeed) LatestRoundData() (*big.Int, error) { data, err := v.feed.LatestRoundData(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: context.Background(), }) if err != nil { @@ -1173,7 +1174,7 @@ func (v *EthereumVRFMockETHLINKFeed) LatestRoundData() (*big.Int, error) { func (v *EthereumVRFMockETHLINKFeed) LatestRoundDataUpdatedAt() (*big.Int, error) { data, err := v.feed.LatestRoundData(&bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: context.Background(), }) if err != nil { @@ -1183,13 +1184,6 @@ func (v *EthereumVRFMockETHLINKFeed) LatestRoundDataUpdatedAt() (*big.Int, error } func (v *EthereumVRFMockETHLINKFeed) SetBlockTimestampDeduction(blockTimestampDeduction *big.Int) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.feed.SetBlockTimestampDeduction(opts, blockTimestampDeduction) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + _, err := v.client.Decode(v.feed.SetBlockTimestampDeduction(v.client.NewTXOpts(), blockTimestampDeduction)) + return err } diff --git a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go index 697e4d14852..6c9a4952299 100644 --- a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go @@ -11,7 +11,6 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/montanaflynn/stats" - "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink/integration-tests/wrappers" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2_5" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_v2plus_load_test_with_metrics" @@ -22,32 +21,32 @@ import ( ) type EthereumVRFCoordinatorV2_5 struct { - address *common.Address - client blockchain.EVMClient + address common.Address + client *seth.Client coordinator vrf_coordinator_v2_5.VRFCoordinatorV25Interface } type EthereumVRFCoordinatorV2PlusUpgradedVersion struct { - address *common.Address - client blockchain.EVMClient + address common.Address + client *seth.Client coordinator *vrf_v2plus_upgraded_version.VRFCoordinatorV2PlusUpgradedVersion } // EthereumVRFv2PlusLoadTestConsumer represents VRFv2Plus consumer contract for performing Load Tests type EthereumVRFv2PlusLoadTestConsumer struct { - address *common.Address + address common.Address client *seth.Client consumer *vrf_v2plus_load_test_with_metrics.VRFV2PlusLoadTestWithMetrics } type EthereumVRFV2PlusWrapperLoadTestConsumer struct { - address *common.Address + address common.Address client *seth.Client consumer *vrfv2plus_wrapper_load_test_consumer.VRFV2PlusWrapperLoadTestConsumer } type EthereumVRFV2PlusWrapper struct { - address *common.Address + address common.Address client *seth.Client wrapper *vrfv2plus_wrapper.VRFV2PlusWrapper } @@ -103,20 +102,31 @@ func (v *EthereumVRFV2PlusWrapper) Coordinator(ctx context.Context) (common.Addr } // DeployVRFCoordinatorV2_5 deploys VRFV2_5 coordinator contract -func (e *EthereumContractDeployer) DeployVRFCoordinatorV2_5(bhsAddr string) (VRFCoordinatorV2_5, error) { - address, _, instance, err := e.client.DeployContract("VRFCoordinatorV2Plus", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return vrf_coordinator_v2_5.DeployVRFCoordinatorV25(auth, wrappers.MustNewWrappedContractBackend(e.client, nil), common.HexToAddress(bhsAddr)) - }) +func DeployVRFCoordinatorV2_5(seth *seth.Client, bhsAddr string) (VRFCoordinatorV2_5, error) { + abi, err := vrf_coordinator_v2_5.VRFCoordinatorV25MetaData.GetAbi() if err != nil { - return nil, err + return &EthereumVRFCoordinatorV2_5{}, fmt.Errorf("failed to get VRFCoordinatorV2Plus ABI: %w", err) } + + coordinatorDeploymentData, err := seth.DeployContract( + seth.NewTXOpts(), + "VRFCoordinatorV2Plus", + *abi, + common.FromHex(vrf_coordinator_v2_5.VRFCoordinatorV25MetaData.Bin), + common.HexToAddress(bhsAddr)) + if err != nil { + return &EthereumVRFCoordinatorV2_5{}, fmt.Errorf("VRFCoordinatorV2Plus instance deployment have failed: %w", err) + } + + contract, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(coordinatorDeploymentData.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRFCoordinatorV2_5{}, fmt.Errorf("failed to instantiate VRFCoordinatorV2Plus instance: %w", err) + } + return &EthereumVRFCoordinatorV2_5{ - client: e.client, - coordinator: instance.(*vrf_coordinator_v2_5.VRFCoordinatorV25), - address: address, + client: seth, + coordinator: contract, + address: coordinatorDeploymentData.Address, }, err } @@ -126,7 +136,7 @@ func (v *EthereumVRFCoordinatorV2_5) Address() string { func (v *EthereumVRFCoordinatorV2_5) HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } hash, err := v.coordinator.HashOfKey(opts, pubKey) @@ -138,7 +148,7 @@ func (v *EthereumVRFCoordinatorV2_5) HashOfKey(ctx context.Context, pubKey [2]*b func (v *EthereumVRFCoordinatorV2_5) GetActiveSubscriptionIds(ctx context.Context, startIndex *big.Int, maxCount *big.Int) ([]*big.Int, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } activeSubscriptionIds, err := v.coordinator.GetActiveSubscriptionIds(opts, startIndex, maxCount) @@ -150,7 +160,7 @@ func (v *EthereumVRFCoordinatorV2_5) GetActiveSubscriptionIds(ctx context.Contex func (v *EthereumVRFCoordinatorV2_5) PendingRequestsExist(ctx context.Context, subID *big.Int) (bool, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } pendingRequestExists, err := v.coordinator.PendingRequestExists(opts, subID) @@ -182,7 +192,7 @@ func (v *EthereumVRFCoordinatorV2_5) ParseRandomWordsRequested(log types.Log) (* func (v *EthereumVRFCoordinatorV2_5) GetSubscription(ctx context.Context, subID *big.Int) (Subscription, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } subscription, err := v.coordinator.GetSubscription(opts, subID) @@ -200,7 +210,7 @@ func (v *EthereumVRFCoordinatorV2_5) GetSubscription(ctx context.Context, subID func (v *EthereumVRFCoordinatorV2_5) GetLinkTotalBalance(ctx context.Context) (*big.Int, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } totalBalance, err := v.coordinator.STotalBalance(opts) @@ -211,7 +221,7 @@ func (v *EthereumVRFCoordinatorV2_5) GetLinkTotalBalance(ctx context.Context) (* } func (v *EthereumVRFCoordinatorV2_5) GetNativeTokenTotalBalance(ctx context.Context) (*big.Int, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } totalBalance, err := v.coordinator.STotalNativeBalance(opts) @@ -225,67 +235,45 @@ func (v *EthereumVRFCoordinatorV2_5) GetNativeTokenTotalBalance(ctx context.Cont // return funds to sub owner, // does not check if pending requests for a sub exist func (v *EthereumVRFCoordinatorV2_5) OwnerCancelSubscription(subID *big.Int) (*types.Transaction, error) { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return nil, err - } - tx, err := v.coordinator.OwnerCancelSubscription( - opts, + tx, err := v.client.Decode(v.coordinator.OwnerCancelSubscription( + v.client.NewTXOpts(), subID, - ) + )) if err != nil { return nil, err } - return tx, v.client.ProcessTransaction(tx) + return tx.Transaction, nil } // CancelSubscription cancels subscription by Sub owner, // return funds to specified address, // checks if pending requests for a sub exist func (v *EthereumVRFCoordinatorV2_5) CancelSubscription(subID *big.Int, to common.Address) (*types.Transaction, error) { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return nil, err - } - tx, err := v.coordinator.CancelSubscription( - opts, + tx, err := v.client.Decode(v.coordinator.CancelSubscription( + v.client.NewTXOpts(), subID, to, - ) + )) if err != nil { return nil, err } - return tx, v.client.ProcessTransaction(tx) + return tx.Transaction, nil } func (v *EthereumVRFCoordinatorV2_5) Withdraw(recipient common.Address) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.Withdraw( - opts, + _, err := v.client.Decode(v.coordinator.Withdraw( + v.client.NewTXOpts(), recipient, - ) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + )) + return err } func (v *EthereumVRFCoordinatorV2_5) WithdrawNative(recipient common.Address) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.WithdrawNative( - opts, + _, err := v.client.Decode(v.coordinator.WithdrawNative( + v.client.NewTXOpts(), recipient, - ) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + )) + return err } func (v *EthereumVRFCoordinatorV2_5) SetConfig( @@ -298,12 +286,8 @@ func (v *EthereumVRFCoordinatorV2_5) SetConfig( fulfillmentFlatFeeLinkDiscountPPM uint32, nativePremiumPercentage uint8, linkPremiumPercentage uint8) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.SetConfig( - opts, + _, err := v.client.Decode(v.coordinator.SetConfig( + v.client.NewTXOpts(), minimumRequestConfirmations, maxGasLimit, stalenessSeconds, @@ -313,114 +297,69 @@ func (v *EthereumVRFCoordinatorV2_5) SetConfig( fulfillmentFlatFeeLinkDiscountPPM, nativePremiumPercentage, linkPremiumPercentage, - ) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + )) + return err } func (v *EthereumVRFCoordinatorV2_5) SetLINKAndLINKNativeFeed(linkAddress string, linkNativeFeedAddress string) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.SetLINKAndLINKNativeFeed( - opts, + _, err := v.client.Decode(v.coordinator.SetLINKAndLINKNativeFeed( + v.client.NewTXOpts(), common.HexToAddress(linkAddress), common.HexToAddress(linkNativeFeedAddress), - ) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + )) + return err } func (v *EthereumVRFCoordinatorV2_5) RegisterProvingKey( publicProvingKey [2]*big.Int, gasLaneMaxGas uint64, ) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.RegisterProvingKey(opts, publicProvingKey, gasLaneMaxGas) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + _, err := v.client.Decode(v.coordinator.RegisterProvingKey(v.client.NewTXOpts(), publicProvingKey, gasLaneMaxGas)) + return err } func (v *EthereumVRFCoordinatorV2_5) CreateSubscription() (*types.Transaction, error) { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) + tx, err := v.client.Decode(v.coordinator.CreateSubscription(v.client.NewTXOpts())) if err != nil { return nil, err } - tx, err := v.coordinator.CreateSubscription(opts) - if err != nil { - return nil, err - } - return tx, v.client.ProcessTransaction(tx) + return tx.Transaction, nil } func (v *EthereumVRFCoordinatorV2_5) Migrate(subId *big.Int, coordinatorAddress string) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.Migrate(opts, subId, common.HexToAddress(coordinatorAddress)) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + _, err := v.client.Decode(v.coordinator.Migrate(v.client.NewTXOpts(), subId, common.HexToAddress(coordinatorAddress))) + return err } func (v *EthereumVRFCoordinatorV2_5) RegisterMigratableCoordinator(migratableCoordinatorAddress string) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.RegisterMigratableCoordinator(opts, common.HexToAddress(migratableCoordinatorAddress)) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + _, err := v.client.Decode(v.coordinator.RegisterMigratableCoordinator(v.client.NewTXOpts(), common.HexToAddress(migratableCoordinatorAddress))) + return err } func (v *EthereumVRFCoordinatorV2_5) AddConsumer(subId *big.Int, consumerAddress string) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.AddConsumer( - opts, + _, err := v.client.Decode(v.coordinator.AddConsumer( + v.client.NewTXOpts(), subId, common.HexToAddress(consumerAddress), - ) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + )) + return err } func (v *EthereumVRFCoordinatorV2_5) FundSubscriptionWithNative(subId *big.Int, nativeTokenAmount *big.Int) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } + opts := v.client.NewTXOpts() opts.Value = nativeTokenAmount - tx, err := v.coordinator.FundSubscriptionWithNative( + _, err := v.client.Decode(v.coordinator.FundSubscriptionWithNative( opts, subId, - ) + )) if err != nil { return err } - return v.client.ProcessTransaction(tx) + return nil } func (v *EthereumVRFCoordinatorV2_5) FindSubscriptionID(subID *big.Int) (*big.Int, error) { - owner := v.client.GetDefaultWallet().Address() + owner := v.client.Addresses[0] subscriptionIterator, err := v.coordinator.FilterSubscriptionCreated( nil, []*big.Int{subID}, @@ -707,20 +646,31 @@ func (v *EthereumVRFv2PlusLoadTestConsumer) GetLoadTestMetrics(ctx context.Conte }, nil } -func (e *EthereumContractDeployer) DeployVRFCoordinatorV2PlusUpgradedVersion(bhsAddr string) (VRFCoordinatorV2PlusUpgradedVersion, error) { - address, _, instance, err := e.client.DeployContract("VRFCoordinatorV2PlusUpgradedVersion", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return vrf_v2plus_upgraded_version.DeployVRFCoordinatorV2PlusUpgradedVersion(auth, backend, common.HexToAddress(bhsAddr)) - }) +func DeployVRFCoordinatorV2PlusUpgradedVersion(seth *seth.Client, bhsAddr string) (VRFCoordinatorV2PlusUpgradedVersion, error) { + abi, err := vrf_v2plus_upgraded_version.VRFCoordinatorV2PlusUpgradedVersionMetaData.GetAbi() if err != nil { - return nil, err + return &EthereumVRFCoordinatorV2PlusUpgradedVersion{}, fmt.Errorf("failed to get VRFCoordinatorV2PlusUpgradedVersion ABI: %w", err) } + + coordinatorDeploymentData, err := seth.DeployContract( + seth.NewTXOpts(), + "VRFCoordinatorV2PlusUpgradedVersion", + *abi, + common.FromHex(vrf_v2plus_upgraded_version.VRFCoordinatorV2PlusUpgradedVersionMetaData.Bin), + common.HexToAddress(bhsAddr)) + if err != nil { + return &EthereumVRFCoordinatorV2PlusUpgradedVersion{}, fmt.Errorf("VRFCoordinatorV2PlusUpgradedVersion instance deployment have failed: %w", err) + } + + contract, err := vrf_v2plus_upgraded_version.NewVRFCoordinatorV2PlusUpgradedVersion(coordinatorDeploymentData.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRFCoordinatorV2PlusUpgradedVersion{}, fmt.Errorf("failed to instantiate VRFCoordinatorV2PlusUpgradedVersion instance: %w", err) + } + return &EthereumVRFCoordinatorV2PlusUpgradedVersion{ - client: e.client, - coordinator: instance.(*vrf_v2plus_upgraded_version.VRFCoordinatorV2PlusUpgradedVersion), - address: address, + client: seth, + coordinator: contract, + address: coordinatorDeploymentData.Address, }, err } @@ -730,7 +680,7 @@ func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) Address() string { func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } hash, err := v.coordinator.HashOfKey(opts, pubKey) @@ -742,7 +692,7 @@ func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) HashOfKey(ctx context.Cont func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) GetActiveSubscriptionIds(ctx context.Context, startIndex *big.Int, maxCount *big.Int) ([]*big.Int, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } activeSubscriptionIds, err := v.coordinator.GetActiveSubscriptionIds(opts, startIndex, maxCount) @@ -754,7 +704,7 @@ func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) GetActiveSubscriptionIds(c func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) GetSubscription(ctx context.Context, subID *big.Int) (vrf_v2plus_upgraded_version.GetSubscription, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } subscription, err := v.coordinator.GetSubscription(opts, subID) @@ -775,12 +725,8 @@ func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) SetConfig( nativePremiumPercentage uint8, linkPremiumPercentage uint8, ) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.SetConfig( - opts, + _, err := v.client.Decode(v.coordinator.SetConfig( + v.client.NewTXOpts(), minimumRequestConfirmations, maxGasLimit, stalenessSeconds, @@ -790,59 +736,35 @@ func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) SetConfig( fulfillmentFlatFeeLinkDiscountPPM, nativePremiumPercentage, linkPremiumPercentage, - ) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + )) + return err } func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) SetLINKAndLINKNativeFeed(linkAddress string, linkNativeFeedAddress string) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.SetLINKAndLINKNativeFeed( - opts, + _, err := v.client.Decode(v.coordinator.SetLINKAndLINKNativeFeed( + v.client.NewTXOpts(), common.HexToAddress(linkAddress), common.HexToAddress(linkNativeFeedAddress), - ) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + )) + return err } func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) RegisterProvingKey( publicProvingKey [2]*big.Int, gasLaneMaxGas uint64, ) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.RegisterProvingKey(opts, publicProvingKey, gasLaneMaxGas) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + _, err := v.client.Decode(v.coordinator.RegisterProvingKey(v.client.NewTXOpts(), publicProvingKey, gasLaneMaxGas)) + return err } func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) CreateSubscription() error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.CreateSubscription(opts) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + _, err := v.client.Decode(v.coordinator.CreateSubscription(v.client.NewTXOpts())) + return err } func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) GetLinkTotalBalance(ctx context.Context) (*big.Int, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } totalBalance, err := v.coordinator.STotalBalance(opts) @@ -853,7 +775,7 @@ func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) GetLinkTotalBalance(ctx co } func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) GetNativeTokenTotalBalance(ctx context.Context) (*big.Int, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), + From: v.client.Addresses[0], Context: ctx, } totalBalance, err := v.coordinator.STotalNativeBalance(opts) @@ -864,63 +786,36 @@ func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) GetNativeTokenTotalBalance } func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) Migrate(subId *big.Int, coordinatorAddress string) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.Migrate(opts, subId, common.HexToAddress(coordinatorAddress)) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + _, err := v.client.Decode(v.coordinator.Migrate(v.client.NewTXOpts(), subId, common.HexToAddress(coordinatorAddress))) + return err } func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) RegisterMigratableCoordinator(migratableCoordinatorAddress string) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.RegisterMigratableCoordinator(opts, common.HexToAddress(migratableCoordinatorAddress)) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + _, err := v.client.Decode(v.coordinator.RegisterMigratableCoordinator(v.client.NewTXOpts(), common.HexToAddress(migratableCoordinatorAddress))) + return err } func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) AddConsumer(subId *big.Int, consumerAddress string) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.AddConsumer( - opts, + _, err := v.client.Decode(v.coordinator.AddConsumer( + v.client.NewTXOpts(), subId, common.HexToAddress(consumerAddress), - ) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + )) + return err } func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) FundSubscriptionWithNative(subId *big.Int, nativeTokenAmount *big.Int) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } + opts := v.client.NewTXOpts() opts.Value = nativeTokenAmount - tx, err := v.coordinator.FundSubscriptionWithNative( + _, err := v.client.Decode(v.coordinator.FundSubscriptionWithNative( opts, subId, - ) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) + )) + return err } func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) FindSubscriptionID() (*big.Int, error) { - owner := v.client.GetDefaultWallet().Address() + owner := v.client.Addresses[0] subscriptionIterator, err := v.coordinator.FilterSubscriptionCreated( nil, nil, @@ -1058,7 +953,7 @@ func DeployVRFv2PlusLoadTestConsumer(seth *seth.Client, coordinatorAddr string) return &EthereumVRFv2PlusLoadTestConsumer{ client: seth, consumer: contract, - address: &data.Address, + address: data.Address, }, err } @@ -1087,7 +982,7 @@ func DeployVRFV2PlusWrapper(seth *seth.Client, linkAddr string, linkEthFeedAddr return &EthereumVRFV2PlusWrapper{ client: seth, wrapper: contract, - address: &data.Address, + address: data.Address, }, err } @@ -1097,7 +992,7 @@ func DeployVRFV2PlusWrapperLoadTestConsumer(seth *seth.Client, vrfV2PlusWrapperA return &EthereumVRFV2PlusWrapperLoadTestConsumer{}, fmt.Errorf("failed to get VRFV2PlusWrapperLoadTestConsumer ABI: %w", err) } - coordinatorDeploymentData, err := seth.DeployContract( + data, err := seth.DeployContract( seth.NewTXOpts(), "VRFV2PlusWrapperLoadTestConsumer", *abi, @@ -1107,7 +1002,7 @@ func DeployVRFV2PlusWrapperLoadTestConsumer(seth *seth.Client, vrfV2PlusWrapperA return &EthereumVRFV2PlusWrapperLoadTestConsumer{}, fmt.Errorf("VRFV2PlusWrapperLoadTestConsumer instance deployment have failed: %w", err) } - contract, err := vrfv2plus_wrapper_load_test_consumer.NewVRFV2PlusWrapperLoadTestConsumer(coordinatorDeploymentData.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + contract, err := vrfv2plus_wrapper_load_test_consumer.NewVRFV2PlusWrapperLoadTestConsumer(data.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) if err != nil { return &EthereumVRFV2PlusWrapperLoadTestConsumer{}, fmt.Errorf("failed to instantiate VRFV2PlusWrapperLoadTestConsumer instance: %w", err) } @@ -1115,7 +1010,7 @@ func DeployVRFV2PlusWrapperLoadTestConsumer(seth *seth.Client, vrfV2PlusWrapperA return &EthereumVRFV2PlusWrapperLoadTestConsumer{ client: seth, consumer: contract, - address: &coordinatorDeploymentData.Address, + address: data.Address, }, err } diff --git a/integration-tests/smoke/vrfv2_test.go b/integration-tests/smoke/vrfv2_test.go index 77fe49f422d..f9608ad603b 100644 --- a/integration-tests/smoke/vrfv2_test.go +++ b/integration-tests/smoke/vrfv2_test.go @@ -49,12 +49,12 @@ func TestVRFv2Basic(t *testing.T) { chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID cleanupFn := func() { - evmClient, err := testEnv.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") + sethClient, err := testEnv.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") - if evmClient.NetworkSimulated() { + if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). - Str("Network Name", evmClient.GetNetworkName()). + Str("Network Name", sethClient.Cfg.Network.Name). Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") } else { if *vrfv2Config.General.CancelSubsAfterTestRun { From 4afe6fed3888fd0fb1a61e87bc45bc22ade79960 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Thu, 25 Apr 2024 12:07:10 +0200 Subject: [PATCH 08/43] wip 8 --- .../actions/ocr2vrf_actions/ocr2vrf_steps.go | 56 +-- integration-tests/actions/seth/actions.go | 342 +++++++++++++++- .../actions/seth/keeper_helpers.go | 32 ++ integration-tests/actions/seth/refund.go | 172 ++++---- .../actions/vrf/vrfv2/contract_steps.go | 25 +- .../actions/vrf/vrfv2plus/contract_steps.go | 34 +- .../actions/vrf/vrfv2plus/logging_helpers.go | 9 +- .../actions/vrf/vrfv2plus/setup_steps.go | 30 +- integration-tests/chaos/ocr2vrf_chaos_test.go | 24 +- .../contracts/contract_deployer.go | 37 +- .../contracts/contract_models.go | 6 + .../contracts/ethereum_contracts.go | 14 +- .../contracts/ethereum_contracts_seth.go | 89 +++++ .../contracts/ethereum_ocr2vrf_contracts.go | 377 ++++++++---------- .../contracts/ethereum_vrf_contracts.go | 65 +-- .../contracts/ethereum_vrfv2plus_contracts.go | 12 +- integration-tests/contracts/test_contracts.go | 31 +- integration-tests/docker/test_env/test_env.go | 2 +- integration-tests/go.mod | 2 +- integration-tests/go.sum | 4 +- integration-tests/smoke/ocr2vrf_test.go | 38 +- integration-tests/smoke/vrfv2plus_test.go | 43 +- 22 files changed, 862 insertions(+), 582 deletions(-) create mode 100644 integration-tests/actions/seth/keeper_helpers.go diff --git a/integration-tests/actions/ocr2vrf_actions/ocr2vrf_steps.go b/integration-tests/actions/ocr2vrf_actions/ocr2vrf_steps.go index dd51e302744..dbffb768985 100644 --- a/integration-tests/actions/ocr2vrf_actions/ocr2vrf_steps.go +++ b/integration-tests/actions/ocr2vrf_actions/ocr2vrf_steps.go @@ -11,15 +11,16 @@ import ( "github.com/stretchr/testify/require" ocr2vrftypes "github.com/smartcontractkit/chainlink-vrf/types" + "github.com/smartcontractkit/seth" "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink-testing-framework/logging" "github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext" + actions_seth "github.com/smartcontractkit/chainlink/integration-tests/actions/seth" chainlinkutils "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/chaintype" - "github.com/smartcontractkit/chainlink/integration-tests/actions" "github.com/smartcontractkit/chainlink/integration-tests/actions/ocr2vrf_actions/ocr2vrf_constants" "github.com/smartcontractkit/chainlink/integration-tests/client" "github.com/smartcontractkit/chainlink/integration-tests/contracts" @@ -164,45 +165,32 @@ func SetAndGetOCR2VRFPluginConfig( return ocr2VRFPluginConfig } -func FundVRFCoordinatorV3Subscription(t *testing.T, linkToken contracts.LinkToken, coordinator contracts.VRFCoordinatorV3, chainClient blockchain.EVMClient, subscriptionID, linkFundingAmount *big.Int) { +func FundVRFCoordinatorV3Subscription(t *testing.T, linkToken contracts.LinkToken, coordinator contracts.VRFCoordinatorV3, chainClient *seth.Client, subscriptionID, linkFundingAmount *big.Int) { encodedSubId, err := chainlinkutils.ABIEncode(`[{"type":"uint256"}]`, subscriptionID) require.NoError(t, err, "Error Abi encoding subscriptionID") _, err = linkToken.TransferAndCall(coordinator.Address(), big.NewInt(0).Mul(linkFundingAmount, big.NewInt(1e18)), encodedSubId) require.NoError(t, err, "Error sending Link token") - err = chainClient.WaitForEvents() - require.NoError(t, err, "Error waiting for TXs to complete") } -func DeployOCR2VRFContracts(t *testing.T, contractDeployer contracts.ContractDeployer, chainClient blockchain.EVMClient, linkToken contracts.LinkToken, beaconPeriodBlocksCount *big.Int, keyID string) (contracts.DKG, contracts.VRFCoordinatorV3, contracts.VRFBeacon, contracts.VRFBeaconConsumer) { - dkg, err := contractDeployer.DeployDKG() +func DeployOCR2VRFContracts(t *testing.T, chainClient *seth.Client, linkToken contracts.LinkToken, beaconPeriodBlocksCount *big.Int, keyID string) (contracts.DKG, contracts.VRFCoordinatorV3, contracts.VRFBeacon, contracts.VRFBeaconConsumer) { + dkg, err := contracts.DeployDKG(chainClient) require.NoError(t, err, "Error deploying DKG Contract") - err = chainClient.WaitForEvents() - require.NoError(t, err, "Error waiting for TXs to complete") - - coordinator, err := contractDeployer.DeployOCR2VRFCoordinator(beaconPeriodBlocksCount, linkToken.Address()) + coordinator, err := contracts.DeployOCR2VRFCoordinator(chainClient, beaconPeriodBlocksCount, linkToken.Address()) require.NoError(t, err, "Error deploying OCR2VRFCoordinator Contract") - err = chainClient.WaitForEvents() - require.NoError(t, err, "Error waiting for TXs to complete") - - vrfBeacon, err := contractDeployer.DeployVRFBeacon(coordinator.Address(), linkToken.Address(), dkg.Address(), keyID) + vrfBeacon, err := contracts.DeployVRFBeacon(chainClient, coordinator.Address(), linkToken.Address(), dkg.Address(), keyID) require.NoError(t, err, "Error deploying VRFBeacon Contract") - err = chainClient.WaitForEvents() - require.NoError(t, err, "Error waiting for TXs to complete") - consumer, err := contractDeployer.DeployVRFBeaconConsumer(coordinator.Address(), beaconPeriodBlocksCount) + consumer, err := contracts.DeployVRFBeaconConsumer(chainClient, coordinator.Address(), beaconPeriodBlocksCount) require.NoError(t, err, "Error deploying VRFBeaconConsumer Contract") - err = chainClient.WaitForEvents() - require.NoError(t, err, "Error waiting for TXs to complete") return dkg, coordinator, vrfBeacon, consumer } func RequestAndRedeemRandomness( t *testing.T, consumer contracts.VRFBeaconConsumer, - chainClient blockchain.EVMClient, vrfBeacon contracts.VRFBeacon, numberOfRandomWordsToRequest uint16, subscriptionID, @@ -218,9 +206,6 @@ func RequestAndRedeemRandomness( require.NoError(t, err, "Error requesting randomness from Consumer Contract") l.Info().Interface("TX Hash", receipt.TxHash).Msg("Randomness requested from Consumer contract") - err = chainClient.WaitForEvents() - require.NoError(t, err, "Error waiting for TXs to complete") - requestID := getRequestId(t, consumer, receipt, confirmationDelay) newTransmissionEvent, err := vrfBeacon.WaitForNewTransmissionEvent(randomnessTransmissionEventTimeout) @@ -229,8 +214,6 @@ func RequestAndRedeemRandomness( err = consumer.RedeemRandomness(subscriptionID, requestID) require.NoError(t, err, "Error redeeming randomness from Consumer Contract") - err = chainClient.WaitForEvents() - require.NoError(t, err, "Error waiting for TXs to complete") return requestID } @@ -238,7 +221,6 @@ func RequestAndRedeemRandomness( func RequestRandomnessFulfillmentAndWaitForFulfilment( t *testing.T, consumer contracts.VRFBeaconConsumer, - chainClient blockchain.EVMClient, vrfBeacon contracts.VRFBeacon, numberOfRandomWordsToRequest uint16, subscriptionID *big.Int, @@ -257,18 +239,12 @@ func RequestRandomnessFulfillmentAndWaitForFulfilment( require.NoError(t, err, "Error requesting Randomness Fulfillment") l.Info().Interface("TX Hash", receipt.TxHash).Msg("Randomness Fulfillment requested from Consumer contract") - err = chainClient.WaitForEvents() - require.NoError(t, err, "Error waiting for TXs to complete") - requestID := getRequestId(t, consumer, receipt, confirmationDelay) newTransmissionEvent, err := vrfBeacon.WaitForNewTransmissionEvent(randomnessTransmissionEventTimeout) require.NoError(t, err, "Error waiting for NewTransmission event from VRF Beacon Contract") l.Info().Interface("NewTransmission event", newTransmissionEvent).Msg("Randomness Fulfillment transmitted by DON") - err = chainClient.WaitForEvents() - require.NoError(t, err, "Error waiting for TXs to complete") - return requestID } @@ -290,12 +266,12 @@ func SetupOCR2VRFUniverse( t *testing.T, linkToken contracts.LinkToken, mockETHLinkFeed contracts.MockETHLINKFeed, - contractDeployer contracts.ContractDeployer, - chainClient blockchain.EVMClient, + chainClient *seth.Client, nodeAddresses []common.Address, chainlinkNodes []*client.ChainlinkK8sClient, testNetwork blockchain.EVMNetwork, ) (contracts.DKG, contracts.VRFCoordinatorV3, contracts.VRFBeacon, contracts.VRFBeaconConsumer, *big.Int) { + l := logging.GetTestLogger(t) // Deploy DKG contract // Deploy VRFCoordinator(beaconPeriodBlocks, linkAddress, linkEthfeedAddress) @@ -303,7 +279,6 @@ func SetupOCR2VRFUniverse( // Deploy Consumer Contract dkgContract, coordinatorContract, vrfBeaconContract, consumerContract := DeployOCR2VRFContracts( t, - contractDeployer, chainClient, linkToken, ocr2vrf_constants.BeaconPeriodBlocksCount, @@ -318,23 +293,17 @@ func SetupOCR2VRFUniverse( require.NoError(t, err, "Error setting Producer for VRFCoordinator contract") err = coordinatorContract.SetConfig(2.5e6, 160 /* 5 EVM words */) require.NoError(t, err, "Error setting config for VRFCoordinator contract") - err = chainClient.WaitForEvents() - require.NoError(t, err, "Error waiting for TXs to complete") // Subscription: //1. Create Subscription err = coordinatorContract.CreateSubscription() require.NoError(t, err, "Error creating subscription in VRFCoordinator contract") - err = chainClient.WaitForEvents() - require.NoError(t, err, "Error waiting for TXs to complete") subID, err := coordinatorContract.FindSubscriptionID() require.NoError(t, err) //2. Add Consumer to subscription err = coordinatorContract.AddConsumer(subID, consumerContract.Address()) require.NoError(t, err, "Error adding a consumer to a subscription in VRFCoordinator contract") - err = chainClient.WaitForEvents() - require.NoError(t, err, "Error waiting for TXs to complete") //3. fund subscription with LINK token FundVRFCoordinatorV3Subscription( @@ -352,10 +321,9 @@ func SetupOCR2VRFUniverse( require.NoError(t, err, "Error setting Payees in VRFBeacon Contract") // fund OCR Nodes (so that they can transmit) - err = actions.FundChainlinkNodes(chainlinkNodes, chainClient, ocr2vrf_constants.EthFundingAmount) + nodes := contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(chainlinkNodes) + err = actions_seth.FundChainlinkNodesFromRootAddress(l, chainClient, nodes, ocr2vrf_constants.EthFundingAmount) require.NoError(t, err, "Error funding Nodes") - err = chainClient.WaitForEvents() - require.NoError(t, err, "Error waiting for TXs to complete") bootstrapNode := chainlinkNodes[0] nonBootstrapNodes := chainlinkNodes[1:] diff --git a/integration-tests/actions/seth/actions.go b/integration-tests/actions/seth/actions.go index 7b128620158..242aa13b1e9 100644 --- a/integration-tests/actions/seth/actions.go +++ b/integration-tests/actions/seth/actions.go @@ -5,25 +5,35 @@ import ( "crypto/ecdsa" "fmt" "math/big" + "strings" "testing" "time" + "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" "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/rpc" "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" + "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/v2/core/gethwrappers/generated/link_token_interface" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/operator_factory" "github.com/smartcontractkit/chainlink-testing-framework/utils/conversions" "github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext" "github.com/smartcontractkit/chainlink/integration-tests/client" "github.com/smartcontractkit/chainlink/integration-tests/contracts" + tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig" + "github.com/smartcontractkit/chainlink/integration-tests/utils" ) var ContractDeploymentInterval = 200 @@ -51,9 +61,61 @@ func FundChainlinkNodes( nodes []contracts.ChainlinkNodeWithKeysAndAddress, privateKey *ecdsa.PrivateKey, amount *big.Float, +) error { + keyAddressFn := func(cl contracts.ChainlinkNodeWithKeysAndAddress) (string, error) { + return cl.PrimaryEthAddress() + } + return fundChainlinkNodesAtAnyKey(logger, client, nodes, privateKey, amount, keyAddressFn) +} + +// FundChainlinkNodesAtKeyIndexFromRootAddress sends native token amount (expressed in human-scale) to each Chainlink Node +// from root private key.It returns an error if any of the transactions failed. It sends the funds to +// node address at keyIndex (as each node can have multiple addresses). +func FundChainlinkNodesAtKeyIndexFromRootAddress( + logger zerolog.Logger, + client *seth.Client, + nodes []contracts.ChainlinkNodeWithKeysAndAddress, + amount *big.Float, + keyIndex int, +) error { + if len(client.PrivateKeys) == 0 { + return errors.Wrap(errors.New(seth.ErrNoKeyLoaded), fmt.Sprintf("requested key: %d", 0)) + } + + return FundChainlinkNodesAtKeyIndex(logger, client, nodes, client.PrivateKeys[0], amount, keyIndex) +} + +// FundChainlinkNodesAtKeyIndex sends native token amount (expressed in human-scale) to each Chainlink Node +// from private key's address. It returns an error if any of the transactions failed. It sends the funds to +// node address at keyIndex (as each node can have multiple addresses). +func FundChainlinkNodesAtKeyIndex( + logger zerolog.Logger, + client *seth.Client, + nodes []contracts.ChainlinkNodeWithKeysAndAddress, + privateKey *ecdsa.PrivateKey, + amount *big.Float, + keyIndex int, +) error { + keyAddressFn := func(cl contracts.ChainlinkNodeWithKeysAndAddress) (string, error) { + toAddress, err := cl.EthAddresses() + if err != nil { + return "", err + } + return toAddress[keyIndex], nil + } + return fundChainlinkNodesAtAnyKey(logger, client, nodes, privateKey, amount, keyAddressFn) +} + +func fundChainlinkNodesAtAnyKey( + logger zerolog.Logger, + client *seth.Client, + nodes []contracts.ChainlinkNodeWithKeysAndAddress, + privateKey *ecdsa.PrivateKey, + amount *big.Float, + keyAddressFn func(contracts.ChainlinkNodeWithKeysAndAddress) (string, error), ) error { for _, cl := range nodes { - toAddress, err := cl.PrimaryEthAddress() + toAddress, err := keyAddressFn(cl) if err != nil { return err } @@ -188,6 +250,18 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa txTimeout = *payload.TxTimeout } + logger.Debug(). + Str("From", fromAddress.Hex()). + Str("To", payload.ToAddress.Hex()). + Str("Amount (wei/ether)", fmt.Sprintf("%s/%s", payload.Amount, conversions.WeiToEther(payload.Amount).Text('f', -1))). + Uint64("Nonce", nonce). + Uint64("Gas Limit", gasLimit). + Str("Gas Price", gasPrice.String()). + Str("Gas Fee Cap", gasFeeCap.String()). + Str("Gas Tip Cap", gasTipCap.String()). + Bool("Dynamic fees", client.Cfg.Network.EIP1559DynamicFees). + Msg("About to send funds") + ctx, cancel = context.WithTimeout(ctx, txTimeout) defer cancel() err = client.Client.SendTransaction(ctx, signedTx) @@ -199,7 +273,7 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa Str("From", fromAddress.Hex()). Str("To", payload.ToAddress.Hex()). Str("TxHash", signedTx.Hash().String()). - Str("Amount", conversions.WeiToEther(payload.Amount).String()). + Str("Amount (wei/ether)", fmt.Sprintf("%s/%s", payload.Amount, conversions.WeiToEther(payload.Amount).Text('f', -1))). Uint64("Nonce", nonce). Uint64("Gas Limit", gasLimit). Str("Gas Price", gasPrice.String()). @@ -406,6 +480,43 @@ func ConfigureOCRv2AggregatorContracts( return nil } +// TeardownSuite tears down networks/clients and environment and creates a logs folder for failed tests in the +// specified path. Can also accept a testreporter (if one was used) to log further results +func TeardownSuite( + t *testing.T, + chainClient *seth.Client, + env *environment.Environment, + chainlinkNodes []*client.ChainlinkK8sClient, + optionalTestReporter testreporters.TestReporter, // Optionally pass in a test reporter to log further metrics + failingLogLevel zapcore.Level, // Examines logs after the test, and fails the test if any Chainlink logs are found at or above provided level + grafnaUrlProvider testreporters.GrafanaURLProvider, +) error { + l := logging.GetTestLogger(t) + if err := testreporters.WriteTeardownLogs(t, env, optionalTestReporter, failingLogLevel, grafnaUrlProvider); err != nil { + return fmt.Errorf("Error dumping environment logs, leaving environment running for manual retrieval, err: %w", err) + } + // Delete all jobs to stop depleting the funds + err := DeleteAllJobs(chainlinkNodes) + if err != nil { + l.Warn().Msgf("Error deleting jobs %+v", err) + } + + if chainlinkNodes != nil { + if err := ReturnFundsFromNodes(l, chainClient, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(chainlinkNodes)); err != nil { + // This printed line is required for tests that use real funds to propagate the failure + // out to the system running the test. Do not remove + fmt.Println(environment.FAILED_FUND_RETURN) + l.Error().Err(err).Str("Namespace", env.Cfg.Namespace). + Msg("Error attempting to return funds from chainlink nodes to network's default wallet. " + + "Environment is left running so you can try manually!") + } + } else { + l.Info().Msg("Successfully returned funds from chainlink nodes to default network wallets") + } + + return env.Shutdown() +} + // TeardownRemoteSuite sends a report and returns funds from chainlink nodes to network's default wallet func TeardownRemoteSuite( t *testing.T, @@ -425,11 +536,12 @@ func TeardownRemoteSuite( l.Warn().Msgf("Error deleting jobs %+v", err) } - if err = ReturnFunds(l, client, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(chainlinkNodes)); err != nil { + if err = ReturnFundsFromNodes(l, client, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(chainlinkNodes)); err != nil { l.Error().Err(err).Str("Namespace", namespace). Msg("Error attempting to return funds from chainlink nodes to network's default wallet. " + "Environment is left running so you can try manually!") } + return err } @@ -647,3 +759,227 @@ func WatchNewFluxRound( } } } + +// EstimateCostForChainlinkOperations estimates the cost of running a number of operations on the Chainlink node based on estimated gas costs. It supports +// both legacy and EIP-1559 transactions. +func EstimateCostForChainlinkOperations(l zerolog.Logger, client *seth.Client, network blockchain.EVMNetwork, amountOfOperations int) (*big.Float, error) { + bigAmountOfOperations := big.NewInt(int64(amountOfOperations)) + estimations := client.CalculateGasEstimations(client.NewDefaultGasEstimationRequest()) + + gasLimit := network.GasEstimationBuffer + network.ChainlinkTransactionLimit + + var gasPriceInWei *big.Int + if client.Cfg.Network.EIP1559DynamicFees { + gasPriceInWei = estimations.GasFeeCap + } else { + gasPriceInWei = estimations.GasPrice + } + + gasCostPerOperationWei := big.NewInt(1).Mul(big.NewInt(1).SetUint64(gasLimit), gasPriceInWei) + gasCostPerOperationETH := conversions.WeiToEther(gasCostPerOperationWei) + // total Wei needed for all TXs = total value for TX * number of TXs + totalWeiForAllOperations := big.NewInt(1).Mul(gasCostPerOperationWei, bigAmountOfOperations) + totalEthForAllOperations := conversions.WeiToEther(totalWeiForAllOperations) + + l.Debug(). + Int("Number of Operations", amountOfOperations). + Uint64("Gas Limit per Operation", gasLimit). + Str("Value per Operation (ETH)", gasCostPerOperationETH.String()). + Str("Total (ETH)", totalEthForAllOperations.String()). + Msg("Calculated ETH for Chainlink Operations") + + return totalEthForAllOperations, nil +} + +// GetLatestFinalizedBlockHeader returns latest finalised block header for given network (taking into account finality tag/depth) +func GetLatestFinalizedBlockHeader(ctx context.Context, client *seth.Client, network blockchain.EVMNetwork) (*types.Header, error) { + if network.FinalityTag { + return client.Client.HeaderByNumber(ctx, big.NewInt(rpc.FinalizedBlockNumber.Int64())) + } + if network.FinalityDepth == 0 { + return nil, fmt.Errorf("finality depth is 0 and finality tag is not enabled") + } + header, err := client.Client.HeaderByNumber(ctx, nil) + if err != nil { + return nil, err + } + latestBlockNumber := header.Number.Uint64() + finalizedBlockNumber := latestBlockNumber - network.FinalityDepth + return client.Client.HeaderByNumber(ctx, big.NewInt(int64(finalizedBlockNumber))) +} + +// SendLinkFundsToDeploymentAddresses deploys MultiCall contract to send LINK to Seth's ephemeral keys +func SendLinkFundsToDeploymentAddresses( + chainClient *seth.Client, + concurrency, + totalUpkeeps, + operationsPerAddress int, + multicallAddress common.Address, + linkAmountPerUpkeep *big.Int, + linkToken contracts.LinkToken, +) error { + var generateCallData = func(receiver common.Address, amount *big.Int) ([]byte, error) { + abi, err := link_token_interface.LinkTokenMetaData.GetAbi() + if err != nil { + return nil, err + } + data, err := abi.Pack("transfer", receiver, amount) + if err != nil { + return nil, err + } + return data, nil + } + + toTransferToMultiCallContract := big.NewInt(0).Mul(linkAmountPerUpkeep, big.NewInt(int64(totalUpkeeps+concurrency))) + toTransferPerClient := big.NewInt(0).Mul(linkAmountPerUpkeep, big.NewInt(int64(operationsPerAddress+1))) + err := linkToken.Transfer(multicallAddress.Hex(), toTransferToMultiCallContract) + if err != nil { + return errors.Wrapf(err, "Error transferring LINK to multicall contract") + } + + balance, err := linkToken.BalanceOf(context.Background(), multicallAddress.Hex()) + if err != nil { + return errors.Wrapf(err, "Error getting LINK balance of multicall contract") + } + + if toTransferToMultiCallContract.Cmp(balance) != 0 { + return fmt.Errorf("Incorrect LINK balance of multicall contract. Expected: %s. Got: %s", toTransferToMultiCallContract.String(), balance.String()) + } + + // Transfer LINK to ephemeral keys + multiCallData := make([][]byte, 0) + for i := 1; i <= concurrency; i++ { + data, err := generateCallData(chainClient.Addresses[i], toTransferPerClient) + if err != nil { + return errors.Wrapf(err, "Error generating call data for LINK transfer") + } + multiCallData = append(multiCallData, data) + } + + var call []contracts.Call + for _, d := range multiCallData { + data := contracts.Call{Target: common.HexToAddress(linkToken.Address()), AllowFailure: false, CallData: d} + call = append(call, data) + } + + multiCallABI, err := abi.JSON(strings.NewReader(contracts.MultiCallABI)) + if err != nil { + return errors.Wrapf(err, "Error getting Multicall contract ABI") + } + boundContract := bind.NewBoundContract(multicallAddress, multiCallABI, chainClient.Client, chainClient.Client, chainClient.Client) + // call aggregate3 to group all msg call data and send them in a single transaction + _, err = chainClient.Decode(boundContract.Transact(chainClient.NewTXOpts(), "aggregate3", call)) + if err != nil { + return errors.Wrapf(err, "Error calling Multicall contract") + } + + for i := 1; i <= concurrency; i++ { + balance, err := linkToken.BalanceOf(context.Background(), chainClient.Addresses[i].Hex()) + if err != nil { + return errors.Wrapf(err, "Error getting LINK balance of ephemeral key %d", i) + } + if balance.Cmp(toTransferPerClient) < 0 { + return fmt.Errorf("Incorrect LINK balance after transfer. Ephemeral key %d. Expected: %s. Got: %s", i, toTransferPerClient.String(), balance.String()) + } + } + + return nil +} + +var noOpSethConfigFn = func(cfg *seth.Config) error { return nil } + +type SethConfigFunction = func(*seth.Config) error + +// OneEphemeralKeysLiveTestnetCheckFn checks whether there's at least one ephemeral key on a simulated network or at least one static key on a live network, +// and that there are no epehemeral keys on a live network. Root key is excluded from the check. +var OneEphemeralKeysLiveTestnetCheckFn = func(sethCfg *seth.Config) error { + concurrency := sethCfg.GetMaxConcurrency() + + if sethCfg.IsSimulatedNetwork() { + if concurrency < 1 { + return fmt.Errorf(INSUFFICIENT_EPHEMERAL_KEYS, 0) + } + + return nil + } + + if sethCfg.EphemeralAddrs != nil && int(*sethCfg.EphemeralAddrs) > 0 { + ephMsg := ` + Error: Ephemeral Addresses Detected on Live Network + + Ephemeral addresses are currently set for use on a live network, which is not permitted. The number of ephemeral addresses set is %d. Please make the following update to your TOML configuration file to correct this: + '[Seth] ephemeral_addresses_number = 0' + + Additionally, ensure the following requirements are met to run this test on a live network: + 1. Use more than one private key in your network configuration. + ` + + return errors.New(ephMsg) + } + + if concurrency < 1 { + return fmt.Errorf(INSUFFICIENT_STATIC_KEYS, len(sethCfg.Network.PrivateKeys)) + } + + return nil +} + +// OneEphemeralKeysLiveTestnetAutoFixFn checks whether there's at least one ephemeral key on a simulated network or at least one static key on a live network, +// and that there are no epehemeral keys on a live network (if ephemeral keys count is different from zero, it will disable them). Root key is excluded from the check. +var OneEphemeralKeysLiveTestnetAutoFixFn = func(sethCfg *seth.Config) error { + concurrency := sethCfg.GetMaxConcurrency() + + if sethCfg.IsSimulatedNetwork() { + if concurrency < 1 { + return fmt.Errorf(INSUFFICIENT_EPHEMERAL_KEYS, 0) + } + + return nil + } + + if sethCfg.EphemeralAddrs != nil && int(*sethCfg.EphemeralAddrs) > 0 { + var zero int64 = 0 + sethCfg.EphemeralAddrs = &zero + } + + if concurrency < 1 { + return fmt.Errorf(INSUFFICIENT_STATIC_KEYS, len(sethCfg.Network.PrivateKeys)) + } + + return nil +} + +// GetChainClient returns a seth client for the given network after validating the config +func GetChainClient(config tc.SethConfig, network blockchain.EVMNetwork) (*seth.Client, error) { + return GetChainClientWithConfigFunction(config, network, noOpSethConfigFn) +} + +// GetChainClientWithConfigFunction returns a seth client for the given network after validating the config and applying the config function +func GetChainClientWithConfigFunction(config tc.SethConfig, network blockchain.EVMNetwork, configFn SethConfigFunction) (*seth.Client, error) { + readSethCfg := config.GetSethConfig() + if readSethCfg == nil { + return nil, fmt.Errorf("Seth config not found") + } + + sethCfg, err := utils.MergeSethAndEvmNetworkConfigs(network, *readSethCfg) + if err != nil { + return nil, errors.Wrapf(err, "Error merging seth and evm network configs") + } + + err = configFn(&sethCfg) + if err != nil { + return nil, errors.Wrapf(err, "Error applying seth config function") + } + + err = utils.ValidateSethNetworkConfig(sethCfg.Network) + if err != nil { + return nil, errors.Wrapf(err, "Error validating seth network config") + } + + chainClient, err := seth.NewClientWithConfig(&sethCfg) + if err != nil { + return nil, errors.Wrapf(err, "Error creating seth client") + } + + return chainClient, nil +} diff --git a/integration-tests/actions/seth/keeper_helpers.go b/integration-tests/actions/seth/keeper_helpers.go new file mode 100644 index 00000000000..1fb7000556e --- /dev/null +++ b/integration-tests/actions/seth/keeper_helpers.go @@ -0,0 +1,32 @@ +package actions_seth + +import ( + "github.com/ethereum/go-ethereum/common" +) + +var ZeroAddress = common.Address{} + +var INSUFFICIENT_EPHEMERAL_KEYS = ` +Error: Insufficient Ephemeral Addresses for Simulated Network + +To operate on a simulated network, you must configure at least one ephemeral address. Currently, %d ephemeral address(es) are set. Please update your TOML configuration file as follows to meet this requirement: +[Seth] ephemeral_addresses_number = 1 + +This adjustment ensures that your setup is minimaly viable. Although it is highly recommended to use at least 20 ephemeral addresses. +` + +var INSUFFICIENT_STATIC_KEYS = ` +Error: Insufficient Private Keys for Live Network + +To run this test on a live network, you must either: +1. Set at least two private keys in the '[Network.WalletKeys]' section of your TOML configuration file. Example format: + [Network.WalletKeys] + NETWORK_NAME=["PRIVATE_KEY_1", "PRIVATE_KEY_2"] +2. Set at least two private keys in the '[Network.EVMNetworks.NETWORK_NAME] section of your TOML configuration file. Example format: + evm_keys=["PRIVATE_KEY_1", "PRIVATE_KEY_2"] + +Currently, only %d private key/s is/are set. + +Recommended Action: +Distribute your funds across multiple private keys and update your configuration accordingly. Even though 1 private key is sufficient for testing, it is highly recommended to use at least 10 private keys. +` diff --git a/integration-tests/actions/seth/refund.go b/integration-tests/actions/seth/refund.go index cca4659cb6d..15927f52227 100644 --- a/integration-tests/actions/seth/refund.go +++ b/integration-tests/actions/seth/refund.go @@ -229,16 +229,16 @@ func (r *OvershotTransferRetrier) Retry(ctx context.Context, logger zerolog.Logg return txErr } -// ReturnFunds returns funds from the given chainlink nodes to the default network wallet. It will use a variety +// ReturnFundsFromNodes returns funds from the given chainlink nodes to the default network wallet. It will use a variety // of strategies to attempt to return funds, including retrying with less funds if the transaction fails due to // insufficient funds, and retrying with a higher gas limit if the transaction fails due to gas too low. -func ReturnFunds(log zerolog.Logger, sethClient *seth.Client, chainlinkNodes []contracts.ChainlinkNodeWithKeysAndAddress) error { - if sethClient == nil { +func ReturnFundsFromNodes(log zerolog.Logger, client *seth.Client, chainlinkNodes []contracts.ChainlinkNodeWithKeysAndAddress) error { + if client == nil { return fmt.Errorf("Seth client is nil, unable to return funds from chainlink nodes") } log.Info().Msg("Attempting to return Chainlink node funds to default network wallets") - if sethClient.Cfg.IsSimulatedNetwork() { - log.Info().Str("Network Name", sethClient.Cfg.Network.Name). + if client.Cfg.IsSimulatedNetwork() { + log.Info().Str("Network Name", client.Cfg.Network.Name). Msg("Network is a simulated network. Skipping fund return.") return nil } @@ -246,7 +246,7 @@ func ReturnFunds(log zerolog.Logger, sethClient *seth.Client, chainlinkNodes []c failedReturns := []common.Address{} for _, chainlinkNode := range chainlinkNodes { - fundedKeys, err := chainlinkNode.ExportEVMKeysForChain(fmt.Sprint(sethClient.ChainID)) + fundedKeys, err := chainlinkNode.ExportEVMKeysForChain(fmt.Sprint(client.ChainID)) if err != nil { return err } @@ -262,94 +262,108 @@ func ReturnFunds(log zerolog.Logger, sethClient *seth.Client, chainlinkNodes []c return err } - publicKey := decryptedKey.PrivateKey.Public() - publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) - if !ok { - return errors.New("error casting public key to ECDSA") - } - fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) - - balance, err := sethClient.Client.BalanceAt(context.Background(), fromAddress, nil) + err = sendAllFundsIfPossible(log, client, decryptedKey.PrivateKey) if err != nil { - return err + publicKey := decryptedKey.PrivateKey.Public() + publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) + if !ok { + return errors.New("error casting public key to ECDSA") + } + failedReturns = append(failedReturns, crypto.PubkeyToAddress(*publicKeyECDSA)) } + } + } - if balance.Cmp(big.NewInt(0)) == 0 { - log.Info(). - Str("Address", fromAddress.String()). - Msg("No balance to return. Skipping return.") - } + if len(failedReturns) > 0 { + return fmt.Errorf("failed to return funds from Chainlink nodes to default network wallet for addresses: %v", failedReturns) + } - // if not set, it will be just set to empty string, which is okay as long as gas estimation is disabled - txPriority := sethClient.Cfg.Network.GasPriceEstimationTxPriority - txTimeout := sethClient.Cfg.Network.TxnTimeout.Duration() + log.Info().Msg("Successfully returned funds from all Chainlink nodes to default network wallets") - if sethClient.Cfg.IsExperimentEnabled(seth.Experiment_SlowFundsReturn) { - txPriority = "slow" - thirtyMinutes := time.Duration(30 * time.Minute) - txTimeout = thirtyMinutes - } + return nil +} - estimations := sethClient.CalculateGasEstimations(seth.GasEstimationRequest{ - GasEstimationEnabled: sethClient.Cfg.Network.GasPriceEstimationEnabled, - FallbackGasPrice: sethClient.Cfg.Network.GasPrice, - FallbackGasFeeCap: sethClient.Cfg.Network.GasFeeCap, - FallbackGasTipCap: sethClient.Cfg.Network.GasTipCap, - Priority: txPriority, - }) - - var maxTotalGasCost *big.Int - if sethClient.Cfg.Network.EIP1559DynamicFees { - maxTotalGasCost = new(big.Int).Mul(big.NewInt(0).SetInt64(sethClient.Cfg.Network.TransferGasFee), estimations.GasFeeCap) - } else { - maxTotalGasCost = new(big.Int).Mul(big.NewInt(0).SetInt64(sethClient.Cfg.Network.TransferGasFee), estimations.GasPrice) - } +func sendAllFundsIfPossible(log zerolog.Logger, sethClient *seth.Client, fromPrivateKey *ecdsa.PrivateKey) error { + publicKey := fromPrivateKey.Public() + publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) + if !ok { + return errors.New("error casting public key to ECDSA") + } - toSend := new(big.Int).Sub(balance, maxTotalGasCost) + fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) + balance, err := sethClient.Client.BalanceAt(context.Background(), fromAddress, nil) + if err != nil { + return err + } - if toSend.Cmp(big.NewInt(0)) <= 0 { - log.Warn(). - Str("Address", fromAddress.String()). - Str("Estimated maximum total gas cost", maxTotalGasCost.String()). - Str("Balance", balance.String()). - Str("To send", toSend.String()). - Msg("Not enough balance to cover gas cost. Skipping return.") + if balance.Cmp(big.NewInt(0)) == 0 { + log.Info(). + Str("Address", fromAddress.String()). + Msg("No balance to return. Skipping return.") + } - failedReturns = append(failedReturns, fromAddress) - continue - } + // if not set, it will be just set to empty string, which is okay as long as gas estimation is disabled + txPriority := sethClient.Cfg.Network.GasPriceEstimationTxPriority + txTimeout := sethClient.Cfg.Network.TxnTimeout.Duration() - payload := FundsToSendPayload{ - ToAddress: sethClient.Addresses[0], - Amount: toSend, - PrivateKey: decryptedKey.PrivateKey, - GasLimit: &sethClient.Cfg.Network.TransferGasFee, - GasPrice: estimations.GasPrice, - GasFeeCap: estimations.GasFeeCap, - GasTipCap: estimations.GasTipCap, - TxTimeout: &txTimeout, - } + if sethClient.Cfg.IsExperimentEnabled(seth.Experiment_SlowFundsReturn) { + txPriority = "slow" + thirtyMinutes := time.Duration(30 * time.Minute) + txTimeout = thirtyMinutes + } - _, err = SendFunds(log, sethClient, payload) - if err != nil { - handler := OvershotTransferRetrier{maxRetries: 10, nextRetrier: &InsufficientFundTransferRetrier{maxRetries: 10, nextRetrier: &GasTooLowTransferRetrier{maxGasLimit: sethClient.Cfg.Network.TransferGasFee * 10}}} - err = handler.Retry(context.Background(), log, sethClient, err, payload, 0) - if err != nil { - log.Error(). - Err(err). - Str("Address", fromAddress.String()). - Msg("Failed to return funds from Chainlink node to default network wallet") - failedReturns = append(failedReturns, fromAddress) - } - } - } + estimations := sethClient.CalculateGasEstimations(seth.GasEstimationRequest{ + GasEstimationEnabled: sethClient.Cfg.Network.GasPriceEstimationEnabled, + FallbackGasPrice: sethClient.Cfg.Network.GasPrice, + FallbackGasFeeCap: sethClient.Cfg.Network.GasFeeCap, + FallbackGasTipCap: sethClient.Cfg.Network.GasTipCap, + Priority: txPriority, + }) + + var maxTotalGasCost *big.Int + if sethClient.Cfg.Network.EIP1559DynamicFees { + maxTotalGasCost = new(big.Int).Mul(big.NewInt(0).SetInt64(sethClient.Cfg.Network.TransferGasFee), estimations.GasFeeCap) + } else { + maxTotalGasCost = new(big.Int).Mul(big.NewInt(0).SetInt64(sethClient.Cfg.Network.TransferGasFee), estimations.GasPrice) } - if len(failedReturns) > 0 { - return fmt.Errorf("failed to return funds from Chainlink nodes to default network wallet for addresses: %v", failedReturns) + toSend := new(big.Int).Sub(balance, maxTotalGasCost) + + if toSend.Cmp(big.NewInt(0)) <= 0 { + log.Warn(). + Str("Address", fromAddress.String()). + Str("Estimated maximum total gas cost", maxTotalGasCost.String()). + Str("Balance", balance.String()). + Str("To send", toSend.String()). + Msg("Not enough balance to cover gas cost. Skipping return.") + + return nil } - log.Info().Msg("Successfully returned funds from all Chainlink nodes to default network wallets") + payload := FundsToSendPayload{ + ToAddress: sethClient.Addresses[0], + Amount: toSend, + PrivateKey: fromPrivateKey, + GasLimit: &sethClient.Cfg.Network.TransferGasFee, + GasPrice: estimations.GasPrice, + GasFeeCap: estimations.GasFeeCap, + GasTipCap: estimations.GasTipCap, + TxTimeout: &txTimeout, + } + + _, err = SendFunds(log, sethClient, payload) + if err != nil { + handler := OvershotTransferRetrier{maxRetries: 10, nextRetrier: &InsufficientFundTransferRetrier{maxRetries: 10, nextRetrier: &GasTooLowTransferRetrier{maxGasLimit: sethClient.Cfg.Network.TransferGasFee * 10}}} + err = handler.Retry(context.Background(), log, sethClient, err, payload, 0) + if err != nil { + log.Error(). + Err(err). + Str("Address", fromAddress.String()). + Msg("Failed to return funds from Chainlink node to default network wallet") + + return err + } + } return nil } diff --git a/integration-tests/actions/vrf/vrfv2/contract_steps.go b/integration-tests/actions/vrf/vrfv2/contract_steps.go index 348119c41bb..2310f164513 100644 --- a/integration-tests/actions/vrf/vrfv2/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2/contract_steps.go @@ -33,15 +33,14 @@ func DeployVRFV2Contracts( useVRFOwner bool, useTestCoordinator bool, ) (*vrfcommon.VRFContracts, error) { - bhs, err := env.ContractDeployer.DeployBlockhashStore() + sethClient, err := env.GetSethClient(chainID) if err != nil { - return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrDeployBlockHashStore, err) + return nil, err } - sethClient, err := env.GetSethClientForSelectedNetwork() - // evmClient, err := env.GetEVMClient(chainID) + bhs, err := contracts.DeployBlockhashStore(sethClient) if err != nil { - return nil, err + return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrDeployBlockHashStore, err) } var coordinatorAddress string @@ -90,10 +89,10 @@ func DeployVRFV2Contracts( }, nil } -func DeployVRFV2Consumers(contractDeployer contracts.ContractDeployer, coordinatorAddress string, consumerContractsAmount int) ([]contracts.VRFv2LoadTestConsumer, error) { +func DeployVRFV2Consumers(client *seth.Client, coordinatorAddress string, consumerContractsAmount int) ([]contracts.VRFv2LoadTestConsumer, error) { var consumers []contracts.VRFv2LoadTestConsumer for i := 1; i <= consumerContractsAmount; i++ { - loadTestConsumer, err := contractDeployer.DeployVRFv2LoadTestConsumer(coordinatorAddress) + loadTestConsumer, err := contracts.DeployVRFv2LoadTestConsumer(client, coordinatorAddress) if err != nil { return nil, fmt.Errorf("%s, err %w", ErrAdvancedConsumer, err) } @@ -697,17 +696,13 @@ func SetupNewConsumersAndSubs( numberOfSubToCreate int, l zerolog.Logger, ) ([]contracts.VRFv2LoadTestConsumer, []uint64, error) { - consumers, err := DeployVRFV2Consumers(env.ContractDeployer, coordinator.Address(), numberOfConsumerContractsToDeployAndAddToSub) - if err != nil { - return nil, nil, fmt.Errorf("err: %w", err) - } - evmClient, err := env.GetEVMClient(chainID) + sethClient, err := env.GetSethClient(chainID) if err != nil { - return nil, []uint64{}, err + return nil, nil, err } - err = evmClient.WaitForEvents() + consumers, err := DeployVRFV2Consumers(sethClient, coordinator.Address(), numberOfConsumerContractsToDeployAndAddToSub) if err != nil { - return nil, nil, fmt.Errorf("%s, err: %w", vrfcommon.ErrWaitTXsComplete, err) + return nil, nil, fmt.Errorf("err: %w", err) } l.Info(). Str("Coordinator", *testConfig.VRFv2.ExistingEnvConfig.ExistingEnvConfig.CoordinatorAddress). diff --git a/integration-tests/actions/vrf/vrfv2plus/contract_steps.go b/integration-tests/actions/vrf/vrfv2plus/contract_steps.go index bc8300f3444..78f6f739c68 100644 --- a/integration-tests/actions/vrf/vrfv2plus/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/contract_steps.go @@ -10,7 +10,6 @@ import ( "github.com/rs/zerolog" "github.com/shopspring/decimal" - "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink-testing-framework/utils/conversions" "github.com/smartcontractkit/chainlink/integration-tests/actions" vrfcommon "github.com/smartcontractkit/chainlink/integration-tests/actions/vrf/common" @@ -25,32 +24,20 @@ import ( func DeployVRFV2_5Contracts( contractDeployer contracts.ContractDeployer, - chainClient blockchain.EVMClient, + chainClient *seth.Client, ) (*vrfcommon.VRFContracts, error) { - bhs, err := contractDeployer.DeployBlockhashStore() + bhs, err := contracts.DeployBlockhashStore(chainClient) if err != nil { return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrDeployBlockHashStore, err) } - err = chainClient.WaitForEvents() - if err != nil { - return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitTXsComplete, err) - } - batchBHS, err := contractDeployer.DeployBatchBlockhashStore(bhs.Address()) + batchBHS, err := contracts.DeployBatchBlockhashStore(chainClient, bhs.Address()) if err != nil { return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrDeployBatchBlockHashStore, err) } - err = chainClient.WaitForEvents() - if err != nil { - return nil, fmt.Errorf("%s, batchBHS err %w", vrfcommon.ErrWaitTXsComplete, err) - } - coordinator, err := contractDeployer.DeployVRFCoordinatorV2_5(bhs.Address()) + coordinator, err := contracts.DeployVRFCoordinatorV2_5(chainClient, bhs.Address()) if err != nil { return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrDeployCoordinator, err) } - err = chainClient.WaitForEvents() - if err != nil { - return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitTXsComplete, err) - } return &vrfcommon.VRFContracts{ CoordinatorV2Plus: coordinator, BHS: bhs, @@ -112,7 +99,6 @@ func VRFV2PlusUpgradedVersionRegisterProvingKey( func FundVRFCoordinatorV2_5Subscription( linkToken contracts.LinkToken, coordinator contracts.VRFCoordinatorV2_5, - chainClient blockchain.EVMClient, subscriptionID *big.Int, linkFundingAmountJuels *big.Int, ) error { @@ -124,7 +110,7 @@ func FundVRFCoordinatorV2_5Subscription( if err != nil { return fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrSendingLinkToken, err) } - return chainClient.WaitForEvents() + return nil } func CreateFundSubsAndAddConsumers( @@ -297,7 +283,7 @@ func FundSubscriptions( } //Link Billing amountJuels := conversions.EtherToWei(subscriptionFundingAmountLink) - err = FundVRFCoordinatorV2_5Subscription(linkAddress, coordinator, evmClient, subID, amountJuels) + err = FundVRFCoordinatorV2_5Subscription(linkAddress, coordinator, subID, amountJuels) if err != nil { return fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrFundSubWithLinkToken, err) } @@ -536,11 +522,11 @@ func SetupVRFV2PlusContracts( l zerolog.Logger, ) (*vrfcommon.VRFContracts, error) { l.Info().Msg("Deploying VRFV2 Plus contracts") - evmClient, err := env.GetEVMClient(chainID) + sethClient, err := env.GetSethClient(chainID) if err != nil { return nil, err } - vrfContracts, err := DeployVRFV2_5Contracts(env.ContractDeployer, evmClient) + vrfContracts, err := DeployVRFV2_5Contracts(env.ContractDeployer, sethClient) if err != nil { return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, ErrDeployVRFV2_5Contracts, err) } @@ -568,10 +554,6 @@ func SetupVRFV2PlusContracts( if err != nil { return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, ErrSetLinkNativeLinkFeed, err) } - err = evmClient.WaitForEvents() - if err != nil { - return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitTXsComplete, err) - } return vrfContracts, nil } diff --git a/integration-tests/actions/vrf/vrfv2plus/logging_helpers.go b/integration-tests/actions/vrf/vrfv2plus/logging_helpers.go index 739772dbc14..b613298f1fd 100644 --- a/integration-tests/actions/vrf/vrfv2plus/logging_helpers.go +++ b/integration-tests/actions/vrf/vrfv2plus/logging_helpers.go @@ -4,7 +4,6 @@ import ( "fmt" "math/big" - "github.com/ethereum/go-ethereum/common" "github.com/rs/zerolog" "github.com/smartcontractkit/chainlink/integration-tests/contracts" @@ -16,14 +15,14 @@ import ( func LogRandRequest( l zerolog.Logger, consumer string, - coordinator *common.Address, + coordinator string, subID *big.Int, isNativeBilling bool, keyHash [32]byte, config *vrfv2plus_config.General) { l.Info(). Str("Consumer", consumer). - Str("Coordinator", coordinator.Hex()). + Str("Coordinator", coordinator). Str("SubID", subID.String()). Bool("IsNativePayment", isNativeBilling). Uint16("MinimumConfirmations", *config.MinimumConfirmations). @@ -38,14 +37,14 @@ func LogRandRequest( func LogMigrationCompletedEvent(l zerolog.Logger, migrationCompletedEvent *vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted, coordinator contracts.Coordinator) { l.Info(). Str("Subscription ID", migrationCompletedEvent.SubId.String()). - Str("Migrated From Coordinator", coordinator.Address().Hex()). + Str("Migrated From Coordinator", coordinator.Address()). Str("Migrated To Coordinator", migrationCompletedEvent.NewCoordinator.String()). Msg("MigrationCompleted Event") } func LogSubDetailsAfterMigration(l zerolog.Logger, newCoordinator contracts.Coordinator, subID *big.Int, migratedSubscription vrf_v2plus_upgraded_version.GetSubscription) { l.Info(). - Str("New Coordinator", newCoordinator.Address().Hex()). + Str("New Coordinator", newCoordinator.Address()). Str("Subscription ID", subID.String()). Str("Juels Balance", migratedSubscription.Balance.String()). Str("Native Token Balance", migratedSubscription.NativeBalance.String()). diff --git a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go index b030a9b9a40..0365aeb09c3 100644 --- a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go @@ -379,14 +379,17 @@ func SetupVRFV2PlusForNewEnv( return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "error creating test env", err) } - env.ParallelTransactions(true) + sethClient, err := env.GetSethClient(chainID) + if err != nil { + return nil, nil, nil, nil, err + } - mockETHLinkFeed, err := env.ContractDeployer.DeployVRFMockETHLINKFeed(big.NewInt(*testConfig.VRFv2Plus.General.LinkNativeFeedResponse)) + mockETHLinkFeed, err := contracts.DeployVRFMockETHLINKFeed(sethClient, big.NewInt(*testConfig.VRFv2Plus.General.LinkNativeFeedResponse)) if err != nil { return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "error deploying mock ETH/LINK feed", err) } - linkToken, err := actions.DeployLINKToken(env.ContractDeployer) + linkToken, err := contracts.DeployLinkTokenContract(l, sethClient) if err != nil { return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "error deploying LINK contract", err) } @@ -418,18 +421,19 @@ func SetupVRFV2PlusForExistingEnv(ctx context.Context, t *testing.T, testConfig if err != nil { return nil, nil, nil, fmt.Errorf("%s, err: %w", "error creating test env", err) } - coordinator, err := env.ContractLoader.LoadVRFCoordinatorV2_5(*commonExistingEnvConfig.CoordinatorAddress) + + sethClient, err := env.GetSethClient(chainID) if err != nil { - return nil, nil, nil, fmt.Errorf("%s, err: %w", "error loading VRFCoordinator2_5", err) + return nil, nil, nil, err } - linkToken, err := env.ContractLoader.LoadLINKToken(*commonExistingEnvConfig.LinkAddress) + + coordinator, err := contracts.LoadVRFCoordinatorV2_5(sethClient, *commonExistingEnvConfig.CoordinatorAddress) if err != nil { - return nil, nil, nil, fmt.Errorf("%s, err: %w", "error loading LinkToken", err) + return nil, nil, nil, fmt.Errorf("%s, err: %w", "error loading VRFCoordinator2_5", err) } - - sethClient, err := env.GetSethClient(chainID) + linkToken, err := contracts.LoadLinkTokenContract(l, sethClient, common.HexToAddress(*commonExistingEnvConfig.LinkAddress)) if err != nil { - return nil, nil, nil, err + return nil, nil, nil, fmt.Errorf("%s, err: %w", "error loading LinkToken", err) } err = vrfcommon.FundNodesIfNeeded(ctx, commonExistingEnvConfig, sethClient, l) @@ -466,6 +470,10 @@ func SetupSubsAndConsumersForExistingEnv( consumers []contracts.VRFv2PlusLoadTestConsumer err error ) + sethClient, err := env.GetSethClient(chainID) + if err != nil { + return nil, nil, err + } if *testConfig.VRFv2Plus.General.UseExistingEnv { commonExistingEnvConfig := testConfig.VRFv2Plus.ExistingEnvConfig.ExistingEnvConfig if *commonExistingEnvConfig.CreateFundSubsAndAddConsumers { @@ -483,7 +491,7 @@ func SetupSubsAndConsumersForExistingEnv( return nil, nil, fmt.Errorf("err: %w", err) } } else { - consumer, err := env.ContractLoader.LoadVRFv2PlusLoadTestConsumer(*commonExistingEnvConfig.ConsumerAddress) + consumer, err := contracts.LoadVRFv2PlusLoadTestConsumer(sethClient, *commonExistingEnvConfig.ConsumerAddress) if err != nil { return nil, nil, fmt.Errorf("err: %w", err) } diff --git a/integration-tests/chaos/ocr2vrf_chaos_test.go b/integration-tests/chaos/ocr2vrf_chaos_test.go index 4869dbcabd3..9ff697748dc 100644 --- a/integration-tests/chaos/ocr2vrf_chaos_test.go +++ b/integration-tests/chaos/ocr2vrf_chaos_test.go @@ -10,7 +10,6 @@ import ( "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" - "github.com/smartcontractkit/chainlink-testing-framework/blockchain" ctf_config "github.com/smartcontractkit/chainlink-testing-framework/config" "github.com/smartcontractkit/chainlink-testing-framework/k8s/chaos" "github.com/smartcontractkit/chainlink-testing-framework/k8s/environment" @@ -20,14 +19,16 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/networks" "github.com/smartcontractkit/chainlink-testing-framework/utils/ptr" "github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext" + actions_seth "github.com/smartcontractkit/chainlink/integration-tests/actions/seth" + "github.com/smartcontractkit/chainlink/integration-tests/contracts" "github.com/smartcontractkit/chainlink/integration-tests/actions" "github.com/smartcontractkit/chainlink/integration-tests/actions/ocr2vrf_actions" "github.com/smartcontractkit/chainlink/integration-tests/actions/ocr2vrf_actions/ocr2vrf_constants" "github.com/smartcontractkit/chainlink/integration-tests/client" "github.com/smartcontractkit/chainlink/integration-tests/config" - "github.com/smartcontractkit/chainlink/integration-tests/contracts" tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig" + "github.com/smartcontractkit/chainlink/integration-tests/utils" ) func TestOCR2VRFChaos(t *testing.T) { @@ -155,33 +156,30 @@ func TestOCR2VRFChaos(t *testing.T) { err = testEnvironment.Client.LabelChaosGroup(testEnvironment.Cfg.Namespace, "instance=node-", 3, 5, ChaosGroupMajority) require.NoError(t, err) - chainClient, err := blockchain.NewEVMClient(testNetwork, testEnvironment, l) - require.NoError(t, err, "Error connecting to blockchain") - contractDeployer, err := contracts.NewContractDeployer(chainClient, l) - require.NoError(t, err, "Error building contract deployer") + testNetwork = utils.MustReplaceSimulatedNetworkUrlWithK8(l, testNetwork, *testEnvironment) + chainClient, err := actions_seth.GetChainClientWithConfigFunction(testconfig, testNetwork, actions_seth.OneEphemeralKeysLiveTestnetCheckFn) + require.NoError(t, err, "Error creating seth client") + chainlinkNodes, err := client.ConnectChainlinkNodes(testEnvironment) require.NoError(t, err, "Error connecting to Chainlink nodes") nodeAddresses, err := actions.ChainlinkNodeAddresses(chainlinkNodes) require.NoError(t, err, "Retrieving on-chain wallet addresses for chainlink nodes shouldn't fail") t.Cleanup(func() { - err := actions.TeardownSuite(t, testEnvironment, chainlinkNodes, nil, zapcore.PanicLevel, &testconfig, chainClient) + err := actions_seth.TeardownSuite(t, chainClient, testEnvironment, chainlinkNodes, nil, zapcore.PanicLevel, &testconfig) require.NoError(t, err, "Error tearing down environment") }) - chainClient.ParallelTransactions(true) - - linkToken, err := contractDeployer.DeployLinkTokenContract() + linkToken, err := contracts.DeployLinkTokenContract(l, chainClient) require.NoError(t, err, "Error deploying LINK token") - mockETHLinkFeed, err := contractDeployer.DeployMockETHLINKFeed(ocr2vrf_constants.LinkEthFeedResponse) + mockETHLinkFeed, err := contracts.DeployMockETHLINKFeed(chainClient, ocr2vrf_constants.LinkEthFeedResponse) require.NoError(t, err, "Error deploying Mock ETH/LINK Feed") _, _, vrfBeaconContract, consumerContract, subID := ocr2vrf_actions.SetupOCR2VRFUniverse( t, linkToken, mockETHLinkFeed, - contractDeployer, chainClient, nodeAddresses, chainlinkNodes, @@ -192,7 +190,6 @@ func TestOCR2VRFChaos(t *testing.T) { requestID := ocr2vrf_actions.RequestAndRedeemRandomness( t, consumerContract, - chainClient, vrfBeaconContract, ocr2vrf_constants.NumberOfRandomWordsToRequest, subID, @@ -219,7 +216,6 @@ func TestOCR2VRFChaos(t *testing.T) { requestID = ocr2vrf_actions.RequestAndRedeemRandomness( t, consumerContract, - chainClient, vrfBeaconContract, ocr2vrf_constants.NumberOfRandomWordsToRequest, subID, diff --git a/integration-tests/contracts/contract_deployer.go b/integration-tests/contracts/contract_deployer.go index 9e7ac32b69b..9551429a4d1 100644 --- a/integration-tests/contracts/contract_deployer.go +++ b/integration-tests/contracts/contract_deployer.go @@ -78,7 +78,6 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/upkeep_counter_wrapper" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/upkeep_perform_counter_restrictive_wrapper" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/upkeep_transcoder" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_mock_ethlink_aggregator" "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" @@ -99,7 +98,6 @@ type ContractDeployer interface { LoadOffChainAggregator(address *common.Address) (OffchainAggregator, error) DeployVRFContract() (VRF, error) DeployMockETHLINKFeed(answer *big.Int) (MockETHLINKFeed, error) - DeployVRFMockETHLINKFeed(answer *big.Int) (VRFMockETHLINKFeed, error) LoadETHLINKFeed(address common.Address) (MockETHLINKFeed, error) DeployMockGasFeed(answer *big.Int) (MockGasFeed, error) LoadGasFeed(address common.Address) (MockGasFeed, error) @@ -125,20 +123,8 @@ type ContractDeployer interface { DeployKeeperPerformDataChecker(expectedData []byte) (KeeperPerformDataChecker, error) DeployUpkeepCounter(testRange *big.Int, interval *big.Int) (UpkeepCounter, error) DeployUpkeepPerformCounterRestrictive(testRange *big.Int, averageEligibilityCadence *big.Int) (UpkeepPerformCounterRestrictive, error) - DeployVRFConsumer(linkAddr string, coordinatorAddr string) (VRFConsumer, error) - DeployVRFConsumerV2(linkAddr string, coordinatorAddr string) (VRFConsumerV2, error) - DeployVRFv2Consumer(coordinatorAddr string) (VRFv2Consumer, error) - DeployVRFv2LoadTestConsumer(coordinatorAddr string) (VRFv2LoadTestConsumer, error) - DeployVRFCoordinatorV2_5(bhsAddr string) (VRFCoordinatorV2_5, error) - DeployVRFCoordinatorV2PlusUpgradedVersion(bhsAddr string) (VRFCoordinatorV2PlusUpgradedVersion, error) - DeployDKG() (DKG, error) - DeployOCR2VRFCoordinator(beaconPeriodBlocksCount *big.Int, linkAddr string) (VRFCoordinatorV3, error) - DeployVRFBeacon(vrfCoordinatorAddress string, linkAddress string, dkgAddress string, keyId string) (VRFBeacon, error) - DeployVRFBeaconConsumer(vrfCoordinatorAddress string, beaconPeriodBlockCount *big.Int) (VRFBeaconConsumer, error) - DeployBlockhashStore() (BlockHashStore, error) DeployOperatorFactory(linkAddr string) (OperatorFactory, error) DeployStaking(params eth_contracts.StakingPoolConstructorParams) (Staking, error) - DeployBatchBlockhashStore(blockhashStoreAddr string) (BatchBlockhashStore, error) DeployFunctionsLoadTestClient(router string) (FunctionsLoadTestClient, error) DeployFunctionsOracleEventsMock() (FunctionsOracleEventsMock, error) DeployFunctionsBillingRegistryEventsMock() (FunctionsBillingRegistryEventsMock, error) @@ -705,30 +691,13 @@ func (e *EthereumContractDeployer) DeployMockETHLINKFeed(answer *big.Int) (MockE if err != nil { return nil, err } - return &EthereumMockETHLINKFeed{ + return &LegacyEthereumMockETHLINKFeed{ client: e.client, feed: instance.(*mock_ethlink_aggregator_wrapper.MockETHLINKAggregator), address: address, }, err } -func (e *EthereumContractDeployer) DeployVRFMockETHLINKFeed(answer *big.Int) (VRFMockETHLINKFeed, error) { - address, _, instance, err := e.client.DeployContract("VRFMockETHLINKAggregator", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return vrf_mock_ethlink_aggregator.DeployVRFMockETHLINKAggregator(auth, backend, answer) - }) - if err != nil { - return nil, err - } - return &EthereumVRFMockETHLINKFeed{ - client: e.client, - feed: instance.(*vrf_mock_ethlink_aggregator.VRFMockETHLINKAggregator), - address: address, - }, err -} - // LoadETHLINKFeed returns deployed on given address EthereumMockETHLINKFeed func (e *EthereumContractDeployer) LoadETHLINKFeed(address common.Address) (MockETHLINKFeed, error) { instance, err := e.client.LoadContract("MockETHLINKFeed", address, func( @@ -740,7 +709,7 @@ func (e *EthereumContractDeployer) LoadETHLINKFeed(address common.Address) (Mock if err != nil { return nil, err } - return &EthereumMockETHLINKFeed{ + return &LegacyEthereumMockETHLINKFeed{ address: &address, client: e.client, feed: instance.(*mock_ethlink_aggregator_wrapper.MockETHLINKAggregator), @@ -1892,7 +1861,7 @@ func (e *EthereumContractDeployer) DeployLogEmitterContract() (LogEmitter, error if err != nil { return nil, err } - return &LogEmitterContract{ + return &LegacyLogEmitterContract{ client: e.client, instance: instance.(*le.LogEmitter), address: *address, diff --git a/integration-tests/contracts/contract_models.go b/integration-tests/contracts/contract_models.go index c61356130ee..b548ec1427a 100644 --- a/integration-tests/contracts/contract_models.go +++ b/integration-tests/contracts/contract_models.go @@ -79,6 +79,7 @@ type LinkToken interface { Transfer(to string, amount *big.Int) error BalanceOf(ctx context.Context, addr string) (*big.Int, error) TransferAndCall(to string, amount *big.Int, data []byte) (*types.Transaction, error) + TransferAndCallFromKey(to string, amount *big.Int, data []byte, keyNum int) (*types.Transaction, error) Name(context.Context) (string, error) } @@ -140,6 +141,7 @@ type ChainlinkNodeWithKeysAndAddress interface { MustReadP2PKeys() (*client.P2PKeys, error) ExportEVMKeysForChain(string) ([]*client.ExportedEVMKey, error) PrimaryEthAddress() (string, error) + EthAddresses() ([]string, error) } type ChainlinkNodeWithForwarder interface { @@ -423,6 +425,10 @@ type LogEmitter interface { EmitLogIntsIndexed(ints []int) (*types.Transaction, error) EmitLogIntMultiIndexed(ints int, ints2 int, count int) (*types.Transaction, error) EmitLogStrings(strings []string) (*types.Transaction, error) + EmitLogIntsFromKey(ints []int, keyNum int) (*types.Transaction, error) + EmitLogIntsIndexedFromKey(ints []int, keyNum int) (*types.Transaction, error) + EmitLogIntMultiIndexedFromKey(ints int, ints2 int, count int, keyNum int) (*types.Transaction, error) + EmitLogStringsFromKey(strings []string, keyNum int) (*types.Transaction, error) EmitLogInt(payload int) (*types.Transaction, error) EmitLogIntIndexed(payload int) (*types.Transaction, error) EmitLogString(strings string) (*types.Transaction, error) diff --git a/integration-tests/contracts/ethereum_contracts.go b/integration-tests/contracts/ethereum_contracts.go index e8b2f184ce9..d2b7a407a9c 100644 --- a/integration-tests/contracts/ethereum_contracts.go +++ b/integration-tests/contracts/ethereum_contracts.go @@ -1291,6 +1291,10 @@ func (l *LegacyEthereumLinkToken) TransferAndCall(to string, amount *big.Int, da return tx, l.client.ProcessTransaction(tx) } +func (l *LegacyEthereumLinkToken) TransferAndCallFromKey(_ string, _ *big.Int, _ []byte, _ int) (*types.Transaction, error) { + panic("supported only with Seth") +} + // LegacyEthereumOffchainAggregator represents the offchain aggregation contract // Deprecated: we are moving away from blockchain.EVMClient, use EthereumOffchainAggregator instead type LegacyEthereumOffchainAggregator struct { @@ -1714,18 +1718,18 @@ func (o *OffchainAggregatorV2RoundConfirmer) Complete() bool { return o.complete } -// EthereumMockETHLINKFeed represents mocked ETH/LINK feed contract -type EthereumMockETHLINKFeed struct { +// LegacyEthereumMockETHLINKFeed represents mocked ETH/LINK feed contract +type LegacyEthereumMockETHLINKFeed struct { client blockchain.EVMClient feed *mock_ethlink_aggregator_wrapper.MockETHLINKAggregator address *common.Address } -func (v *EthereumMockETHLINKFeed) Address() string { +func (v *LegacyEthereumMockETHLINKFeed) Address() string { return v.address.Hex() } -func (v *EthereumMockETHLINKFeed) LatestRoundData() (*big.Int, error) { +func (v *LegacyEthereumMockETHLINKFeed) LatestRoundData() (*big.Int, error) { data, err := v.feed.LatestRoundData(&bind.CallOpts{ From: common.HexToAddress(v.client.GetDefaultWallet().Address()), Context: context.Background(), @@ -1736,7 +1740,7 @@ func (v *EthereumMockETHLINKFeed) LatestRoundData() (*big.Int, error) { return data.Ans, nil } -func (v *EthereumMockETHLINKFeed) LatestRoundDataUpdatedAt() (*big.Int, error) { +func (v *LegacyEthereumMockETHLINKFeed) LatestRoundDataUpdatedAt() (*big.Int, error) { data, err := v.feed.LatestRoundData(&bind.CallOpts{ From: common.HexToAddress(v.client.GetDefaultWallet().Address()), Context: context.Background(), diff --git a/integration-tests/contracts/ethereum_contracts_seth.go b/integration-tests/contracts/ethereum_contracts_seth.go index 5302854b0ba..beab47b8e26 100644 --- a/integration-tests/contracts/ethereum_contracts_seth.go +++ b/integration-tests/contracts/ethereum_contracts_seth.go @@ -28,6 +28,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/authorized_forwarder" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/flux_aggregator_wrapper" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/link_token_interface" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/mock_ethlink_aggregator_wrapper" "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/generated/oracle_wrapper" @@ -688,6 +689,19 @@ func (l *EthereumLinkToken) TransferAndCall(to string, amount *big.Int, data []b return decodedTx.Transaction, nil } +func (l *EthereumLinkToken) TransferAndCallFromKey(to string, amount *big.Int, data []byte, keyNum int) (*types.Transaction, error) { + l.l.Info(). + Str("From", l.client.Addresses[keyNum].Hex()). + Str("To", to). + Str("Amount", amount.String()). + Msg("Transferring and Calling LINK") + decodedTx, err := l.client.Decode(l.instance.TransferAndCall(l.client.NewTXKeyOpts(keyNum), common.HexToAddress(to), amount, data)) + if err != nil { + return nil, err + } + return decodedTx.Transaction, nil +} + // DeployFluxAggregatorContract deploys the Flux Aggregator Contract on an EVM chain func DeployFluxAggregatorContract( seth *seth.Client, @@ -816,6 +830,81 @@ func (f *EthereumFluxAggregator) LatestRoundData(ctx context.Context) (flux_aggr }) } +// EthereumMockETHLINKFeed represents mocked ETH/LINK feed contract +type EthereumMockETHLINKFeed struct { + client *seth.Client + feed *mock_ethlink_aggregator_wrapper.MockETHLINKAggregator + address *common.Address +} + +func (v *EthereumMockETHLINKFeed) Address() string { + return v.address.Hex() +} + +func (v *EthereumMockETHLINKFeed) LatestRoundData() (*big.Int, error) { + data, err := v.feed.LatestRoundData(&bind.CallOpts{ + From: v.client.Addresses[0], + Context: context.Background(), + }) + if err != nil { + return nil, err + } + return data.Ans, nil +} + +func (v *EthereumMockETHLINKFeed) LatestRoundDataUpdatedAt() (*big.Int, error) { + data, err := v.feed.LatestRoundData(&bind.CallOpts{ + From: v.client.Addresses[0], + Context: context.Background(), + }) + if err != nil { + return nil, err + } + return data.UpdatedAt, nil +} + +func DeployMockETHLINKFeed(client *seth.Client, answer *big.Int) (MockETHLINKFeed, error) { + abi, err := mock_ethlink_aggregator_wrapper.MockETHLINKAggregatorMetaData.GetAbi() + if err != nil { + return &EthereumMockETHLINKFeed{}, fmt.Errorf("failed to get MockETHLINKFeed ABI: %w", err) + } + data, err := client.DeployContract(client.NewTXOpts(), "MockETHLINKFeed", *abi, common.FromHex(mock_ethlink_aggregator_wrapper.MockETHLINKAggregatorMetaData.Bin), answer) + if err != nil { + return &EthereumMockETHLINKFeed{}, fmt.Errorf("MockETHLINKFeed instance deployment have failed: %w", err) + } + + instance, err := mock_ethlink_aggregator_wrapper.NewMockETHLINKAggregator(data.Address, wrappers.MustNewWrappedContractBackend(nil, client)) + if err != nil { + return &EthereumMockETHLINKFeed{}, fmt.Errorf("failed to instantiate MockETHLINKFeed instance: %w", err) + } + + return &EthereumMockETHLINKFeed{ + address: &data.Address, + client: client, + feed: instance, + }, nil +} + +func LoadMockETHLINKFeed(client *seth.Client, address common.Address) (MockETHLINKFeed, error) { + abi, err := mock_ethlink_aggregator_wrapper.MockETHLINKAggregatorMetaData.GetAbi() + if err != nil { + return &EthereumMockETHLINKFeed{}, fmt.Errorf("failed to get MockETHLINKFeed ABI: %w", err) + } + client.ContractStore.AddABI("MockETHLINKFeed", *abi) + client.ContractStore.AddBIN("MockETHLINKFeed", common.FromHex(mock_ethlink_aggregator_wrapper.MockETHLINKAggregatorMetaData.Bin)) + + instance, err := mock_ethlink_aggregator_wrapper.NewMockETHLINKAggregator(address, wrappers.MustNewWrappedContractBackend(nil, client)) + if err != nil { + return &EthereumMockETHLINKFeed{}, fmt.Errorf("failed to instantiate MockETHLINKFeed instance: %w", err) + } + + return &EthereumMockETHLINKFeed{ + address: &address, + client: client, + feed: instance, + }, nil +} + // GetContractData retrieves basic data for the flux aggregator contract func (f *EthereumFluxAggregator) GetContractData(ctx context.Context) (*FluxAggregatorData, error) { opts := &bind.CallOpts{ diff --git a/integration-tests/contracts/ethereum_ocr2vrf_contracts.go b/integration-tests/contracts/ethereum_ocr2vrf_contracts.go index 8ca80380a28..9cf636bbc81 100644 --- a/integration-tests/contracts/ethereum_ocr2vrf_contracts.go +++ b/integration-tests/contracts/ethereum_ocr2vrf_contracts.go @@ -12,115 +12,157 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/rs/zerolog/log" - "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink-vrf/archive/gethwrappers/dkg" "github.com/smartcontractkit/chainlink-vrf/archive/gethwrappers/vrf_beacon" "github.com/smartcontractkit/chainlink-vrf/archive/gethwrappers/vrf_beacon_consumer" "github.com/smartcontractkit/chainlink-vrf/archive/gethwrappers/vrf_coordinator" + "github.com/smartcontractkit/chainlink/integration-tests/wrappers" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/batch_blockhash_store" + "github.com/smartcontractkit/seth" ) // EthereumDKG represents DKG contract type EthereumDKG struct { - address *common.Address - client blockchain.EVMClient + address common.Address + client *seth.Client dkg *dkg.DKG } // EthereumVRFCoordinatorV3 represents VRFCoordinatorV3 contract type EthereumVRFCoordinatorV3 struct { - address *common.Address - client blockchain.EVMClient + address common.Address + client *seth.Client vrfCoordinatorV3 *vrf_coordinator.VRFCoordinator } // EthereumVRFBeacon represents VRFBeacon contract type EthereumVRFBeacon struct { - address *common.Address - client blockchain.EVMClient + address common.Address + client *seth.Client vrfBeacon *vrf_beacon.VRFBeacon } // EthereumVRFBeaconConsumer represents VRFBeaconConsumer contract type EthereumVRFBeaconConsumer struct { - address *common.Address - client blockchain.EVMClient + address common.Address + client *seth.Client vrfBeaconConsumer *vrf_beacon_consumer.BeaconVRFConsumer } // DeployDKG deploys DKG contract -func (e *EthereumContractDeployer) DeployDKG() (DKG, error) { - address, _, instance, err := e.client.DeployContract("DKG", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return dkg.DeployDKG(auth, backend) - }) +func DeployDKG(seth *seth.Client) (DKG, error) { + abi, err := dkg.DKGMetaData.GetAbi() if err != nil { - return nil, err + return &EthereumDKG{}, fmt.Errorf("failed to get DKG ABI: %w", err) } + + data, err := seth.DeployContract( + seth.NewTXOpts(), + "DKG", + *abi, + common.FromHex(dkg.DKGMetaData.Bin)) + if err != nil { + return &EthereumDKG{}, fmt.Errorf("DKG instance deployment have failed: %w", err) + } + + contract, err := dkg.NewDKG(data.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumDKG{}, fmt.Errorf("failed to instantiate DKG instance: %w", err) + } + return &EthereumDKG{ - client: e.client, - dkg: instance.(*dkg.DKG), - address: address, + client: seth, + dkg: contract, + address: data.Address, }, err } // DeployOCR2VRFCoordinator deploys CR2VRFCoordinator contract -func (e *EthereumContractDeployer) DeployOCR2VRFCoordinator(beaconPeriodBlocksCount *big.Int, linkAddress string) (VRFCoordinatorV3, error) { - address, _, instance, err := e.client.DeployContract("VRFCoordinatorV3", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return vrf_coordinator.DeployVRFCoordinator(auth, backend, beaconPeriodBlocksCount, common.HexToAddress(linkAddress)) - }) +func DeployOCR2VRFCoordinator(seth *seth.Client, beaconPeriodBlocksCount *big.Int, linkAddress string) (VRFCoordinatorV3, error) { + abi, err := vrf_coordinator.VRFCoordinatorMetaData.GetAbi() if err != nil { - return nil, err + return &EthereumVRFCoordinatorV3{}, fmt.Errorf("failed to get VRFCoordinatorV3 ABI: %w", err) } + + data, err := seth.DeployContract( + seth.NewTXOpts(), + "VRFCoordinatorV3", + *abi, + common.FromHex(vrf_coordinator.VRFCoordinatorMetaData.Bin), + beaconPeriodBlocksCount, common.HexToAddress(linkAddress)) + if err != nil { + return &EthereumVRFCoordinatorV3{}, fmt.Errorf("VRFCoordinatorV3 instance deployment have failed: %w", err) + } + + contract, err := vrf_coordinator.NewVRFCoordinator(data.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRFCoordinatorV3{}, fmt.Errorf("failed to instantiate VRFCoordinatorV3 instance: %w", err) + } + return &EthereumVRFCoordinatorV3{ - client: e.client, - vrfCoordinatorV3: instance.(*vrf_coordinator.VRFCoordinator), - address: address, + client: seth, + vrfCoordinatorV3: contract, + address: data.Address, }, err } // DeployVRFBeacon deploys DeployVRFBeacon contract -func (e *EthereumContractDeployer) DeployVRFBeacon(vrfCoordinatorAddress string, linkAddress string, dkgAddress string, keyId string) (VRFBeacon, error) { +func DeployVRFBeacon(seth *seth.Client, vrfCoordinatorAddress string, linkAddress string, dkgAddress string, keyId string) (VRFBeacon, error) { + abi, err := vrf_beacon.VRFBeaconMetaData.GetAbi() + if err != nil { + return &EthereumVRFBeacon{}, fmt.Errorf("failed to get VRFBeacon ABI: %w", err) + } keyIDBytes, err := DecodeHexTo32ByteArray(keyId) if err != nil { return nil, err } - address, _, instance, err := e.client.DeployContract("VRFBeacon", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return vrf_beacon.DeployVRFBeacon(auth, backend, common.HexToAddress(linkAddress), common.HexToAddress(vrfCoordinatorAddress), common.HexToAddress(dkgAddress), keyIDBytes) - }) + data, err := seth.DeployContract( + seth.NewTXOpts(), + "VRFBeacon", + *abi, + common.FromHex(vrf_beacon.VRFBeaconMetaData.Bin), + common.HexToAddress(linkAddress), common.HexToAddress(vrfCoordinatorAddress), common.HexToAddress(dkgAddress), keyIDBytes) if err != nil { - return nil, err + return &EthereumVRFBeacon{}, fmt.Errorf("VRFBeacon instance deployment have failed: %w", err) + } + + contract, err := vrf_beacon.NewVRFBeacon(data.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRFBeacon{}, fmt.Errorf("failed to instantiate VRFBeacon instance: %w", err) } + return &EthereumVRFBeacon{ - client: e.client, - vrfBeacon: instance.(*vrf_beacon.VRFBeacon), - address: address, + client: seth, + vrfBeacon: contract, + address: data.Address, }, err } // DeployBatchBlockhashStore deploys DeployBatchBlockhashStore contract -func (e *EthereumContractDeployer) DeployBatchBlockhashStore(blockhashStoreAddr string) (BatchBlockhashStore, error) { - address, _, instance, err := e.client.DeployContract("BatchBlockhashStore", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return batch_blockhash_store.DeployBatchBlockhashStore(auth, backend, common.HexToAddress(blockhashStoreAddr)) - }) +func DeployBatchBlockhashStore(seth *seth.Client, blockhashStoreAddr string) (BatchBlockhashStore, error) { + abi, err := batch_blockhash_store.BatchBlockhashStoreMetaData.GetAbi() if err != nil { - return nil, err + return &EthereumBatchBlockhashStore{}, fmt.Errorf("failed to get BatchBlockhashStore ABI: %w", err) + } + data, err := seth.DeployContract( + seth.NewTXOpts(), + "BatchBlockhashStore", + *abi, + common.FromHex(batch_blockhash_store.BatchBlockhashStoreMetaData.Bin), + common.HexToAddress(blockhashStoreAddr)) + if err != nil { + return &EthereumBatchBlockhashStore{}, fmt.Errorf("BatchBlockhashStore instance deployment have failed: %w", err) + } + + contract, err := batch_blockhash_store.NewBatchBlockhashStore(data.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumBatchBlockhashStore{}, fmt.Errorf("failed to instantiate BatchBlockhashStore instance: %w", err) } - return &LegacyEthereumBatchBlockhashStore{ - client: e.client, - batchBlockhashStore: instance.(*batch_blockhash_store.BatchBlockhashStore), - address: address, + + return &EthereumBatchBlockhashStore{ + client: seth, + batchBlockhashStore: contract, + address: data.Address, }, err } @@ -139,20 +181,30 @@ func DecodeHexTo32ByteArray(val string) ([32]byte, error) { } // DeployVRFBeaconConsumer deploys VRFv@ consumer contract -func (e *EthereumContractDeployer) DeployVRFBeaconConsumer(vrfCoordinatorAddress string, beaconPeriodBlockCount *big.Int) (VRFBeaconConsumer, error) { - address, _, instance, err := e.client.DeployContract("VRFBeaconConsumer", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return vrf_beacon_consumer.DeployBeaconVRFConsumer(auth, backend, common.HexToAddress(vrfCoordinatorAddress), false, beaconPeriodBlockCount) - }) +func DeployVRFBeaconConsumer(seth *seth.Client, vrfCoordinatorAddress string, beaconPeriodBlockCount *big.Int) (VRFBeaconConsumer, error) { + abi, err := vrf_beacon_consumer.BeaconVRFConsumerMetaData.GetAbi() if err != nil { - return nil, err + return &EthereumVRFBeaconConsumer{}, fmt.Errorf("failed to get VRFBeaconConsumer ABI: %w", err) + } + data, err := seth.DeployContract( + seth.NewTXOpts(), + "VRFBeaconConsumer", + *abi, + common.FromHex(vrf_beacon_consumer.BeaconVRFConsumerMetaData.Bin), + common.HexToAddress(vrfCoordinatorAddress), false, beaconPeriodBlockCount) + if err != nil { + return &EthereumVRFBeaconConsumer{}, fmt.Errorf("VRFBeaconConsumer instance deployment have failed: %w", err) } + + contract, err := vrf_beacon_consumer.NewBeaconVRFConsumer(data.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRFBeaconConsumer{}, fmt.Errorf("failed to instantiate VRFBeaconConsumer instance: %w", err) + } + return &EthereumVRFBeaconConsumer{ - client: e.client, - vrfBeaconConsumer: instance.(*vrf_beacon_consumer.BeaconVRFConsumer), - address: address, + client: seth, + vrfBeaconConsumer: contract, + address: data.Address, }, err } @@ -165,20 +217,12 @@ func (dkgContract *EthereumDKG) AddClient(keyID string, clientAddress string) er if err != nil { return err } - opts, err := dkgContract.client.TransactionOpts(dkgContract.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := dkgContract.dkg.AddClient( - opts, + _, err = dkgContract.client.Decode(dkgContract.dkg.AddClient( + dkgContract.client.NewTXOpts(), keyIDBytes, common.HexToAddress(clientAddress), - ) - if err != nil { - return err - } - return dkgContract.client.ProcessTransaction(tx) - + )) + return err } func (dkgContract *EthereumDKG) SetConfig( @@ -189,23 +233,16 @@ func (dkgContract *EthereumDKG) SetConfig( offchainConfigVersion uint64, offchainConfig []byte, ) error { - opts, err := dkgContract.client.TransactionOpts(dkgContract.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := dkgContract.dkg.SetConfig( - opts, + _, err := dkgContract.client.Decode(dkgContract.dkg.SetConfig( + dkgContract.client.NewTXOpts(), signerAddresses, transmitterAddresses, f, onchainConfig, offchainConfigVersion, offchainConfig, - ) - if err != nil { - return err - } - return dkgContract.client.ProcessTransaction(tx) + )) + return err } func (dkgContract *EthereumDKG) WaitForTransmittedEvent(timeout time.Duration) (*dkg.DKGTransmitted, error) { @@ -253,42 +290,28 @@ func (coordinator *EthereumVRFCoordinatorV3) Address() string { } func (coordinator *EthereumVRFCoordinatorV3) SetProducer(producerAddress string) error { - opts, err := coordinator.client.TransactionOpts(coordinator.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := coordinator.vrfCoordinatorV3.SetProducer( - opts, + _, err := coordinator.client.Decode(coordinator.vrfCoordinatorV3.SetProducer( + coordinator.client.NewTXOpts(), common.HexToAddress(producerAddress), - ) - if err != nil { - return err - } - return coordinator.client.ProcessTransaction(tx) + )) + return err } func (coordinator *EthereumVRFCoordinatorV3) CreateSubscription() error { - opts, err := coordinator.client.TransactionOpts(coordinator.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := coordinator.vrfCoordinatorV3.CreateSubscription( - opts, - ) - if err != nil { - return err - } - return coordinator.client.ProcessTransaction(tx) + _, err := coordinator.client.Decode(coordinator.vrfCoordinatorV3.CreateSubscription( + coordinator.client.NewTXOpts(), + )) + return err } func (coordinator *EthereumVRFCoordinatorV3) FindSubscriptionID() (*big.Int, error) { fopts := &bind.FilterOpts{} - owner := coordinator.client.GetDefaultWallet().Address() + owner := coordinator.client.Addresses[0] subscriptionIterator, err := coordinator.vrfCoordinatorV3.FilterSubscriptionCreated( fopts, nil, - []common.Address{common.HexToAddress(owner)}, + []common.Address{owner}, ) if err != nil { return nil, err @@ -302,37 +325,23 @@ func (coordinator *EthereumVRFCoordinatorV3) FindSubscriptionID() (*big.Int, err } func (coordinator *EthereumVRFCoordinatorV3) AddConsumer(subId *big.Int, consumerAddress string) error { - opts, err := coordinator.client.TransactionOpts(coordinator.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := coordinator.vrfCoordinatorV3.AddConsumer( - opts, + _, err := coordinator.client.Decode(coordinator.vrfCoordinatorV3.AddConsumer( + coordinator.client.NewTXOpts(), subId, common.HexToAddress(consumerAddress), - ) - if err != nil { - return err - } - return coordinator.client.ProcessTransaction(tx) + )) + return err } func (coordinator *EthereumVRFCoordinatorV3) SetConfig(maxCallbackGasLimit uint32, maxCallbackArgumentsLength uint32) error { - opts, err := coordinator.client.TransactionOpts(coordinator.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := coordinator.vrfCoordinatorV3.SetCallbackConfig( - opts, + _, err := coordinator.client.Decode(coordinator.vrfCoordinatorV3.SetCallbackConfig( + coordinator.client.NewTXOpts(), vrf_coordinator.VRFCoordinatorCallbackConfig{ MaxCallbackGasLimit: maxCallbackGasLimit, MaxCallbackArgumentsLength: maxCallbackArgumentsLength, // 5 EVM words }, - ) - if err != nil { - return err - } - return coordinator.client.ProcessTransaction(tx) + )) + return err } func (beacon *EthereumVRFBeacon) Address() string { @@ -340,20 +349,12 @@ func (beacon *EthereumVRFBeacon) Address() string { } func (beacon *EthereumVRFBeacon) SetPayees(transmitterAddresses []common.Address, payeesAddresses []common.Address) error { - opts, err := beacon.client.TransactionOpts(beacon.client.GetDefaultWallet()) - if err != nil { - return err - } - - tx, err := beacon.vrfBeacon.SetPayees( - opts, + _, err := beacon.client.Decode(beacon.vrfBeacon.SetPayees( + beacon.client.NewTXOpts(), transmitterAddresses, payeesAddresses, - ) - if err != nil { - return err - } - return beacon.client.ProcessTransaction(tx) + )) + return err } func (beacon *EthereumVRFBeacon) SetConfig( @@ -364,23 +365,16 @@ func (beacon *EthereumVRFBeacon) SetConfig( offchainConfigVersion uint64, offchainConfig []byte, ) error { - opts, err := beacon.client.TransactionOpts(beacon.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := beacon.vrfBeacon.SetConfig( - opts, + _, err := beacon.client.Decode(beacon.vrfBeacon.SetConfig( + beacon.client.NewTXOpts(), signerAddresses, transmitterAddresses, f, onchainConfig, offchainConfigVersion, offchainConfig, - ) - if err != nil { - return err - } - return beacon.client.ProcessTransaction(tx) + )) + return err } func (beacon *EthereumVRFBeacon) WaitForConfigSetEvent(timeout time.Duration) (*vrf_beacon.VRFBeaconConfigSet, error) { @@ -426,7 +420,7 @@ func (beacon *EthereumVRFBeacon) WaitForNewTransmissionEvent(timeout time.Durati func (beacon *EthereumVRFBeacon) LatestConfigDigestAndEpoch(ctx context.Context) (vrf_beacon.LatestConfigDigestAndEpoch, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(beacon.client.GetDefaultWallet().Address()), + From: beacon.client.Addresses[0], Context: ctx, } return beacon.vrfBeacon.LatestConfigDigestAndEpoch(opts) @@ -440,58 +434,37 @@ func (consumer *EthereumVRFBeaconConsumer) RequestRandomness( numWords uint16, subID, confirmationDelayArg *big.Int, ) (*types.Receipt, error) { - opts, err := consumer.client.TransactionOpts(consumer.client.GetDefaultWallet()) - if err != nil { - return nil, fmt.Errorf("TransactionOpts failed, err: %w", err) - } - tx, err := consumer.vrfBeaconConsumer.TestRequestRandomness( - opts, + tx, err := consumer.client.Decode(consumer.vrfBeaconConsumer.TestRequestRandomness( + consumer.client.NewTXOpts(), numWords, subID, confirmationDelayArg, - ) + )) if err != nil { return nil, fmt.Errorf("TestRequestRandomness failed, err: %w", err) } - err = consumer.client.ProcessTransaction(tx) - if err != nil { - return nil, fmt.Errorf("ProcessTransaction failed, err: %w", err) - } - err = consumer.client.WaitForEvents() - - if err != nil { - return nil, fmt.Errorf("WaitForEvents failed, err: %w", err) - } - receipt, err := consumer.client.GetTxReceipt(tx.Hash()) - if err != nil { - return nil, fmt.Errorf("GetTxReceipt failed, err: %w", err) - } log.Info().Interface("Sub ID", subID). Interface("Number of Words", numWords). Interface("Number of Confirmations", confirmationDelayArg). Msg("RequestRandomness called") - return receipt, nil + return tx.Receipt, nil } func (consumer *EthereumVRFBeaconConsumer) RedeemRandomness( subID, requestID *big.Int, ) error { - opts, err := consumer.client.TransactionOpts(consumer.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := consumer.vrfBeaconConsumer.TestRedeemRandomness( - opts, + _, err := consumer.client.Decode(consumer.vrfBeaconConsumer.TestRedeemRandomness( + consumer.client.NewTXOpts(), subID, requestID, - ) + )) if err != nil { return err } log.Info().Interface("Sub ID", subID). Interface("Request ID", requestID). Msg("RedeemRandomness called") - return consumer.client.ProcessTransaction(tx) + return nil } func (consumer *EthereumVRFBeaconConsumer) RequestRandomnessFulfillment( @@ -501,48 +474,32 @@ func (consumer *EthereumVRFBeaconConsumer) RequestRandomnessFulfillment( callbackGasLimit uint32, arguments []byte, ) (*types.Receipt, error) { - opts, err := consumer.client.TransactionOpts(consumer.client.GetDefaultWallet()) - if err != nil { - return nil, err - } + opts := consumer.client.NewTXOpts() // overriding gas limit because gas estimated by TestRequestRandomnessFulfillment // is incorrect opts.GasLimit = uint64(requestGasLimit) - tx, err := consumer.vrfBeaconConsumer.TestRequestRandomnessFulfillment( + tx, err := consumer.client.Decode(consumer.vrfBeaconConsumer.TestRequestRandomnessFulfillment( opts, subID, numWords, confirmationDelayArg, callbackGasLimit, arguments, - ) + )) if err != nil { return nil, fmt.Errorf("TestRequestRandomnessFulfillment failed, err: %w", err) } - err = consumer.client.ProcessTransaction(tx) - if err != nil { - return nil, fmt.Errorf("ProcessTransaction failed, err: %w", err) - } - err = consumer.client.WaitForEvents() - - if err != nil { - return nil, fmt.Errorf("WaitForEvents failed, err: %w", err) - } - receipt, err := consumer.client.GetTxReceipt(tx.Hash()) - if err != nil { - return nil, fmt.Errorf("GetTxReceipt failed, err: %w", err) - } log.Info().Interface("Sub ID", subID). Interface("Number of Words", numWords). Interface("Number of Confirmations", confirmationDelayArg). Interface("Callback Gas Limit", callbackGasLimit). Msg("RequestRandomnessFulfillment called") - return receipt, nil + return tx.Receipt, nil } func (consumer *EthereumVRFBeaconConsumer) IBeaconPeriodBlocks(ctx context.Context) (*big.Int, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(consumer.client.GetDefaultWallet().Address()), + From: consumer.client.Addresses[0], Context: ctx, } return consumer.vrfBeaconConsumer.IBeaconPeriodBlocks(opts) @@ -550,7 +507,7 @@ func (consumer *EthereumVRFBeaconConsumer) IBeaconPeriodBlocks(ctx context.Conte func (consumer *EthereumVRFBeaconConsumer) GetRequestIdsBy(ctx context.Context, nextBeaconOutputHeight *big.Int, confDelay *big.Int) (*big.Int, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(consumer.client.GetDefaultWallet().Address()), + From: consumer.client.Addresses[0], Context: ctx, } return consumer.vrfBeaconConsumer.SRequestsIDs(opts, nextBeaconOutputHeight, confDelay) @@ -558,7 +515,7 @@ func (consumer *EthereumVRFBeaconConsumer) GetRequestIdsBy(ctx context.Context, func (consumer *EthereumVRFBeaconConsumer) GetRandomnessByRequestId(ctx context.Context, requestID *big.Int, numWordIndex *big.Int) (*big.Int, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(consumer.client.GetDefaultWallet().Address()), + From: consumer.client.Addresses[0], Context: ctx, } return consumer.vrfBeaconConsumer.SReceivedRandomnessByRequestID(opts, requestID, numWordIndex) diff --git a/integration-tests/contracts/ethereum_vrf_contracts.go b/integration-tests/contracts/ethereum_vrf_contracts.go index c2f12e29446..8aeb247455c 100644 --- a/integration-tests/contracts/ethereum_vrf_contracts.go +++ b/integration-tests/contracts/ethereum_vrf_contracts.go @@ -17,14 +17,14 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/batch_blockhash_store" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/blockhash_store" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_consumer_interface" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_coordinator_interface" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_wrapper" + "github.com/smartcontractkit/seth" ) -// LegacyEthereumBatchBlockhashStore represents BatchBlockhashStore contract -type LegacyEthereumBatchBlockhashStore struct { - address *common.Address - client blockchain.EVMClient +// EthereumBatchBlockhashStore represents BatchBlockhashStore contract +type EthereumBatchBlockhashStore struct { + address common.Address + client *seth.Client batchBlockhashStore *batch_blockhash_store.BatchBlockhashStore } @@ -95,24 +95,6 @@ func (e *EthereumContractDeployer) DeployBlockhashStore() (BlockHashStore, error }, err } -// DeployVRFCoordinator deploys VRF coordinator contract -func (e *EthereumContractDeployer) DeployVRFCoordinator(linkAddr string, bhsAddr string) (VRFCoordinator, error) { - address, _, instance, err := e.client.DeployContract("VRFCoordinator", func( - auth *bind.TransactOpts, - backend bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return solidity_vrf_coordinator_interface.DeployVRFCoordinator(auth, wrappers.MustNewWrappedContractBackend(e.client, nil), common.HexToAddress(linkAddr), common.HexToAddress(bhsAddr)) - }) - if err != nil { - return nil, err - } - return &LegacyEthereumVRFCoordinator{ - client: e.client, - coordinator: instance.(*solidity_vrf_coordinator_interface.VRFCoordinator), - address: address, - }, err -} - // DeployVRFConsumer deploys VRF consumer contract func (e *EthereumContractDeployer) DeployVRFConsumer(linkAddr string, coordinatorAddr string) (VRFConsumer, error) { address, _, instance, err := e.client.DeployContract("VRFConsumer", func( @@ -147,41 +129,6 @@ func (v *LegacyEthereumBlockhashStore) GetBlockHash(ctx context.Context, blockNu return blockHash, nil } -func (v *LegacyEthereumVRFCoordinator) Address() string { - return v.address.Hex() -} - -// HashOfKey get a hash of proving key to use it as a request ID part for VRF -func (v *LegacyEthereumVRFCoordinator) HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error) { - opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), - Context: ctx, - } - hash, err := v.coordinator.HashOfKey(opts, pubKey) - if err != nil { - return [32]byte{}, err - } - return hash, nil -} - -// RegisterProvingKey register VRF proving key -func (v *LegacyEthereumVRFCoordinator) RegisterProvingKey( - fee *big.Int, - oracleAddr string, - publicProvingKey [2]*big.Int, - jobID [32]byte, -) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.coordinator.RegisterProvingKey(opts, fee, common.HexToAddress(oracleAddr), publicProvingKey, jobID) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) -} - func (v *LegacyEthereumVRFConsumer) Address() string { return v.address.Hex() } @@ -309,6 +256,6 @@ func (v *LegacyEthereumVRF) ProofLength(ctxt context.Context) (*big.Int, error) return v.vrf.PROOFLENGTH(opts) } -func (v *LegacyEthereumBatchBlockhashStore) Address() string { +func (v *EthereumBatchBlockhashStore) Address() string { return v.address.Hex() } diff --git a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go index 6c9a4952299..7755a21cc55 100644 --- a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go @@ -646,14 +646,14 @@ func (v *EthereumVRFv2PlusLoadTestConsumer) GetLoadTestMetrics(ctx context.Conte }, nil } -func DeployVRFCoordinatorV2PlusUpgradedVersion(seth *seth.Client, bhsAddr string) (VRFCoordinatorV2PlusUpgradedVersion, error) { +func DeployVRFCoordinatorV2PlusUpgradedVersion(client *seth.Client, bhsAddr string) (VRFCoordinatorV2PlusUpgradedVersion, error) { abi, err := vrf_v2plus_upgraded_version.VRFCoordinatorV2PlusUpgradedVersionMetaData.GetAbi() if err != nil { return &EthereumVRFCoordinatorV2PlusUpgradedVersion{}, fmt.Errorf("failed to get VRFCoordinatorV2PlusUpgradedVersion ABI: %w", err) } - coordinatorDeploymentData, err := seth.DeployContract( - seth.NewTXOpts(), + data, err := client.DeployContract( + client.NewTXOpts(), "VRFCoordinatorV2PlusUpgradedVersion", *abi, common.FromHex(vrf_v2plus_upgraded_version.VRFCoordinatorV2PlusUpgradedVersionMetaData.Bin), @@ -662,15 +662,15 @@ func DeployVRFCoordinatorV2PlusUpgradedVersion(seth *seth.Client, bhsAddr string return &EthereumVRFCoordinatorV2PlusUpgradedVersion{}, fmt.Errorf("VRFCoordinatorV2PlusUpgradedVersion instance deployment have failed: %w", err) } - contract, err := vrf_v2plus_upgraded_version.NewVRFCoordinatorV2PlusUpgradedVersion(coordinatorDeploymentData.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + contract, err := vrf_v2plus_upgraded_version.NewVRFCoordinatorV2PlusUpgradedVersion(data.Address, wrappers.MustNewWrappedContractBackend(nil, client)) if err != nil { return &EthereumVRFCoordinatorV2PlusUpgradedVersion{}, fmt.Errorf("failed to instantiate VRFCoordinatorV2PlusUpgradedVersion instance: %w", err) } return &EthereumVRFCoordinatorV2PlusUpgradedVersion{ - client: seth, + client: client, coordinator: contract, - address: coordinatorDeploymentData.Address, + address: data.Address, }, err } diff --git a/integration-tests/contracts/test_contracts.go b/integration-tests/contracts/test_contracts.go index 8a6d0b5be02..25b87bcc5ba 100644 --- a/integration-tests/contracts/test_contracts.go +++ b/integration-tests/contracts/test_contracts.go @@ -12,18 +12,18 @@ import ( le "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/log_emitter" ) -type LogEmitterContract struct { +type LegacyLogEmitterContract struct { address common.Address client blockchain.EVMClient instance *le.LogEmitter l zerolog.Logger } -func (e *LogEmitterContract) Address() common.Address { +func (e *LegacyLogEmitterContract) Address() common.Address { return e.address } -func (e *LogEmitterContract) EmitLogInts(ints []int) (*types.Transaction, error) { +func (e *LegacyLogEmitterContract) EmitLogInts(ints []int) (*types.Transaction, error) { opts, err := e.client.TransactionOpts(e.client.GetDefaultWallet()) if err != nil { return nil, err @@ -39,7 +39,7 @@ func (e *LogEmitterContract) EmitLogInts(ints []int) (*types.Transaction, error) return tx, e.client.ProcessTransaction(tx) } -func (e *LogEmitterContract) EmitLogIntsIndexed(ints []int) (*types.Transaction, error) { +func (e *LegacyLogEmitterContract) EmitLogIntsIndexed(ints []int) (*types.Transaction, error) { opts, err := e.client.TransactionOpts(e.client.GetDefaultWallet()) if err != nil { return nil, err @@ -55,7 +55,7 @@ func (e *LogEmitterContract) EmitLogIntsIndexed(ints []int) (*types.Transaction, return tx, e.client.ProcessTransaction(tx) } -func (e *LogEmitterContract) EmitLogIntMultiIndexed(ints int, ints2 int, count int) (*types.Transaction, error) { +func (e *LegacyLogEmitterContract) EmitLogIntMultiIndexed(ints int, ints2 int, count int) (*types.Transaction, error) { opts, err := e.client.TransactionOpts(e.client.GetDefaultWallet()) if err != nil { return nil, err @@ -67,7 +67,7 @@ func (e *LogEmitterContract) EmitLogIntMultiIndexed(ints int, ints2 int, count i return tx, e.client.ProcessTransaction(tx) } -func (e *LogEmitterContract) EmitLogStrings(strings []string) (*types.Transaction, error) { +func (e *LegacyLogEmitterContract) EmitLogStrings(strings []string) (*types.Transaction, error) { opts, err := e.client.TransactionOpts(e.client.GetDefaultWallet()) if err != nil { return nil, err @@ -79,14 +79,27 @@ func (e *LogEmitterContract) EmitLogStrings(strings []string) (*types.Transactio return tx, e.client.ProcessTransaction(tx) } -func (e *LogEmitterContract) EmitLogInt(payload int) (*types.Transaction, error) { +func (e *LegacyLogEmitterContract) EmitLogInt(payload int) (*types.Transaction, error) { return e.EmitLogInts([]int{payload}) } -func (e *LogEmitterContract) EmitLogIntIndexed(payload int) (*types.Transaction, error) { +func (e *LegacyLogEmitterContract) EmitLogIntIndexed(payload int) (*types.Transaction, error) { return e.EmitLogIntsIndexed([]int{payload}) } -func (e *LogEmitterContract) EmitLogString(strings string) (*types.Transaction, error) { +func (e *LegacyLogEmitterContract) EmitLogString(strings string) (*types.Transaction, error) { return e.EmitLogStrings([]string{strings}) } + +func (e *LegacyLogEmitterContract) EmitLogIntsFromKey(_ []int, _ int) (*types.Transaction, error) { + panic("only Seth-based contracts support this method") +} +func (e *LegacyLogEmitterContract) EmitLogIntsIndexedFromKey(_ []int, _ int) (*types.Transaction, error) { + panic("only Seth-based contracts support this method") +} +func (e *LegacyLogEmitterContract) EmitLogIntMultiIndexedFromKey(_ int, _ int, _ int, _ int) (*types.Transaction, error) { + panic("only Seth-based contracts support this method") +} +func (e *LegacyLogEmitterContract) EmitLogStringsFromKey(_ []string, _ int) (*types.Transaction, error) { + panic("only Seth-based contracts support this method") +} diff --git a/integration-tests/docker/test_env/test_env.go b/integration-tests/docker/test_env/test_env.go index 08943b87501..f7e5188e696 100644 --- a/integration-tests/docker/test_env/test_env.go +++ b/integration-tests/docker/test_env/test_env.go @@ -299,7 +299,7 @@ func (te *CLClusterTestEnv) returnFunds() error { } for _, sethClient := range te.sethClients { - if err := actions_seth.ReturnFunds(te.l, sethClient, contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(te.ClCluster.NodeAPIs())); err != nil { + if err := actions_seth.ReturnFundsFromNodes(te.l, sethClient, contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(te.ClCluster.NodeAPIs())); err != nil { te.l.Error().Err(err).Msg("Error returning funds from node") } } diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 4f166385c69..b6b6b04a299 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -30,7 +30,7 @@ require ( github.com/smartcontractkit/chainlink-vrf v0.0.0-20240222010609-cd67d123c772 github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000 github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c - github.com/smartcontractkit/seth v0.1.6 + github.com/smartcontractkit/seth v0.1.6-0.20240424154541-db45307043b2 github.com/smartcontractkit/wasp v0.4.5 github.com/spf13/cobra v1.8.0 github.com/stretchr/testify v1.9.0 diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 65b67170dea..248abf2b517 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -1539,8 +1539,8 @@ github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJ github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0= github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c h1:lIyMbTaF2H0Q71vkwZHX/Ew4KF2BxiKhqEXwF8rn+KI= github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c/go.mod h1:fb1ZDVXACvu4frX3APHZaEBp0xi1DIm34DcA0CwTsZM= -github.com/smartcontractkit/seth v0.1.6 h1:exU96KiKM/gxvp7OR8KkOXnTgbtFNepdhMBvyobFKCw= -github.com/smartcontractkit/seth v0.1.6/go.mod h1:2TMOZQ8WTAw7rR1YBbXpnad6VmT/+xDd/nXLmB7Eero= +github.com/smartcontractkit/seth v0.1.6-0.20240424154541-db45307043b2 h1:pOLrnNRYpOfPQPPn/8B0Z12TIsyu8q3dwZXspWzzzTY= +github.com/smartcontractkit/seth v0.1.6-0.20240424154541-db45307043b2/go.mod h1:2TMOZQ8WTAw7rR1YBbXpnad6VmT/+xDd/nXLmB7Eero= github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 h1:yiKnypAqP8l0OX0P3klzZ7SCcBUxy5KqTAKZmQOvSQE= github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1/go.mod h1:q6f4fe39oZPdsh1i57WznEZgxd8siidMaSFq3wdPmVg= github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1 h1:Dai1bn+Q5cpeGMQwRdjOdVjG8mmFFROVkSKuUgBErRQ= diff --git a/integration-tests/smoke/ocr2vrf_test.go b/integration-tests/smoke/ocr2vrf_test.go index 3f9a7e3649a..642ad106e64 100644 --- a/integration-tests/smoke/ocr2vrf_test.go +++ b/integration-tests/smoke/ocr2vrf_test.go @@ -21,11 +21,13 @@ import ( "github.com/smartcontractkit/chainlink/integration-tests/actions" "github.com/smartcontractkit/chainlink/integration-tests/actions/ocr2vrf_actions" "github.com/smartcontractkit/chainlink/integration-tests/actions/ocr2vrf_actions/ocr2vrf_constants" + actions_seth "github.com/smartcontractkit/chainlink/integration-tests/actions/seth" "github.com/smartcontractkit/chainlink/integration-tests/client" "github.com/smartcontractkit/chainlink/integration-tests/config" "github.com/smartcontractkit/chainlink/integration-tests/contracts" "github.com/smartcontractkit/chainlink/integration-tests/testconfig" tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig" + "github.com/smartcontractkit/chainlink/integration-tests/utils" ) var ocr2vrfSmokeConfig *testconfig.TestConfig @@ -44,33 +46,30 @@ func TestOCR2VRFRedeemModel(t *testing.T) { return } - chainClient, err := blockchain.NewEVMClient(testNetwork, testEnvironment, l) - require.NoError(t, err, "Error connecting to blockchain") - contractDeployer, err := contracts.NewContractDeployer(chainClient, l) - require.NoError(t, err, "Error building contract deployer") + testNetwork = utils.MustReplaceSimulatedNetworkUrlWithK8(l, testNetwork, *testEnvironment) + chainClient, err := actions_seth.GetChainClientWithConfigFunction(config, testNetwork, actions_seth.OneEphemeralKeysLiveTestnetCheckFn) + require.NoError(t, err, "Error creating seth client") + chainlinkNodes, err := client.ConnectChainlinkNodes(testEnvironment) require.NoError(t, err, "Error connecting to Chainlink nodes") nodeAddresses, err := actions.ChainlinkNodeAddresses(chainlinkNodes) require.NoError(t, err, "Retreiving on-chain wallet addresses for chainlink nodes shouldn't fail") t.Cleanup(func() { - err := actions.TeardownSuite(t, testEnvironment, chainlinkNodes, nil, zapcore.ErrorLevel, &config, chainClient) + err := actions_seth.TeardownSuite(t, chainClient, testEnvironment, chainlinkNodes, nil, zapcore.ErrorLevel, &config) require.NoError(t, err, "Error tearing down environment") }) - chainClient.ParallelTransactions(true) - - linkToken, err := contractDeployer.DeployLinkTokenContract() + linkToken, err := contracts.DeployLinkTokenContract(l, chainClient) require.NoError(t, err, "Error deploying LINK token") - mockETHLinkFeed, err := contractDeployer.DeployMockETHLINKFeed(ocr2vrf_constants.LinkEthFeedResponse) + mockETHLinkFeed, err := contracts.DeployMockETHLINKFeed(chainClient, ocr2vrf_constants.LinkEthFeedResponse) require.NoError(t, err, "Error deploying Mock ETH/LINK Feed") _, _, vrfBeaconContract, consumerContract, subID := ocr2vrf_actions.SetupOCR2VRFUniverse( t, linkToken, mockETHLinkFeed, - contractDeployer, chainClient, nodeAddresses, chainlinkNodes, @@ -81,7 +80,6 @@ func TestOCR2VRFRedeemModel(t *testing.T) { requestID := ocr2vrf_actions.RequestAndRedeemRandomness( t, consumerContract, - chainClient, vrfBeaconContract, ocr2vrf_constants.NumberOfRandomWordsToRequest, subID, @@ -111,33 +109,30 @@ func TestOCR2VRFFulfillmentModel(t *testing.T) { return } - chainClient, err := blockchain.NewEVMClient(testNetwork, testEnvironment, l) - require.NoError(t, err, "Error connecting to blockchain") - contractDeployer, err := contracts.NewContractDeployer(chainClient, l) - require.NoError(t, err, "Error building contract deployer") + testNetwork = utils.MustReplaceSimulatedNetworkUrlWithK8(l, testNetwork, *testEnvironment) + chainClient, err := actions_seth.GetChainClientWithConfigFunction(config, testNetwork, actions_seth.OneEphemeralKeysLiveTestnetCheckFn) + require.NoError(t, err, "Error creating seth client") + chainlinkNodes, err := client.ConnectChainlinkNodes(testEnvironment) require.NoError(t, err, "Error connecting to Chainlink nodes") nodeAddresses, err := actions.ChainlinkNodeAddresses(chainlinkNodes) require.NoError(t, err, "Retreiving on-chain wallet addresses for chainlink nodes shouldn't fail") t.Cleanup(func() { - err := actions.TeardownSuite(t, testEnvironment, chainlinkNodes, nil, zapcore.ErrorLevel, &config, chainClient) + err := actions_seth.TeardownSuite(t, chainClient, testEnvironment, chainlinkNodes, nil, zapcore.ErrorLevel, &config) require.NoError(t, err, "Error tearing down environment") }) - chainClient.ParallelTransactions(true) - - linkToken, err := contractDeployer.DeployLinkTokenContract() + linkToken, err := contracts.DeployLinkTokenContract(l, chainClient) require.NoError(t, err, "Error deploying LINK token") - mockETHLinkFeed, err := contractDeployer.DeployMockETHLINKFeed(ocr2vrf_constants.LinkEthFeedResponse) + mockETHLinkFeed, err := contracts.DeployMockETHLINKFeed(chainClient, ocr2vrf_constants.LinkEthFeedResponse) require.NoError(t, err, "Error deploying Mock ETH/LINK Feed") _, _, vrfBeaconContract, consumerContract, subID := ocr2vrf_actions.SetupOCR2VRFUniverse( t, linkToken, mockETHLinkFeed, - contractDeployer, chainClient, nodeAddresses, chainlinkNodes, @@ -147,7 +142,6 @@ func TestOCR2VRFFulfillmentModel(t *testing.T) { requestID := ocr2vrf_actions.RequestRandomnessFulfillmentAndWaitForFulfilment( t, consumerContract, - chainClient, vrfBeaconContract, ocr2vrf_constants.NumberOfRandomWordsToRequest, subID, diff --git a/integration-tests/smoke/vrfv2plus_test.go b/integration-tests/smoke/vrfv2plus_test.go index 36fc9d5268d..64685399227 100644 --- a/integration-tests/smoke/vrfv2plus_test.go +++ b/integration-tests/smoke/vrfv2plus_test.go @@ -812,12 +812,13 @@ func TestVRFv2PlusMigration(t *testing.T) { vrfv2PlusConfig := config.VRFv2Plus chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") + cleanupFn := func() { - evmClient, err := env.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - if evmClient.NetworkSimulated() { + if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). - Str("Network Name", evmClient.GetNetworkName()). + Str("Network Name", sethClient.Cfg.Network.Name). Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { @@ -841,10 +842,6 @@ func TestVRFv2PlusMigration(t *testing.T) { env, vrfContracts, vrfKey, nodeTypeToNodeMap, err = vrfv2plus.SetupVRFV2PlusUniverse(testcontext.Get(t), t, config, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "error setting up VRFV2Plus universe") - evmClient, err := env.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - defaultWalletAddress = evmClient.GetDefaultWallet().Address() - // Migrate subscription from old coordinator to new coordinator, verify if balances // are moved correctly and requests can be made successfully in the subscription in // new coordinator @@ -877,12 +874,9 @@ func TestVRFv2PlusMigration(t *testing.T) { require.NoError(t, err, "error getting subscription information") //Migration Process - newCoordinator, err := env.ContractDeployer.DeployVRFCoordinatorV2PlusUpgradedVersion(vrfContracts.BHS.Address()) + newCoordinator, err := contracts.DeployVRFCoordinatorV2PlusUpgradedVersion(sethClient, vrfContracts.BHS.Address()) require.NoError(t, err, "error deploying VRF CoordinatorV2PlusUpgradedVersion") - err = evmClient.WaitForEvents() - require.NoError(t, err, vrfcommon.ErrWaitTXsComplete) - _, err = vrfv2plus.VRFV2PlusUpgradedVersionRegisterProvingKey(vrfKey.VRFKey, newCoordinator, uint64(assets.GWei(*configCopy.VRFv2Plus.General.CLNodeMaxGasPriceGWei).Int64())) require.NoError(t, err, fmt.Errorf("%s, err: %w", vrfcommon.ErrRegisteringProvingKey, err)) @@ -901,8 +895,6 @@ func TestVRFv2PlusMigration(t *testing.T) { err = newCoordinator.SetLINKAndLINKNativeFeed(vrfContracts.LinkToken.Address(), vrfContracts.MockETHLINKFeed.Address()) require.NoError(t, err, vrfv2plus.ErrSetLinkNativeLinkFeed) - err = evmClient.WaitForEvents() - require.NoError(t, err, vrfcommon.ErrWaitTXsComplete) vrfJobSpecConfig := vrfcommon.VRFJobSpecConfig{ ForwardingAllowed: *configCopy.VRFv2Plus.General.VRFJobForwardingAllowed, @@ -927,25 +919,17 @@ func TestVRFv2PlusMigration(t *testing.T) { err = vrfContracts.CoordinatorV2Plus.RegisterMigratableCoordinator(newCoordinator.Address()) require.NoError(t, err, "error registering migratable coordinator") - err = evmClient.WaitForEvents() - require.NoError(t, err, vrfcommon.ErrWaitTXsComplete) - oldCoordinatorLinkTotalBalanceBeforeMigration, oldCoordinatorEthTotalBalanceBeforeMigration, err := vrfv2plus.GetCoordinatorTotalBalance(vrfContracts.CoordinatorV2Plus) require.NoError(t, err) migratedCoordinatorLinkTotalBalanceBeforeMigration, migratedCoordinatorEthTotalBalanceBeforeMigration, err := vrfv2plus.GetUpgradedCoordinatorTotalBalance(newCoordinator) require.NoError(t, err) - err = evmClient.WaitForEvents() - require.NoError(t, err, vrfcommon.ErrWaitTXsComplete) - err = vrfContracts.CoordinatorV2Plus.Migrate(subID, newCoordinator.Address()) require.NoError(t, err, "error migrating sub id ", subID.String(), " from ", vrfContracts.CoordinatorV2Plus.Address(), " to new Coordinator address ", newCoordinator.Address()) migrationCompletedEvent, err := vrfContracts.CoordinatorV2Plus.WaitForMigrationCompletedEvent(time.Minute * 1) require.NoError(t, err, "error waiting for MigrationCompleted event") - err = evmClient.WaitForEvents() - require.NoError(t, err, vrfcommon.ErrWaitTXsComplete) vrfv2plus.LogMigrationCompletedEvent(l, migrationCompletedEvent, vrfContracts.CoordinatorV2Plus) @@ -1061,12 +1045,9 @@ func TestVRFv2PlusMigration(t *testing.T) { require.NoError(t, err, "error getting subscription information") //Migration Process - newCoordinator, err := env.ContractDeployer.DeployVRFCoordinatorV2PlusUpgradedVersion(vrfContracts.BHS.Address()) + newCoordinator, err := contracts.DeployVRFCoordinatorV2PlusUpgradedVersion(sethClient, vrfContracts.BHS.Address()) require.NoError(t, err, "error deploying VRF CoordinatorV2PlusUpgradedVersion") - err = evmClient.WaitForEvents() - require.NoError(t, err, vrfcommon.ErrWaitTXsComplete) - _, err = vrfv2plus.VRFV2PlusUpgradedVersionRegisterProvingKey(vrfKey.VRFKey, newCoordinator, uint64(assets.GWei(*configCopy.VRFv2Plus.General.CLNodeMaxGasPriceGWei).Int64())) require.NoError(t, err, fmt.Errorf("%s, err: %w", vrfcommon.ErrRegisteringProvingKey, err)) @@ -1085,8 +1066,6 @@ func TestVRFv2PlusMigration(t *testing.T) { err = newCoordinator.SetLINKAndLINKNativeFeed(vrfContracts.LinkToken.Address(), vrfContracts.MockETHLINKFeed.Address()) require.NoError(t, err, vrfv2plus.ErrSetLinkNativeLinkFeed) - err = evmClient.WaitForEvents() - require.NoError(t, err, vrfcommon.ErrWaitTXsComplete) vrfJobSpecConfig := vrfcommon.VRFJobSpecConfig{ ForwardingAllowed: *configCopy.VRFv2Plus.General.VRFJobForwardingAllowed, @@ -1111,26 +1090,18 @@ func TestVRFv2PlusMigration(t *testing.T) { err = vrfContracts.CoordinatorV2Plus.RegisterMigratableCoordinator(newCoordinator.Address()) require.NoError(t, err, "error registering migratable coordinator") - err = evmClient.WaitForEvents() - require.NoError(t, err, vrfcommon.ErrWaitTXsComplete) - oldCoordinatorLinkTotalBalanceBeforeMigration, oldCoordinatorEthTotalBalanceBeforeMigration, err := vrfv2plus.GetCoordinatorTotalBalance(vrfContracts.CoordinatorV2Plus) require.NoError(t, err) migratedCoordinatorLinkTotalBalanceBeforeMigration, migratedCoordinatorEthTotalBalanceBeforeMigration, err := vrfv2plus.GetUpgradedCoordinatorTotalBalance(newCoordinator) require.NoError(t, err) - err = evmClient.WaitForEvents() - require.NoError(t, err, vrfcommon.ErrWaitTXsComplete) - // Migrate wrapper's sub using coordinator's migrate method err = vrfContracts.CoordinatorV2Plus.Migrate(subID, newCoordinator.Address()) require.NoError(t, err, "error migrating sub id ", subID.String(), " from ", vrfContracts.CoordinatorV2Plus.Address(), " to new Coordinator address ", newCoordinator.Address()) migrationCompletedEvent, err := vrfContracts.CoordinatorV2Plus.WaitForMigrationCompletedEvent(time.Minute * 1) require.NoError(t, err, "error waiting for MigrationCompleted event") - err = evmClient.WaitForEvents() - require.NoError(t, err, vrfcommon.ErrWaitTXsComplete) vrfv2plus.LogMigrationCompletedEvent(l, migrationCompletedEvent, vrfContracts.CoordinatorV2Plus) From 5fb6f53443308b5dfd665c6a6514f91016d3b7e7 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Thu, 25 Apr 2024 12:10:01 +0200 Subject: [PATCH 09/43] fix --- integration-tests/contracts/ethereum_vrf_contracts_seth.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/contracts/ethereum_vrf_contracts_seth.go b/integration-tests/contracts/ethereum_vrf_contracts_seth.go index bdc7ee7154c..86d95c4d219 100644 --- a/integration-tests/contracts/ethereum_vrf_contracts_seth.go +++ b/integration-tests/contracts/ethereum_vrf_contracts_seth.go @@ -244,7 +244,7 @@ func DeployVRFMockETHLINKFeed(seth *seth.Client, answer *big.Int) (VRFMockETHLIN seth.NewTXOpts(), "VRFMockETHLINKAggregator", *abi, - common.FromHex(solidity_vrf_consumer_interface.VRFConsumerMetaData.Bin), + common.FromHex(vrf_mock_ethlink_aggregator.VRFMockETHLINKAggregatorMetaData.Bin), answer, ) if err != nil { From 756fe829c56abd0c17c6b585d012661905e31824 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Thu, 25 Apr 2024 12:36:13 +0200 Subject: [PATCH 10/43] wip 9 --- integration-tests/actions/actions.go | 13 +--- .../actions/vrf/vrfv2/contract_steps.go | 78 +------------------ .../actions/vrf/vrfv2/setup_steps.go | 9 --- .../contracts/contract_vrf_models.go | 8 +- .../contracts/ethereum_vrfv2_contracts.go | 16 ++-- integration-tests/load/vrfv2/vrfv2_test.go | 33 +++----- integration-tests/smoke/vrfv2_test.go | 72 +++++------------ integration-tests/smoke/vrfv2plus_test.go | 50 ++++-------- 8 files changed, 66 insertions(+), 213 deletions(-) diff --git a/integration-tests/actions/actions.go b/integration-tests/actions/actions.go index a0cb01ec19f..48b40d11944 100644 --- a/integration-tests/actions/actions.go +++ b/integration-tests/actions/actions.go @@ -33,6 +33,7 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext" "github.com/smartcontractkit/chainlink/integration-tests/client" "github.com/smartcontractkit/chainlink/integration-tests/contracts" + "github.com/smartcontractkit/seth" ) // ContractDeploymentInterval After how many contract actions to wait before starting any more @@ -475,14 +476,6 @@ func GetTxFromAddress(tx *types.Transaction) (string, error) { return from.String(), err } -// todo - move to CTF -func GetTxByHash(ctx context.Context, client blockchain.EVMClient, hash common.Hash) (*types.Transaction, bool, error) { - return client.(*blockchain.EthereumMultinodeClient). - DefaultClient.(*blockchain.EthereumClient). - Client. - TransactionByHash(ctx, hash) -} - // todo - move to CTF func DecodeTxInputData(abiString string, data []byte) (map[string]interface{}, error) { jsonABI, err := abi.JSON(strings.NewReader(abiString)) @@ -505,7 +498,7 @@ func DecodeTxInputData(abiString string, data []byte) (map[string]interface{}, e // todo - move to EVMClient func WaitForBlockNumberToBe( waitForBlockNumberToBe uint64, - client blockchain.EVMClient, + client *seth.Client, wg *sync.WaitGroup, timeout time.Duration, t testing.TB, @@ -527,7 +520,7 @@ func WaitForBlockNumberToBe( waitForBlockNumberToBe, blockNumber) case <-ticker.C: go func() { - currentBlockNumber, err := client.LatestBlockNumber(testcontext.Get(t)) + currentBlockNumber, err := client.Client.BlockNumber(testcontext.Get(t)) if err != nil { errorChannel <- err } diff --git a/integration-tests/actions/vrf/vrfv2/contract_steps.go b/integration-tests/actions/vrf/vrfv2/contract_steps.go index 2310f164513..c9c9d242977 100644 --- a/integration-tests/actions/vrf/vrfv2/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2/contract_steps.go @@ -10,7 +10,6 @@ import ( "github.com/rs/zerolog" "github.com/shopspring/decimal" - "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink-testing-framework/utils/conversions" "github.com/smartcontractkit/chainlink/integration-tests/actions" vrfcommon "github.com/smartcontractkit/chainlink/integration-tests/actions/vrf/common" @@ -196,16 +195,6 @@ func SetupVRFV2Contracts( if err != nil { return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrSetVRFCoordinatorConfig, err) } - - evmClient, err := env.GetEVMClient(chainID) - if err != nil { - return nil, err - } - - err = evmClient.WaitForEvents() - if err != nil { - return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) - } return vrfContracts, nil } @@ -219,15 +208,6 @@ func setupVRFOwnerContract(env *test_env.CLClusterTestEnv, chainID int64, contra if err != nil { return nil } - evmClient, err := env.GetEVMClient(chainID) - if err != nil { - return err - } - - err = evmClient.WaitForEvents() - if err != nil { - return nil - } l.Info(). Str("VRFOwner", contracts.VRFOwner.Address()). Msg("Accepting VRF Ownership") @@ -235,10 +215,6 @@ func setupVRFOwnerContract(env *test_env.CLClusterTestEnv, chainID int64, contra if err != nil { return nil } - err = evmClient.WaitForEvents() - if err != nil { - return nil - } l.Info(). Strs("Authorized Senders", allNativeTokenKeyAddressStrings). Str("VRFOwner", contracts.VRFOwner.Address()). @@ -247,10 +223,6 @@ func setupVRFOwnerContract(env *test_env.CLClusterTestEnv, chainID int64, contra if err != nil { return nil } - err = evmClient.WaitForEvents() - if err != nil { - return fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) - } return err } @@ -281,16 +253,6 @@ func CreateFundSubsAndAddConsumers( if err != nil { return nil, err } - - evmClient, err := env.GetEVMClient(chainID) - if err != nil { - return nil, err - } - - err = evmClient.WaitForEvents() - if err != nil { - return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) - } return subIDs, nil } @@ -306,15 +268,6 @@ func CreateSubsAndFund( if err != nil { return nil, err } - evmClient, err := env.GetEVMClient(chainID) - if err != nil { - return nil, err - } - - err = evmClient.WaitForEvents() - if err != nil { - return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) - } err = FundSubscriptions(env, chainID, subscriptionFundingAmountLink, linkToken, coordinator, subs) if err != nil { return nil, err @@ -356,25 +309,10 @@ func AddConsumersToSubs( } func CreateSubAndFindSubID(env *test_env.CLClusterTestEnv, chainID int64, coordinator contracts.VRFCoordinatorV2) (uint64, error) { - tx, err := coordinator.CreateSubscription() + receipt, err := coordinator.CreateSubscription() if err != nil { return 0, fmt.Errorf("%s, err %w", vrfcommon.ErrCreateVRFSubscription, err) } - evmClient, err := env.GetEVMClient(chainID) - if err != nil { - return 0, err - } - - err = evmClient.WaitForEvents() - if err != nil { - return 0, fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) - } - - receipt, err := evmClient.GetTxReceipt(tx.Hash()) - if err != nil { - return 0, fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) - } - //SubscriptionsCreated Log should be emitted with the subscription ID subID := receipt.Logs[0].Topics[1].Big().Uint64() @@ -389,30 +327,20 @@ func FundSubscriptions( coordinator contracts.VRFCoordinatorV2, subIDs []uint64, ) error { - evmClient, err := env.GetEVMClient(chainID) - if err != nil { - return err - } - for _, subID := range subIDs { //Link Billing amountJuels := conversions.EtherToWei(subscriptionFundingAmountLink) - err := FundVRFCoordinatorV2Subscription(linkAddress, coordinator, evmClient, subID, amountJuels) + err := FundVRFCoordinatorV2Subscription(linkAddress, coordinator, subID, amountJuels) if err != nil { return fmt.Errorf("%s, err %w", vrfcommon.ErrFundSubWithLinkToken, err) } } - err = evmClient.WaitForEvents() - if err != nil { - return fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) - } return nil } func FundVRFCoordinatorV2Subscription( linkToken contracts.LinkToken, coordinator contracts.VRFCoordinatorV2, - chainClient blockchain.EVMClient, subscriptionID uint64, linkFundingAmountJuels *big.Int, ) error { @@ -424,7 +352,7 @@ func FundVRFCoordinatorV2Subscription( if err != nil { return fmt.Errorf("%s, err %w", vrfcommon.ErrSendingLinkToken, err) } - return chainClient.WaitForEvents() + return nil } func DirectFundingRequestRandomnessAndWaitForFulfillment( diff --git a/integration-tests/actions/vrf/vrfv2/setup_steps.go b/integration-tests/actions/vrf/vrfv2/setup_steps.go index dd3391979ac..aee2d313eb5 100644 --- a/integration-tests/actions/vrf/vrfv2/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2/setup_steps.go @@ -124,11 +124,6 @@ func SetupVRFV2Environment( return nil, nil, nil, fmt.Errorf("%s, err %w", vrfcommon.ErrCreatingProvingKeyHash, err) } - evmClient, err := env.GetEVMClient(chainID) - if err != nil { - return nil, nil, nil, err - } - sethClient, err := env.GetSethClient(chainID) if err != nil { return nil, nil, nil, err @@ -145,10 +140,6 @@ func SetupVRFV2Environment( if err != nil { return nil, nil, nil, err } - err = evmClient.WaitForEvents() - if err != nil { - return nil, nil, nil, fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) - } nodeTypeToNodeMap[vrfcommon.VRF].TXKeyAddressStrings = vrfTXKeyAddressStrings diff --git a/integration-tests/contracts/contract_vrf_models.go b/integration-tests/contracts/contract_vrf_models.go index aaccbad0602..314c587d5e5 100644 --- a/integration-tests/contracts/contract_vrf_models.go +++ b/integration-tests/contracts/contract_vrf_models.go @@ -57,17 +57,17 @@ type VRFCoordinatorV2 interface { ) error TransferOwnership(to common.Address) error HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error) - CreateSubscription() (*types.Transaction, error) + CreateSubscription() (*types.Receipt, error) AddConsumer(subId uint64, consumerAddress string) error Address() string GetSubscription(ctx context.Context, subID uint64) (Subscription, error) GetOwner(ctx context.Context) (common.Address, error) PendingRequestsExist(ctx context.Context, subID uint64) (bool, error) - OwnerCancelSubscription(subID uint64) (*types.Transaction, error) + OwnerCancelSubscription(subID uint64) (*types.Receipt, error) ParseSubscriptionCanceled(log types.Log) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) ParseRandomWordsRequested(log types.Log) (*CoordinatorRandomWordsRequested, error) ParseLog(log types.Log) (generated.AbigenLog, error) - CancelSubscription(subID uint64, to common.Address) (*types.Transaction, error) + CancelSubscription(subID uint64, to common.Address) (*types.Receipt, error) FindSubscriptionID(subID uint64) (uint64, error) WaitForRandomWordsFulfilledEvent(filter RandomWordsFulfilledEventFilter) (*CoordinatorRandomWordsFulfilled, error) WaitForRandomWordsRequestedEvent(keyHash [][32]byte, subID []uint64, sender []common.Address, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2RandomWordsRequested, error) @@ -193,7 +193,7 @@ type VRFOwner interface { SetAuthorizedSenders(senders []common.Address) error AcceptVRFOwnership() error WaitForRandomWordsForcedEvent(requestIDs []*big.Int, subIds []uint64, senders []common.Address, timeout time.Duration) (*vrf_owner.VRFOwnerRandomWordsForced, error) - OwnerCancelSubscription(subID uint64) (*types.Transaction, error) + OwnerCancelSubscription(subID uint64) (*types.Receipt, error) } type VRFConsumer interface { diff --git a/integration-tests/contracts/ethereum_vrfv2_contracts.go b/integration-tests/contracts/ethereum_vrfv2_contracts.go index cf5c19ae431..54da02e196c 100644 --- a/integration-tests/contracts/ethereum_vrfv2_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2_contracts.go @@ -454,9 +454,9 @@ func (v *EthereumVRFCoordinatorV2) TransferOwnership(to common.Address) error { return err } -func (v *EthereumVRFCoordinatorV2) CreateSubscription() (*types.Transaction, error) { +func (v *EthereumVRFCoordinatorV2) CreateSubscription() (*types.Receipt, error) { tx, err := v.client.Decode(v.coordinator.CreateSubscription(v.client.NewTXOpts())) - return tx.Transaction, err + return tx.Receipt, err } func (v *EthereumVRFCoordinatorV2) AddConsumer(subId uint64, consumerAddress string) error { @@ -489,12 +489,12 @@ func (v *EthereumVRFCoordinatorV2) OracleWithdraw(recipient common.Address, amou // return funds to the subscription owner, // down not check if pending requests for a sub exist, // outstanding requests may fail onchain -func (v *EthereumVRFCoordinatorV2) OwnerCancelSubscription(subID uint64) (*types.Transaction, error) { +func (v *EthereumVRFCoordinatorV2) OwnerCancelSubscription(subID uint64) (*types.Receipt, error) { tx, err := v.client.Decode(v.coordinator.OwnerCancelSubscription( v.client.NewTXOpts(), subID, )) - return tx.Transaction, err + return tx.Receipt, err } func (v *EthereumVRFCoordinatorV2) ParseSubscriptionCanceled(log types.Log) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) { @@ -528,13 +528,13 @@ func (v *EthereumVRFCoordinatorV2) ParseLog(log types.Log) (generated.AbigenLog, // CancelSubscription cancels subscription by Sub owner, // return funds to specified address, // checks if pending requests for a sub exist -func (v *EthereumVRFCoordinatorV2) CancelSubscription(subID uint64, to common.Address) (*types.Transaction, error) { +func (v *EthereumVRFCoordinatorV2) CancelSubscription(subID uint64, to common.Address) (*types.Receipt, error) { tx, err := v.client.Decode(v.coordinator.CancelSubscription( v.client.NewTXOpts(), subID, to, )) - return tx.Transaction, err + return tx.Receipt, err } func (v *EthereumVRFCoordinatorV2) FindSubscriptionID(subID uint64) (uint64, error) { @@ -1149,12 +1149,12 @@ func (v *EthereumVRFOwner) WaitForRandomWordsForcedEvent(requestIDs []*big.Int, } } -func (v *EthereumVRFOwner) OwnerCancelSubscription(subID uint64) (*types.Transaction, error) { +func (v *EthereumVRFOwner) OwnerCancelSubscription(subID uint64) (*types.Receipt, error) { tx, err := v.client.Decode(v.vrfOwner.OwnerCancelSubscription( v.client.NewTXOpts(), subID, )) - return tx.Transaction, err + return tx.Receipt, err } func (v *EthereumVRFMockETHLINKFeed) Address() string { diff --git a/integration-tests/load/vrfv2/vrfv2_test.go b/integration-tests/load/vrfv2/vrfv2_test.go index e420d66ec8c..5558b7af025 100644 --- a/integration-tests/load/vrfv2/vrfv2_test.go +++ b/integration-tests/load/vrfv2/vrfv2_test.go @@ -60,6 +60,9 @@ func TestVRFV2Performance(t *testing.T) { chainID := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0].ChainID updatedLabels := UpdateLabels(labels, t) + sethClient, err := testEnv.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") + l.Info(). Str("Test Type", testType). Str("Test Duration", vrfv2Config.Performance.TestDuration.Duration.Truncate(time.Second).String()). @@ -72,12 +75,9 @@ func TestVRFV2Performance(t *testing.T) { cleanupFn := func() { teardown(t, vrfContracts.VRFV2Consumers[0], lc, updatedLabels, testReporter, testType, &testConfig) - evmClient, err := testEnv.GetEVMClient(chainID) - require.NoError(t, err, "error getting EVM client") - - if evmClient.NetworkSimulated() { + if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). - Str("Network Name", evmClient.GetNetworkName()). + Str("Network Name", sethClient.Cfg.Network.Name). Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") } else { if *vrfv2Config.General.CancelSubsAfterTestRun { @@ -102,9 +102,6 @@ func TestVRFV2Performance(t *testing.T) { testEnv, vrfContracts, vrfKey, _, err = vrfv2.SetupVRFV2Universe(testcontext.Get(t), t, testConfig, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "error setting up VRFV2 universe") - evmClient, err := testEnv.GetEVMClient(chainID) - require.NoError(t, err, "error getting EVM client") - var consumers []contracts.VRFv2LoadTestConsumer subIDs, consumers, err := vrfv2.SetupSubsAndConsumersForExistingEnv( testEnv, @@ -126,7 +123,6 @@ func TestVRFV2Performance(t *testing.T) { l.Debug().Int("Number of Subs", len(subIDs)).Msg("Subs involved in the test") vrfContracts.VRFV2Consumers = consumers - defaultWalletAddress = evmClient.GetDefaultWallet().Address() // is our "job" stable at all, no memory leaks, no flaking performance under some RPS? t.Run("vrfv2 performance test", func(t *testing.T) { @@ -212,16 +208,15 @@ func TestVRFV2BHSPerformance(t *testing.T) { Msg("Performance Test Configuration") chainID := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0].ChainID + sethClient, err := testEnv.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") cleanupFn := func() { teardown(t, vrfContracts.VRFV2Consumers[0], lc, updatedLabels, testReporter, testType, &testConfig) - evmClient, err := testEnv.GetEVMClient(chainID) - require.NoError(t, err, "error getting EVM client") - - if evmClient.NetworkSimulated() { + if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). - Str("Network Name", evmClient.GetNetworkName()). + Str("Network Name", sethClient.Cfg.Network.Name). Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") } else { if *vrfv2Config.General.CancelSubsAfterTestRun { @@ -246,10 +241,6 @@ func TestVRFV2BHSPerformance(t *testing.T) { testEnv, vrfContracts, vrfKey, _, err = vrfv2.SetupVRFV2Universe(testcontext.Get(t), t, testConfig, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "error setting up VRFV2 universe") - evmClient, err := testEnv.GetEVMClient(chainID) - require.NoError(t, err, "error getting EVM client") - - defaultWalletAddress = evmClient.GetDefaultWallet().Address() t.Run("vrfv2 and bhs performance test", func(t *testing.T) { configCopy := testConfig.MustCopy().(tc.TestConfig) //Underfund Subscription @@ -307,9 +298,9 @@ func TestVRFV2BHSPerformance(t *testing.T) { var wgBlockNumberTobe sync.WaitGroup wgBlockNumberTobe.Add(1) //Wait at least 256 blocks - latestBlockNumber, err := evmClient.LatestBlockNumber(testcontext.Get(t)) - require.NoError(t, err, "error getting latest block number") - _, err = actions.WaitForBlockNumberToBe(latestBlockNumber+uint64(256), evmClient, &wgBlockNumberTobe, configCopy.VRFv2.General.WaitFor256BlocksTimeout.Duration, t) + latestBlockNumber, err := sethClient.Client.BlockNumber(testcontext.Get(t)) + require.NoError(t, err) + _, err = actions.WaitForBlockNumberToBe(latestBlockNumber+uint64(256), sethClient, &wgBlockNumberTobe, configCopy.VRFv2.General.WaitFor256BlocksTimeout.Duration, t) wgBlockNumberTobe.Wait() require.NoError(t, err, "error waiting for block number to be") diff --git a/integration-tests/smoke/vrfv2_test.go b/integration-tests/smoke/vrfv2_test.go index f9608ad603b..3c319250d20 100644 --- a/integration-tests/smoke/vrfv2_test.go +++ b/integration-tests/smoke/vrfv2_test.go @@ -77,10 +77,6 @@ func TestVRFv2Basic(t *testing.T) { testEnv, vrfContracts, vrfKey, nodeTypeToNodeMap, err = vrfv2.SetupVRFV2Universe(testcontext.Get(t), t, config, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "Error setting up VRFV2 universe") - evmClient, err := testEnv.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - - defaultWalletAddress = evmClient.GetDefaultWallet().Address() t.Run("Request Randomness", func(t *testing.T) { configCopy := config.MustCopy().(tc.TestConfig) @@ -309,9 +305,6 @@ func TestVRFv2Basic(t *testing.T) { err = vrfContracts.CoordinatorV2.OracleWithdraw(common.HexToAddress(defaultWalletAddress), amountToWithdrawLink) require.NoError(t, err, "Error withdrawing LINK from coordinator to default wallet") - err = evmClient.WaitForEvents() - require.NoError(t, err, vrfcommon.ErrWaitTXsComplete) - defaultWalletBalanceLinkAfterOracleWithdraw, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), defaultWalletAddress) require.NoError(t, err) @@ -359,13 +352,11 @@ func TestVRFv2Basic(t *testing.T) { Str("Returning funds to", testWalletAddress.String()). Msg("Canceling subscription and returning funds to subscription owner") - tx, err := vrfContracts.CoordinatorV2.CancelSubscription(subIDForCancelling, testWalletAddress) + cancellationTxReceipt, err := vrfContracts.CoordinatorV2.CancelSubscription(subIDForCancelling, testWalletAddress) require.NoError(t, err, "Error canceling subscription") subscriptionCanceledEvent, err := vrfContracts.CoordinatorV2.WaitForSubscriptionCanceledEvent([]uint64{subIDForCancelling}, time.Second*30) require.NoError(t, err, "error waiting for subscription canceled event") - cancellationTxReceipt, err := evmClient.GetTxReceipt(tx.Hash()) - require.NoError(t, err, "error getting tx cancellation Tx Receipt") txGasUsed := new(big.Int).SetUint64(cancellationTxReceipt.GasUsed) // we don't have that information for older Geth versions @@ -469,15 +460,12 @@ func TestVRFv2Basic(t *testing.T) { Msg("Canceling subscription and returning funds to subscription owner") // Call OwnerCancelSubscription - tx, err := vrfContracts.CoordinatorV2.OwnerCancelSubscription(subIDForOwnerCancelling) + cancellationTxReceipt, err := vrfContracts.CoordinatorV2.OwnerCancelSubscription(subIDForOwnerCancelling) require.NoError(t, err, "Error canceling subscription") subscriptionCanceledEvent, err := vrfContracts.CoordinatorV2.WaitForSubscriptionCanceledEvent([]uint64{subIDForOwnerCancelling}, time.Second*30) require.NoError(t, err, "error waiting for subscription canceled event") - cancellationTxReceipt, err := evmClient.GetTxReceipt(tx.Hash()) - require.NoError(t, err, "error getting tx cancellation Tx Receipt") - txGasUsed := new(big.Int).SetUint64(cancellationTxReceipt.GasUsed) // we don't have that information for older Geth versions if cancellationTxReceipt.EffectiveGasPrice == nil { @@ -542,12 +530,12 @@ func TestVRFv2MultipleSendingKeys(t *testing.T) { } chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID vrfv2Config := config.VRFv2 + sethClient, err := testEnv.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") cleanupFn := func() { - evmClient, err := testEnv.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - if evmClient.NetworkSimulated() { + if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). - Str("Network Name", evmClient.GetNetworkName()). + Str("Network Name", sethClient.Cfg.Network.Name). Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") } else { if *vrfv2Config.General.CancelSubsAfterTestRun { @@ -571,10 +559,6 @@ func TestVRFv2MultipleSendingKeys(t *testing.T) { testEnv, vrfContracts, vrfKey, nodeTypeToNodeMap, err = vrfv2.SetupVRFV2Universe(testcontext.Get(t), t, config, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "Error setting up VRFV2 universe") - evmClient, err := testEnv.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - defaultWalletAddress = evmClient.GetDefaultWallet().Address() - t.Run("Request Randomness with multiple sending keys", func(t *testing.T) { configCopy := config.MustCopy().(tc.TestConfig) @@ -617,8 +601,7 @@ func TestVRFv2MultipleSendingKeys(t *testing.T) { ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") - //todo - move TransactionByHash to EVMClient in CTF - fulfillmentTx, _, err := actions.GetTxByHash(testcontext.Get(t), evmClient, randomWordsFulfilledEvent.Raw.TxHash) + fulfillmentTx, _, err := sethClient.Client.TransactionByHash(testcontext.Get(t), randomWordsFulfilledEvent.Raw.TxHash) require.NoError(t, err, "error getting tx from hash") fulfillmentTxFromAddress, err := actions.GetTxFromAddress(fulfillmentTx) require.NoError(t, err, "error getting tx from address") @@ -651,11 +634,11 @@ func TestVRFOwner(t *testing.T) { chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID vrfv2Config := config.VRFv2 cleanupFn := func() { - evmClient, err := testEnv.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - if evmClient.NetworkSimulated() { + sethClient, err := testEnv.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") + if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). - Str("Network Name", evmClient.GetNetworkName()). + Str("Network Name", sethClient.Cfg.Network.Name). Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") } else { if *vrfv2Config.General.CancelSubsAfterTestRun { @@ -679,10 +662,6 @@ func TestVRFOwner(t *testing.T) { testEnv, vrfContracts, vrfKey, _, err = vrfv2.SetupVRFV2Universe(testcontext.Get(t), t, config, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "Error setting up VRFV2 universe") - evmClient, err := testEnv.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - defaultWalletAddress = evmClient.GetDefaultWallet().Address() - t.Run("Request Randomness With Force-Fulfill", func(t *testing.T) { configCopy := config.MustCopy().(tc.TestConfig) @@ -713,9 +692,6 @@ func TestVRFOwner(t *testing.T) { ) require.NoError(t, err, "error transferring link to consumer contract") - err = evmClient.WaitForEvents() - require.NoError(t, err, vrfcommon.ErrWaitTXsComplete) - consumerLinkBalance, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), consumers[0].Address()) require.NoError(t, err, "error getting consumer link balance") l.Info(). @@ -725,8 +701,6 @@ func TestVRFOwner(t *testing.T) { err = vrfContracts.MockETHLINKFeed.SetBlockTimestampDeduction(big.NewInt(3)) require.NoError(t, err) - err = evmClient.WaitForEvents() - require.NoError(t, err, vrfcommon.ErrWaitTXsComplete) // test and assert _, randFulfilledEvent, _, err := vrfv2.RequestRandomnessWithForceFulfillAndWaitForFulfillment( @@ -793,12 +767,13 @@ func TestVRFV2WithBHS(t *testing.T) { vrfv2Config := config.VRFv2 chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID + sethClient, err := testEnv.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") + cleanupFn := func() { - evmClient, err := testEnv.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - if evmClient.NetworkSimulated() { + if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). - Str("Network Name", evmClient.GetNetworkName()). + Str("Network Name", sethClient.Cfg.Network.Name). Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") } else { if *vrfv2Config.General.CancelSubsAfterTestRun { @@ -827,10 +802,6 @@ func TestVRFV2WithBHS(t *testing.T) { testEnv, vrfContracts, vrfKey, nodeTypeToNodeMap, err = vrfv2.SetupVRFV2Universe(testcontext.Get(t), t, config, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "Error setting up VRFV2 universe") - evmClient, err := testEnv.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - defaultWalletAddress = evmClient.GetDefaultWallet().Address() - t.Run("BHS Job with complete E2E - wait 256 blocks to see if Rand Request is fulfilled", func(t *testing.T) { t.Skip("Skipped since should be run on-demand on live testnet due to long execution time") //BHS node should fill in blockhashes into BHS contract depending on the waitBlocks and lookBackBlocks settings @@ -874,7 +845,7 @@ func TestVRFV2WithBHS(t *testing.T) { var wg sync.WaitGroup wg.Add(1) //Wait at least 256 blocks - _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(257), evmClient, &wg, time.Second*260, t) + _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(257), sethClient, &wg, time.Second*260, t) wg.Wait() require.NoError(t, err) err = vrfv2.FundSubscriptions(testEnv, chainID, big.NewFloat(*configCopy.VRFv2.General.SubscriptionFundingAmountLink), vrfContracts.LinkToken, vrfContracts.CoordinatorV2, subIDsForBHS) @@ -937,12 +908,10 @@ func TestVRFV2WithBHS(t *testing.T) { var wg sync.WaitGroup wg.Add(1) - _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(*configCopy.VRFv2.General.BHSJobWaitBlocks), evmClient, &wg, time.Minute*1, t) + _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(*configCopy.VRFv2.General.BHSJobWaitBlocks), sethClient, &wg, time.Minute*1, t) wg.Wait() require.NoError(t, err, "error waiting for blocknumber to be") - err = evmClient.WaitForEvents() - require.NoError(t, err, vrfcommon.ErrWaitTXsComplete) metrics, err := consumers[0].GetLoadTestMetrics(testcontext.Get(t)) require.Equal(t, 0, metrics.RequestCount.Cmp(big.NewInt(1))) require.Equal(t, 0, metrics.FulfilmentCount.Cmp(big.NewInt(0))) @@ -960,7 +929,7 @@ func TestVRFV2WithBHS(t *testing.T) { require.Equal(t, strings.ToLower(vrfContracts.BHS.Address()), strings.ToLower(clNodeTxs.Data[0].Attributes.To)) - bhsStoreTx, _, err := actions.GetTxByHash(testcontext.Get(t), evmClient, common.HexToHash(txHash)) + bhsStoreTx, _, err := sethClient.Client.TransactionByHash(testcontext.Get(t), common.HexToHash(txHash)) require.NoError(t, err, "error getting tx from hash") bhsStoreTxInputData, err := actions.DecodeTxInputData(blockhash_store.BlockhashStoreABI, bhsStoreTx.Data()) @@ -969,9 +938,6 @@ func TestVRFV2WithBHS(t *testing.T) { Msg("BHS Node's Store Blockhash for Blocknumber Method TX") require.Equal(t, randRequestBlockNumber, bhsStoreTxInputData["n"].(*big.Int).Uint64()) - err = evmClient.WaitForEvents() - require.NoError(t, err, vrfcommon.ErrWaitTXsComplete) - var randRequestBlockHash [32]byte gom.Eventually(func(g gomega.Gomega) { randRequestBlockHash, err = vrfContracts.BHS.GetBlockHash(testcontext.Get(t), big.NewInt(int64(randRequestBlockNumber))) diff --git a/integration-tests/smoke/vrfv2plus_test.go b/integration-tests/smoke/vrfv2plus_test.go index 64685399227..6844de8f84d 100644 --- a/integration-tests/smoke/vrfv2plus_test.go +++ b/integration-tests/smoke/vrfv2plus_test.go @@ -703,14 +703,12 @@ func TestVRFv2PlusMultipleSendingKeys(t *testing.T) { require.NoError(t, err, "Error getting config") vrfv2PlusConfig := config.VRFv2Plus chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID - + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") cleanupFn := func() { - evmClient, err := env.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - - if evmClient.NetworkSimulated() { + if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). - Str("Network Name", evmClient.GetNetworkName()). + Str("Network Name", sethClient.Cfg.Network.Name). Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { @@ -734,10 +732,6 @@ func TestVRFv2PlusMultipleSendingKeys(t *testing.T) { env, vrfContracts, vrfKey, nodeTypeToNodeMap, err = vrfv2plus.SetupVRFV2PlusUniverse(testcontext.Get(t), t, config, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "error setting up VRFV2Plus universe") - evmClient, err := env.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - defaultWalletAddress = evmClient.GetDefaultWallet().Address() - t.Run("Request Randomness with multiple sending keys", func(t *testing.T) { configCopy := config.MustCopy().(tc.TestConfig) var isNativeBilling = true @@ -777,8 +771,7 @@ func TestVRFv2PlusMultipleSendingKeys(t *testing.T) { ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") - //todo - move TransactionByHash to EVMClient in CTF - fulfillmentTx, _, err := actions.GetTxByHash(testcontext.Get(t), evmClient, randomWordsFulfilledEvent.Raw.TxHash) + fulfillmentTx, _, err := sethClient.Client.TransactionByHash(testcontext.Get(t), randomWordsFulfilledEvent.Raw.TxHash) require.NoError(t, err, "error getting tx from hash") fulfillmentTxFromAddress, err := actions.GetTxFromAddress(fulfillmentTx) require.NoError(t, err, "error getting tx from address") @@ -1205,13 +1198,13 @@ func TestVRFV2PlusWithBHS(t *testing.T) { require.NoError(t, err, "Error getting config") vrfv2PlusConfig := config.VRFv2Plus chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") cleanupFn := func() { - evmClient, err := env.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - if evmClient.NetworkSimulated() { + if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). - Str("Network Name", evmClient.GetNetworkName()). + Str("Network Name", sethClient.Cfg.Network.Name). Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { @@ -1240,10 +1233,6 @@ func TestVRFV2PlusWithBHS(t *testing.T) { env, vrfContracts, vrfKey, nodeTypeToNodeMap, err = vrfv2plus.SetupVRFV2PlusUniverse(testcontext.Get(t), t, config, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "error setting up VRFV2Plus universe") - evmClient, err := env.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - defaultWalletAddress = evmClient.GetDefaultWallet().Address() - var isNativeBilling = true t.Run("BHS Job with complete E2E - wait 256 blocks to see if Rand Request is fulfilled", func(t *testing.T) { t.Skip("Skipped since should be run on-demand on live testnet due to long execution time") @@ -1284,7 +1273,7 @@ func TestVRFV2PlusWithBHS(t *testing.T) { var wg sync.WaitGroup wg.Add(1) //Wait at least 256 blocks - _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(257), evmClient, &wg, time.Second*260, t) + _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(257), sethClient, &wg, time.Second*260, t) wg.Wait() require.NoError(t, err) err = vrfv2plus.FundSubscriptions( @@ -1361,12 +1350,10 @@ func TestVRFV2PlusWithBHS(t *testing.T) { var wg sync.WaitGroup wg.Add(1) - _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(*configCopy.VRFv2Plus.General.BHSJobWaitBlocks+10), evmClient, &wg, time.Minute*1, t) + _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(*configCopy.VRFv2Plus.General.BHSJobWaitBlocks+10), sethClient, &wg, time.Minute*1, t) wg.Wait() require.NoError(t, err, "error waiting for blocknumber to be") - err = evmClient.WaitForEvents() - require.NoError(t, err, vrfcommon.ErrWaitTXsComplete) metrics, err := consumers[0].GetLoadTestMetrics(testcontext.Get(t)) require.Equal(t, 0, metrics.RequestCount.Cmp(big.NewInt(1))) require.Equal(t, 0, metrics.FulfilmentCount.Cmp(big.NewInt(0))) @@ -1384,7 +1371,7 @@ func TestVRFV2PlusWithBHS(t *testing.T) { require.Equal(t, strings.ToLower(vrfContracts.BHS.Address()), strings.ToLower(clNodeTxs.Data[0].Attributes.To)) - bhsStoreTx, _, err := actions.GetTxByHash(testcontext.Get(t), evmClient, common.HexToHash(txHash)) + bhsStoreTx, _, err := sethClient.Client.TransactionByHash(testcontext.Get(t), common.HexToHash(txHash)) require.NoError(t, err, "error getting tx from hash") bhsStoreTxInputData, err := actions.DecodeTxInputData(blockhash_store.BlockhashStoreABI, bhsStoreTx.Data()) @@ -1393,9 +1380,6 @@ func TestVRFV2PlusWithBHS(t *testing.T) { Msg("BHS Node's Store Blockhash for Blocknumber Method TX") require.Equal(t, randRequestBlockNumber, bhsStoreTxInputData["n"].(*big.Int).Uint64()) - err = evmClient.WaitForEvents() - require.NoError(t, err, vrfcommon.ErrWaitTXsComplete) - var randRequestBlockHash [32]byte gom.Eventually(func(g gomega.Gomega) { randRequestBlockHash, err = vrfContracts.BHS.GetBlockHash(testcontext.Get(t), big.NewInt(int64(randRequestBlockNumber))) @@ -1426,13 +1410,13 @@ func TestVRFV2PlusWithBHF(t *testing.T) { vrfv2PlusConfig := config.VRFv2Plus chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") cleanupFn := func() { - evmClient, err := env.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - if evmClient.NetworkSimulated() { + if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). - Str("Network Name", evmClient.GetNetworkName()). + Str("Network Name", sethClient.Cfg.Network.Name). Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { @@ -1507,7 +1491,7 @@ func TestVRFV2PlusWithBHF(t *testing.T) { var wg sync.WaitGroup wg.Add(1) //Wait at least 260 blocks - _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(260), evmClient, &wg, time.Second*262, t) + _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(260), sethClient, &wg, time.Second*262, t) wg.Wait() require.NoError(t, err) l.Info().Float64("SubscriptionFundingAmountNative", *configCopy.VRFv2Plus.General.SubscriptionRefundingAmountNative). From 67d4c7f9172ce9b7e4b330fabea0d39479631132 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Thu, 25 Apr 2024 14:18:06 +0200 Subject: [PATCH 11/43] wip 10 --- .../contracts/contract_vrf_models.go | 4 +- .../contracts/ethereum_vrfv2plus_contracts.go | 8 +- integration-tests/load/vrfv2/vrfv2_test.go | 18 +-- .../load/vrfv2plus/vrfv2plus_test.go | 41 ++---- integration-tests/smoke/vrfv2_test.go | 49 +++--- integration-tests/smoke/vrfv2plus_test.go | 139 ++++++++---------- 6 files changed, 116 insertions(+), 143 deletions(-) diff --git a/integration-tests/contracts/contract_vrf_models.go b/integration-tests/contracts/contract_vrf_models.go index 314c587d5e5..ee13274c25f 100644 --- a/integration-tests/contracts/contract_vrf_models.go +++ b/integration-tests/contracts/contract_vrf_models.go @@ -110,8 +110,8 @@ type VRFCoordinatorV2_5 interface { Address() string PendingRequestsExist(ctx context.Context, subID *big.Int) (bool, error) GetSubscription(ctx context.Context, subID *big.Int) (Subscription, error) - OwnerCancelSubscription(subID *big.Int) (*types.Transaction, error) - CancelSubscription(subID *big.Int, to common.Address) (*types.Transaction, error) + OwnerCancelSubscription(subID *big.Int) (*types.Receipt, error) + CancelSubscription(subID *big.Int, to common.Address) (*types.Receipt, error) Withdraw(recipient common.Address) error WithdrawNative(recipient common.Address) error GetNativeTokenTotalBalance(ctx context.Context) (*big.Int, error) diff --git a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go index 7755a21cc55..25fca374e19 100644 --- a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go @@ -234,7 +234,7 @@ func (v *EthereumVRFCoordinatorV2_5) GetNativeTokenTotalBalance(ctx context.Cont // OwnerCancelSubscription cancels subscription by Coordinator owner // return funds to sub owner, // does not check if pending requests for a sub exist -func (v *EthereumVRFCoordinatorV2_5) OwnerCancelSubscription(subID *big.Int) (*types.Transaction, error) { +func (v *EthereumVRFCoordinatorV2_5) OwnerCancelSubscription(subID *big.Int) (*types.Receipt, error) { tx, err := v.client.Decode(v.coordinator.OwnerCancelSubscription( v.client.NewTXOpts(), subID, @@ -242,13 +242,13 @@ func (v *EthereumVRFCoordinatorV2_5) OwnerCancelSubscription(subID *big.Int) (*t if err != nil { return nil, err } - return tx.Transaction, nil + return tx.Receipt, nil } // CancelSubscription cancels subscription by Sub owner, // return funds to specified address, // checks if pending requests for a sub exist -func (v *EthereumVRFCoordinatorV2_5) CancelSubscription(subID *big.Int, to common.Address) (*types.Transaction, error) { +func (v *EthereumVRFCoordinatorV2_5) CancelSubscription(subID *big.Int, to common.Address) (*types.Receipt, error) { tx, err := v.client.Decode(v.coordinator.CancelSubscription( v.client.NewTXOpts(), subID, @@ -257,7 +257,7 @@ func (v *EthereumVRFCoordinatorV2_5) CancelSubscription(subID *big.Int, to commo if err != nil { return nil, err } - return tx.Transaction, nil + return tx.Receipt, nil } func (v *EthereumVRFCoordinatorV2_5) Withdraw(recipient common.Address) error { diff --git a/integration-tests/load/vrfv2/vrfv2_test.go b/integration-tests/load/vrfv2/vrfv2_test.go index 5558b7af025..315936d1a66 100644 --- a/integration-tests/load/vrfv2/vrfv2_test.go +++ b/integration-tests/load/vrfv2/vrfv2_test.go @@ -38,7 +38,6 @@ func TestVRFV2Performance(t *testing.T) { testEnv *test_env.CLClusterTestEnv vrfContracts *vrfcommon.VRFContracts subIDsForCancellingAfterTest []uint64 - defaultWalletAddress string vrfKey *vrfcommon.VRFKeyData ) l := logging.GetTestLogger(t) @@ -60,9 +59,6 @@ func TestVRFV2Performance(t *testing.T) { chainID := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0].ChainID updatedLabels := UpdateLabels(labels, t) - sethClient, err := testEnv.GetSethClient(chainID) - require.NoError(t, err, "Getting Seth client shouldn't fail") - l.Info(). Str("Test Type", testType). Str("Test Duration", vrfv2Config.Performance.TestDuration.Duration.Truncate(time.Second).String()). @@ -75,6 +71,9 @@ func TestVRFV2Performance(t *testing.T) { cleanupFn := func() { teardown(t, vrfContracts.VRFV2Consumers[0], lc, updatedLabels, testReporter, testType, &testConfig) + sethClient, err := testEnv.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") + if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). Str("Network Name", sethClient.Cfg.Network.Name). @@ -82,7 +81,7 @@ func TestVRFV2Performance(t *testing.T) { } else { if *vrfv2Config.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, defaultWalletAddress, subIDsForCancellingAfterTest, l) + vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2Config.General.UseExistingEnv { @@ -176,7 +175,6 @@ func TestVRFV2BHSPerformance(t *testing.T) { testEnv *test_env.CLClusterTestEnv vrfContracts *vrfcommon.VRFContracts subIDsForCancellingAfterTest []uint64 - defaultWalletAddress string vrfKey *vrfcommon.VRFKeyData ) l := logging.GetTestLogger(t) @@ -208,12 +206,12 @@ func TestVRFV2BHSPerformance(t *testing.T) { Msg("Performance Test Configuration") chainID := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0].ChainID - sethClient, err := testEnv.GetSethClient(chainID) - require.NoError(t, err, "Getting Seth client shouldn't fail") cleanupFn := func() { teardown(t, vrfContracts.VRFV2Consumers[0], lc, updatedLabels, testReporter, testType, &testConfig) + sethClient, err := testEnv.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). Str("Network Name", sethClient.Cfg.Network.Name). @@ -221,7 +219,7 @@ func TestVRFV2BHSPerformance(t *testing.T) { } else { if *vrfv2Config.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, defaultWalletAddress, subIDsForCancellingAfterTest, l) + vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2Config.General.UseExistingEnv { @@ -298,6 +296,8 @@ func TestVRFV2BHSPerformance(t *testing.T) { var wgBlockNumberTobe sync.WaitGroup wgBlockNumberTobe.Add(1) //Wait at least 256 blocks + sethClient, err := testEnv.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") latestBlockNumber, err := sethClient.Client.BlockNumber(testcontext.Get(t)) require.NoError(t, err) _, err = actions.WaitForBlockNumberToBe(latestBlockNumber+uint64(256), sethClient, &wgBlockNumberTobe, configCopy.VRFv2.General.WaitFor256BlocksTimeout.Duration, t) diff --git a/integration-tests/load/vrfv2plus/vrfv2plus_test.go b/integration-tests/load/vrfv2plus/vrfv2plus_test.go index d461b4cde20..c00185e06f7 100644 --- a/integration-tests/load/vrfv2plus/vrfv2plus_test.go +++ b/integration-tests/load/vrfv2plus/vrfv2plus_test.go @@ -37,7 +37,6 @@ func TestVRFV2PlusPerformance(t *testing.T) { testEnv *test_env.CLClusterTestEnv vrfContracts *vrfcommon.VRFContracts subIDsForCancellingAfterTest []*big.Int - defaultWalletAddress string vrfKey *vrfcommon.VRFKeyData ) l := logging.GetTestLogger(t) @@ -71,18 +70,16 @@ func TestVRFV2PlusPerformance(t *testing.T) { cleanupFn := func() { teardown(t, vrfContracts.VRFV2PlusConsumer[0], lc, updatedLabels, testReporter, testType, &testConfig) - - evmClient, err := testEnv.GetEVMClient(chainID) - require.NoError(t, err, "error getting EVM client") - - if evmClient.NetworkSimulated() { + sethClient, err := testEnv.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") + if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). - Str("Network Name", evmClient.GetNetworkName()). + Str("Network Name", sethClient.Cfg.Network.Name). Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") } else { if *testConfig.VRFv2Plus.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, defaultWalletAddress, subIDsForCancellingAfterTest, l) + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) } } if !*testConfig.VRFv2Plus.General.UseExistingEnv { @@ -100,9 +97,6 @@ func TestVRFV2PlusPerformance(t *testing.T) { testEnv, vrfContracts, vrfKey, _, err = vrfv2plus.SetupVRFV2PlusUniverse(testcontext.Get(t), t, testConfig, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "error setting up VRFV2Plus universe") - evmClient, err := testEnv.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - var consumers []contracts.VRFv2PlusLoadTestConsumer subIDs, consumers, err := vrfv2plus.SetupSubsAndConsumersForExistingEnv( testEnv, @@ -124,7 +118,6 @@ func TestVRFV2PlusPerformance(t *testing.T) { l.Info().Int("Number of Subs", len(subIDs)).Msg("Subs involved in the test") vrfContracts.VRFV2PlusConsumer = consumers - defaultWalletAddress = evmClient.GetDefaultWallet().Address() // is our "job" stable at all, no memory leaks, no flaking performance under some RPS? t.Run("vrfv2plus performance test", func(t *testing.T) { @@ -179,7 +172,6 @@ func TestVRFV2PlusBHSPerformance(t *testing.T) { testEnv *test_env.CLClusterTestEnv vrfContracts *vrfcommon.VRFContracts subIDsForCancellingAfterTest []*big.Int - defaultWalletAddress string vrfKey *vrfcommon.VRFKeyData ) l := logging.GetTestLogger(t) @@ -214,18 +206,16 @@ func TestVRFV2PlusBHSPerformance(t *testing.T) { cleanupFn := func() { teardown(t, vrfContracts.VRFV2PlusConsumer[0], lc, updatedLabels, testReporter, testType, &testConfig) - - evmClient, err := testEnv.GetEVMClient(chainID) - require.NoError(t, err, "error getting EVM client") - - if evmClient.NetworkSimulated() { + sethClient, err := testEnv.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") + if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). - Str("Network Name", evmClient.GetNetworkName()). + Str("Network Name", sethClient.Cfg.Network.Name). Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") } else { if *testConfig.VRFv2Plus.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, defaultWalletAddress, subIDsForCancellingAfterTest, l) + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) } } if !*testConfig.VRFv2Plus.General.UseExistingEnv { @@ -243,11 +233,6 @@ func TestVRFV2PlusBHSPerformance(t *testing.T) { testEnv, vrfContracts, vrfKey, _, err = vrfv2plus.SetupVRFV2PlusUniverse(testcontext.Get(t), t, testConfig, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "error setting up VRFV2Plus universe") - evmClient, err := testEnv.GetEVMClient(chainID) - require.NoError(t, err, "error getting EVM client") - - defaultWalletAddress = evmClient.GetDefaultWallet().Address() - t.Run("vrfv2plus and bhs performance test", func(t *testing.T) { configCopy := testConfig.MustCopy().(tc.TestConfig) //Underfund Subscription @@ -308,9 +293,11 @@ func TestVRFV2PlusBHSPerformance(t *testing.T) { var wgBlockNumberTobe sync.WaitGroup wgBlockNumberTobe.Add(1) //Wait at least 256 blocks - latestBlockNumber, err := evmClient.LatestBlockNumber(testcontext.Get(t)) + sethClient, err := testEnv.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") + latestBlockNumber, err := sethClient.Client.BlockNumber(testcontext.Get(t)) require.NoError(t, err, "error getting latest block number") - _, err = actions.WaitForBlockNumberToBe(latestBlockNumber+uint64(256), evmClient, &wgBlockNumberTobe, configCopy.VRFv2Plus.General.WaitFor256BlocksTimeout.Duration, t) + _, err = actions.WaitForBlockNumberToBe(latestBlockNumber+uint64(256), sethClient, &wgBlockNumberTobe, configCopy.VRFv2Plus.General.WaitFor256BlocksTimeout.Duration, t) wgBlockNumberTobe.Wait() require.NoError(t, err, "error waiting for block number to be") diff --git a/integration-tests/smoke/vrfv2_test.go b/integration-tests/smoke/vrfv2_test.go index 3c319250d20..e07898fbaa4 100644 --- a/integration-tests/smoke/vrfv2_test.go +++ b/integration-tests/smoke/vrfv2_test.go @@ -37,7 +37,6 @@ func TestVRFv2Basic(t *testing.T) { testEnv *test_env.CLClusterTestEnv vrfContracts *vrfcommon.VRFContracts subIDsForCancellingAfterTest []uint64 - defaultWalletAddress string vrfKey *vrfcommon.VRFKeyData nodeTypeToNodeMap map[vrfcommon.VRFNodeType]*vrfcommon.VRFNode ) @@ -51,7 +50,6 @@ func TestVRFv2Basic(t *testing.T) { cleanupFn := func() { sethClient, err := testEnv.GetSethClient(chainID) require.NoError(t, err, "Getting Seth client shouldn't fail") - if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). Str("Network Name", sethClient.Cfg.Network.Name). @@ -59,7 +57,7 @@ func TestVRFv2Basic(t *testing.T) { } else { if *vrfv2Config.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, defaultWalletAddress, subIDsForCancellingAfterTest, l) + vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2Config.General.UseExistingEnv { @@ -78,6 +76,9 @@ func TestVRFv2Basic(t *testing.T) { testEnv, vrfContracts, vrfKey, nodeTypeToNodeMap, err = vrfv2.SetupVRFV2Universe(testcontext.Get(t), t, config, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "Error setting up VRFV2 universe") + sethClient, err := testEnv.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") + t.Run("Request Randomness", func(t *testing.T) { configCopy := config.MustCopy().(tc.TestConfig) consumers, subIDsForRequestRandomness, err := vrfv2.SetupNewConsumersAndSubs( @@ -294,18 +295,18 @@ func TestVRFv2Basic(t *testing.T) { amountToWithdrawLink := fulfilledEventLink.Payment - defaultWalletBalanceLinkBeforeOracleWithdraw, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), defaultWalletAddress) + defaultWalletBalanceLinkBeforeOracleWithdraw, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.Addresses[0].Hex()) require.NoError(t, err) l.Info(). - Str("Returning to", defaultWalletAddress). + Str("Returning to", sethClient.Addresses[0].Hex()). Str("Amount", amountToWithdrawLink.String()). Msg("Invoking Oracle Withdraw for LINK") - err = vrfContracts.CoordinatorV2.OracleWithdraw(common.HexToAddress(defaultWalletAddress), amountToWithdrawLink) + err = vrfContracts.CoordinatorV2.OracleWithdraw(sethClient.Addresses[0], amountToWithdrawLink) require.NoError(t, err, "Error withdrawing LINK from coordinator to default wallet") - defaultWalletBalanceLinkAfterOracleWithdraw, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), defaultWalletAddress) + defaultWalletBalanceLinkAfterOracleWithdraw, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.Addresses[0].Hex()) require.NoError(t, err) require.Equal( @@ -446,7 +447,7 @@ func TestVRFv2Basic(t *testing.T) { require.NoError(t, err) require.True(t, pendingRequestsExist, "Pending requests should exist after unfilfulled requests due to low sub balance") - walletBalanceLinkBeforeSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), defaultWalletAddress) + walletBalanceLinkBeforeSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.Addresses[0].Hex()) require.NoError(t, err) subscriptionForCancelling, err = vrfContracts.CoordinatorV2.GetSubscription(testcontext.Get(t), subIDForOwnerCancelling) @@ -456,7 +457,7 @@ func TestVRFv2Basic(t *testing.T) { l.Info(). Str("Subscription Amount Link", subBalanceLink.String()). Uint64("Returning funds from SubID", subIDForOwnerCancelling). - Str("Returning funds to", defaultWalletAddress). + Str("Returning funds to", sethClient.Addresses[0].Hex()). Msg("Canceling subscription and returning funds to subscription owner") // Call OwnerCancelSubscription @@ -487,7 +488,7 @@ func TestVRFv2Basic(t *testing.T) { require.Equal(t, subBalanceLink, subscriptionCanceledEvent.Amount, "SubscriptionCanceled event LINK amount is not equal to sub amount while canceling subscription") - walletBalanceLinkAfterSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), defaultWalletAddress) + walletBalanceLinkAfterSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.Addresses[0].Hex()) require.NoError(t, err) // Verify that subscription was deleted from Coordinator contract @@ -518,7 +519,6 @@ func TestVRFv2MultipleSendingKeys(t *testing.T) { testEnv *test_env.CLClusterTestEnv vrfContracts *vrfcommon.VRFContracts subIDsForCancellingAfterTest []uint64 - defaultWalletAddress string vrfKey *vrfcommon.VRFKeyData nodeTypeToNodeMap map[vrfcommon.VRFNodeType]*vrfcommon.VRFNode ) @@ -530,9 +530,10 @@ func TestVRFv2MultipleSendingKeys(t *testing.T) { } chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID vrfv2Config := config.VRFv2 - sethClient, err := testEnv.GetSethClient(chainID) - require.NoError(t, err, "Getting Seth client shouldn't fail") + cleanupFn := func() { + sethClient, err := testEnv.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). Str("Network Name", sethClient.Cfg.Network.Name). @@ -540,7 +541,7 @@ func TestVRFv2MultipleSendingKeys(t *testing.T) { } else { if *vrfv2Config.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, defaultWalletAddress, subIDsForCancellingAfterTest, l) + vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2Config.General.UseExistingEnv { @@ -600,7 +601,8 @@ func TestVRFv2MultipleSendingKeys(t *testing.T) { configCopy.VRFv2.General.RandomWordsFulfilledEventTimeout.Duration, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") - + sethClient, err := testEnv.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") fulfillmentTx, _, err := sethClient.Client.TransactionByHash(testcontext.Get(t), randomWordsFulfilledEvent.Raw.TxHash) require.NoError(t, err, "error getting tx from hash") fulfillmentTxFromAddress, err := actions.GetTxFromAddress(fulfillmentTx) @@ -624,7 +626,6 @@ func TestVRFOwner(t *testing.T) { testEnv *test_env.CLClusterTestEnv vrfContracts *vrfcommon.VRFContracts subIDsForCancellingAfterTest []uint64 - defaultWalletAddress string vrfKey *vrfcommon.VRFKeyData ) l := logging.GetTestLogger(t) @@ -633,6 +634,7 @@ func TestVRFOwner(t *testing.T) { require.NoError(t, err, "Error getting config") chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID vrfv2Config := config.VRFv2 + cleanupFn := func() { sethClient, err := testEnv.GetSethClient(chainID) require.NoError(t, err, "Getting Seth client shouldn't fail") @@ -643,7 +645,7 @@ func TestVRFOwner(t *testing.T) { } else { if *vrfv2Config.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, defaultWalletAddress, subIDsForCancellingAfterTest, l) + vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2Config.General.UseExistingEnv { @@ -756,7 +758,6 @@ func TestVRFV2WithBHS(t *testing.T) { testEnv *test_env.CLClusterTestEnv vrfContracts *vrfcommon.VRFContracts subIDsForCancellingAfterTest []uint64 - defaultWalletAddress string vrfKey *vrfcommon.VRFKeyData nodeTypeToNodeMap map[vrfcommon.VRFNodeType]*vrfcommon.VRFNode ) @@ -767,10 +768,9 @@ func TestVRFV2WithBHS(t *testing.T) { vrfv2Config := config.VRFv2 chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID - sethClient, err := testEnv.GetSethClient(chainID) - require.NoError(t, err, "Getting Seth client shouldn't fail") - cleanupFn := func() { + sethClient, err := testEnv.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). Str("Network Name", sethClient.Cfg.Network.Name). @@ -778,7 +778,7 @@ func TestVRFV2WithBHS(t *testing.T) { } else { if *vrfv2Config.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, defaultWalletAddress, subIDsForCancellingAfterTest, l) + vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2Config.General.UseExistingEnv { @@ -845,6 +845,8 @@ func TestVRFV2WithBHS(t *testing.T) { var wg sync.WaitGroup wg.Add(1) //Wait at least 256 blocks + sethClient, err := testEnv.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(257), sethClient, &wg, time.Second*260, t) wg.Wait() require.NoError(t, err) @@ -906,6 +908,9 @@ func TestVRFV2WithBHS(t *testing.T) { _, err = vrfContracts.BHS.GetBlockHash(testcontext.Get(t), big.NewInt(int64(randRequestBlockNumber))) require.Error(t, err, "error not occurred when getting blockhash for a blocknumber which was not stored in BHS contract") + sethClient, err := testEnv.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") + var wg sync.WaitGroup wg.Add(1) _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(*configCopy.VRFv2.General.BHSJobWaitBlocks), sethClient, &wg, time.Minute*1, t) diff --git a/integration-tests/smoke/vrfv2plus_test.go b/integration-tests/smoke/vrfv2plus_test.go index 6844de8f84d..b0e0b0d602b 100644 --- a/integration-tests/smoke/vrfv2plus_test.go +++ b/integration-tests/smoke/vrfv2plus_test.go @@ -38,7 +38,6 @@ func TestVRFv2Plus(t *testing.T) { env *test_env.CLClusterTestEnv vrfContracts *vrfcommon.VRFContracts subIDsForCancellingAfterTest []*big.Int - defaultWalletAddress string vrfKey *vrfcommon.VRFKeyData nodeTypeToNodeMap map[vrfcommon.VRFNodeType]*vrfcommon.VRFNode ) @@ -50,17 +49,17 @@ func TestVRFv2Plus(t *testing.T) { chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID cleanupFn := func() { - evmClient, err := env.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") - if evmClient.NetworkSimulated() { + if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). - Str("Network Name", evmClient.GetNetworkName()). + Str("Network Name", sethClient.Cfg.Network.Name). Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, defaultWalletAddress, subIDsForCancellingAfterTest, l) + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2PlusConfig.General.UseExistingEnv { @@ -79,9 +78,8 @@ func TestVRFv2Plus(t *testing.T) { env, vrfContracts, vrfKey, nodeTypeToNodeMap, err = vrfv2plus.SetupVRFV2PlusUniverse(testcontext.Get(t), t, config, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "Error setting up VRFv2Plus universe") - evmClient, err := env.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - defaultWalletAddress = evmClient.GetDefaultWallet().Address() + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") t.Run("Link Billing", func(t *testing.T) { configCopy := config.MustCopy().(tc.TestConfig) @@ -301,7 +299,7 @@ func TestVRFv2Plus(t *testing.T) { testConfig := configCopy.VRFv2Plus.General var isNativeBilling = true - wrapperConsumerBalanceBeforeRequestWei, err := evmClient.BalanceAt(testcontext.Get(t), common.HexToAddress(wrapperContracts.LoadTestConsumers[0].Address())) + wrapperConsumerBalanceBeforeRequestWei, err := sethClient.Client.BalanceAt(testcontext.Get(t), common.HexToAddress(wrapperContracts.LoadTestConsumers[0].Address()), nil) require.NoError(t, err, "error getting wrapper consumer balance") wrapperSubscription, err := vrfContracts.CoordinatorV2Plus.GetSubscription(testcontext.Get(t), wrapperSubID) @@ -331,7 +329,7 @@ func TestVRFv2Plus(t *testing.T) { expectedWrapperConsumerWeiBalance := new(big.Int).Sub(wrapperConsumerBalanceBeforeRequestWei, consumerStatus.Paid) - wrapperConsumerBalanceAfterRequestWei, err := evmClient.BalanceAt(testcontext.Get(t), common.HexToAddress(wrapperContracts.LoadTestConsumers[0].Address())) + wrapperConsumerBalanceAfterRequestWei, err := sethClient.Client.BalanceAt(testcontext.Get(t), common.HexToAddress(wrapperContracts.LoadTestConsumers[0].Address()), nil) require.NoError(t, err, "error getting wrapper consumer balance") require.Equal(t, expectedWrapperConsumerWeiBalance, wrapperConsumerBalanceAfterRequestWei) @@ -368,7 +366,7 @@ func TestVRFv2Plus(t *testing.T) { testWalletAddress, err := actions.GenerateWallet() require.NoError(t, err) - testWalletBalanceNativeBeforeSubCancelling, err := evmClient.BalanceAt(testcontext.Get(t), testWalletAddress) + testWalletBalanceNativeBeforeSubCancelling, err := sethClient.Client.BalanceAt(testcontext.Get(t), testWalletAddress, nil) require.NoError(t, err) testWalletBalanceLinkBeforeSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), testWalletAddress.String()) @@ -385,15 +383,12 @@ func TestVRFv2Plus(t *testing.T) { Str("Returning funds from SubID", subID.String()). Str("Returning funds to", testWalletAddress.String()). Msg("Canceling subscription and returning funds to subscription owner") - tx, err := vrfContracts.CoordinatorV2Plus.CancelSubscription(subID, testWalletAddress) + cancellationTxReceipt, err := vrfContracts.CoordinatorV2Plus.CancelSubscription(subID, testWalletAddress) require.NoError(t, err, "Error canceling subscription") subscriptionCanceledEvent, err := vrfContracts.CoordinatorV2Plus.WaitForSubscriptionCanceledEvent(subID, time.Second*30) require.NoError(t, err, "error waiting for subscription canceled event") - cancellationTxReceipt, err := evmClient.GetTxReceipt(tx.Hash()) - require.NoError(t, err, "error getting tx cancellation Tx Receipt") - txGasUsed := new(big.Int).SetUint64(cancellationTxReceipt.GasUsed) // we don't have that information for older Geth versions if cancellationTxReceipt.EffectiveGasPrice == nil { @@ -417,7 +412,7 @@ func TestVRFv2Plus(t *testing.T) { require.Equal(t, subBalanceNative, subscriptionCanceledEvent.AmountNative, "SubscriptionCanceled event native amount is not equal to sub amount while canceling subscription") require.Equal(t, subBalanceLink, subscriptionCanceledEvent.AmountLink, "SubscriptionCanceled event LINK amount is not equal to sub amount while canceling subscription") - testWalletBalanceNativeAfterSubCancelling, err := evmClient.BalanceAt(testcontext.Get(t), testWalletAddress) + testWalletBalanceNativeAfterSubCancelling, err := sethClient.Client.BalanceAt(testcontext.Get(t), testWalletAddress, nil) require.NoError(t, err) testWalletBalanceLinkAfterSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), testWalletAddress.String()) @@ -510,10 +505,10 @@ func TestVRFv2Plus(t *testing.T) { require.NoError(t, err) require.True(t, pendingRequestsExist, "Pending requests should exist after unfulfilled rand requests due to low sub balance") - walletBalanceNativeBeforeSubCancelling, err := evmClient.BalanceAt(testcontext.Get(t), common.HexToAddress(defaultWalletAddress)) + walletBalanceNativeBeforeSubCancelling, err := sethClient.Client.BalanceAt(testcontext.Get(t), common.HexToAddress(sethClient.Addresses[0].Hex()), nil) require.NoError(t, err) - walletBalanceLinkBeforeSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), defaultWalletAddress) + walletBalanceLinkBeforeSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.Addresses[0].Hex()) require.NoError(t, err) subscriptionForCancelling, err := vrfContracts.CoordinatorV2Plus.GetSubscription(testcontext.Get(t), subID) @@ -525,17 +520,14 @@ func TestVRFv2Plus(t *testing.T) { Str("Subscription Amount Native", subBalanceNative.String()). Str("Subscription Amount Link", subBalanceLink.String()). Str("Returning funds from SubID", subID.String()). - Str("Returning funds to", defaultWalletAddress). + Str("Returning funds to", sethClient.Addresses[0].Hex()). Msg("Canceling subscription and returning funds to subscription owner") - tx, err := vrfContracts.CoordinatorV2Plus.OwnerCancelSubscription(subID) + cancellationTxReceipt, err := vrfContracts.CoordinatorV2Plus.OwnerCancelSubscription(subID) require.NoError(t, err, "Error canceling subscription") subscriptionCanceledEvent, err := vrfContracts.CoordinatorV2Plus.WaitForSubscriptionCanceledEvent(subID, time.Second*30) require.NoError(t, err, "error waiting for subscription canceled event") - cancellationTxReceipt, err := evmClient.GetTxReceipt(tx.Hash()) - require.NoError(t, err, "error getting tx cancellation Tx Receipt") - txGasUsed := new(big.Int).SetUint64(cancellationTxReceipt.GasUsed) // we don't have that information for older Geth versions if cancellationTxReceipt.EffectiveGasPrice == nil { @@ -559,10 +551,10 @@ func TestVRFv2Plus(t *testing.T) { require.Equal(t, subBalanceNative, subscriptionCanceledEvent.AmountNative, "SubscriptionCanceled event native amount is not equal to sub amount while canceling subscription") require.Equal(t, subBalanceLink, subscriptionCanceledEvent.AmountLink, "SubscriptionCanceled event LINK amount is not equal to sub amount while canceling subscription") - walletBalanceNativeAfterSubCancelling, err := evmClient.BalanceAt(testcontext.Get(t), common.HexToAddress(defaultWalletAddress)) + walletBalanceNativeAfterSubCancelling, err := sethClient.Client.BalanceAt(testcontext.Get(t), common.HexToAddress(sethClient.Addresses[0].Hex()), nil) require.NoError(t, err) - walletBalanceLinkAfterSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), defaultWalletAddress) + walletBalanceLinkAfterSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.Addresses[0].Hex()) require.NoError(t, err) //Verify that sub was deleted from Coordinator @@ -645,40 +637,37 @@ func TestVRFv2Plus(t *testing.T) { require.NoError(t, err) amountToWithdrawLink := fulfilledEventLink.Payment - defaultWalletBalanceNativeBeforeWithdraw, err := evmClient.BalanceAt(testcontext.Get(t), common.HexToAddress(defaultWalletAddress)) + defaultWalletBalanceNativeBeforeWithdraw, err := sethClient.Client.BalanceAt(testcontext.Get(t), common.HexToAddress(sethClient.Addresses[0].Hex()), nil) require.NoError(t, err) - defaultWalletBalanceLinkBeforeWithdraw, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), defaultWalletAddress) + defaultWalletBalanceLinkBeforeWithdraw, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.Addresses[0].Hex()) require.NoError(t, err) l.Info(). - Str("Returning to", defaultWalletAddress). + Str("Returning to", sethClient.Addresses[0].Hex()). Str("Amount", amountToWithdrawLink.String()). Msg("Invoking Oracle Withdraw for LINK") err = vrfContracts.CoordinatorV2Plus.Withdraw( - common.HexToAddress(defaultWalletAddress), + common.HexToAddress(sethClient.Addresses[0].Hex()), ) require.NoError(t, err, "error withdrawing LINK from coordinator to default wallet") amountToWithdrawNative := fulfilledEventNative.Payment l.Info(). - Str("Returning to", defaultWalletAddress). + Str("Returning to", sethClient.Addresses[0].Hex()). Str("Amount", amountToWithdrawNative.String()). Msg("Invoking Oracle Withdraw for Native") err = vrfContracts.CoordinatorV2Plus.WithdrawNative( - common.HexToAddress(defaultWalletAddress), + common.HexToAddress(sethClient.Addresses[0].Hex()), ) require.NoError(t, err, "error withdrawing Native tokens from coordinator to default wallet") - err = evmClient.WaitForEvents() - require.NoError(t, err, vrfcommon.ErrWaitTXsComplete) - - defaultWalletBalanceNativeAfterWithdraw, err := evmClient.BalanceAt(testcontext.Get(t), common.HexToAddress(defaultWalletAddress)) + defaultWalletBalanceNativeAfterWithdraw, err := sethClient.Client.BalanceAt(testcontext.Get(t), common.HexToAddress(sethClient.Addresses[0].Hex()), nil) require.NoError(t, err) - defaultWalletBalanceLinkAfterWithdraw, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), defaultWalletAddress) + defaultWalletBalanceLinkAfterWithdraw, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.Addresses[0].Hex()) require.NoError(t, err) //not possible to verify exact amount of Native/LINK returned as defaultWallet is used in other tests in parallel which might affect the balance @@ -693,7 +682,6 @@ func TestVRFv2PlusMultipleSendingKeys(t *testing.T) { env *test_env.CLClusterTestEnv vrfContracts *vrfcommon.VRFContracts subIDsForCancellingAfterTest []*big.Int - defaultWalletAddress string vrfKey *vrfcommon.VRFKeyData nodeTypeToNodeMap map[vrfcommon.VRFNodeType]*vrfcommon.VRFNode ) @@ -703,9 +691,10 @@ func TestVRFv2PlusMultipleSendingKeys(t *testing.T) { require.NoError(t, err, "Error getting config") vrfv2PlusConfig := config.VRFv2Plus chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID - sethClient, err := env.GetSethClient(chainID) - require.NoError(t, err, "Getting Seth client shouldn't fail") + cleanupFn := func() { + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). Str("Network Name", sethClient.Cfg.Network.Name). @@ -713,7 +702,7 @@ func TestVRFv2PlusMultipleSendingKeys(t *testing.T) { } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, defaultWalletAddress, subIDsForCancellingAfterTest, l) + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2PlusConfig.General.UseExistingEnv { @@ -770,7 +759,8 @@ func TestVRFv2PlusMultipleSendingKeys(t *testing.T) { l, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") - + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") fulfillmentTx, _, err := sethClient.Client.TransactionByHash(testcontext.Get(t), randomWordsFulfilledEvent.Raw.TxHash) require.NoError(t, err, "error getting tx from hash") fulfillmentTxFromAddress, err := actions.GetTxFromAddress(fulfillmentTx) @@ -794,7 +784,6 @@ func TestVRFv2PlusMigration(t *testing.T) { env *test_env.CLClusterTestEnv vrfContracts *vrfcommon.VRFContracts subIDsForCancellingAfterTest []*big.Int - defaultWalletAddress string vrfKey *vrfcommon.VRFKeyData nodeTypeToNodeMap map[vrfcommon.VRFNodeType]*vrfcommon.VRFNode ) @@ -805,10 +794,9 @@ func TestVRFv2PlusMigration(t *testing.T) { vrfv2PlusConfig := config.VRFv2Plus chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID - sethClient, err := env.GetSethClient(chainID) - require.NoError(t, err, "Getting Seth client shouldn't fail") - cleanupFn := func() { + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). Str("Network Name", sethClient.Cfg.Network.Name). @@ -816,7 +804,7 @@ func TestVRFv2PlusMigration(t *testing.T) { } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, defaultWalletAddress, subIDsForCancellingAfterTest, l) + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2PlusConfig.General.UseExistingEnv { @@ -835,6 +823,9 @@ func TestVRFv2PlusMigration(t *testing.T) { env, vrfContracts, vrfKey, nodeTypeToNodeMap, err = vrfv2plus.SetupVRFV2PlusUniverse(testcontext.Get(t), t, config, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "error setting up VRFV2Plus universe") + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") + // Migrate subscription from old coordinator to new coordinator, verify if balances // are moved correctly and requests can be made successfully in the subscription in // new coordinator @@ -1188,7 +1179,6 @@ func TestVRFV2PlusWithBHS(t *testing.T) { env *test_env.CLClusterTestEnv vrfContracts *vrfcommon.VRFContracts subIDsForCancellingAfterTest []*big.Int - defaultWalletAddress string vrfKey *vrfcommon.VRFKeyData nodeTypeToNodeMap map[vrfcommon.VRFNodeType]*vrfcommon.VRFNode ) @@ -1198,10 +1188,10 @@ func TestVRFV2PlusWithBHS(t *testing.T) { require.NoError(t, err, "Error getting config") vrfv2PlusConfig := config.VRFv2Plus chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID - sethClient, err := env.GetSethClient(chainID) - require.NoError(t, err, "Getting Seth client shouldn't fail") cleanupFn := func() { + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). Str("Network Name", sethClient.Cfg.Network.Name). @@ -1209,7 +1199,7 @@ func TestVRFV2PlusWithBHS(t *testing.T) { } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, defaultWalletAddress, subIDsForCancellingAfterTest, l) + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2PlusConfig.General.UseExistingEnv { @@ -1233,6 +1223,9 @@ func TestVRFV2PlusWithBHS(t *testing.T) { env, vrfContracts, vrfKey, nodeTypeToNodeMap, err = vrfv2plus.SetupVRFV2PlusUniverse(testcontext.Get(t), t, config, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "error setting up VRFV2Plus universe") + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") + var isNativeBilling = true t.Run("BHS Job with complete E2E - wait 256 blocks to see if Rand Request is fulfilled", func(t *testing.T) { t.Skip("Skipped since should be run on-demand on live testnet due to long execution time") @@ -1399,7 +1392,6 @@ func TestVRFV2PlusWithBHF(t *testing.T) { env *test_env.CLClusterTestEnv vrfContracts *vrfcommon.VRFContracts subIDsForCancellingAfterTest []*big.Int - defaultWalletAddress string vrfKey *vrfcommon.VRFKeyData nodeTypeToNodeMap map[vrfcommon.VRFNodeType]*vrfcommon.VRFNode ) @@ -1408,12 +1400,11 @@ func TestVRFV2PlusWithBHF(t *testing.T) { config, err := tc.GetConfig("Smoke", tc.VRFv2Plus) require.NoError(t, err, "Error getting config") vrfv2PlusConfig := config.VRFv2Plus - chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID - sethClient, err := env.GetSethClient(chainID) - require.NoError(t, err, "Getting Seth client shouldn't fail") cleanupFn := func() { + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). Str("Network Name", sethClient.Cfg.Network.Name). @@ -1421,7 +1412,7 @@ func TestVRFV2PlusWithBHF(t *testing.T) { } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, defaultWalletAddress, subIDsForCancellingAfterTest, l) + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2PlusConfig.General.UseExistingEnv { @@ -1447,9 +1438,9 @@ func TestVRFV2PlusWithBHF(t *testing.T) { env, vrfContracts, vrfKey, nodeTypeToNodeMap, err = vrfv2plus.SetupVRFV2PlusUniverse( testcontext.Get(t), t, config, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err) - evmClient, err := env.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - defaultWalletAddress = evmClient.GetDefaultWallet().Address() + + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") var isNativeBilling = true t.Run("BHF Job with complete E2E - wait 256 blocks to see if Rand Request is fulfilled", func(t *testing.T) { @@ -1548,7 +1539,6 @@ func TestVRFv2PlusReplayAfterTimeout(t *testing.T) { env *test_env.CLClusterTestEnv vrfContracts *vrfcommon.VRFContracts subIDsForCancellingAfterTest []*big.Int - defaultWalletAddress string vrfKey *vrfcommon.VRFKeyData nodeTypeToNodeMap map[vrfcommon.VRFNodeType]*vrfcommon.VRFNode ) @@ -1560,16 +1550,16 @@ func TestVRFv2PlusReplayAfterTimeout(t *testing.T) { chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID cleanupFn := func() { - evmClient, err := env.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - if evmClient.NetworkSimulated() { + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") + if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). - Str("Network Name", evmClient.GetNetworkName()). + Str("Network Name", sethClient.Cfg.Network.Name). Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, defaultWalletAddress, subIDsForCancellingAfterTest, l) + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2PlusConfig.General.UseExistingEnv { @@ -1594,10 +1584,6 @@ func TestVRFv2PlusReplayAfterTimeout(t *testing.T) { env, vrfContracts, vrfKey, nodeTypeToNodeMap, err = vrfv2plus.SetupVRFV2PlusUniverse(testcontext.Get(t), t, config, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "error setting up VRFV2Plus universe") - evmClient, err := env.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - defaultWalletAddress = evmClient.GetDefaultWallet().Address() - t.Run("Timed out request fulfilled after node restart with replay", func(t *testing.T) { configCopy := config.MustCopy().(tc.TestConfig) var isNativeBilling = false @@ -1748,7 +1734,6 @@ func TestVRFv2PlusPendingBlockSimulationAndZeroConfirmationDelays(t *testing.T) env *test_env.CLClusterTestEnv vrfContracts *vrfcommon.VRFContracts subIDsForCancellingAfterTest []*big.Int - defaultWalletAddress string vrfKey *vrfcommon.VRFKeyData ) l := logging.GetTestLogger(t) @@ -1759,16 +1744,16 @@ func TestVRFv2PlusPendingBlockSimulationAndZeroConfirmationDelays(t *testing.T) chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID cleanupFn := func() { - evmClient, err := env.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - if evmClient.NetworkSimulated() { + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") + if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). - Str("Network Name", evmClient.GetNetworkName()). + Str("Network Name", sethClient.Cfg.Network.Name). Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, defaultWalletAddress, subIDsForCancellingAfterTest, l) + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2PlusConfig.General.UseExistingEnv { @@ -1791,10 +1776,6 @@ func TestVRFv2PlusPendingBlockSimulationAndZeroConfirmationDelays(t *testing.T) env, vrfContracts, vrfKey, _, err = vrfv2plus.SetupVRFV2PlusUniverse(testcontext.Get(t), t, config, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "error setting up VRFV2Plus universe") - evmClient, err := env.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - defaultWalletAddress = evmClient.GetDefaultWallet().Address() - consumers, subIDs, err := vrfv2plus.SetupNewConsumersAndSubs( env, chainID, From b735d3206588a2cc75e52a3cefa9702395c60cf9 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Thu, 25 Apr 2024 14:35:15 +0200 Subject: [PATCH 12/43] fix --- integration-tests/contracts/ethereum_ocr2vrf_contracts.go | 4 ---- integration-tests/go.mod | 2 +- integration-tests/go.sum | 4 ++-- integration-tests/load/go.mod | 2 +- integration-tests/load/go.sum | 4 ++-- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/integration-tests/contracts/ethereum_ocr2vrf_contracts.go b/integration-tests/contracts/ethereum_ocr2vrf_contracts.go index 5ee0cd2bf35..bcc73ed01e1 100644 --- a/integration-tests/contracts/ethereum_ocr2vrf_contracts.go +++ b/integration-tests/contracts/ethereum_ocr2vrf_contracts.go @@ -12,10 +12,6 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/rs/zerolog/log" - "github.com/smartcontractkit/chainlink-vrf/archive/gethwrappers/dkg" - "github.com/smartcontractkit/chainlink-vrf/archive/gethwrappers/vrf_beacon" - "github.com/smartcontractkit/chainlink-vrf/archive/gethwrappers/vrf_beacon_consumer" - "github.com/smartcontractkit/chainlink-vrf/archive/gethwrappers/vrf_coordinator" "github.com/smartcontractkit/chainlink/integration-tests/wrappers" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/batch_blockhash_store" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ocr2vrf/generated/dkg" diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 1ae924ae152..c8628e7e6f7 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -27,7 +27,7 @@ require ( github.com/smartcontractkit/chainlink-automation v1.0.3 github.com/smartcontractkit/chainlink-common v0.1.7-0.20240424132620-add4946c1c73 github.com/smartcontractkit/chainlink-testing-framework v1.28.4 - github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868 + github.com/smartcontractkit/chainlink-vrf v0.0.0-20240229152020-3390c480411a github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000 github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c github.com/smartcontractkit/seth v0.1.6-0.20240424154541-db45307043b2 diff --git a/integration-tests/go.sum b/integration-tests/go.sum index a8b632a4fc5..19255a182ad 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -1531,8 +1531,8 @@ github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.202403 github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20240325075535-0f7eb05ee595/go.mod h1:vV6WfnVIbK5Q1JsIru4YcTG0T1uRpLJm6t2BgCnCSsg= github.com/smartcontractkit/chainlink-testing-framework v1.28.4 h1:/OOPH76VFQlG5HEXrXgBVDv1fjuasQzMV1EyeaaXWzM= github.com/smartcontractkit/chainlink-testing-framework v1.28.4/go.mod h1:jN+HgXbriq6fKRlIqLw9F3I81aYImV6kBJkIfz0mdIA= -github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868 h1:FFdvEzlYwcuVHkdZ8YnZR/XomeMGbz5E2F2HZI3I3w8= -github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868/go.mod h1:Kn1Hape05UzFZ7bOUnm3GVsHzP0TNrVmpfXYNHdqGGs= +github.com/smartcontractkit/chainlink-vrf v0.0.0-20240229152020-3390c480411a h1:W2/6HhPCSaUCyHct1oUXZtt7UneM3OUcI203wq+zOnE= +github.com/smartcontractkit/chainlink-vrf v0.0.0-20240229152020-3390c480411a/go.mod h1:Kn1Hape05UzFZ7bOUnm3GVsHzP0TNrVmpfXYNHdqGGs= github.com/smartcontractkit/go-plugin v0.0.0-20240208201424-b3b91517de16 h1:TFe+FvzxClblt6qRfqEhUfa4kFQx5UobuoFGO2W4mMo= github.com/smartcontractkit/go-plugin v0.0.0-20240208201424-b3b91517de16/go.mod h1:lBS5MtSSBZk0SHc66KACcjjlU6WzEVP/8pwz68aMkCI= github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJif132UCdjo8u43i7iPN1/MFnu49hv7lFGFftCHKU= diff --git a/integration-tests/load/go.mod b/integration-tests/load/go.mod index 128c611c04d..c7a018ee428 100644 --- a/integration-tests/load/go.mod +++ b/integration-tests/load/go.mod @@ -372,7 +372,7 @@ require ( github.com/smartcontractkit/chainlink-solana v1.0.3-0.20240422172640-59d47c73ba58 // indirect github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20240325075535-0f7eb05ee595 // indirect github.com/smartcontractkit/chainlink-testing-framework/grafana v0.0.0-20240227164431-18a7065e23ea // indirect - github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868 // indirect + github.com/smartcontractkit/chainlink-vrf v0.0.0-20240229152020-3390c480411a // indirect github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 // indirect github.com/smartcontractkit/wsrpc v0.8.1 // indirect github.com/soheilhy/cmux v0.1.5 // indirect diff --git a/integration-tests/load/go.sum b/integration-tests/load/go.sum index 291f221f4b8..8c0aad9e8d8 100644 --- a/integration-tests/load/go.sum +++ b/integration-tests/load/go.sum @@ -1516,8 +1516,8 @@ github.com/smartcontractkit/chainlink-testing-framework v1.28.4 h1:/OOPH76VFQlG5 github.com/smartcontractkit/chainlink-testing-framework v1.28.4/go.mod h1:jN+HgXbriq6fKRlIqLw9F3I81aYImV6kBJkIfz0mdIA= github.com/smartcontractkit/chainlink-testing-framework/grafana v0.0.0-20240227164431-18a7065e23ea h1:ZdLmNAfKRjH8AYUvjiiDGUgiWQfq/7iNpxyTkvjx/ko= github.com/smartcontractkit/chainlink-testing-framework/grafana v0.0.0-20240227164431-18a7065e23ea/go.mod h1:gCKC9w6XpNk6jm+XIk2psrkkfxhi421N9NSiFceXW88= -github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868 h1:FFdvEzlYwcuVHkdZ8YnZR/XomeMGbz5E2F2HZI3I3w8= -github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868/go.mod h1:Kn1Hape05UzFZ7bOUnm3GVsHzP0TNrVmpfXYNHdqGGs= +github.com/smartcontractkit/chainlink-vrf v0.0.0-20240229152020-3390c480411a h1:W2/6HhPCSaUCyHct1oUXZtt7UneM3OUcI203wq+zOnE= +github.com/smartcontractkit/chainlink-vrf v0.0.0-20240229152020-3390c480411a/go.mod h1:Kn1Hape05UzFZ7bOUnm3GVsHzP0TNrVmpfXYNHdqGGs= 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= From 14092f4227440f9c6e9ce0295d505842ddf733ce Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Thu, 25 Apr 2024 14:43:16 +0200 Subject: [PATCH 13/43] fix go mod --- integration-tests/load/go.mod | 2 +- integration-tests/load/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integration-tests/load/go.mod b/integration-tests/load/go.mod index c7a018ee428..8a94f7023fb 100644 --- a/integration-tests/load/go.mod +++ b/integration-tests/load/go.mod @@ -21,7 +21,7 @@ require ( github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20240214231432-4ad5eb95178c github.com/smartcontractkit/chainlink/v2 v2.9.0-beta0.0.20240216210048-da02459ddad8 github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c - github.com/smartcontractkit/seth v0.1.6 + github.com/smartcontractkit/seth v0.1.6-0.20240424154541-db45307043b2 github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1 github.com/smartcontractkit/wasp v0.4.6 github.com/stretchr/testify v1.9.0 diff --git a/integration-tests/load/go.sum b/integration-tests/load/go.sum index 8c0aad9e8d8..94ab512f83f 100644 --- a/integration-tests/load/go.sum +++ b/integration-tests/load/go.sum @@ -1524,8 +1524,8 @@ github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJ github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0= github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c h1:lIyMbTaF2H0Q71vkwZHX/Ew4KF2BxiKhqEXwF8rn+KI= github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c/go.mod h1:fb1ZDVXACvu4frX3APHZaEBp0xi1DIm34DcA0CwTsZM= -github.com/smartcontractkit/seth v0.1.6 h1:exU96KiKM/gxvp7OR8KkOXnTgbtFNepdhMBvyobFKCw= -github.com/smartcontractkit/seth v0.1.6/go.mod h1:2TMOZQ8WTAw7rR1YBbXpnad6VmT/+xDd/nXLmB7Eero= +github.com/smartcontractkit/seth v0.1.6-0.20240424154541-db45307043b2 h1:pOLrnNRYpOfPQPPn/8B0Z12TIsyu8q3dwZXspWzzzTY= +github.com/smartcontractkit/seth v0.1.6-0.20240424154541-db45307043b2/go.mod h1:2TMOZQ8WTAw7rR1YBbXpnad6VmT/+xDd/nXLmB7Eero= github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 h1:yiKnypAqP8l0OX0P3klzZ7SCcBUxy5KqTAKZmQOvSQE= github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1/go.mod h1:q6f4fe39oZPdsh1i57WznEZgxd8siidMaSFq3wdPmVg= github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1 h1:Dai1bn+Q5cpeGMQwRdjOdVjG8mmFFROVkSKuUgBErRQ= From c2212181068734a7cb03b418c849bf6271a09599 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Thu, 25 Apr 2024 14:53:04 +0200 Subject: [PATCH 14/43] fix --- integration-tests/actions/actions.go | 3 ++- .../actions/ocr2vrf_actions/ocr2vrf_steps.go | 6 ++--- .../actions/vrf/common/actions.go | 5 ++-- .../actions/vrf/vrfv2/contract_steps.go | 23 +++++++--------- .../actions/vrf/vrfv2/setup_steps.go | 15 ++++------- .../actions/vrf/vrfv2plus/contract_steps.go | 6 ++--- .../actions/vrf/vrfv2plus/setup_steps.go | 6 ++--- .../contracts/contract_loader.go | 3 ++- .../contracts/contract_vrf_models.go | 10 +++---- .../contracts/ethereum_contracts.go | 3 --- .../contracts/ethereum_contracts_seth.go | 3 --- .../contracts/ethereum_ocr2vrf_contracts.go | 3 ++- .../contracts/ethereum_vrf_contracts.go | 3 ++- .../contracts/ethereum_vrfv2_contracts.go | 27 ++++++++++--------- .../contracts/ethereum_vrfv2plus_contracts.go | 25 +++++++---------- integration-tests/smoke/vrfv2_test.go | 12 ++++++--- integration-tests/smoke/vrfv2plus_test.go | 8 ++++-- 17 files changed, 77 insertions(+), 84 deletions(-) diff --git a/integration-tests/actions/actions.go b/integration-tests/actions/actions.go index 83f53e72374..1b8b4829d5f 100644 --- a/integration-tests/actions/actions.go +++ b/integration-tests/actions/actions.go @@ -28,6 +28,8 @@ import ( "github.com/rs/zerolog/log" "go.uber.org/zap/zapcore" + "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink-testing-framework/blockchain" ctfClient "github.com/smartcontractkit/chainlink-testing-framework/client" "github.com/smartcontractkit/chainlink-testing-framework/k8s/environment" @@ -38,7 +40,6 @@ import ( "github.com/smartcontractkit/chainlink/integration-tests/client" "github.com/smartcontractkit/chainlink/integration-tests/contracts" "github.com/smartcontractkit/chainlink/integration-tests/docker/test_env" - "github.com/smartcontractkit/seth" ) // ContractDeploymentInterval After how many contract actions to wait before starting any more diff --git a/integration-tests/actions/ocr2vrf_actions/ocr2vrf_steps.go b/integration-tests/actions/ocr2vrf_actions/ocr2vrf_steps.go index dbffb768985..61989def0c8 100644 --- a/integration-tests/actions/ocr2vrf_actions/ocr2vrf_steps.go +++ b/integration-tests/actions/ocr2vrf_actions/ocr2vrf_steps.go @@ -10,9 +10,10 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/stretchr/testify/require" - ocr2vrftypes "github.com/smartcontractkit/chainlink-vrf/types" "github.com/smartcontractkit/seth" + ocr2vrftypes "github.com/smartcontractkit/chainlink-vrf/types" + "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink-testing-framework/logging" "github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext" @@ -165,7 +166,7 @@ func SetAndGetOCR2VRFPluginConfig( return ocr2VRFPluginConfig } -func FundVRFCoordinatorV3Subscription(t *testing.T, linkToken contracts.LinkToken, coordinator contracts.VRFCoordinatorV3, chainClient *seth.Client, subscriptionID, linkFundingAmount *big.Int) { +func FundVRFCoordinatorV3Subscription(t *testing.T, linkToken contracts.LinkToken, coordinator contracts.VRFCoordinatorV3, subscriptionID, linkFundingAmount *big.Int) { encodedSubId, err := chainlinkutils.ABIEncode(`[{"type":"uint256"}]`, subscriptionID) require.NoError(t, err, "Error Abi encoding subscriptionID") _, err = linkToken.TransferAndCall(coordinator.Address(), big.NewInt(0).Mul(linkFundingAmount, big.NewInt(1e18)), encodedSubId) @@ -310,7 +311,6 @@ func SetupOCR2VRFUniverse( t, linkToken, coordinatorContract, - chainClient, subID, ocr2vrf_constants.LinkFundingAmount, ) diff --git a/integration-tests/actions/vrf/common/actions.go b/integration-tests/actions/vrf/common/actions.go index 2151cd3094d..876cc918783 100644 --- a/integration-tests/actions/vrf/common/actions.go +++ b/integration-tests/actions/vrf/common/actions.go @@ -11,13 +11,14 @@ import ( "github.com/google/uuid" "github.com/rs/zerolog" + "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink-testing-framework/utils/conversions" actions_seth "github.com/smartcontractkit/chainlink/integration-tests/actions/seth" "github.com/smartcontractkit/chainlink/integration-tests/client" "github.com/smartcontractkit/chainlink/integration-tests/contracts" "github.com/smartcontractkit/chainlink/integration-tests/docker/test_env" vrf_common_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/common/vrf" - "github.com/smartcontractkit/seth" ) func CreateFundAndGetSendingKeys( @@ -313,7 +314,7 @@ func CreateVRFKeyOnVRFNode(vrfNode *VRFNode, l zerolog.Logger) (*client.VRFKey, return vrfKey, pubKeyCompressed, nil } -func FundNodesIfNeeded(ctx context.Context, existingEnvConfig *vrf_common_config.ExistingEnvConfig, client *seth.Client, l zerolog.Logger) error { +func FundNodesIfNeeded(existingEnvConfig *vrf_common_config.ExistingEnvConfig, client *seth.Client, l zerolog.Logger) error { if *existingEnvConfig.NodeSendingKeyFundingMin > 0 { for _, sendingKey := range existingEnvConfig.NodeSendingKeys { address := common.HexToAddress(sendingKey) diff --git a/integration-tests/actions/vrf/vrfv2/contract_steps.go b/integration-tests/actions/vrf/vrfv2/contract_steps.go index f6eef5f5e4e..385c73bcc8b 100644 --- a/integration-tests/actions/vrf/vrfv2/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2/contract_steps.go @@ -10,6 +10,8 @@ import ( "github.com/rs/zerolog" "github.com/shopspring/decimal" + "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink-testing-framework/utils/conversions" "github.com/smartcontractkit/chainlink/integration-tests/actions" vrfcommon "github.com/smartcontractkit/chainlink/integration-tests/actions/vrf/common" @@ -21,7 +23,6 @@ import ( chainlinkutils "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_owner" - "github.com/smartcontractkit/seth" ) func DeployVRFV2Contracts( @@ -48,9 +49,6 @@ func DeployVRFV2Contracts( if err != nil { return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrDeployCoordinator, err) } - if err != nil { - return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrWaitTXsComplete, err) - } coordinatorAddress = testCoordinator.Address() } else { coordinator, err := contracts.DeployVRFCoordinatorV2(sethClient, linkTokenContract.Address(), bhs.Address(), linkEthFeedContract.Address()) @@ -198,7 +196,7 @@ func SetupVRFV2Contracts( return vrfContracts, nil } -func setupVRFOwnerContract(env *test_env.CLClusterTestEnv, chainID int64, contracts *vrfcommon.VRFContracts, allNativeTokenKeyAddressStrings []string, allNativeTokenKeyAddresses []common.Address, l zerolog.Logger) error { +func setupVRFOwnerContract(contracts *vrfcommon.VRFContracts, allNativeTokenKeyAddressStrings []string, allNativeTokenKeyAddresses []common.Address, l zerolog.Logger) error { l.Info().Msg("Setting up VRFOwner contract") l.Info(). Str("Coordinator", contracts.CoordinatorV2.Address()). @@ -264,11 +262,11 @@ func CreateSubsAndFund( coordinator contracts.VRFCoordinatorV2, subAmountToCreate int, ) ([]uint64, error) { - subs, err := CreateSubs(env, chainID, coordinator, subAmountToCreate) + subs, err := CreateSubs(coordinator, subAmountToCreate) if err != nil { return nil, err } - err = FundSubscriptions(env, chainID, subscriptionFundingAmountLink, linkToken, coordinator, subs) + err = FundSubscriptions(env, subscriptionFundingAmountLink, linkToken, coordinator, subs) if err != nil { return nil, err } @@ -276,15 +274,13 @@ func CreateSubsAndFund( } func CreateSubs( - env *test_env.CLClusterTestEnv, - chainID int64, coordinator contracts.VRFCoordinatorV2, subAmountToCreate int, ) ([]uint64, error) { var subIDArr []uint64 for i := 0; i < subAmountToCreate; i++ { - subID, err := CreateSubAndFindSubID(env, chainID, coordinator) + subID, err := CreateSubAndFindSubID(coordinator) if err != nil { return nil, err } @@ -308,7 +304,7 @@ func AddConsumersToSubs( return nil } -func CreateSubAndFindSubID(env *test_env.CLClusterTestEnv, chainID int64, coordinator contracts.VRFCoordinatorV2) (uint64, error) { +func CreateSubAndFindSubID(coordinator contracts.VRFCoordinatorV2) (uint64, error) { receipt, err := coordinator.CreateSubscription() if err != nil { return 0, fmt.Errorf("%s, err %w", vrfcommon.ErrCreateVRFSubscription, err) @@ -321,7 +317,6 @@ func CreateSubAndFindSubID(env *test_env.CLClusterTestEnv, chainID int64, coordi func FundSubscriptions( env *test_env.CLClusterTestEnv, - chainID int64, subscriptionFundingAmountLink *big.Float, linkAddress contracts.LinkToken, coordinator contracts.VRFCoordinatorV2, @@ -594,10 +589,10 @@ func WaitRandomWordsFulfilledEvent( return randomWordsFulfilledEvent, err } -func SetupVRFOwnerContractIfNeeded(useVRFOwner bool, env *test_env.CLClusterTestEnv, chainID int64, vrfContracts *vrfcommon.VRFContracts, vrfTXKeyAddressStrings []string, vrfTXKeyAddresses []common.Address, l zerolog.Logger) (*vrfcommon.VRFOwnerConfig, error) { +func SetupVRFOwnerContractIfNeeded(useVRFOwner bool, chainID int64, vrfContracts *vrfcommon.VRFContracts, vrfTXKeyAddressStrings []string, vrfTXKeyAddresses []common.Address, l zerolog.Logger) (*vrfcommon.VRFOwnerConfig, error) { var vrfOwnerConfig *vrfcommon.VRFOwnerConfig if useVRFOwner { - err := setupVRFOwnerContract(env, chainID, vrfContracts, vrfTXKeyAddressStrings, vrfTXKeyAddresses, l) + err := setupVRFOwnerContract(vrfContracts, vrfTXKeyAddressStrings, vrfTXKeyAddresses, l) if err != nil { return nil, err } diff --git a/integration-tests/actions/vrf/vrfv2/setup_steps.go b/integration-tests/actions/vrf/vrfv2/setup_steps.go index aee2d313eb5..a637a1bad33 100644 --- a/integration-tests/actions/vrf/vrfv2/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2/setup_steps.go @@ -63,10 +63,6 @@ func CreateVRFV2Job( spec.UseVRFOwner = true } - if err != nil { - return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrParseJob, err) - - } job, err := chainlinkNode.MustCreateJob(spec) if err != nil { return nil, fmt.Errorf("%s, err %w", ErrCreatingVRFv2Job, err) @@ -143,7 +139,7 @@ func SetupVRFV2Environment( nodeTypeToNodeMap[vrfcommon.VRF].TXKeyAddressStrings = vrfTXKeyAddressStrings - vrfOwnerConfig, err := SetupVRFOwnerContractIfNeeded(useVRFOwner, env, chainID, vrfContracts, vrfTXKeyAddressStrings, vrfTXKeyAddresses, l) + vrfOwnerConfig, err := SetupVRFOwnerContractIfNeeded(useVRFOwner, chainID, vrfContracts, vrfTXKeyAddressStrings, vrfTXKeyAddresses, l) if err != nil { return nil, nil, nil, err } @@ -239,7 +235,6 @@ func setupVRFNode(contracts *vrfcommon.VRFContracts, chainID *big.Int, vrfv2Conf func SetupVRFV2WrapperEnvironment( ctx context.Context, env *test_env.CLClusterTestEnv, - chainID int64, vrfv2TestConfig tc.VRFv2TestConfig, linkToken contracts.LinkToken, mockNativeLINKFeed contracts.VRFMockETHLINKFeed, @@ -285,7 +280,7 @@ func SetupVRFV2WrapperEnvironment( } // Fund wrapper subscription - err = FundSubscriptions(env, chainID, big.NewFloat(*vrfv2Config.General.SubscriptionFundingAmountLink), linkToken, coordinator, []uint64{wrapperSubID}) + err = FundSubscriptions(env, big.NewFloat(*vrfv2Config.General.SubscriptionFundingAmountLink), linkToken, coordinator, []uint64{wrapperSubID}) if err != nil { return nil, nil, err } @@ -311,7 +306,7 @@ func SetupVRFV2Universe(ctx context.Context, t *testing.T, testConfig tc.TestCon err error ) if *testConfig.VRFv2.General.UseExistingEnv { - vrfContracts, vrfKey, env, err = SetupVRFV2ForExistingEnv(ctx, t, testConfig, chainID, cleanupFn, l) + vrfContracts, vrfKey, env, err = SetupVRFV2ForExistingEnv(t, testConfig, chainID, cleanupFn, l) if err != nil { return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "Error setting up VRF V2 for Existing env", err) } @@ -387,7 +382,7 @@ func SetupVRFV2ForNewEnv( return vrfContracts, vrfKey, env, nodeTypeToNode, nil } -func SetupVRFV2ForExistingEnv(ctx context.Context, t *testing.T, testConfig tc.TestConfig, chainID int64, cleanupFn func(), l zerolog.Logger) (*vrfcommon.VRFContracts, *vrfcommon.VRFKeyData, *test_env.CLClusterTestEnv, error) { +func SetupVRFV2ForExistingEnv(t *testing.T, testConfig tc.TestConfig, chainID int64, cleanupFn func(), l zerolog.Logger) (*vrfcommon.VRFContracts, *vrfcommon.VRFKeyData, *test_env.CLClusterTestEnv, error) { commonExistingEnvConfig := testConfig.VRFv2.ExistingEnvConfig.ExistingEnvConfig env, err := test_env.NewCLTestEnvBuilder(). WithTestInstance(t). @@ -416,7 +411,7 @@ func SetupVRFV2ForExistingEnv(ctx context.Context, t *testing.T, testConfig tc.T return nil, nil, nil, err } - err = vrfcommon.FundNodesIfNeeded(ctx, commonExistingEnvConfig, sethClient, l) + err = vrfcommon.FundNodesIfNeeded(commonExistingEnvConfig, sethClient, l) if err != nil { return nil, nil, nil, fmt.Errorf("err: %w", err) } diff --git a/integration-tests/actions/vrf/vrfv2plus/contract_steps.go b/integration-tests/actions/vrf/vrfv2plus/contract_steps.go index 6536e5db637..473e9b96549 100644 --- a/integration-tests/actions/vrf/vrfv2plus/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/contract_steps.go @@ -10,6 +10,8 @@ import ( "github.com/rs/zerolog" "github.com/shopspring/decimal" + "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink-testing-framework/utils/conversions" "github.com/smartcontractkit/chainlink/integration-tests/actions" vrfcommon "github.com/smartcontractkit/chainlink/integration-tests/actions/vrf/common" @@ -19,11 +21,9 @@ import ( tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig" vrfv2plus_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/vrfv2plus" chainlinkutils "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" - "github.com/smartcontractkit/seth" ) func DeployVRFV2_5Contracts( - contractDeployer contracts.ContractDeployer, chainClient *seth.Client, ) (*vrfcommon.VRFContracts, error) { bhs, err := contracts.DeployBlockhashStore(chainClient) @@ -526,7 +526,7 @@ func SetupVRFV2PlusContracts( if err != nil { return nil, err } - vrfContracts, err := DeployVRFV2_5Contracts(env.ContractDeployer, sethClient) + vrfContracts, err := DeployVRFV2_5Contracts(sethClient) if err != nil { return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, ErrDeployVRFV2_5Contracts, err) } diff --git a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go index 0365aeb09c3..1673c3eca93 100644 --- a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go @@ -341,7 +341,7 @@ func SetupVRFV2PlusUniverse(ctx context.Context, t *testing.T, testConfig tc.Tes err error ) if *testConfig.VRFv2Plus.General.UseExistingEnv { - vrfContracts, vrfKey, env, err = SetupVRFV2PlusForExistingEnv(ctx, t, testConfig, chainID, cleanupFn, l) + vrfContracts, vrfKey, env, err = SetupVRFV2PlusForExistingEnv(t, testConfig, chainID, cleanupFn, l) if err != nil { return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "Error setting up VRF V2 Plus for Existing env", err) } @@ -411,7 +411,7 @@ func SetupVRFV2PlusForNewEnv( return vrfContracts, vrfKey, env, nodeTypeToNode, nil } -func SetupVRFV2PlusForExistingEnv(ctx context.Context, t *testing.T, testConfig tc.TestConfig, chainID int64, cleanupFn func(), l zerolog.Logger) (*vrfcommon.VRFContracts, *vrfcommon.VRFKeyData, *test_env.CLClusterTestEnv, error) { +func SetupVRFV2PlusForExistingEnv(t *testing.T, testConfig tc.TestConfig, chainID int64, cleanupFn func(), l zerolog.Logger) (*vrfcommon.VRFContracts, *vrfcommon.VRFKeyData, *test_env.CLClusterTestEnv, error) { commonExistingEnvConfig := testConfig.VRFv2Plus.ExistingEnvConfig.ExistingEnvConfig env, err := test_env.NewCLTestEnvBuilder(). WithTestInstance(t). @@ -436,7 +436,7 @@ func SetupVRFV2PlusForExistingEnv(ctx context.Context, t *testing.T, testConfig return nil, nil, nil, fmt.Errorf("%s, err: %w", "error loading LinkToken", err) } - err = vrfcommon.FundNodesIfNeeded(ctx, commonExistingEnvConfig, sethClient, l) + err = vrfcommon.FundNodesIfNeeded(commonExistingEnvConfig, sethClient, l) if err != nil { return nil, nil, nil, fmt.Errorf("err: %w", err) } diff --git a/integration-tests/contracts/contract_loader.go b/integration-tests/contracts/contract_loader.go index dd72e40e6cc..5609b01ad6f 100644 --- a/integration-tests/contracts/contract_loader.go +++ b/integration-tests/contracts/contract_loader.go @@ -4,9 +4,10 @@ import ( "errors" "fmt" + "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2_5" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_v2plus_load_test_with_metrics" - "github.com/smartcontractkit/seth" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" diff --git a/integration-tests/contracts/contract_vrf_models.go b/integration-tests/contracts/contract_vrf_models.go index 50f4ef8f811..1798910d4d8 100644 --- a/integration-tests/contracts/contract_vrf_models.go +++ b/integration-tests/contracts/contract_vrf_models.go @@ -63,11 +63,11 @@ type VRFCoordinatorV2 interface { GetSubscription(ctx context.Context, subID uint64) (Subscription, error) GetOwner(ctx context.Context) (common.Address, error) PendingRequestsExist(ctx context.Context, subID uint64) (bool, error) - OwnerCancelSubscription(subID uint64) (*types.Receipt, error) + OwnerCancelSubscription(subID uint64) (*types.Transaction, error) ParseSubscriptionCanceled(log types.Log) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) ParseRandomWordsRequested(log types.Log) (*CoordinatorRandomWordsRequested, error) ParseLog(log types.Log) (generated.AbigenLog, error) - CancelSubscription(subID uint64, to common.Address) (*types.Receipt, error) + CancelSubscription(subID uint64, to common.Address) (*types.Transaction, error) FindSubscriptionID(subID uint64) (uint64, error) WaitForRandomWordsFulfilledEvent(filter RandomWordsFulfilledEventFilter) (*CoordinatorRandomWordsFulfilled, error) WaitForRandomWordsRequestedEvent(keyHash [][32]byte, subID []uint64, sender []common.Address, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2RandomWordsRequested, error) @@ -110,8 +110,8 @@ type VRFCoordinatorV2_5 interface { Address() string PendingRequestsExist(ctx context.Context, subID *big.Int) (bool, error) GetSubscription(ctx context.Context, subID *big.Int) (Subscription, error) - OwnerCancelSubscription(subID *big.Int) (*types.Receipt, error) - CancelSubscription(subID *big.Int, to common.Address) (*types.Receipt, error) + OwnerCancelSubscription(subID *big.Int) (*types.Transaction, error) + CancelSubscription(subID *big.Int, to common.Address) (*types.Transaction, error) Withdraw(recipient common.Address) error WithdrawNative(recipient common.Address) error GetNativeTokenTotalBalance(ctx context.Context) (*big.Int, error) @@ -193,7 +193,7 @@ type VRFOwner interface { SetAuthorizedSenders(senders []common.Address) error AcceptVRFOwnership() error WaitForRandomWordsForcedEvent(requestIDs []*big.Int, subIds []uint64, senders []common.Address, timeout time.Duration) (*vrf_owner.VRFOwnerRandomWordsForced, error) - OwnerCancelSubscription(subID uint64) (*types.Receipt, error) + OwnerCancelSubscription(subID uint64) (*types.Transaction, error) } type VRFConsumer interface { diff --git a/integration-tests/contracts/ethereum_contracts.go b/integration-tests/contracts/ethereum_contracts.go index d2b7a407a9c..cc909a0a75a 100644 --- a/integration-tests/contracts/ethereum_contracts.go +++ b/integration-tests/contracts/ethereum_contracts.go @@ -1350,9 +1350,6 @@ func (o *LegacyEthereumOffchainAggregator) SetConfig( return fmt.Errorf("no OCR keys found for node %v", node) } primaryOCRKey := ocrKeys.Data[0] - if err != nil { - return err - } p2pKeys, err := node.MustReadP2PKeys() if err != nil { return err diff --git a/integration-tests/contracts/ethereum_contracts_seth.go b/integration-tests/contracts/ethereum_contracts_seth.go index beab47b8e26..97201c47bdf 100644 --- a/integration-tests/contracts/ethereum_contracts_seth.go +++ b/integration-tests/contracts/ethereum_contracts_seth.go @@ -143,9 +143,6 @@ func (o *EthereumOffchainAggregator) SetConfig( return fmt.Errorf("no OCR keys found for node %v", node) } primaryOCRKey := ocrKeys.Data[0] - if err != nil { - return err - } p2pKeys, err := node.MustReadP2PKeys() if err != nil { return err diff --git a/integration-tests/contracts/ethereum_ocr2vrf_contracts.go b/integration-tests/contracts/ethereum_ocr2vrf_contracts.go index bcc73ed01e1..32bd7c14a95 100644 --- a/integration-tests/contracts/ethereum_ocr2vrf_contracts.go +++ b/integration-tests/contracts/ethereum_ocr2vrf_contracts.go @@ -12,13 +12,14 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/rs/zerolog/log" + "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink/integration-tests/wrappers" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/batch_blockhash_store" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ocr2vrf/generated/dkg" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ocr2vrf/generated/vrf_beacon" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ocr2vrf/generated/vrf_beacon_consumer" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ocr2vrf/generated/vrf_coordinator" - "github.com/smartcontractkit/seth" ) // EthereumDKG represents DKG contract diff --git a/integration-tests/contracts/ethereum_vrf_contracts.go b/integration-tests/contracts/ethereum_vrf_contracts.go index 8aeb247455c..d30732c5602 100644 --- a/integration-tests/contracts/ethereum_vrf_contracts.go +++ b/integration-tests/contracts/ethereum_vrf_contracts.go @@ -12,13 +12,14 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/rs/zerolog/log" + "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink/integration-tests/wrappers" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/batch_blockhash_store" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/blockhash_store" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_consumer_interface" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_wrapper" - "github.com/smartcontractkit/seth" ) // EthereumBatchBlockhashStore represents BatchBlockhashStore contract diff --git a/integration-tests/contracts/ethereum_vrfv2_contracts.go b/integration-tests/contracts/ethereum_vrfv2_contracts.go index 54da02e196c..2e20d67da4b 100644 --- a/integration-tests/contracts/ethereum_vrfv2_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2_contracts.go @@ -13,11 +13,12 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/rs/zerolog/log" + "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink/integration-tests/wrappers" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_mock_ethlink_aggregator" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_owner" - "github.com/smartcontractkit/seth" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_consumer_v2" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2" @@ -489,12 +490,12 @@ func (v *EthereumVRFCoordinatorV2) OracleWithdraw(recipient common.Address, amou // return funds to the subscription owner, // down not check if pending requests for a sub exist, // outstanding requests may fail onchain -func (v *EthereumVRFCoordinatorV2) OwnerCancelSubscription(subID uint64) (*types.Receipt, error) { - tx, err := v.client.Decode(v.coordinator.OwnerCancelSubscription( +func (v *EthereumVRFCoordinatorV2) OwnerCancelSubscription(subID uint64) (*types.Transaction, error) { + // Do not wrap in Decode() to avoid waiting until the transaction is mined + return v.coordinator.OwnerCancelSubscription( v.client.NewTXOpts(), subID, - )) - return tx.Receipt, err + ) } func (v *EthereumVRFCoordinatorV2) ParseSubscriptionCanceled(log types.Log) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) { @@ -528,13 +529,13 @@ func (v *EthereumVRFCoordinatorV2) ParseLog(log types.Log) (generated.AbigenLog, // CancelSubscription cancels subscription by Sub owner, // return funds to specified address, // checks if pending requests for a sub exist -func (v *EthereumVRFCoordinatorV2) CancelSubscription(subID uint64, to common.Address) (*types.Receipt, error) { - tx, err := v.client.Decode(v.coordinator.CancelSubscription( +func (v *EthereumVRFCoordinatorV2) CancelSubscription(subID uint64, to common.Address) (*types.Transaction, error) { + // Do not wrap in Decode() to avoid waiting until the transaction is mined. + return v.coordinator.CancelSubscription( v.client.NewTXOpts(), subID, to, - )) - return tx.Receipt, err + ) } func (v *EthereumVRFCoordinatorV2) FindSubscriptionID(subID uint64) (uint64, error) { @@ -1149,12 +1150,12 @@ func (v *EthereumVRFOwner) WaitForRandomWordsForcedEvent(requestIDs []*big.Int, } } -func (v *EthereumVRFOwner) OwnerCancelSubscription(subID uint64) (*types.Receipt, error) { - tx, err := v.client.Decode(v.vrfOwner.OwnerCancelSubscription( +func (v *EthereumVRFOwner) OwnerCancelSubscription(subID uint64) (*types.Transaction, error) { + // Do not wrap in Decode() to avoid waiting until the transaction is mined + return v.vrfOwner.OwnerCancelSubscription( v.client.NewTXOpts(), subID, - )) - return tx.Receipt, err + ) } func (v *EthereumVRFMockETHLINKFeed) Address() string { diff --git a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go index 25fca374e19..8c9d07696c6 100644 --- a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go @@ -11,13 +11,14 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/montanaflynn/stats" + "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink/integration-tests/wrappers" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2_5" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_v2plus_load_test_with_metrics" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_v2plus_upgraded_version" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrfv2plus_wrapper" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrfv2plus_wrapper_load_test_consumer" - "github.com/smartcontractkit/seth" ) type EthereumVRFCoordinatorV2_5 struct { @@ -234,30 +235,24 @@ func (v *EthereumVRFCoordinatorV2_5) GetNativeTokenTotalBalance(ctx context.Cont // OwnerCancelSubscription cancels subscription by Coordinator owner // return funds to sub owner, // does not check if pending requests for a sub exist -func (v *EthereumVRFCoordinatorV2_5) OwnerCancelSubscription(subID *big.Int) (*types.Receipt, error) { - tx, err := v.client.Decode(v.coordinator.OwnerCancelSubscription( +func (v *EthereumVRFCoordinatorV2_5) OwnerCancelSubscription(subID *big.Int) (*types.Transaction, error) { + // Do not wrap in Decode() to avoid waiting until the transaction is mined + return v.coordinator.OwnerCancelSubscription( v.client.NewTXOpts(), subID, - )) - if err != nil { - return nil, err - } - return tx.Receipt, nil + ) } // CancelSubscription cancels subscription by Sub owner, // return funds to specified address, // checks if pending requests for a sub exist -func (v *EthereumVRFCoordinatorV2_5) CancelSubscription(subID *big.Int, to common.Address) (*types.Receipt, error) { - tx, err := v.client.Decode(v.coordinator.CancelSubscription( +func (v *EthereumVRFCoordinatorV2_5) CancelSubscription(subID *big.Int, to common.Address) (*types.Transaction, error) { + // Do not wrap in Decode() to avoid waiting until the transaction is mined + return v.coordinator.CancelSubscription( v.client.NewTXOpts(), subID, to, - )) - if err != nil { - return nil, err - } - return tx.Receipt, nil + ) } func (v *EthereumVRFCoordinatorV2_5) Withdraw(recipient common.Address) error { diff --git a/integration-tests/smoke/vrfv2_test.go b/integration-tests/smoke/vrfv2_test.go index 6cecd20408a..a4baf7ab647 100644 --- a/integration-tests/smoke/vrfv2_test.go +++ b/integration-tests/smoke/vrfv2_test.go @@ -231,7 +231,6 @@ func TestVRFv2Basic(t *testing.T) { wrapperContracts, wrapperSubID, err := vrfv2.SetupVRFV2WrapperEnvironment( testcontext.Get(t), testEnv, - chainID, &configCopy, vrfContracts.LinkToken, vrfContracts.MockETHLINKFeed, @@ -401,12 +400,15 @@ func TestVRFv2Basic(t *testing.T) { Str("Returning funds to", testWalletAddress.String()). Msg("Canceling subscription and returning funds to subscription owner") - cancellationTxReceipt, err := vrfContracts.CoordinatorV2.CancelSubscription(subIDForCancelling, testWalletAddress) + tx, err := vrfContracts.CoordinatorV2.CancelSubscription(subIDForCancelling, testWalletAddress) require.NoError(t, err, "Error canceling subscription") subscriptionCanceledEvent, err := vrfContracts.CoordinatorV2.WaitForSubscriptionCanceledEvent([]uint64{subIDForCancelling}, time.Second*30) require.NoError(t, err, "error waiting for subscription canceled event") + cancellationTxReceipt, err := sethClient.Client.TransactionReceipt(testcontext.Get(t), tx.Hash()) + require.NoError(t, err, "error getting tx cancellation Tx Receipt") + txGasUsed := new(big.Int).SetUint64(cancellationTxReceipt.GasUsed) // we don't have that information for older Geth versions if cancellationTxReceipt.EffectiveGasPrice == nil { @@ -509,12 +511,14 @@ func TestVRFv2Basic(t *testing.T) { Msg("Canceling subscription and returning funds to subscription owner") // Call OwnerCancelSubscription - cancellationTxReceipt, err := vrfContracts.CoordinatorV2.OwnerCancelSubscription(subIDForOwnerCancelling) + tx, err := vrfContracts.CoordinatorV2.OwnerCancelSubscription(subIDForOwnerCancelling) require.NoError(t, err, "Error canceling subscription") subscriptionCanceledEvent, err := vrfContracts.CoordinatorV2.WaitForSubscriptionCanceledEvent([]uint64{subIDForOwnerCancelling}, time.Second*30) require.NoError(t, err, "error waiting for subscription canceled event") + cancellationTxReceipt, err := sethClient.Client.TransactionReceipt(testcontext.Get(t), tx.Hash()) + require.NoError(t, err, "error getting tx cancellation Tx Receipt") txGasUsed := new(big.Int).SetUint64(cancellationTxReceipt.GasUsed) // we don't have that information for older Geth versions if cancellationTxReceipt.EffectiveGasPrice == nil { @@ -898,7 +902,7 @@ func TestVRFV2WithBHS(t *testing.T) { _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(257), sethClient, &wg, time.Second*260, t) wg.Wait() require.NoError(t, err) - err = vrfv2.FundSubscriptions(testEnv, chainID, big.NewFloat(*configCopy.VRFv2.General.SubscriptionFundingAmountLink), vrfContracts.LinkToken, vrfContracts.CoordinatorV2, subIDsForBHS) + err = vrfv2.FundSubscriptions(testEnv, big.NewFloat(*configCopy.VRFv2.General.SubscriptionFundingAmountLink), vrfContracts.LinkToken, vrfContracts.CoordinatorV2, subIDsForBHS) require.NoError(t, err, "error funding subscriptions") randomWordsFulfilledEvent, err := vrfContracts.CoordinatorV2.WaitForRandomWordsFulfilledEvent( contracts.RandomWordsFulfilledEventFilter{ diff --git a/integration-tests/smoke/vrfv2plus_test.go b/integration-tests/smoke/vrfv2plus_test.go index 4f229edd32b..dc0d01b2e3e 100644 --- a/integration-tests/smoke/vrfv2plus_test.go +++ b/integration-tests/smoke/vrfv2plus_test.go @@ -429,12 +429,14 @@ func TestVRFv2Plus(t *testing.T) { Str("Returning funds from SubID", subID.String()). Str("Returning funds to", testWalletAddress.String()). Msg("Canceling subscription and returning funds to subscription owner") - cancellationTxReceipt, err := vrfContracts.CoordinatorV2Plus.CancelSubscription(subID, testWalletAddress) + tx, err := vrfContracts.CoordinatorV2Plus.CancelSubscription(subID, testWalletAddress) require.NoError(t, err, "Error canceling subscription") subscriptionCanceledEvent, err := vrfContracts.CoordinatorV2Plus.WaitForSubscriptionCanceledEvent(subID, time.Second*30) require.NoError(t, err, "error waiting for subscription canceled event") + cancellationTxReceipt, err := sethClient.Client.TransactionReceipt(testcontext.Get(t), tx.Hash()) + require.NoError(t, err, "error getting tx cancellation Tx Receipt") txGasUsed := new(big.Int).SetUint64(cancellationTxReceipt.GasUsed) // we don't have that information for older Geth versions if cancellationTxReceipt.EffectiveGasPrice == nil { @@ -568,12 +570,14 @@ func TestVRFv2Plus(t *testing.T) { Str("Returning funds from SubID", subID.String()). Str("Returning funds to", sethClient.Addresses[0].Hex()). Msg("Canceling subscription and returning funds to subscription owner") - cancellationTxReceipt, err := vrfContracts.CoordinatorV2Plus.OwnerCancelSubscription(subID) + tx, err := vrfContracts.CoordinatorV2Plus.OwnerCancelSubscription(subID) require.NoError(t, err, "Error canceling subscription") subscriptionCanceledEvent, err := vrfContracts.CoordinatorV2Plus.WaitForSubscriptionCanceledEvent(subID, time.Second*30) require.NoError(t, err, "error waiting for subscription canceled event") + cancellationTxReceipt, err := sethClient.Client.TransactionReceipt(testcontext.Get(t), tx.Hash()) + require.NoError(t, err, "error getting tx cancellation Tx Receipt") txGasUsed := new(big.Int).SetUint64(cancellationTxReceipt.GasUsed) // we don't have that information for older Geth versions if cancellationTxReceipt.EffectiveGasPrice == nil { From cc13fa28289dfe4f4e650b51238f0f112113ff77 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Thu, 25 Apr 2024 15:05:26 +0200 Subject: [PATCH 15/43] fix lint --- integration-tests/actions/seth/actions.go | 2 +- .../actions/vrf/vrfv2/contract_steps.go | 13 ++---- .../actions/vrf/vrfv2/setup_steps.go | 4 +- .../contracts/contract_deployer.go | 40 +++++++++---------- .../contracts/ethereum_vrf_contracts.go | 6 +-- .../contracts/ethereum_vrfv2_contracts.go | 4 +- .../contracts/ethereum_vrfv2plus_contracts.go | 2 +- integration-tests/load/vrfv2/vrfv2_test.go | 2 - integration-tests/smoke/vrfv2_test.go | 2 +- 9 files changed, 33 insertions(+), 42 deletions(-) diff --git a/integration-tests/actions/seth/actions.go b/integration-tests/actions/seth/actions.go index 242aa13b1e9..987f05af183 100644 --- a/integration-tests/actions/seth/actions.go +++ b/integration-tests/actions/seth/actions.go @@ -886,7 +886,7 @@ func SendLinkFundsToDeploymentAddresses( return nil } -var noOpSethConfigFn = func(cfg *seth.Config) error { return nil } +var noOpSethConfigFn = func(_ *seth.Config) error { return nil } type SethConfigFunction = func(*seth.Config) error diff --git a/integration-tests/actions/vrf/vrfv2/contract_steps.go b/integration-tests/actions/vrf/vrfv2/contract_steps.go index 385c73bcc8b..40c2c6346aa 100644 --- a/integration-tests/actions/vrf/vrfv2/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2/contract_steps.go @@ -225,15 +225,13 @@ func setupVRFOwnerContract(contracts *vrfcommon.VRFContracts, allNativeTokenKeyA } func CreateFundSubsAndAddConsumers( - env *test_env.CLClusterTestEnv, - chainID int64, subscriptionFundingAmountLink *big.Float, linkToken contracts.LinkToken, coordinator contracts.VRFCoordinatorV2, consumers []contracts.VRFv2LoadTestConsumer, numberOfSubToCreate int, ) ([]uint64, error) { - subIDs, err := CreateSubsAndFund(env, chainID, subscriptionFundingAmountLink, linkToken, coordinator, numberOfSubToCreate) + subIDs, err := CreateSubsAndFund(subscriptionFundingAmountLink, linkToken, coordinator, numberOfSubToCreate) if err != nil { return nil, err } @@ -255,8 +253,6 @@ func CreateFundSubsAndAddConsumers( } func CreateSubsAndFund( - env *test_env.CLClusterTestEnv, - chainID int64, subscriptionFundingAmountLink *big.Float, linkToken contracts.LinkToken, coordinator contracts.VRFCoordinatorV2, @@ -266,7 +262,7 @@ func CreateSubsAndFund( if err != nil { return nil, err } - err = FundSubscriptions(env, subscriptionFundingAmountLink, linkToken, coordinator, subs) + err = FundSubscriptions(subscriptionFundingAmountLink, linkToken, coordinator, subs) if err != nil { return nil, err } @@ -316,7 +312,6 @@ func CreateSubAndFindSubID(coordinator contracts.VRFCoordinatorV2) (uint64, erro } func FundSubscriptions( - env *test_env.CLClusterTestEnv, subscriptionFundingAmountLink *big.Float, linkAddress contracts.LinkToken, coordinator contracts.VRFCoordinatorV2, @@ -589,7 +584,7 @@ func WaitRandomWordsFulfilledEvent( return randomWordsFulfilledEvent, err } -func SetupVRFOwnerContractIfNeeded(useVRFOwner bool, chainID int64, vrfContracts *vrfcommon.VRFContracts, vrfTXKeyAddressStrings []string, vrfTXKeyAddresses []common.Address, l zerolog.Logger) (*vrfcommon.VRFOwnerConfig, error) { +func SetupVRFOwnerContractIfNeeded(useVRFOwner bool, vrfContracts *vrfcommon.VRFContracts, vrfTXKeyAddressStrings []string, vrfTXKeyAddresses []common.Address, l zerolog.Logger) (*vrfcommon.VRFOwnerConfig, error) { var vrfOwnerConfig *vrfcommon.VRFOwnerConfig if useVRFOwner { err := setupVRFOwnerContract(vrfContracts, vrfTXKeyAddressStrings, vrfTXKeyAddresses, l) @@ -632,8 +627,6 @@ func SetupNewConsumersAndSubs( Int("Number of Subs to create", numberOfSubToCreate). Msg("Creating and funding subscriptions, deploying and adding consumers to subs") subIDs, err := CreateFundSubsAndAddConsumers( - env, - chainID, big.NewFloat(*testConfig.VRFv2.General.SubscriptionFundingAmountLink), linkToken, coordinator, diff --git a/integration-tests/actions/vrf/vrfv2/setup_steps.go b/integration-tests/actions/vrf/vrfv2/setup_steps.go index a637a1bad33..52b9aba3689 100644 --- a/integration-tests/actions/vrf/vrfv2/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2/setup_steps.go @@ -139,7 +139,7 @@ func SetupVRFV2Environment( nodeTypeToNodeMap[vrfcommon.VRF].TXKeyAddressStrings = vrfTXKeyAddressStrings - vrfOwnerConfig, err := SetupVRFOwnerContractIfNeeded(useVRFOwner, chainID, vrfContracts, vrfTXKeyAddressStrings, vrfTXKeyAddresses, l) + vrfOwnerConfig, err := SetupVRFOwnerContractIfNeeded(useVRFOwner, vrfContracts, vrfTXKeyAddressStrings, vrfTXKeyAddresses, l) if err != nil { return nil, nil, nil, err } @@ -280,7 +280,7 @@ func SetupVRFV2WrapperEnvironment( } // Fund wrapper subscription - err = FundSubscriptions(env, big.NewFloat(*vrfv2Config.General.SubscriptionFundingAmountLink), linkToken, coordinator, []uint64{wrapperSubID}) + err = FundSubscriptions(big.NewFloat(*vrfv2Config.General.SubscriptionFundingAmountLink), linkToken, coordinator, []uint64{wrapperSubID}) if err != nil { return nil, nil, err } diff --git a/integration-tests/contracts/contract_deployer.go b/integration-tests/contracts/contract_deployer.go index 9551429a4d1..41a135001a5 100644 --- a/integration-tests/contracts/contract_deployer.go +++ b/integration-tests/contracts/contract_deployer.go @@ -508,7 +508,7 @@ func (e *EthereumContractDeployer) DeployOffchainAggregatorEventsMock() (Offchai func (e *EthereumContractDeployer) DeployLinkTokenContract() (LinkToken, error) { linkTokenAddress, _, instance, err := e.client.DeployContract("LINK Token", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return link_token_interface.DeployLinkToken(auth, wrappers.MustNewWrappedContractBackend(e.client, nil)) }) @@ -684,7 +684,7 @@ func (e *EthereumContractDeployer) DeployOracle(linkAddr string) (Oracle, error) func (e *EthereumContractDeployer) DeployMockETHLINKFeed(answer *big.Int) (MockETHLINKFeed, error) { address, _, instance, err := e.client.DeployContract("MockETHLINKAggregator", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return mock_ethlink_aggregator_wrapper.DeployMockETHLINKAggregator(auth, wrappers.MustNewWrappedContractBackend(e.client, nil), answer) }) @@ -719,7 +719,7 @@ func (e *EthereumContractDeployer) LoadETHLINKFeed(address common.Address) (Mock func (e *EthereumContractDeployer) DeployMockGasFeed(answer *big.Int) (MockGasFeed, error) { address, _, instance, err := e.client.DeployContract("MockGasFeed", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return mock_gas_aggregator_wrapper.DeployMockGASAggregator(auth, wrappers.MustNewWrappedContractBackend(e.client, nil), answer) }) @@ -754,7 +754,7 @@ func (e *EthereumContractDeployer) LoadGasFeed(address common.Address) (MockGasF func (e *EthereumContractDeployer) DeployUpkeepTranscoder() (UpkeepTranscoder, error) { address, _, instance, err := e.client.DeployContract("UpkeepTranscoder", func( opts *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return upkeep_transcoder.DeployUpkeepTranscoder(opts, wrappers.MustNewWrappedContractBackend(e.client, nil)) }) @@ -796,7 +796,7 @@ func (e *EthereumContractDeployer) DeployKeeperRegistrar(registryVersion eth_con // deploy registrar 2.0 address, _, instance, err := e.client.DeployContract("KeeperRegistrar", func( opts *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return keeper_registrar_wrapper2_0.DeployKeeperRegistrar(opts, wrappers.MustNewWrappedContractBackend(e.client, nil), common.HexToAddress(linkAddr), registrarSettings.AutoApproveConfigType, registrarSettings.AutoApproveMaxAllowed, common.HexToAddress(registrarSettings.RegistryAddr), registrarSettings.MinLinkJuels) @@ -815,7 +815,7 @@ func (e *EthereumContractDeployer) DeployKeeperRegistrar(registryVersion eth_con // deploy registrar 2.1 address, _, instance, err := e.client.DeployContract("AutomationRegistrar", func( opts *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { // set default TriggerType to 0(conditional), AutoApproveConfigType to 2(auto approve enabled), AutoApproveMaxAllowed to 1000 triggerConfigs := []registrar21.AutomationRegistrar21InitialTriggerConfig{ @@ -936,7 +936,7 @@ func (e *EthereumContractDeployer) DeployKeeperRegistry( case eth_contracts.RegistryVersion_1_0, eth_contracts.RegistryVersion_1_1: address, _, instance, err := e.client.DeployContract("KeeperRegistry1_1", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return keeper_registry_wrapper1_1.DeployKeeperRegistry( auth, @@ -968,7 +968,7 @@ func (e *EthereumContractDeployer) DeployKeeperRegistry( case eth_contracts.RegistryVersion_1_2: address, _, instance, err := e.client.DeployContract("KeeperRegistry1_2", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return keeper_registry_wrapper1_2.DeployKeeperRegistry( auth, @@ -1006,7 +1006,7 @@ func (e *EthereumContractDeployer) DeployKeeperRegistry( case eth_contracts.RegistryVersion_1_3: logicAddress, _, _, err := e.client.DeployContract("KeeperRegistryLogic1_3", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return keeper_registry_logic1_3.DeployKeeperRegistryLogic( auth, @@ -1028,7 +1028,7 @@ func (e *EthereumContractDeployer) DeployKeeperRegistry( address, _, instance, err := e.client.DeployContract("KeeperRegistry1_3", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return keeper_registry_wrapper1_3.DeployKeeperRegistry( auth, @@ -1064,7 +1064,7 @@ func (e *EthereumContractDeployer) DeployKeeperRegistry( case eth_contracts.RegistryVersion_2_0: logicAddress, _, _, err := e.client.DeployContract("KeeperRegistryLogic2_0", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return keeper_registry_logic2_0.DeployKeeperRegistryLogic( auth, @@ -1085,7 +1085,7 @@ func (e *EthereumContractDeployer) DeployKeeperRegistry( address, _, instance, err := e.client.DeployContract("KeeperRegistry2_0", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return keeper_registry_wrapper2_0.DeployKeeperRegistry( @@ -1112,7 +1112,7 @@ func (e *EthereumContractDeployer) DeployKeeperRegistry( registryLogicBAddr, _, _, err := e.client.DeployContract("KeeperRegistryLogicB2_1", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return registrylogicb21.DeployKeeperRegistryLogicB( @@ -1135,7 +1135,7 @@ func (e *EthereumContractDeployer) DeployKeeperRegistry( registryLogicAAddr, _, _, err := e.client.DeployContract("KeeperRegistryLogicA2_1", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return registrylogica21.DeployKeeperRegistryLogicA( @@ -1153,7 +1153,7 @@ func (e *EthereumContractDeployer) DeployKeeperRegistry( address, _, _, err := e.client.DeployContract("KeeperRegistry2_1", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return registry21.DeployKeeperRegistry( auth, @@ -1189,28 +1189,28 @@ func (e *EthereumContractDeployer) DeployKeeperRegistry( if chainId == networks.ScrollMainnet.ChainID || chainId == networks.ScrollSepolia.ChainID { chainModuleAddr, _, _, err = e.client.DeployContract("ScrollModule", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return scroll_module.DeployScrollModule(auth, wrappers.MustNewWrappedContractBackend(e.client, nil)) }) } else if chainId == networks.ArbitrumMainnet.ChainID || chainId == networks.ArbitrumSepolia.ChainID { chainModuleAddr, _, _, err = e.client.DeployContract("ArbitrumModule", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return arbitrum_module.DeployArbitrumModule(auth, wrappers.MustNewWrappedContractBackend(e.client, nil)) }) } else if chainId == networks.OptimismMainnet.ChainID || chainId == networks.OptimismSepolia.ChainID { chainModuleAddr, _, _, err = e.client.DeployContract("OptimismModule", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return optimism_module.DeployOptimismModule(auth, wrappers.MustNewWrappedContractBackend(e.client, nil)) }) } else { chainModuleAddr, _, _, err = e.client.DeployContract("ChainModuleBase", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return chain_module_base.DeployChainModuleBase(auth, wrappers.MustNewWrappedContractBackend(e.client, nil)) }) @@ -1235,7 +1235,7 @@ func (e *EthereumContractDeployer) DeployKeeperRegistry( } registryLogicBAddr, _, _, err := e.client.DeployContract("AutomationRegistryLogicB2_2", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return registrylogicb22.DeployAutomationRegistryLogicB( diff --git a/integration-tests/contracts/ethereum_vrf_contracts.go b/integration-tests/contracts/ethereum_vrf_contracts.go index d30732c5602..0c356c6f628 100644 --- a/integration-tests/contracts/ethereum_vrf_contracts.go +++ b/integration-tests/contracts/ethereum_vrf_contracts.go @@ -64,7 +64,7 @@ type LegacyEthereumVRF struct { func (e *EthereumContractDeployer) DeployVRFContract() (VRF, error) { address, _, instance, err := e.client.DeployContract("VRF", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return solidity_vrf_wrapper.DeployVRF(auth, wrappers.MustNewWrappedContractBackend(e.client, nil)) }) @@ -82,7 +82,7 @@ func (e *EthereumContractDeployer) DeployVRFContract() (VRF, error) { func (e *EthereumContractDeployer) DeployBlockhashStore() (BlockHashStore, error) { address, _, instance, err := e.client.DeployContract("BlockhashStore", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return blockhash_store.DeployBlockhashStore(auth, wrappers.MustNewWrappedContractBackend(e.client, nil)) }) @@ -100,7 +100,7 @@ func (e *EthereumContractDeployer) DeployBlockhashStore() (BlockHashStore, error func (e *EthereumContractDeployer) DeployVRFConsumer(linkAddr string, coordinatorAddr string) (VRFConsumer, error) { address, _, instance, err := e.client.DeployContract("VRFConsumer", func( auth *bind.TransactOpts, - backend bind.ContractBackend, + _ bind.ContractBackend, ) (common.Address, *types.Transaction, interface{}, error) { return solidity_vrf_consumer_interface.DeployVRFConsumer(auth, wrappers.MustNewWrappedContractBackend(e.client, nil), common.HexToAddress(coordinatorAddr), common.HexToAddress(linkAddr)) }) diff --git a/integration-tests/contracts/ethereum_vrfv2_contracts.go b/integration-tests/contracts/ethereum_vrfv2_contracts.go index 2e20d67da4b..83e222a19a7 100644 --- a/integration-tests/contracts/ethereum_vrfv2_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2_contracts.go @@ -811,7 +811,7 @@ func (v *EthereumVRFConsumerV2) GasAvailable() (*big.Int, error) { }) } -func (v *EthereumVRFConsumerV2) Fund(ethAmount *big.Float) error { +func (v *EthereumVRFConsumerV2) Fund(_ *big.Float) error { panic("do not use this function, use actions_seth.SendFunds() instead, otherwise we will have to deal with circular dependencies") } @@ -1022,7 +1022,7 @@ func (v *EthereumVRFV2WrapperLoadTestConsumer) Address() string { return v.address.Hex() } -func (v *EthereumVRFV2WrapperLoadTestConsumer) Fund(ethAmount *big.Float) error { +func (v *EthereumVRFV2WrapperLoadTestConsumer) Fund(_ *big.Float) error { panic("do not use this function, use actions_seth.SendFunds() instead, otherwise we will have to deal with circular dependencies") } diff --git a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go index 8c9d07696c6..70ff0fb2cc2 100644 --- a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go @@ -1013,7 +1013,7 @@ func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) Address() string { return v.address.Hex() } -func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) Fund(ethAmount *big.Float) error { +func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) Fund(_ *big.Float) error { panic("do not use this function, use actions_seth.SendFunds() instead, otherwise we will have to deal with circular dependencies") } diff --git a/integration-tests/load/vrfv2/vrfv2_test.go b/integration-tests/load/vrfv2/vrfv2_test.go index dd0d222d547..709e3cbafc5 100644 --- a/integration-tests/load/vrfv2/vrfv2_test.go +++ b/integration-tests/load/vrfv2/vrfv2_test.go @@ -315,8 +315,6 @@ func TestVRFV2BHSPerformance(t *testing.T) { Uints64("SubIDs", subIDsString). Msg("Funding Subscriptions with Link and Native Tokens") err = vrfv2.FundSubscriptions( - testEnv, - chainID, big.NewFloat(*configCopy.VRFv2.General.SubscriptionRefundingAmountLink), vrfContracts.LinkToken, vrfContracts.CoordinatorV2, diff --git a/integration-tests/smoke/vrfv2_test.go b/integration-tests/smoke/vrfv2_test.go index a4baf7ab647..12055aafafb 100644 --- a/integration-tests/smoke/vrfv2_test.go +++ b/integration-tests/smoke/vrfv2_test.go @@ -902,7 +902,7 @@ func TestVRFV2WithBHS(t *testing.T) { _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(257), sethClient, &wg, time.Second*260, t) wg.Wait() require.NoError(t, err) - err = vrfv2.FundSubscriptions(testEnv, big.NewFloat(*configCopy.VRFv2.General.SubscriptionFundingAmountLink), vrfContracts.LinkToken, vrfContracts.CoordinatorV2, subIDsForBHS) + err = vrfv2.FundSubscriptions(big.NewFloat(*configCopy.VRFv2.General.SubscriptionFundingAmountLink), vrfContracts.LinkToken, vrfContracts.CoordinatorV2, subIDsForBHS) require.NoError(t, err, "error funding subscriptions") randomWordsFulfilledEvent, err := vrfContracts.CoordinatorV2.WaitForRandomWordsFulfilledEvent( contracts.RandomWordsFulfilledEventFilter{ From 87d4400dd79fc098f91660563a79038bccfafb6d Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Thu, 25 Apr 2024 16:00:07 +0200 Subject: [PATCH 16/43] fix --- integration-tests/actions/actions.go | 11 +++-------- integration-tests/smoke/vrfv2_test.go | 18 ++++++++---------- integration-tests/smoke/vrfv2plus_test.go | 20 +++++++++----------- 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/integration-tests/actions/actions.go b/integration-tests/actions/actions.go index 1b8b4829d5f..912c5eabf9b 100644 --- a/integration-tests/actions/actions.go +++ b/integration-tests/actions/actions.go @@ -549,12 +549,12 @@ func WaitForBlockNumberToBe( // todo - move to EVMClient func RewindSimulatedChainToBlockNumber( ctx context.Context, - evmClient blockchain.EVMClient, + client *seth.Client, rpcURL string, rewindChainToBlockNumber uint64, l zerolog.Logger, ) (uint64, error) { - latestBlockNumberBeforeReorg, err := evmClient.LatestBlockNumber(ctx) + latestBlockNumberBeforeReorg, err := client.Client.BlockNumber(ctx) if err != nil { return 0, fmt.Errorf("error getting latest block number: %w", err) } @@ -571,12 +571,7 @@ func RewindSimulatedChainToBlockNumber( return 0, fmt.Errorf("error making reorg: %w", err) } - err = evmClient.WaitForEvents() - if err != nil { - return 0, fmt.Errorf("error waiting for events: %w", err) - } - - latestBlockNumberAfterReorg, err := evmClient.LatestBlockNumber(ctx) + latestBlockNumberAfterReorg, err := client.Client.BlockNumber(ctx) if err != nil { return 0, fmt.Errorf("error getting latest block number: %w", err) } diff --git a/integration-tests/smoke/vrfv2_test.go b/integration-tests/smoke/vrfv2_test.go index 12055aafafb..733e159ce7b 100644 --- a/integration-tests/smoke/vrfv2_test.go +++ b/integration-tests/smoke/vrfv2_test.go @@ -1025,12 +1025,11 @@ func TestVRFV2NodeReorg(t *testing.T) { chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID cleanupFn := func() { - evmClient, err := env.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - - if evmClient.NetworkSimulated() { + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") + if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). - Str("Network Name", evmClient.GetNetworkName()). + Str("Network Name", sethClient.Cfg.Network.Name). Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") } else { if *vrfv2Config.General.CancelSubsAfterTestRun { @@ -1054,9 +1053,8 @@ func TestVRFV2NodeReorg(t *testing.T) { env, vrfContracts, vrfKey, _, err = vrfv2.SetupVRFV2Universe(testcontext.Get(t), t, config, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "Error setting up VRFv2 universe") - evmClient, err := env.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - defaultWalletAddress = evmClient.GetDefaultWallet().Address() + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") consumers, subIDs, err := vrfv2.SetupNewConsumersAndSubs( env, @@ -1102,7 +1100,7 @@ func TestVRFV2NodeReorg(t *testing.T) { require.NoError(t, err, "error getting rpc url") //2. rewind chain by n number of blocks - basically, mimicking reorg scenario - latestBlockNumberAfterReorg, err := actions.RewindSimulatedChainToBlockNumber(testcontext.Get(t), evmClient, rpcUrl, rewindChainToBlock, l) + latestBlockNumberAfterReorg, err := actions.RewindSimulatedChainToBlockNumber(testcontext.Get(t), sethClient, rpcUrl, rewindChainToBlock, l) require.NoError(t, err, fmt.Sprintf("error rewinding chain to block number %d", rewindChainToBlock)) //3.1 ensure that chain is reorged and latest block number is greater than the block number when request was made @@ -1149,7 +1147,7 @@ func TestVRFV2NodeReorg(t *testing.T) { require.NoError(t, err, "error getting rpc url") //3. rewind chain by n number of blocks - basically, mimicking reorg scenario - latestBlockNumberAfterReorg, err := actions.RewindSimulatedChainToBlockNumber(testcontext.Get(t), evmClient, rpcUrl, rewindChainToBlockNumber, l) + latestBlockNumberAfterReorg, err := actions.RewindSimulatedChainToBlockNumber(testcontext.Get(t), sethClient, rpcUrl, rewindChainToBlockNumber, l) require.NoError(t, err, fmt.Sprintf("error rewinding chain to block number %d", rewindChainToBlockNumber)) //4. ensure that chain is reorged and latest block number is less than the block number when request was made diff --git a/integration-tests/smoke/vrfv2plus_test.go b/integration-tests/smoke/vrfv2plus_test.go index dc0d01b2e3e..29cc8c7f8b5 100644 --- a/integration-tests/smoke/vrfv2plus_test.go +++ b/integration-tests/smoke/vrfv2plus_test.go @@ -1882,12 +1882,11 @@ func TestVRFv2PlusNodeReorg(t *testing.T) { chainID := networks.MustGetSelectedNetworkConfig(config.GetNetworkConfig())[0].ChainID cleanupFn := func() { - evmClient, err := env.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - - if evmClient.NetworkSimulated() { + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") + if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). - Str("Network Name", evmClient.GetNetworkName()). + Str("Network Name", sethClient.Cfg.Network.Name). Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.") } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { @@ -1911,12 +1910,11 @@ func TestVRFv2PlusNodeReorg(t *testing.T) { env, vrfContracts, vrfKey, _, err = vrfv2plus.SetupVRFV2PlusUniverse(testcontext.Get(t), t, config, chainID, cleanupFn, newEnvConfig, l) require.NoError(t, err, "Error setting up VRFv2Plus universe") - evmClient, err := env.GetEVMClient(chainID) - require.NoError(t, err, "Getting EVM client shouldn't fail") - defaultWalletAddress = evmClient.GetDefaultWallet().Address() - var isNativeBilling = true + sethClient, err := env.GetSethClient(chainID) + require.NoError(t, err, "Getting Seth client shouldn't fail") + consumers, subIDs, err := vrfv2plus.SetupNewConsumersAndSubs( env, chainID, @@ -1957,7 +1955,7 @@ func TestVRFv2PlusNodeReorg(t *testing.T) { require.NoError(t, err, "error getting rpc url") //2. rewind chain by n number of blocks - basically, mimicking reorg scenario - latestBlockNumberAfterReorg, err := actions.RewindSimulatedChainToBlockNumber(testcontext.Get(t), evmClient, rpcUrl, rewindChainToBlock, l) + latestBlockNumberAfterReorg, err := actions.RewindSimulatedChainToBlockNumber(testcontext.Get(t), sethClient, rpcUrl, rewindChainToBlock, l) require.NoError(t, err, fmt.Sprintf("error rewinding chain to block number %d", rewindChainToBlock)) //3.1 ensure that chain is reorged and latest block number is greater than the block number when request was made @@ -2002,7 +2000,7 @@ func TestVRFv2PlusNodeReorg(t *testing.T) { require.NoError(t, err, "error getting rpc url") //3. rewind chain by n number of blocks - basically, mimicking reorg scenario - latestBlockNumberAfterReorg, err := actions.RewindSimulatedChainToBlockNumber(testcontext.Get(t), evmClient, rpcUrl, rewindChainToBlockNumber, l) + latestBlockNumberAfterReorg, err := actions.RewindSimulatedChainToBlockNumber(testcontext.Get(t), sethClient, rpcUrl, rewindChainToBlockNumber, l) require.NoError(t, err, fmt.Sprintf("error rewinding chain to block number %d", rewindChainToBlockNumber)) //4. ensure that chain is reorged and latest block number is less than the block number when request was made From ea66dec16f01d92c6accd33c2bdf8c2cc45b23a2 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Thu, 25 Apr 2024 16:23:20 +0200 Subject: [PATCH 17/43] Fix --- integration-tests/actions/vrf/common/actions.go | 10 ++++++---- integration-tests/actions/vrf/vrfv2/setup_steps.go | 3 ++- integration-tests/actions/vrf/vrfv2plus/setup_steps.go | 2 ++ integration-tests/smoke/ocr2vrf_test.go | 7 +++---- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/integration-tests/actions/vrf/common/actions.go b/integration-tests/actions/vrf/common/actions.go index 876cc918783..f6bc5564d79 100644 --- a/integration-tests/actions/vrf/common/actions.go +++ b/integration-tests/actions/vrf/common/actions.go @@ -64,8 +64,9 @@ func CreateAndFundSendingKeys( } newNativeTokenKeyAddresses = append(newNativeTokenKeyAddresses, newTxKey.Data.Attributes.Address) _, err = actions_seth.SendFunds(l, client, actions_seth.FundsToSendPayload{ - ToAddress: common.HexToAddress(newTxKey.Data.Attributes.Address), - Amount: conversions.EtherToWei(big.NewFloat(chainlinkNodeFunding)), + ToAddress: common.HexToAddress(newTxKey.Data.Attributes.Address), + Amount: conversions.EtherToWei(big.NewFloat(chainlinkNodeFunding)), + PrivateKey: client.PrivateKeys[0], }) if err != nil { return nil, err @@ -333,8 +334,9 @@ func FundNodesIfNeeded(existingEnvConfig *vrf_common_config.ExistingEnvConfig, c Str("Funding Amount in wei", fundingToSendWei.String()). Msg("Funding Node's Sending Key") _, err := actions_seth.SendFunds(l, client, actions_seth.FundsToSendPayload{ - ToAddress: common.HexToAddress(sendingKey), - Amount: fundingToSendWei, + ToAddress: common.HexToAddress(sendingKey), + Amount: fundingToSendWei, + PrivateKey: client.PrivateKeys[0], }) if err != nil { return err diff --git a/integration-tests/actions/vrf/vrfv2/setup_steps.go b/integration-tests/actions/vrf/vrfv2/setup_steps.go index 52b9aba3689..4e9516ba68e 100644 --- a/integration-tests/actions/vrf/vrfv2/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2/setup_steps.go @@ -388,6 +388,7 @@ func SetupVRFV2ForExistingEnv(t *testing.T, testConfig tc.TestConfig, chainID in WithTestInstance(t). WithTestConfig(&testConfig). WithCustomCleanup(cleanupFn). + WithSeth(). Build() if err != nil { return nil, nil, nil, fmt.Errorf("%s, err: %w", "error creating test env", err) @@ -461,7 +462,7 @@ func SetupSubsAndConsumersForExistingEnv( return nil, nil, fmt.Errorf("err: %w", err) } } else { - client, err := env.GetSethClientForSelectedNetwork() + client, err := env.GetSethClient(chainID) if err != nil { return nil, nil, err } diff --git a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go index 1673c3eca93..20fc77f89d9 100644 --- a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go @@ -374,6 +374,7 @@ func SetupVRFV2PlusForNewEnv( WithCLNodes(len(newEnvConfig.NodesToCreate)). WithFunding(big.NewFloat(*testConfig.Common.ChainlinkNodeFunding)). WithCustomCleanup(cleanupFn). + WithSeth(). Build() if err != nil { return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "error creating test env", err) @@ -417,6 +418,7 @@ func SetupVRFV2PlusForExistingEnv(t *testing.T, testConfig tc.TestConfig, chainI WithTestInstance(t). WithTestConfig(&testConfig). WithCustomCleanup(cleanupFn). + WithSeth(). Build() if err != nil { return nil, nil, nil, fmt.Errorf("%s, err: %w", "error creating test env", err) diff --git a/integration-tests/smoke/ocr2vrf_test.go b/integration-tests/smoke/ocr2vrf_test.go index 642ad106e64..bf4f5804e99 100644 --- a/integration-tests/smoke/ocr2vrf_test.go +++ b/integration-tests/smoke/ocr2vrf_test.go @@ -26,7 +26,6 @@ import ( "github.com/smartcontractkit/chainlink/integration-tests/config" "github.com/smartcontractkit/chainlink/integration-tests/contracts" "github.com/smartcontractkit/chainlink/integration-tests/testconfig" - tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig" "github.com/smartcontractkit/chainlink/integration-tests/utils" ) @@ -36,7 +35,7 @@ func TestOCR2VRFRedeemModel(t *testing.T) { t.Parallel() t.Skip("VRFv3 is on pause, skipping") l := logging.GetTestLogger(t) - config, err := tc.GetConfig("Smoke", tc.OCR2) + config, err := testconfig.GetConfig("Smoke", testconfig.OCR2) if err != nil { t.Fatal(err) } @@ -99,7 +98,7 @@ func TestOCR2VRFFulfillmentModel(t *testing.T) { t.Parallel() t.Skip("VRFv3 is on pause, skipping") l := logging.GetTestLogger(t) - config, err := tc.GetConfig("Smoke", tc.OCR2) + config, err := testconfig.GetConfig("Smoke", testconfig.OCR2) if err != nil { t.Fatal(err) } @@ -159,7 +158,7 @@ func TestOCR2VRFFulfillmentModel(t *testing.T) { func setupOCR2VRFEnvironment(t *testing.T) (testEnvironment *environment.Environment, testNetwork blockchain.EVMNetwork) { if ocr2vrfSmokeConfig == nil { - c, err := testconfig.GetConfig("Smoke", tc.OCR2VRF) + c, err := testconfig.GetConfig("Smoke", testconfig.OCR2VRF) if err != nil { t.Fatal(err) } From 579280e0280cccab23050af516fb412f7b8682ae Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Thu, 25 Apr 2024 16:37:15 +0200 Subject: [PATCH 18/43] fix vrfv2plus --- .../actions/vrf/vrfv2plus/contract_steps.go | 45 ++----------------- .../actions/vrf/vrfv2plus/setup_steps.go | 2 - .../load/vrfv2plus/vrfv2plus_test.go | 2 - integration-tests/smoke/vrfv2plus_test.go | 6 --- 4 files changed, 3 insertions(+), 52 deletions(-) diff --git a/integration-tests/actions/vrf/vrfv2plus/contract_steps.go b/integration-tests/actions/vrf/vrfv2plus/contract_steps.go index 473e9b96549..ad7e841e67b 100644 --- a/integration-tests/actions/vrf/vrfv2plus/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/contract_steps.go @@ -146,20 +146,8 @@ func CreateFundSubsAndAddConsumers( subToConsumersMap, coordinator, ) - if err != nil { - return nil, err - } - - evmClient, err := env.GetEVMClient(chainID) - if err != nil { - return nil, err - } - err = evmClient.WaitForEvents() - if err != nil { - return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitTXsComplete, err) - } - return subIDs, nil + return subIDs, err } func CreateSubsAndFund( @@ -175,18 +163,7 @@ func CreateSubsAndFund( if err != nil { return nil, err } - evmClient, err := env.GetEVMClient(chainID) - if err != nil { - return nil, err - } - - err = evmClient.WaitForEvents() - if err != nil { - return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitTXsComplete, err) - } err = FundSubscriptions( - env, - chainID, subscriptionFundingAmountNative, subscriptionFundingAmountLink, linkToken, @@ -237,16 +214,11 @@ func CreateSubAndFindSubID(env *test_env.CLClusterTestEnv, chainID int64, coordi if err != nil { return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrCreateVRFSubscription, err) } - evmClient, err := env.GetEVMClient(chainID) + sethClient, err := env.GetSethClient(chainID) if err != nil { return nil, err } - err = evmClient.WaitForEvents() - if err != nil { - return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitTXsComplete, err) - } - - receipt, err := evmClient.GetTxReceipt(tx.Hash()) + receipt, err := sethClient.Client.TransactionReceipt(context.Background(), tx.Hash()) if err != nil { return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitTXsComplete, err) } @@ -258,19 +230,12 @@ func CreateSubAndFindSubID(env *test_env.CLClusterTestEnv, chainID int64, coordi } func FundSubscriptions( - env *test_env.CLClusterTestEnv, - chainID int64, subscriptionFundingAmountNative *big.Float, subscriptionFundingAmountLink *big.Float, linkAddress contracts.LinkToken, coordinator contracts.VRFCoordinatorV2_5, subIDs []*big.Int, ) error { - evmClient, err := env.GetEVMClient(chainID) - if err != nil { - return err - } - for _, subID := range subIDs { //Native Billing amountWei := conversions.EtherToWei(subscriptionFundingAmountNative) @@ -288,10 +253,6 @@ func FundSubscriptions( return fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrFundSubWithLinkToken, err) } } - err = evmClient.WaitForEvents() - if err != nil { - return fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitTXsComplete, err) - } return nil } diff --git a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go index 20fc77f89d9..e09ce9b6c25 100644 --- a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go @@ -303,8 +303,6 @@ func SetupVRFV2PlusWrapperEnvironment( } err = FundSubscriptions( - env, - chainID, big.NewFloat(*vrfv2PlusTestConfig.GetVRFv2PlusConfig().General.SubscriptionFundingAmountNative), big.NewFloat(*vrfv2PlusTestConfig.GetVRFv2PlusConfig().General.SubscriptionFundingAmountLink), linkToken, diff --git a/integration-tests/load/vrfv2plus/vrfv2plus_test.go b/integration-tests/load/vrfv2plus/vrfv2plus_test.go index d6f6099697c..d53e79a3a54 100644 --- a/integration-tests/load/vrfv2plus/vrfv2plus_test.go +++ b/integration-tests/load/vrfv2plus/vrfv2plus_test.go @@ -316,8 +316,6 @@ func TestVRFV2PlusBHSPerformance(t *testing.T) { Strs("SubIDs", subIDsString). Msg("Funding Subscriptions with Link and Native Tokens") err = vrfv2plus.FundSubscriptions( - testEnv, - chainID, big.NewFloat(*configCopy.VRFv2Plus.General.SubscriptionRefundingAmountNative), big.NewFloat(*configCopy.VRFv2Plus.General.SubscriptionRefundingAmountLink), vrfContracts.LinkToken, diff --git a/integration-tests/smoke/vrfv2plus_test.go b/integration-tests/smoke/vrfv2plus_test.go index 29cc8c7f8b5..d5396c4cc15 100644 --- a/integration-tests/smoke/vrfv2plus_test.go +++ b/integration-tests/smoke/vrfv2plus_test.go @@ -1320,8 +1320,6 @@ func TestVRFV2PlusWithBHS(t *testing.T) { wg.Wait() require.NoError(t, err) err = vrfv2plus.FundSubscriptions( - env, - chainID, big.NewFloat(*configCopy.VRFv2Plus.General.SubscriptionRefundingAmountNative), big.NewFloat(*configCopy.VRFv2Plus.General.SubscriptionRefundingAmountLink), vrfContracts.LinkToken, @@ -1539,8 +1537,6 @@ func TestVRFV2PlusWithBHF(t *testing.T) { Float64("SubscriptionFundingAmountLink", *configCopy.VRFv2Plus.General.SubscriptionRefundingAmountLink). Msg("Funding subscription") err = vrfv2plus.FundSubscriptions( - env, - chainID, big.NewFloat(*configCopy.VRFv2Plus.General.SubscriptionRefundingAmountNative), big.NewFloat(*configCopy.VRFv2Plus.General.SubscriptionRefundingAmountLink), vrfContracts.LinkToken, @@ -1702,8 +1698,6 @@ func TestVRFv2PlusReplayAfterTimeout(t *testing.T) { // 5. fund sub so that node can fulfill request err = vrfv2plus.FundSubscriptions( - env, - chainID, fundingLinkAmt, fundingNativeAmt, vrfContracts.LinkToken, From 9f16f32842b1588c3f8e3ad0cfa597ca17a0428a Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Thu, 25 Apr 2024 16:58:53 +0200 Subject: [PATCH 19/43] fix 2 --- integration-tests/actions/vrf/vrfv2plus/setup_steps.go | 9 ++++++++- .../contracts/ethereum_vrfv2plus_contracts.go | 3 ++- integration-tests/smoke/vrfv2plus_test.go | 2 ++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go index e09ce9b6c25..3b7ab8bd8ce 100644 --- a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go @@ -14,6 +14,8 @@ import ( "github.com/google/uuid" "github.com/rs/zerolog" + "github.com/smartcontractkit/chainlink-testing-framework/utils/conversions" + actions_seth "github.com/smartcontractkit/chainlink/integration-tests/actions/seth" vrfcommon "github.com/smartcontractkit/chainlink/integration-tests/actions/vrf/common" tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig" "github.com/smartcontractkit/chainlink/integration-tests/types/config/node" @@ -238,6 +240,7 @@ func setupVRFNode(contracts *vrfcommon.VRFContracts, chainID *big.Int, config *v func SetupVRFV2PlusWrapperEnvironment( ctx context.Context, + l zerolog.Logger, env *test_env.CLClusterTestEnv, chainID int64, vrfv2PlusTestConfig types.VRFv2PlusTestConfig, @@ -323,7 +326,11 @@ func SetupVRFV2PlusWrapperEnvironment( } //fund consumer with Eth - err = wrapperContracts.LoadTestConsumers[0].Fund(big.NewFloat(*vrfv2PlusConfig.WrapperConsumerFundingAmountNativeToken)) + _, err = actions_seth.SendFunds(l, sethClient, actions_seth.FundsToSendPayload{ + ToAddress: common.HexToAddress(wrapperContracts.LoadTestConsumers[0].Address()), + Amount: conversions.EtherToWei(big.NewFloat(*vrfv2PlusConfig.WrapperConsumerFundingAmountNativeToken)), + PrivateKey: sethClient.PrivateKeys[0], + }) if err != nil { return nil, nil, err } diff --git a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go index 70ff0fb2cc2..5437da39b00 100644 --- a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go @@ -322,7 +322,8 @@ func (v *EthereumVRFCoordinatorV2_5) CreateSubscription() (*types.Transaction, e } func (v *EthereumVRFCoordinatorV2_5) Migrate(subId *big.Int, coordinatorAddress string) error { - _, err := v.client.Decode(v.coordinator.Migrate(v.client.NewTXOpts(), subId, common.HexToAddress(coordinatorAddress))) + // Do not wrap in Decode() to avoid waiting until the transaction is mined. + _, err := v.coordinator.Migrate(v.client.NewTXOpts(), subId, common.HexToAddress(coordinatorAddress)) return err } diff --git a/integration-tests/smoke/vrfv2plus_test.go b/integration-tests/smoke/vrfv2plus_test.go index d5396c4cc15..4849383fceb 100644 --- a/integration-tests/smoke/vrfv2plus_test.go +++ b/integration-tests/smoke/vrfv2plus_test.go @@ -280,6 +280,7 @@ func TestVRFv2Plus(t *testing.T) { configCopy := config.MustCopy().(tc.TestConfig) wrapperContracts, wrapperSubID, err := vrfv2plus.SetupVRFV2PlusWrapperEnvironment( testcontext.Get(t), + l, env, chainID, &configCopy, @@ -1052,6 +1053,7 @@ func TestVRFv2PlusMigration(t *testing.T) { wrapperContracts, wrapperSubID, err := vrfv2plus.SetupVRFV2PlusWrapperEnvironment( testcontext.Get(t), + l, env, chainID, &configCopy, From 06bf8d2900b6f75902bc4cdc1458dae73112086b Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Fri, 26 Apr 2024 12:35:02 +0200 Subject: [PATCH 20/43] fix --- integration-tests/actions/vrf/vrfv2/setup_steps.go | 3 ++- integration-tests/smoke/vrfv2_test.go | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/integration-tests/actions/vrf/vrfv2/setup_steps.go b/integration-tests/actions/vrf/vrfv2/setup_steps.go index 4e9516ba68e..d30aebd501d 100644 --- a/integration-tests/actions/vrf/vrfv2/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2/setup_steps.go @@ -235,6 +235,7 @@ func setupVRFNode(contracts *vrfcommon.VRFContracts, chainID *big.Int, vrfv2Conf func SetupVRFV2WrapperEnvironment( ctx context.Context, env *test_env.CLClusterTestEnv, + chainID int64, vrfv2TestConfig tc.VRFv2TestConfig, linkToken contracts.LinkToken, mockNativeLINKFeed contracts.VRFMockETHLINKFeed, @@ -242,7 +243,7 @@ func SetupVRFV2WrapperEnvironment( keyHash [32]byte, wrapperConsumerContractsAmount int, ) (*VRFV2WrapperContracts, *uint64, error) { - sethClient, err := env.GetSethClientForSelectedNetwork() + sethClient, err := env.GetSethClient(chainID) if err != nil { return nil, nil, err } diff --git a/integration-tests/smoke/vrfv2_test.go b/integration-tests/smoke/vrfv2_test.go index 733e159ce7b..5890ea363ef 100644 --- a/integration-tests/smoke/vrfv2_test.go +++ b/integration-tests/smoke/vrfv2_test.go @@ -231,6 +231,7 @@ func TestVRFv2Basic(t *testing.T) { wrapperContracts, wrapperSubID, err := vrfv2.SetupVRFV2WrapperEnvironment( testcontext.Get(t), testEnv, + chainID, &configCopy, vrfContracts.LinkToken, vrfContracts.MockETHLINKFeed, From 0febc2dc83b9ea7a820c4832f3b2e8006b97985f Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Fri, 26 Apr 2024 13:33:52 +0200 Subject: [PATCH 21/43] wip --- integration-tests/actions/vrf/vrfv2plus/setup_steps.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go index 3b7ab8bd8ce..5a959a48d13 100644 --- a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go @@ -334,6 +334,16 @@ func SetupVRFV2PlusWrapperEnvironment( if err != nil { return nil, nil, err } + + wrapperConsumerBalanceBeforeRequestWei, err := sethClient.Client.BalanceAt(context.Background(), common.HexToAddress(wrapperContracts.LoadTestConsumers[0].Address()), nil) + if err != nil { + return nil, nil, err + } + l.Info(). + Str("WrapperConsumerBalanceBeforeRequestWei", wrapperConsumerBalanceBeforeRequestWei.String()). + Str("WrapperConsumerAddress", wrapperContracts.LoadTestConsumers[0].Address()). + Msg("WrapperConsumerBalanceBeforeRequestWei") + return wrapperContracts, wrapperSubID, nil } From f20fe27723a716a041d29d28bf2ae7e99df0c561 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:57:47 +0200 Subject: [PATCH 22/43] bump gas limit for sending funds to EOA --- integration-tests/actions/vrf/vrfv2plus/setup_steps.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go index 5a959a48d13..83998866326 100644 --- a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go @@ -326,10 +326,12 @@ func SetupVRFV2PlusWrapperEnvironment( } //fund consumer with Eth + gasLimit := int64(2 * 21000) _, err = actions_seth.SendFunds(l, sethClient, actions_seth.FundsToSendPayload{ ToAddress: common.HexToAddress(wrapperContracts.LoadTestConsumers[0].Address()), Amount: conversions.EtherToWei(big.NewFloat(*vrfv2PlusConfig.WrapperConsumerFundingAmountNativeToken)), PrivateKey: sethClient.PrivateKeys[0], + GasLimit: &gasLimit, }) if err != nil { return nil, nil, err From 08ce45ad65978a4ff696e07aa93f46f33a63e83b Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:58:06 +0200 Subject: [PATCH 23/43] check receipt when sending funds --- integration-tests/actions/seth/actions.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/integration-tests/actions/seth/actions.go b/integration-tests/actions/seth/actions.go index 987f05af183..15bf62dca60 100644 --- a/integration-tests/actions/seth/actions.go +++ b/integration-tests/actions/seth/actions.go @@ -282,7 +282,26 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa Bool("Dynamic fees", client.Cfg.Network.EIP1559DynamicFees). Msg("Sent funds") - return client.WaitMined(ctx, logger, client.Client, signedTx) + receipt, receiptErr := client.WaitMined(ctx, logger, client.Client, signedTx) + if receiptErr != nil { + return nil, errors.Wrap(receiptErr, "failed to wait for transaction to be mined") + } + + if receipt.Status == 1 { + return receipt, nil + } + + tx, _, err := client.Client.TransactionByHash(ctx, signedTx.Hash()) + if err != nil { + return nil, errors.Wrap(err, "failed to get transaction by hash ") + } + + _, err = client.Decode(tx, receiptErr) + if err != nil { + return nil, err + } + + return receipt, nil } // DeployForwarderContracts first deploys Operator Factory and then uses it to deploy given number of From 272c1d000b5504be1566fbd11dd45e76db5ac426 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Tue, 7 May 2024 11:13:43 +0200 Subject: [PATCH 24/43] fix go mod --- integration-tests/load/go.mod | 2 +- integration-tests/load/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integration-tests/load/go.mod b/integration-tests/load/go.mod index a5d34d84349..3110fc6a0a0 100644 --- a/integration-tests/load/go.mod +++ b/integration-tests/load/go.mod @@ -21,7 +21,7 @@ require ( github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20240214231432-4ad5eb95178c github.com/smartcontractkit/chainlink/v2 v2.9.0-beta0.0.20240216210048-da02459ddad8 github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c - github.com/smartcontractkit/seth v0.1.6-0.20240424154541-db45307043b2 + github.com/smartcontractkit/seth v0.1.6-0.20240429143720-cacb8160ecec github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1 github.com/smartcontractkit/wasp v0.4.6 github.com/stretchr/testify v1.9.0 diff --git a/integration-tests/load/go.sum b/integration-tests/load/go.sum index f854bbddf51..100f1bcc2cd 100644 --- a/integration-tests/load/go.sum +++ b/integration-tests/load/go.sum @@ -1524,8 +1524,8 @@ github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJ github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0= github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c h1:lIyMbTaF2H0Q71vkwZHX/Ew4KF2BxiKhqEXwF8rn+KI= github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c/go.mod h1:fb1ZDVXACvu4frX3APHZaEBp0xi1DIm34DcA0CwTsZM= -github.com/smartcontractkit/seth v0.1.6-0.20240424154541-db45307043b2 h1:pOLrnNRYpOfPQPPn/8B0Z12TIsyu8q3dwZXspWzzzTY= -github.com/smartcontractkit/seth v0.1.6-0.20240424154541-db45307043b2/go.mod h1:2TMOZQ8WTAw7rR1YBbXpnad6VmT/+xDd/nXLmB7Eero= +github.com/smartcontractkit/seth v0.1.6-0.20240429143720-cacb8160ecec h1:BT1loU6TT2YqMenD7XE+aw7IeeTiC25+r1TLKAySVIg= +github.com/smartcontractkit/seth v0.1.6-0.20240429143720-cacb8160ecec/go.mod h1:2TMOZQ8WTAw7rR1YBbXpnad6VmT/+xDd/nXLmB7Eero= github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 h1:yiKnypAqP8l0OX0P3klzZ7SCcBUxy5KqTAKZmQOvSQE= github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1/go.mod h1:q6f4fe39oZPdsh1i57WznEZgxd8siidMaSFq3wdPmVg= github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1 h1:Dai1bn+Q5cpeGMQwRdjOdVjG8mmFFROVkSKuUgBErRQ= From 65d3c780fc7a66046431e43c678762c9a4ee1b91 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Fri, 10 May 2024 11:07:44 +0200 Subject: [PATCH 25/43] Fix test context --- integration-tests/actions/seth/actions.go | 4 +- integration-tests/actions/seth/refund.go | 10 ++--- .../actions/vrf/common/actions.go | 4 +- .../actions/vrf/vrfv2/setup_steps.go | 3 +- .../actions/vrf/vrfv2plus/contract_steps.go | 14 +++++-- .../actions/vrf/vrfv2plus/setup_steps.go | 10 +++-- integration-tests/docker/test_env/test_env.go | 8 ++-- .../docker/test_env/test_env_builder.go | 3 +- integration-tests/load/vrfv2/vrfv2_test.go | 4 +- .../load/vrfv2plus/vrfv2plus_test.go | 6 ++- integration-tests/smoke/vrfv2_test.go | 12 +++--- integration-tests/smoke/vrfv2plus_test.go | 37 ++++++++++++++----- 12 files changed, 74 insertions(+), 41 deletions(-) diff --git a/integration-tests/actions/seth/actions.go b/integration-tests/actions/seth/actions.go index 6fc40e4ac97..43b71d317d2 100644 --- a/integration-tests/actions/seth/actions.go +++ b/integration-tests/actions/seth/actions.go @@ -521,7 +521,7 @@ func TeardownSuite( } if chainlinkNodes != nil { - if err := ReturnFundsFromNodes(l, chainClient, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(chainlinkNodes)); err != nil { + if err := ReturnFundsFromNodes(testcontext.Get(t), l, chainClient, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(chainlinkNodes)); err != nil { // This printed line is required for tests that use real funds to propagate the failure // out to the system running the test. Do not remove fmt.Println(environment.FAILED_FUND_RETURN) @@ -555,7 +555,7 @@ func TeardownRemoteSuite( l.Warn().Msgf("Error deleting jobs %+v", err) } - if err = ReturnFundsFromNodes(l, client, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(chainlinkNodes)); err != nil { + if err = ReturnFundsFromNodes(testcontext.Get(t), l, client, contracts.ChainlinkK8sClientToChainlinkNodeWithKeysAndAddress(chainlinkNodes)); err != nil { l.Error().Err(err).Str("Namespace", namespace). Msg("Error attempting to return funds from chainlink nodes to network's default wallet. " + "Environment is left running so you can try manually!") diff --git a/integration-tests/actions/seth/refund.go b/integration-tests/actions/seth/refund.go index 15927f52227..1fc8a9a3f43 100644 --- a/integration-tests/actions/seth/refund.go +++ b/integration-tests/actions/seth/refund.go @@ -232,7 +232,7 @@ func (r *OvershotTransferRetrier) Retry(ctx context.Context, logger zerolog.Logg // ReturnFundsFromNodes returns funds from the given chainlink nodes to the default network wallet. It will use a variety // of strategies to attempt to return funds, including retrying with less funds if the transaction fails due to // insufficient funds, and retrying with a higher gas limit if the transaction fails due to gas too low. -func ReturnFundsFromNodes(log zerolog.Logger, client *seth.Client, chainlinkNodes []contracts.ChainlinkNodeWithKeysAndAddress) error { +func ReturnFundsFromNodes(ctx context.Context, log zerolog.Logger, client *seth.Client, chainlinkNodes []contracts.ChainlinkNodeWithKeysAndAddress) error { if client == nil { return fmt.Errorf("Seth client is nil, unable to return funds from chainlink nodes") } @@ -262,7 +262,7 @@ func ReturnFundsFromNodes(log zerolog.Logger, client *seth.Client, chainlinkNode return err } - err = sendAllFundsIfPossible(log, client, decryptedKey.PrivateKey) + err = sendAllFundsIfPossible(ctx, log, client, decryptedKey.PrivateKey) if err != nil { publicKey := decryptedKey.PrivateKey.Public() publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) @@ -283,7 +283,7 @@ func ReturnFundsFromNodes(log zerolog.Logger, client *seth.Client, chainlinkNode return nil } -func sendAllFundsIfPossible(log zerolog.Logger, sethClient *seth.Client, fromPrivateKey *ecdsa.PrivateKey) error { +func sendAllFundsIfPossible(ctx context.Context, log zerolog.Logger, sethClient *seth.Client, fromPrivateKey *ecdsa.PrivateKey) error { publicKey := fromPrivateKey.Public() publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) if !ok { @@ -291,7 +291,7 @@ func sendAllFundsIfPossible(log zerolog.Logger, sethClient *seth.Client, fromPri } fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) - balance, err := sethClient.Client.BalanceAt(context.Background(), fromAddress, nil) + balance, err := sethClient.Client.BalanceAt(ctx, fromAddress, nil) if err != nil { return err } @@ -354,7 +354,7 @@ func sendAllFundsIfPossible(log zerolog.Logger, sethClient *seth.Client, fromPri _, err = SendFunds(log, sethClient, payload) if err != nil { handler := OvershotTransferRetrier{maxRetries: 10, nextRetrier: &InsufficientFundTransferRetrier{maxRetries: 10, nextRetrier: &GasTooLowTransferRetrier{maxGasLimit: sethClient.Cfg.Network.TransferGasFee * 10}}} - err = handler.Retry(context.Background(), log, sethClient, err, payload, 0) + err = handler.Retry(ctx, log, sethClient, err, payload, 0) if err != nil { log.Error(). Err(err). diff --git a/integration-tests/actions/vrf/common/actions.go b/integration-tests/actions/vrf/common/actions.go index f6bc5564d79..ef4c928fe11 100644 --- a/integration-tests/actions/vrf/common/actions.go +++ b/integration-tests/actions/vrf/common/actions.go @@ -315,11 +315,11 @@ func CreateVRFKeyOnVRFNode(vrfNode *VRFNode, l zerolog.Logger) (*client.VRFKey, return vrfKey, pubKeyCompressed, nil } -func FundNodesIfNeeded(existingEnvConfig *vrf_common_config.ExistingEnvConfig, client *seth.Client, l zerolog.Logger) error { +func FundNodesIfNeeded(ctx context.Context, existingEnvConfig *vrf_common_config.ExistingEnvConfig, client *seth.Client, l zerolog.Logger) error { if *existingEnvConfig.NodeSendingKeyFundingMin > 0 { for _, sendingKey := range existingEnvConfig.NodeSendingKeys { address := common.HexToAddress(sendingKey) - sendingKeyBalance, err := client.Client.BalanceAt(context.Background(), address, nil) + sendingKeyBalance, err := client.Client.BalanceAt(ctx, address, nil) if err != nil { return err } diff --git a/integration-tests/actions/vrf/vrfv2/setup_steps.go b/integration-tests/actions/vrf/vrfv2/setup_steps.go index ac48467eb23..34ed3553ccc 100644 --- a/integration-tests/actions/vrf/vrfv2/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2/setup_steps.go @@ -13,6 +13,7 @@ import ( "github.com/google/uuid" + "github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext" "github.com/smartcontractkit/chainlink/integration-tests/actions" "github.com/smartcontractkit/chainlink/integration-tests/docker/test_env" testconfig "github.com/smartcontractkit/chainlink/integration-tests/testconfig/vrfv2" @@ -416,7 +417,7 @@ func SetupVRFV2ForExistingEnv(t *testing.T, testConfig tc.TestConfig, chainID in return nil, nil, nil, err } - err = vrfcommon.FundNodesIfNeeded(commonExistingEnvConfig, sethClient, l) + err = vrfcommon.FundNodesIfNeeded(testcontext.Get(t), commonExistingEnvConfig, sethClient, l) if err != nil { return nil, nil, nil, fmt.Errorf("err: %w", err) } diff --git a/integration-tests/actions/vrf/vrfv2plus/contract_steps.go b/integration-tests/actions/vrf/vrfv2plus/contract_steps.go index 873253598db..725c0f4de2e 100644 --- a/integration-tests/actions/vrf/vrfv2plus/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/contract_steps.go @@ -119,6 +119,7 @@ func FundVRFCoordinatorV2_5Subscription( } func CreateFundSubsAndAddConsumers( + ctx context.Context, env *test_env.CLClusterTestEnv, chainID int64, subscriptionFundingAmountNative *big.Float, @@ -129,6 +130,7 @@ func CreateFundSubsAndAddConsumers( numberOfSubToCreate int, ) ([]*big.Int, error) { subIDs, err := CreateSubsAndFund( + ctx, env, chainID, subscriptionFundingAmountNative, @@ -156,6 +158,7 @@ func CreateFundSubsAndAddConsumers( } func CreateSubsAndFund( + ctx context.Context, env *test_env.CLClusterTestEnv, chainID int64, subscriptionFundingAmountNative *big.Float, @@ -164,7 +167,7 @@ func CreateSubsAndFund( coordinator contracts.VRFCoordinatorV2_5, subAmountToCreate int, ) ([]*big.Int, error) { - subs, err := CreateSubs(env, chainID, coordinator, subAmountToCreate) + subs, err := CreateSubs(ctx, env, chainID, coordinator, subAmountToCreate) if err != nil { return nil, err } @@ -182,6 +185,7 @@ func CreateSubsAndFund( } func CreateSubs( + ctx context.Context, env *test_env.CLClusterTestEnv, chainID int64, coordinator contracts.VRFCoordinatorV2_5, @@ -190,7 +194,7 @@ func CreateSubs( var subIDArr []*big.Int for i := 0; i < subAmountToCreate; i++ { - subID, err := CreateSubAndFindSubID(env, chainID, coordinator) + subID, err := CreateSubAndFindSubID(ctx, env, chainID, coordinator) if err != nil { return nil, err } @@ -214,7 +218,7 @@ func AddConsumersToSubs( return nil } -func CreateSubAndFindSubID(env *test_env.CLClusterTestEnv, chainID int64, coordinator contracts.VRFCoordinatorV2_5) (*big.Int, error) { +func CreateSubAndFindSubID(ctx context.Context, env *test_env.CLClusterTestEnv, chainID int64, coordinator contracts.VRFCoordinatorV2_5) (*big.Int, error) { tx, err := coordinator.CreateSubscription() if err != nil { return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrCreateVRFSubscription, err) @@ -223,7 +227,7 @@ func CreateSubAndFindSubID(env *test_env.CLClusterTestEnv, chainID int64, coordi if err != nil { return nil, err } - receipt, err := sethClient.Client.TransactionReceipt(context.Background(), tx.Hash()) + receipt, err := sethClient.Client.TransactionReceipt(ctx, tx.Hash()) if err != nil { return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitTXsComplete, err) } @@ -525,6 +529,7 @@ func SetupVRFV2PlusContracts( } func SetupNewConsumersAndSubs( + ctx context.Context, env *test_env.CLClusterTestEnv, chainID int64, coordinator contracts.VRFCoordinatorV2_5, @@ -547,6 +552,7 @@ func SetupNewConsumersAndSubs( Int("Number of Subs to create", numberOfSubToCreate). Msg("Creating and funding subscriptions, deploying and adding consumers to subs") subIDs, err := CreateFundSubsAndAddConsumers( + ctx, env, chainID, big.NewFloat(*testConfig.VRFv2Plus.General.SubscriptionFundingAmountNative), diff --git a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go index 140d092e14b..c6abb6b034c 100644 --- a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go @@ -15,6 +15,7 @@ import ( "github.com/rs/zerolog" "github.com/smartcontractkit/chainlink-testing-framework/utils/conversions" + "github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext" actions_seth "github.com/smartcontractkit/chainlink/integration-tests/actions/seth" vrfcommon "github.com/smartcontractkit/chainlink/integration-tests/actions/vrf/common" tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig" @@ -258,7 +259,7 @@ func SetupVRFV2PlusWrapperEnvironment( wrapperConsumerContractsAmount int, ) (*VRFV2PlusWrapperContracts, *big.Int, error) { // external EOA has to create a subscription for the wrapper first - wrapperSubId, err := CreateSubAndFindSubID(env, chainID, coordinator) + wrapperSubId, err := CreateSubAndFindSubID(ctx, env, chainID, coordinator) if err != nil { return nil, nil, err } @@ -344,7 +345,7 @@ func SetupVRFV2PlusWrapperEnvironment( return nil, nil, err } - wrapperConsumerBalanceBeforeRequestWei, err := sethClient.Client.BalanceAt(context.Background(), common.HexToAddress(wrapperContracts.LoadTestConsumers[0].Address()), nil) + wrapperConsumerBalanceBeforeRequestWei, err := sethClient.Client.BalanceAt(ctx, common.HexToAddress(wrapperContracts.LoadTestConsumers[0].Address()), nil) if err != nil { return nil, nil, err } @@ -462,7 +463,7 @@ func SetupVRFV2PlusForExistingEnv(t *testing.T, testConfig tc.TestConfig, chainI return nil, nil, nil, fmt.Errorf("%s, err: %w", "error loading LinkToken", err) } - err = vrfcommon.FundNodesIfNeeded(commonExistingEnvConfig, sethClient, l) + err = vrfcommon.FundNodesIfNeeded(testcontext.Get(t), commonExistingEnvConfig, sethClient, l) if err != nil { return nil, nil, nil, fmt.Errorf("err: %w", err) } @@ -482,6 +483,7 @@ func SetupVRFV2PlusForExistingEnv(t *testing.T, testConfig tc.TestConfig, chainI } func SetupSubsAndConsumersForExistingEnv( + ctx context.Context, env *test_env.CLClusterTestEnv, chainID int64, coordinator contracts.VRFCoordinatorV2_5, @@ -504,6 +506,7 @@ func SetupSubsAndConsumersForExistingEnv( commonExistingEnvConfig := testConfig.VRFv2Plus.ExistingEnvConfig.ExistingEnvConfig if *commonExistingEnvConfig.CreateFundSubsAndAddConsumers { consumers, subIDs, err = SetupNewConsumersAndSubs( + ctx, env, chainID, coordinator, @@ -531,6 +534,7 @@ func SetupSubsAndConsumersForExistingEnv( } } else { consumers, subIDs, err = SetupNewConsumersAndSubs( + ctx, env, chainID, coordinator, diff --git a/integration-tests/docker/test_env/test_env.go b/integration-tests/docker/test_env/test_env.go index 48bd82cfb71..3c673112b5e 100644 --- a/integration-tests/docker/test_env/test_env.go +++ b/integration-tests/docker/test_env/test_env.go @@ -211,7 +211,7 @@ type CleanupOpts struct { } // Cleanup cleans the environment up after it's done being used, mainly for returning funds when on live networks and logs. -func (te *CLClusterTestEnv) Cleanup(opts CleanupOpts) error { +func (te *CLClusterTestEnv) Cleanup(ctx context.Context, opts CleanupOpts) error { te.l.Info().Msg("Cleaning up test environment") runIdErr := runid.RemoveLocalRunId(te.TestConfig.GetLoggingConfig().RunId) @@ -235,7 +235,7 @@ func (te *CLClusterTestEnv) Cleanup(opts CleanupOpts) error { te.l.Info(). Msg("Network is a simulated network. Skipping fund return.") } else { - if err := te.returnFunds(); err != nil { + if err := te.returnFunds(ctx); err != nil { return err } } @@ -356,7 +356,7 @@ func (te *CLClusterTestEnv) logWhetherAllContainersAreRunning() { } } -func (te *CLClusterTestEnv) returnFunds() error { +func (te *CLClusterTestEnv) returnFunds(ctx context.Context) error { te.l.Info().Msg("Attempting to return Chainlink node funds to default network wallets") if len(te.evmClients) == 0 && len(te.sethClients) == 0 { @@ -394,7 +394,7 @@ func (te *CLClusterTestEnv) returnFunds() error { } for _, sethClient := range te.sethClients { - if err := actions_seth.ReturnFundsFromNodes(te.l, sethClient, contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(te.ClCluster.NodeAPIs())); err != nil { + if err := actions_seth.ReturnFundsFromNodes(ctx, te.l, sethClient, contracts.ChainlinkClientToChainlinkNodeWithKeysAndAddress(te.ClCluster.NodeAPIs())); err != nil { te.l.Error().Err(err).Msg("Error returning funds from node") } } diff --git a/integration-tests/docker/test_env/test_env_builder.go b/integration-tests/docker/test_env/test_env_builder.go index c8b4ac8e734..5e6099b83a7 100644 --- a/integration-tests/docker/test_env/test_env_builder.go +++ b/integration-tests/docker/test_env/test_env_builder.go @@ -18,6 +18,7 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/logstream" "github.com/smartcontractkit/chainlink-testing-framework/networks" "github.com/smartcontractkit/chainlink-testing-framework/utils/osutil" + "github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext" evmcfg "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml" "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" @@ -259,7 +260,7 @@ func (b *CLTestEnvBuilder) Build() (*CLClusterTestEnv, error) { case CleanUpTypeStandard: b.t.Cleanup(func() { // Cleanup test environment - if err := b.te.Cleanup(CleanupOpts{TestName: b.t.Name()}); err != nil { + if err := b.te.Cleanup(testcontext.Get(b.t), CleanupOpts{TestName: b.t.Name()}); err != nil { b.l.Error().Err(err).Msg("Error cleaning up test environment") } }) diff --git a/integration-tests/load/vrfv2/vrfv2_test.go b/integration-tests/load/vrfv2/vrfv2_test.go index 709e3cbafc5..8578efdee56 100644 --- a/integration-tests/load/vrfv2/vrfv2_test.go +++ b/integration-tests/load/vrfv2/vrfv2_test.go @@ -85,7 +85,7 @@ func TestVRFV2Performance(t *testing.T) { } } if !*vrfv2Config.General.UseExistingEnv { - if err := testEnv.Cleanup(test_env.CleanupOpts{}); err != nil { + if err := testEnv.Cleanup(testcontext.Get(t), test_env.CleanupOpts{}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -223,7 +223,7 @@ func TestVRFV2BHSPerformance(t *testing.T) { } } if !*vrfv2Config.General.UseExistingEnv { - if err := testEnv.Cleanup(test_env.CleanupOpts{}); err != nil { + if err := testEnv.Cleanup(testcontext.Get(t), test_env.CleanupOpts{}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } diff --git a/integration-tests/load/vrfv2plus/vrfv2plus_test.go b/integration-tests/load/vrfv2plus/vrfv2plus_test.go index d53e79a3a54..cc16ed5a0a5 100644 --- a/integration-tests/load/vrfv2plus/vrfv2plus_test.go +++ b/integration-tests/load/vrfv2plus/vrfv2plus_test.go @@ -83,7 +83,7 @@ func TestVRFV2PlusPerformance(t *testing.T) { } } if !*testConfig.VRFv2Plus.General.UseExistingEnv { - if err := testEnv.Cleanup(test_env.CleanupOpts{}); err != nil { + if err := testEnv.Cleanup(testcontext.Get(t), test_env.CleanupOpts{}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -99,6 +99,7 @@ func TestVRFV2PlusPerformance(t *testing.T) { var consumers []contracts.VRFv2PlusLoadTestConsumer subIDs, consumers, err := vrfv2plus.SetupSubsAndConsumersForExistingEnv( + testcontext.Get(t), testEnv, chainID, vrfContracts.CoordinatorV2Plus, @@ -219,7 +220,7 @@ func TestVRFV2PlusBHSPerformance(t *testing.T) { } } if !*testConfig.VRFv2Plus.General.UseExistingEnv { - if err := testEnv.Cleanup(test_env.CleanupOpts{}); err != nil { + if err := testEnv.Cleanup(testcontext.Get(t), test_env.CleanupOpts{}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -240,6 +241,7 @@ func TestVRFV2PlusBHSPerformance(t *testing.T) { configCopy.VRFv2Plus.General.SubscriptionFundingAmountNative = ptr.Ptr(float64(0)) underfundedSubIDs, consumers, err := vrfv2plus.SetupSubsAndConsumersForExistingEnv( + testcontext.Get(t), testEnv, chainID, vrfContracts.CoordinatorV2Plus, diff --git a/integration-tests/smoke/vrfv2_test.go b/integration-tests/smoke/vrfv2_test.go index f2335f899f5..6462669be1f 100644 --- a/integration-tests/smoke/vrfv2_test.go +++ b/integration-tests/smoke/vrfv2_test.go @@ -61,7 +61,7 @@ func TestVRFv2Basic(t *testing.T) { } } if !*vrfv2Config.General.UseExistingEnv { - if err := testEnv.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := testEnv.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -592,7 +592,7 @@ func TestVRFv2MultipleSendingKeys(t *testing.T) { } } if !*vrfv2Config.General.UseExistingEnv { - if err := testEnv.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := testEnv.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -696,7 +696,7 @@ func TestVRFOwner(t *testing.T) { } } if !*vrfv2Config.General.UseExistingEnv { - if err := testEnv.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := testEnv.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -829,7 +829,7 @@ func TestVRFV2WithBHS(t *testing.T) { } } if !*vrfv2Config.General.UseExistingEnv { - if err := testEnv.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := testEnv.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -1033,7 +1033,7 @@ func TestVRFV2NodeReorg(t *testing.T) { } } if !*vrfv2Config.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -1193,7 +1193,7 @@ func TestVRFv2BatchFulfillmentEnabledDisabled(t *testing.T) { } } if !*vrfv2Config.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } diff --git a/integration-tests/smoke/vrfv2plus_test.go b/integration-tests/smoke/vrfv2plus_test.go index 51fa276893d..d3b2b715559 100644 --- a/integration-tests/smoke/vrfv2plus_test.go +++ b/integration-tests/smoke/vrfv2plus_test.go @@ -63,7 +63,7 @@ func TestVRFv2Plus(t *testing.T) { } } if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -85,6 +85,7 @@ func TestVRFv2Plus(t *testing.T) { configCopy := config.MustCopy().(tc.TestConfig) var isNativeBilling = false consumers, subIDsForRequestRandomness, err := vrfv2plus.SetupNewConsumersAndSubs( + testcontext.Get(t), env, chainID, vrfContracts.CoordinatorV2Plus, @@ -142,7 +143,9 @@ func TestVRFv2Plus(t *testing.T) { var isNativeBilling = true consumers, subIDs, err := vrfv2plus.SetupNewConsumersAndSubs( + testcontext.Get(t), env, + chainID, vrfContracts.CoordinatorV2Plus, configCopy, @@ -197,6 +200,7 @@ func TestVRFv2Plus(t *testing.T) { var isNativeBilling = true consumers, subIDs, err := vrfv2plus.SetupNewConsumersAndSubs( + testcontext.Get(t), env, chainID, vrfContracts.CoordinatorV2Plus, @@ -239,6 +243,7 @@ func TestVRFv2Plus(t *testing.T) { configCopy := config.MustCopy().(tc.TestConfig) var isNativeBilling = false consumers, subIDsForRequestRandomness, err := vrfv2plus.SetupNewConsumersAndSubs( + testcontext.Get(t), env, chainID, vrfContracts.CoordinatorV2Plus, @@ -392,6 +397,7 @@ func TestVRFv2Plus(t *testing.T) { t.Run("Canceling Sub And Returning Funds", func(t *testing.T) { configCopy := config.MustCopy().(tc.TestConfig) _, subIDs, err := vrfv2plus.SetupNewConsumersAndSubs( + testcontext.Get(t), env, chainID, vrfContracts.CoordinatorV2Plus, @@ -499,6 +505,7 @@ func TestVRFv2Plus(t *testing.T) { testConfig.SubscriptionFundingAmountLink = ptr.Ptr(float64(0)) consumers, subIDs, err := vrfv2plus.SetupNewConsumersAndSubs( + testcontext.Get(t), env, chainID, vrfContracts.CoordinatorV2Plus, @@ -647,6 +654,7 @@ func TestVRFv2Plus(t *testing.T) { t.Run("Owner Withdraw", func(t *testing.T) { configCopy := config.MustCopy().(tc.TestConfig) consumers, subIDs, err := vrfv2plus.SetupNewConsumersAndSubs( + testcontext.Get(t), env, chainID, vrfContracts.CoordinatorV2Plus, @@ -755,7 +763,7 @@ func TestVRFv2PlusMultipleSendingKeys(t *testing.T) { } } if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -775,6 +783,7 @@ func TestVRFv2PlusMultipleSendingKeys(t *testing.T) { var isNativeBilling = true consumers, subIDs, err := vrfv2plus.SetupNewConsumersAndSubs( + testcontext.Get(t), env, chainID, vrfContracts.CoordinatorV2Plus, @@ -857,7 +866,7 @@ func TestVRFv2PlusMigration(t *testing.T) { } } if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -882,6 +891,7 @@ func TestVRFv2PlusMigration(t *testing.T) { configCopy := config.MustCopy().(tc.TestConfig) consumers, subIDs, err := vrfv2plus.SetupNewConsumersAndSubs( + testcontext.Get(t), env, chainID, vrfContracts.CoordinatorV2Plus, @@ -1253,7 +1263,7 @@ func TestVRFV2PlusWithBHS(t *testing.T) { } } if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -1285,6 +1295,7 @@ func TestVRFV2PlusWithBHS(t *testing.T) { configCopy.VRFv2Plus.General.SubscriptionFundingAmountNative = ptr.Ptr(float64(0)) consumers, subIDs, err := vrfv2plus.SetupNewConsumersAndSubs( + testcontext.Get(t), env, chainID, vrfContracts.CoordinatorV2Plus, @@ -1358,6 +1369,7 @@ func TestVRFV2PlusWithBHS(t *testing.T) { configCopy.VRFv2Plus.General.SubscriptionFundingAmountNative = ptr.Ptr(float64(0)) consumers, subIDs, err := vrfv2plus.SetupNewConsumersAndSubs( + testcontext.Get(t), env, chainID, vrfContracts.CoordinatorV2Plus, @@ -1464,7 +1476,7 @@ func TestVRFV2PlusWithBHF(t *testing.T) { } } if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -1499,6 +1511,7 @@ func TestVRFV2PlusWithBHF(t *testing.T) { configCopy.VRFv2Plus.General.SubscriptionFundingAmountNative = ptr.Ptr(float64(0)) consumers, subIDs, err := vrfv2plus.SetupNewConsumersAndSubs( + testcontext.Get(t), env, chainID, vrfContracts.CoordinatorV2Plus, @@ -1609,7 +1622,7 @@ func TestVRFv2PlusReplayAfterTimeout(t *testing.T) { } } if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -1635,6 +1648,7 @@ func TestVRFv2PlusReplayAfterTimeout(t *testing.T) { var isNativeBilling = false consumers, subIDs, err := vrfv2plus.SetupNewConsumersAndSubs( + testcontext.Get(t), env, chainID, vrfContracts.CoordinatorV2Plus, @@ -1671,6 +1685,7 @@ func TestVRFv2PlusReplayAfterTimeout(t *testing.T) { Int("Number of Subs to create", 1). Msg("Creating and funding subscriptions, adding consumers") fundedSubIDs, err := vrfv2plus.CreateFundSubsAndAddConsumers( + testcontext.Get(t), env, chainID, fundingLinkAmt, @@ -1801,7 +1816,7 @@ func TestVRFv2PlusPendingBlockSimulationAndZeroConfirmationDelays(t *testing.T) } } if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -1821,6 +1836,7 @@ func TestVRFv2PlusPendingBlockSimulationAndZeroConfirmationDelays(t *testing.T) require.NoError(t, err, "error setting up VRFV2Plus universe") consumers, subIDs, err := vrfv2plus.SetupNewConsumersAndSubs( + testcontext.Get(t), env, chainID, vrfContracts.CoordinatorV2Plus, @@ -1889,7 +1905,7 @@ func TestVRFv2PlusNodeReorg(t *testing.T) { } } if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -1910,6 +1926,7 @@ func TestVRFv2PlusNodeReorg(t *testing.T) { require.NoError(t, err, "Getting Seth client shouldn't fail") consumers, subIDs, err := vrfv2plus.SetupNewConsumersAndSubs( + testcontext.Get(t), env, chainID, vrfContracts.CoordinatorV2Plus, @@ -2047,7 +2064,7 @@ func TestVRFv2PlusBatchFulfillmentEnabledDisabled(t *testing.T) { } } if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -2115,6 +2132,7 @@ func TestVRFv2PlusBatchFulfillmentEnabledDisabled(t *testing.T) { vrfNode.Job = job consumers, subIDs, err := vrfv2plus.SetupNewConsumersAndSubs( + testcontext.Get(t), env, chainID, vrfContracts.CoordinatorV2Plus, @@ -2229,6 +2247,7 @@ func TestVRFv2PlusBatchFulfillmentEnabledDisabled(t *testing.T) { vrfNode.Job = job consumers, subIDs, err := vrfv2plus.SetupNewConsumersAndSubs( + testcontext.Get(t), env, chainID, vrfContracts.CoordinatorV2Plus, From dbe63f86f64215dc90dc9fe01cacedcd2823f7c9 Mon Sep 17 00:00:00 2001 From: Bartek Tofel Date: Fri, 10 May 2024 11:57:39 +0200 Subject: [PATCH 26/43] use latest Seth that estimates gas for funds sending --- integration-tests/actions/seth/actions.go | 25 ++++++++++++------- .../actions/vrf/vrfv2plus/setup_steps.go | 4 +-- integration-tests/go.mod | 2 +- integration-tests/go.sum | 4 +-- integration-tests/load/go.mod | 2 +- integration-tests/load/go.sum | 4 +-- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/integration-tests/actions/seth/actions.go b/integration-tests/actions/seth/actions.go index 43b71d317d2..199f7e0fb06 100644 --- a/integration-tests/actions/seth/actions.go +++ b/integration-tests/actions/seth/actions.go @@ -183,20 +183,27 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa return nil, err } - gasLimit := uint64(client.Cfg.Network.TransferGasFee) + var gasLimit int64 + gasLimitRaw, err := client.EstimateGasLimitForFundTransfer(fromAddress, payload.ToAddress, payload.Amount) + if err != nil { + gasLimit = client.Cfg.Network.TransferGasFee + } else { + gasLimit = int64(gasLimitRaw) + } + gasPrice := big.NewInt(0) gasFeeCap := big.NewInt(0) gasTipCap := big.NewInt(0) if payload.GasLimit != nil { - gasLimit = uint64(*payload.GasLimit) + gasLimit = *payload.GasLimit } if client.Cfg.Network.EIP1559DynamicFees { // if any of the dynamic fees are not set, we need to either estimate them or read them from config if payload.GasFeeCap == nil || payload.GasTipCap == nil { - // estimatior or config reading happens here - txOptions := client.NewTXOpts(seth.WithGasLimit(gasLimit)) + // estimation or config reading happens here + txOptions := client.NewTXOpts(seth.WithGasLimit(uint64(gasLimit))) gasFeeCap = txOptions.GasFeeCap gasTipCap = txOptions.GasTipCap } @@ -211,7 +218,7 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa } } else { if payload.GasPrice == nil { - txOptions := client.NewTXOpts((seth.WithGasLimit(gasLimit))) + txOptions := client.NewTXOpts(seth.WithGasLimit(uint64(gasLimit))) gasPrice = txOptions.GasPrice } else { gasPrice = payload.GasPrice @@ -225,7 +232,7 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa Nonce: nonce, To: &payload.ToAddress, Value: payload.Amount, - Gas: gasLimit, + Gas: uint64(gasLimit), GasFeeCap: gasFeeCap, GasTipCap: gasTipCap, } @@ -234,7 +241,7 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa Nonce: nonce, To: &payload.ToAddress, Value: payload.Amount, - Gas: gasLimit, + Gas: uint64(gasLimit), GasPrice: gasPrice, } } @@ -255,7 +262,7 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa Str("To", payload.ToAddress.Hex()). Str("Amount (wei/ether)", fmt.Sprintf("%s/%s", payload.Amount, conversions.WeiToEther(payload.Amount).Text('f', -1))). Uint64("Nonce", nonce). - Uint64("Gas Limit", gasLimit). + Int64("Gas Limit", gasLimit). Str("Gas Price", gasPrice.String()). Str("Gas Fee Cap", gasFeeCap.String()). Str("Gas Tip Cap", gasTipCap.String()). @@ -275,7 +282,7 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa Str("TxHash", signedTx.Hash().String()). Str("Amount (wei/ether)", fmt.Sprintf("%s/%s", payload.Amount, conversions.WeiToEther(payload.Amount).Text('f', -1))). Uint64("Nonce", nonce). - Uint64("Gas Limit", gasLimit). + Int64("Gas Limit", gasLimit). Str("Gas Price", gasPrice.String()). Str("Gas Fee Cap", gasFeeCap.String()). Str("Gas Tip Cap", gasTipCap.String()). diff --git a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go index c6abb6b034c..27ae6271524 100644 --- a/integration-tests/actions/vrf/vrfv2plus/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/setup_steps.go @@ -333,13 +333,11 @@ func SetupVRFV2PlusWrapperEnvironment( return nil, nil, err } - //fund consumer with Eth - gasLimit := int64(2 * 21000) + //fund consumer with Eth (native token) _, err = actions_seth.SendFunds(l, sethClient, actions_seth.FundsToSendPayload{ ToAddress: common.HexToAddress(wrapperContracts.LoadTestConsumers[0].Address()), Amount: conversions.EtherToWei(big.NewFloat(*vrfv2PlusConfig.WrapperConsumerFundingAmountNativeToken)), PrivateKey: sethClient.PrivateKeys[0], - GasLimit: &gasLimit, }) if err != nil { return nil, nil, err diff --git a/integration-tests/go.mod b/integration-tests/go.mod index b376dcdb3a4..3aff4420940 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -31,7 +31,7 @@ require ( github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868 github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000 github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c - github.com/smartcontractkit/seth v0.1.6-0.20240429143720-cacb8160ecec + github.com/smartcontractkit/seth v1.0.9 github.com/smartcontractkit/wasp v0.4.5 github.com/spf13/cobra v1.8.0 github.com/stretchr/testify v1.9.0 diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 9fcb97899ce..a465230e5df 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -1540,8 +1540,8 @@ github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJ github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0= github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c h1:lIyMbTaF2H0Q71vkwZHX/Ew4KF2BxiKhqEXwF8rn+KI= github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c/go.mod h1:fb1ZDVXACvu4frX3APHZaEBp0xi1DIm34DcA0CwTsZM= -github.com/smartcontractkit/seth v0.1.6-0.20240429143720-cacb8160ecec h1:BT1loU6TT2YqMenD7XE+aw7IeeTiC25+r1TLKAySVIg= -github.com/smartcontractkit/seth v0.1.6-0.20240429143720-cacb8160ecec/go.mod h1:2TMOZQ8WTAw7rR1YBbXpnad6VmT/+xDd/nXLmB7Eero= +github.com/smartcontractkit/seth v1.0.9 h1:v+gxRY5JT9u4Ptk1mg/Sm76aqdG2vFw1zq1Ngwoj6yk= +github.com/smartcontractkit/seth v1.0.9/go.mod h1:2TMOZQ8WTAw7rR1YBbXpnad6VmT/+xDd/nXLmB7Eero= github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 h1:yiKnypAqP8l0OX0P3klzZ7SCcBUxy5KqTAKZmQOvSQE= github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1/go.mod h1:q6f4fe39oZPdsh1i57WznEZgxd8siidMaSFq3wdPmVg= github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1 h1:Dai1bn+Q5cpeGMQwRdjOdVjG8mmFFROVkSKuUgBErRQ= diff --git a/integration-tests/load/go.mod b/integration-tests/load/go.mod index c74b9599b8b..2e817d4311f 100644 --- a/integration-tests/load/go.mod +++ b/integration-tests/load/go.mod @@ -21,7 +21,7 @@ require ( github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20240214231432-4ad5eb95178c github.com/smartcontractkit/chainlink/v2 v2.9.0-beta0.0.20240216210048-da02459ddad8 github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c - github.com/smartcontractkit/seth v0.1.6-0.20240429143720-cacb8160ecec + github.com/smartcontractkit/seth v1.0.9 github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1 github.com/smartcontractkit/wasp v0.4.6 github.com/stretchr/testify v1.9.0 diff --git a/integration-tests/load/go.sum b/integration-tests/load/go.sum index 98297e49cc2..53ecdfc8a4e 100644 --- a/integration-tests/load/go.sum +++ b/integration-tests/load/go.sum @@ -1524,8 +1524,8 @@ github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJ github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0= github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c h1:lIyMbTaF2H0Q71vkwZHX/Ew4KF2BxiKhqEXwF8rn+KI= github.com/smartcontractkit/libocr v0.0.0-20240419185742-fd3cab206b2c/go.mod h1:fb1ZDVXACvu4frX3APHZaEBp0xi1DIm34DcA0CwTsZM= -github.com/smartcontractkit/seth v0.1.6-0.20240429143720-cacb8160ecec h1:BT1loU6TT2YqMenD7XE+aw7IeeTiC25+r1TLKAySVIg= -github.com/smartcontractkit/seth v0.1.6-0.20240429143720-cacb8160ecec/go.mod h1:2TMOZQ8WTAw7rR1YBbXpnad6VmT/+xDd/nXLmB7Eero= +github.com/smartcontractkit/seth v1.0.9 h1:v+gxRY5JT9u4Ptk1mg/Sm76aqdG2vFw1zq1Ngwoj6yk= +github.com/smartcontractkit/seth v1.0.9/go.mod h1:2TMOZQ8WTAw7rR1YBbXpnad6VmT/+xDd/nXLmB7Eero= github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 h1:yiKnypAqP8l0OX0P3klzZ7SCcBUxy5KqTAKZmQOvSQE= github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1/go.mod h1:q6f4fe39oZPdsh1i57WznEZgxd8siidMaSFq3wdPmVg= github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1 h1:Dai1bn+Q5cpeGMQwRdjOdVjG8mmFFROVkSKuUgBErRQ= From 702df4a34ff96a4daef194982f717abc3fc7fcb0 Mon Sep 17 00:00:00 2001 From: Ilja Pavlovs Date: Sun, 12 May 2024 20:19:58 +0300 Subject: [PATCH 27/43] adding Polygon Amoy and Arb Sepolia with default config; small refactoring --- integration-tests/actions/actions.go | 26 ++++++--- integration-tests/load/vrfv2/vrfv2_test.go | 9 ++- .../load/vrfv2plus/vrfv2plus_test.go | 11 +++- integration-tests/smoke/vrfv2_test.go | 18 +++++- integration-tests/smoke/vrfv2plus_test.go | 27 ++++++++- integration-tests/testconfig/default.toml | 57 ++++++++++++++++++- 6 files changed, 130 insertions(+), 18 deletions(-) diff --git a/integration-tests/actions/actions.go b/integration-tests/actions/actions.go index 912c5eabf9b..d666a497666 100644 --- a/integration-tests/actions/actions.go +++ b/integration-tests/actions/actions.go @@ -501,42 +501,50 @@ func DecodeTxInputData(abiString string, data []byte) (map[string]interface{}, e return inputsMap, nil } -// todo - move to EVMClient +// todo - move to CTF func WaitForBlockNumberToBe( waitForBlockNumberToBe uint64, client *seth.Client, wg *sync.WaitGroup, timeout time.Duration, t testing.TB, + l zerolog.Logger, ) (uint64, error) { blockNumberChannel := make(chan uint64) errorChannel := make(chan error) testContext, testCancel := context.WithTimeout(context.Background(), timeout) defer testCancel() - - ticker := time.NewTicker(time.Second * 1) - var blockNumber uint64 + ticker := time.NewTicker(time.Second * 5) + var latestBlockNumber uint64 for { select { case <-testContext.Done(): ticker.Stop() wg.Done() - return blockNumber, + return latestBlockNumber, fmt.Errorf("timeout waiting for Block Number to be: %d. Last recorded block number was: %d", - waitForBlockNumberToBe, blockNumber) + waitForBlockNumberToBe, latestBlockNumber) case <-ticker.C: go func() { currentBlockNumber, err := client.Client.BlockNumber(testcontext.Get(t)) if err != nil { errorChannel <- err } + l.Info(). + Uint64("Latest Block Number", currentBlockNumber). + Uint64("Desired Block Number", waitForBlockNumberToBe). + Msg("Waiting for Block Number to be") blockNumberChannel <- currentBlockNumber }() - case blockNumber = <-blockNumberChannel: - if blockNumber == waitForBlockNumberToBe { + case latestBlockNumber = <-blockNumberChannel: + if latestBlockNumber >= waitForBlockNumberToBe { ticker.Stop() wg.Done() - return blockNumber, nil + l.Info(). + Uint64("Latest Block Number", latestBlockNumber). + Uint64("Desired Block Number", waitForBlockNumberToBe). + Msg("Desired Block Number reached!") + return latestBlockNumber, nil } case err := <-errorChannel: ticker.Stop() diff --git a/integration-tests/load/vrfv2/vrfv2_test.go b/integration-tests/load/vrfv2/vrfv2_test.go index 709e3cbafc5..a541784da58 100644 --- a/integration-tests/load/vrfv2/vrfv2_test.go +++ b/integration-tests/load/vrfv2/vrfv2_test.go @@ -300,7 +300,14 @@ func TestVRFV2BHSPerformance(t *testing.T) { require.NoError(t, err, "Getting Seth client shouldn't fail") latestBlockNumber, err := sethClient.Client.BlockNumber(testcontext.Get(t)) require.NoError(t, err) - _, err = actions.WaitForBlockNumberToBe(latestBlockNumber+uint64(256), sethClient, &wgBlockNumberTobe, configCopy.VRFv2.General.WaitFor256BlocksTimeout.Duration, t) + _, err = actions.WaitForBlockNumberToBe( + latestBlockNumber+uint64(256), + sethClient, + &wgBlockNumberTobe, + configCopy.VRFv2.General.WaitFor256BlocksTimeout.Duration, + t, + l, + ) wgBlockNumberTobe.Wait() require.NoError(t, err, "error waiting for block number to be") diff --git a/integration-tests/load/vrfv2plus/vrfv2plus_test.go b/integration-tests/load/vrfv2plus/vrfv2plus_test.go index d53e79a3a54..fed9243b7f3 100644 --- a/integration-tests/load/vrfv2plus/vrfv2plus_test.go +++ b/integration-tests/load/vrfv2plus/vrfv2plus_test.go @@ -226,7 +226,7 @@ func TestVRFV2PlusBHSPerformance(t *testing.T) { } newEnvConfig := vrfcommon.NewEnvConfig{ - NodesToCreate: []vrfcommon.VRFNodeType{vrfcommon.VRF}, + NodesToCreate: []vrfcommon.VRFNodeType{vrfcommon.VRF, vrfcommon.BHS}, NumberOfTxKeysToCreate: *vrfv2PlusConfig.General.NumberOfSendingKeysToCreate, } @@ -297,7 +297,14 @@ func TestVRFV2PlusBHSPerformance(t *testing.T) { require.NoError(t, err, "Getting Seth client shouldn't fail") latestBlockNumber, err := sethClient.Client.BlockNumber(testcontext.Get(t)) require.NoError(t, err, "error getting latest block number") - _, err = actions.WaitForBlockNumberToBe(latestBlockNumber+uint64(256), sethClient, &wgBlockNumberTobe, configCopy.VRFv2Plus.General.WaitFor256BlocksTimeout.Duration, t) + _, err = actions.WaitForBlockNumberToBe( + latestBlockNumber+uint64(256), + sethClient, + &wgBlockNumberTobe, + configCopy.VRFv2Plus.General.WaitFor256BlocksTimeout.Duration, + t, + l, + ) wgBlockNumberTobe.Wait() require.NoError(t, err, "error waiting for block number to be") diff --git a/integration-tests/smoke/vrfv2_test.go b/integration-tests/smoke/vrfv2_test.go index f2335f899f5..c0679c560c7 100644 --- a/integration-tests/smoke/vrfv2_test.go +++ b/integration-tests/smoke/vrfv2_test.go @@ -894,7 +894,14 @@ func TestVRFV2WithBHS(t *testing.T) { //Wait at least 256 blocks sethClient, err := testEnv.GetSethClient(chainID) require.NoError(t, err, "Getting Seth client shouldn't fail") - _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(257), sethClient, &wg, time.Second*260, t) + _, err = actions.WaitForBlockNumberToBe( + randRequestBlockNumber+uint64(257), + sethClient, + &wg, + time.Second*260, + t, + l, + ) wg.Wait() require.NoError(t, err) err = vrfv2.FundSubscriptions(big.NewFloat(*configCopy.VRFv2.General.SubscriptionFundingAmountLink), vrfContracts.LinkToken, vrfContracts.CoordinatorV2, subIDsForBHS) @@ -960,7 +967,14 @@ func TestVRFV2WithBHS(t *testing.T) { var wg sync.WaitGroup wg.Add(1) - _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(*configCopy.VRFv2.General.BHSJobWaitBlocks), sethClient, &wg, time.Minute*1, t) + _, err = actions.WaitForBlockNumberToBe( + randRequestBlockNumber+uint64(*configCopy.VRFv2.General.BHSJobWaitBlocks), + sethClient, + &wg, + time.Minute*1, + t, + l, + ) wg.Wait() require.NoError(t, err, "error waiting for blocknumber to be") diff --git a/integration-tests/smoke/vrfv2plus_test.go b/integration-tests/smoke/vrfv2plus_test.go index 51fa276893d..c2b565e46e7 100644 --- a/integration-tests/smoke/vrfv2plus_test.go +++ b/integration-tests/smoke/vrfv2plus_test.go @@ -1316,7 +1316,14 @@ func TestVRFV2PlusWithBHS(t *testing.T) { var wg sync.WaitGroup wg.Add(1) //Wait at least 256 blocks - _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(257), sethClient, &wg, time.Second*260, t) + _, err = actions.WaitForBlockNumberToBe( + randRequestBlockNumber+uint64(257), + sethClient, + &wg, + time.Second*260, + t, + l, + ) wg.Wait() require.NoError(t, err) err = vrfv2plus.FundSubscriptions( @@ -1391,7 +1398,14 @@ func TestVRFV2PlusWithBHS(t *testing.T) { var wg sync.WaitGroup wg.Add(1) - _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(*configCopy.VRFv2Plus.General.BHSJobWaitBlocks+10), sethClient, &wg, time.Minute*1, t) + _, err = actions.WaitForBlockNumberToBe( + randRequestBlockNumber+uint64(*configCopy.VRFv2Plus.General.BHSJobWaitBlocks+10), + sethClient, + &wg, + time.Minute*1, + t, + l, + ) wg.Wait() require.NoError(t, err, "error waiting for blocknumber to be") @@ -1530,7 +1544,14 @@ func TestVRFV2PlusWithBHF(t *testing.T) { var wg sync.WaitGroup wg.Add(1) //Wait at least 260 blocks - _, err = actions.WaitForBlockNumberToBe(randRequestBlockNumber+uint64(260), sethClient, &wg, time.Second*262, t) + _, err = actions.WaitForBlockNumberToBe( + randRequestBlockNumber+uint64(260), + sethClient, + &wg, + time.Second*262, + t, + l, + ) wg.Wait() require.NoError(t, err) l.Info().Float64("SubscriptionFundingAmountNative", *configCopy.VRFv2Plus.General.SubscriptionRefundingAmountNative). diff --git a/integration-tests/testconfig/default.toml b/integration-tests/testconfig/default.toml index ef3f60d4282..50cc74e4154 100644 --- a/integration-tests/testconfig/default.toml +++ b/integration-tests/testconfig/default.toml @@ -203,4 +203,59 @@ gas_price = 50_000_000 # EIP-1559 transactions gas_fee_cap = 3_800_000_000 -gas_tip_cap = 1_800_000_000 \ No newline at end of file +gas_tip_cap = 1_800_000_000 + + +[[Seth.networks]] +name = "ARBITRUM_SEPOLIA" +chain_id = "421614" +transaction_timeout = "1m" + +# if set to true we will estimate gas for every transaction +gas_price_estimation_enabled = true + +# transfer_gas_fee is gas limit that will be used, when funding CL nodes and returning funds from there and when funding and returning funds from ephemeral keys +# we use hardcoded value in order to be estimate how much funds are available for sending or returning after tx costs have been paid +transfer_gas_fee = 50_000 +# gas limit should be explicitly set only if you are connecting to a node that's incapable of estimating gas limit itself (should only happen for very old versions) +# gas_limit = 100_000_000 + +# manual settings, used when gas_price_estimation_enabled is false or when it fails +# legacy transactions +gas_price = 50_000_000_000 +# EIP-1559 transactions +eip_1559_dynamic_fees = true +gas_fee_cap = 50_000_000_000 +gas_tip_cap = 2_000_000_000 + +# how many last blocks to use, when estimating gas for a transaction +gas_price_estimation_blocks = 100 +# priority of the transaction, can be "fast", "standard" or "slow" (the higher the priority, the higher adjustment factor will be used for gas estimation) [default: "standard"] +gas_price_estimation_tx_priority = "standard" + +[[Seth.networks]] +name = "POLYGON_AMOY" +chain_id = "80002" +transaction_timeout = "1m" + +# if set to true we will estimate gas for every transaction +gas_price_estimation_enabled = true + +# transfer_gas_fee is gas limit that will be used, when funding CL nodes and returning funds from there and when funding and returning funds from ephemeral keys +# we use hardcoded value in order to be estimate how much funds are available for sending or returning after tx costs have been paid +transfer_gas_fee = 21_000 +# gas limit should be explicitly set only if you are connecting to a node that's incapable of estimating gas limit itself (should only happen for very old versions) +# gas_limit = 100_000_000 + +# manual settings, used when gas_price_estimation_enabled is false or when it fails +# legacy transactions +gas_price = 200_000_000_000 +# EIP-1559 transactions +eip_1559_dynamic_fees = true +gas_fee_cap = 200_000_000_000 +gas_tip_cap = 2_000_000_000 + +# how many last blocks to use, when estimating gas for a transaction +gas_price_estimation_blocks = 100 +# priority of the transaction, can be "fast", "standard" or "slow" (the higher the priority, the higher adjustment factor will be used for gas estimation) [default: "standard"] +gas_price_estimation_tx_priority = "standard" From 3703d86149ebf8a38496a7538ed9a0e68518e3ab Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Mon, 13 May 2024 11:03:14 +0200 Subject: [PATCH 28/43] Fix passing wrapped contract backend --- integration-tests/contracts/contract_loader.go | 5 +++-- integration-tests/contracts/ethereum_contracts_seth.go | 2 +- integration-tests/contracts/ethereum_vrfv2_contracts.go | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/integration-tests/contracts/contract_loader.go b/integration-tests/contracts/contract_loader.go index 5609b01ad6f..a81643b17c0 100644 --- a/integration-tests/contracts/contract_loader.go +++ b/integration-tests/contracts/contract_loader.go @@ -6,6 +6,7 @@ import ( "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink/integration-tests/wrappers" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2_5" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_v2plus_load_test_with_metrics" @@ -371,7 +372,7 @@ func LoadVRFCoordinatorV2_5(seth *seth.Client, addr string) (VRFCoordinatorV2_5, seth.ContractStore.AddABI("VRFCoordinatorV2_5", *abi) seth.ContractStore.AddBIN("VRFCoordinatorV2_5", common.FromHex(vrf_coordinator_v2_5.VRFCoordinatorV25MetaData.Bin)) - contract, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(address, seth.Client) + contract, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(address, wrappers.MustNewWrappedContractBackend(nil, seth)) if err != nil { return &EthereumVRFCoordinatorV2_5{}, fmt.Errorf("failed to instantiate VRFCoordinatorV2_5 instance: %w", err) } @@ -392,7 +393,7 @@ func LoadVRFv2PlusLoadTestConsumer(seth *seth.Client, addr string) (VRFv2PlusLoa seth.ContractStore.AddABI("VRFV2PlusLoadTestWithMetrics", *abi) seth.ContractStore.AddBIN("VRFV2PlusLoadTestWithMetrics", common.FromHex(vrf_v2plus_load_test_with_metrics.VRFV2PlusLoadTestWithMetricsMetaData.Bin)) - contract, err := vrf_v2plus_load_test_with_metrics.NewVRFV2PlusLoadTestWithMetrics(address, seth.Client) + contract, err := vrf_v2plus_load_test_with_metrics.NewVRFV2PlusLoadTestWithMetrics(address, wrappers.MustNewWrappedContractBackend(nil, seth)) if err != nil { return &EthereumVRFv2PlusLoadTestConsumer{}, fmt.Errorf("failed to instantiate VRFV2PlusLoadTestWithMetrics instance: %w", err) } diff --git a/integration-tests/contracts/ethereum_contracts_seth.go b/integration-tests/contracts/ethereum_contracts_seth.go index 97201c47bdf..20711e1537d 100644 --- a/integration-tests/contracts/ethereum_contracts_seth.go +++ b/integration-tests/contracts/ethereum_contracts_seth.go @@ -51,7 +51,7 @@ func LoadOffchainAggregator(l zerolog.Logger, seth *seth.Client, contractAddress seth.ContractStore.AddABI("OffChainAggregator", *abi) seth.ContractStore.AddBIN("OffChainAggregator", common.FromHex(offchainaggregator.OffchainAggregatorMetaData.Bin)) - ocr, err := offchainaggregator.NewOffchainAggregator(contractAddress, seth.Client) + ocr, err := offchainaggregator.NewOffchainAggregator(contractAddress, wrappers.MustNewWrappedContractBackend(nil, seth)) if err != nil { return EthereumOffchainAggregator{}, fmt.Errorf("failed to instantiate OCR instance: %w", err) } diff --git a/integration-tests/contracts/ethereum_vrfv2_contracts.go b/integration-tests/contracts/ethereum_vrfv2_contracts.go index e29fc36fa83..f5259a38093 100644 --- a/integration-tests/contracts/ethereum_vrfv2_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2_contracts.go @@ -131,7 +131,7 @@ func LoadVRFCoordinatorV2(seth *seth.Client, address string) (*EthereumVRFCoordi seth.ContractStore.AddABI("VRFCoordinatorV2", *abi) seth.ContractStore.AddBIN("VRFCoordinatorV2", common.FromHex(vrf_coordinator_v2.VRFCoordinatorV2MetaData.Bin)) - contract, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(address), seth.Client) + contract, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(address), wrappers.MustNewWrappedContractBackend(nil, seth)) if err != nil { return &EthereumVRFCoordinatorV2{}, fmt.Errorf("failed to instantiate VRFCoordinatorV2 instance: %w", err) } @@ -297,7 +297,7 @@ func LoadVRFv2LoadTestConsumer(seth *seth.Client, addr common.Address) (VRFv2Loa seth.ContractStore.AddABI("VRFV2LoadTestWithMetrics", *abi) seth.ContractStore.AddBIN("VRFV2LoadTestWithMetrics", common.FromHex(vrf_load_test_with_metrics.VRFV2LoadTestWithMetricsMetaData.Bin)) - contract, err := vrf_load_test_with_metrics.NewVRFV2LoadTestWithMetrics(addr, seth.Client) + contract, err := vrf_load_test_with_metrics.NewVRFV2LoadTestWithMetrics(addr, wrappers.MustNewWrappedContractBackend(nil, seth)) if err != nil { return &EthereumVRFv2LoadTestConsumer{}, fmt.Errorf("failed to instantiate VRFV2LoadTestWithMetrics instance: %w", err) } @@ -817,7 +817,7 @@ func (v *EthereumVRFConsumerV2) LoadExistingConsumer(seth *seth.Client, address seth.ContractStore.AddABI("VRFConsumerV2", *abi) seth.ContractStore.AddBIN("VRFConsumerV2", common.FromHex(vrf_consumer_v2.VRFConsumerV2MetaData.Bin)) - contract, err := vrf_consumer_v2.NewVRFConsumerV2(address, seth.Client) + contract, err := vrf_consumer_v2.NewVRFConsumerV2(address, wrappers.MustNewWrappedContractBackend(nil, seth)) if err != nil { return fmt.Errorf("failed to instantiate VRFConsumerV2 instance: %w", err) } From 340ddac38da63f9e789b06c47cee1fadaa1be23b Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Mon, 13 May 2024 11:08:32 +0200 Subject: [PATCH 29/43] Use MustGetRootKeyAddress() --- .../actions/vrf/vrfv2/setup_steps.go | 2 +- .../contracts/ethereum_ocr2vrf_contracts.go | 10 +-- .../contracts/ethereum_vrf_contracts_seth.go | 10 +-- .../contracts/ethereum_vrfv2_contracts.go | 66 ++++++++--------- .../contracts/ethereum_vrfv2plus_contracts.go | 70 +++++++++---------- integration-tests/load/vrfv2/vrfv2_test.go | 4 +- .../load/vrfv2plus/vrfv2plus_test.go | 4 +- integration-tests/smoke/vrfv2_test.go | 22 +++--- integration-tests/smoke/vrfv2plus_test.go | 40 +++++------ 9 files changed, 114 insertions(+), 114 deletions(-) diff --git a/integration-tests/actions/vrf/vrfv2/setup_steps.go b/integration-tests/actions/vrf/vrfv2/setup_steps.go index 34ed3553ccc..27de1135528 100644 --- a/integration-tests/actions/vrf/vrfv2/setup_steps.go +++ b/integration-tests/actions/vrf/vrfv2/setup_steps.go @@ -377,7 +377,7 @@ func SetupVRFV2ForNewEnv( linkToken, mockETHLinkFeed, //register proving key against EOA address in order to return funds to this address - sethClient.Addresses[0].Hex(), + sethClient.MustGetRootKeyAddress().Hex(), newEnvConfig.NumberOfTxKeysToCreate, l, ) diff --git a/integration-tests/contracts/ethereum_ocr2vrf_contracts.go b/integration-tests/contracts/ethereum_ocr2vrf_contracts.go index 32bd7c14a95..4ef0740fdbc 100644 --- a/integration-tests/contracts/ethereum_ocr2vrf_contracts.go +++ b/integration-tests/contracts/ethereum_ocr2vrf_contracts.go @@ -307,7 +307,7 @@ func (coordinator *EthereumVRFCoordinatorV3) CreateSubscription() error { func (coordinator *EthereumVRFCoordinatorV3) FindSubscriptionID() (*big.Int, error) { fopts := &bind.FilterOpts{} - owner := coordinator.client.Addresses[0] + owner := coordinator.client.MustGetRootKeyAddress() subscriptionIterator, err := coordinator.vrfCoordinatorV3.FilterSubscriptionCreated( fopts, @@ -421,7 +421,7 @@ func (beacon *EthereumVRFBeacon) WaitForNewTransmissionEvent(timeout time.Durati func (beacon *EthereumVRFBeacon) LatestConfigDigestAndEpoch(ctx context.Context) (vrf_beacon.LatestConfigDigestAndEpoch, error) { opts := &bind.CallOpts{ - From: beacon.client.Addresses[0], + From: beacon.client.MustGetRootKeyAddress(), Context: ctx, } return beacon.vrfBeacon.LatestConfigDigestAndEpoch(opts) @@ -500,7 +500,7 @@ func (consumer *EthereumVRFBeaconConsumer) RequestRandomnessFulfillment( func (consumer *EthereumVRFBeaconConsumer) IBeaconPeriodBlocks(ctx context.Context) (*big.Int, error) { opts := &bind.CallOpts{ - From: consumer.client.Addresses[0], + From: consumer.client.MustGetRootKeyAddress(), Context: ctx, } return consumer.vrfBeaconConsumer.IBeaconPeriodBlocks(opts) @@ -508,7 +508,7 @@ func (consumer *EthereumVRFBeaconConsumer) IBeaconPeriodBlocks(ctx context.Conte func (consumer *EthereumVRFBeaconConsumer) GetRequestIdsBy(ctx context.Context, nextBeaconOutputHeight *big.Int, confDelay *big.Int) (*big.Int, error) { opts := &bind.CallOpts{ - From: consumer.client.Addresses[0], + From: consumer.client.MustGetRootKeyAddress(), Context: ctx, } return consumer.vrfBeaconConsumer.SRequestsIDs(opts, nextBeaconOutputHeight, confDelay) @@ -516,7 +516,7 @@ func (consumer *EthereumVRFBeaconConsumer) GetRequestIdsBy(ctx context.Context, func (consumer *EthereumVRFBeaconConsumer) GetRandomnessByRequestId(ctx context.Context, requestID *big.Int, numWordIndex *big.Int) (*big.Int, error) { opts := &bind.CallOpts{ - From: consumer.client.Addresses[0], + From: consumer.client.MustGetRootKeyAddress(), Context: ctx, } return consumer.vrfBeaconConsumer.SReceivedRandomnessByRequestID(opts, requestID, numWordIndex) diff --git a/integration-tests/contracts/ethereum_vrf_contracts_seth.go b/integration-tests/contracts/ethereum_vrf_contracts_seth.go index 86d95c4d219..437cf013553 100644 --- a/integration-tests/contracts/ethereum_vrf_contracts_seth.go +++ b/integration-tests/contracts/ethereum_vrf_contracts_seth.go @@ -269,7 +269,7 @@ func (v *EthereumBlockhashStore) Address() string { func (v *EthereumBlockhashStore) GetBlockHash(ctx context.Context, blockNumber *big.Int) ([32]byte, error) { blockHash, err := v.blockHashStore.GetBlockhash(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }, blockNumber) if err != nil { @@ -285,7 +285,7 @@ func (v *EthereumVRFCoordinator) Address() string { // HashOfKey get a hash of proving key to use it as a request ID part for VRF func (v *EthereumVRFCoordinator) HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error) { hash, err := v.coordinator.HashOfKey(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }, pubKey) if err != nil { @@ -322,7 +322,7 @@ func (v *EthereumVRFConsumer) RequestRandomness(hash [32]byte, fee *big.Int) err // CurrentRoundID helper roundID counter in consumer to check when all randomness requests are finished func (v *EthereumVRFConsumer) CurrentRoundID(ctx context.Context) (*big.Int, error) { return v.consumer.CurrentRoundID(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) } @@ -330,7 +330,7 @@ func (v *EthereumVRFConsumer) CurrentRoundID(ctx context.Context) (*big.Int, err // RandomnessOutput get VRF randomness output func (v *EthereumVRFConsumer) RandomnessOutput(ctx context.Context) (*big.Int, error) { return v.consumer.RandomnessOutput(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) } @@ -343,7 +343,7 @@ func (v *EthereumVRF) Fund(_ *big.Float) error { // ProofLength returns the PROOFLENGTH call from the VRF contract func (v *EthereumVRF) ProofLength(ctx context.Context) (*big.Int, error) { return v.vrf.PROOFLENGTH(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) } diff --git a/integration-tests/contracts/ethereum_vrfv2_contracts.go b/integration-tests/contracts/ethereum_vrfv2_contracts.go index f5259a38093..d8d073c62b7 100644 --- a/integration-tests/contracts/ethereum_vrfv2_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2_contracts.go @@ -373,7 +373,7 @@ func (v *EthereumVRFCoordinatorV2) Address() string { func (v *EthereumVRFCoordinatorV2) HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } hash, err := v.coordinator.HashOfKey(opts, pubKey) @@ -385,7 +385,7 @@ func (v *EthereumVRFCoordinatorV2) HashOfKey(ctx context.Context, pubKey [2]*big func (v *EthereumVRFCoordinatorV2) GetSubscription(ctx context.Context, subID uint64) (Subscription, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } subscription, err := v.coordinator.GetSubscription(opts, subID) @@ -403,7 +403,7 @@ func (v *EthereumVRFCoordinatorV2) GetSubscription(ctx context.Context, subID ui func (v *EthereumVRFCoordinatorV2) GetOwner(ctx context.Context) (common.Address, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } coordinatorOwnerAddress, err := v.coordinator.Owner(opts) @@ -415,7 +415,7 @@ func (v *EthereumVRFCoordinatorV2) GetOwner(ctx context.Context) (common.Address func (v *EthereumVRFCoordinatorV2) GetRequestConfig(ctx context.Context) (GetRequestConfig, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } minConfirmations, maxGas, keyHashes, err := v.coordinator.GetRequestConfig(opts) @@ -433,7 +433,7 @@ func (v *EthereumVRFCoordinatorV2) GetRequestConfig(ctx context.Context) (GetReq func (v *EthereumVRFCoordinatorV2) GetConfig(ctx context.Context) (vrf_coordinator_v2.GetConfig, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } config, err := v.coordinator.GetConfig(opts) @@ -445,7 +445,7 @@ func (v *EthereumVRFCoordinatorV2) GetConfig(ctx context.Context) (vrf_coordinat func (v *EthereumVRFCoordinatorV2) GetFallbackWeiPerUnitLink(ctx context.Context) (*big.Int, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } fallbackWeiPerUnitLink, err := v.coordinator.GetFallbackWeiPerUnitLink(opts) @@ -457,7 +457,7 @@ func (v *EthereumVRFCoordinatorV2) GetFallbackWeiPerUnitLink(ctx context.Context func (v *EthereumVRFCoordinatorV2) GetFeeConfig(ctx context.Context) (vrf_coordinator_v2.GetFeeConfig, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } config, err := v.coordinator.GetFeeConfig(opts) @@ -510,7 +510,7 @@ func (v *EthereumVRFCoordinatorV2) AddConsumer(subId uint64, consumerAddress str func (v *EthereumVRFCoordinatorV2) PendingRequestsExist(ctx context.Context, subID uint64) (bool, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } pendingRequestExists, err := v.coordinator.PendingRequestExists(opts, subID) @@ -593,7 +593,7 @@ func (v *EthereumVRFCoordinatorV2) CancelSubscription(subID uint64, to common.Ad } func (v *EthereumVRFCoordinatorV2) FindSubscriptionID(subID uint64) (uint64, error) { - owner := v.client.Addresses[0] + owner := v.client.MustGetRootKeyAddress() subscriptionIterator, err := v.coordinator.FilterSubscriptionCreated( nil, []uint64{subID}, @@ -797,7 +797,7 @@ func (v *EthereumVRFConsumerV2) GetAllRandomWords(ctx context.Context, num int) words := make([]*big.Int, 0) for i := 0; i < num; i++ { word, err := v.consumer.SRandomWords(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }, big.NewInt(int64(i))) if err != nil { @@ -852,7 +852,7 @@ func (v *EthereumVRFv2Consumer) Address() string { // CurrentSubscription get current VRFv2 subscription func (v *EthereumVRFConsumerV2) CurrentSubscription() (uint64, error) { return v.consumer.SSubId(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: context.Background(), }) } @@ -860,7 +860,7 @@ func (v *EthereumVRFConsumerV2) CurrentSubscription() (uint64, error) { // GasAvailable get available gas after randomness fulfilled func (v *EthereumVRFConsumerV2) GasAvailable() (*big.Int, error) { return v.consumer.SGasAvailable(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: context.Background(), }) } @@ -904,7 +904,7 @@ func (v *EthereumVRFv2Consumer) RequestRandomness(hash [32]byte, subID uint64, c // RandomnessOutput get VRFv2 randomness output (word) func (v *EthereumVRFConsumerV2) RandomnessOutput(ctx context.Context, arg0 *big.Int) (*big.Int, error) { return v.consumer.SRandomWords(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }, arg0) } @@ -965,28 +965,28 @@ func (v *EthereumVRFv2LoadTestConsumer) RequestRandomWordsWithForceFulfill( func (v *EthereumVRFv2Consumer) GetRequestStatus(ctx context.Context, requestID *big.Int) (vrf_v2_consumer_wrapper.GetRequestStatus, error) { return v.consumer.GetRequestStatus(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }, requestID) } func (v *EthereumVRFv2Consumer) GetLastRequestId(ctx context.Context) (*big.Int, error) { return v.consumer.LastRequestId(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) } func (v *EthereumVRFv2LoadTestConsumer) GetRequestStatus(ctx context.Context, requestID *big.Int) (vrf_load_test_with_metrics.GetRequestStatus, error) { return v.consumer.GetRequestStatus(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }, requestID) } func (v *EthereumVRFv2LoadTestConsumer) GetLastRequestId(ctx context.Context) (*big.Int, error) { return v.consumer.SLastRequestId(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) } @@ -998,14 +998,14 @@ func (v *EthereumVRFv2LoadTestConsumer) ResetMetrics() error { func (v *EthereumVRFv2LoadTestConsumer) GetLoadTestMetrics(ctx context.Context) (*VRFLoadTestMetrics, error) { requestCount, err := v.consumer.SRequestCount(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) if err != nil { return &VRFLoadTestMetrics{}, err } fulfilmentCount, err := v.consumer.SResponseCount(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) @@ -1013,14 +1013,14 @@ func (v *EthereumVRFv2LoadTestConsumer) GetLoadTestMetrics(ctx context.Context) return &VRFLoadTestMetrics{}, err } averageFulfillmentInMillions, err := v.consumer.SAverageFulfillmentInMillions(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) if err != nil { return &VRFLoadTestMetrics{}, err } slowestFulfillment, err := v.consumer.SSlowestFulfillment(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) @@ -1028,7 +1028,7 @@ func (v *EthereumVRFv2LoadTestConsumer) GetLoadTestMetrics(ctx context.Context) return &VRFLoadTestMetrics{}, err } fastestFulfillment, err := v.consumer.SFastestFulfillment(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) if err != nil { @@ -1067,7 +1067,7 @@ func (v *EthereumVRFV2Wrapper) SetConfig(wrapperGasOverhead uint32, coordinatorG func (v *EthereumVRFV2Wrapper) GetSubID(ctx context.Context) (uint64, error) { return v.wrapper.SUBSCRIPTIONID(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) } @@ -1095,35 +1095,35 @@ func (v *EthereumVRFV2WrapperLoadTestConsumer) RequestRandomness(coordinator Coo func (v *EthereumVRFV2WrapperLoadTestConsumer) GetRequestStatus(ctx context.Context, requestID *big.Int) (vrfv2_wrapper_load_test_consumer.GetRequestStatus, error) { return v.consumer.GetRequestStatus(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }, requestID) } func (v *EthereumVRFV2WrapperLoadTestConsumer) GetLastRequestId(ctx context.Context) (*big.Int, error) { return v.consumer.SLastRequestId(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) } func (v *EthereumVRFV2WrapperLoadTestConsumer) GetWrapper(ctx context.Context) (common.Address, error) { return v.consumer.IVrfV2Wrapper(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) } func (v *EthereumVRFV2WrapperLoadTestConsumer) GetLoadTestMetrics(ctx context.Context) (*VRFLoadTestMetrics, error) { requestCount, err := v.consumer.SRequestCount(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) if err != nil { return nil, err } fulfilmentCount, err := v.consumer.SResponseCount(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) @@ -1131,14 +1131,14 @@ func (v *EthereumVRFV2WrapperLoadTestConsumer) GetLoadTestMetrics(ctx context.Co return nil, err } averageFulfillmentInMillions, err := v.consumer.SAverageFulfillmentInMillions(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) if err != nil { return nil, err } slowestFulfillment, err := v.consumer.SSlowestFulfillment(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) @@ -1146,7 +1146,7 @@ func (v *EthereumVRFV2WrapperLoadTestConsumer) GetLoadTestMetrics(ctx context.Co return nil, err } fastestFulfillment, err := v.consumer.SFastestFulfillment(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) if err != nil { @@ -1218,7 +1218,7 @@ func (v *EthereumVRFMockETHLINKFeed) Address() string { func (v *EthereumVRFMockETHLINKFeed) LatestRoundData() (*big.Int, error) { data, err := v.feed.LatestRoundData(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: context.Background(), }) if err != nil { @@ -1229,7 +1229,7 @@ func (v *EthereumVRFMockETHLINKFeed) LatestRoundData() (*big.Int, error) { func (v *EthereumVRFMockETHLINKFeed) LatestRoundDataUpdatedAt() (*big.Int, error) { data, err := v.feed.LatestRoundData(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: context.Background(), }) if err != nil { diff --git a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go index 8f5bc667b3f..35dbcefd1b6 100644 --- a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go @@ -96,14 +96,14 @@ func (v *EthereumVRFV2PlusWrapper) SetConfig(wrapperGasOverhead uint32, func (v *EthereumVRFV2PlusWrapper) GetSubID(ctx context.Context) (*big.Int, error) { return v.wrapper.SUBSCRIPTIONID(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) } func (v *EthereumVRFV2PlusWrapper) Coordinator(ctx context.Context) (common.Address, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } return v.wrapper.SVrfCoordinator(opts) @@ -176,7 +176,7 @@ func (v *EthereumBatchVRFCoordinatorV2Plus) Address() string { func (v *EthereumVRFCoordinatorV2_5) HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } hash, err := v.coordinator.HashOfKey(opts, pubKey) @@ -188,7 +188,7 @@ func (v *EthereumVRFCoordinatorV2_5) HashOfKey(ctx context.Context, pubKey [2]*b func (v *EthereumVRFCoordinatorV2_5) GetActiveSubscriptionIds(ctx context.Context, startIndex *big.Int, maxCount *big.Int) ([]*big.Int, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } activeSubscriptionIds, err := v.coordinator.GetActiveSubscriptionIds(opts, startIndex, maxCount) @@ -200,7 +200,7 @@ func (v *EthereumVRFCoordinatorV2_5) GetActiveSubscriptionIds(ctx context.Contex func (v *EthereumVRFCoordinatorV2_5) PendingRequestsExist(ctx context.Context, subID *big.Int) (bool, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } pendingRequestExists, err := v.coordinator.PendingRequestExists(opts, subID) @@ -249,7 +249,7 @@ func (v *EthereumVRFCoordinatorV2_5) ParseRandomWordsFulfilled(log types.Log) (* func (v *EthereumVRFCoordinatorV2_5) GetSubscription(ctx context.Context, subID *big.Int) (Subscription, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } subscription, err := v.coordinator.GetSubscription(opts, subID) @@ -267,7 +267,7 @@ func (v *EthereumVRFCoordinatorV2_5) GetSubscription(ctx context.Context, subID func (v *EthereumVRFCoordinatorV2_5) GetLinkTotalBalance(ctx context.Context) (*big.Int, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } totalBalance, err := v.coordinator.STotalBalance(opts) @@ -278,7 +278,7 @@ func (v *EthereumVRFCoordinatorV2_5) GetLinkTotalBalance(ctx context.Context) (* } func (v *EthereumVRFCoordinatorV2_5) GetNativeTokenTotalBalance(ctx context.Context) (*big.Int, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } totalBalance, err := v.coordinator.STotalNativeBalance(opts) @@ -411,7 +411,7 @@ func (v *EthereumVRFCoordinatorV2_5) FundSubscriptionWithNative(subId *big.Int, } func (v *EthereumVRFCoordinatorV2_5) FindSubscriptionID(subID *big.Int) (*big.Int, error) { - owner := v.client.Addresses[0] + owner := v.client.MustGetRootKeyAddress() subscriptionIterator, err := v.coordinator.FilterSubscriptionCreated( nil, []*big.Int{subID}, @@ -575,34 +575,34 @@ func (v *EthereumVRFv2PlusLoadTestConsumer) ResetMetrics() error { func (v *EthereumVRFv2PlusLoadTestConsumer) GetCoordinator(ctx context.Context) (common.Address, error) { return v.consumer.SVrfCoordinator(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) } func (v *EthereumVRFv2PlusLoadTestConsumer) GetRequestStatus(ctx context.Context, requestID *big.Int) (vrf_v2plus_load_test_with_metrics.GetRequestStatus, error) { return v.consumer.GetRequestStatus(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }, requestID) } func (v *EthereumVRFv2PlusLoadTestConsumer) GetLastRequestId(ctx context.Context) (*big.Int, error) { return v.consumer.SLastRequestId(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) } func (v *EthereumVRFv2PlusLoadTestConsumer) GetLoadTestMetrics(ctx context.Context) (*VRFLoadTestMetrics, error) { requestCount, err := v.consumer.SRequestCount(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) if err != nil { return nil, err } fulfilmentCount, err := v.consumer.SResponseCount(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) @@ -610,14 +610,14 @@ func (v *EthereumVRFv2PlusLoadTestConsumer) GetLoadTestMetrics(ctx context.Conte return nil, err } averageFulfillmentInMillions, err := v.consumer.SAverageResponseTimeInBlocksMillions(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) if err != nil { return nil, err } slowestFulfillment, err := v.consumer.SSlowestResponseTimeInBlocks(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) @@ -625,28 +625,28 @@ func (v *EthereumVRFv2PlusLoadTestConsumer) GetLoadTestMetrics(ctx context.Conte return nil, err } fastestFulfillment, err := v.consumer.SFastestResponseTimeInBlocks(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) if err != nil { return nil, err } averageResponseTimeInSeconds, err := v.consumer.SAverageResponseTimeInSecondsMillions(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) if err != nil { return nil, err } slowestResponseTimeInSeconds, err := v.consumer.SSlowestResponseTimeInSeconds(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) if err != nil { return nil, err } fastestResponseTimeInSeconds, err := v.consumer.SFastestResponseTimeInSeconds(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) if err != nil { @@ -655,7 +655,7 @@ func (v *EthereumVRFv2PlusLoadTestConsumer) GetLoadTestMetrics(ctx context.Conte var responseTimesInBlocks []uint32 for { currentResponseTimesInBlocks, err := v.consumer.GetRequestBlockTimes(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }, big.NewInt(int64(len(responseTimesInBlocks))), big.NewInt(1000)) if err != nil { @@ -732,7 +732,7 @@ func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) Address() string { func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } hash, err := v.coordinator.HashOfKey(opts, pubKey) @@ -744,7 +744,7 @@ func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) HashOfKey(ctx context.Cont func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) GetActiveSubscriptionIds(ctx context.Context, startIndex *big.Int, maxCount *big.Int) ([]*big.Int, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } activeSubscriptionIds, err := v.coordinator.GetActiveSubscriptionIds(opts, startIndex, maxCount) @@ -756,7 +756,7 @@ func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) GetActiveSubscriptionIds(c func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) GetSubscription(ctx context.Context, subID *big.Int) (vrf_v2plus_upgraded_version.GetSubscription, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } subscription, err := v.coordinator.GetSubscription(opts, subID) @@ -816,7 +816,7 @@ func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) CreateSubscription() error func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) GetLinkTotalBalance(ctx context.Context) (*big.Int, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } totalBalance, err := v.coordinator.STotalBalance(opts) @@ -827,7 +827,7 @@ func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) GetLinkTotalBalance(ctx co } func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) GetNativeTokenTotalBalance(ctx context.Context) (*big.Int, error) { opts := &bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, } totalBalance, err := v.coordinator.STotalNativeBalance(opts) @@ -867,7 +867,7 @@ func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) FundSubscriptionWithNative } func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) FindSubscriptionID() (*big.Int, error) { - owner := v.client.Addresses[0] + owner := v.client.MustGetRootKeyAddress() subscriptionIterator, err := v.coordinator.FilterSubscriptionCreated( nil, nil, @@ -1129,35 +1129,35 @@ func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) RequestRandomnessNative( func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) GetRequestStatus(ctx context.Context, requestID *big.Int) (vrfv2plus_wrapper_load_test_consumer.GetRequestStatus, error) { return v.consumer.GetRequestStatus(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }, requestID) } func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) GetLastRequestId(ctx context.Context) (*big.Int, error) { return v.consumer.SLastRequestId(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) } func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) GetWrapper(ctx context.Context) (common.Address, error) { return v.consumer.IVrfV2PlusWrapper(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) } func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) GetLoadTestMetrics(ctx context.Context) (*VRFLoadTestMetrics, error) { requestCount, err := v.consumer.SRequestCount(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) if err != nil { return nil, err } fulfilmentCount, err := v.consumer.SResponseCount(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) @@ -1165,14 +1165,14 @@ func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) GetLoadTestMetrics(ctx contex return nil, err } averageFulfillmentInMillions, err := v.consumer.SAverageFulfillmentInMillions(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) if err != nil { return nil, err } slowestFulfillment, err := v.consumer.SSlowestFulfillment(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) @@ -1180,7 +1180,7 @@ func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) GetLoadTestMetrics(ctx contex return nil, err } fastestFulfillment, err := v.consumer.SFastestFulfillment(&bind.CallOpts{ - From: v.client.Addresses[0], + From: v.client.MustGetRootKeyAddress(), Context: ctx, }) if err != nil { diff --git a/integration-tests/load/vrfv2/vrfv2_test.go b/integration-tests/load/vrfv2/vrfv2_test.go index 2849814baaa..4d5126e35f8 100644 --- a/integration-tests/load/vrfv2/vrfv2_test.go +++ b/integration-tests/load/vrfv2/vrfv2_test.go @@ -81,7 +81,7 @@ func TestVRFV2Performance(t *testing.T) { } else { if *vrfv2Config.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) + vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2Config.General.UseExistingEnv { @@ -219,7 +219,7 @@ func TestVRFV2BHSPerformance(t *testing.T) { } else { if *vrfv2Config.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) + vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2Config.General.UseExistingEnv { diff --git a/integration-tests/load/vrfv2plus/vrfv2plus_test.go b/integration-tests/load/vrfv2plus/vrfv2plus_test.go index 162ed09e966..878d7830879 100644 --- a/integration-tests/load/vrfv2plus/vrfv2plus_test.go +++ b/integration-tests/load/vrfv2plus/vrfv2plus_test.go @@ -79,7 +79,7 @@ func TestVRFV2PlusPerformance(t *testing.T) { } else { if *testConfig.VRFv2Plus.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) } } if !*testConfig.VRFv2Plus.General.UseExistingEnv { @@ -216,7 +216,7 @@ func TestVRFV2PlusBHSPerformance(t *testing.T) { } else { if *testConfig.VRFv2Plus.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) } } if !*testConfig.VRFv2Plus.General.UseExistingEnv { diff --git a/integration-tests/smoke/vrfv2_test.go b/integration-tests/smoke/vrfv2_test.go index 9c6e7099277..1f2c0be17de 100644 --- a/integration-tests/smoke/vrfv2_test.go +++ b/integration-tests/smoke/vrfv2_test.go @@ -57,7 +57,7 @@ func TestVRFv2Basic(t *testing.T) { } else { if *vrfv2Config.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) + vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2Config.General.UseExistingEnv { @@ -339,18 +339,18 @@ func TestVRFv2Basic(t *testing.T) { amountToWithdrawLink := fulfilledEventLink.Payment - defaultWalletBalanceLinkBeforeOracleWithdraw, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.Addresses[0].Hex()) + defaultWalletBalanceLinkBeforeOracleWithdraw, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.MustGetRootKeyAddress().Hex()) require.NoError(t, err) l.Info(). - Str("Returning to", sethClient.Addresses[0].Hex()). + Str("Returning to", sethClient.MustGetRootKeyAddress().Hex()). Str("Amount", amountToWithdrawLink.String()). Msg("Invoking Oracle Withdraw for LINK") - err = vrfContracts.CoordinatorV2.OracleWithdraw(sethClient.Addresses[0], amountToWithdrawLink) + err = vrfContracts.CoordinatorV2.OracleWithdraw(sethClient.MustGetRootKeyAddress(), amountToWithdrawLink) require.NoError(t, err, "Error withdrawing LINK from coordinator to default wallet") - defaultWalletBalanceLinkAfterOracleWithdraw, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.Addresses[0].Hex()) + defaultWalletBalanceLinkAfterOracleWithdraw, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.MustGetRootKeyAddress().Hex()) require.NoError(t, err) require.Equal( @@ -492,7 +492,7 @@ func TestVRFv2Basic(t *testing.T) { require.NoError(t, err) require.True(t, pendingRequestsExist, "Pending requests should exist after unfilfulled requests due to low sub balance") - walletBalanceLinkBeforeSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.Addresses[0].Hex()) + walletBalanceLinkBeforeSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.MustGetRootKeyAddress().Hex()) require.NoError(t, err) subscriptionForCancelling, err = vrfContracts.CoordinatorV2.GetSubscription(testcontext.Get(t), subIDForOwnerCancelling) @@ -502,7 +502,7 @@ func TestVRFv2Basic(t *testing.T) { l.Info(). Str("Subscription Amount Link", subBalanceLink.String()). Uint64("Returning funds from SubID", subIDForOwnerCancelling). - Str("Returning funds to", sethClient.Addresses[0].Hex()). + Str("Returning funds to", sethClient.MustGetRootKeyAddress().Hex()). Msg("Canceling subscription and returning funds to subscription owner") // Call OwnerCancelSubscription @@ -535,7 +535,7 @@ func TestVRFv2Basic(t *testing.T) { require.Equal(t, subBalanceLink, subscriptionCanceledEvent.Amount, "SubscriptionCanceled event LINK amount is not equal to sub amount while canceling subscription") - walletBalanceLinkAfterSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.Addresses[0].Hex()) + walletBalanceLinkAfterSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.MustGetRootKeyAddress().Hex()) require.NoError(t, err) // Verify that subscription was deleted from Coordinator contract @@ -588,7 +588,7 @@ func TestVRFv2MultipleSendingKeys(t *testing.T) { } else { if *vrfv2Config.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) + vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2Config.General.UseExistingEnv { @@ -692,7 +692,7 @@ func TestVRFOwner(t *testing.T) { } else { if *vrfv2Config.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) + vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2Config.General.UseExistingEnv { @@ -825,7 +825,7 @@ func TestVRFV2WithBHS(t *testing.T) { } else { if *vrfv2Config.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) + vrfv2.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2Config.General.UseExistingEnv { diff --git a/integration-tests/smoke/vrfv2plus_test.go b/integration-tests/smoke/vrfv2plus_test.go index 74e9f588337..7025230f8b5 100644 --- a/integration-tests/smoke/vrfv2plus_test.go +++ b/integration-tests/smoke/vrfv2plus_test.go @@ -59,7 +59,7 @@ func TestVRFv2Plus(t *testing.T) { } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2PlusConfig.General.UseExistingEnv { @@ -559,10 +559,10 @@ func TestVRFv2Plus(t *testing.T) { require.NoError(t, err) require.True(t, pendingRequestsExist, "Pending requests should exist after unfulfilled rand requests due to low sub balance") - walletBalanceNativeBeforeSubCancelling, err := sethClient.Client.BalanceAt(testcontext.Get(t), common.HexToAddress(sethClient.Addresses[0].Hex()), nil) + walletBalanceNativeBeforeSubCancelling, err := sethClient.Client.BalanceAt(testcontext.Get(t), common.HexToAddress(sethClient.MustGetRootKeyAddress().Hex()), nil) require.NoError(t, err) - walletBalanceLinkBeforeSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.Addresses[0].Hex()) + walletBalanceLinkBeforeSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.MustGetRootKeyAddress().Hex()) require.NoError(t, err) subscriptionForCancelling, err := vrfContracts.CoordinatorV2Plus.GetSubscription(testcontext.Get(t), subID) @@ -574,7 +574,7 @@ func TestVRFv2Plus(t *testing.T) { Str("Subscription Amount Native", subBalanceNative.String()). Str("Subscription Amount Link", subBalanceLink.String()). Str("Returning funds from SubID", subID.String()). - Str("Returning funds to", sethClient.Addresses[0].Hex()). + Str("Returning funds to", sethClient.MustGetRootKeyAddress().Hex()). Msg("Canceling subscription and returning funds to subscription owner") tx, err := vrfContracts.CoordinatorV2Plus.OwnerCancelSubscription(subID) require.NoError(t, err, "Error canceling subscription") @@ -607,10 +607,10 @@ func TestVRFv2Plus(t *testing.T) { require.Equal(t, subBalanceNative, subscriptionCanceledEvent.AmountNative, "SubscriptionCanceled event native amount is not equal to sub amount while canceling subscription") require.Equal(t, subBalanceLink, subscriptionCanceledEvent.AmountLink, "SubscriptionCanceled event LINK amount is not equal to sub amount while canceling subscription") - walletBalanceNativeAfterSubCancelling, err := sethClient.Client.BalanceAt(testcontext.Get(t), common.HexToAddress(sethClient.Addresses[0].Hex()), nil) + walletBalanceNativeAfterSubCancelling, err := sethClient.Client.BalanceAt(testcontext.Get(t), common.HexToAddress(sethClient.MustGetRootKeyAddress().Hex()), nil) require.NoError(t, err) - walletBalanceLinkAfterSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.Addresses[0].Hex()) + walletBalanceLinkAfterSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.MustGetRootKeyAddress().Hex()) require.NoError(t, err) //Verify that sub was deleted from Coordinator @@ -694,37 +694,37 @@ func TestVRFv2Plus(t *testing.T) { require.NoError(t, err) amountToWithdrawLink := fulfilledEventLink.Payment - defaultWalletBalanceNativeBeforeWithdraw, err := sethClient.Client.BalanceAt(testcontext.Get(t), common.HexToAddress(sethClient.Addresses[0].Hex()), nil) + defaultWalletBalanceNativeBeforeWithdraw, err := sethClient.Client.BalanceAt(testcontext.Get(t), common.HexToAddress(sethClient.MustGetRootKeyAddress().Hex()), nil) require.NoError(t, err) - defaultWalletBalanceLinkBeforeWithdraw, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.Addresses[0].Hex()) + defaultWalletBalanceLinkBeforeWithdraw, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.MustGetRootKeyAddress().Hex()) require.NoError(t, err) l.Info(). - Str("Returning to", sethClient.Addresses[0].Hex()). + Str("Returning to", sethClient.MustGetRootKeyAddress().Hex()). Str("Amount", amountToWithdrawLink.String()). Msg("Invoking Oracle Withdraw for LINK") err = vrfContracts.CoordinatorV2Plus.Withdraw( - common.HexToAddress(sethClient.Addresses[0].Hex()), + common.HexToAddress(sethClient.MustGetRootKeyAddress().Hex()), ) require.NoError(t, err, "error withdrawing LINK from coordinator to default wallet") amountToWithdrawNative := fulfilledEventNative.Payment l.Info(). - Str("Returning to", sethClient.Addresses[0].Hex()). + Str("Returning to", sethClient.MustGetRootKeyAddress().Hex()). Str("Amount", amountToWithdrawNative.String()). Msg("Invoking Oracle Withdraw for Native") err = vrfContracts.CoordinatorV2Plus.WithdrawNative( - common.HexToAddress(sethClient.Addresses[0].Hex()), + common.HexToAddress(sethClient.MustGetRootKeyAddress().Hex()), ) require.NoError(t, err, "error withdrawing Native tokens from coordinator to default wallet") - defaultWalletBalanceNativeAfterWithdraw, err := sethClient.Client.BalanceAt(testcontext.Get(t), common.HexToAddress(sethClient.Addresses[0].Hex()), nil) + defaultWalletBalanceNativeAfterWithdraw, err := sethClient.Client.BalanceAt(testcontext.Get(t), common.HexToAddress(sethClient.MustGetRootKeyAddress().Hex()), nil) require.NoError(t, err) - defaultWalletBalanceLinkAfterWithdraw, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.Addresses[0].Hex()) + defaultWalletBalanceLinkAfterWithdraw, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.MustGetRootKeyAddress().Hex()) require.NoError(t, err) //not possible to verify exact amount of Native/LINK returned as defaultWallet is used in other tests in parallel which might affect the balance @@ -759,7 +759,7 @@ func TestVRFv2PlusMultipleSendingKeys(t *testing.T) { } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2PlusConfig.General.UseExistingEnv { @@ -862,7 +862,7 @@ func TestVRFv2PlusMigration(t *testing.T) { } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2PlusConfig.General.UseExistingEnv { @@ -1259,7 +1259,7 @@ func TestVRFV2PlusWithBHS(t *testing.T) { } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2PlusConfig.General.UseExistingEnv { @@ -1486,7 +1486,7 @@ func TestVRFV2PlusWithBHF(t *testing.T) { } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2PlusConfig.General.UseExistingEnv { @@ -1639,7 +1639,7 @@ func TestVRFv2PlusReplayAfterTimeout(t *testing.T) { } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2PlusConfig.General.UseExistingEnv { @@ -1833,7 +1833,7 @@ func TestVRFv2PlusPendingBlockSimulationAndZeroConfirmationDelays(t *testing.T) } else { if *vrfv2PlusConfig.General.CancelSubsAfterTestRun { //cancel subs and return funds to sub owner - vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.Addresses[0].Hex(), subIDsForCancellingAfterTest, l) + vrfv2plus.CancelSubsAndReturnFunds(testcontext.Get(t), vrfContracts, sethClient.MustGetRootKeyAddress().Hex(), subIDsForCancellingAfterTest, l) } } if !*vrfv2PlusConfig.General.UseExistingEnv { From 355aa347d608a67055e5f6517e0d1543a579d8ba Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Mon, 13 May 2024 11:17:48 +0200 Subject: [PATCH 30/43] Show funding amount in ETH --- integration-tests/actions/vrf/common/actions.go | 1 + 1 file changed, 1 insertion(+) diff --git a/integration-tests/actions/vrf/common/actions.go b/integration-tests/actions/vrf/common/actions.go index ef4c928fe11..fa7ba94ae70 100644 --- a/integration-tests/actions/vrf/common/actions.go +++ b/integration-tests/actions/vrf/common/actions.go @@ -332,6 +332,7 @@ func FundNodesIfNeeded(ctx context.Context, existingEnvConfig *vrf_common_config if fundingToSendWei.Cmp(big.NewInt(0)) == 1 { log. Str("Funding Amount in wei", fundingToSendWei.String()). + Str("Funding Amount in ETH", conversions.WeiToEther(fundingToSendWei).String()). Msg("Funding Node's Sending Key") _, err := actions_seth.SendFunds(l, client, actions_seth.FundsToSendPayload{ ToAddress: common.HexToAddress(sendingKey), From 212c2a3fa2bd058d5ad6b8150ceef5ddde3cd8cc Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Mon, 13 May 2024 11:35:22 +0200 Subject: [PATCH 31/43] Remove legacy vrf code --- .../contracts/contract_deployer.go | 1 - .../contracts/ethereum_vrf_contracts.go | 475 ++++++++++++------ .../contracts/ethereum_vrf_contracts_seth.go | 349 ------------- 3 files changed, 323 insertions(+), 502 deletions(-) delete mode 100644 integration-tests/contracts/ethereum_vrf_contracts_seth.go diff --git a/integration-tests/contracts/contract_deployer.go b/integration-tests/contracts/contract_deployer.go index cab2fae4433..a3218d66e78 100644 --- a/integration-tests/contracts/contract_deployer.go +++ b/integration-tests/contracts/contract_deployer.go @@ -96,7 +96,6 @@ type ContractDeployer interface { LoadLinkToken(address common.Address) (LinkToken, error) DeployOffChainAggregator(linkAddr string, offchainOptions OffchainOptions) (OffchainAggregator, error) LoadOffChainAggregator(address *common.Address) (OffchainAggregator, error) - DeployVRFContract() (VRF, error) DeployMockETHLINKFeed(answer *big.Int) (MockETHLINKFeed, error) LoadETHLINKFeed(address common.Address) (MockETHLINKFeed, error) DeployMockGasFeed(answer *big.Int) (MockGasFeed, error) diff --git a/integration-tests/contracts/ethereum_vrf_contracts.go b/integration-tests/contracts/ethereum_vrf_contracts.go index 0c356c6f628..7b79ca01739 100644 --- a/integration-tests/contracts/ethereum_vrf_contracts.go +++ b/integration-tests/contracts/ethereum_vrf_contracts.go @@ -6,10 +6,8 @@ import ( "math/big" "time" - "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" "github.com/rs/zerolog/log" "github.com/smartcontractkit/seth" @@ -19,164 +17,71 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/batch_blockhash_store" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/blockhash_store" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_consumer_interface" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_coordinator_interface" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_wrapper" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_test_v2" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_mock_ethlink_aggregator" ) -// EthereumBatchBlockhashStore represents BatchBlockhashStore contract -type EthereumBatchBlockhashStore struct { - address common.Address - client *seth.Client - batchBlockhashStore *batch_blockhash_store.BatchBlockhashStore -} - -// LegacyEthereumBlockhashStore represents a blockhash store for VRF contract -type LegacyEthereumBlockhashStore struct { +// EthereumBlockhashStore represents a blockhash store for VRF contract +type EthereumBlockhashStore struct { address *common.Address - client blockchain.EVMClient + client *seth.Client blockHashStore *blockhash_store.BlockhashStore } -// LegacyEthereumVRFConsumer represents VRF consumer contract -type LegacyEthereumVRFConsumer struct { - address *common.Address - client blockchain.EVMClient - consumer *solidity_vrf_consumer_interface.VRFConsumer +// EthereumVRFCoordinator represents VRF coordinator contract +type EthereumVRFCoordinator struct { + address *common.Address + client *seth.Client + coordinator *solidity_vrf_coordinator_interface.VRFCoordinator } -// VRFConsumerRoundConfirmer is a header subscription that awaits for a certain VRF round to be completed -type VRFConsumerRoundConfirmer struct { - consumer VRFConsumer - roundID *big.Int - doneChan chan struct{} - context context.Context - cancel context.CancelFunc - done bool -} - -// LegacyEthereumVRF represents a VRF contract -type LegacyEthereumVRF struct { - client blockchain.EVMClient - vrf *solidity_vrf_wrapper.VRF - address *common.Address -} - -// DeployVRFContract deploy VRF contract -func (e *EthereumContractDeployer) DeployVRFContract() (VRF, error) { - address, _, instance, err := e.client.DeployContract("VRF", func( - auth *bind.TransactOpts, - _ bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return solidity_vrf_wrapper.DeployVRF(auth, wrappers.MustNewWrappedContractBackend(e.client, nil)) - }) - if err != nil { - return nil, err - } - return &LegacyEthereumVRF{ - client: e.client, - vrf: instance.(*solidity_vrf_wrapper.VRF), - address: address, - }, err +type EthereumVRFCoordinatorTestV2 struct { + address *common.Address + client *seth.Client + coordinator *vrf_coordinator_test_v2.VRFCoordinatorTestV2 } -// DeployBlockhashStore deploys blockhash store used with VRF contract -func (e *EthereumContractDeployer) DeployBlockhashStore() (BlockHashStore, error) { - address, _, instance, err := e.client.DeployContract("BlockhashStore", func( - auth *bind.TransactOpts, - _ bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return blockhash_store.DeployBlockhashStore(auth, wrappers.MustNewWrappedContractBackend(e.client, nil)) - }) - if err != nil { - return nil, err - } - return &LegacyEthereumBlockhashStore{ - client: e.client, - blockHashStore: instance.(*blockhash_store.BlockhashStore), - address: address, - }, err -} - -// DeployVRFConsumer deploys VRF consumer contract -func (e *EthereumContractDeployer) DeployVRFConsumer(linkAddr string, coordinatorAddr string) (VRFConsumer, error) { - address, _, instance, err := e.client.DeployContract("VRFConsumer", func( - auth *bind.TransactOpts, - _ bind.ContractBackend, - ) (common.Address, *types.Transaction, interface{}, error) { - return solidity_vrf_consumer_interface.DeployVRFConsumer(auth, wrappers.MustNewWrappedContractBackend(e.client, nil), common.HexToAddress(coordinatorAddr), common.HexToAddress(linkAddr)) - }) - if err != nil { - return nil, err - } - return &LegacyEthereumVRFConsumer{ - client: e.client, - consumer: instance.(*solidity_vrf_consumer_interface.VRFConsumer), - address: address, - }, err -} - -func (v *LegacyEthereumBlockhashStore) Address() string { +func (v *EthereumVRFCoordinatorTestV2) Address() string { return v.address.Hex() } -func (v *LegacyEthereumBlockhashStore) GetBlockHash(ctx context.Context, blockNumber *big.Int) ([32]byte, error) { - opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), - Context: ctx, - } - blockHash, err := v.blockHashStore.GetBlockhash(opts, blockNumber) - if err != nil { - return [32]byte{}, err - } - return blockHash, nil -} - -func (v *LegacyEthereumVRFConsumer) Address() string { - return v.address.Hex() +// EthereumVRFConsumer represents VRF consumer contract +type EthereumVRFConsumer struct { + address *common.Address + client *seth.Client + consumer *solidity_vrf_consumer_interface.VRFConsumer } -func (v *LegacyEthereumVRFConsumer) Fund(ethAmount *big.Float) error { - gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{ - To: v.address, - }) - if err != nil { - return err - } - return v.client.Fund(v.address.Hex(), ethAmount, gasEstimates) +// EthereumVRF represents a VRF contract +type EthereumVRF struct { + client *seth.Client + vrf *solidity_vrf_wrapper.VRF + address *common.Address } -// RequestRandomness requests VRF randomness -func (v *LegacyEthereumVRFConsumer) RequestRandomness(hash [32]byte, fee *big.Int) error { - opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet()) - if err != nil { - return err - } - tx, err := v.consumer.TestRequestRandomness(opts, hash, fee) - if err != nil { - return err - } - return v.client.ProcessTransaction(tx) +type EthereumVRFMockETHLINKAggregator struct { + client *seth.Client + address *common.Address + contract *vrf_mock_ethlink_aggregator.VRFMockETHLINKAggregator } -// CurrentRoundID helper roundID counter in consumer to check when all randomness requests are finished -func (v *LegacyEthereumVRFConsumer) CurrentRoundID(ctx context.Context) (*big.Int, error) { - opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), - Context: ctx, - } - return v.consumer.CurrentRoundID(opts) +// EthereumBatchBlockhashStore represents BatchBlockhashStore contract +type EthereumBatchBlockhashStore struct { + address common.Address + client *seth.Client + batchBlockhashStore *batch_blockhash_store.BatchBlockhashStore } -// RandomnessOutput get VRF randomness output -func (v *LegacyEthereumVRFConsumer) RandomnessOutput(ctx context.Context) (*big.Int, error) { - opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), - Context: ctx, - } - out, err := v.consumer.RandomnessOutput(opts) - if err != nil { - return nil, err - } - return out, nil +// VRFConsumerRoundConfirmer is a header subscription that awaits for a certain VRF round to be completed +type VRFConsumerRoundConfirmer struct { + consumer VRFConsumer + roundID *big.Int + doneChan chan struct{} + context context.Context + cancel context.CancelFunc + done bool } // NewVRFConsumerRoundConfirmer provides a new instance of a NewVRFConsumerRoundConfirmer @@ -237,26 +142,292 @@ func (f *VRFConsumerRoundConfirmer) Wait() error { } } -// Fund sends specified currencies to the contract -func (v *LegacyEthereumVRF) Fund(ethAmount *big.Float) error { - gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{ - To: v.address, - }) +func (v *EthereumBatchBlockhashStore) Address() string { + return v.address.Hex() +} + +func (a *EthereumVRFMockETHLINKAggregator) Address() string { + return a.address.Hex() +} + +func (a *EthereumVRFMockETHLINKAggregator) LatestRoundData() (*big.Int, error) { + data, err := a.contract.LatestRoundData(a.client.NewCallOpts()) if err != nil { - return err + return nil, err } - return v.client.Fund(v.address.Hex(), ethAmount, gasEstimates) + return data.Ans, nil } -// ProofLength returns the PROOFLENGTH call from the VRF contract -func (v *LegacyEthereumVRF) ProofLength(ctxt context.Context) (*big.Int, error) { - opts := &bind.CallOpts{ - From: common.HexToAddress(v.client.GetDefaultWallet().Address()), - Context: ctxt, +func (a *EthereumVRFMockETHLINKAggregator) LatestRoundDataUpdatedAt() (*big.Int, error) { + data, err := a.contract.LatestRoundData(a.client.NewCallOpts()) + if err != nil { + return nil, err } - return v.vrf.PROOFLENGTH(opts) + return data.UpdatedAt, nil } -func (v *EthereumBatchBlockhashStore) Address() string { +func (a *EthereumVRFMockETHLINKAggregator) SetBlockTimestampDeduction(blockTimestampDeduction *big.Int) error { + _, err := a.client.Decode(a.contract.SetBlockTimestampDeduction(a.client.NewTXOpts(), blockTimestampDeduction)) + return err +} + +// DeployVRFContract deploy VRFv1 contract +func DeployVRFv1Contract(seth *seth.Client) (VRF, error) { + abi, err := solidity_vrf_wrapper.VRFMetaData.GetAbi() + if err != nil { + return &EthereumVRF{}, fmt.Errorf("failed to get VRF ABI: %w", err) + } + + vrfDeploymentData, err := seth.DeployContract( + seth.NewTXOpts(), + "VRF", + *abi, + common.FromHex(solidity_vrf_wrapper.VRFMetaData.Bin)) + if err != nil { + return &EthereumVRF{}, fmt.Errorf("VRF instance deployment have failed: %w", err) + } + + vrf, err := solidity_vrf_wrapper.NewVRF(vrfDeploymentData.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRF{}, fmt.Errorf("failed to instantiate VRF instance: %w", err) + } + + return &EthereumVRF{ + client: seth, + vrf: vrf, + address: &vrfDeploymentData.Address, + }, err +} + +// DeployBlockhashStore deploys blockhash store used with VRF contract +func DeployBlockhashStore(seth *seth.Client) (BlockHashStore, error) { + abi, err := blockhash_store.BlockhashStoreMetaData.GetAbi() + if err != nil { + return &EthereumBlockhashStore{}, fmt.Errorf("failed to get BlockhashStore ABI: %w", err) + } + + storeDeploymentData, err := seth.DeployContract( + seth.NewTXOpts(), + "BlockhashStore", + *abi, + common.FromHex(blockhash_store.BlockhashStoreMetaData.Bin)) + if err != nil { + return &EthereumBlockhashStore{}, fmt.Errorf("BlockhashStore instance deployment have failed: %w", err) + } + + store, err := blockhash_store.NewBlockhashStore(storeDeploymentData.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumBlockhashStore{}, fmt.Errorf("failed to instantiate BlockhashStore instance: %w", err) + } + + return &EthereumBlockhashStore{ + client: seth, + blockHashStore: store, + address: &storeDeploymentData.Address, + }, err +} + +// DeployVRFCoordinator deploys VRF coordinator contract +func DeployVRFCoordinator(seth *seth.Client, linkAddr, bhsAddr string) (VRFCoordinator, error) { + abi, err := solidity_vrf_coordinator_interface.VRFCoordinatorMetaData.GetAbi() + if err != nil { + return &EthereumVRFCoordinator{}, fmt.Errorf("failed to get VRFCoordinator ABI: %w", err) + } + + coordinatorDeploymentData, err := seth.DeployContract( + seth.NewTXOpts(), + "VRFCoordinator", + *abi, + common.FromHex(solidity_vrf_coordinator_interface.VRFCoordinatorMetaData.Bin), + common.HexToAddress(linkAddr), + common.HexToAddress(bhsAddr)) + if err != nil { + return &EthereumVRFCoordinator{}, fmt.Errorf("VRFCoordinator instance deployment have failed: %w", err) + } + + coordinator, err := solidity_vrf_coordinator_interface.NewVRFCoordinator(coordinatorDeploymentData.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRFCoordinator{}, fmt.Errorf("failed to instantiate VRFCoordinator instance: %w", err) + } + + return &EthereumVRFCoordinator{ + client: seth, + coordinator: coordinator, + address: &coordinatorDeploymentData.Address, + }, err +} + +func DeployVRFCoordinatorTestV2(seth *seth.Client, linkAddr, bhsAddr, linkEthFeedAddr string) (*EthereumVRFCoordinatorTestV2, error) { + abi, err := vrf_coordinator_test_v2.VRFCoordinatorTestV2MetaData.GetAbi() + if err != nil { + return &EthereumVRFCoordinatorTestV2{}, fmt.Errorf("failed to get VRFCoordinatorTestV2 ABI: %w", err) + } + + coordinatorDeploymentData, err := seth.DeployContract( + seth.NewTXOpts(), + "VRFCoordinatorTestV2", + *abi, + common.FromHex(vrf_coordinator_test_v2.VRFCoordinatorTestV2MetaData.Bin), + common.HexToAddress(linkAddr), + common.HexToAddress(bhsAddr), + common.HexToAddress(linkEthFeedAddr)) + if err != nil { + return &EthereumVRFCoordinatorTestV2{}, fmt.Errorf("VRFCoordinatorTestV2 instance deployment have failed: %w", err) + } + + coordinator, err := vrf_coordinator_test_v2.NewVRFCoordinatorTestV2(coordinatorDeploymentData.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRFCoordinatorTestV2{}, fmt.Errorf("failed to instantiate VRFCoordinatorTestV2 instance: %w", err) + } + + return &EthereumVRFCoordinatorTestV2{ + client: seth, + coordinator: coordinator, + address: &coordinatorDeploymentData.Address, + }, err +} + +// DeployVRFConsumer deploys VRF consumer contract +func DeployVRFConsumer(seth *seth.Client, linkAddr, coordinatorAddr string) (VRFConsumer, error) { + abi, err := solidity_vrf_consumer_interface.VRFConsumerMetaData.GetAbi() + if err != nil { + return &EthereumVRFConsumer{}, fmt.Errorf("failed to get VRFConsumer ABI: %w", err) + } + + consumerDeploymentData, err := seth.DeployContract( + seth.NewTXOpts(), + "VRFConsumer", + *abi, + common.FromHex(solidity_vrf_consumer_interface.VRFConsumerMetaData.Bin), + common.HexToAddress(coordinatorAddr), + common.HexToAddress(linkAddr), + ) + if err != nil { + return &EthereumVRFConsumer{}, fmt.Errorf("VRFConsumer instance deployment have failed: %w", err) + } + + consumer, err := solidity_vrf_consumer_interface.NewVRFConsumer(consumerDeploymentData.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRFConsumer{}, fmt.Errorf("failed to instantiate VRFConsumer instance: %w", err) + } + + return &EthereumVRFConsumer{ + client: seth, + consumer: consumer, + address: &consumerDeploymentData.Address, + }, err +} + +func DeployVRFMockETHLINKFeed(seth *seth.Client, answer *big.Int) (VRFMockETHLINKFeed, error) { + abi, err := vrf_mock_ethlink_aggregator.VRFMockETHLINKAggregatorMetaData.GetAbi() + if err != nil { + return &EthereumVRFMockETHLINKAggregator{}, fmt.Errorf("failed to get VRFMockETHLINKAggregator ABI: %w", err) + } + + deployment, err := seth.DeployContract( + seth.NewTXOpts(), + "VRFMockETHLINKAggregator", + *abi, + common.FromHex(vrf_mock_ethlink_aggregator.VRFMockETHLINKAggregatorMetaData.Bin), + answer, + ) + if err != nil { + return &EthereumVRFMockETHLINKAggregator{}, fmt.Errorf("VRFMockETHLINKAggregator deployment have failed: %w", err) + } + + contract, err := vrf_mock_ethlink_aggregator.NewVRFMockETHLINKAggregator(deployment.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) + if err != nil { + return &EthereumVRFMockETHLINKAggregator{}, fmt.Errorf("failed to instantiate VRFMockETHLINKAggregator instance: %w", err) + } + + return &EthereumVRFMockETHLINKAggregator{ + client: seth, + contract: contract, + address: &deployment.Address, + }, err +} + +func (v *EthereumBlockhashStore) Address() string { + return v.address.Hex() +} + +func (v *EthereumBlockhashStore) GetBlockHash(ctx context.Context, blockNumber *big.Int) ([32]byte, error) { + blockHash, err := v.blockHashStore.GetBlockhash(&bind.CallOpts{ + From: v.client.MustGetRootKeyAddress(), + Context: ctx, + }, blockNumber) + if err != nil { + return [32]byte{}, err + } + return blockHash, nil +} + +func (v *EthereumVRFCoordinator) Address() string { + return v.address.Hex() +} + +// HashOfKey get a hash of proving key to use it as a request ID part for VRF +func (v *EthereumVRFCoordinator) HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error) { + hash, err := v.coordinator.HashOfKey(&bind.CallOpts{ + From: v.client.MustGetRootKeyAddress(), + Context: ctx, + }, pubKey) + if err != nil { + return [32]byte{}, err + } + return hash, nil +} + +// RegisterProvingKey register VRF proving key +func (v *EthereumVRFCoordinator) RegisterProvingKey( + fee *big.Int, + oracleAddr string, + publicProvingKey [2]*big.Int, + jobID [32]byte, +) error { + _, err := v.client.Decode(v.coordinator.RegisterProvingKey(v.client.NewTXOpts(), fee, common.HexToAddress(oracleAddr), publicProvingKey, jobID)) + return err +} + +func (v *EthereumVRFConsumer) Address() string { return v.address.Hex() } + +func (v *EthereumVRFConsumer) Fund(_ *big.Float) error { + panic("do not use this function, use actions_seth.SendFunds() instead, otherwise we will have to deal with circular dependencies") +} + +// RequestRandomness requests VRF randomness +func (v *EthereumVRFConsumer) RequestRandomness(hash [32]byte, fee *big.Int) error { + _, err := v.client.Decode(v.consumer.TestRequestRandomness(v.client.NewTXOpts(), hash, fee)) + return err +} + +// CurrentRoundID helper roundID counter in consumer to check when all randomness requests are finished +func (v *EthereumVRFConsumer) CurrentRoundID(ctx context.Context) (*big.Int, error) { + return v.consumer.CurrentRoundID(&bind.CallOpts{ + From: v.client.MustGetRootKeyAddress(), + Context: ctx, + }) +} + +// RandomnessOutput get VRF randomness output +func (v *EthereumVRFConsumer) RandomnessOutput(ctx context.Context) (*big.Int, error) { + return v.consumer.RandomnessOutput(&bind.CallOpts{ + From: v.client.MustGetRootKeyAddress(), + Context: ctx, + }) +} + +// Fund sends specified currencies to the contract +func (v *EthereumVRF) Fund(_ *big.Float) error { + panic("do not use this function, use actions_seth.SendFunds() instead, otherwise we will have to deal with circular dependencies") +} + +// ProofLength returns the PROOFLENGTH call from the VRF contract +func (v *EthereumVRF) ProofLength(ctx context.Context) (*big.Int, error) { + return v.vrf.PROOFLENGTH(&bind.CallOpts{ + From: v.client.MustGetRootKeyAddress(), + Context: ctx, + }) +} diff --git a/integration-tests/contracts/ethereum_vrf_contracts_seth.go b/integration-tests/contracts/ethereum_vrf_contracts_seth.go deleted file mode 100644 index 437cf013553..00000000000 --- a/integration-tests/contracts/ethereum_vrf_contracts_seth.go +++ /dev/null @@ -1,349 +0,0 @@ -package contracts - -import ( - "context" - "fmt" - "math/big" - - "github.com/ethereum/go-ethereum/accounts/abi/bind" - "github.com/ethereum/go-ethereum/common" - "github.com/smartcontractkit/seth" - - "github.com/smartcontractkit/chainlink/integration-tests/wrappers" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/blockhash_store" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_consumer_interface" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_coordinator_interface" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_wrapper" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_test_v2" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_mock_ethlink_aggregator" -) - -// EthereumBlockhashStore represents a blockhash store for VRF contract -type EthereumBlockhashStore struct { - address *common.Address - client *seth.Client - blockHashStore *blockhash_store.BlockhashStore -} - -// EthereumVRFCoordinator represents VRF coordinator contract -type EthereumVRFCoordinator struct { - address *common.Address - client *seth.Client - coordinator *solidity_vrf_coordinator_interface.VRFCoordinator -} - -type EthereumVRFCoordinatorTestV2 struct { - address *common.Address - client *seth.Client - coordinator *vrf_coordinator_test_v2.VRFCoordinatorTestV2 -} - -func (v *EthereumVRFCoordinatorTestV2) Address() string { - return v.address.Hex() -} - -// EthereumVRFConsumer represents VRF consumer contract -type EthereumVRFConsumer struct { - address *common.Address - client *seth.Client - consumer *solidity_vrf_consumer_interface.VRFConsumer -} - -// EthereumVRF represents a VRF contract -type EthereumVRF struct { - client *seth.Client - vrf *solidity_vrf_wrapper.VRF - address *common.Address -} - -type EthereumVRFMockETHLINKAggregator struct { - client *seth.Client - address *common.Address - contract *vrf_mock_ethlink_aggregator.VRFMockETHLINKAggregator -} - -func (a *EthereumVRFMockETHLINKAggregator) Address() string { - return a.address.Hex() -} - -func (a *EthereumVRFMockETHLINKAggregator) LatestRoundData() (*big.Int, error) { - data, err := a.contract.LatestRoundData(a.client.NewCallOpts()) - if err != nil { - return nil, err - } - return data.Ans, nil -} - -func (a *EthereumVRFMockETHLINKAggregator) LatestRoundDataUpdatedAt() (*big.Int, error) { - data, err := a.contract.LatestRoundData(a.client.NewCallOpts()) - if err != nil { - return nil, err - } - return data.UpdatedAt, nil -} - -func (a *EthereumVRFMockETHLINKAggregator) SetBlockTimestampDeduction(blockTimestampDeduction *big.Int) error { - _, err := a.client.Decode(a.contract.SetBlockTimestampDeduction(a.client.NewTXOpts(), blockTimestampDeduction)) - return err -} - -// DeployVRFContract deploy VRFv1 contract -func DeployVRFv1Contract(seth *seth.Client) (VRF, error) { - abi, err := solidity_vrf_wrapper.VRFMetaData.GetAbi() - if err != nil { - return &EthereumVRF{}, fmt.Errorf("failed to get VRF ABI: %w", err) - } - - vrfDeploymentData, err := seth.DeployContract( - seth.NewTXOpts(), - "VRF", - *abi, - common.FromHex(solidity_vrf_wrapper.VRFMetaData.Bin)) - if err != nil { - return &EthereumVRF{}, fmt.Errorf("VRF instance deployment have failed: %w", err) - } - - vrf, err := solidity_vrf_wrapper.NewVRF(vrfDeploymentData.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) - if err != nil { - return &EthereumVRF{}, fmt.Errorf("failed to instantiate VRF instance: %w", err) - } - - return &EthereumVRF{ - client: seth, - vrf: vrf, - address: &vrfDeploymentData.Address, - }, err -} - -// DeployBlockhashStore deploys blockhash store used with VRF contract -func DeployBlockhashStore(seth *seth.Client) (BlockHashStore, error) { - abi, err := blockhash_store.BlockhashStoreMetaData.GetAbi() - if err != nil { - return &EthereumBlockhashStore{}, fmt.Errorf("failed to get BlockhashStore ABI: %w", err) - } - - storeDeploymentData, err := seth.DeployContract( - seth.NewTXOpts(), - "BlockhashStore", - *abi, - common.FromHex(blockhash_store.BlockhashStoreMetaData.Bin)) - if err != nil { - return &EthereumBlockhashStore{}, fmt.Errorf("BlockhashStore instance deployment have failed: %w", err) - } - - store, err := blockhash_store.NewBlockhashStore(storeDeploymentData.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) - if err != nil { - return &EthereumBlockhashStore{}, fmt.Errorf("failed to instantiate BlockhashStore instance: %w", err) - } - - return &EthereumBlockhashStore{ - client: seth, - blockHashStore: store, - address: &storeDeploymentData.Address, - }, err -} - -// DeployVRFCoordinator deploys VRF coordinator contract -func DeployVRFCoordinator(seth *seth.Client, linkAddr, bhsAddr string) (VRFCoordinator, error) { - abi, err := solidity_vrf_coordinator_interface.VRFCoordinatorMetaData.GetAbi() - if err != nil { - return &EthereumVRFCoordinator{}, fmt.Errorf("failed to get VRFCoordinator ABI: %w", err) - } - - coordinatorDeploymentData, err := seth.DeployContract( - seth.NewTXOpts(), - "VRFCoordinator", - *abi, - common.FromHex(solidity_vrf_coordinator_interface.VRFCoordinatorMetaData.Bin), - common.HexToAddress(linkAddr), - common.HexToAddress(bhsAddr)) - if err != nil { - return &EthereumVRFCoordinator{}, fmt.Errorf("VRFCoordinator instance deployment have failed: %w", err) - } - - coordinator, err := solidity_vrf_coordinator_interface.NewVRFCoordinator(coordinatorDeploymentData.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) - if err != nil { - return &EthereumVRFCoordinator{}, fmt.Errorf("failed to instantiate VRFCoordinator instance: %w", err) - } - - return &EthereumVRFCoordinator{ - client: seth, - coordinator: coordinator, - address: &coordinatorDeploymentData.Address, - }, err -} - -func DeployVRFCoordinatorTestV2(seth *seth.Client, linkAddr, bhsAddr, linkEthFeedAddr string) (*EthereumVRFCoordinatorTestV2, error) { - abi, err := vrf_coordinator_test_v2.VRFCoordinatorTestV2MetaData.GetAbi() - if err != nil { - return &EthereumVRFCoordinatorTestV2{}, fmt.Errorf("failed to get VRFCoordinatorTestV2 ABI: %w", err) - } - - coordinatorDeploymentData, err := seth.DeployContract( - seth.NewTXOpts(), - "VRFCoordinatorTestV2", - *abi, - common.FromHex(vrf_coordinator_test_v2.VRFCoordinatorTestV2MetaData.Bin), - common.HexToAddress(linkAddr), - common.HexToAddress(bhsAddr), - common.HexToAddress(linkEthFeedAddr)) - if err != nil { - return &EthereumVRFCoordinatorTestV2{}, fmt.Errorf("VRFCoordinatorTestV2 instance deployment have failed: %w", err) - } - - coordinator, err := vrf_coordinator_test_v2.NewVRFCoordinatorTestV2(coordinatorDeploymentData.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) - if err != nil { - return &EthereumVRFCoordinatorTestV2{}, fmt.Errorf("failed to instantiate VRFCoordinatorTestV2 instance: %w", err) - } - - return &EthereumVRFCoordinatorTestV2{ - client: seth, - coordinator: coordinator, - address: &coordinatorDeploymentData.Address, - }, err -} - -// DeployVRFConsumer deploys VRF consumer contract -func DeployVRFConsumer(seth *seth.Client, linkAddr, coordinatorAddr string) (VRFConsumer, error) { - abi, err := solidity_vrf_consumer_interface.VRFConsumerMetaData.GetAbi() - if err != nil { - return &EthereumVRFConsumer{}, fmt.Errorf("failed to get VRFConsumer ABI: %w", err) - } - - consumerDeploymentData, err := seth.DeployContract( - seth.NewTXOpts(), - "VRFConsumer", - *abi, - common.FromHex(solidity_vrf_consumer_interface.VRFConsumerMetaData.Bin), - common.HexToAddress(coordinatorAddr), - common.HexToAddress(linkAddr), - ) - if err != nil { - return &EthereumVRFConsumer{}, fmt.Errorf("VRFConsumer instance deployment have failed: %w", err) - } - - consumer, err := solidity_vrf_consumer_interface.NewVRFConsumer(consumerDeploymentData.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) - if err != nil { - return &EthereumVRFConsumer{}, fmt.Errorf("failed to instantiate VRFConsumer instance: %w", err) - } - - return &EthereumVRFConsumer{ - client: seth, - consumer: consumer, - address: &consumerDeploymentData.Address, - }, err -} - -func DeployVRFMockETHLINKFeed(seth *seth.Client, answer *big.Int) (VRFMockETHLINKFeed, error) { - abi, err := vrf_mock_ethlink_aggregator.VRFMockETHLINKAggregatorMetaData.GetAbi() - if err != nil { - return &EthereumVRFMockETHLINKAggregator{}, fmt.Errorf("failed to get VRFMockETHLINKAggregator ABI: %w", err) - } - - deployment, err := seth.DeployContract( - seth.NewTXOpts(), - "VRFMockETHLINKAggregator", - *abi, - common.FromHex(vrf_mock_ethlink_aggregator.VRFMockETHLINKAggregatorMetaData.Bin), - answer, - ) - if err != nil { - return &EthereumVRFMockETHLINKAggregator{}, fmt.Errorf("VRFMockETHLINKAggregator deployment have failed: %w", err) - } - - contract, err := vrf_mock_ethlink_aggregator.NewVRFMockETHLINKAggregator(deployment.Address, wrappers.MustNewWrappedContractBackend(nil, seth)) - if err != nil { - return &EthereumVRFMockETHLINKAggregator{}, fmt.Errorf("failed to instantiate VRFMockETHLINKAggregator instance: %w", err) - } - - return &EthereumVRFMockETHLINKAggregator{ - client: seth, - contract: contract, - address: &deployment.Address, - }, err -} - -func (v *EthereumBlockhashStore) Address() string { - return v.address.Hex() -} - -func (v *EthereumBlockhashStore) GetBlockHash(ctx context.Context, blockNumber *big.Int) ([32]byte, error) { - blockHash, err := v.blockHashStore.GetBlockhash(&bind.CallOpts{ - From: v.client.MustGetRootKeyAddress(), - Context: ctx, - }, blockNumber) - if err != nil { - return [32]byte{}, err - } - return blockHash, nil -} - -func (v *EthereumVRFCoordinator) Address() string { - return v.address.Hex() -} - -// HashOfKey get a hash of proving key to use it as a request ID part for VRF -func (v *EthereumVRFCoordinator) HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error) { - hash, err := v.coordinator.HashOfKey(&bind.CallOpts{ - From: v.client.MustGetRootKeyAddress(), - Context: ctx, - }, pubKey) - if err != nil { - return [32]byte{}, err - } - return hash, nil -} - -// RegisterProvingKey register VRF proving key -func (v *EthereumVRFCoordinator) RegisterProvingKey( - fee *big.Int, - oracleAddr string, - publicProvingKey [2]*big.Int, - jobID [32]byte, -) error { - _, err := v.client.Decode(v.coordinator.RegisterProvingKey(v.client.NewTXOpts(), fee, common.HexToAddress(oracleAddr), publicProvingKey, jobID)) - return err -} - -func (v *EthereumVRFConsumer) Address() string { - return v.address.Hex() -} - -func (v *EthereumVRFConsumer) Fund(_ *big.Float) error { - panic("do not use this function, use actions_seth.SendFunds() instead, otherwise we will have to deal with circular dependencies") -} - -// RequestRandomness requests VRF randomness -func (v *EthereumVRFConsumer) RequestRandomness(hash [32]byte, fee *big.Int) error { - _, err := v.client.Decode(v.consumer.TestRequestRandomness(v.client.NewTXOpts(), hash, fee)) - return err -} - -// CurrentRoundID helper roundID counter in consumer to check when all randomness requests are finished -func (v *EthereumVRFConsumer) CurrentRoundID(ctx context.Context) (*big.Int, error) { - return v.consumer.CurrentRoundID(&bind.CallOpts{ - From: v.client.MustGetRootKeyAddress(), - Context: ctx, - }) -} - -// RandomnessOutput get VRF randomness output -func (v *EthereumVRFConsumer) RandomnessOutput(ctx context.Context) (*big.Int, error) { - return v.consumer.RandomnessOutput(&bind.CallOpts{ - From: v.client.MustGetRootKeyAddress(), - Context: ctx, - }) -} - -// Fund sends specified currencies to the contract -func (v *EthereumVRF) Fund(_ *big.Float) error { - panic("do not use this function, use actions_seth.SendFunds() instead, otherwise we will have to deal with circular dependencies") -} - -// ProofLength returns the PROOFLENGTH call from the VRF contract -func (v *EthereumVRF) ProofLength(ctx context.Context) (*big.Int, error) { - return v.vrf.PROOFLENGTH(&bind.CallOpts{ - From: v.client.MustGetRootKeyAddress(), - Context: ctx, - }) -} From 3ea165d7a72abe0a476e995f1c3df0f3a665e9c4 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Mon, 13 May 2024 11:50:38 +0200 Subject: [PATCH 32/43] Fix lint --- integration-tests/docker/test_env/test_env.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration-tests/docker/test_env/test_env.go b/integration-tests/docker/test_env/test_env.go index bbe50fcefc7..af50a63e6d3 100644 --- a/integration-tests/docker/test_env/test_env.go +++ b/integration-tests/docker/test_env/test_env.go @@ -235,7 +235,7 @@ func (te *CLClusterTestEnv) Cleanup(ctx context.Context, opts CleanupOpts) error te.l.Info(). Msg("Network is a simulated network. Skipping fund return.") } else { - if err := te.returnFunds(ctx); err != nil { + if err := te.returnFunds(); err != nil { return err } } @@ -356,7 +356,7 @@ func (te *CLClusterTestEnv) logWhetherAllContainersAreRunning() { } } -func (te *CLClusterTestEnv) returnFunds(ctx context.Context) error { +func (te *CLClusterTestEnv) returnFunds() error { te.l.Info().Msg("Attempting to return Chainlink node funds to default network wallets") if len(te.evmClients) == 0 && len(te.sethClients) == 0 { From 37c25fc1bf90a335864d3be6305f7bb778228fae Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Mon, 13 May 2024 11:58:24 +0200 Subject: [PATCH 33/43] Fix lint 2 --- integration-tests/docker/test_env/test_env.go | 2 +- .../docker/test_env/test_env_builder.go | 3 +-- integration-tests/load/vrfv2/vrfv2_test.go | 4 ++-- .../load/vrfv2plus/vrfv2plus_test.go | 4 ++-- integration-tests/smoke/vrfv2_test.go | 12 ++++++------ integration-tests/smoke/vrfv2plus_test.go | 18 +++++++++--------- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/integration-tests/docker/test_env/test_env.go b/integration-tests/docker/test_env/test_env.go index af50a63e6d3..2a620427885 100644 --- a/integration-tests/docker/test_env/test_env.go +++ b/integration-tests/docker/test_env/test_env.go @@ -211,7 +211,7 @@ type CleanupOpts struct { } // Cleanup cleans the environment up after it's done being used, mainly for returning funds when on live networks and logs. -func (te *CLClusterTestEnv) Cleanup(ctx context.Context, opts CleanupOpts) error { +func (te *CLClusterTestEnv) Cleanup(opts CleanupOpts) error { te.l.Info().Msg("Cleaning up test environment") runIdErr := runid.RemoveLocalRunId(te.TestConfig.GetLoggingConfig().RunId) diff --git a/integration-tests/docker/test_env/test_env_builder.go b/integration-tests/docker/test_env/test_env_builder.go index bef03a33e44..19617b0c5f7 100644 --- a/integration-tests/docker/test_env/test_env_builder.go +++ b/integration-tests/docker/test_env/test_env_builder.go @@ -18,7 +18,6 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/logstream" "github.com/smartcontractkit/chainlink-testing-framework/networks" "github.com/smartcontractkit/chainlink-testing-framework/utils/osutil" - "github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext" evmcfg "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml" "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" @@ -259,7 +258,7 @@ func (b *CLTestEnvBuilder) Build() (*CLClusterTestEnv, error) { case CleanUpTypeStandard: b.t.Cleanup(func() { // Cleanup test environment - if err := b.te.Cleanup(testcontext.Get(b.t), CleanupOpts{TestName: b.t.Name()}); err != nil { + if err := b.te.Cleanup(CleanupOpts{TestName: b.t.Name()}); err != nil { b.l.Error().Err(err).Msg("Error cleaning up test environment") } }) diff --git a/integration-tests/load/vrfv2/vrfv2_test.go b/integration-tests/load/vrfv2/vrfv2_test.go index 4d5126e35f8..deb37e5783b 100644 --- a/integration-tests/load/vrfv2/vrfv2_test.go +++ b/integration-tests/load/vrfv2/vrfv2_test.go @@ -85,7 +85,7 @@ func TestVRFV2Performance(t *testing.T) { } } if !*vrfv2Config.General.UseExistingEnv { - if err := testEnv.Cleanup(testcontext.Get(t), test_env.CleanupOpts{}); err != nil { + if err := testEnv.Cleanup(test_env.CleanupOpts{}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -223,7 +223,7 @@ func TestVRFV2BHSPerformance(t *testing.T) { } } if !*vrfv2Config.General.UseExistingEnv { - if err := testEnv.Cleanup(testcontext.Get(t), test_env.CleanupOpts{}); err != nil { + if err := testEnv.Cleanup(test_env.CleanupOpts{}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } diff --git a/integration-tests/load/vrfv2plus/vrfv2plus_test.go b/integration-tests/load/vrfv2plus/vrfv2plus_test.go index 878d7830879..85d0b9aa233 100644 --- a/integration-tests/load/vrfv2plus/vrfv2plus_test.go +++ b/integration-tests/load/vrfv2plus/vrfv2plus_test.go @@ -83,7 +83,7 @@ func TestVRFV2PlusPerformance(t *testing.T) { } } if !*testConfig.VRFv2Plus.General.UseExistingEnv { - if err := testEnv.Cleanup(testcontext.Get(t), test_env.CleanupOpts{}); err != nil { + if err := testEnv.Cleanup(test_env.CleanupOpts{}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -220,7 +220,7 @@ func TestVRFV2PlusBHSPerformance(t *testing.T) { } } if !*testConfig.VRFv2Plus.General.UseExistingEnv { - if err := testEnv.Cleanup(testcontext.Get(t), test_env.CleanupOpts{}); err != nil { + if err := testEnv.Cleanup(test_env.CleanupOpts{}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } diff --git a/integration-tests/smoke/vrfv2_test.go b/integration-tests/smoke/vrfv2_test.go index 1f2c0be17de..3632dadd404 100644 --- a/integration-tests/smoke/vrfv2_test.go +++ b/integration-tests/smoke/vrfv2_test.go @@ -61,7 +61,7 @@ func TestVRFv2Basic(t *testing.T) { } } if !*vrfv2Config.General.UseExistingEnv { - if err := testEnv.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := testEnv.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -592,7 +592,7 @@ func TestVRFv2MultipleSendingKeys(t *testing.T) { } } if !*vrfv2Config.General.UseExistingEnv { - if err := testEnv.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := testEnv.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -696,7 +696,7 @@ func TestVRFOwner(t *testing.T) { } } if !*vrfv2Config.General.UseExistingEnv { - if err := testEnv.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := testEnv.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -829,7 +829,7 @@ func TestVRFV2WithBHS(t *testing.T) { } } if !*vrfv2Config.General.UseExistingEnv { - if err := testEnv.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := testEnv.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -1047,7 +1047,7 @@ func TestVRFV2NodeReorg(t *testing.T) { } } if !*vrfv2Config.General.UseExistingEnv { - if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -1207,7 +1207,7 @@ func TestVRFv2BatchFulfillmentEnabledDisabled(t *testing.T) { } } if !*vrfv2Config.General.UseExistingEnv { - if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } diff --git a/integration-tests/smoke/vrfv2plus_test.go b/integration-tests/smoke/vrfv2plus_test.go index 7025230f8b5..089f68bf77f 100644 --- a/integration-tests/smoke/vrfv2plus_test.go +++ b/integration-tests/smoke/vrfv2plus_test.go @@ -63,7 +63,7 @@ func TestVRFv2Plus(t *testing.T) { } } if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -763,7 +763,7 @@ func TestVRFv2PlusMultipleSendingKeys(t *testing.T) { } } if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -866,7 +866,7 @@ func TestVRFv2PlusMigration(t *testing.T) { } } if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -1263,7 +1263,7 @@ func TestVRFV2PlusWithBHS(t *testing.T) { } } if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -1490,7 +1490,7 @@ func TestVRFV2PlusWithBHF(t *testing.T) { } } if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -1643,7 +1643,7 @@ func TestVRFv2PlusReplayAfterTimeout(t *testing.T) { } } if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -1837,7 +1837,7 @@ func TestVRFv2PlusPendingBlockSimulationAndZeroConfirmationDelays(t *testing.T) } } if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -1926,7 +1926,7 @@ func TestVRFv2PlusNodeReorg(t *testing.T) { } } if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } @@ -2085,7 +2085,7 @@ func TestVRFv2PlusBatchFulfillmentEnabledDisabled(t *testing.T) { } } if !*vrfv2PlusConfig.General.UseExistingEnv { - if err := env.Cleanup(testcontext.Get(t), test_env.CleanupOpts{TestName: t.Name()}); err != nil { + if err := env.Cleanup(test_env.CleanupOpts{TestName: t.Name()}); err != nil { l.Error().Err(err).Msg("Error cleaning up test environment") } } From f2ae505fcaecb809e06ba0ffc9555880ec378061 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Mon, 13 May 2024 14:08:43 +0200 Subject: [PATCH 34/43] Use AnySyncedKey in wasp guns --- .../actions/vrf/common/logging_helpers.go | 2 ++ .../actions/vrf/vrfv2/contract_steps.go | 8 ++++-- .../actions/vrf/vrfv2plus/contract_steps.go | 9 ++++++- .../contracts/contract_vrf_models.go | 2 ++ .../contracts/ethereum_vrfv2_contracts.go | 3 ++- .../contracts/ethereum_vrfv2plus_contracts.go | 3 ++- integration-tests/load/vrfv2/gun.go | 9 +++++++ integration-tests/load/vrfv2/vrfv2_test.go | 6 +++-- integration-tests/load/vrfv2plus/gun.go | 9 +++++++ .../load/vrfv2plus/vrfv2plus_test.go | 6 +++-- integration-tests/smoke/vrfv2_test.go | 14 +++++++++- integration-tests/smoke/vrfv2plus_test.go | 26 +++++++++++++++++-- 12 files changed, 85 insertions(+), 12 deletions(-) diff --git a/integration-tests/actions/vrf/common/logging_helpers.go b/integration-tests/actions/vrf/common/logging_helpers.go index f9c8a031678..c81e4bd4453 100644 --- a/integration-tests/actions/vrf/common/logging_helpers.go +++ b/integration-tests/actions/vrf/common/logging_helpers.go @@ -58,8 +58,10 @@ func LogRandomWordsFulfilledEvent( coordinator contracts.Coordinator, randomWordsFulfilledEvent *contracts.CoordinatorRandomWordsFulfilled, isNativeBilling bool, + keyNum int, ) { l.Info(). + Int("KeyNum", keyNum). Bool("Native Billing", isNativeBilling). Str("Coordinator", coordinator.Address()). Str("Total Payment", randomWordsFulfilledEvent.Payment.String()). diff --git a/integration-tests/actions/vrf/vrfv2/contract_steps.go b/integration-tests/actions/vrf/vrfv2/contract_steps.go index 96ceaebe36f..72b2cf4833c 100644 --- a/integration-tests/actions/vrf/vrfv2/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2/contract_steps.go @@ -409,6 +409,7 @@ func RequestRandomnessAndWaitForFulfillment( randomnessRequestCountPerRequest uint16, randomnessRequestCountPerRequestDeviation uint16, randomWordsFulfilledEventTimeout time.Duration, + keyNum int, ) (*contracts.CoordinatorRandomWordsRequested, *contracts.CoordinatorRandomWordsFulfilled, error) { randomWordsRequestedEvent, err := RequestRandomness( l, @@ -421,6 +422,7 @@ func RequestRandomnessAndWaitForFulfillment( numberOfWords, randomnessRequestCountPerRequest, randomnessRequestCountPerRequestDeviation, + keyNum, ) if err != nil { return nil, nil, err @@ -448,6 +450,7 @@ func RequestRandomness( numberOfWords uint32, randomnessRequestCountPerRequest uint16, randomnessRequestCountPerRequestDeviation uint16, + keyNum int, ) (*contracts.CoordinatorRandomWordsRequested, error) { logRandRequest( l, @@ -469,6 +472,7 @@ func RequestRandomness( callbackGasLimit, numberOfWords, randomnessRequestCountPerRequest, + keyNum, ) if err != nil { return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrRequestRandomness, err) @@ -563,7 +567,7 @@ func RequestRandomnessWithForceFulfillAndWaitForFulfillment( return nil, nil, nil, err case configSetEvent = <-configSetEventChannel: case randomWordsFulfilledEvent = <-randWordsFulfilledEventChannel: - vrfcommon.LogRandomWordsFulfilledEvent(l, coordinator, randomWordsFulfilledEvent, false) + vrfcommon.LogRandomWordsFulfilledEvent(l, coordinator, randomWordsFulfilledEvent, false, 0) case randomWordsForcedEvent = <-randWordsForcedEventChannel: vrfcommon.LogRandomWordsForcedEvent(l, vrfOwner, randomWordsForcedEvent) case <-time.After(randomWordsFulfilledEventTimeout): @@ -588,7 +592,7 @@ func WaitRandomWordsFulfilledEvent( if err != nil { return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrWaitRandomWordsFulfilledEvent, err) } - vrfcommon.LogRandomWordsFulfilledEvent(l, coordinator, randomWordsFulfilledEvent, false) + vrfcommon.LogRandomWordsFulfilledEvent(l, coordinator, randomWordsFulfilledEvent, false, 0) return randomWordsFulfilledEvent, err } diff --git a/integration-tests/actions/vrf/vrfv2plus/contract_steps.go b/integration-tests/actions/vrf/vrfv2plus/contract_steps.go index 725c0f4de2e..1c79c9697e5 100644 --- a/integration-tests/actions/vrf/vrfv2plus/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/contract_steps.go @@ -297,6 +297,7 @@ func RequestRandomness( isNativeBilling bool, config *vrfv2plus_config.General, l zerolog.Logger, + keyNum int, ) (*contracts.CoordinatorRandomWordsRequested, error) { LogRandRequest( l, @@ -316,6 +317,7 @@ func RequestRandomness( isNativeBilling, *config.NumberOfWords, *config.RandomnessRequestCountPerRequest, + keyNum, ) if err != nil { return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrRequestRandomness, err) @@ -333,6 +335,7 @@ func RequestRandomnessAndWaitForFulfillment( isNativeBilling bool, config *vrfv2plus_config.General, l zerolog.Logger, + keyNum int, ) (*contracts.CoordinatorRandomWordsRequested, *contracts.CoordinatorRandomWordsFulfilled, error) { randomWordsRequestedEvent, err := RequestRandomness( consumer, @@ -342,6 +345,7 @@ func RequestRandomnessAndWaitForFulfillment( isNativeBilling, config, l, + keyNum, ) if err != nil { return nil, nil, err @@ -354,6 +358,7 @@ func RequestRandomnessAndWaitForFulfillment( isNativeBilling, config.RandomWordsFulfilledEventTimeout.Duration, l, + keyNum, ) if err != nil { return nil, nil, err @@ -445,6 +450,7 @@ func DirectFundingRequestRandomnessAndWaitForFulfillment( isNativeBilling, config.RandomWordsFulfilledEventTimeout.Duration, l, + 0, ) } @@ -455,6 +461,7 @@ func WaitRandomWordsFulfilledEvent( isNativeBilling bool, randomWordsFulfilledEventTimeout time.Duration, l zerolog.Logger, + keyNum int, ) (*contracts.CoordinatorRandomWordsFulfilled, error) { randomWordsFulfilledEvent, err := coordinator.WaitForRandomWordsFulfilledEvent( contracts.RandomWordsFulfilledEventFilter{ @@ -467,7 +474,7 @@ func WaitRandomWordsFulfilledEvent( return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrWaitRandomWordsFulfilledEvent, err) } - vrfcommon.LogRandomWordsFulfilledEvent(l, coordinator, randomWordsFulfilledEvent, isNativeBilling) + vrfcommon.LogRandomWordsFulfilledEvent(l, coordinator, randomWordsFulfilledEvent, isNativeBilling, keyNum) return randomWordsFulfilledEvent, err } diff --git a/integration-tests/contracts/contract_vrf_models.go b/integration-tests/contracts/contract_vrf_models.go index 4ed527214f9..d5fbde6130f 100644 --- a/integration-tests/contracts/contract_vrf_models.go +++ b/integration-tests/contracts/contract_vrf_models.go @@ -236,6 +236,7 @@ type VRFv2LoadTestConsumer interface { callbackGasLimit uint32, numWords uint32, requestCount uint16, + keyNum int, ) (*CoordinatorRandomWordsRequested, error) RequestRandomWordsWithForceFulfill( coordinator Coordinator, @@ -273,6 +274,7 @@ type VRFv2PlusLoadTestConsumer interface { nativePayment bool, numWords uint32, requestCount uint16, + keyNum int, ) (*CoordinatorRandomWordsRequested, error) GetRequestStatus(ctx context.Context, requestID *big.Int) (vrf_v2plus_load_test_with_metrics.GetRequestStatus, error) GetLastRequestId(ctx context.Context) (*big.Int, error) diff --git a/integration-tests/contracts/ethereum_vrfv2_contracts.go b/integration-tests/contracts/ethereum_vrfv2_contracts.go index d8d073c62b7..070ef5d3311 100644 --- a/integration-tests/contracts/ethereum_vrfv2_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2_contracts.go @@ -921,8 +921,9 @@ func (v *EthereumVRFv2LoadTestConsumer) RequestRandomness( callbackGasLimit uint32, numWords uint32, requestCount uint16, + keyNum int, ) (*CoordinatorRandomWordsRequested, error) { - tx, err := v.client.Decode(v.consumer.RequestRandomWords(v.client.NewTXOpts(), subID, requestConfirmations, keyHash, callbackGasLimit, numWords, requestCount)) + tx, err := v.client.Decode(v.consumer.RequestRandomWords(v.client.NewTXKeyOpts(keyNum), subID, requestConfirmations, keyHash, callbackGasLimit, numWords, requestCount)) if err != nil { return nil, fmt.Errorf("RequestRandomWords failed, err: %w", err) } diff --git a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go index 35dbcefd1b6..5a1afa1b9a2 100644 --- a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go @@ -556,8 +556,9 @@ func (v *EthereumVRFv2PlusLoadTestConsumer) RequestRandomness( nativePayment bool, numWords uint32, requestCount uint16, + keyNum int, ) (*CoordinatorRandomWordsRequested, error) { - tx, err := v.client.Decode(v.consumer.RequestRandomWords(v.client.NewTXOpts(), subID, requestConfirmations, keyHash, callbackGasLimit, nativePayment, numWords, requestCount)) + tx, err := v.client.Decode(v.consumer.RequestRandomWords(v.client.NewTXKeyOpts(keyNum), subID, requestConfirmations, keyHash, callbackGasLimit, nativePayment, numWords, requestCount)) if err != nil { return nil, err } diff --git a/integration-tests/load/vrfv2/gun.go b/integration-tests/load/vrfv2/gun.go index d15ee18d451..f619da7b8c0 100644 --- a/integration-tests/load/vrfv2/gun.go +++ b/integration-tests/load/vrfv2/gun.go @@ -4,6 +4,7 @@ import ( "math/rand" "github.com/rs/zerolog" + "github.com/smartcontractkit/seth" "github.com/smartcontractkit/wasp" vrfcommon "github.com/smartcontractkit/chainlink/integration-tests/actions/vrf/common" @@ -17,6 +18,7 @@ type BHSTestGun struct { keyHash [32]byte testConfig *vrfv2_config.Config logger zerolog.Logger + sethClient *seth.Client } func NewBHSTestGun( @@ -25,6 +27,7 @@ func NewBHSTestGun( subIDs []uint64, testConfig *vrfv2_config.Config, logger zerolog.Logger, + sethClient *seth.Client, ) *BHSTestGun { return &BHSTestGun{ contracts: contracts, @@ -32,6 +35,7 @@ func NewBHSTestGun( keyHash: keyHash, testConfig: testConfig, logger: logger, + sethClient: sethClient, } } @@ -48,6 +52,7 @@ func (m *BHSTestGun) Call(_ *wasp.Generator) *wasp.Response { *m.testConfig.General.NumberOfWords, *m.testConfig.General.RandomnessRequestCountPerRequest, *m.testConfig.General.RandomnessRequestCountPerRequestDeviation, + m.sethClient.AnySyncedKey(), ) //todo - might need to store randRequestBlockNumber and blockhash to verify that it was stored in BHS contract at the end of the test if err != nil { @@ -62,6 +67,7 @@ type SingleHashGun struct { subIDs []uint64 testConfig *vrfv2_config.Config logger zerolog.Logger + sethClient *seth.Client } func NewSingleHashGun( @@ -70,6 +76,7 @@ func NewSingleHashGun( subIDs []uint64, testConfig *vrfv2_config.Config, logger zerolog.Logger, + sethClient *seth.Client, ) *SingleHashGun { return &SingleHashGun{ contracts: contracts, @@ -77,6 +84,7 @@ func NewSingleHashGun( subIDs: subIDs, testConfig: testConfig, logger: logger, + sethClient: sethClient, } } @@ -101,6 +109,7 @@ func (m *SingleHashGun) Call(_ *wasp.Generator) *wasp.Response { randomnessRequestCountPerRequest, *vrfv2Config.RandomnessRequestCountPerRequestDeviation, vrfv2Config.RandomWordsFulfilledEventTimeout.Duration, + m.sethClient.AnySyncedKey(), ) if err != nil { return &wasp.Response{Error: err.Error(), Failed: true} diff --git a/integration-tests/load/vrfv2/vrfv2_test.go b/integration-tests/load/vrfv2/vrfv2_test.go index deb37e5783b..a405a25fbe7 100644 --- a/integration-tests/load/vrfv2/vrfv2_test.go +++ b/integration-tests/load/vrfv2/vrfv2_test.go @@ -57,6 +57,7 @@ func TestVRFV2Performance(t *testing.T) { return } chainID := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0].ChainID + sethClient, err := testEnv.GetSethClient(chainID) updatedLabels := UpdateLabels(labels, t) l.Info(). @@ -71,7 +72,6 @@ func TestVRFV2Performance(t *testing.T) { cleanupFn := func() { teardown(t, vrfContracts.VRFV2Consumers[0], lc, updatedLabels, testReporter, testType, &testConfig) - sethClient, err := testEnv.GetSethClient(chainID) require.NoError(t, err, "Getting Seth client shouldn't fail") if sethClient.Cfg.IsSimulatedNetwork() { @@ -141,6 +141,7 @@ func TestVRFV2Performance(t *testing.T) { subIDs, vrfv2Config, l, + sethClient, ), Labels: labels, LokiConfig: lokiConfig, @@ -206,11 +207,11 @@ func TestVRFV2BHSPerformance(t *testing.T) { Msg("Performance Test Configuration") chainID := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0].ChainID + sethClient, err := testEnv.GetSethClient(chainID) cleanupFn := func() { teardown(t, vrfContracts.VRFV2Consumers[0], lc, updatedLabels, testReporter, testType, &testConfig) - sethClient, err := testEnv.GetSethClient(chainID) require.NoError(t, err, "Getting Seth client shouldn't fail") if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). @@ -278,6 +279,7 @@ func TestVRFV2BHSPerformance(t *testing.T) { underfundedSubIDs, configCopy.VRFv2, l, + sethClient, ), Labels: labels, LokiConfig: lokiConfig, diff --git a/integration-tests/load/vrfv2plus/gun.go b/integration-tests/load/vrfv2plus/gun.go index 6879fbe32dc..41ab176d056 100644 --- a/integration-tests/load/vrfv2plus/gun.go +++ b/integration-tests/load/vrfv2plus/gun.go @@ -6,6 +6,7 @@ import ( "math/rand" "github.com/rs/zerolog" + "github.com/smartcontractkit/seth" "github.com/smartcontractkit/wasp" vrfcommon "github.com/smartcontractkit/chainlink/integration-tests/actions/vrf/common" @@ -19,6 +20,7 @@ type BHSTestGun struct { subIDs []*big.Int testConfig *vrfv2plus_config.Config logger zerolog.Logger + sethClient *seth.Client } func NewBHSTestGun( @@ -27,6 +29,7 @@ func NewBHSTestGun( subIDs []*big.Int, testConfig *vrfv2plus_config.Config, logger zerolog.Logger, + sethClient *seth.Client, ) *BHSTestGun { return &BHSTestGun{ contracts: contracts, @@ -34,6 +37,7 @@ func NewBHSTestGun( keyHash: keyHash, testConfig: testConfig, logger: logger, + sethClient: sethClient, } } @@ -54,6 +58,7 @@ func (m *BHSTestGun) Call(_ *wasp.Generator) *wasp.Response { billingType, vrfv2PlusConfig, m.logger, + m.sethClient.AnySyncedKey(), ) //todo - might need to store randRequestBlockNumber and blockhash to verify that it was stored in BHS contract at the end of the test if err != nil { @@ -69,6 +74,7 @@ type SingleHashGun struct { subIDs []*big.Int testConfig *vrfv2plus_config.Config logger zerolog.Logger + sethClient *seth.Client } func NewSingleHashGun( @@ -77,6 +83,7 @@ func NewSingleHashGun( subIDs []*big.Int, testConfig *vrfv2plus_config.Config, logger zerolog.Logger, + sethClient *seth.Client, ) *SingleHashGun { return &SingleHashGun{ contracts: contracts, @@ -84,6 +91,7 @@ func NewSingleHashGun( subIDs: subIDs, testConfig: testConfig, logger: logger, + sethClient: sethClient, } } @@ -109,6 +117,7 @@ func (m *SingleHashGun) Call(_ *wasp.Generator) *wasp.Response { billingType, vrfv2PlusConfig, m.logger, + m.sethClient.AnySyncedKey(), ) if err != nil { return &wasp.Response{Error: err.Error(), Failed: true} diff --git a/integration-tests/load/vrfv2plus/vrfv2plus_test.go b/integration-tests/load/vrfv2plus/vrfv2plus_test.go index 85d0b9aa233..6f1885899e9 100644 --- a/integration-tests/load/vrfv2plus/vrfv2plus_test.go +++ b/integration-tests/load/vrfv2plus/vrfv2plus_test.go @@ -56,6 +56,7 @@ func TestVRFV2PlusPerformance(t *testing.T) { return } chainID := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0].ChainID + sethClient, err := testEnv.GetSethClient(chainID) updatedLabels := UpdateLabels(labels, t) l.Info(). @@ -70,7 +71,6 @@ func TestVRFV2PlusPerformance(t *testing.T) { cleanupFn := func() { teardown(t, vrfContracts.VRFV2PlusConsumer[0], lc, updatedLabels, testReporter, testType, &testConfig) - sethClient, err := testEnv.GetSethClient(chainID) require.NoError(t, err, "Getting Seth client shouldn't fail") if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). @@ -139,6 +139,7 @@ func TestVRFV2PlusPerformance(t *testing.T) { subIDs, vrfv2PlusConfig, l, + sethClient, ), Labels: labels, LokiConfig: wasp.NewLokiConfig(cfgl.Endpoint, cfgl.TenantId, cfgl.BasicAuth, cfgl.BearerToken), @@ -204,10 +205,10 @@ func TestVRFV2PlusBHSPerformance(t *testing.T) { Msg("Performance Test Configuration") chainID := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0].ChainID + sethClient, err := testEnv.GetSethClient(chainID) cleanupFn := func() { teardown(t, vrfContracts.VRFV2PlusConsumer[0], lc, updatedLabels, testReporter, testType, &testConfig) - sethClient, err := testEnv.GetSethClient(chainID) require.NoError(t, err, "Getting Seth client shouldn't fail") if sethClient.Cfg.IsSimulatedNetwork() { l.Info(). @@ -277,6 +278,7 @@ func TestVRFV2PlusBHSPerformance(t *testing.T) { underfundedSubIDs, configCopy.VRFv2Plus, l, + sethClient, ), Labels: labels, LokiConfig: lokiConfig, diff --git a/integration-tests/smoke/vrfv2_test.go b/integration-tests/smoke/vrfv2_test.go index 3632dadd404..85c4a4864ff 100644 --- a/integration-tests/smoke/vrfv2_test.go +++ b/integration-tests/smoke/vrfv2_test.go @@ -113,6 +113,7 @@ func TestVRFv2Basic(t *testing.T) { *configCopy.VRFv2.General.RandomnessRequestCountPerRequest, *configCopy.VRFv2.General.RandomnessRequestCountPerRequestDeviation, configCopy.VRFv2.General.RandomWordsFulfilledEventTimeout.Duration, + 0, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") @@ -168,6 +169,7 @@ func TestVRFv2Basic(t *testing.T) { *testConfig.RandomnessRequestCountPerRequest, *testConfig.RandomnessRequestCountPerRequestDeviation, testConfig.RandomWordsFulfilledEventTimeout.Duration, + 0, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") @@ -216,6 +218,7 @@ func TestVRFv2Basic(t *testing.T) { *configCopy.VRFv2.General.RandomnessRequestCountPerRequest, *configCopy.VRFv2.General.RandomnessRequestCountPerRequestDeviation, configCopy.VRFv2.General.RandomWordsFulfilledEventTimeout.Duration, + 0, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") @@ -334,6 +337,7 @@ func TestVRFv2Basic(t *testing.T) { *configCopy.VRFv2.General.RandomnessRequestCountPerRequest, *configCopy.VRFv2.General.RandomnessRequestCountPerRequestDeviation, configCopy.VRFv2.General.RandomWordsFulfilledEventTimeout.Duration, + 0, ) require.NoError(t, err) @@ -485,6 +489,7 @@ func TestVRFv2Basic(t *testing.T) { *configCopy.VRFv2.General.RandomnessRequestCountPerRequest, *configCopy.VRFv2.General.RandomnessRequestCountPerRequestDeviation, randomWordsFulfilledEventTimeout, + 0, ) require.Error(t, err, "Error should occur while waiting for fulfilment due to low sub balance") @@ -646,6 +651,7 @@ func TestVRFv2MultipleSendingKeys(t *testing.T) { *configCopy.VRFv2.General.RandomnessRequestCountPerRequest, *configCopy.VRFv2.General.RandomnessRequestCountPerRequestDeviation, configCopy.VRFv2.General.RandomWordsFulfilledEventTimeout.Duration, + 0, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") sethClient, err := testEnv.GetSethClient(chainID) @@ -884,6 +890,7 @@ func TestVRFV2WithBHS(t *testing.T) { *configCopy.VRFv2.General.NumberOfWords, *configCopy.VRFv2.General.RandomnessRequestCountPerRequest, *configCopy.VRFv2.General.RandomnessRequestCountPerRequestDeviation, + 0, ) require.NoError(t, err, "error requesting randomness") @@ -913,7 +920,7 @@ func TestVRFV2WithBHS(t *testing.T) { }, ) require.NoError(t, err, "error waiting for randomness fulfilled event") - vrfcommon.LogRandomWordsFulfilledEvent(l, vrfContracts.CoordinatorV2, randomWordsFulfilledEvent, false) + vrfcommon.LogRandomWordsFulfilledEvent(l, vrfContracts.CoordinatorV2, randomWordsFulfilledEvent, false, 0) status, err := consumers[0].GetRequestStatus(testcontext.Get(t), randomWordsFulfilledEvent.RequestId) require.NoError(t, err, "error getting rand request status") require.True(t, status.Fulfilled) @@ -954,6 +961,7 @@ func TestVRFV2WithBHS(t *testing.T) { *configCopy.VRFv2.General.NumberOfWords, *configCopy.VRFv2.General.RandomnessRequestCountPerRequest, *configCopy.VRFv2.General.RandomnessRequestCountPerRequestDeviation, + 0, ) require.NoError(t, err, "error requesting randomness") @@ -1099,6 +1107,7 @@ func TestVRFV2NodeReorg(t *testing.T) { *configCopy.VRFv2.General.RandomnessRequestCountPerRequest, *configCopy.VRFv2.General.RandomnessRequestCountPerRequestDeviation, configCopy.VRFv2.General.RandomWordsFulfilledEventTimeout.Duration, + 0, ) require.NoError(t, err) @@ -1146,6 +1155,7 @@ func TestVRFV2NodeReorg(t *testing.T) { *configCopy.VRFv2.General.NumberOfWords, *configCopy.VRFv2.General.RandomnessRequestCountPerRequest, *configCopy.VRFv2.General.RandomnessRequestCountPerRequestDeviation, + 0, ) require.NoError(t, err) @@ -1307,6 +1317,7 @@ func TestVRFv2BatchFulfillmentEnabledDisabled(t *testing.T) { *configCopy.VRFv2.General.RandomnessRequestCountPerRequest, *configCopy.VRFv2.General.RandomnessRequestCountPerRequestDeviation, configCopy.VRFv2.General.RandomWordsFulfilledEventTimeout.Duration, + 0, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") @@ -1426,6 +1437,7 @@ func TestVRFv2BatchFulfillmentEnabledDisabled(t *testing.T) { *configCopy.VRFv2.General.RandomnessRequestCountPerRequest, *configCopy.VRFv2.General.RandomnessRequestCountPerRequestDeviation, configCopy.VRFv2.General.RandomWordsFulfilledEventTimeout.Duration, + 0, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") diff --git a/integration-tests/smoke/vrfv2plus_test.go b/integration-tests/smoke/vrfv2plus_test.go index 089f68bf77f..291b803f52f 100644 --- a/integration-tests/smoke/vrfv2plus_test.go +++ b/integration-tests/smoke/vrfv2plus_test.go @@ -113,6 +113,7 @@ func TestVRFv2Plus(t *testing.T) { isNativeBilling, configCopy.VRFv2Plus.General, l, + 0, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") @@ -172,6 +173,7 @@ func TestVRFv2Plus(t *testing.T) { isNativeBilling, configCopy.VRFv2Plus.General, l, + 0, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") require.False(t, randomWordsFulfilledEvent.OnlyPremium) @@ -227,6 +229,7 @@ func TestVRFv2Plus(t *testing.T) { isNativeBilling, testConfig, l, + 0, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") @@ -272,6 +275,7 @@ func TestVRFv2Plus(t *testing.T) { isNativeBilling, configCopy.VRFv2Plus.General, l, + 0, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") @@ -539,6 +543,7 @@ func TestVRFv2Plus(t *testing.T) { false, configCopy.VRFv2Plus.General, l, + 0, ) require.Error(t, err, "error should occur for waiting for fulfilment due to low sub balance") @@ -551,6 +556,7 @@ func TestVRFv2Plus(t *testing.T) { true, configCopy.VRFv2Plus.General, l, + 0, ) require.Error(t, err, "error should occur for waiting for fulfilment due to low sub balance") @@ -679,6 +685,7 @@ func TestVRFv2Plus(t *testing.T) { false, configCopy.VRFv2Plus.General, l, + 0, ) require.NoError(t, err) @@ -690,6 +697,7 @@ func TestVRFv2Plus(t *testing.T) { true, configCopy.VRFv2Plus.General, l, + 0, ) require.NoError(t, err) amountToWithdrawLink := fulfilledEventLink.Payment @@ -815,6 +823,7 @@ func TestVRFv2PlusMultipleSendingKeys(t *testing.T) { isNativeBilling, configCopy.VRFv2Plus.General, l, + 0, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") sethClient, err := env.GetSethClient(chainID) @@ -1037,6 +1046,7 @@ func TestVRFv2PlusMigration(t *testing.T) { false, configCopy.VRFv2Plus.General, l, + 0, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") @@ -1049,6 +1059,7 @@ func TestVRFv2PlusMigration(t *testing.T) { true, configCopy.VRFv2Plus.General, l, + 0, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") }) @@ -1320,6 +1331,7 @@ func TestVRFV2PlusWithBHS(t *testing.T) { isNativeBilling, configCopy.VRFv2Plus.General, l, + 0, ) require.NoError(t, err, "error requesting randomness") @@ -1353,7 +1365,7 @@ func TestVRFV2PlusWithBHS(t *testing.T) { }, ) require.NoError(t, err, "error waiting for randomness fulfilled event") - vrfcommon.LogRandomWordsFulfilledEvent(l, vrfContracts.CoordinatorV2Plus, randomWordsFulfilledEvent, isNativeBilling) + vrfcommon.LogRandomWordsFulfilledEvent(l, vrfContracts.CoordinatorV2Plus, randomWordsFulfilledEvent, isNativeBilling, 0) status, err := consumers[0].GetRequestStatus(testcontext.Get(t), randomWordsFulfilledEvent.RequestId) require.NoError(t, err, "error getting rand request status") require.True(t, status.Fulfilled) @@ -1402,6 +1414,7 @@ func TestVRFV2PlusWithBHS(t *testing.T) { isNativeBilling, configCopy.VRFv2Plus.General, l, + 0, ) require.NoError(t, err, "error requesting randomness") randRequestBlockNumber := randomWordsRequestedEvent.Raw.BlockNumber @@ -1550,6 +1563,7 @@ func TestVRFV2PlusWithBHF(t *testing.T) { isNativeBilling, configCopy.VRFv2Plus.General, l, + 0, ) require.NoError(t, err, "error requesting randomness") @@ -1586,7 +1600,7 @@ func TestVRFV2PlusWithBHF(t *testing.T) { }, ) require.NoError(t, err, "error waiting for randomness fulfilled event") - vrfcommon.LogRandomWordsFulfilledEvent(l, vrfContracts.CoordinatorV2Plus, randomWordsFulfilledEvent, isNativeBilling) + vrfcommon.LogRandomWordsFulfilledEvent(l, vrfContracts.CoordinatorV2Plus, randomWordsFulfilledEvent, isNativeBilling, 0) status, err := consumers[0].GetRequestStatus(testcontext.Get(t), randomWordsFulfilledEvent.RequestId) require.NoError(t, err, "error getting rand request status") require.True(t, status.Fulfilled) @@ -1695,6 +1709,7 @@ func TestVRFv2PlusReplayAfterTimeout(t *testing.T) { isNativeBilling, configCopy.VRFv2Plus.General, l, + 0, ) require.NoError(t, err, "error requesting randomness and waiting for requested event") @@ -1725,6 +1740,7 @@ func TestVRFv2PlusReplayAfterTimeout(t *testing.T) { isNativeBilling, configCopy.VRFv2Plus.General, l, + 0, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") require.True(t, randomWordsFulfilledEvent.Success, "RandomWordsFulfilled Event's `Success` field should be true") @@ -1887,6 +1903,7 @@ func TestVRFv2PlusPendingBlockSimulationAndZeroConfirmationDelays(t *testing.T) isNativeBilling, config.VRFv2Plus.General, l, + 0, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") @@ -1977,6 +1994,7 @@ func TestVRFv2PlusNodeReorg(t *testing.T) { isNativeBilling, configCopy.VRFv2Plus.General, l, + 0, ) require.NoError(t, err) @@ -2004,6 +2022,7 @@ func TestVRFv2PlusNodeReorg(t *testing.T) { isNativeBilling, configCopy.VRFv2Plus.General.RandomWordsFulfilledEventTimeout.Duration, l, + 0, ) require.NoError(t, err, "error waiting for randomness fulfilled event") }) @@ -2022,6 +2041,7 @@ func TestVRFv2PlusNodeReorg(t *testing.T) { isNativeBilling, configCopy.VRFv2Plus.General, l, + 0, ) require.NoError(t, err) @@ -2181,6 +2201,7 @@ func TestVRFv2PlusBatchFulfillmentEnabledDisabled(t *testing.T) { isNativeBilling, configCopy.VRFv2Plus.General, l, + 0, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") @@ -2296,6 +2317,7 @@ func TestVRFv2PlusBatchFulfillmentEnabledDisabled(t *testing.T) { isNativeBilling, configCopy.VRFv2Plus.General, l, + 0, ) require.NoError(t, err, "error requesting randomness and waiting for fulfilment") From 161eb7b5ce1c8e923500f9dea1f5c12cb5c54c0f Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Mon, 13 May 2024 14:23:15 +0200 Subject: [PATCH 35/43] Log key num --- integration-tests/actions/vrf/common/logging_helpers.go | 2 ++ integration-tests/actions/vrf/vrfv2/contract_steps.go | 8 +++++--- integration-tests/actions/vrf/vrfv2/logging_helpers.go | 2 ++ integration-tests/actions/vrf/vrfv2plus/contract_steps.go | 6 ++++-- .../actions/vrf/vrfv2plus/logging_helpers.go | 5 ++++- integration-tests/smoke/vrfv2_test.go | 2 +- 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/integration-tests/actions/vrf/common/logging_helpers.go b/integration-tests/actions/vrf/common/logging_helpers.go index c81e4bd4453..cf65798d54b 100644 --- a/integration-tests/actions/vrf/common/logging_helpers.go +++ b/integration-tests/actions/vrf/common/logging_helpers.go @@ -36,8 +36,10 @@ func LogRandomnessRequestedEvent( coordinator contracts.Coordinator, randomWordsRequestedEvent *contracts.CoordinatorRandomWordsRequested, isNativeBilling bool, + keyNum int, ) { l.Info(). + Int("KeyNum", keyNum). Str("Coordinator", coordinator.Address()). Bool("Native Billing", isNativeBilling). Str("Request ID", randomWordsRequestedEvent.RequestId.String()). diff --git a/integration-tests/actions/vrf/vrfv2/contract_steps.go b/integration-tests/actions/vrf/vrfv2/contract_steps.go index 72b2cf4833c..59d7e688b3d 100644 --- a/integration-tests/actions/vrf/vrfv2/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2/contract_steps.go @@ -377,6 +377,7 @@ func DirectFundingRequestRandomnessAndWaitForFulfillment( randomnessRequestCountPerRequest, randomnessRequestCountPerRequestDeviation, vrfv2KeyData.KeyHash, + 0, ) randomWordsRequestedEvent, err := consumer.RequestRandomness( coordinator, @@ -463,6 +464,7 @@ func RequestRandomness( randomnessRequestCountPerRequest, randomnessRequestCountPerRequestDeviation, vrfKeyData.KeyHash, + keyNum, ) randomWordsRequestedEvent, err := consumer.RequestRandomness( coordinator, @@ -477,7 +479,7 @@ func RequestRandomness( if err != nil { return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrRequestRandomness, err) } - vrfcommon.LogRandomnessRequestedEvent(l, coordinator, randomWordsRequestedEvent, false) + vrfcommon.LogRandomnessRequestedEvent(l, coordinator, randomWordsRequestedEvent, false, keyNum) return randomWordsRequestedEvent, err } @@ -497,7 +499,7 @@ func RequestRandomnessWithForceFulfillAndWaitForFulfillment( linkAddress common.Address, randomWordsFulfilledEventTimeout time.Duration, ) (*contracts.CoordinatorConfigSet, *contracts.CoordinatorRandomWordsFulfilled, *vrf_owner.VRFOwnerRandomWordsForced, error) { - logRandRequest(l, consumer.Address(), coordinator.Address(), 0, minimumConfirmations, callbackGasLimit, numberOfWords, randomnessRequestCountPerRequest, randomnessRequestCountPerRequestDeviation, vrfv2KeyData.KeyHash) + logRandRequest(l, consumer.Address(), coordinator.Address(), 0, minimumConfirmations, callbackGasLimit, numberOfWords, randomnessRequestCountPerRequest, randomnessRequestCountPerRequestDeviation, vrfv2KeyData.KeyHash, 0) randomWordsRequestedEvent, err := consumer.RequestRandomWordsWithForceFulfill( coordinator, vrfv2KeyData.KeyHash, @@ -512,7 +514,7 @@ func RequestRandomnessWithForceFulfillAndWaitForFulfillment( return nil, nil, nil, fmt.Errorf("%s, err %w", vrfcommon.ErrRequestRandomness, err) } - vrfcommon.LogRandomnessRequestedEvent(l, coordinator, randomWordsRequestedEvent, false) + vrfcommon.LogRandomnessRequestedEvent(l, coordinator, randomWordsRequestedEvent, false, 0) errorChannel := make(chan error) configSetEventChannel := make(chan *contracts.CoordinatorConfigSet) diff --git a/integration-tests/actions/vrf/vrfv2/logging_helpers.go b/integration-tests/actions/vrf/vrfv2/logging_helpers.go index 248eebf45f1..ea6e15b2ff5 100644 --- a/integration-tests/actions/vrf/vrfv2/logging_helpers.go +++ b/integration-tests/actions/vrf/vrfv2/logging_helpers.go @@ -17,8 +17,10 @@ func logRandRequest( randomnessRequestCountPerRequest uint16, randomnessRequestCountPerRequestDeviation uint16, keyhash [32]byte, + keyNum int, ) { l.Info(). + Int("KeyNum", keyNum). Str("Consumer", consumer). Str("Coordinator", coordinator). Uint64("SubID", subID). diff --git a/integration-tests/actions/vrf/vrfv2plus/contract_steps.go b/integration-tests/actions/vrf/vrfv2plus/contract_steps.go index 1c79c9697e5..953fc3ffc89 100644 --- a/integration-tests/actions/vrf/vrfv2plus/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/contract_steps.go @@ -307,6 +307,7 @@ func RequestRandomness( isNativeBilling, vrfKeyData.KeyHash, config, + keyNum, ) randomWordsRequestedEvent, err := consumer.RequestRandomness( coordinator, @@ -322,7 +323,7 @@ func RequestRandomness( if err != nil { return nil, fmt.Errorf(vrfcommon.ErrGenericFormat, vrfcommon.ErrRequestRandomness, err) } - vrfcommon.LogRandomnessRequestedEvent(l, coordinator, randomWordsRequestedEvent, isNativeBilling) + vrfcommon.LogRandomnessRequestedEvent(l, coordinator, randomWordsRequestedEvent, isNativeBilling, keyNum) return randomWordsRequestedEvent, err } @@ -395,6 +396,7 @@ func WrapperRequestRandomness(consumer contracts.VRFv2PlusWrapperLoadTestConsume isNativeBilling, vrfKeyData.KeyHash, config, + 0, ) var randomWordsRequestedEvent *contracts.CoordinatorRandomWordsRequested var err error @@ -421,7 +423,7 @@ func WrapperRequestRandomness(consumer contracts.VRFv2PlusWrapperLoadTestConsume return nil, "", fmt.Errorf(vrfcommon.ErrGenericFormat, ErrRequestRandomnessDirectFundingLinkPayment, err) } } - vrfcommon.LogRandomnessRequestedEvent(l, coordinator, randomWordsRequestedEvent, isNativeBilling) + vrfcommon.LogRandomnessRequestedEvent(l, coordinator, randomWordsRequestedEvent, isNativeBilling, 0) wrapperAddress, err := consumer.GetWrapper(context.Background()) if err != nil { return nil, "", fmt.Errorf("error getting wrapper address, err: %w", err) diff --git a/integration-tests/actions/vrf/vrfv2plus/logging_helpers.go b/integration-tests/actions/vrf/vrfv2plus/logging_helpers.go index b613298f1fd..1c6e2edaa0a 100644 --- a/integration-tests/actions/vrf/vrfv2plus/logging_helpers.go +++ b/integration-tests/actions/vrf/vrfv2plus/logging_helpers.go @@ -19,8 +19,11 @@ func LogRandRequest( subID *big.Int, isNativeBilling bool, keyHash [32]byte, - config *vrfv2plus_config.General) { + config *vrfv2plus_config.General, + keyNum int, +) { l.Info(). + Int("KeyNum", keyNum). Str("Consumer", consumer). Str("Coordinator", coordinator). Str("SubID", subID.String()). diff --git a/integration-tests/smoke/vrfv2_test.go b/integration-tests/smoke/vrfv2_test.go index 85c4a4864ff..3b3ddab1640 100644 --- a/integration-tests/smoke/vrfv2_test.go +++ b/integration-tests/smoke/vrfv2_test.go @@ -894,7 +894,7 @@ func TestVRFV2WithBHS(t *testing.T) { ) require.NoError(t, err, "error requesting randomness") - vrfcommon.LogRandomnessRequestedEvent(l, vrfContracts.CoordinatorV2, randomWordsRequestedEvent, false) + vrfcommon.LogRandomnessRequestedEvent(l, vrfContracts.CoordinatorV2, randomWordsRequestedEvent, false, 0) randRequestBlockNumber := randomWordsRequestedEvent.Raw.BlockNumber var wg sync.WaitGroup wg.Add(1) From 8e2a981b71b74b7c95578219d862a762307c2fc5 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Mon, 13 May 2024 15:09:28 +0200 Subject: [PATCH 36/43] Add RequestRandomnessFromKey and use GetChainClientWithConfigFunction in load tests --- .../actions/vrf/vrfv2/contract_steps.go | 2 +- .../actions/vrf/vrfv2plus/contract_steps.go | 2 +- .../contracts/contract_vrf_models.go | 18 ++++++++++++++++++ .../contracts/ethereum_vrfv2_contracts.go | 12 ++++++++++++ .../contracts/ethereum_vrfv2plus_contracts.go | 13 +++++++++++++ integration-tests/load/vrfv2/vrfv2_test.go | 8 ++++++-- .../load/vrfv2plus/vrfv2plus_test.go | 13 +++++++++---- 7 files changed, 60 insertions(+), 8 deletions(-) diff --git a/integration-tests/actions/vrf/vrfv2/contract_steps.go b/integration-tests/actions/vrf/vrfv2/contract_steps.go index 59d7e688b3d..5d9b96cd2ad 100644 --- a/integration-tests/actions/vrf/vrfv2/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2/contract_steps.go @@ -466,7 +466,7 @@ func RequestRandomness( vrfKeyData.KeyHash, keyNum, ) - randomWordsRequestedEvent, err := consumer.RequestRandomness( + randomWordsRequestedEvent, err := consumer.RequestRandomnessFromKey( coordinator, vrfKeyData.KeyHash, subID, diff --git a/integration-tests/actions/vrf/vrfv2plus/contract_steps.go b/integration-tests/actions/vrf/vrfv2plus/contract_steps.go index 953fc3ffc89..27b0b69cf20 100644 --- a/integration-tests/actions/vrf/vrfv2plus/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/contract_steps.go @@ -309,7 +309,7 @@ func RequestRandomness( config, keyNum, ) - randomWordsRequestedEvent, err := consumer.RequestRandomness( + randomWordsRequestedEvent, err := consumer.RequestRandomnessFromKey( coordinator, vrfKeyData.KeyHash, subID, diff --git a/integration-tests/contracts/contract_vrf_models.go b/integration-tests/contracts/contract_vrf_models.go index d5fbde6130f..b8f0487f61f 100644 --- a/integration-tests/contracts/contract_vrf_models.go +++ b/integration-tests/contracts/contract_vrf_models.go @@ -236,6 +236,15 @@ type VRFv2LoadTestConsumer interface { callbackGasLimit uint32, numWords uint32, requestCount uint16, + ) (*CoordinatorRandomWordsRequested, error) + RequestRandomnessFromKey( + coordinator Coordinator, + keyHash [32]byte, + subID uint64, + requestConfirmations uint16, + callbackGasLimit uint32, + numWords uint32, + requestCount uint16, keyNum int, ) (*CoordinatorRandomWordsRequested, error) RequestRandomWordsWithForceFulfill( @@ -274,6 +283,15 @@ type VRFv2PlusLoadTestConsumer interface { nativePayment bool, numWords uint32, requestCount uint16, + ) (*CoordinatorRandomWordsRequested, error) + RequestRandomnessFromKey( + coordinator Coordinator, + keyHash [32]byte, subID *big.Int, + requestConfirmations uint16, + callbackGasLimit uint32, + nativePayment bool, + numWords uint32, + requestCount uint16, keyNum int, ) (*CoordinatorRandomWordsRequested, error) GetRequestStatus(ctx context.Context, requestID *big.Int) (vrf_v2plus_load_test_with_metrics.GetRequestStatus, error) diff --git a/integration-tests/contracts/ethereum_vrfv2_contracts.go b/integration-tests/contracts/ethereum_vrfv2_contracts.go index 070ef5d3311..18c32ba44c6 100644 --- a/integration-tests/contracts/ethereum_vrfv2_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2_contracts.go @@ -921,6 +921,18 @@ func (v *EthereumVRFv2LoadTestConsumer) RequestRandomness( callbackGasLimit uint32, numWords uint32, requestCount uint16, +) (*CoordinatorRandomWordsRequested, error) { + return v.RequestRandomnessFromKey(coordinator, keyHash, subID, requestConfirmations, callbackGasLimit, numWords, requestCount, 0) +} + +func (v *EthereumVRFv2LoadTestConsumer) RequestRandomnessFromKey( + coordinator Coordinator, + keyHash [32]byte, + subID uint64, + requestConfirmations uint16, + callbackGasLimit uint32, + numWords uint32, + requestCount uint16, keyNum int, ) (*CoordinatorRandomWordsRequested, error) { tx, err := v.client.Decode(v.consumer.RequestRandomWords(v.client.NewTXKeyOpts(keyNum), subID, requestConfirmations, keyHash, callbackGasLimit, numWords, requestCount)) diff --git a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go index 5a1afa1b9a2..9fad7c6d737 100644 --- a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go @@ -548,6 +548,7 @@ func (v *EthereumVRFCoordinatorV2_5) WaitForMigrationCompletedEvent(timeout time func (v *EthereumVRFv2PlusLoadTestConsumer) Address() string { return v.address.Hex() } + func (v *EthereumVRFv2PlusLoadTestConsumer) RequestRandomness( coordinator Coordinator, keyHash [32]byte, subID *big.Int, @@ -556,6 +557,18 @@ func (v *EthereumVRFv2PlusLoadTestConsumer) RequestRandomness( nativePayment bool, numWords uint32, requestCount uint16, +) (*CoordinatorRandomWordsRequested, error) { + return v.RequestRandomnessFromKey(coordinator, keyHash, subID, requestConfirmations, callbackGasLimit, nativePayment, numWords, requestCount, 0) +} + +func (v *EthereumVRFv2PlusLoadTestConsumer) RequestRandomnessFromKey( + coordinator Coordinator, + keyHash [32]byte, subID *big.Int, + requestConfirmations uint16, + callbackGasLimit uint32, + nativePayment bool, + numWords uint32, + requestCount uint16, keyNum int, ) (*CoordinatorRandomWordsRequested, error) { tx, err := v.client.Decode(v.consumer.RequestRandomWords(v.client.NewTXKeyOpts(keyNum), subID, requestConfirmations, keyHash, callbackGasLimit, nativePayment, numWords, requestCount)) diff --git a/integration-tests/load/vrfv2/vrfv2_test.go b/integration-tests/load/vrfv2/vrfv2_test.go index a405a25fbe7..07d4257e00f 100644 --- a/integration-tests/load/vrfv2/vrfv2_test.go +++ b/integration-tests/load/vrfv2/vrfv2_test.go @@ -15,6 +15,7 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/utils/ptr" "github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext" "github.com/smartcontractkit/chainlink/integration-tests/actions" + actions_seth "github.com/smartcontractkit/chainlink/integration-tests/actions/seth" vrfcommon "github.com/smartcontractkit/chainlink/integration-tests/actions/vrf/common" "github.com/smartcontractkit/chainlink/integration-tests/actions/vrf/vrfv2" "github.com/smartcontractkit/chainlink/integration-tests/contracts" @@ -56,8 +57,11 @@ func TestVRFV2Performance(t *testing.T) { l.Error().Err(err).Msg(ErrLokiClient) return } - chainID := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0].ChainID - sethClient, err := testEnv.GetSethClient(chainID) + network := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0] + chainID := network.ChainID + sethClient, err := actions_seth.GetChainClientWithConfigFunction(testConfig, network, actions_seth.OneEphemeralKeysLiveTestnetCheckFn) + require.NoError(t, err, "Error creating seth client") + updatedLabels := UpdateLabels(labels, t) l.Info(). diff --git a/integration-tests/load/vrfv2plus/vrfv2plus_test.go b/integration-tests/load/vrfv2plus/vrfv2plus_test.go index 6f1885899e9..ddeaa472db8 100644 --- a/integration-tests/load/vrfv2plus/vrfv2plus_test.go +++ b/integration-tests/load/vrfv2plus/vrfv2plus_test.go @@ -19,6 +19,7 @@ import ( "github.com/smartcontractkit/chainlink/integration-tests/contracts" "github.com/smartcontractkit/chainlink/integration-tests/testreporters" + actions_seth "github.com/smartcontractkit/chainlink/integration-tests/actions/seth" vrfcommon "github.com/smartcontractkit/chainlink/integration-tests/actions/vrf/common" "github.com/smartcontractkit/chainlink/integration-tests/docker/test_env" @@ -55,8 +56,10 @@ func TestVRFV2PlusPerformance(t *testing.T) { l.Error().Err(err).Msg(ErrLokiClient) return } - chainID := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0].ChainID - sethClient, err := testEnv.GetSethClient(chainID) + network := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0] + chainID := network.ChainID + sethClient, err := actions_seth.GetChainClientWithConfigFunction(testConfig, network, actions_seth.OneEphemeralKeysLiveTestnetCheckFn) + require.NoError(t, err, "Error creating seth client") updatedLabels := UpdateLabels(labels, t) l.Info(). @@ -204,8 +207,10 @@ func TestVRFV2PlusBHSPerformance(t *testing.T) { Bool("UseExistingEnv", *vrfv2PlusConfig.General.UseExistingEnv). Msg("Performance Test Configuration") - chainID := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0].ChainID - sethClient, err := testEnv.GetSethClient(chainID) + network := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0] + chainID := network.ChainID + sethClient, err := actions_seth.GetChainClientWithConfigFunction(testConfig, network, actions_seth.OneEphemeralKeysLiveTestnetCheckFn) + require.NoError(t, err, "Error creating seth client") cleanupFn := func() { teardown(t, vrfContracts.VRFV2PlusConsumer[0], lc, updatedLabels, testReporter, testType, &testConfig) From bd68776dab29b621126644beb44909db3744996c Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Tue, 14 May 2024 08:56:09 +0200 Subject: [PATCH 37/43] Extract events from tx logs --- .../actions/vrf/vrfv2/contract_steps.go | 2 +- .../actions/vrf/vrfv2plus/contract_steps.go | 2 +- .../contracts/contract_vrf_models.go | 22 +-- .../contracts/ethereum_vrfv2_contracts.go | 172 +++++------------- .../contracts/ethereum_vrfv2plus_contracts.go | 156 ++++++++-------- integration-tests/smoke/vrfv2_test.go | 55 +++--- integration-tests/smoke/vrfv2plus_test.go | 74 +++----- 7 files changed, 189 insertions(+), 294 deletions(-) diff --git a/integration-tests/actions/vrf/vrfv2/contract_steps.go b/integration-tests/actions/vrf/vrfv2/contract_steps.go index 5d9b96cd2ad..4f0ac9a5b6c 100644 --- a/integration-tests/actions/vrf/vrfv2/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2/contract_steps.go @@ -664,7 +664,7 @@ func CancelSubsAndReturnFunds(ctx context.Context, vrfContracts *vrfcommon.VRFCo l.Error().Err(err).Msg("Error checking if pending requests exist") } if !pendingRequestsExist { - _, err := vrfContracts.CoordinatorV2.CancelSubscription(subID, common.HexToAddress(eoaWalletAddress)) + _, _, err := vrfContracts.CoordinatorV2.CancelSubscription(subID, common.HexToAddress(eoaWalletAddress)) if err != nil { l.Error().Err(err).Msg("Error canceling subscription") } diff --git a/integration-tests/actions/vrf/vrfv2plus/contract_steps.go b/integration-tests/actions/vrf/vrfv2plus/contract_steps.go index 27b0b69cf20..6151931d566 100644 --- a/integration-tests/actions/vrf/vrfv2plus/contract_steps.go +++ b/integration-tests/actions/vrf/vrfv2plus/contract_steps.go @@ -588,7 +588,7 @@ func CancelSubsAndReturnFunds(ctx context.Context, vrfContracts *vrfcommon.VRFCo l.Error().Err(err).Msg("Error checking if pending requests exist") } if !pendingRequestsExist { - _, err := vrfContracts.CoordinatorV2Plus.CancelSubscription(subID, common.HexToAddress(eoaWalletAddress)) + _, _, err := vrfContracts.CoordinatorV2Plus.CancelSubscription(subID, common.HexToAddress(eoaWalletAddress)) if err != nil { l.Error().Err(err).Msg("Error canceling subscription") } diff --git a/integration-tests/contracts/contract_vrf_models.go b/integration-tests/contracts/contract_vrf_models.go index b8f0487f61f..7529696a77b 100644 --- a/integration-tests/contracts/contract_vrf_models.go +++ b/integration-tests/contracts/contract_vrf_models.go @@ -8,6 +8,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" + "github.com/smartcontractkit/seth" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2_5" @@ -63,20 +65,14 @@ type VRFCoordinatorV2 interface { GetSubscription(ctx context.Context, subID uint64) (Subscription, error) GetOwner(ctx context.Context) (common.Address, error) PendingRequestsExist(ctx context.Context, subID uint64) (bool, error) - OwnerCancelSubscription(subID uint64) (*types.Transaction, error) + OwnerCancelSubscription(subID uint64) (*seth.DecodedTransaction, *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) + CancelSubscription(subID uint64, to common.Address) (*seth.DecodedTransaction, *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) ParseSubscriptionCanceled(log types.Log) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) ParseRandomWordsRequested(log types.Log) (*CoordinatorRandomWordsRequested, error) ParseRandomWordsFulfilled(log types.Log) (*CoordinatorRandomWordsFulfilled, error) ParseLog(log types.Log) (generated.AbigenLog, error) - CancelSubscription(subID uint64, to common.Address) (*types.Transaction, error) FindSubscriptionID(subID uint64) (uint64, error) WaitForRandomWordsFulfilledEvent(filter RandomWordsFulfilledEventFilter) (*CoordinatorRandomWordsFulfilled, error) - WaitForRandomWordsRequestedEvent(keyHash [][32]byte, subID []uint64, sender []common.Address, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2RandomWordsRequested, error) - WaitForSubscriptionCanceledEvent(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) - WaitForSubscriptionConsumerAdded(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionConsumerAdded, error) - WaitForSubscriptionConsumerRemoved(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionConsumerRemoved, error) - WaitForSubscriptionCreatedEvent(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCreated, error) - WaitForSubscriptionFunded(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionFunded, error) WaitForConfigSetEvent(timeout time.Duration) (*CoordinatorConfigSet, error) OracleWithdraw(recipient common.Address, amount *big.Int) error } @@ -104,24 +100,21 @@ type VRFCoordinatorV2_5 interface { HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error) CreateSubscription() (*types.Transaction, error) GetActiveSubscriptionIds(ctx context.Context, startIndex *big.Int, maxCount *big.Int) ([]*big.Int, error) - Migrate(subId *big.Int, coordinatorAddress string) error + Migrate(subId *big.Int, coordinatorAddress string) (*seth.DecodedTransaction, *vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted, error) RegisterMigratableCoordinator(migratableCoordinatorAddress string) error AddConsumer(subId *big.Int, consumerAddress string) error FundSubscriptionWithNative(subId *big.Int, nativeTokenAmount *big.Int) error Address() string PendingRequestsExist(ctx context.Context, subID *big.Int) (bool, error) GetSubscription(ctx context.Context, subID *big.Int) (Subscription, error) - OwnerCancelSubscription(subID *big.Int) (*types.Transaction, error) - CancelSubscription(subID *big.Int, to common.Address) (*types.Transaction, error) + OwnerCancelSubscription(subID *big.Int) (*seth.DecodedTransaction, *vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled, error) + CancelSubscription(subID *big.Int, to common.Address) (*seth.DecodedTransaction, *vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled, error) Withdraw(recipient common.Address) error WithdrawNative(recipient common.Address) error GetNativeTokenTotalBalance(ctx context.Context) (*big.Int, error) GetLinkTotalBalance(ctx context.Context) (*big.Int, error) FindSubscriptionID(subID *big.Int) (*big.Int, error) - WaitForSubscriptionCreatedEvent(timeout time.Duration) (*vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCreated, error) - WaitForSubscriptionCanceledEvent(subID *big.Int, timeout time.Duration) (*vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled, error) WaitForRandomWordsFulfilledEvent(filter RandomWordsFulfilledEventFilter) (*CoordinatorRandomWordsFulfilled, error) - WaitForMigrationCompletedEvent(timeout time.Duration) (*vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted, error) ParseRandomWordsRequested(log types.Log) (*CoordinatorRandomWordsRequested, error) ParseRandomWordsFulfilled(log types.Log) (*CoordinatorRandomWordsFulfilled, error) WaitForConfigSetEvent(timeout time.Duration) (*CoordinatorConfigSet, error) @@ -160,7 +153,6 @@ type VRFCoordinatorV2PlusUpgradedVersion interface { GetActiveSubscriptionIds(ctx context.Context, startIndex *big.Int, maxCount *big.Int) ([]*big.Int, error) FindSubscriptionID() (*big.Int, error) WaitForRandomWordsFulfilledEvent(filter RandomWordsFulfilledEventFilter) (*CoordinatorRandomWordsFulfilled, error) - WaitForMigrationCompletedEvent(timeout time.Duration) (*vrf_v2plus_upgraded_version.VRFCoordinatorV2PlusUpgradedVersionMigrationCompleted, error) ParseRandomWordsRequested(log types.Log) (*CoordinatorRandomWordsRequested, error) ParseRandomWordsFulfilled(log types.Log) (*CoordinatorRandomWordsFulfilled, error) WaitForConfigSetEvent(timeout time.Duration) (*CoordinatorConfigSet, error) diff --git a/integration-tests/contracts/ethereum_vrfv2_contracts.go b/integration-tests/contracts/ethereum_vrfv2_contracts.go index 18c32ba44c6..09e865dedf9 100644 --- a/integration-tests/contracts/ethereum_vrfv2_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2_contracts.go @@ -529,12 +529,16 @@ func (v *EthereumVRFCoordinatorV2) OracleWithdraw(recipient common.Address, amou // return funds to the subscription owner, // down not check if pending requests for a sub exist, // outstanding requests may fail onchain -func (v *EthereumVRFCoordinatorV2) OwnerCancelSubscription(subID uint64) (*types.Transaction, error) { - // Do not wrap in Decode() to avoid waiting until the transaction is mined - return v.coordinator.OwnerCancelSubscription( +func (v *EthereumVRFCoordinatorV2) OwnerCancelSubscription(subID uint64) (*seth.DecodedTransaction, *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) { + tx, err := v.client.Decode(v.coordinator.OwnerCancelSubscription( v.client.NewTXOpts(), subID, - ) + )) + if err != nil { + return nil, nil, err + } + event, err := extractVRFCoordinatorV2SubscriptionCanceledEvent(tx.Events) + return tx, event, err } func (v *EthereumVRFCoordinatorV2) ParseSubscriptionCanceled(log types.Log) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) { @@ -583,13 +587,17 @@ func (v *EthereumVRFCoordinatorV2) ParseLog(log types.Log) (generated.AbigenLog, // CancelSubscription cancels subscription by Sub owner, // return funds to specified address, // checks if pending requests for a sub exist -func (v *EthereumVRFCoordinatorV2) CancelSubscription(subID uint64, to common.Address) (*types.Transaction, error) { - // Do not wrap in Decode() to avoid waiting until the transaction is mined. - return v.coordinator.CancelSubscription( +func (v *EthereumVRFCoordinatorV2) CancelSubscription(subID uint64, to common.Address) (*seth.DecodedTransaction, *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) { + tx, err := v.client.Decode(v.coordinator.CancelSubscription( v.client.NewTXOpts(), subID, to, - ) + )) + if err != nil { + return nil, nil, err + } + event, err := extractVRFCoordinatorV2SubscriptionCanceledEvent(tx.Events) + return tx, event, err } func (v *EthereumVRFCoordinatorV2) FindSubscriptionID(subID uint64) (uint64, error) { @@ -635,126 +643,6 @@ func (v *EthereumVRFCoordinatorV2) WaitForRandomWordsFulfilledEvent(filter Rando } } -func (v *EthereumVRFCoordinatorV2) WaitForRandomWordsRequestedEvent(keyHash [][32]byte, subID []uint64, sender []common.Address, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2RandomWordsRequested, error) { - eventsChannel := make(chan *vrf_coordinator_v2.VRFCoordinatorV2RandomWordsRequested) - subscription, err := v.coordinator.WatchRandomWordsRequested(nil, eventsChannel, keyHash, subID, sender) - if err != nil { - return nil, err - } - defer subscription.Unsubscribe() - - for { - select { - case err := <-subscription.Err(): - return nil, err - case <-time.After(timeout): - return nil, fmt.Errorf("timeout waiting for RandomWordsRequested event") - case event := <-eventsChannel: - return event, nil - } - } -} - -func (v *EthereumVRFCoordinatorV2) WaitForSubscriptionFunded(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionFunded, error) { - eventsChannel := make(chan *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionFunded) - subscription, err := v.coordinator.WatchSubscriptionFunded(nil, eventsChannel, subID) - if err != nil { - return nil, err - } - defer subscription.Unsubscribe() - - for { - select { - case err := <-subscription.Err(): - return nil, err - case <-time.After(timeout): - return nil, fmt.Errorf("timeout waiting for SubscriptionFunded event") - case event := <-eventsChannel: - return event, nil - } - } -} - -func (v *EthereumVRFCoordinatorV2) WaitForSubscriptionCanceledEvent(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) { - eventsChannel := make(chan *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled) - subscription, err := v.coordinator.WatchSubscriptionCanceled(nil, eventsChannel, subID) - if err != nil { - return nil, err - } - defer subscription.Unsubscribe() - - for { - select { - case err := <-subscription.Err(): - return nil, err - case <-time.After(timeout): - return nil, fmt.Errorf("timeout waiting for SubscriptionCanceled event") - case sub := <-eventsChannel: - return sub, nil - } - } -} - -func (v *EthereumVRFCoordinatorV2) WaitForSubscriptionCreatedEvent(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCreated, error) { - eventsChannel := make(chan *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCreated) - subscription, err := v.coordinator.WatchSubscriptionCreated(nil, eventsChannel, subID) - if err != nil { - return nil, err - } - defer subscription.Unsubscribe() - - for { - select { - case err := <-subscription.Err(): - return nil, err - case <-time.After(timeout): - return nil, fmt.Errorf("timeout waiting for SubscriptionCreated event") - case event := <-eventsChannel: - return event, nil - } - } -} - -func (v *EthereumVRFCoordinatorV2) WaitForSubscriptionConsumerAdded(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionConsumerAdded, error) { - eventsChannel := make(chan *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionConsumerAdded) - subscription, err := v.coordinator.WatchSubscriptionConsumerAdded(nil, eventsChannel, subID) - if err != nil { - return nil, err - } - defer subscription.Unsubscribe() - - for { - select { - case err := <-subscription.Err(): - return nil, err - case <-time.After(timeout): - return nil, fmt.Errorf("timeout waiting for SubscriptionConsumerAdded event") - case event := <-eventsChannel: - return event, nil - } - } -} - -func (v *EthereumVRFCoordinatorV2) WaitForSubscriptionConsumerRemoved(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionConsumerRemoved, error) { - eventsChannel := make(chan *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionConsumerRemoved) - subscription, err := v.coordinator.WatchSubscriptionConsumerRemoved(nil, eventsChannel, subID) - if err != nil { - return nil, err - } - defer subscription.Unsubscribe() - - for { - select { - case err := <-subscription.Err(): - return nil, err - case <-time.After(timeout): - return nil, fmt.Errorf("timeout waiting for SubscriptionConsumerRemoved event") - case event := <-eventsChannel: - return event, nil - } - } -} - func (v *EthereumVRFCoordinatorV2) WaitForConfigSetEvent(timeout time.Duration) (*CoordinatorConfigSet, error) { eventsChannel := make(chan *vrf_coordinator_v2.VRFCoordinatorV2ConfigSet) subscription, err := v.coordinator.WatchConfigSet(nil, eventsChannel) @@ -1255,3 +1143,31 @@ func (v *EthereumVRFMockETHLINKFeed) SetBlockTimestampDeduction(blockTimestampDe _, err := v.client.Decode(v.feed.SetBlockTimestampDeduction(v.client.NewTXOpts(), blockTimestampDeduction)) return err } + +func extractVRFCoordinatorV2SubscriptionCanceledEvent(events []seth.DecodedTransactionLog) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) { + var event vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled + for i, e := range events { + if len(e.Topics) == 0 { + return nil, fmt.Errorf("no topics in event %d", i) + } + switch e.Topics[0] { + case vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled{}.Topic().String(): + if to, ok := e.EventData["to"].(common.Address); ok { + event.To = to + } else { + return nil, fmt.Errorf("'to' not found in the event") + } + if amount, ok := e.EventData["amount"].(*big.Int); ok { + event.Amount = amount + } else { + return nil, fmt.Errorf("'amount' not found in the event") + } + if subId, ok := e.EventData["subId"].(uint64); ok { + event.SubId = subId + } else { + return nil, fmt.Errorf("'subId' not found in the event") + } + } + } + return &event, nil +} diff --git a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go index 9fad7c6d737..548bc80fcb8 100644 --- a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go @@ -291,24 +291,32 @@ func (v *EthereumVRFCoordinatorV2_5) GetNativeTokenTotalBalance(ctx context.Cont // OwnerCancelSubscription cancels subscription by Coordinator owner // return funds to sub owner, // does not check if pending requests for a sub exist -func (v *EthereumVRFCoordinatorV2_5) OwnerCancelSubscription(subID *big.Int) (*types.Transaction, error) { - // Do not wrap in Decode() to avoid waiting until the transaction is mined - return v.coordinator.OwnerCancelSubscription( +func (v *EthereumVRFCoordinatorV2_5) OwnerCancelSubscription(subID *big.Int) (*seth.DecodedTransaction, *vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled, error) { + tx, err := v.client.Decode(v.coordinator.OwnerCancelSubscription( v.client.NewTXOpts(), subID, - ) + )) + if err != nil { + return nil, nil, err + } + cancelEvent, err := extractVRFCoordinatorV25SubscriptionCanceledEvent(tx.Events) + return tx, cancelEvent, err } // CancelSubscription cancels subscription by Sub owner, // return funds to specified address, // checks if pending requests for a sub exist -func (v *EthereumVRFCoordinatorV2_5) CancelSubscription(subID *big.Int, to common.Address) (*types.Transaction, error) { - // Do not wrap in Decode() to avoid waiting until the transaction is mined - return v.coordinator.CancelSubscription( +func (v *EthereumVRFCoordinatorV2_5) CancelSubscription(subID *big.Int, to common.Address) (*seth.DecodedTransaction, *vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled, error) { + tx, err := v.client.Decode(v.coordinator.CancelSubscription( v.client.NewTXOpts(), subID, to, - ) + )) + if err != nil { + return nil, nil, err + } + cancelEvent, err := extractVRFCoordinatorV25SubscriptionCanceledEvent(tx.Events) + return tx, cancelEvent, err } func (v *EthereumVRFCoordinatorV2_5) Withdraw(recipient common.Address) error { @@ -377,10 +385,13 @@ func (v *EthereumVRFCoordinatorV2_5) CreateSubscription() (*types.Transaction, e return tx.Transaction, nil } -func (v *EthereumVRFCoordinatorV2_5) Migrate(subId *big.Int, coordinatorAddress string) error { - // Do not wrap in Decode() to avoid waiting until the transaction is mined. - _, err := v.coordinator.Migrate(v.client.NewTXOpts(), subId, common.HexToAddress(coordinatorAddress)) - return err +func (v *EthereumVRFCoordinatorV2_5) Migrate(subId *big.Int, coordinatorAddress string) (*seth.DecodedTransaction, *vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted, error) { + tx, err := v.client.Decode(v.coordinator.Migrate(v.client.NewTXOpts(), subId, common.HexToAddress(coordinatorAddress))) + if err != nil { + return nil, nil, err + } + event, err := extractVRFCoordinatorV25MigrationCompletedEvent(tx.Events) + return tx, event, err } func (v *EthereumVRFCoordinatorV2_5) RegisterMigratableCoordinator(migratableCoordinatorAddress string) error { @@ -427,26 +438,6 @@ func (v *EthereumVRFCoordinatorV2_5) FindSubscriptionID(subID *big.Int) (*big.In return subscriptionIterator.Event.SubId, nil } -func (v *EthereumVRFCoordinatorV2_5) WaitForSubscriptionCreatedEvent(timeout time.Duration) (*vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCreated, error) { - eventsChannel := make(chan *vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCreated) - subscription, err := v.coordinator.WatchSubscriptionCreated(nil, eventsChannel, nil) - if err != nil { - return nil, err - } - defer subscription.Unsubscribe() - - for { - select { - case err := <-subscription.Err(): - return nil, err - case <-time.After(timeout): - return nil, fmt.Errorf("timeout waiting for SubscriptionCreated event") - case sub := <-eventsChannel: - return sub, nil - } - } -} - func (v *EthereumVRFCoordinatorV2_5) WaitForSubscriptionCanceledEvent(subID *big.Int, timeout time.Duration) (*vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled, error) { eventsChannel := make(chan *vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled) subscription, err := v.coordinator.WatchSubscriptionCanceled(nil, eventsChannel, []*big.Int{subID}) @@ -525,26 +516,6 @@ func (v *EthereumVRFCoordinatorV2_5) WaitForConfigSetEvent(timeout time.Duration } } -func (v *EthereumVRFCoordinatorV2_5) WaitForMigrationCompletedEvent(timeout time.Duration) (*vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted, error) { - eventsChannel := make(chan *vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted) - subscription, err := v.coordinator.WatchMigrationCompleted(nil, eventsChannel) - if err != nil { - return nil, err - } - defer subscription.Unsubscribe() - - for { - select { - case err := <-subscription.Err(): - return nil, err - case <-time.After(timeout): - return nil, fmt.Errorf("timeout waiting for MigrationCompleted event") - case migrationCompletedEvent := <-eventsChannel: - return migrationCompletedEvent, nil - } - } -} - func (v *EthereumVRFv2PlusLoadTestConsumer) Address() string { return v.address.Hex() } @@ -926,26 +897,6 @@ func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) WaitForRandomWordsFulfille } } -func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) WaitForMigrationCompletedEvent(timeout time.Duration) (*vrf_v2plus_upgraded_version.VRFCoordinatorV2PlusUpgradedVersionMigrationCompleted, error) { - eventsChannel := make(chan *vrf_v2plus_upgraded_version.VRFCoordinatorV2PlusUpgradedVersionMigrationCompleted) - subscription, err := v.coordinator.WatchMigrationCompleted(nil, eventsChannel) - if err != nil { - return nil, fmt.Errorf("parse RandomWordsRequested log failed, err: %w", err) - } - defer subscription.Unsubscribe() - - for { - select { - case err := <-subscription.Err(): - return nil, err - case <-time.After(timeout): - return nil, fmt.Errorf("timeout waiting for MigrationCompleted event") - case migrationCompletedEvent := <-eventsChannel: - return migrationCompletedEvent, nil - } - } -} - func (v *EthereumVRFCoordinatorV2PlusUpgradedVersion) ParseRandomWordsRequested(log types.Log) (*CoordinatorRandomWordsRequested, error) { randomWordsRequested, err := v.coordinator.ParseRandomWordsRequested(log) if err != nil { @@ -1212,3 +1163,64 @@ func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) GetLoadTestMetrics(ctx contex FastestResponseTimeInSeconds: nil, }, nil } + +func extractVRFCoordinatorV25SubscriptionCanceledEvent(events []seth.DecodedTransactionLog) (*vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled, error) { + var cancelEvent vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled + for i, event := range events { + if len(event.Topics) == 0 { + return nil, fmt.Errorf("no topics in event %d", i) + } + switch event.Topics[0] { + case vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled{}.Topic().String(): + if to, ok := event.EventData["to"].(common.Address); ok { + cancelEvent.To = to + } else { + return nil, fmt.Errorf("'to' not found in the event") + } + if amountNative, ok := event.EventData["amountNative"].(*big.Int); ok { + cancelEvent.AmountNative = amountNative + } else { + return nil, fmt.Errorf("'amountNative' not found in the event") + } + if amountLink, ok := event.EventData["amountLink"].(*big.Int); ok { + cancelEvent.AmountLink = amountLink + } else { + return nil, fmt.Errorf("'amountLink' not found in the event") + } + if subId, ok := event.EventData["subId"].(*big.Int); ok { + cancelEvent.SubId = subId + } else { + return nil, fmt.Errorf("'subId' not found in the event") + } + } + } + return &cancelEvent, nil +} + +func extractVRFCoordinatorV25MigrationCompletedEvent(events []seth.DecodedTransactionLog) (*vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted, error) { + var event vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted + for i, e := range events { + if len(e.Topics) == 0 { + return nil, fmt.Errorf("no topics in event %d", i) + } + switch e.Topics[0] { + case vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted{}.Topic().String(): + if newCoordinator, ok := e.EventData["newCoordinator"].(common.Address); ok { + event.NewCoordinator = newCoordinator + } else { + return nil, fmt.Errorf("'newCoordinator' not found in the event") + } + if raw, ok := e.EventData["raw"].(types.Log); ok { + event.Raw = raw + } else { + return nil, fmt.Errorf("'amountNative' not found in the event") + } + if subId, ok := e.EventData["subId"].(*big.Int); ok { + event.SubId = subId + } else { + return nil, fmt.Errorf("'subId' not found in the event") + } + } + } + return &event, nil +} diff --git a/integration-tests/smoke/vrfv2_test.go b/integration-tests/smoke/vrfv2_test.go index 3b3ddab1640..355f1464891 100644 --- a/integration-tests/smoke/vrfv2_test.go +++ b/integration-tests/smoke/vrfv2_test.go @@ -400,35 +400,29 @@ func TestVRFv2Basic(t *testing.T) { Str("Returning funds to", testWalletAddress.String()). Msg("Canceling subscription and returning funds to subscription owner") - tx, err := vrfContracts.CoordinatorV2.CancelSubscription(subIDForCancelling, testWalletAddress) + cancellationTx, cancellationEvent, err := vrfContracts.CoordinatorV2.CancelSubscription(subIDForCancelling, testWalletAddress) require.NoError(t, err, "Error canceling subscription") - subscriptionCanceledEvent, err := vrfContracts.CoordinatorV2.WaitForSubscriptionCanceledEvent([]uint64{subIDForCancelling}, time.Second*30) - require.NoError(t, err, "error waiting for subscription canceled event") - - cancellationTxReceipt, err := sethClient.Client.TransactionReceipt(testcontext.Get(t), tx.Hash()) - require.NoError(t, err, "error getting tx cancellation Tx Receipt") - - txGasUsed := new(big.Int).SetUint64(cancellationTxReceipt.GasUsed) + txGasUsed := new(big.Int).SetUint64(cancellationTx.Receipt.GasUsed) // we don't have that information for older Geth versions - if cancellationTxReceipt.EffectiveGasPrice == nil { - cancellationTxReceipt.EffectiveGasPrice = new(big.Int).SetUint64(0) + if cancellationTx.Receipt.EffectiveGasPrice == nil { + cancellationTx.Receipt.EffectiveGasPrice = new(big.Int).SetUint64(0) } - cancellationTxFeeWei := new(big.Int).Mul(txGasUsed, cancellationTxReceipt.EffectiveGasPrice) + cancellationTxFeeWei := new(big.Int).Mul(txGasUsed, cancellationTx.Receipt.EffectiveGasPrice) l.Info(). Str("Cancellation Tx Fee Wei", cancellationTxFeeWei.String()). - Str("Effective Gas Price", cancellationTxReceipt.EffectiveGasPrice.String()). - Uint64("Gas Used", cancellationTxReceipt.GasUsed). + Str("Effective Gas Price", cancellationTx.Receipt.EffectiveGasPrice.String()). + Uint64("Gas Used", cancellationTx.Receipt.GasUsed). Msg("Cancellation TX Receipt") l.Info(). - Str("Returned Subscription Amount Link", subscriptionCanceledEvent.Amount.String()). - Uint64("SubID", subscriptionCanceledEvent.SubId). - Str("Returned to", subscriptionCanceledEvent.To.String()). + Str("Returned Subscription Amount Link", cancellationEvent.Amount.String()). + Uint64("SubID", cancellationEvent.SubId). + Str("Returned to", cancellationEvent.To.String()). Msg("Subscription Canceled Event") - require.Equal(t, subBalanceLink, subscriptionCanceledEvent.Amount, "SubscriptionCanceled event LINK amount is not equal to sub amount while canceling subscription") + require.Equal(t, subBalanceLink, cancellationEvent.Amount, "SubscriptionCanceled event LINK amount is not equal to sub amount while canceling subscription") testWalletBalanceLinkAfterSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), testWalletAddress.String()) require.NoError(t, err) @@ -511,34 +505,29 @@ func TestVRFv2Basic(t *testing.T) { Msg("Canceling subscription and returning funds to subscription owner") // Call OwnerCancelSubscription - tx, err := vrfContracts.CoordinatorV2.OwnerCancelSubscription(subIDForOwnerCancelling) + cancellationTx, cancellationEvent, err := vrfContracts.CoordinatorV2.OwnerCancelSubscription(subIDForOwnerCancelling) require.NoError(t, err, "Error canceling subscription") - subscriptionCanceledEvent, err := vrfContracts.CoordinatorV2.WaitForSubscriptionCanceledEvent([]uint64{subIDForOwnerCancelling}, time.Second*30) - require.NoError(t, err, "error waiting for subscription canceled event") - - cancellationTxReceipt, err := sethClient.Client.TransactionReceipt(testcontext.Get(t), tx.Hash()) - require.NoError(t, err, "error getting tx cancellation Tx Receipt") - txGasUsed := new(big.Int).SetUint64(cancellationTxReceipt.GasUsed) + txGasUsed := new(big.Int).SetUint64(cancellationTx.Receipt.GasUsed) // we don't have that information for older Geth versions - if cancellationTxReceipt.EffectiveGasPrice == nil { - cancellationTxReceipt.EffectiveGasPrice = new(big.Int).SetUint64(0) + if cancellationTx.Receipt.EffectiveGasPrice == nil { + cancellationTx.Receipt.EffectiveGasPrice = new(big.Int).SetUint64(0) } - cancellationTxFeeWei := new(big.Int).Mul(txGasUsed, cancellationTxReceipt.EffectiveGasPrice) + cancellationTxFeeWei := new(big.Int).Mul(txGasUsed, cancellationTx.Receipt.EffectiveGasPrice) l.Info(). Str("Cancellation Tx Fee Wei", cancellationTxFeeWei.String()). - Str("Effective Gas Price", cancellationTxReceipt.EffectiveGasPrice.String()). - Uint64("Gas Used", cancellationTxReceipt.GasUsed). + Str("Effective Gas Price", cancellationTx.Receipt.EffectiveGasPrice.String()). + Uint64("Gas Used", cancellationTx.Receipt.GasUsed). Msg("Cancellation TX Receipt") l.Info(). - Str("Returned Subscription Amount Link", subscriptionCanceledEvent.Amount.String()). - Uint64("SubID", subscriptionCanceledEvent.SubId). - Str("Returned to", subscriptionCanceledEvent.To.String()). + Str("Returned Subscription Amount Link", cancellationEvent.Amount.String()). + Uint64("SubID", cancellationEvent.SubId). + Str("Returned to", cancellationEvent.To.String()). Msg("Subscription Canceled Event") - require.Equal(t, subBalanceLink, subscriptionCanceledEvent.Amount, "SubscriptionCanceled event LINK amount is not equal to sub amount while canceling subscription") + require.Equal(t, subBalanceLink, cancellationEvent.Amount, "SubscriptionCanceled event LINK amount is not equal to sub amount while canceling subscription") walletBalanceLinkAfterSubCancelling, err := vrfContracts.LinkToken.BalanceOf(testcontext.Get(t), sethClient.MustGetRootKeyAddress().Hex()) require.NoError(t, err) diff --git a/integration-tests/smoke/vrfv2plus_test.go b/integration-tests/smoke/vrfv2plus_test.go index 291b803f52f..2589e6ae6e0 100644 --- a/integration-tests/smoke/vrfv2plus_test.go +++ b/integration-tests/smoke/vrfv2plus_test.go @@ -438,36 +438,32 @@ func TestVRFv2Plus(t *testing.T) { Str("Returning funds from SubID", subID.String()). Str("Returning funds to", testWalletAddress.String()). Msg("Canceling subscription and returning funds to subscription owner") - tx, err := vrfContracts.CoordinatorV2Plus.CancelSubscription(subID, testWalletAddress) - require.NoError(t, err, "Error canceling subscription") - subscriptionCanceledEvent, err := vrfContracts.CoordinatorV2Plus.WaitForSubscriptionCanceledEvent(subID, time.Second*30) - require.NoError(t, err, "error waiting for subscription canceled event") + cancellationTx, cancellationEvent, err := vrfContracts.CoordinatorV2Plus.CancelSubscription(subID, testWalletAddress) + require.NoError(t, err, "Error canceling subscription") - cancellationTxReceipt, err := sethClient.Client.TransactionReceipt(testcontext.Get(t), tx.Hash()) - require.NoError(t, err, "error getting tx cancellation Tx Receipt") - txGasUsed := new(big.Int).SetUint64(cancellationTxReceipt.GasUsed) + txGasUsed := new(big.Int).SetUint64(cancellationTx.Receipt.GasUsed) // we don't have that information for older Geth versions - if cancellationTxReceipt.EffectiveGasPrice == nil { - cancellationTxReceipt.EffectiveGasPrice = new(big.Int).SetUint64(0) + if cancellationTx.Receipt.EffectiveGasPrice == nil { + cancellationTx.Receipt.EffectiveGasPrice = new(big.Int).SetUint64(0) } - cancellationTxFeeWei := new(big.Int).Mul(txGasUsed, cancellationTxReceipt.EffectiveGasPrice) + cancellationTxFeeWei := new(big.Int).Mul(txGasUsed, cancellationTx.Receipt.EffectiveGasPrice) l.Info(). Str("Cancellation Tx Fee Wei", cancellationTxFeeWei.String()). - Str("Effective Gas Price", cancellationTxReceipt.EffectiveGasPrice.String()). - Uint64("Gas Used", cancellationTxReceipt.GasUsed). + Str("Effective Gas Price", cancellationTx.Receipt.EffectiveGasPrice.String()). + Uint64("Gas Used", cancellationTx.Receipt.GasUsed). Msg("Cancellation TX Receipt") l.Info(). - Str("Returned Subscription Amount Native", subscriptionCanceledEvent.AmountNative.String()). - Str("Returned Subscription Amount Link", subscriptionCanceledEvent.AmountLink.String()). - Str("SubID", subscriptionCanceledEvent.SubId.String()). - Str("Returned to", subscriptionCanceledEvent.To.String()). + Str("Returned Subscription Amount Native", cancellationEvent.AmountLink.String()). + Str("Returned Subscription Amount Link", cancellationEvent.AmountLink.String()). + Str("SubID", cancellationEvent.SubId.String()). + Str("Returned to", cancellationEvent.To.String()). Msg("Subscription Canceled Event") - require.Equal(t, subBalanceNative, subscriptionCanceledEvent.AmountNative, "SubscriptionCanceled event native amount is not equal to sub amount while canceling subscription") - require.Equal(t, subBalanceLink, subscriptionCanceledEvent.AmountLink, "SubscriptionCanceled event LINK amount is not equal to sub amount while canceling subscription") + require.Equal(t, subBalanceNative, cancellationEvent.AmountNative, "SubscriptionCanceled event native amount is not equal to sub amount while canceling subscription") + require.Equal(t, subBalanceLink, cancellationEvent.AmountLink, "SubscriptionCanceled event LINK amount is not equal to sub amount while canceling subscription") testWalletBalanceNativeAfterSubCancelling, err := sethClient.Client.BalanceAt(testcontext.Get(t), testWalletAddress, nil) require.NoError(t, err) @@ -582,36 +578,32 @@ func TestVRFv2Plus(t *testing.T) { Str("Returning funds from SubID", subID.String()). Str("Returning funds to", sethClient.MustGetRootKeyAddress().Hex()). Msg("Canceling subscription and returning funds to subscription owner") - tx, err := vrfContracts.CoordinatorV2Plus.OwnerCancelSubscription(subID) - require.NoError(t, err, "Error canceling subscription") - subscriptionCanceledEvent, err := vrfContracts.CoordinatorV2Plus.WaitForSubscriptionCanceledEvent(subID, time.Second*30) - require.NoError(t, err, "error waiting for subscription canceled event") + cancellationTx, cancellationEvent, err := vrfContracts.CoordinatorV2Plus.OwnerCancelSubscription(subID) + require.NoError(t, err, "Error canceling subscription") - cancellationTxReceipt, err := sethClient.Client.TransactionReceipt(testcontext.Get(t), tx.Hash()) - require.NoError(t, err, "error getting tx cancellation Tx Receipt") - txGasUsed := new(big.Int).SetUint64(cancellationTxReceipt.GasUsed) + txGasUsed := new(big.Int).SetUint64(cancellationTx.Receipt.GasUsed) // we don't have that information for older Geth versions - if cancellationTxReceipt.EffectiveGasPrice == nil { - cancellationTxReceipt.EffectiveGasPrice = new(big.Int).SetUint64(0) + if cancellationTx.Receipt.EffectiveGasPrice == nil { + cancellationTx.Receipt.EffectiveGasPrice = new(big.Int).SetUint64(0) } - cancellationTxFeeWei := new(big.Int).Mul(txGasUsed, cancellationTxReceipt.EffectiveGasPrice) + cancellationTxFeeWei := new(big.Int).Mul(txGasUsed, cancellationTx.Receipt.EffectiveGasPrice) l.Info(). Str("Cancellation Tx Fee Wei", cancellationTxFeeWei.String()). - Str("Effective Gas Price", cancellationTxReceipt.EffectiveGasPrice.String()). - Uint64("Gas Used", cancellationTxReceipt.GasUsed). + Str("Effective Gas Price", cancellationTx.Receipt.EffectiveGasPrice.String()). + Uint64("Gas Used", cancellationTx.Receipt.GasUsed). Msg("Cancellation TX Receipt") l.Info(). - Str("Returned Subscription Amount Native", subscriptionCanceledEvent.AmountNative.String()). - Str("Returned Subscription Amount Link", subscriptionCanceledEvent.AmountLink.String()). - Str("SubID", subscriptionCanceledEvent.SubId.String()). - Str("Returned to", subscriptionCanceledEvent.To.String()). + Str("Returned Subscription Amount Native", cancellationEvent.AmountNative.String()). + Str("Returned Subscription Amount Link", cancellationEvent.AmountLink.String()). + Str("SubID", cancellationEvent.SubId.String()). + Str("Returned to", cancellationEvent.To.String()). Msg("Subscription Canceled Event") - require.Equal(t, subBalanceNative, subscriptionCanceledEvent.AmountNative, "SubscriptionCanceled event native amount is not equal to sub amount while canceling subscription") - require.Equal(t, subBalanceLink, subscriptionCanceledEvent.AmountLink, "SubscriptionCanceled event LINK amount is not equal to sub amount while canceling subscription") + require.Equal(t, subBalanceNative, cancellationEvent.AmountNative, "SubscriptionCanceled event native amount is not equal to sub amount while canceling subscription") + require.Equal(t, subBalanceLink, cancellationEvent.AmountLink, "SubscriptionCanceled event LINK amount is not equal to sub amount while canceling subscription") walletBalanceNativeAfterSubCancelling, err := sethClient.Client.BalanceAt(testcontext.Get(t), common.HexToAddress(sethClient.MustGetRootKeyAddress().Hex()), nil) require.NoError(t, err) @@ -977,11 +969,8 @@ func TestVRFv2PlusMigration(t *testing.T) { migratedCoordinatorLinkTotalBalanceBeforeMigration, migratedCoordinatorEthTotalBalanceBeforeMigration, err := vrfv2plus.GetUpgradedCoordinatorTotalBalance(newCoordinator) require.NoError(t, err) - err = vrfContracts.CoordinatorV2Plus.Migrate(subID, newCoordinator.Address()) - + _, migrationCompletedEvent, err := vrfContracts.CoordinatorV2Plus.Migrate(subID, newCoordinator.Address()) require.NoError(t, err, "error migrating sub id ", subID.String(), " from ", vrfContracts.CoordinatorV2Plus.Address(), " to new Coordinator address ", newCoordinator.Address()) - migrationCompletedEvent, err := vrfContracts.CoordinatorV2Plus.WaitForMigrationCompletedEvent(time.Minute * 1) - require.NoError(t, err, "error waiting for MigrationCompleted event") vrfv2plus.LogMigrationCompletedEvent(l, migrationCompletedEvent, vrfContracts.CoordinatorV2Plus) @@ -1152,11 +1141,8 @@ func TestVRFv2PlusMigration(t *testing.T) { require.NoError(t, err) // Migrate wrapper's sub using coordinator's migrate method - err = vrfContracts.CoordinatorV2Plus.Migrate(subID, newCoordinator.Address()) - + _, migrationCompletedEvent, err := vrfContracts.CoordinatorV2Plus.Migrate(subID, newCoordinator.Address()) require.NoError(t, err, "error migrating sub id ", subID.String(), " from ", vrfContracts.CoordinatorV2Plus.Address(), " to new Coordinator address ", newCoordinator.Address()) - migrationCompletedEvent, err := vrfContracts.CoordinatorV2Plus.WaitForMigrationCompletedEvent(time.Minute * 1) - require.NoError(t, err, "error waiting for MigrationCompleted event") vrfv2plus.LogMigrationCompletedEvent(l, migrationCompletedEvent, vrfContracts.CoordinatorV2Plus) From 25aa355c0b9f1de82c053a5eeb308a8e5643edbe Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Tue, 14 May 2024 09:10:36 +0200 Subject: [PATCH 38/43] Use SethRootKeyIndex --- integration-tests/smoke/vrfv2_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/integration-tests/smoke/vrfv2_test.go b/integration-tests/smoke/vrfv2_test.go index 355f1464891..f07018a9e01 100644 --- a/integration-tests/smoke/vrfv2_test.go +++ b/integration-tests/smoke/vrfv2_test.go @@ -31,6 +31,10 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/blockhash_store" ) +const ( + SethRootKeyIndex = 0 +) + func TestVRFv2Basic(t *testing.T) { t.Parallel() var ( @@ -879,7 +883,7 @@ func TestVRFV2WithBHS(t *testing.T) { *configCopy.VRFv2.General.NumberOfWords, *configCopy.VRFv2.General.RandomnessRequestCountPerRequest, *configCopy.VRFv2.General.RandomnessRequestCountPerRequestDeviation, - 0, + SethRootKeyIndex, ) require.NoError(t, err, "error requesting randomness") @@ -950,7 +954,7 @@ func TestVRFV2WithBHS(t *testing.T) { *configCopy.VRFv2.General.NumberOfWords, *configCopy.VRFv2.General.RandomnessRequestCountPerRequest, *configCopy.VRFv2.General.RandomnessRequestCountPerRequestDeviation, - 0, + SethRootKeyIndex, ) require.NoError(t, err, "error requesting randomness") @@ -1144,7 +1148,7 @@ func TestVRFV2NodeReorg(t *testing.T) { *configCopy.VRFv2.General.NumberOfWords, *configCopy.VRFv2.General.RandomnessRequestCountPerRequest, *configCopy.VRFv2.General.RandomnessRequestCountPerRequestDeviation, - 0, + SethRootKeyIndex, ) require.NoError(t, err) From f2b51bf90feb7a8eecc962cb2bd2fe947da8651f Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Tue, 14 May 2024 11:44:22 +0200 Subject: [PATCH 39/43] Fix getting event data --- integration-tests/contracts/ethereum_vrfv2plus_contracts.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go index 548bc80fcb8..db24288a721 100644 --- a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go @@ -1210,11 +1210,6 @@ func extractVRFCoordinatorV25MigrationCompletedEvent(events []seth.DecodedTransa } else { return nil, fmt.Errorf("'newCoordinator' not found in the event") } - if raw, ok := e.EventData["raw"].(types.Log); ok { - event.Raw = raw - } else { - return nil, fmt.Errorf("'amountNative' not found in the event") - } if subId, ok := e.EventData["subId"].(*big.Int); ok { event.SubId = subId } else { From ab04fe41349ebfd0bc799bedac1648c2fa5f0151 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Wed, 15 May 2024 15:28:26 +0200 Subject: [PATCH 40/43] Fix parsing events --- .../contracts/ethereum_vrfv2_contracts.go | 56 +++++------ .../contracts/ethereum_vrfv2plus_contracts.go | 94 +++++++------------ .../load/vrfv2plus/vrfv2plus_test.go | 6 +- 3 files changed, 63 insertions(+), 93 deletions(-) diff --git a/integration-tests/contracts/ethereum_vrfv2_contracts.go b/integration-tests/contracts/ethereum_vrfv2_contracts.go index 09e865dedf9..8786f201b29 100644 --- a/integration-tests/contracts/ethereum_vrfv2_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2_contracts.go @@ -537,8 +537,18 @@ func (v *EthereumVRFCoordinatorV2) OwnerCancelSubscription(subID uint64) (*seth. if err != nil { return nil, nil, err } - event, err := extractVRFCoordinatorV2SubscriptionCanceledEvent(tx.Events) - return tx, event, err + var subCanceledEvent *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled + for _, log := range tx.Receipt.Logs { + for _, topic := range log.Topics { + if topic.Cmp(vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled{}.Topic()) == 0 { + subCanceledEvent, err = v.coordinator.ParseSubscriptionCanceled(*log) + if err != nil { + return nil, nil, fmt.Errorf("parsing SubscriptionCanceled log failed, err: %w", err) + } + } + } + } + return tx, subCanceledEvent, err } func (v *EthereumVRFCoordinatorV2) ParseSubscriptionCanceled(log types.Log) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) { @@ -596,8 +606,18 @@ func (v *EthereumVRFCoordinatorV2) CancelSubscription(subID uint64, to common.Ad if err != nil { return nil, nil, err } - event, err := extractVRFCoordinatorV2SubscriptionCanceledEvent(tx.Events) - return tx, event, err + var subCanceledEvent *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled + for _, log := range tx.Receipt.Logs { + for _, topic := range log.Topics { + if topic.Cmp(vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled{}.Topic()) == 0 { + subCanceledEvent, err = v.coordinator.ParseSubscriptionCanceled(*log) + if err != nil { + return nil, nil, fmt.Errorf("parsing SubscriptionCanceled log failed, err: %w", err) + } + } + } + } + return tx, subCanceledEvent, err } func (v *EthereumVRFCoordinatorV2) FindSubscriptionID(subID uint64) (uint64, error) { @@ -1143,31 +1163,3 @@ func (v *EthereumVRFMockETHLINKFeed) SetBlockTimestampDeduction(blockTimestampDe _, err := v.client.Decode(v.feed.SetBlockTimestampDeduction(v.client.NewTXOpts(), blockTimestampDeduction)) return err } - -func extractVRFCoordinatorV2SubscriptionCanceledEvent(events []seth.DecodedTransactionLog) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) { - var event vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled - for i, e := range events { - if len(e.Topics) == 0 { - return nil, fmt.Errorf("no topics in event %d", i) - } - switch e.Topics[0] { - case vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled{}.Topic().String(): - if to, ok := e.EventData["to"].(common.Address); ok { - event.To = to - } else { - return nil, fmt.Errorf("'to' not found in the event") - } - if amount, ok := e.EventData["amount"].(*big.Int); ok { - event.Amount = amount - } else { - return nil, fmt.Errorf("'amount' not found in the event") - } - if subId, ok := e.EventData["subId"].(uint64); ok { - event.SubId = subId - } else { - return nil, fmt.Errorf("'subId' not found in the event") - } - } - } - return &event, nil -} diff --git a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go index db24288a721..16f2ec203e7 100644 --- a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go @@ -299,7 +299,17 @@ func (v *EthereumVRFCoordinatorV2_5) OwnerCancelSubscription(subID *big.Int) (*s if err != nil { return nil, nil, err } - cancelEvent, err := extractVRFCoordinatorV25SubscriptionCanceledEvent(tx.Events) + var cancelEvent *vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled + for _, log := range tx.Receipt.Logs { + for _, topic := range log.Topics { + if topic.Cmp(vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled{}.Topic()) == 0 { + cancelEvent, err = v.coordinator.ParseSubscriptionCanceled(*log) + if err != nil { + return nil, nil, fmt.Errorf("parsing SubscriptionCanceled log failed, err: %w", err) + } + } + } + } return tx, cancelEvent, err } @@ -315,7 +325,17 @@ func (v *EthereumVRFCoordinatorV2_5) CancelSubscription(subID *big.Int, to commo if err != nil { return nil, nil, err } - cancelEvent, err := extractVRFCoordinatorV25SubscriptionCanceledEvent(tx.Events) + var cancelEvent *vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled + for _, log := range tx.Receipt.Logs { + for _, topic := range log.Topics { + if topic.Cmp(vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled{}.Topic()) == 0 { + cancelEvent, err = v.coordinator.ParseSubscriptionCanceled(*log) + if err != nil { + return nil, nil, fmt.Errorf("parsing SubscriptionCanceled log failed, err: %w", err) + } + } + } + } return tx, cancelEvent, err } @@ -390,8 +410,18 @@ func (v *EthereumVRFCoordinatorV2_5) Migrate(subId *big.Int, coordinatorAddress if err != nil { return nil, nil, err } - event, err := extractVRFCoordinatorV25MigrationCompletedEvent(tx.Events) - return tx, event, err + var migrationCompletedEvent *vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted + for _, log := range tx.Receipt.Logs { + for _, topic := range log.Topics { + if topic.Cmp(vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted{}.Topic()) == 0 { + migrationCompletedEvent, err = v.coordinator.ParseMigrationCompleted(*log) + if err != nil { + return nil, nil, fmt.Errorf("parsing MigrationCompleted log failed, err: %w", err) + } + } + } + } + return tx, migrationCompletedEvent, err } func (v *EthereumVRFCoordinatorV2_5) RegisterMigratableCoordinator(migratableCoordinatorAddress string) error { @@ -1163,59 +1193,3 @@ func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) GetLoadTestMetrics(ctx contex FastestResponseTimeInSeconds: nil, }, nil } - -func extractVRFCoordinatorV25SubscriptionCanceledEvent(events []seth.DecodedTransactionLog) (*vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled, error) { - var cancelEvent vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled - for i, event := range events { - if len(event.Topics) == 0 { - return nil, fmt.Errorf("no topics in event %d", i) - } - switch event.Topics[0] { - case vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled{}.Topic().String(): - if to, ok := event.EventData["to"].(common.Address); ok { - cancelEvent.To = to - } else { - return nil, fmt.Errorf("'to' not found in the event") - } - if amountNative, ok := event.EventData["amountNative"].(*big.Int); ok { - cancelEvent.AmountNative = amountNative - } else { - return nil, fmt.Errorf("'amountNative' not found in the event") - } - if amountLink, ok := event.EventData["amountLink"].(*big.Int); ok { - cancelEvent.AmountLink = amountLink - } else { - return nil, fmt.Errorf("'amountLink' not found in the event") - } - if subId, ok := event.EventData["subId"].(*big.Int); ok { - cancelEvent.SubId = subId - } else { - return nil, fmt.Errorf("'subId' not found in the event") - } - } - } - return &cancelEvent, nil -} - -func extractVRFCoordinatorV25MigrationCompletedEvent(events []seth.DecodedTransactionLog) (*vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted, error) { - var event vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted - for i, e := range events { - if len(e.Topics) == 0 { - return nil, fmt.Errorf("no topics in event %d", i) - } - switch e.Topics[0] { - case vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted{}.Topic().String(): - if newCoordinator, ok := e.EventData["newCoordinator"].(common.Address); ok { - event.NewCoordinator = newCoordinator - } else { - return nil, fmt.Errorf("'newCoordinator' not found in the event") - } - if subId, ok := e.EventData["subId"].(*big.Int); ok { - event.SubId = subId - } else { - return nil, fmt.Errorf("'subId' not found in the event") - } - } - } - return &event, nil -} diff --git a/integration-tests/load/vrfv2plus/vrfv2plus_test.go b/integration-tests/load/vrfv2plus/vrfv2plus_test.go index ddeaa472db8..1cb7c52c200 100644 --- a/integration-tests/load/vrfv2plus/vrfv2plus_test.go +++ b/integration-tests/load/vrfv2plus/vrfv2plus_test.go @@ -7,6 +7,7 @@ import ( "time" "github.com/rs/zerolog/log" + "github.com/smartcontractkit/seth" "github.com/smartcontractkit/wasp" "github.com/stretchr/testify/require" @@ -58,7 +59,10 @@ func TestVRFV2PlusPerformance(t *testing.T) { } network := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0] chainID := network.ChainID - sethClient, err := actions_seth.GetChainClientWithConfigFunction(testConfig, network, actions_seth.OneEphemeralKeysLiveTestnetCheckFn) + // sethClient, err := testEnv.GetSethClient(chainID) + sethClient, err := actions_seth.GetChainClientWithConfigFunction(testConfig, network, func(c *seth.Config) error { + return nil + }) require.NoError(t, err, "Error creating seth client") updatedLabels := UpdateLabels(labels, t) From 59e49d36581f93ea5e6f22c9f83d60b2dcdc2bb2 Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Wed, 15 May 2024 17:01:05 +0200 Subject: [PATCH 41/43] Fix load tests --- integration-tests/docker/test_env/test_env_builder.go | 2 +- integration-tests/load/vrfv2/vrfv2_test.go | 2 +- integration-tests/load/vrfv2plus/gun.go | 4 +++- integration-tests/load/vrfv2plus/vrfv2plus_test.go | 6 +----- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/integration-tests/docker/test_env/test_env_builder.go b/integration-tests/docker/test_env/test_env_builder.go index 0089ce0778a..d79ad22884a 100644 --- a/integration-tests/docker/test_env/test_env_builder.go +++ b/integration-tests/docker/test_env/test_env_builder.go @@ -513,7 +513,7 @@ func (b *CLTestEnvBuilder) Build() (*CLClusterTestEnv, error) { if b.hasSeth { b.te.sethClients = make(map[int64]*seth.Client) - seth, err := actions_seth.GetChainClientWithConfigFunction(b.testConfig, networkConfig, actions_seth.OneEphemeralKeysLiveTestnetAutoFixFn) + seth, err := actions_seth.GetChainClient(b.testConfig, networkConfig) if err != nil { return nil, err } diff --git a/integration-tests/load/vrfv2/vrfv2_test.go b/integration-tests/load/vrfv2/vrfv2_test.go index 76e34858216..04234a904ae 100644 --- a/integration-tests/load/vrfv2/vrfv2_test.go +++ b/integration-tests/load/vrfv2/vrfv2_test.go @@ -59,7 +59,7 @@ func TestVRFV2Performance(t *testing.T) { } network := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0] chainID := network.ChainID - sethClient, err := actions_seth.GetChainClientWithConfigFunction(testConfig, network, actions_seth.OneEphemeralKeysLiveTestnetCheckFn) + sethClient, err := actions_seth.GetChainClient(testConfig, network) require.NoError(t, err, "Error creating seth client") updatedLabels := UpdateLabels(labels, t) diff --git a/integration-tests/load/vrfv2plus/gun.go b/integration-tests/load/vrfv2plus/gun.go index 41ab176d056..5327db35a13 100644 --- a/integration-tests/load/vrfv2plus/gun.go +++ b/integration-tests/load/vrfv2plus/gun.go @@ -14,6 +14,8 @@ import ( vrfv2plus_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/vrfv2plus" ) +const RootKeyNum = 0 + type BHSTestGun struct { contracts *vrfcommon.VRFContracts keyHash [32]byte @@ -117,7 +119,7 @@ func (m *SingleHashGun) Call(_ *wasp.Generator) *wasp.Response { billingType, vrfv2PlusConfig, m.logger, - m.sethClient.AnySyncedKey(), + RootKeyNum, ) if err != nil { return &wasp.Response{Error: err.Error(), Failed: true} diff --git a/integration-tests/load/vrfv2plus/vrfv2plus_test.go b/integration-tests/load/vrfv2plus/vrfv2plus_test.go index 8acfadbe227..18ad008651f 100644 --- a/integration-tests/load/vrfv2plus/vrfv2plus_test.go +++ b/integration-tests/load/vrfv2plus/vrfv2plus_test.go @@ -7,7 +7,6 @@ import ( "time" "github.com/rs/zerolog/log" - "github.com/smartcontractkit/seth" "github.com/smartcontractkit/wasp" "github.com/stretchr/testify/require" @@ -59,10 +58,7 @@ func TestVRFV2PlusPerformance(t *testing.T) { } network := networks.MustGetSelectedNetworkConfig(testConfig.GetNetworkConfig())[0] chainID := network.ChainID - // sethClient, err := testEnv.GetSethClient(chainID) - sethClient, err := actions_seth.GetChainClientWithConfigFunction(testConfig, network, func(c *seth.Config) error { - return nil - }) + sethClient, err := actions_seth.GetChainClient(testConfig, network) require.NoError(t, err, "Error creating seth client") updatedLabels := UpdateLabels(labels, t) From d7ada9b928ae998faa308ae89cee6e582b783f2e Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Wed, 15 May 2024 17:05:43 +0200 Subject: [PATCH 42/43] Do not use AnySyncedKey --- integration-tests/load/vrfv2/gun.go | 6 ++++-- integration-tests/load/vrfv2plus/gun.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/integration-tests/load/vrfv2/gun.go b/integration-tests/load/vrfv2/gun.go index f619da7b8c0..8576715e15f 100644 --- a/integration-tests/load/vrfv2/gun.go +++ b/integration-tests/load/vrfv2/gun.go @@ -12,6 +12,8 @@ import ( vrfv2_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/vrfv2" ) +const RootKeyNum = 0 + type BHSTestGun struct { contracts *vrfcommon.VRFContracts subIDs []uint64 @@ -52,7 +54,7 @@ func (m *BHSTestGun) Call(_ *wasp.Generator) *wasp.Response { *m.testConfig.General.NumberOfWords, *m.testConfig.General.RandomnessRequestCountPerRequest, *m.testConfig.General.RandomnessRequestCountPerRequestDeviation, - m.sethClient.AnySyncedKey(), + RootKeyNum, ) //todo - might need to store randRequestBlockNumber and blockhash to verify that it was stored in BHS contract at the end of the test if err != nil { @@ -109,7 +111,7 @@ func (m *SingleHashGun) Call(_ *wasp.Generator) *wasp.Response { randomnessRequestCountPerRequest, *vrfv2Config.RandomnessRequestCountPerRequestDeviation, vrfv2Config.RandomWordsFulfilledEventTimeout.Duration, - m.sethClient.AnySyncedKey(), + RootKeyNum, ) if err != nil { return &wasp.Response{Error: err.Error(), Failed: true} diff --git a/integration-tests/load/vrfv2plus/gun.go b/integration-tests/load/vrfv2plus/gun.go index 5327db35a13..66f6f75928b 100644 --- a/integration-tests/load/vrfv2plus/gun.go +++ b/integration-tests/load/vrfv2plus/gun.go @@ -60,7 +60,7 @@ func (m *BHSTestGun) Call(_ *wasp.Generator) *wasp.Response { billingType, vrfv2PlusConfig, m.logger, - m.sethClient.AnySyncedKey(), + RootKeyNum, ) //todo - might need to store randRequestBlockNumber and blockhash to verify that it was stored in BHS contract at the end of the test if err != nil { From ef712a038581675f523fa72306052a64fb904afa Mon Sep 17 00:00:00 2001 From: lukaszcl <120112546+lukaszcl@users.noreply.github.com> Date: Wed, 15 May 2024 17:31:44 +0200 Subject: [PATCH 43/43] Support multiple keys with AvailableSethKeyNum --- .../docker/test_env/test_env_builder.go | 2 +- integration-tests/load/vrfv2/gun.go | 7 +++---- integration-tests/load/vrfv2plus/gun.go | 7 +++---- integration-tests/utils/seth.go | 12 ++++++++++++ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/integration-tests/docker/test_env/test_env_builder.go b/integration-tests/docker/test_env/test_env_builder.go index d79ad22884a..5997d67915d 100644 --- a/integration-tests/docker/test_env/test_env_builder.go +++ b/integration-tests/docker/test_env/test_env_builder.go @@ -420,7 +420,7 @@ func (b *CLTestEnvBuilder) Build() (*CLClusterTestEnv, error) { } if b.hasSeth { - seth, err := actions_seth.GetChainClientWithConfigFunction(b.testConfig, networkConfig, actions_seth.OneEphemeralKeysLiveTestnetAutoFixFn) + seth, err := actions_seth.GetChainClient(b.testConfig, networkConfig) if err != nil { return nil, err } diff --git a/integration-tests/load/vrfv2/gun.go b/integration-tests/load/vrfv2/gun.go index 8576715e15f..a962dbfd6bb 100644 --- a/integration-tests/load/vrfv2/gun.go +++ b/integration-tests/load/vrfv2/gun.go @@ -10,10 +10,9 @@ import ( vrfcommon "github.com/smartcontractkit/chainlink/integration-tests/actions/vrf/common" "github.com/smartcontractkit/chainlink/integration-tests/actions/vrf/vrfv2" vrfv2_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/vrfv2" + "github.com/smartcontractkit/chainlink/integration-tests/utils" ) -const RootKeyNum = 0 - type BHSTestGun struct { contracts *vrfcommon.VRFContracts subIDs []uint64 @@ -54,7 +53,7 @@ func (m *BHSTestGun) Call(_ *wasp.Generator) *wasp.Response { *m.testConfig.General.NumberOfWords, *m.testConfig.General.RandomnessRequestCountPerRequest, *m.testConfig.General.RandomnessRequestCountPerRequestDeviation, - RootKeyNum, + utils.AvailableSethKeyNum(m.sethClient), ) //todo - might need to store randRequestBlockNumber and blockhash to verify that it was stored in BHS contract at the end of the test if err != nil { @@ -111,7 +110,7 @@ func (m *SingleHashGun) Call(_ *wasp.Generator) *wasp.Response { randomnessRequestCountPerRequest, *vrfv2Config.RandomnessRequestCountPerRequestDeviation, vrfv2Config.RandomWordsFulfilledEventTimeout.Duration, - RootKeyNum, + utils.AvailableSethKeyNum(m.sethClient), ) if err != nil { return &wasp.Response{Error: err.Error(), Failed: true} diff --git a/integration-tests/load/vrfv2plus/gun.go b/integration-tests/load/vrfv2plus/gun.go index 66f6f75928b..c95e7161322 100644 --- a/integration-tests/load/vrfv2plus/gun.go +++ b/integration-tests/load/vrfv2plus/gun.go @@ -12,10 +12,9 @@ import ( vrfcommon "github.com/smartcontractkit/chainlink/integration-tests/actions/vrf/common" "github.com/smartcontractkit/chainlink/integration-tests/actions/vrf/vrfv2plus" vrfv2plus_config "github.com/smartcontractkit/chainlink/integration-tests/testconfig/vrfv2plus" + "github.com/smartcontractkit/chainlink/integration-tests/utils" ) -const RootKeyNum = 0 - type BHSTestGun struct { contracts *vrfcommon.VRFContracts keyHash [32]byte @@ -60,7 +59,7 @@ func (m *BHSTestGun) Call(_ *wasp.Generator) *wasp.Response { billingType, vrfv2PlusConfig, m.logger, - RootKeyNum, + utils.AvailableSethKeyNum(m.sethClient), ) //todo - might need to store randRequestBlockNumber and blockhash to verify that it was stored in BHS contract at the end of the test if err != nil { @@ -119,7 +118,7 @@ func (m *SingleHashGun) Call(_ *wasp.Generator) *wasp.Response { billingType, vrfv2PlusConfig, m.logger, - RootKeyNum, + utils.AvailableSethKeyNum(m.sethClient), ) if err != nil { return &wasp.Response{Error: err.Error(), Failed: true} diff --git a/integration-tests/utils/seth.go b/integration-tests/utils/seth.go index cc5f1c60485..af953f49d48 100644 --- a/integration-tests/utils/seth.go +++ b/integration-tests/utils/seth.go @@ -132,3 +132,15 @@ func ValidateSethNetworkConfig(cfg *seth.Network) error { return nil } + +const RootKeyNum = 0 + +// AvailableSethKeyNum returns the available Seth address index +// If there are multiple addresses, it will return any synced key +// Otherwise it will return the root key +func AvailableSethKeyNum(client *seth.Client) int { + if len(client.Addresses) > 1 { + return client.AnySyncedKey() + } + return RootKeyNum +}