Skip to content

Commit

Permalink
VRF-598: adjust tests to run VRF V2 Plus load tests against already d…
Browse files Browse the repository at this point in the history
…eployed contracts (#10908)
  • Loading branch information
iljapavlovs authored Oct 12, 2023
1 parent 4c76ff2 commit 78b9a28
Show file tree
Hide file tree
Showing 12 changed files with 412 additions and 193 deletions.
33 changes: 14 additions & 19 deletions .github/workflows/on-demand-vrfv2plus-load-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,22 @@ on:
chainlinkVersion:
description: Container image version for the Chainlink nodes
required: true
default: "2.5.0"
default: "2.6.0-beta0"
testDuration:
description: Duration of the test (time string)
required: false
default: 1m
chainlinkNodeFunding:
description: How much to fund each Chainlink node (in ETH)
required: false
default: ".1"
rps:
description: Requests Per Second
required: false
default: 1
rateLimitDuration:
description: How long to wait between requests
required: false
default: 1m
randomnessRequestCountPerRequest:
description: Randomness request Count per one TX request
required: false
default: 1
useExistingEnv:
description: Whether to deploy a new contracts or use an existing one
required: false
default: false
configBase64:
description: TOML config in base64
required: false
jobs:
vrfv2plus_load_test:
name: ${{ inputs.network }} VRFV2 Plus Load Test
Expand All @@ -72,15 +67,15 @@ jobs:
env:
SELECTED_NETWORKS: ${{ inputs.network }}
VRFV2PLUS_TEST_DURATION: ${{ inputs.testDuration }}
VRFV2PLUS_CHAINLINK_NODE_FUNDING: ${{ inputs.chainlinkNodeFunding }}
VRFV2PLUS_RATE_LIMIT_UNIT_DURATION: ${{ inputs.rateLimitDuration }}
VRFV2PLUS_RPS: ${{ inputs.rps }}
VRFV2PLUS_RATE_LIMIT_UNIT_DURATION: 1m
VRFV2PLUS_RPS: 1
VRFV2PLUS_RANDOMNESS_REQUEST_COUNT_PER_REQUEST: ${{ inputs.randomnessRequestCountPerRequest }}

VRFV2PLUS_USE_EXISTING_ENV: ${{ inputs.useExistingEnv }}
CONFIG: ${{ inputs.configBase64 }}
TEST_LOG_LEVEL: debug
REF_NAME: ${{ github.head_ref || github.ref_name }}
ENV_JOB_IMAGE_BASE: ${{ secrets.QA_AWS_ACCOUNT_NUMBER }}.dkr.ecr.${{ secrets.QA_AWS_REGION }}.amazonaws.com/chainlink-tests

CHAINLINK_IMAGE: ${{ inputs.chainlinkImage }}
CHAINLINK_VERSION: ${{ inputs.chainlinkVersion }}
WASP_LOG_LEVEL: info
steps:
- name: Collect Metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,8 @@ func VRFV2PlusDeployUniverse(e helpers.Environment,
"\nBatch VRF Coordinator Address:", contractAddresses.BatchCoordinatorAddress,
"\nVRF Consumer Address:", consumerAddress,
"\nVRF Subscription Id:", subID,
"\nVRF Subscription Balance:", *subscriptionBalanceJuels,
"\nVRF Subscription LINK Balance:", *subscriptionBalanceJuels,
"\nVRF Subscription Native Balance:", *subscriptionBalanceNativeWei,
"\nPossible VRF Request command: ",
fmt.Sprintf("go run . eoa-load-test-request-with-metrics --consumer-address=%s --sub-id=%d --key-hash=%s --request-confirmations %d --requests 1 --runs 1 --cb-gas-limit 1_000_000", consumerAddress, subID, keyHash, *coordinatorConfig.MinConfs),
"\nRetrieve Request Status: ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,10 @@ type VRFV2PlusConfig struct {
TestDuration time.Duration `envconfig:"TEST_DURATION" default:"3m"` // How long to run the test for
RPS int64 `envconfig:"RPS" default:"1"` // How many requests per second to send
RateLimitUnitDuration time.Duration `envconfig:"RATE_LIMIT_UNIT_DURATION" default:"1m"`
//Using existing environment and contracts
UseExistingEnv bool `envconfig:"USE_EXISTING_ENV" default:"false"` // Whether to use an existing environment or create a new one
CoordinatorAddress string `envconfig:"COORDINATOR_ADDRESS" default:""` // Coordinator address
ConsumerAddress string `envconfig:"CONSUMER_ADDRESS" default:""` // Consumer address
SubID string `envconfig:"SUB_ID" default:""` // Subscription ID
KeyHash string `envconfig:"KEY_HASH" default:""`
}
192 changes: 163 additions & 29 deletions integration-tests/actions/vrfv2plus/vrfv2plus_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package vrfv2plus
import (
"context"
"fmt"
"github.com/smartcontractkit/chainlink/v2/core/assets"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrfv2plus_wrapper_load_test_consumer"
"math/big"
"time"

Expand Down Expand Up @@ -509,9 +511,9 @@ func RequestRandomnessAndWaitForFulfillment(
subID *big.Int,
isNativeBilling bool,
vrfv2PlusConfig vrfv2plus_config.VRFV2PlusConfig,
//todo - should it be here?
l zerolog.Logger,
) (*vrf_coordinator_v2_5.VRFCoordinatorV25RandomWordsFulfilled, error) {
logRandRequest(consumer.Address(), coordinator.Address(), subID, isNativeBilling, vrfv2PlusConfig, l)
_, err := consumer.RequestRandomness(
vrfv2PlusData.KeyHash,
subID,
Expand All @@ -525,7 +527,7 @@ func RequestRandomnessAndWaitForFulfillment(
return nil, errors.Wrap(err, ErrRequestRandomness)
}

return WaitForRequestAndFulfillmentEvents(consumer.Address(), coordinator, vrfv2PlusData, subID, l)
return WaitForRequestAndFulfillmentEvents(consumer.Address(), coordinator, vrfv2PlusData, subID, isNativeBilling, l)
}

func RequestRandomnessAndWaitForFulfillmentUpgraded(
Expand All @@ -537,6 +539,7 @@ func RequestRandomnessAndWaitForFulfillmentUpgraded(
vrfv2PlusConfig vrfv2plus_config.VRFV2PlusConfig,
l zerolog.Logger,
) (*vrf_v2plus_upgraded_version.VRFCoordinatorV2PlusUpgradedVersionRandomWordsFulfilled, error) {
logRandRequest(consumer.Address(), coordinator.Address(), subID, isNativeBilling, vrfv2PlusConfig, l)
_, err := consumer.RequestRandomness(
vrfv2PlusData.KeyHash,
subID,
Expand All @@ -560,15 +563,7 @@ func RequestRandomnessAndWaitForFulfillmentUpgraded(
return nil, errors.Wrap(err, ErrWaitRandomWordsRequestedEvent)
}

l.Debug().
Str("Request ID", randomWordsRequestedEvent.RequestId.String()).
Str("Subscription ID", randomWordsRequestedEvent.SubId.String()).
Str("Sender Address", randomWordsRequestedEvent.Sender.String()).
Interface("Keyhash", randomWordsRequestedEvent.KeyHash).
Uint32("Callback Gas Limit", randomWordsRequestedEvent.CallbackGasLimit).
Uint32("Number of Words", randomWordsRequestedEvent.NumWords).
Uint16("Minimum Request Confirmations", randomWordsRequestedEvent.MinimumRequestConfirmations).
Msg("RandomnessRequested Event")
LogRandomnessRequestedEventUpgraded(l, coordinator, randomWordsRequestedEvent)

randomWordsFulfilledEvent, err := coordinator.WaitForRandomWordsFulfilledEvent(
[]*big.Int{subID},
Expand All @@ -578,14 +573,8 @@ func RequestRandomnessAndWaitForFulfillmentUpgraded(
if err != nil {
return nil, errors.Wrap(err, ErrWaitRandomWordsFulfilledEvent)
}
LogRandomWordsFulfilledEventUpgraded(l, coordinator, randomWordsFulfilledEvent)

l.Debug().
Str("Total Payment in Juels", randomWordsFulfilledEvent.Payment.String()).
Str("TX Hash", randomWordsFulfilledEvent.Raw.TxHash.String()).
Str("Subscription ID", randomWordsFulfilledEvent.SubID.String()).
Str("Request ID", randomWordsFulfilledEvent.RequestId.String()).
Bool("Success", randomWordsFulfilledEvent.Success).
Msg("RandomWordsFulfilled Event (TX metadata)")
return randomWordsFulfilledEvent, err
}

Expand All @@ -598,6 +587,7 @@ func DirectFundingRequestRandomnessAndWaitForFulfillment(
vrfv2PlusConfig vrfv2plus_config.VRFV2PlusConfig,
l zerolog.Logger,
) (*vrf_coordinator_v2_5.VRFCoordinatorV25RandomWordsFulfilled, error) {
logRandRequest(consumer.Address(), coordinator.Address(), subID, isNativeBilling, vrfv2PlusConfig, l)
if isNativeBilling {
_, err := consumer.RequestRandomnessNative(
vrfv2PlusConfig.MinimumConfirmations,
Expand All @@ -623,14 +613,15 @@ func DirectFundingRequestRandomnessAndWaitForFulfillment(
if err != nil {
return nil, errors.Wrap(err, "error getting wrapper address")
}
return WaitForRequestAndFulfillmentEvents(wrapperAddress.String(), coordinator, vrfv2PlusData, subID, l)
return WaitForRequestAndFulfillmentEvents(wrapperAddress.String(), coordinator, vrfv2PlusData, subID, isNativeBilling, l)
}

func WaitForRequestAndFulfillmentEvents(
consumerAddress string,
coordinator contracts.VRFCoordinatorV2_5,
vrfv2PlusData *VRFV2PlusData,
subID *big.Int,
isNativeBilling bool,
l zerolog.Logger,
) (*vrf_coordinator_v2_5.VRFCoordinatorV25RandomWordsFulfilled, error) {
randomWordsRequestedEvent, err := coordinator.WaitForRandomWordsRequestedEvent(
Expand All @@ -643,15 +634,7 @@ func WaitForRequestAndFulfillmentEvents(
return nil, errors.Wrap(err, ErrWaitRandomWordsRequestedEvent)
}

l.Debug().
Str("Request ID", randomWordsRequestedEvent.RequestId.String()).
Str("Subscription ID", randomWordsRequestedEvent.SubId.String()).
Str("Sender Address", randomWordsRequestedEvent.Sender.String()).
Interface("Keyhash", randomWordsRequestedEvent.KeyHash).
Uint32("Callback Gas Limit", randomWordsRequestedEvent.CallbackGasLimit).
Uint32("Number of Words", randomWordsRequestedEvent.NumWords).
Uint16("Minimum Request Confirmations", randomWordsRequestedEvent.MinimumRequestConfirmations).
Msg("RandomnessRequested Event")
LogRandomnessRequestedEvent(l, coordinator, randomWordsRequestedEvent, isNativeBilling)

randomWordsFulfilledEvent, err := coordinator.WaitForRandomWordsFulfilledEvent(
[]*big.Int{subID},
Expand All @@ -662,12 +645,163 @@ func WaitForRequestAndFulfillmentEvents(
return nil, errors.Wrap(err, ErrWaitRandomWordsFulfilledEvent)
}

LogRandomWordsFulfilledEvent(l, coordinator, randomWordsFulfilledEvent, isNativeBilling)
return randomWordsFulfilledEvent, err
}

func LogSubDetails(l zerolog.Logger, subscription vrf_coordinator_v2_5.GetSubscription, subID *big.Int, coordinator contracts.VRFCoordinatorV2_5) {
l.Debug().
Str("Coordinator", coordinator.Address()).
Str("Link Balance", (*assets.Link)(subscription.Balance).Link()).
Str("Native Token Balance", assets.FormatWei(subscription.NativeBalance)).
Str("Subscription ID", subID.String()).
Str("Subscription Owner", subscription.Owner.String()).
Interface("Subscription Consumers", subscription.Consumers).
Msg("Subscription Data")
}

func LogRandomnessRequestedEventUpgraded(
l zerolog.Logger,
coordinator contracts.VRFCoordinatorV2PlusUpgradedVersion,
randomWordsRequestedEvent *vrf_v2plus_upgraded_version.VRFCoordinatorV2PlusUpgradedVersionRandomWordsRequested,
) {
l.Debug().
Str("Coordinator", coordinator.Address()).
Str("Request ID", randomWordsRequestedEvent.RequestId.String()).
Str("Subscription ID", randomWordsRequestedEvent.SubId.String()).
Str("Sender Address", randomWordsRequestedEvent.Sender.String()).
Interface("Keyhash", randomWordsRequestedEvent.KeyHash).
Uint32("Callback Gas Limit", randomWordsRequestedEvent.CallbackGasLimit).
Uint32("Number of Words", randomWordsRequestedEvent.NumWords).
Uint16("Minimum Request Confirmations", randomWordsRequestedEvent.MinimumRequestConfirmations).
Msg("RandomnessRequested Event")
}

func LogRandomWordsFulfilledEventUpgraded(
l zerolog.Logger,
coordinator contracts.VRFCoordinatorV2PlusUpgradedVersion,
randomWordsFulfilledEvent *vrf_v2plus_upgraded_version.VRFCoordinatorV2PlusUpgradedVersionRandomWordsFulfilled,
) {
l.Debug().
Str("Coordinator", coordinator.Address()).
Str("Total Payment in Juels", randomWordsFulfilledEvent.Payment.String()).
Str("TX Hash", randomWordsFulfilledEvent.Raw.TxHash.String()).
Str("Subscription ID", randomWordsFulfilledEvent.SubID.String()).
Str("Request ID", randomWordsFulfilledEvent.RequestId.String()).
Bool("Success", randomWordsFulfilledEvent.Success).
Msg("RandomWordsFulfilled Event (TX metadata)")
}

func LogRandomnessRequestedEvent(
l zerolog.Logger,
coordinator contracts.VRFCoordinatorV2_5,
randomWordsRequestedEvent *vrf_coordinator_v2_5.VRFCoordinatorV25RandomWordsRequested,
isNativeBilling bool,
) {
l.Debug().
Str("Coordinator", coordinator.Address()).
Bool("Native Billing", isNativeBilling).
Str("Request ID", randomWordsRequestedEvent.RequestId.String()).
Str("Subscription ID", randomWordsRequestedEvent.SubId.String()).
Str("Sender Address", randomWordsRequestedEvent.Sender.String()).
Interface("Keyhash", randomWordsRequestedEvent.KeyHash).
Uint32("Callback Gas Limit", randomWordsRequestedEvent.CallbackGasLimit).
Uint32("Number of Words", randomWordsRequestedEvent.NumWords).
Uint16("Minimum Request Confirmations", randomWordsRequestedEvent.MinimumRequestConfirmations).
Msg("RandomnessRequested Event")
}

func LogRandomWordsFulfilledEvent(
l zerolog.Logger,
coordinator contracts.VRFCoordinatorV2_5,
randomWordsFulfilledEvent *vrf_coordinator_v2_5.VRFCoordinatorV25RandomWordsFulfilled,
isNativeBilling bool,
) {
l.Debug().
Bool("Native Billing", isNativeBilling).
Str("Coordinator", coordinator.Address()).
Str("Total Payment", randomWordsFulfilledEvent.Payment.String()).
Str("TX Hash", randomWordsFulfilledEvent.Raw.TxHash.String()).
Str("Subscription ID", randomWordsFulfilledEvent.SubId.String()).
Str("Request ID", randomWordsFulfilledEvent.RequestId.String()).
Bool("Success", randomWordsFulfilledEvent.Success).
Msg("RandomWordsFulfilled Event (TX metadata)")
return randomWordsFulfilledEvent, err
}

func LogMigrationCompletedEvent(l zerolog.Logger, migrationCompletedEvent *vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted, vrfv2PlusContracts *VRFV2_5Contracts) {
l.Debug().
Str("Subscription ID", migrationCompletedEvent.SubId.String()).
Str("Migrated From Coordinator", vrfv2PlusContracts.Coordinator.Address()).
Str("Migrated To Coordinator", migrationCompletedEvent.NewCoordinator.String()).
Msg("MigrationCompleted Event")
}

func LogSubDetailsAfterMigration(l zerolog.Logger, newCoordinator contracts.VRFCoordinatorV2PlusUpgradedVersion, subID *big.Int, migratedSubscription vrf_v2plus_upgraded_version.GetSubscription) {
l.Debug().
Str("New Coordinator", newCoordinator.Address()).
Str("Subscription ID", subID.String()).
Str("Juels Balance", migratedSubscription.Balance.String()).
Str("Native Token Balance", migratedSubscription.NativeBalance.String()).
Str("Subscription Owner", migratedSubscription.Owner.String()).
Interface("Subscription Consumers", migratedSubscription.Consumers).
Msg("Subscription Data After Migration to New Coordinator")
}

func LogFulfillmentDetailsLinkBilling(
l zerolog.Logger,
wrapperConsumerJuelsBalanceBeforeRequest *big.Int,
wrapperConsumerJuelsBalanceAfterRequest *big.Int,
consumerStatus vrfv2plus_wrapper_load_test_consumer.GetRequestStatus,
randomWordsFulfilledEvent *vrf_coordinator_v2_5.VRFCoordinatorV25RandomWordsFulfilled,
) {
l.Debug().
Str("Consumer Balance Before Request (Link)", (*assets.Link)(wrapperConsumerJuelsBalanceBeforeRequest).Link()).
Str("Consumer Balance After Request (Link)", (*assets.Link)(wrapperConsumerJuelsBalanceAfterRequest).Link()).
Bool("Fulfilment Status", consumerStatus.Fulfilled).
Str("Paid by Consumer Contract (Link)", (*assets.Link)(consumerStatus.Paid).Link()).
Str("Paid by Coordinator Sub (Link)", (*assets.Link)(randomWordsFulfilledEvent.Payment).Link()).
Str("RequestTimestamp", consumerStatus.RequestTimestamp.String()).
Str("FulfilmentTimestamp", consumerStatus.FulfilmentTimestamp.String()).
Str("RequestBlockNumber", consumerStatus.RequestBlockNumber.String()).
Str("FulfilmentBlockNumber", consumerStatus.FulfilmentBlockNumber.String()).
Str("TX Hash", randomWordsFulfilledEvent.Raw.TxHash.String()).
Msg("Random Words Fulfilment Details For Link Billing")
}

func LogFulfillmentDetailsNativeBilling(
l zerolog.Logger,
wrapperConsumerBalanceBeforeRequestWei *big.Int,
wrapperConsumerBalanceAfterRequestWei *big.Int,
consumerStatus vrfv2plus_wrapper_load_test_consumer.GetRequestStatus,
randomWordsFulfilledEvent *vrf_coordinator_v2_5.VRFCoordinatorV25RandomWordsFulfilled,
) {
l.Debug().
Str("Consumer Balance Before Request", assets.FormatWei(wrapperConsumerBalanceBeforeRequestWei)).
Str("Consumer Balance After Request", assets.FormatWei(wrapperConsumerBalanceAfterRequestWei)).
Bool("Fulfilment Status", consumerStatus.Fulfilled).
Str("Paid by Consumer Contract", assets.FormatWei(consumerStatus.Paid)).
Str("Paid by Coordinator Sub", assets.FormatWei(randomWordsFulfilledEvent.Payment)).
Str("RequestTimestamp", consumerStatus.RequestTimestamp.String()).
Str("FulfilmentTimestamp", consumerStatus.FulfilmentTimestamp.String()).
Str("RequestBlockNumber", consumerStatus.RequestBlockNumber.String()).
Str("FulfilmentBlockNumber", consumerStatus.FulfilmentBlockNumber.String()).
Str("TX Hash", randomWordsFulfilledEvent.Raw.TxHash.String()).
Msg("Random Words Request Fulfilment Details For Native Billing")
}

func logRandRequest(
consumer string,
coordinator string,
subID *big.Int,
isNativeBilling bool,
vrfv2PlusConfig vrfv2plus_config.VRFV2PlusConfig,
l zerolog.Logger) {
l.Debug().
Str("Consumer", consumer).
Str("Coordinator", coordinator).
Str("subID", subID.String()).
Bool("IsNativePayment", isNativeBilling).
Uint16("MinimumConfirmations", vrfv2PlusConfig.MinimumConfirmations).
Uint16("RandomnessRequestCountPerRequest", vrfv2PlusConfig.RandomnessRequestCountPerRequest).
Msg("Requesting randomness")
}
Loading

0 comments on commit 78b9a28

Please sign in to comment.