Skip to content

Commit

Permalink
VRF-1098: Fix BHS Performance test after migrating to Seth (#13266)
Browse files Browse the repository at this point in the history
* VRF-1098: Fix BHS Performance test after migrating to Seth

* VRF-1098: skip tests based on env variable

* VRF-1098: retrieve blockhashtore address when using existing env

* VRF-1098: minor refactoring

* VRF-1098: big refactoring to make code more DRY
  • Loading branch information
iljapavlovs authored May 21, 2024
1 parent 14ec6c4 commit 2644bd1
Show file tree
Hide file tree
Showing 12 changed files with 348 additions and 214 deletions.
19 changes: 19 additions & 0 deletions integration-tests/actions/vrf/common/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math/big"
"sync"
"testing"
"time"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -13,6 +14,7 @@ import (

"github.com/smartcontractkit/seth"

ctf_test_env "github.com/smartcontractkit/chainlink-testing-framework/docker/test_env"
"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"
Expand Down Expand Up @@ -350,3 +352,20 @@ func FundNodesIfNeeded(ctx context.Context, existingEnvConfig *vrf_common_config
}
return nil
}

func BuildNewCLEnvForVRF(t *testing.T, envConfig VRFEnvConfig, newEnvConfig NewEnvConfig, network ctf_test_env.EthereumNetwork) (*test_env.CLClusterTestEnv, error) {
env, err := test_env.NewCLTestEnvBuilder().
WithTestInstance(t).
WithTestConfig(&envConfig.TestConfig).
WithPrivateEthereumNetwork(network.EthereumNetworkConfig).
WithCLNodes(len(newEnvConfig.NodesToCreate)).
WithFunding(big.NewFloat(*envConfig.TestConfig.Common.ChainlinkNodeFunding)).
WithChainlinkNodeLogScanner(newEnvConfig.ChainlinkNodeLogScannerSettings).
WithCustomCleanup(envConfig.CleanupFn).
WithSeth().
Build()
if err != nil {
return nil, fmt.Errorf("%s, err: %w", "error creating test env", err)
}
return env, nil
}
16 changes: 12 additions & 4 deletions integration-tests/actions/vrf/common/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
"github.com/smartcontractkit/chainlink/integration-tests/docker/test_env"
tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig"
)

type VRFEncodedProvingKey [2]*big.Int
Expand Down Expand Up @@ -83,8 +84,15 @@ type VRFLoadTestConsumer interface {
}

type NewEnvConfig struct {
NodesToCreate []VRFNodeType
NumberOfTxKeysToCreate int
UseVRFOwner bool
UseTestCoordinator bool
NodesToCreate []VRFNodeType
NumberOfTxKeysToCreate int
UseVRFOwner bool
UseTestCoordinator bool
ChainlinkNodeLogScannerSettings test_env.ChainlinkNodeLogScannerSettings
}

type VRFEnvConfig struct {
TestConfig tc.TestConfig
ChainID int64
CleanupFn func()
}
67 changes: 26 additions & 41 deletions integration-tests/actions/vrf/vrfv2/setup_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,9 @@ func SetupVRFV2WrapperEnvironment(
func SetupVRFV2Universe(
ctx context.Context,
t *testing.T,
testConfig tc.TestConfig,
chainID int64,
cleanupFn func(),
envConfig vrfcommon.VRFEnvConfig,
newEnvConfig vrfcommon.NewEnvConfig,
l zerolog.Logger,
chainlinkNodeLogScannerSettings test_env.ChainlinkNodeLogScannerSettings,
) (*test_env.CLClusterTestEnv, *vrfcommon.VRFContracts, *vrfcommon.VRFKeyData, map[vrfcommon.VRFNodeType]*vrfcommon.VRFNode, error) {
var (
env *test_env.CLClusterTestEnv
Expand All @@ -319,13 +316,13 @@ func SetupVRFV2Universe(
nodeTypeToNodeMap map[vrfcommon.VRFNodeType]*vrfcommon.VRFNode
err error
)
if *testConfig.VRFv2.General.UseExistingEnv {
vrfContracts, vrfKey, env, err = SetupVRFV2ForExistingEnv(t, testConfig, chainID, cleanupFn, l)
if *envConfig.TestConfig.VRFv2.General.UseExistingEnv {
vrfContracts, vrfKey, env, err = SetupVRFV2ForExistingEnv(t, envConfig, l)
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "Error setting up VRF V2 for Existing env", err)
}
} else {
vrfContracts, vrfKey, env, nodeTypeToNodeMap, err = SetupVRFV2ForNewEnv(ctx, t, testConfig, chainID, cleanupFn, newEnvConfig, l, chainlinkNodeLogScannerSettings)
vrfContracts, vrfKey, env, nodeTypeToNodeMap, err = SetupVRFV2ForNewEnv(ctx, t, envConfig, newEnvConfig, l)
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "Error setting up VRF V2 for New env", err)
}
Expand All @@ -336,54 +333,36 @@ func SetupVRFV2Universe(
func SetupVRFV2ForNewEnv(
ctx context.Context,
t *testing.T,
testConfig tc.TestConfig,
chainID int64,
cleanupFn func(),
envConfig vrfcommon.VRFEnvConfig,
newEnvConfig vrfcommon.NewEnvConfig,
l zerolog.Logger,
chainlinkNodeLogScannerSettings test_env.ChainlinkNodeLogScannerSettings,
) (*vrfcommon.VRFContracts, *vrfcommon.VRFKeyData, *test_env.CLClusterTestEnv, map[vrfcommon.VRFNodeType]*vrfcommon.VRFNode, error) {
network, err := actions.EthereumNetworkConfigFromConfig(l, &testConfig)
network, err := actions.EthereumNetworkConfigFromConfig(l, &envConfig.TestConfig)
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "Error building ethereum network config", err)
return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "Error building ethereum network config for V2", err)
}

