Skip to content

Commit

Permalink
VRF-745: fund CL sending keys if needed in WASP test
Browse files Browse the repository at this point in the history
  • Loading branch information
iljapavlovs committed Nov 11, 2023
1 parent f017270 commit 6df74be
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 14 deletions.
4 changes: 3 additions & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/smartcontractkit/ocr2keepers v0.7.28
github.com/smartcontractkit/ocr2vrf v0.0.0-20230804151440-2f1eb1e20687
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1
github.com/smartcontractkit/wasp v0.3.0
github.com/smartcontractkit/wasp v0.3.3
github.com/spf13/cobra v1.6.1
github.com/stretchr/testify v1.8.4
github.com/testcontainers/testcontainers-go v0.23.0
Expand Down Expand Up @@ -84,6 +84,7 @@ require (
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/c2h5oh/datasize v0.0.0-20200112174442-28bbd4740fee // indirect
github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8 // indirect
github.com/cdk8s-team/cdk8s-core-go/cdk8s/v2 v2.7.5 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
Expand Down Expand Up @@ -359,6 +360,7 @@ require (
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/otiai10/copy v1.14.0 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect
Expand Down
6 changes: 6 additions & 0 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,8 @@ github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
github.com/c2h5oh/datasize v0.0.0-20200112174442-28bbd4740fee h1:BnPxIde0gjtTnc9Er7cxvBk8DHLWhEux0SxayC8dP6I=
github.com/c2h5oh/datasize v0.0.0-20200112174442-28bbd4740fee/go.mod h1:S/7n9copUssQ56c7aAgHqftWO4LTf4xY6CGWt8Bc+3M=
github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8 h1:SjZ2GvvOononHOpK84APFuMvxqsk3tEIaKH/z4Rpu3g=
github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8/go.mod h1:uEyr4WpAH4hio6LFriaPkL938XnrvLpNPmQHBdrmbIE=
github.com/cdk8s-team/cdk8s-core-go/cdk8s/v2 v2.7.5 h1:rvc39Ol6z3MvaBzXkxFC6Nfsnixq/dRypushKDd7Nc0=
github.com/cdk8s-team/cdk8s-core-go/cdk8s/v2 v2.7.5/go.mod h1:R/pdNYDYFQk+tuuOo7QES1kkv6OLmp5ze2XBZQIVffM=
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
Expand Down Expand Up @@ -2197,6 +2199,8 @@ github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0Mw
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0=
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
Expand Down Expand Up @@ -2393,6 +2397,8 @@ github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1 h1:D
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1/go.mod h1:G5Sd/yzHWf26rQ+X0nG9E0buKPqRGPMJAfk2gwCzOOw=
github.com/smartcontractkit/wasp v0.3.0 h1:mueeLvpb6HyGNwILxCOKShDR6q18plQn7Gb1j3G/Qkk=
github.com/smartcontractkit/wasp v0.3.0/go.mod h1:skquNdMbKxIrHi5O8Kyukf66AaaXuEpEEaSTxfHbhak=
github.com/smartcontractkit/wasp v0.3.3 h1:intmbdif53nIiK//Vv7MGt2iEcmuQLGBcnFnAho8MRA=
github.com/smartcontractkit/wasp v0.3.3/go.mod h1:FFxNXzgJ+LU5jvyp3hmdNlpYBiivYf3wUTN+dDdFv9g=
github.com/smartcontractkit/wsrpc v0.7.2 h1:iBXzMeg7vc5YoezIQBq896y25BARw7OKbhrb6vPbtRQ=
github.com/smartcontractkit/wsrpc v0.7.2/go.mod h1:sj7QX2NQibhkhxTfs3KOhAj/5xwgqMipTvJVSssT9i0=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
Expand Down
11 changes: 6 additions & 5 deletions integration-tests/load/vrfv2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ type ExistingEnvConfig struct {
LinkAddress string `toml:"link_address"`
SubID uint64 `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 {
Expand All @@ -53,13 +54,13 @@ type Common struct {
}

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 {
SubFundsLink float64 `toml:"sub_funds_link"`
SubFundsNative float64 `toml:"sub_funds_native"`
SubFundsLink float64 `toml:"sub_funds_link"`
}

type Soak struct {
Expand Down
21 changes: 14 additions & 7 deletions integration-tests/load/vrfv2/config.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@

[Common]
minimum_confirmations = 3
minimum_confirmations = 1

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

[ExistingEnvConfig]
coordinator_address = "0x27b61f155F772b291D1d9B478BeAd37B2Ae447b0"
coordinator_address = "0x50d47e4142598E3411aA864e08a44284e471AC6f"
#consumer_address = "0x087F232165D9bA1A602f148025e5D0666953F64a"
#sub_id = "52116875585187328970776211988181422347535732407068188096422095950800466618218"
key_hash = "0x787d74caea10b2b357790d5b5247c2f63d1d91572a9846f780606e4d953677ae"
key_hash = "0x027f94ff1465b3525f9fc03e9ff7d6d2c0953482246dd6ae07570c45d6631414"
create_fund_subs_and_add_consumers = true
link_address = "0x779877A7B0D9E8603169DdbD7836e478b4624789"
link_address = "0xb1D4538B4571d411F07960EF2838Ce337FE1E80E"
sub_funds_link = 3
sub_funds_native = 1
node_sending_key_funding_min = 2
node_sending_keys = [
"0x3d659dE506d3b22e7660d579327126221EfB2651",
"0x7cAF21fA7423b3f4Ec15f87C7BBa83aE8cA4bDf3",
"0x8E1aDA97ac6883E8D7738E2dB9cC1A32211d3429",
"0xA4fdfE2c9438fd8388C2837c0AB199946f8041D3",
"0xb4CC2d6f933244Ff596dd1A7aB6E96769d237B3b",
"0xded252Eb0caA71aFABab6a0fd948eA9CaAdf7012",
]

# 10 RPM - 1 tx request with 1 rand request in each tx every 6 seconds
[Soak]
Expand Down
49 changes: 48 additions & 1 deletion integration-tests/load/vrfv2/vrfv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package loadvrfv2

import (
"context"
"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/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink-testing-framework/utils"
"github.com/smartcontractkit/chainlink/integration-tests/actions"
"github.com/smartcontractkit/chainlink/integration-tests/actions/vrfv2/vrfv2_config"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
Expand Down Expand Up @@ -141,6 +145,9 @@ func TestVRFV2Performance(t *testing.T) {
subIDs = append(subIDs, vrfv2Config.SubID)
}

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

vrfv2Contracts = &vrfv2.VRFV2Contracts{
Coordinator: coordinator,
LoadTestConsumers: consumers,
Expand All @@ -160,7 +167,7 @@ func TestVRFV2Performance(t *testing.T) {

} else {
//todo: temporary solution with envconfig and toml config until VRF-662 is implemented
vrfv2Config.ChainlinkNodeFunding = cfg.NewEnvConfig.NodeFunds
vrfv2Config.ChainlinkNodeFunding = cfg.NewEnvConfig.NodeSendingKeyFunding
vrfv2Config.SubscriptionFundingAmountLink = cfg.NewEnvConfig.Funding.SubFundsLink
env, err = test_env.NewCLTestEnvBuilder().
WithTestLogger(t).
Expand Down Expand Up @@ -277,6 +284,46 @@ func TestVRFV2Performance(t *testing.T) {

}

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 := utils.EtherToWei(big.NewFloat(cfg.ExistingEnvConfig.NodeSendingKeyFundingMin))
fundingToSendWei := new(big.Int).Sub(fundingAtLeast, sendingKeyBalance)
fundingToSendEth := utils.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(
t *testing.T,
consumer contracts.VRFv2LoadTestConsumer,
Expand Down

0 comments on commit 6df74be

Please sign in to comment.