Skip to content

Commit

Permalink
VRF-765: make optional to cancel subs after test run for VRF WASP tes…
Browse files Browse the repository at this point in the history
…ts (#11379)
  • Loading branch information
iljapavlovs authored Nov 24, 2023
1 parent 853a617 commit ec7c8c9
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 84 deletions.
3 changes: 2 additions & 1 deletion integration-tests/load/vrfv2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ type NewEnvConfig struct {
}

type Common struct {
MinimumConfirmations uint16 `toml:"minimum_confirmations"`
MinimumConfirmations uint16 `toml:"minimum_confirmations"`
CancelSubsAfterTestRun bool `toml:"cancel_subs_after_test_run"`
}

type Funding struct {
Expand Down
19 changes: 10 additions & 9 deletions integration-tests/load/vrfv2/config.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@

[Common]
minimum_confirmations = 3
cancel_subs_after_test_run = true

[NewEnvConfig]
sub_funds_link = 1
node_sending_key_funding = 10
sub_funds_link = 1000
node_sending_key_funding = 1000

[ExistingEnvConfig]
coordinator_address = "0x50d47e4142598E3411aA864e08a44284e471AC6f"
#consumer_address = "0x087F232165D9bA1A602f148025e5D0666953F64a"
#sub_id = "52116875585187328970776211988181422347535732407068188096422095950800466618218"
key_hash = "0x027f94ff1465b3525f9fc03e9ff7d6d2c0953482246dd6ae07570c45d6631414"
coordinator_address = ""
consumer_address = ""
sub_id = 1
key_hash = ""
create_fund_subs_and_add_consumers = true
link_address = "0xb1D4538B4571d411F07960EF2838Ce337FE1E80E"
sub_funds_link = 3
node_sending_key_funding_min = 2
link_address = ""
sub_funds_link = 10
node_sending_key_funding_min = 1
node_sending_keys = [
"",
"",
Expand Down
57 changes: 27 additions & 30 deletions integration-tests/load/vrfv2/vrfv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,9 @@ func TestVRFV2Performance(t *testing.T) {
Str("Network Name", env.EVMClient.GetNetworkName()).
Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.")
} else {
//cancel subs and return funds to sub owner
for _, subID := range subIDs {
l.Info().
Uint64("Returning funds from SubID", subID).
Str("Returning funds to", eoaWalletAddress).
Msg("Canceling subscription and returning funds to subscription owner")
pendingRequestsExist, err := vrfv2Contracts.Coordinator.PendingRequestsExist(context.Background(), subID)
if err != nil {
l.Error().Err(err).Msg("Error checking if pending requests exist")
}
if !pendingRequestsExist {
_, err := vrfv2Contracts.Coordinator.CancelSubscription(subID, common.HexToAddress(eoaWalletAddress))
if err != nil {
l.Error().Err(err).Msg("Error canceling subscription")
}
} else {
l.Error().Uint64("Sub ID", subID).Msg("Pending requests exist for subscription, cannot cancel subscription and return funds")
}

if cfg.Common.CancelSubsAfterTestRun {
//cancel subs and return funds to sub owner
cancelSubsAndReturnFunds(subIDs, l)
}
}
}).
Expand Down Expand Up @@ -186,18 +170,10 @@ func TestVRFV2Performance(t *testing.T) {
Str("Network Name", env.EVMClient.GetNetworkName()).
Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.")
} else {
for _, subID := range subIDs {
l.Info().
Uint64("Returning funds from SubID", subID).
Str("Returning funds to", eoaWalletAddress).
Msg("Canceling subscription and returning funds to subscription owner")
_, err := vrfv2Contracts.Coordinator.CancelSubscription(subID, common.HexToAddress(eoaWalletAddress))
if err != nil {
l.Error().Err(err).Msg("Error canceling subscription")
}
if cfg.Common.CancelSubsAfterTestRun {
//cancel subs and return funds to sub owner
cancelSubsAndReturnFunds(subIDs, l)
}
//err = vrfv2.ReturnFundsForFulfilledRequests(env.EVMClient, vrfv2Contracts.Coordinator, l)
//l.Error().Err(err).Msg("Error returning funds for fulfilled requests")
}
if err := env.Cleanup(); err != nil {
l.Error().Err(err).Msg("Error cleaning up test environment")
Expand Down Expand Up @@ -287,6 +263,27 @@ func TestVRFV2Performance(t *testing.T) {

}

func cancelSubsAndReturnFunds(subIDs []uint64, l zerolog.Logger) {
for _, subID := range subIDs {
l.Info().
Uint64("Returning funds from SubID", subID).
Str("Returning funds to", eoaWalletAddress).
Msg("Canceling subscription and returning funds to subscription owner")
pendingRequestsExist, err := vrfv2Contracts.Coordinator.PendingRequestsExist(context.Background(), subID)
if err != nil {
l.Error().Err(err).Msg("Error checking if pending requests exist")
}
if !pendingRequestsExist {
_, err := vrfv2Contracts.Coordinator.CancelSubscription(subID, common.HexToAddress(eoaWalletAddress))
if err != nil {
l.Error().Err(err).Msg("Error canceling subscription")
}
} else {
l.Error().Uint64("Sub ID", subID).Msg("Pending requests exist for subscription, cannot cancel subscription and return funds")
}
}
}

func FundNodesIfNeeded(cfg *PerformanceConfig, client blockchain.EVMClient, l zerolog.Logger) error {
if cfg.ExistingEnvConfig.NodeSendingKeyFundingMin > 0 {
for _, sendingKey := range cfg.ExistingEnvConfig.NodeSendingKeys {
Expand Down
11 changes: 7 additions & 4 deletions integration-tests/load/vrfv2plus/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,24 @@ type ExistingEnvConfig struct {
LinkAddress string `toml:"link_address"`
SubID string `toml:"sub_id"`
KeyHash string `toml:"key_hash"`
SubFunding
CreateFundSubsAndAddConsumers bool `toml:"create_fund_subs_and_add_consumers"`
Funding
CreateFundSubsAndAddConsumers bool `toml:"create_fund_subs_and_add_consumers"`
NodeSendingKeys []string `toml:"node_sending_keys"`
}

type NewEnvConfig struct {
Funding
}

type Common struct {
MinimumConfirmations uint16 `toml:"minimum_confirmations"`
MinimumConfirmations uint16 `toml:"minimum_confirmations"`
CancelSubsAfterTestRun bool `toml:"cancel_subs_after_test_run"`
}

type Funding struct {
NodeFunds float64 `toml:"node_funds"`
SubFunding
NodeSendingKeyFunding float64 `toml:"node_sending_key_funding"`
NodeSendingKeyFundingMin float64 `toml:"node_sending_key_funding_min"`
}

type SubFunding struct {
Expand Down
28 changes: 19 additions & 9 deletions integration-tests/load/vrfv2plus/config.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@

[Common]
minimum_confirmations = 3
cancel_subs_after_test_run = true

[NewEnvConfig]
sub_funds_link = 1
sub_funds_native = 1
node_funds = 10
node_sending_key_funding = 1000

[ExistingEnvConfig]
coordinator_address = "0x27b61f155F772b291D1d9B478BeAd37B2Ae447b0"
#consumer_address = "0x087F232165D9bA1A602f148025e5D0666953F64a"
#sub_id = "52116875585187328970776211988181422347535732407068188096422095950800466618218"
key_hash = "0x787d74caea10b2b357790d5b5247c2f63d1d91572a9846f780606e4d953677ae"
coordinator_address = ""
consumer_address = ""
sub_id = 1
key_hash = ""
create_fund_subs_and_add_consumers = true
link_address = "0x779877A7B0D9E8603169DdbD7836e478b4624789"
sub_funds_link = 3
sub_funds_native = 1
link_address = ""
sub_funds_link = 10
node_sending_key_funding_min = 1
node_sending_keys = [
"",
"",
"",
"",
"",
"",
]

# 10 RPM - 1 tx request with 1 rand request in each tx every 6 seconds
[Soak]
Expand All @@ -25,7 +35,7 @@ randomness_request_count_per_request = 1 # amount of randomness requests to make
randomness_request_count_per_request_deviation = 0 #NOTE - deviation should be less than randomness_request_count_per_request setting
number_of_sub_to_create = 1

# approx 60 RPM - 1 tx request with 4 rand requests in each tx every 3 seconds
# approx 60 RPM - 1 tx request with 3 rand requests in each tx every 3 seconds
[Load]
rate_limit_unit_duration = "3s"
rps = 1
Expand All @@ -47,4 +57,4 @@ rate_limit_unit_duration = "1m"
rps = 1
randomness_request_count_per_request = 150 # amount of randomness requests to make per one TX request
randomness_request_count_per_request_deviation = 0 #NOTE - deviation should be less than randomness_request_count_per_request setting
number_of_sub_to_create = 1
number_of_sub_to_create = 1
108 changes: 77 additions & 31 deletions integration-tests/load/vrfv2plus/vrfv2plus_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package loadvrfv2plus

import (
"context"
"math/big"
"os"
"sync"
"testing"
"time"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/kelseyhightower/envconfig"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/smartcontractkit/wasp"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink-testing-framework/utils/conversions"
"github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext"
"github.com/smartcontractkit/chainlink/integration-tests/testreporters"

Expand Down Expand Up @@ -93,25 +98,9 @@ func TestVRFV2PlusPerformance(t *testing.T) {
Str("Network Name", env.EVMClient.GetNetworkName()).
Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.")
} else {
//cancel subs and return funds to sub owner
for _, subID := range subIDs {
l.Info().
Str("Returning funds from SubID", subID.String()).
Str("Returning funds to", eoaWalletAddress).
Msg("Canceling subscription and returning funds to subscription owner")
pendingRequestsExist, err := vrfv2PlusContracts.Coordinator.PendingRequestsExist(testcontext.Get(t), subID)
if err != nil {
l.Error().Err(err).Msg("Error checking if pending requests exist")
}
if !pendingRequestsExist {
_, err := vrfv2PlusContracts.Coordinator.CancelSubscription(subID, common.HexToAddress(eoaWalletAddress))
if err != nil {
l.Error().Err(err).Msg("Error canceling subscription")
}
} else {
l.Error().Str("Sub ID", subID.String()).Msg("Pending requests exist for subscription, cannot cancel subscription and return funds")
}

if cfg.Common.CancelSubsAfterTestRun {
//cancel subs and return funds to sub owner
cancelSubsAndReturnFunds(subIDs, l)
}
}
}).
Expand Down Expand Up @@ -147,6 +136,9 @@ func TestVRFV2PlusPerformance(t *testing.T) {
subIDs = append(subIDs, subID)
}

err = FundNodesIfNeeded(cfg, env.EVMClient, l)
require.NoError(t, err)

vrfv2PlusContracts = &vrfv2plus.VRFV2_5Contracts{
Coordinator: coordinator,
LoadTestConsumers: consumers,
Expand All @@ -166,7 +158,7 @@ func TestVRFV2PlusPerformance(t *testing.T) {

} else {
//todo: temporary solution with envconfig and toml config until VRF-662 is implemented
vrfv2PlusConfig.ChainlinkNodeFunding = cfg.NewEnvConfig.NodeFunds
vrfv2PlusConfig.ChainlinkNodeFunding = cfg.NewEnvConfig.NodeSendingKeyFunding
vrfv2PlusConfig.SubscriptionFundingAmountLink = cfg.NewEnvConfig.Funding.SubFundsLink
vrfv2PlusConfig.SubscriptionFundingAmountNative = cfg.NewEnvConfig.Funding.SubFundsNative
env, err = test_env.NewCLTestEnvBuilder().
Expand All @@ -183,18 +175,10 @@ func TestVRFV2PlusPerformance(t *testing.T) {
Str("Network Name", env.EVMClient.GetNetworkName()).
Msg("Network is a simulated network. Skipping fund return for Coordinator Subscriptions.")
} else {
for _, subID := range subIDs {
l.Info().
Str("Returning funds from SubID", subID.String()).
Str("Returning funds to", eoaWalletAddress).
Msg("Canceling subscription and returning funds to subscription owner")
_, err := vrfv2PlusContracts.Coordinator.CancelSubscription(subID, common.HexToAddress(eoaWalletAddress))
if err != nil {
l.Error().Err(err).Msg("Error canceling subscription")
}
if cfg.Common.CancelSubsAfterTestRun {
//cancel subs and return funds to sub owner
cancelSubsAndReturnFunds(subIDs, l)
}
//err = vrfv2plus.ReturnFundsForFulfilledRequests(env.EVMClient, vrfv2PlusContracts.Coordinator, l)
//l.Error().Err(err).Msg("Error returning funds for fulfilled requests")
}
if err := env.Cleanup(); err != nil {
l.Error().Err(err).Msg("Error cleaning up test environment")
Expand Down Expand Up @@ -281,6 +265,68 @@ func TestVRFV2PlusPerformance(t *testing.T) {
Interface("Fulfilment Count", fulfilmentCount).
Msg("Final Request/Fulfilment Stats")
})

}

func cancelSubsAndReturnFunds(subIDs []*big.Int, l zerolog.Logger) {
for _, subID := range subIDs {
l.Info().
Str("Returning funds from SubID", subID.String()).
Str("Returning funds to", eoaWalletAddress).
Msg("Canceling subscription and returning funds to subscription owner")
pendingRequestsExist, err := vrfv2PlusContracts.Coordinator.PendingRequestsExist(context.Background(), subID)
if err != nil {
l.Error().Err(err).Msg("Error checking if pending requests exist")
}
if !pendingRequestsExist {
_, err := vrfv2PlusContracts.Coordinator.CancelSubscription(subID, common.HexToAddress(eoaWalletAddress))
if err != nil {
l.Error().Err(err).Msg("Error canceling subscription")
}
} else {
l.Error().Str("Sub ID", subID.String()).Msg("Pending requests exist for subscription, cannot cancel subscription and return funds")
}
}
}

func FundNodesIfNeeded(cfg *PerformanceConfig, client blockchain.EVMClient, l zerolog.Logger) error {
if cfg.ExistingEnvConfig.NodeSendingKeyFundingMin > 0 {
for _, sendingKey := range cfg.ExistingEnvConfig.NodeSendingKeys {
address := common.HexToAddress(sendingKey)
sendingKeyBalance, err := client.BalanceAt(context.Background(), address)
if err != nil {
return err
}
fundingAtLeast := conversions.EtherToWei(big.NewFloat(cfg.ExistingEnvConfig.NodeSendingKeyFundingMin))
fundingToSendWei := new(big.Int).Sub(fundingAtLeast, sendingKeyBalance)
fundingToSendEth := conversions.WeiToEther(fundingToSendWei)
if fundingToSendWei.Cmp(big.NewInt(0)) == 1 {
l.Info().
Str("Sending Key", sendingKey).
Str("Sending Key Current Balance", sendingKeyBalance.String()).
Str("Should have at least", fundingAtLeast.String()).
Str("Funding Amount in ETH", fundingToSendEth.String()).
Msg("Funding Node's Sending Key")
gasEstimates, err := client.EstimateGas(ethereum.CallMsg{
To: &address,
})
if err != nil {
return err
}
err = client.Fund(sendingKey, fundingToSendEth, gasEstimates)
if err != nil {
return err
}
} else {
l.Info().
Str("Sending Key", sendingKey).
Str("Sending Key Current Balance", sendingKeyBalance.String()).
Str("Should have at least", fundingAtLeast.String()).
Msg("Skipping Node's Sending Key funding as it has enough funds")
}
}
}
return nil
}

func teardown(
Expand Down

0 comments on commit ec7c8c9

Please sign in to comment.