env, err := test_env.NewCLTestEnvBuilder().
WithTestInstance(t).
WithTestConfig(&testConfig).
WithPrivateEthereumNetwork(network.EthereumNetworkConfig).
WithCLNodes(len(newEnvConfig.NodesToCreate)).
WithFunding(big.NewFloat(*testConfig.Common.ChainlinkNodeFunding)).
WithChainlinkNodeLogScanner(chainlinkNodeLogScannerSettings).
WithCustomCleanup(cleanupFn).
WithSeth().
Build()

env, err := vrfcommon.BuildNewCLEnvForVRF(t, envConfig, newEnvConfig, network)
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "error creating test env", err)
return nil, nil, nil, nil, err
}

sethClient, err := env.GetSethClientForSelectedNetwork()
if err != nil {
return nil, nil, nil, nil, err
}

mockETHLinkFeed, err := contracts.DeployVRFMockETHLINKFeed(sethClient, big.NewInt(*testConfig.VRFv2.General.LinkNativeFeedResponse))
mockETHLinkFeed, err := contracts.DeployVRFMockETHLINKFeed(sethClient, big.NewInt(*envConfig.TestConfig.VRFv2.General.LinkNativeFeedResponse))
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "error deploying mock ETH/LINK feed", err)
}

linkToken, err := contracts.DeployLinkTokenContract(l, sethClient)
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "error deploying LINK contract", err)
}

vrfContracts, vrfKey, nodeTypeToNode, err := SetupVRFV2Environment(
ctx,
env,
chainID,
envConfig.ChainID,
newEnvConfig.NodesToCreate,
&testConfig,
&envConfig.TestConfig,
newEnvConfig.UseVRFOwner,
newEnvConfig.UseTestCoordinator,
linkToken,
Expand All @@ -399,12 +378,12 @@ func SetupVRFV2ForNewEnv(
return vrfContracts, vrfKey, env, nodeTypeToNode, nil
}

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
func SetupVRFV2ForExistingEnv(t *testing.T, envConfig vrfcommon.VRFEnvConfig, l zerolog.Logger) (*vrfcommon.VRFContracts, *vrfcommon.VRFKeyData, *test_env.CLClusterTestEnv, error) {
commonExistingEnvConfig := envConfig.TestConfig.VRFv2.ExistingEnvConfig.ExistingEnvConfig
env, err := test_env.NewCLTestEnvBuilder().
WithTestInstance(t).
WithTestConfig(&testConfig).
WithCustomCleanup(cleanupFn).
WithTestConfig(&envConfig.TestConfig).
WithCustomCleanup(envConfig.CleanupFn).
WithSeth().
Build()
if err != nil {
Expand All @@ -423,21 +402,27 @@ func SetupVRFV2ForExistingEnv(t *testing.T, testConfig tc.TestConfig, chainID in
if err != nil {
return nil, nil, nil, fmt.Errorf("%s, err: %w", "error loading LinkToken", err)
}

sethClient, err := env.GetSethClient(chainID)
sethClient, err := env.GetSethClient(envConfig.ChainID)
if err != nil {
return nil, nil, nil, err
}

err = vrfcommon.FundNodesIfNeeded(testcontext.Get(t), commonExistingEnvConfig, sethClient, l)
if err != nil {
return nil, nil, nil, fmt.Errorf("err: %w", err)
}
blockHashStoreAddress, err := coordinator.GetBlockHashStoreAddress(testcontext.Get(t))
if err != nil {
return nil, nil, nil, fmt.Errorf("err: %w", err)
}
blockHashStore, err := contracts.LoadBlockHashStore(sethClient, blockHashStoreAddress.String())
if err != nil {
return nil, nil, nil, fmt.Errorf("%s, err: %w", "error loading BlockHashStore", err)
}
vrfContracts := &vrfcommon.VRFContracts{
CoordinatorV2: coordinator,
VRFV2Consumers: nil,
LinkToken: linkToken,
BHS: nil,
BHS: blockHashStore,
}
vrfKey := &vrfcommon.VRFKeyData{
VRFKey: nil,
Expand Down
69 changes: 27 additions & 42 deletions integration-tests/actions/vrf/vrfv2plus/setup_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,9 @@ func SetupVRFV2PlusWrapperEnvironment(
func SetupVRFV2PlusUniverse(
ctx context.Context,
t *testing.T,
testConfig tc.TestConfig,
chainID int64,
cleanupFn func(),
envConfig vrfcommon.VRFEnvConfig,
newEnvConfig vrfcommon.NewEnvConfig,
l zerolog.Logger,
chainlinkNodeLogScannerSettings test_env.ChainlinkNodeLogScannerSettings,
) (*test_env.CLClusterTestEnv, *vrfcommon.VRFContracts, *vrfcommon.VRFKeyData, map[vrfcommon.VRFNodeType]*vrfcommon.VRFNode, error) {
var (
env *test_env.CLClusterTestEnv
Expand All @@ -372,13 +369,13 @@ func SetupVRFV2PlusUniverse(
nodeTypeToNode map[vrfcommon.VRFNodeType]*vrfcommon.VRFNode
err error
)
if *testConfig.VRFv2Plus.General.UseExistingEnv {
vrfContracts, vrfKey, env, err = SetupVRFV2PlusForExistingEnv(t, testConfig, chainID, cleanupFn, l)
if *envConfig.TestConfig.VRFv2Plus.General.UseExistingEnv {
vrfContracts, vrfKey, env, err = SetupVRFV2PlusForExistingEnv(t, envConfig, l)
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "Error setting up VRF V2 Plus for Existing env", err)
}
} else {
vrfContracts, vrfKey, env, nodeTypeToNode, err = SetupVRFV2PlusForNewEnv(ctx, t, testConfig, chainID, cleanupFn, newEnvConfig, l, chainlinkNodeLogScannerSettings)
vrfContracts, vrfKey, env, nodeTypeToNode, err = SetupVRFV2PlusForNewEnv(ctx, t, envConfig, newEnvConfig, l)
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "Error setting up VRF V2 Plus for New env", err)
}
Expand All @@ -389,52 +386,36 @@ func SetupVRFV2PlusUniverse(
func SetupVRFV2PlusForNewEnv(
ctx context.Context,
t *testing.T,
testConfig tc.TestConfig,
chainID int64,
cleanupFn func(),
envConfig vrfcommon.VRFEnvConfig,
newEnvConfig vrfcommon.NewEnvConfig,
l zerolog.Logger,
chainlinkNodeLogScannerSettings test_env.ChainlinkNodeLogScannerSettings,
) (*vrfcommon.VRFContracts, *vrfcommon.VRFKeyData, *test_env.CLClusterTestEnv, map[vrfcommon.VRFNodeType]*vrfcommon.VRFNode, error) {
network, err := actions.EthereumNetworkConfigFromConfig(l, &testConfig)
network, err := actions.EthereumNetworkConfigFromConfig(l, &envConfig.TestConfig)
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "Error building ethereum network config", err)
return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "Error building ethereum network config for V2Plus", err)
}
env, err := test_env.NewCLTestEnvBuilder().
WithTestInstance(t).
WithTestConfig(&testConfig).
WithPrivateEthereumNetwork(network.EthereumNetworkConfig).
WithCLNodes(len(newEnvConfig.NodesToCreate)).
WithFunding(big.NewFloat(*testConfig.Common.ChainlinkNodeFunding)).
WithChainlinkNodeLogScanner(chainlinkNodeLogScannerSettings).
WithCustomCleanup(cleanupFn).
WithSeth().
Build()
env, err := vrfcommon.BuildNewCLEnvForVRF(t, envConfig, newEnvConfig, network)
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "error creating test env", err)
return nil, nil, nil, nil, err
}

sethClient, err := env.GetSethClient(chainID)
sethClient, err := env.GetSethClient(envConfig.ChainID)
if err != nil {
return nil, nil, nil, nil, err
}

mockETHLinkFeed, err := contracts.DeployVRFMockETHLINKFeed(sethClient, big.NewInt(*testConfig.VRFv2Plus.General.LinkNativeFeedResponse))
mockETHLinkFeed, err := contracts.DeployVRFMockETHLINKFeed(sethClient, big.NewInt(*envConfig.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 := contracts.DeployLinkTokenContract(l, sethClient)
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("%s, err: %w", "error deploying LINK contract", err)
}

vrfContracts, vrfKey, nodeTypeToNode, err := SetupVRFV2_5Environment(
ctx,
env,
chainID,
envConfig.ChainID,
newEnvConfig.NodesToCreate,
&testConfig,
&envConfig.TestConfig,
linkToken,
mockETHLinkFeed,
newEnvConfig.NumberOfTxKeysToCreate,
Expand All @@ -446,23 +427,21 @@ func SetupVRFV2PlusForNewEnv(
return vrfContracts, vrfKey, env, nodeTypeToNode, nil
}

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
func SetupVRFV2PlusForExistingEnv(t *testing.T, envConfig vrfcommon.VRFEnvConfig, l zerolog.Logger) (*vrfcommon.VRFContracts, *vrfcommon.VRFKeyData, *test_env.CLClusterTestEnv, error) {
commonExistingEnvConfig := envConfig.TestConfig.VRFv2Plus.ExistingEnvConfig.ExistingEnvConfig
env, err := test_env.NewCLTestEnvBuilder().
WithTestInstance(t).
WithTestConfig(&testConfig).
WithCustomCleanup(cleanupFn).
WithTestConfig(&envConfig.TestConfig).
WithCustomCleanup(envConfig.CleanupFn).
WithSeth().
Build()
if err != nil {
return nil, nil, nil, fmt.Errorf("%s, err: %w", "error creating test env", err)
}

sethClient, err := env.GetSethClient(chainID)
sethClient, err := env.GetSethClient(envConfig.ChainID)
if err != nil {
return nil, nil, nil, err
}

coordinator, err := contracts.LoadVRFCoordinatorV2_5(sethClient, *commonExistingEnvConfig.CoordinatorAddress)
if err != nil {
return nil, nil, nil, fmt.Errorf("%s, err: %w", "error loading VRFCoordinator2_5", err)
Expand All @@ -471,18 +450,24 @@ func SetupVRFV2PlusForExistingEnv(t *testing.T, testConfig tc.TestConfig, chainI
if err != nil {
return nil, nil, nil, fmt.Errorf("%s, err: %w", "error loading LinkToken", err)
}

err = vrfcommon.FundNodesIfNeeded(testcontext.Get(t), commonExistingEnvConfig, sethClient, l)
if err != nil {
return nil, nil, nil, fmt.Errorf("err: %w", err)
}
blockHashStoreAddress, err := coordinator.GetBlockHashStoreAddress(testcontext.Get(t))
if err != nil {
return nil, nil, nil, fmt.Errorf("err: %w", err)
}
blockHashStore, err := contracts.LoadBlockHashStore(sethClient, blockHashStoreAddress.String())
if err != nil {
return nil, nil, nil, fmt.Errorf("%s, err: %w", "error loading BlockHashStore", err)
}
vrfContracts := &vrfcommon.VRFContracts{
CoordinatorV2Plus: coordinator,
VRFV2PlusConsumer: nil,
LinkToken: linkToken,
BHS: nil,
BHS: blockHashStore,
}

vrfKey := &vrfcommon.VRFKeyData{
VRFKey: nil,
EncodedProvingKey: [2]*big.Int{},
Expand Down
Loading

0 comments on commit 2644bd1

Please sign in to comment.