From e499700c67cd352b0456f33f4e917766da1cd15a Mon Sep 17 00:00:00 2001 From: Ilja Pavlovs Date: Tue, 10 Oct 2023 13:12:22 +0300 Subject: [PATCH 1/9] VRF-586: add env setup script for VRF V2 Plus (#10892) * VRF-586: add env setup script for VRF V2 Plus * VRF-586: deleting debug logs --- .../scripts/common/vrf/constants/constants.go | 34 ++ .../docker/db/create-multiple-databases.sh | 0 .../vrf}/docker/docker-compose.yml | 4 +- .../testnet => common/vrf}/docker/sample.env | 0 .../vrf}/docker/secrets/apicredentials | 0 .../vrf}/docker/secrets/password.txt | 0 .../vrf}/docker/toml-config/base.toml | 0 .../vrf}/docker/toml-config/bhf.toml | 0 .../vrf}/docker/toml-config/bhs.toml | 0 .../vrf}/docker/toml-config/rpc-nodes.toml | 0 .../vrf}/docker/toml-config/secrets.toml | 0 .../toml-config/vrf-backup-other-chains.toml | 2 +- .../vrf}/docker/toml-config/vrf-backup.toml | 0 .../vrf}/docker/toml-config/vrf-primary.toml | 2 +- .../wait-for-others/docker-wait-for-it.sh | 0 .../wait-for-others/docker-wait-for-others.sh | 0 .../testnet => common/vrf}/jobs/jobs.go | 42 +- core/scripts/common/vrf/model/model.go | 46 ++ .../vrf}/setup-envs/README.md | 22 +- .../testnet => common/vrf}/setup-envs/main.go | 187 +++++--- core/scripts/common/vrf/util/util.go | 22 + .../vrfv2/testnet/constants/constants.go | 28 -- core/scripts/vrfv2/testnet/main.go | 38 +- .../{scripts => v2scripts}/super_scripts.go | 121 ++--- .../testnet/{scripts => v2scripts}/util.go | 4 +- core/scripts/vrfv2plus/testnet/main.go | 45 +- .../{ => v2plusscripts}/super_scripts.go | 432 +++++++++++------- .../testnet/{ => v2plusscripts}/util.go | 66 ++- 28 files changed, 665 insertions(+), 430 deletions(-) create mode 100644 core/scripts/common/vrf/constants/constants.go rename core/scripts/{vrfv2/testnet => common/vrf}/docker/db/create-multiple-databases.sh (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/docker-compose.yml (98%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/sample.env (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/secrets/apicredentials (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/secrets/password.txt (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/toml-config/base.toml (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/toml-config/bhf.toml (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/toml-config/bhs.toml (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/toml-config/rpc-nodes.toml (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/toml-config/secrets.toml (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/toml-config/vrf-backup-other-chains.toml (81%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/toml-config/vrf-backup.toml (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/toml-config/vrf-primary.toml (76%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/wait-for-others/docker-wait-for-it.sh (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/docker/wait-for-others/docker-wait-for-others.sh (100%) rename core/scripts/{vrfv2/testnet => common/vrf}/jobs/jobs.go (55%) create mode 100644 core/scripts/common/vrf/model/model.go rename core/scripts/{vrfv2/testnet => common/vrf}/setup-envs/README.md (72%) rename core/scripts/{vrfv2/testnet => common/vrf}/setup-envs/main.go (72%) create mode 100644 core/scripts/common/vrf/util/util.go delete mode 100644 core/scripts/vrfv2/testnet/constants/constants.go rename core/scripts/vrfv2/testnet/{scripts => v2scripts}/super_scripts.go (83%) rename core/scripts/vrfv2/testnet/{scripts => v2scripts}/util.go (99%) rename core/scripts/vrfv2plus/testnet/{ => v2plusscripts}/super_scripts.go (61%) rename core/scripts/vrfv2plus/testnet/{ => v2plusscripts}/util.go (79%) diff --git a/core/scripts/common/vrf/constants/constants.go b/core/scripts/common/vrf/constants/constants.go new file mode 100644 index 00000000000..b21f6b0b323 --- /dev/null +++ b/core/scripts/common/vrf/constants/constants.go @@ -0,0 +1,34 @@ +package constants + +import ( + "math/big" +) + +var ( + SubscriptionBalanceJuels = "1e19" + SubscriptionBalanceNativeWei = "1e18" + + // optional flags + FallbackWeiPerUnitLink = big.NewInt(6e16) + BatchFulfillmentEnabled = true + MinConfs = 3 + NodeSendingKeyFundingAmount = "1e17" + MaxGasLimit = int64(2.5e6) + StalenessSeconds = int64(86400) + GasAfterPayment = int64(33285) + + //vrfv2 + FlatFeeTier1 = int64(500) + FlatFeeTier2 = int64(500) + FlatFeeTier3 = int64(500) + FlatFeeTier4 = int64(500) + FlatFeeTier5 = int64(500) + ReqsForTier2 = int64(0) + ReqsForTier3 = int64(0) + ReqsForTier4 = int64(0) + ReqsForTier5 = int64(0) + + //vrfv2plus + FlatFeeLinkPPM = int64(500) + FlatFeeNativePPM = int64(500) +) diff --git a/core/scripts/vrfv2/testnet/docker/db/create-multiple-databases.sh b/core/scripts/common/vrf/docker/db/create-multiple-databases.sh similarity index 100% rename from core/scripts/vrfv2/testnet/docker/db/create-multiple-databases.sh rename to core/scripts/common/vrf/docker/db/create-multiple-databases.sh diff --git a/core/scripts/vrfv2/testnet/docker/docker-compose.yml b/core/scripts/common/vrf/docker/docker-compose.yml similarity index 98% rename from core/scripts/vrfv2/testnet/docker/docker-compose.yml rename to core/scripts/common/vrf/docker/docker-compose.yml index d31c50f3463..5c14c4670d8 100644 --- a/core/scripts/vrfv2/testnet/docker/docker-compose.yml +++ b/core/scripts/common/vrf/docker/docker-compose.yml @@ -132,9 +132,9 @@ services: secrets: node_password: - file: ./secrets/password.txt + file: secrets/password.txt apicredentials: - file: ./secrets/apicredentials + file: secrets/apicredentials volumes: docker-compose-db: diff --git a/core/scripts/vrfv2/testnet/docker/sample.env b/core/scripts/common/vrf/docker/sample.env similarity index 100% rename from core/scripts/vrfv2/testnet/docker/sample.env rename to core/scripts/common/vrf/docker/sample.env diff --git a/core/scripts/vrfv2/testnet/docker/secrets/apicredentials b/core/scripts/common/vrf/docker/secrets/apicredentials similarity index 100% rename from core/scripts/vrfv2/testnet/docker/secrets/apicredentials rename to core/scripts/common/vrf/docker/secrets/apicredentials diff --git a/core/scripts/vrfv2/testnet/docker/secrets/password.txt b/core/scripts/common/vrf/docker/secrets/password.txt similarity index 100% rename from core/scripts/vrfv2/testnet/docker/secrets/password.txt rename to core/scripts/common/vrf/docker/secrets/password.txt diff --git a/core/scripts/vrfv2/testnet/docker/toml-config/base.toml b/core/scripts/common/vrf/docker/toml-config/base.toml similarity index 100% rename from core/scripts/vrfv2/testnet/docker/toml-config/base.toml rename to core/scripts/common/vrf/docker/toml-config/base.toml diff --git a/core/scripts/vrfv2/testnet/docker/toml-config/bhf.toml b/core/scripts/common/vrf/docker/toml-config/bhf.toml similarity index 100% rename from core/scripts/vrfv2/testnet/docker/toml-config/bhf.toml rename to core/scripts/common/vrf/docker/toml-config/bhf.toml diff --git a/core/scripts/vrfv2/testnet/docker/toml-config/bhs.toml b/core/scripts/common/vrf/docker/toml-config/bhs.toml similarity index 100% rename from core/scripts/vrfv2/testnet/docker/toml-config/bhs.toml rename to core/scripts/common/vrf/docker/toml-config/bhs.toml diff --git a/core/scripts/vrfv2/testnet/docker/toml-config/rpc-nodes.toml b/core/scripts/common/vrf/docker/toml-config/rpc-nodes.toml similarity index 100% rename from core/scripts/vrfv2/testnet/docker/toml-config/rpc-nodes.toml rename to core/scripts/common/vrf/docker/toml-config/rpc-nodes.toml diff --git a/core/scripts/vrfv2/testnet/docker/toml-config/secrets.toml b/core/scripts/common/vrf/docker/toml-config/secrets.toml similarity index 100% rename from core/scripts/vrfv2/testnet/docker/toml-config/secrets.toml rename to core/scripts/common/vrf/docker/toml-config/secrets.toml diff --git a/core/scripts/vrfv2/testnet/docker/toml-config/vrf-backup-other-chains.toml b/core/scripts/common/vrf/docker/toml-config/vrf-backup-other-chains.toml similarity index 81% rename from core/scripts/vrfv2/testnet/docker/toml-config/vrf-backup-other-chains.toml rename to core/scripts/common/vrf/docker/toml-config/vrf-backup-other-chains.toml index a39c6b15c57..ba71abe92fc 100644 --- a/core/scripts/vrfv2/testnet/docker/toml-config/vrf-backup-other-chains.toml +++ b/core/scripts/common/vrf/docker/toml-config/vrf-backup-other-chains.toml @@ -1,5 +1,5 @@ [Feature] -LogPoller = false #VRF V2 uses Log Broadcast3er instead of Log poller +LogPoller = false #VRF V2 uses Log Broadcaster instead of Log poller [[EVM]] ChainID = '11155111' diff --git a/core/scripts/vrfv2/testnet/docker/toml-config/vrf-backup.toml b/core/scripts/common/vrf/docker/toml-config/vrf-backup.toml similarity index 100% rename from core/scripts/vrfv2/testnet/docker/toml-config/vrf-backup.toml rename to core/scripts/common/vrf/docker/toml-config/vrf-backup.toml diff --git a/core/scripts/vrfv2/testnet/docker/toml-config/vrf-primary.toml b/core/scripts/common/vrf/docker/toml-config/vrf-primary.toml similarity index 76% rename from core/scripts/vrfv2/testnet/docker/toml-config/vrf-primary.toml rename to core/scripts/common/vrf/docker/toml-config/vrf-primary.toml index 67cd33659fb..6cb78789b23 100644 --- a/core/scripts/vrfv2/testnet/docker/toml-config/vrf-primary.toml +++ b/core/scripts/common/vrf/docker/toml-config/vrf-primary.toml @@ -1,5 +1,5 @@ [Feature] -LogPoller = false #VRF V2 uses Log Broadcast3er instead of Log poller +LogPoller = false #VRF V2 uses Log Broadcaster instead of Log poller [[EVM]] ChainID = '11155111' diff --git a/core/scripts/vrfv2/testnet/docker/wait-for-others/docker-wait-for-it.sh b/core/scripts/common/vrf/docker/wait-for-others/docker-wait-for-it.sh similarity index 100% rename from core/scripts/vrfv2/testnet/docker/wait-for-others/docker-wait-for-it.sh rename to core/scripts/common/vrf/docker/wait-for-others/docker-wait-for-it.sh diff --git a/core/scripts/vrfv2/testnet/docker/wait-for-others/docker-wait-for-others.sh b/core/scripts/common/vrf/docker/wait-for-others/docker-wait-for-others.sh similarity index 100% rename from core/scripts/vrfv2/testnet/docker/wait-for-others/docker-wait-for-others.sh rename to core/scripts/common/vrf/docker/wait-for-others/docker-wait-for-others.sh diff --git a/core/scripts/vrfv2/testnet/jobs/jobs.go b/core/scripts/common/vrf/jobs/jobs.go similarity index 55% rename from core/scripts/vrfv2/testnet/jobs/jobs.go rename to core/scripts/common/vrf/jobs/jobs.go index 8ff0195bfa8..674cca175c8 100644 --- a/core/scripts/vrfv2/testnet/jobs/jobs.go +++ b/core/scripts/common/vrf/jobs/jobs.go @@ -1,7 +1,7 @@ package jobs var ( - VRFJobFormatted = `type = "vrf" + VRFV2JobFormatted = `type = "vrf" name = "vrf_v2" schemaVersion = 1 coordinatorAddress = "%s" @@ -38,6 +38,46 @@ simulate [type=ethcall decode_log->vrf->estimate_gas->simulate """` + VRFV2PlusJobFormatted = ` +type = "vrf" +name = "vrf_v2_plus" +schemaVersion = 1 +coordinatorAddress = "%s" +batchCoordinatorAddress = "%s" +batchFulfillmentEnabled = %t +batchFulfillmentGasMultiplier = 1.1 +publicKey = "%s" +minIncomingConfirmations = %d +evmChainID = "%d" +fromAddresses = ["%s"] +pollPeriod = "300ms" +requestTimeout = "30m0s" +observationSource = """ +decode_log [type=ethabidecodelog + abi="RandomWordsRequested(bytes32 indexed keyHash,uint256 requestId,uint256 preSeed,uint256 indexed subId,uint16 minimumRequestConfirmations,uint32 callbackGasLimit,uint32 numWords,bytes extraArgs,address indexed sender)" + data="$(jobRun.logData)" + topics="$(jobRun.logTopics)"] +generate_proof [type=vrfv2plus + publicKey="$(jobSpec.publicKey)" + requestBlockHash="$(jobRun.logBlockHash)" + requestBlockNumber="$(jobRun.logBlockNumber)" + topics="$(jobRun.logTopics)"] +estimate_gas [type=estimategaslimit + to="%s" + multiplier="1.1" + data="$(generate_proof.output)"] +simulate_fulfillment [type=ethcall + from="%s" + to="%s" + gas="$(estimate_gas)" + gasPrice="$(jobSpec.maxGasPrice)" + extractRevertReason=true + contract="%s" + data="$(generate_proof.output)"] +decode_log->generate_proof->estimate_gas->simulate_fulfillment +""" +` + BHSJobFormatted = `type = "blockhashstore" schemaVersion = 1 name = "blockhashstore" diff --git a/core/scripts/common/vrf/model/model.go b/core/scripts/common/vrf/model/model.go new file mode 100644 index 00000000000..bd0e3bbe364 --- /dev/null +++ b/core/scripts/common/vrf/model/model.go @@ -0,0 +1,46 @@ +package model + +import ( + "github.com/ethereum/go-ethereum/common" + "math/big" +) + +var ( + VRFPrimaryNodeName = "vrf-primary-node" + VRFBackupNodeName = "vrf-backup-node" + BHSNodeName = "bhs-node" + BHSBackupNodeName = "bhs-backup-node" + BHFNodeName = "bhf-node" +) + +type Node struct { + URL string + CredsFile string + SendingKeys []SendingKey + NumberOfSendingKeysToCreate int + SendingKeyFundingAmount *big.Int + VrfKeys []string + jobSpec string +} + +type SendingKey struct { + Address string + BalanceEth *big.Int +} + +type JobSpecs struct { + VRFPrimaryNode string + VRFBackupyNode string + BHSNode string + BHSBackupNode string + BHFNode string +} + +type ContractAddresses struct { + LinkAddress string + LinkEthAddress string + BhsContractAddress common.Address + BatchBHSAddress common.Address + CoordinatorAddress common.Address + BatchCoordinatorAddress common.Address +} diff --git a/core/scripts/vrfv2/testnet/setup-envs/README.md b/core/scripts/common/vrf/setup-envs/README.md similarity index 72% rename from core/scripts/vrfv2/testnet/setup-envs/README.md rename to core/scripts/common/vrf/setup-envs/README.md index a36e3829c43..33515338a24 100644 --- a/core/scripts/vrfv2/testnet/setup-envs/README.md +++ b/core/scripts/common/vrf/setup-envs/README.md @@ -4,8 +4,8 @@ * Currently possible to fund all nodes with one amount of native tokens ## Commands: 1. If using Docker Compose - 1. create `.env` file in `core/scripts/vrfv2/testnet/docker` (can use `sample.env` file as an example) - 2. go to `core/scripts/vrfv2/testnet/docker` folder and start containers - `docker compose up` + 1. create `.env` file in `core/scripts/common/vrf/docker` (can use `sample.env` file as an example) + 2. go to `core/scripts/common/vrf/docker` folder and start containers - `docker compose up` 2. Update [rpc-nodes.toml](..%2Fdocker%2Ftoml-config%2Frpc-nodes.toml) with relevant RPC nodes 3. Create files with credentials desirably outside `chainlink` repo (just not to push creds accidentally). Populate the files with relevant credentials for the nodes 4. Ensure that following env variables are set @@ -14,9 +14,10 @@ export ETH_URL= export ETH_CHAIN_ID= export ACCOUNT_KEY= ``` -5. execute from `core/scripts/vrfv2/testnet/setup-envs` folder +5. execute from `core/scripts/common/vrf/setup-envs` folder ``` go run . \ +--vrf-version="v2plus" \ --vrf-primary-node-url=http://localhost:6610 \ --vrf-primary-creds-file \ --vrf-backup-node-url=http://localhost:6611 \ @@ -27,13 +28,14 @@ go run . \ --bhs-bk-creds-file \ --bhf-node-url=http://localhost:6614 \ --bhf-creds-file \ ---deploy-contracts true \ ---batch-fulfillment-enabled true \ ---min-confs 1 \ ---num-eth-keys 5 \ ---num-vrf-keys 1 \ ---sending-key-funding-amount 100000000000000000 - +--deploy-contracts-and-create-jobs="true" \ +--subscription-balance="1e19" \ +--subscription-balance-native="1e18" \ +--batch-fulfillment-enabled="true" \ +--min-confs=3 \ +--num-eth-keys=1 \ +--num-vrf-keys=1 \ +--sending-key-funding-amount="1e17" ``` Optional parameters - will not be deployed if specified (NOT WORKING YET) diff --git a/core/scripts/vrfv2/testnet/setup-envs/main.go b/core/scripts/common/vrf/setup-envs/main.go similarity index 72% rename from core/scripts/vrfv2/testnet/setup-envs/main.go rename to core/scripts/common/vrf/setup-envs/main.go index 9e6edf725e5..8a7b1c8b439 100644 --- a/core/scripts/vrfv2/testnet/setup-envs/main.go +++ b/core/scripts/common/vrf/setup-envs/main.go @@ -6,11 +6,15 @@ import ( "flag" "fmt" "github.com/ethereum/go-ethereum/common" + "github.com/shopspring/decimal" helpers "github.com/smartcontractkit/chainlink/core/scripts/common" - "github.com/smartcontractkit/chainlink/core/scripts/vrfv2/testnet/constants" - "github.com/smartcontractkit/chainlink/core/scripts/vrfv2/testnet/scripts" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/constants" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/model" + "github.com/smartcontractkit/chainlink/core/scripts/vrfv2/testnet/v2scripts" + "github.com/smartcontractkit/chainlink/core/scripts/vrfv2plus/testnet/v2plusscripts" clcmd "github.com/smartcontractkit/chainlink/v2/core/cmd" "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/chainlink/v2/core/web/presenters" "github.com/urfave/cli" "io" @@ -54,7 +58,7 @@ func main() { bhsNodeURL := flag.String("bhs-node-url", "", "remote node URL") bhsBackupNodeURL := flag.String("bhs-backup-node-url", "", "remote node URL") bhfNodeURL := flag.String("bhf-node-url", "", "remote node URL") - nodeSendingKeyFundingAmount := flag.Int64("sending-key-funding-amount", constants.NodeSendingKeyFundingAmountGwei, "remote node URL") + nodeSendingKeyFundingAmount := flag.String("sending-key-funding-amount", constants.NodeSendingKeyFundingAmount, "sending key funding amount") vrfPrimaryCredsFile := flag.String("vrf-primary-creds-file", "", "Creds to authenticate to the node") vrfBackupCredsFile := flag.String("vrf-bk-creds-file", "", "Creds to authenticate to the node") @@ -65,12 +69,15 @@ func main() { numEthKeys := flag.Int("num-eth-keys", 5, "Number of eth keys to create") maxGasPriceGwei := flag.Int("max-gas-price-gwei", -1, "Max gas price gwei of the eth keys") numVRFKeys := flag.Int("num-vrf-keys", 1, "Number of vrf keys to create") + batchFulfillmentEnabled := flag.Bool("batch-fulfillment-enabled", constants.BatchFulfillmentEnabled, "whether to enable batch fulfillment on Cl node") - deployContracts := flag.Bool("deploy-contracts", true, "whether to deploy contracts and create jobs") + vrfVersion := flag.String("vrf-version", "v2", "VRF version to use") + deployContractsAndCreateJobs := flag.Bool("deploy-contracts-and-create-jobs", false, "whether to deploy contracts and create jobs") - batchFulfillmentEnabled := flag.Bool("batch-fulfillment-enabled", constants.BatchFulfillmentEnabled, "whether to enable batch fulfillment on Cl node") - minConfs := flag.Int("min-confs", constants.MinConfs, "minimum confirmations") + subscriptionBalanceJuelsString := flag.String("subscription-balance", constants.SubscriptionBalanceJuels, "amount to fund subscription with Link token (Juels)") + subscriptionBalanceNativeWeiString := flag.String("subscription-balance-native", constants.SubscriptionBalanceNativeWei, "amount to fund subscription with native token (Wei)") + minConfs := flag.Int("min-confs", constants.MinConfs, "minimum confirmations") linkAddress := flag.String("link-address", "", "address of link token") linkEthAddress := flag.String("link-eth-feed", "", "address of link eth feed") bhsContractAddressString := flag.String("bhs-address", "", "address of BHS contract") @@ -80,41 +87,50 @@ func main() { e := helpers.SetupEnv(false) flag.Parse() - nodesMap := make(map[string]scripts.Node) + nodesMap := make(map[string]model.Node) + + if *vrfVersion != "v2" && *vrfVersion != "v2plus" { + panic(fmt.Sprintf("Invalid VRF Version `%s`. Only `v2` and `v2plus` are supported", *vrfVersion)) + } + fmt.Println("Using VRF Version:", *vrfVersion) + + fundingAmount := decimal.RequireFromString(*nodeSendingKeyFundingAmount).BigInt() + subscriptionBalanceJuels := decimal.RequireFromString(*subscriptionBalanceJuelsString).BigInt() + subscriptionBalanceNativeWei := decimal.RequireFromString(*subscriptionBalanceNativeWeiString).BigInt() if *vrfPrimaryNodeURL != "" { - nodesMap[scripts.VRFPrimaryNodeName] = scripts.Node{ + nodesMap[model.VRFPrimaryNodeName] = model.Node{ URL: *vrfPrimaryNodeURL, - SendingKeyFundingAmount: *big.NewInt(*nodeSendingKeyFundingAmount), + SendingKeyFundingAmount: fundingAmount, CredsFile: *vrfPrimaryCredsFile, } } if *vrfBackupNodeURL != "" { - nodesMap[scripts.VRFBackupNodeName] = scripts.Node{ + nodesMap[model.VRFBackupNodeName] = model.Node{ URL: *vrfBackupNodeURL, - SendingKeyFundingAmount: *big.NewInt(*nodeSendingKeyFundingAmount), + SendingKeyFundingAmount: fundingAmount, CredsFile: *vrfBackupCredsFile, } } if *bhsNodeURL != "" { - nodesMap[scripts.BHSNodeName] = scripts.Node{ + nodesMap[model.BHSNodeName] = model.Node{ URL: *bhsNodeURL, - SendingKeyFundingAmount: *big.NewInt(*nodeSendingKeyFundingAmount), + SendingKeyFundingAmount: fundingAmount, CredsFile: *bhsCredsFile, } } if *bhsBackupNodeURL != "" { - nodesMap[scripts.BHSBackupNodeName] = scripts.Node{ + nodesMap[model.BHSBackupNodeName] = model.Node{ URL: *bhsBackupNodeURL, - SendingKeyFundingAmount: *big.NewInt(*nodeSendingKeyFundingAmount), + SendingKeyFundingAmount: fundingAmount, CredsFile: *bhsBackupCredsFile, } } if *bhfNodeURL != "" { - nodesMap[scripts.BHFNodeName] = scripts.Node{ + nodesMap[model.BHFNodeName] = model.Node{ URL: *bhfNodeURL, - SendingKeyFundingAmount: *big.NewInt(*nodeSendingKeyFundingAmount), + SendingKeyFundingAmount: fundingAmount, CredsFile: *bhfCredsFile, } } @@ -124,14 +140,14 @@ func main() { client, app := connectToNode(&node.URL, output, node.CredsFile) ethKeys := createETHKeysIfNeeded(client, app, output, numEthKeys, &node.URL, maxGasPriceGwei) - if key == scripts.VRFPrimaryNodeName { + if key == model.VRFPrimaryNodeName { vrfKeys := createVRFKeyIfNeeded(client, app, output, numVRFKeys, &node.URL) node.VrfKeys = mapVrfKeysToStringArr(vrfKeys) printVRFKeyData(vrfKeys) exportVRFKey(client, app, vrfKeys[0], output) } - if key == scripts.VRFBackupNodeName { + if key == model.VRFBackupNodeName { vrfKeys := getVRFKeys(client, app, output) node.VrfKeys = mapVrfKeysToStringArr(vrfKeys) } @@ -141,23 +157,11 @@ func main() { fundNodesIfNeeded(node, key, e) nodesMap[key] = node } - importVRFKeyToNodeIfSet(vrfBackupNodeURL, nodesMap, output, nodesMap[scripts.VRFBackupNodeName].CredsFile) - fmt.Println() + importVRFKeyToNodeIfSet(vrfBackupNodeURL, nodesMap, output, nodesMap[model.VRFBackupNodeName].CredsFile) - if *deployContracts { - feeConfig := vrf_coordinator_v2.VRFCoordinatorV2FeeConfig{ - FulfillmentFlatFeeLinkPPMTier1: uint32(constants.FlatFeeTier1), - FulfillmentFlatFeeLinkPPMTier2: uint32(constants.FlatFeeTier2), - FulfillmentFlatFeeLinkPPMTier3: uint32(constants.FlatFeeTier3), - FulfillmentFlatFeeLinkPPMTier4: uint32(constants.FlatFeeTier4), - FulfillmentFlatFeeLinkPPMTier5: uint32(constants.FlatFeeTier5), - ReqsForTier2: big.NewInt(constants.ReqsForTier2), - ReqsForTier3: big.NewInt(constants.ReqsForTier3), - ReqsForTier4: big.NewInt(constants.ReqsForTier4), - ReqsForTier5: big.NewInt(constants.ReqsForTier5), - } + if *deployContractsAndCreateJobs { - contractAddresses := scripts.ContractAddresses{ + contractAddresses := model.ContractAddresses{ LinkAddress: *linkAddress, LinkEthAddress: *linkEthAddress, BhsContractAddress: common.HexToAddress(*bhsContractAddressString), @@ -166,24 +170,65 @@ func main() { BatchCoordinatorAddress: common.HexToAddress(*batchCoordinatorAddressString), } - coordinatorConfig := scripts.CoordinatorConfig{ - MinConfs: minConfs, - MaxGasLimit: &constants.MaxGasLimit, - StalenessSeconds: &constants.StalenessSeconds, - GasAfterPayment: &constants.GasAfterPayment, - FallbackWeiPerUnitLink: constants.FallbackWeiPerUnitLink, - FeeConfig: feeConfig, - } + var jobSpecs model.JobSpecs + + switch *vrfVersion { + case "v2": + feeConfigV2 := vrf_coordinator_v2.VRFCoordinatorV2FeeConfig{ + FulfillmentFlatFeeLinkPPMTier1: uint32(constants.FlatFeeTier1), + FulfillmentFlatFeeLinkPPMTier2: uint32(constants.FlatFeeTier2), + FulfillmentFlatFeeLinkPPMTier3: uint32(constants.FlatFeeTier3), + FulfillmentFlatFeeLinkPPMTier4: uint32(constants.FlatFeeTier4), + FulfillmentFlatFeeLinkPPMTier5: uint32(constants.FlatFeeTier5), + ReqsForTier2: big.NewInt(constants.ReqsForTier2), + ReqsForTier3: big.NewInt(constants.ReqsForTier3), + ReqsForTier4: big.NewInt(constants.ReqsForTier4), + ReqsForTier5: big.NewInt(constants.ReqsForTier5), + } + + coordinatorConfigV2 := v2scripts.CoordinatorConfigV2{ + MinConfs: minConfs, + MaxGasLimit: &constants.MaxGasLimit, + StalenessSeconds: &constants.StalenessSeconds, + GasAfterPayment: &constants.GasAfterPayment, + FallbackWeiPerUnitLink: constants.FallbackWeiPerUnitLink, + FeeConfig: feeConfigV2, + } - jobSpecs := scripts.VRFV2DeployUniverse( - e, - constants.SubscriptionBalanceJuels, - &nodesMap[scripts.VRFPrimaryNodeName].VrfKeys[0], - contractAddresses, - coordinatorConfig, - *batchFulfillmentEnabled, - nodesMap, - ) + jobSpecs = v2scripts.VRFV2DeployUniverse( + e, + subscriptionBalanceJuels, + &nodesMap[model.VRFPrimaryNodeName].VrfKeys[0], + contractAddresses, + coordinatorConfigV2, + *batchFulfillmentEnabled, + nodesMap, + ) + case "v2plus": + feeConfigV2Plus := vrf_coordinator_v2_5.VRFCoordinatorV25FeeConfig{ + FulfillmentFlatFeeLinkPPM: uint32(constants.FlatFeeLinkPPM), + FulfillmentFlatFeeNativePPM: uint32(constants.FlatFeeNativePPM), + } + coordinatorConfigV2Plus := v2plusscripts.CoordinatorConfigV2Plus{ + MinConfs: minConfs, + MaxGasLimit: &constants.MaxGasLimit, + StalenessSeconds: &constants.StalenessSeconds, + GasAfterPayment: &constants.GasAfterPayment, + FallbackWeiPerUnitLink: constants.FallbackWeiPerUnitLink, + FeeConfig: feeConfigV2Plus, + } + + jobSpecs = v2plusscripts.VRFV2PlusDeployUniverse( + e, + subscriptionBalanceJuels, + subscriptionBalanceNativeWei, + &nodesMap[model.VRFPrimaryNodeName].VrfKeys[0], + contractAddresses, + coordinatorConfigV2Plus, + *batchFulfillmentEnabled, + nodesMap, + ) + } for key, node := range nodesMap { client, app := connectToNode(&node.URL, output, node.CredsFile) @@ -196,41 +241,43 @@ func main() { deleteJob(jobID, client, app, output) } //CREATE JOBS + switch key { - case scripts.VRFPrimaryNodeName: + case model.VRFPrimaryNodeName: createJob(jobSpecs.VRFPrimaryNode, client, app, output) - case scripts.VRFBackupNodeName: + case model.VRFBackupNodeName: createJob(jobSpecs.VRFBackupyNode, client, app, output) - case scripts.BHSNodeName: + case model.BHSNodeName: createJob(jobSpecs.BHSNode, client, app, output) - case scripts.BHSBackupNodeName: + case model.BHSBackupNodeName: createJob(jobSpecs.BHSBackupNode, client, app, output) - case scripts.BHFNodeName: + case model.BHFNodeName: createJob(jobSpecs.BHFNode, client, app, output) } } } - } -func fundNodesIfNeeded(node scripts.Node, key string, e helpers.Environment) { - if node.SendingKeyFundingAmount.Int64() > 0 { - fmt.Println("\nFunding", key, "Node's Sending Keys...") +func fundNodesIfNeeded(node model.Node, key string, e helpers.Environment) { + if node.SendingKeyFundingAmount.Cmp(big.NewInt(0)) == 1 { + fmt.Println("\nFunding", key, "Node's Sending Keys. Need to fund each key with", node.SendingKeyFundingAmount, "wei") for _, sendingKey := range node.SendingKeys { - fundingToSendWei := node.SendingKeyFundingAmount.Int64() - sendingKey.BalanceEth.Int64() - if fundingToSendWei > 0 { - helpers.FundNode(e, sendingKey.Address, big.NewInt(fundingToSendWei)) + fundingToSendWei := new(big.Int).Sub(node.SendingKeyFundingAmount, sendingKey.BalanceEth) + if fundingToSendWei.Cmp(big.NewInt(0)) == 1 { + helpers.FundNode(e, sendingKey.Address, fundingToSendWei) } else { - fmt.Println("\nSkipping Funding", sendingKey.Address, "since it has", sendingKey.BalanceEth.Int64(), "wei") + fmt.Println("\nSkipping Funding", sendingKey.Address, "since it has", sendingKey.BalanceEth.String(), "wei") } } + } else { + fmt.Println("\nSkipping Funding", key, "Node's Sending Keys since funding amount is 0 wei") } } -func importVRFKeyToNodeIfSet(vrfBackupNodeURL *string, nodes map[string]scripts.Node, output *bytes.Buffer, file string) { +func importVRFKeyToNodeIfSet(vrfBackupNodeURL *string, nodes map[string]model.Node, output *bytes.Buffer, file string) { if *vrfBackupNodeURL != "" { - vrfBackupNode := nodes[scripts.VRFBackupNodeName] - vrfPrimaryNode := nodes[scripts.VRFBackupNodeName] + vrfBackupNode := nodes[model.VRFBackupNodeName] + vrfPrimaryNode := nodes[model.VRFBackupNodeName] if len(vrfBackupNode.VrfKeys) == 0 || vrfPrimaryNode.VrfKeys[0] != vrfBackupNode.VrfKeys[0] { client, app := connectToNode(&vrfBackupNode.URL, output, file) @@ -335,10 +382,10 @@ func printETHKeyData(ethKeys []presenters.ETHKeyResource) { } } -func mapEthKeysToSendingKeyArr(ethKeys []presenters.ETHKeyResource) []scripts.SendingKey { - var sendingKeys []scripts.SendingKey +func mapEthKeysToSendingKeyArr(ethKeys []presenters.ETHKeyResource) []model.SendingKey { + var sendingKeys []model.SendingKey for _, ethKey := range ethKeys { - sendingKey := scripts.SendingKey{Address: ethKey.Address, BalanceEth: *ethKey.EthBalance.ToInt()} + sendingKey := model.SendingKey{Address: ethKey.Address, BalanceEth: ethKey.EthBalance.ToInt()} sendingKeys = append(sendingKeys, sendingKey) } return sendingKeys diff --git a/core/scripts/common/vrf/util/util.go b/core/scripts/common/vrf/util/util.go new file mode 100644 index 00000000000..751aa013201 --- /dev/null +++ b/core/scripts/common/vrf/util/util.go @@ -0,0 +1,22 @@ +package util + +import ( + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/model" +) + +func MapToSendingKeyArr(nodeSendingKeys []string) []model.SendingKey { + var sendingKeys []model.SendingKey + + for _, key := range nodeSendingKeys { + sendingKeys = append(sendingKeys, model.SendingKey{Address: key}) + } + return sendingKeys +} + +func MapToAddressArr(sendingKeys []model.SendingKey) []string { + var sendingKeysString []string + for _, sendingKey := range sendingKeys { + sendingKeysString = append(sendingKeysString, sendingKey.Address) + } + return sendingKeysString +} diff --git a/core/scripts/vrfv2/testnet/constants/constants.go b/core/scripts/vrfv2/testnet/constants/constants.go deleted file mode 100644 index 73356d48ffc..00000000000 --- a/core/scripts/vrfv2/testnet/constants/constants.go +++ /dev/null @@ -1,28 +0,0 @@ -package constants - -import ( - "github.com/smartcontractkit/chainlink/v2/core/assets" - "math/big" -) - -var ( - SubscriptionBalanceJuels = assets.Ether(10).ToInt() - - // optional flags - FallbackWeiPerUnitLink = big.NewInt(6e16) - BatchFulfillmentEnabled = true - MinConfs = 3 - NodeSendingKeyFundingAmountGwei = assets.GWei(0).Int64() //100000000 = 0.1 ETH - MaxGasLimit = int64(2.5e6) - StalenessSeconds = int64(86400) - GasAfterPayment = int64(33285) - FlatFeeTier1 = int64(500) - FlatFeeTier2 = int64(500) - FlatFeeTier3 = int64(500) - FlatFeeTier4 = int64(500) - FlatFeeTier5 = int64(500) - ReqsForTier2 = int64(0) - ReqsForTier3 = int64(0) - ReqsForTier4 = int64(0) - ReqsForTier5 = int64(0) -) diff --git a/core/scripts/vrfv2/testnet/main.go b/core/scripts/vrfv2/testnet/main.go index d418eb6d153..5b216776bd9 100644 --- a/core/scripts/vrfv2/testnet/main.go +++ b/core/scripts/vrfv2/testnet/main.go @@ -11,7 +11,7 @@ import ( "os" "strings" - "github.com/smartcontractkit/chainlink/core/scripts/vrfv2/testnet/scripts" + "github.com/smartcontractkit/chainlink/core/scripts/vrfv2/testnet/v2scripts" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_owner_test_consumer" "github.com/ethereum/go-ethereum" @@ -350,7 +350,7 @@ func main() { cmd := flag.NewFlagSet("batch-bhs-deploy", flag.ExitOnError) bhsAddr := cmd.String("bhs-address", "", "address of the blockhash store contract") helpers.ParseArgs(cmd, os.Args[2:], "bhs-address") - scripts.DeployBatchBHS(e, common.HexToAddress(*bhsAddr)) + v2scripts.DeployBatchBHS(e, common.HexToAddress(*bhsAddr)) case "batch-bhs-store": cmd := flag.NewFlagSet("batch-bhs-store", flag.ExitOnError) batchAddr := cmd.String("batch-bhs-address", "", "address of the batch bhs contract") @@ -418,7 +418,7 @@ func main() { } if *startBlock == -1 { - closestBlock, err2 := scripts.ClosestBlock(e, common.HexToAddress(*batchAddr), uint64(*endBlock), uint64(*batchSize)) + closestBlock, err2 := v2scripts.ClosestBlock(e, common.HexToAddress(*batchAddr), uint64(*endBlock), uint64(*batchSize)) // found a block with blockhash stored that's more recent that end block if err2 == nil { *startBlock = int64(closestBlock) @@ -491,14 +491,14 @@ func main() { helpers.PanicErr(err) fmt.Println("latest head number:", h.Number.String()) case "bhs-deploy": - scripts.DeployBHS(e) + v2scripts.DeployBHS(e) case "coordinator-deploy": coordinatorDeployCmd := flag.NewFlagSet("coordinator-deploy", flag.ExitOnError) coordinatorDeployLinkAddress := coordinatorDeployCmd.String("link-address", "", "address of link token") coordinatorDeployBHSAddress := coordinatorDeployCmd.String("bhs-address", "", "address of bhs") coordinatorDeployLinkEthFeedAddress := coordinatorDeployCmd.String("link-eth-feed", "", "address of link-eth-feed") helpers.ParseArgs(coordinatorDeployCmd, os.Args[2:], "link-address", "bhs-address", "link-eth-feed") - scripts.DeployCoordinator(e, *coordinatorDeployLinkAddress, *coordinatorDeployBHSAddress, *coordinatorDeployLinkEthFeedAddress) + v2scripts.DeployCoordinator(e, *coordinatorDeployLinkAddress, *coordinatorDeployBHSAddress, *coordinatorDeployLinkEthFeedAddress) case "coordinator-get-config": cmd := flag.NewFlagSet("coordinator-get-config", flag.ExitOnError) coordinatorAddress := cmd.String("coordinator-address", "", "coordinator address") @@ -507,7 +507,7 @@ func main() { coordinator, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - scripts.PrintCoordinatorConfig(coordinator) + v2scripts.PrintCoordinatorConfig(coordinator) case "coordinator-set-config": cmd := flag.NewFlagSet("coordinator-set-config", flag.ExitOnError) setConfigAddress := cmd.String("coordinator-address", "", "coordinator address") @@ -530,7 +530,7 @@ func main() { coordinator, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(*setConfigAddress), e.Ec) helpers.PanicErr(err) - scripts.SetCoordinatorConfig( + v2scripts.SetCoordinatorConfig( e, *coordinator, uint16(*minConfs), @@ -564,7 +564,7 @@ func main() { *registerKeyUncompressedPubKey = strings.Replace(*registerKeyUncompressedPubKey, "0x", "04", 1) } - scripts.RegisterCoordinatorProvingKey(e, *coordinator, *registerKeyUncompressedPubKey, *registerKeyOracleAddress) + v2scripts.RegisterCoordinatorProvingKey(e, *coordinator, *registerKeyUncompressedPubKey, *registerKeyOracleAddress) case "coordinator-deregister-key": coordinatorDeregisterKey := flag.NewFlagSet("coordinator-deregister-key", flag.ExitOnError) deregisterKeyAddress := coordinatorDeregisterKey.String("address", "", "coordinator address") @@ -692,14 +692,14 @@ func main() { helpers.PanicErr(err) fmt.Printf("Request config %+v Rw %+v Rid %+v\n", rc, rw, rid) case "deploy-universe": - scripts.DeployUniverseViaCLI(e) + v2scripts.DeployUniverseViaCLI(e) case "eoa-consumer-deploy": consumerDeployCmd := flag.NewFlagSet("eoa-consumer-deploy", flag.ExitOnError) consumerCoordinator := consumerDeployCmd.String("coordinator-address", "", "coordinator address") consumerLinkAddress := consumerDeployCmd.String("link-address", "", "link-address") helpers.ParseArgs(consumerDeployCmd, os.Args[2:], "coordinator-address", "link-address") - scripts.EoaDeployConsumer(e, *consumerCoordinator, *consumerLinkAddress) + v2scripts.EoaDeployConsumer(e, *consumerCoordinator, *consumerLinkAddress) case "eoa-load-test-consumer-deploy": loadTestConsumerDeployCmd := flag.NewFlagSet("eoa-load-test-consumer-deploy", flag.ExitOnError) consumerCoordinator := loadTestConsumerDeployCmd.String("coordinator-address", "", "coordinator address") @@ -716,7 +716,7 @@ func main() { loadTestConsumerDeployCmd := flag.NewFlagSet("eoa-load-test-consumer-with-metrics-deploy", flag.ExitOnError) consumerCoordinator := loadTestConsumerDeployCmd.String("coordinator-address", "", "coordinator address") helpers.ParseArgs(loadTestConsumerDeployCmd, os.Args[2:], "coordinator-address") - scripts.EoaLoadTestConsumerWithMetricsDeploy(e, *consumerCoordinator) + v2scripts.EoaLoadTestConsumerWithMetricsDeploy(e, *consumerCoordinator) case "eoa-vrf-owner-test-consumer-deploy": loadTestConsumerDeployCmd := flag.NewFlagSet("eoa-vrf-owner-test-consumer-deploy", flag.ExitOnError) consumerCoordinator := loadTestConsumerDeployCmd.String("coordinator-address", "", "coordinator address") @@ -734,7 +734,7 @@ func main() { helpers.ParseArgs(createSubCmd, os.Args[2:], "coordinator-address") coordinator, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - scripts.EoaCreateSub(e, *coordinator) + v2scripts.EoaCreateSub(e, *coordinator) case "eoa-add-sub-consumer": addSubConsCmd := flag.NewFlagSet("eoa-add-sub-consumer", flag.ExitOnError) coordinatorAddress := addSubConsCmd.String("coordinator-address", "", "coordinator address") @@ -743,7 +743,7 @@ func main() { helpers.ParseArgs(addSubConsCmd, os.Args[2:], "coordinator-address", "sub-id", "consumer-address") coordinator, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - scripts.EoaAddConsumerToSub(e, *coordinator, uint64(*subID), *consumerAddress) + v2scripts.EoaAddConsumerToSub(e, *coordinator, uint64(*subID), *consumerAddress) case "eoa-create-fund-authorize-sub": // Lets just treat the owner key as the EOA controlling the sub cfaSubCmd := flag.NewFlagSet("eoa-create-fund-authorize-sub", flag.ExitOnError) @@ -1029,7 +1029,7 @@ func main() { coordinator, err := vrf_coordinator_v2.NewVRFCoordinatorV2(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - scripts.EoaFundSubscription(e, *coordinator, *consumerLinkAddress, amount, uint64(*subID)) + v2scripts.EoaFundSubscription(e, *coordinator, *consumerLinkAddress, amount, uint64(*subID)) case "eoa-read": cmd := flag.NewFlagSet("eoa-read", flag.ExitOnError) consumerAddress := cmd.String("consumer", "", "consumer address") @@ -1197,7 +1197,7 @@ func main() { linkETHFeedAddress := cmd.String("link-eth-feed", "", "address of link-eth-feed") coordinatorAddress := cmd.String("coordinator-address", "", "address of the vrf coordinator v2 contract") helpers.ParseArgs(cmd, os.Args[2:], "link-address", "link-eth-feed", "coordinator-address") - scripts.WrapperDeploy(e, + v2scripts.WrapperDeploy(e, common.HexToAddress(*linkAddress), common.HexToAddress(*linkETHFeedAddress), common.HexToAddress(*coordinatorAddress)) @@ -1235,7 +1235,7 @@ func main() { maxNumWords := cmd.Uint("max-num-words", 10, "the keyhash that wrapper requests should use") helpers.ParseArgs(cmd, os.Args[2:], "wrapper-address", "key-hash") - scripts.WrapperConfigure(e, + v2scripts.WrapperConfigure(e, common.HexToAddress(*wrapperAddress), *wrapperGasOverhead, *coordinatorGasOverhead, @@ -1267,7 +1267,7 @@ func main() { wrapperAddress := cmd.String("wrapper-address", "", "address of the VRFV2Wrapper contract") helpers.ParseArgs(cmd, os.Args[2:], "link-address", "wrapper-address") - scripts.WrapperConsumerDeploy(e, + v2scripts.WrapperConsumerDeploy(e, common.HexToAddress(*linkAddress), common.HexToAddress(*wrapperAddress)) case "wrapper-consumer-request": @@ -1344,10 +1344,10 @@ func main() { batchBHSAddress := cmd.String("batch-bhs-address", "", "address of the batch blockhash store") batchSize := cmd.Uint64("batch-size", 100, "batch size") helpers.ParseArgs(cmd, os.Args[2:], "block-number", "batch-bhs-address") - _, err := scripts.ClosestBlock(e, common.HexToAddress(*batchBHSAddress), *blockNumber, *batchSize) + _, err := v2scripts.ClosestBlock(e, common.HexToAddress(*batchBHSAddress), *blockNumber, *batchSize) helpers.PanicErr(err) case "wrapper-universe-deploy": - scripts.DeployWrapperUniverse(e) + v2scripts.DeployWrapperUniverse(e) default: panic("unrecognized subcommand: " + os.Args[1]) } diff --git a/core/scripts/vrfv2/testnet/scripts/super_scripts.go b/core/scripts/vrfv2/testnet/v2scripts/super_scripts.go similarity index 83% rename from core/scripts/vrfv2/testnet/scripts/super_scripts.go rename to core/scripts/vrfv2/testnet/v2scripts/super_scripts.go index 3594636a604..f5e37005690 100644 --- a/core/scripts/vrfv2/testnet/scripts/super_scripts.go +++ b/core/scripts/vrfv2/testnet/v2scripts/super_scripts.go @@ -1,12 +1,14 @@ -package scripts +package v2scripts import ( "context" "encoding/hex" "flag" "fmt" - "github.com/smartcontractkit/chainlink/core/scripts/vrfv2/testnet/constants" - "github.com/smartcontractkit/chainlink/core/scripts/vrfv2/testnet/jobs" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/constants" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/jobs" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/model" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/util" "math/big" "os" "strings" @@ -22,47 +24,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/signatures/secp256k1" ) -var ( - VRFPrimaryNodeName = "vrf-primary-node" - VRFBackupNodeName = "vrf-backup-node" - BHSNodeName = "bhs-node" - BHSBackupNodeName = "bhs-backup-node" - BHFNodeName = "bhf-node" -) - -type Node struct { - URL string - CredsFile string - SendingKeys []SendingKey - NumberOfSendingKeysToCreate int - SendingKeyFundingAmount big.Int - VrfKeys []string - jobSpec string -} - -type SendingKey struct { - Address string - BalanceEth big.Int -} - -type JobSpecs struct { - VRFPrimaryNode string - VRFBackupyNode string - BHSNode string - BHSBackupNode string - BHFNode string -} - -type ContractAddresses struct { - LinkAddress string - LinkEthAddress string - BhsContractAddress common.Address - BatchBHSAddress common.Address - CoordinatorAddress common.Address - BatchCoordinatorAddress common.Address -} - -type CoordinatorConfig struct { +type CoordinatorConfigV2 struct { MinConfs *int MaxGasLimit *int64 StalenessSeconds *int64 @@ -82,8 +44,8 @@ func DeployUniverseViaCLI(e helpers.Environment) { coordinatorAddressString := *deployCmd.String("coordinator-address", "", "address of VRF Coordinator contract") batchCoordinatorAddressString := *deployCmd.String("batch-coordinator-address", "", "address Batch VRF Coordinator contract") - subscriptionBalanceJuelsString := deployCmd.String("subscription-balance", constants.SubscriptionBalanceJuels.String(), "amount to fund subscription") - nodeSendingKeyFundingAmount := deployCmd.Int64("sending-key-funding-amount", constants.NodeSendingKeyFundingAmountGwei, "CL node sending key funding amount") + subscriptionBalanceJuelsString := deployCmd.String("subscription-balance", constants.SubscriptionBalanceJuels, "amount to fund subscription") + nodeSendingKeyFundingAmount := deployCmd.String("sending-key-funding-amount", constants.NodeSendingKeyFundingAmount, "CL node sending key funding amount") batchFulfillmentEnabled := deployCmd.Bool("batch-fulfillment-enabled", constants.BatchFulfillmentEnabled, "whether send randomness fulfillments in batches inside one tx from CL node") @@ -127,11 +89,15 @@ func DeployUniverseViaCLI(e helpers.Environment) { vrfPrimaryNodeSendingKeys := strings.Split(*vrfPrimaryNodeSendingKeysString, ",") - nodesMap := make(map[string]Node) + nodesMap := make(map[string]model.Node) - nodesMap[VRFPrimaryNodeName] = Node{ - SendingKeys: mapToSendingKeyArr(vrfPrimaryNodeSendingKeys), - SendingKeyFundingAmount: *big.NewInt(*nodeSendingKeyFundingAmount), + fundingAmount, ok := new(big.Int).SetString(*nodeSendingKeyFundingAmount, 10) + if !ok { + panic(fmt.Sprintf("failed to parse node sending key funding amount '%s'", *nodeSendingKeyFundingAmount)) + } + nodesMap[model.VRFPrimaryNodeName] = model.Node{ + SendingKeys: util.MapToSendingKeyArr(vrfPrimaryNodeSendingKeys), + SendingKeyFundingAmount: fundingAmount, } bhsContractAddress := common.HexToAddress(bhsContractAddressString) @@ -139,7 +105,7 @@ func DeployUniverseViaCLI(e helpers.Environment) { coordinatorAddress := common.HexToAddress(coordinatorAddressString) batchCoordinatorAddress := common.HexToAddress(batchCoordinatorAddressString) - contractAddresses := ContractAddresses{ + contractAddresses := model.ContractAddresses{ LinkAddress: linkAddress, LinkEthAddress: linkEthAddress, BhsContractAddress: bhsContractAddress, @@ -148,7 +114,7 @@ func DeployUniverseViaCLI(e helpers.Environment) { BatchCoordinatorAddress: batchCoordinatorAddress, } - coordinatorConfig := CoordinatorConfig{ + coordinatorConfig := CoordinatorConfigV2{ MinConfs: minConfs, MaxGasLimit: maxGasLimit, StalenessSeconds: stalenessSeconds, @@ -167,31 +133,22 @@ func DeployUniverseViaCLI(e helpers.Environment) { nodesMap, ) - vrfPrimaryNode := nodesMap[VRFPrimaryNodeName] + vrfPrimaryNode := nodesMap[model.VRFPrimaryNodeName] fmt.Println("Funding node's sending keys...") for _, sendingKey := range vrfPrimaryNode.SendingKeys { - helpers.FundNode(e, sendingKey.Address, &vrfPrimaryNode.SendingKeyFundingAmount) + helpers.FundNode(e, sendingKey.Address, vrfPrimaryNode.SendingKeyFundingAmount) } } -func mapToSendingKeyArr(nodeSendingKeys []string) []SendingKey { - var sendingKeys []SendingKey - - for _, key := range nodeSendingKeys { - sendingKeys = append(sendingKeys, SendingKey{Address: key}) - } - return sendingKeys -} - func VRFV2DeployUniverse( e helpers.Environment, subscriptionBalanceJuels *big.Int, registerKeyUncompressedPubKey *string, - contractAddresses ContractAddresses, - coordinatorConfig CoordinatorConfig, + contractAddresses model.ContractAddresses, + coordinatorConfig CoordinatorConfigV2, batchFulfillmentEnabled bool, - nodesMap map[string]Node, -) JobSpecs { + nodesMap map[string]model.Node, +) model.JobSpecs { // Put key in ECDSA format if strings.HasPrefix(*registerKeyUncompressedPubKey, "0x") { @@ -246,7 +203,7 @@ func VRFV2DeployUniverse( if contractAddresses.BatchCoordinatorAddress.String() == "0x0000000000000000000000000000000000000000" { fmt.Println("\nDeploying Batch Coordinator...") - contractAddresses.BatchCoordinatorAddress = deployBatchCoordinatorV2(e, contractAddresses.CoordinatorAddress) + contractAddresses.BatchCoordinatorAddress = DeployBatchCoordinatorV2(e, contractAddresses.CoordinatorAddress) } fmt.Println("\nSetting Coordinator Config...") @@ -302,31 +259,31 @@ func VRFV2DeployUniverse( fmt.Printf("Subscription %+v\n", s) formattedVrfPrimaryJobSpec := fmt.Sprintf( - jobs.VRFJobFormatted, + jobs.VRFV2JobFormatted, contractAddresses.CoordinatorAddress, //coordinatorAddress contractAddresses.BatchCoordinatorAddress, //batchCoordinatorAddress batchFulfillmentEnabled, //batchFulfillmentEnabled compressedPkHex, //publicKey *coordinatorConfig.MinConfs, //minIncomingConfirmations e.ChainID, //evmChainID - strings.Join(mapToAddressArr(nodesMap[VRFPrimaryNodeName].SendingKeys), "\",\""), //fromAddresses + strings.Join(util.MapToAddressArr(nodesMap[model.VRFPrimaryNodeName].SendingKeys), "\",\""), //fromAddresses contractAddresses.CoordinatorAddress, - nodesMap[VRFPrimaryNodeName].SendingKeys[0].Address, + nodesMap[model.VRFPrimaryNodeName].SendingKeys[0].Address, contractAddresses.CoordinatorAddress, contractAddresses.CoordinatorAddress, ) formattedVrfBackupJobSpec := fmt.Sprintf( - jobs.VRFJobFormatted, + jobs.VRFV2JobFormatted, contractAddresses.CoordinatorAddress, //coordinatorAddress contractAddresses.BatchCoordinatorAddress, //batchCoordinatorAddress batchFulfillmentEnabled, //batchFulfillmentEnabled compressedPkHex, //publicKey 100, //minIncomingConfirmations e.ChainID, //evmChainID - strings.Join(mapToAddressArr(nodesMap[VRFBackupNodeName].SendingKeys), "\",\""), //fromAddresses + strings.Join(util.MapToAddressArr(nodesMap[model.VRFBackupNodeName].SendingKeys), "\",\""), //fromAddresses contractAddresses.CoordinatorAddress, - nodesMap[VRFPrimaryNodeName].SendingKeys[0], + nodesMap[model.VRFPrimaryNodeName].SendingKeys[0], contractAddresses.CoordinatorAddress, contractAddresses.CoordinatorAddress, ) @@ -338,7 +295,7 @@ func VRFV2DeployUniverse( 200, //lookbackBlocks contractAddresses.BhsContractAddress, //bhs address e.ChainID, //chain id - strings.Join(mapToAddressArr(nodesMap[BHSNodeName].SendingKeys), "\",\""), //sending addresses + strings.Join(util.MapToAddressArr(nodesMap[model.BHSNodeName].SendingKeys), "\",\""), //sending addresses ) formattedBHSBackupJobSpec := fmt.Sprintf( @@ -348,7 +305,7 @@ func VRFV2DeployUniverse( 200, //lookbackBlocks contractAddresses.BhsContractAddress, //bhs adreess e.ChainID, //chain id - strings.Join(mapToAddressArr(nodesMap[BHSBackupNodeName].SendingKeys), "\",\""), //sending addresses + strings.Join(util.MapToAddressArr(nodesMap[model.BHSBackupNodeName].SendingKeys), "\",\""), //sending addresses ) formattedBHFJobSpec := fmt.Sprintf( @@ -357,7 +314,7 @@ func VRFV2DeployUniverse( contractAddresses.BhsContractAddress, //bhs adreess contractAddresses.BatchBHSAddress, //batchBHS e.ChainID, //chain id - strings.Join(mapToAddressArr(nodesMap[BHFNodeName].SendingKeys), "\",\""), //sending addresses + strings.Join(util.MapToAddressArr(nodesMap[model.BHFNodeName].SendingKeys), "\",\""), //sending addresses ) fmt.Println( @@ -379,7 +336,7 @@ func VRFV2DeployUniverse( formattedVrfPrimaryJobSpec, ) - return JobSpecs{ + return model.JobSpecs{ VRFPrimaryNode: formattedVrfPrimaryJobSpec, VRFBackupyNode: formattedVrfBackupJobSpec, BHSNode: formattedBHSJobSpec, @@ -388,14 +345,6 @@ func VRFV2DeployUniverse( } } -func mapToAddressArr(sendingKeys []SendingKey) []string { - var sendingKeysString []string - for _, sendingKey := range sendingKeys { - sendingKeysString = append(sendingKeysString, sendingKey.Address) - } - return sendingKeysString -} - func DeployWrapperUniverse(e helpers.Environment) { cmd := flag.NewFlagSet("wrapper-universe-deploy", flag.ExitOnError) linkAddress := cmd.String("link-address", "", "address of link token") diff --git a/core/scripts/vrfv2/testnet/scripts/util.go b/core/scripts/vrfv2/testnet/v2scripts/util.go similarity index 99% rename from core/scripts/vrfv2/testnet/scripts/util.go rename to core/scripts/vrfv2/testnet/v2scripts/util.go index a55a78adb58..0e348e9c01c 100644 --- a/core/scripts/vrfv2/testnet/scripts/util.go +++ b/core/scripts/vrfv2/testnet/v2scripts/util.go @@ -1,4 +1,4 @@ -package scripts +package v2scripts import ( "context" @@ -53,7 +53,7 @@ func DeployCoordinator( return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) } -func deployBatchCoordinatorV2(e helpers.Environment, coordinatorAddress common.Address) (batchCoordinatorAddress common.Address) { +func DeployBatchCoordinatorV2(e helpers.Environment, coordinatorAddress common.Address) (batchCoordinatorAddress common.Address) { _, tx, _, err := batch_vrf_coordinator_v2.DeployBatchVRFCoordinatorV2(e.Owner, e.Ec, coordinatorAddress) helpers.PanicErr(err) return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) diff --git a/core/scripts/vrfv2plus/testnet/main.go b/core/scripts/vrfv2plus/testnet/main.go index 889350a61dd..0d1bf9a9481 100644 --- a/core/scripts/vrfv2plus/testnet/main.go +++ b/core/scripts/vrfv2plus/testnet/main.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "flag" "fmt" + "github.com/smartcontractkit/chainlink/core/scripts/vrfv2plus/testnet/v2plusscripts" "log" "math/big" "os" @@ -50,7 +51,6 @@ import ( var ( batchCoordinatorV2PlusABI = evmtypes.MustGetABI(batch_vrf_coordinator_v2plus.BatchVRFCoordinatorV2PlusABI) - coordinatorV2PlusABI = evmtypes.MustGetABI(vrf_coordinator_v2plus_interface.IVRFCoordinatorV2PlusInternalABI) ) func main() { @@ -102,9 +102,9 @@ func main() { helpers.PanicErr(err) fmt.Println("gas cost:", gasCost) case "smoke": - smokeTestVRF(e) + v2plusscripts.SmokeTestVRF(e) case "smoke-bhs": - smokeTestBHS(e) + v2plusscripts.SmokeTestBHS(e) case "manual-fulfill": cmd := flag.NewFlagSet("manual-fulfill", flag.ExitOnError) // In order to get the tx data for a fulfillment transaction, you can grep the @@ -337,7 +337,7 @@ func main() { cmd := flag.NewFlagSet("batch-bhs-deploy", flag.ExitOnError) bhsAddr := cmd.String("bhs-address", "", "address of the blockhash store contract") helpers.ParseArgs(cmd, os.Args[2:], "bhs-address") - deployBatchBHS(e, common.HexToAddress(*bhsAddr)) + v2plusscripts.DeployBatchBHS(e, common.HexToAddress(*bhsAddr)) case "batch-bhs-store": cmd := flag.NewFlagSet("batch-bhs-store", flag.ExitOnError) batchAddr := cmd.String("batch-bhs-address", "", "address of the batch bhs contract") @@ -513,14 +513,14 @@ func main() { helpers.PanicErr(err) fmt.Println("latest head number:", h.Number.String()) case "bhs-deploy": - deployBHS(e) + v2plusscripts.DeployBHS(e) case "coordinator-deploy": coordinatorDeployCmd := flag.NewFlagSet("coordinator-deploy", flag.ExitOnError) coordinatorDeployLinkAddress := coordinatorDeployCmd.String("link-address", "", "address of link token") coordinatorDeployBHSAddress := coordinatorDeployCmd.String("bhs-address", "", "address of bhs") coordinatorDeployLinkEthFeedAddress := coordinatorDeployCmd.String("link-eth-feed", "", "address of link-eth-feed") helpers.ParseArgs(coordinatorDeployCmd, os.Args[2:], "link-address", "bhs-address", "link-eth-feed") - deployCoordinator(e, *coordinatorDeployLinkAddress, *coordinatorDeployBHSAddress, *coordinatorDeployLinkEthFeedAddress) + v2plusscripts.DeployCoordinator(e, *coordinatorDeployLinkAddress, *coordinatorDeployBHSAddress, *coordinatorDeployLinkEthFeedAddress) case "coordinator-get-config": cmd := flag.NewFlagSet("coordinator-get-config", flag.ExitOnError) coordinatorAddress := cmd.String("coordinator-address", "", "coordinator address") @@ -529,7 +529,7 @@ func main() { coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - printCoordinatorConfig(coordinator) + v2plusscripts.PrintCoordinatorConfig(coordinator) case "coordinator-set-config": cmd := flag.NewFlagSet("coordinator-set-config", flag.ExitOnError) setConfigAddress := cmd.String("coordinator-address", "", "coordinator address") @@ -545,7 +545,7 @@ func main() { coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(common.HexToAddress(*setConfigAddress), e.Ec) helpers.PanicErr(err) - setCoordinatorConfig( + v2plusscripts.SetCoordinatorConfig( e, *coordinator, uint16(*minConfs), @@ -572,7 +572,7 @@ func main() { *registerKeyUncompressedPubKey = strings.Replace(*registerKeyUncompressedPubKey, "0x", "04", 1) } - registerCoordinatorProvingKey(e, *coordinator, *registerKeyUncompressedPubKey, *registerKeyOracleAddress) + v2plusscripts.RegisterCoordinatorProvingKey(e, *coordinator, *registerKeyUncompressedPubKey, *registerKeyOracleAddress) case "coordinator-deregister-key": coordinatorDeregisterKey := flag.NewFlagSet("coordinator-deregister-key", flag.ExitOnError) deregisterKeyAddress := coordinatorDeregisterKey.String("address", "", "coordinator address") @@ -704,7 +704,7 @@ func main() { helpers.PanicErr(err) fmt.Printf("Request config %+v Rw %+v Rid %+v\n", rc, rw, rid) case "deploy-universe": - deployUniverse(e) + v2plusscripts.DeployUniverseViaCLI(e) case "generate-proof-v2-plus": generateProofForV2Plus(e) case "eoa-consumer-deploy": @@ -713,7 +713,7 @@ func main() { consumerLinkAddress := consumerDeployCmd.String("link-address", "", "link-address") helpers.ParseArgs(consumerDeployCmd, os.Args[2:], "coordinator-address", "link-address", "key-hash") - eoaDeployConsumer(e, *consumerCoordinator, *consumerLinkAddress) + v2plusscripts.EoaDeployConsumer(e, *consumerCoordinator, *consumerLinkAddress) case "eoa-load-test-consumer-deploy": loadTestConsumerDeployCmd := flag.NewFlagSet("eoa-load-test-consumer-deploy", flag.ExitOnError) consumerCoordinator := loadTestConsumerDeployCmd.String("coordinator-address", "", "coordinator address") @@ -743,7 +743,7 @@ func main() { helpers.ParseArgs(createSubCmd, os.Args[2:], "coordinator-address") coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - eoaCreateSub(e, *coordinator) + v2plusscripts.EoaCreateSub(e, *coordinator) case "eoa-add-sub-consumer": addSubConsCmd := flag.NewFlagSet("eoa-add-sub-consumer", flag.ExitOnError) coordinatorAddress := addSubConsCmd.String("coordinator-address", "", "coordinator address") @@ -753,7 +753,7 @@ func main() { coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) parsedSubID := parseSubID(*subID) - eoaAddConsumerToSub(e, *coordinator, parsedSubID, *consumerAddress) + v2plusscripts.EoaAddConsumerToSub(e, *coordinator, parsedSubID, *consumerAddress) case "eoa-create-fund-authorize-sub": // Lets just treat the owner key as the EOA controlling the sub cfaSubCmd := flag.NewFlagSet("eoa-create-fund-authorize-sub", flag.ExitOnError) @@ -969,12 +969,9 @@ func main() { if !s { panic(fmt.Sprintf("failed to parse top up amount '%s'", *amountStr)) } - coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(common.HexToAddress(*coordinatorAddress), e.Ec) - helpers.PanicErr(err) - e.Owner.Value = amount - tx, err := coordinator.FundSubscriptionWithNative(e.Owner, parseSubID(*subID)) - helpers.PanicErr(err) - helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) + parsedSubID := parseSubID(*subID) + + v2plusscripts.EoaFundSubWithNative(e, common.HexToAddress(*coordinatorAddress), parsedSubID, amount) case "eoa-fund-sub": fund := flag.NewFlagSet("eoa-fund-sub", flag.ExitOnError) coordinatorAddress := fund.String("coordinator-address", "", "coordinator address") @@ -989,7 +986,7 @@ func main() { coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - eoaFundSubscription(e, *coordinator, *consumerLinkAddress, amount, parseSubID(*subID)) + v2plusscripts.EoaFundSubWithLink(e, *coordinator, *consumerLinkAddress, amount, parseSubID(*subID)) case "eoa-read": cmd := flag.NewFlagSet("eoa-read", flag.ExitOnError) consumerAddress := cmd.String("consumer", "", "consumer address") @@ -1122,7 +1119,7 @@ func main() { linkETHFeedAddress := cmd.String("link-eth-feed", "", "address of link-eth-feed") coordinatorAddress := cmd.String("coordinator-address", "", "address of the vrf coordinator v2 contract") helpers.ParseArgs(cmd, os.Args[2:], "link-address", "link-eth-feed", "coordinator-address") - wrapperDeploy(e, + v2plusscripts.WrapperDeploy(e, common.HexToAddress(*linkAddress), common.HexToAddress(*linkETHFeedAddress), common.HexToAddress(*coordinatorAddress)) @@ -1164,7 +1161,7 @@ func main() { fulfillmentFlatFeeNativePPM := cmd.Uint("fulfillment-flat-fee-native-ppm", 500, "the native flat fee in ppm to charge for fulfillment") helpers.ParseArgs(cmd, os.Args[2:], "wrapper-address", "key-hash", "fallback-wei-per-unit-link") - wrapperConfigure(e, + v2plusscripts.WrapperConfigure(e, common.HexToAddress(*wrapperAddress), *wrapperGasOverhead, *coordinatorGasOverhead, @@ -1200,7 +1197,7 @@ func main() { wrapperAddress := cmd.String("wrapper-address", "", "address of the VRFV2Wrapper contract") helpers.ParseArgs(cmd, os.Args[2:], "link-address", "wrapper-address") - wrapperConsumerDeploy(e, + v2plusscripts.WrapperConsumerDeploy(e, common.HexToAddress(*linkAddress), common.HexToAddress(*wrapperAddress)) case "wrapper-consumer-request": @@ -1272,7 +1269,7 @@ func main() { helpers.ParseArgs(cmd, os.Args[2:]) _ = helpers.CalculateLatestBlockHeader(e, *blockNumber) case "wrapper-universe-deploy": - deployWrapperUniverse(e) + v2plusscripts.DeployWrapperUniverse(e) default: panic("unrecognized subcommand: " + os.Args[1]) } diff --git a/core/scripts/vrfv2plus/testnet/super_scripts.go b/core/scripts/vrfv2plus/testnet/v2plusscripts/super_scripts.go similarity index 61% rename from core/scripts/vrfv2plus/testnet/super_scripts.go rename to core/scripts/vrfv2plus/testnet/v2plusscripts/super_scripts.go index 24a737be111..4e93d20f6d6 100644 --- a/core/scripts/vrfv2plus/testnet/super_scripts.go +++ b/core/scripts/vrfv2plus/testnet/v2plusscripts/super_scripts.go @@ -1,4 +1,4 @@ -package main +package v2plusscripts import ( "bytes" @@ -6,6 +6,12 @@ import ( "encoding/hex" "flag" "fmt" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/constants" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/jobs" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/model" + "github.com/smartcontractkit/chainlink/core/scripts/common/vrf/util" + evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2plus_interface" "math/big" "os" "strings" @@ -18,7 +24,6 @@ import ( "github.com/shopspring/decimal" helpers "github.com/smartcontractkit/chainlink/core/scripts/common" - "github.com/smartcontractkit/chainlink/v2/core/assets" evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/batch_blockhash_store" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/blockhash_store" @@ -30,46 +35,18 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/vrf/proof" ) -const formattedVRFJob = ` -type = "vrf" -name = "vrf_v2_plus" -schemaVersion = 1 -coordinatorAddress = "%s" -batchCoordinatorAddress = "%s" -batchFulfillmentEnabled = %t -batchFulfillmentGasMultiplier = 1.1 -publicKey = "%s" -minIncomingConfirmations = 3 -evmChainID = "%d" -fromAddresses = ["%s"] -pollPeriod = "5s" -requestTimeout = "24h" -observationSource = """ -decode_log [type=ethabidecodelog - abi="RandomWordsRequested(bytes32 indexed keyHash,uint256 requestId,uint256 preSeed,uint256 indexed subId,uint16 minimumRequestConfirmations,uint32 callbackGasLimit,uint32 numWords,bytes extraArgs,address indexed sender)" - data="$(jobRun.logData)" - topics="$(jobRun.logTopics)"] -generate_proof [type=vrfv2plus - publicKey="$(jobSpec.publicKey)" - requestBlockHash="$(jobRun.logBlockHash)" - requestBlockNumber="$(jobRun.logBlockNumber)" - topics="$(jobRun.logTopics)"] -estimate_gas [type=estimategaslimit - to="%s" - multiplier="1.1" - data="$(generate_proof.output)"] -simulate_fulfillment [type=ethcall - to="%s" - gas="$(estimate_gas)" - gasPrice="$(jobSpec.maxGasPrice)" - extractRevertReason=true - contract="%s" - data="$(generate_proof.output)"] -decode_log->generate_proof->estimate_gas->simulate_fulfillment -""" -` - -func smokeTestVRF(e helpers.Environment) { +var coordinatorV2PlusABI = evmtypes.MustGetABI(vrf_coordinator_v2plus_interface.IVRFCoordinatorV2PlusInternalABI) + +type CoordinatorConfigV2Plus struct { + MinConfs *int + MaxGasLimit *int64 + StalenessSeconds *int64 + GasAfterPayment *int64 + FallbackWeiPerUnitLink *big.Int + FeeConfig vrf_coordinator_v2_5.VRFCoordinatorV25FeeConfig +} + +func SmokeTestVRF(e helpers.Environment) { smokeCmd := flag.NewFlagSet("smoke", flag.ExitOnError) // required flags @@ -120,7 +97,7 @@ func smokeTestVRF(e helpers.Environment) { var bhsContractAddress common.Address if len(*bhsAddressStr) == 0 { fmt.Println("\nDeploying BHS...") - bhsContractAddress = deployBHS(e) + bhsContractAddress = DeployBHS(e) } else { bhsContractAddress = common.HexToAddress(*bhsAddressStr) } @@ -128,7 +105,7 @@ func smokeTestVRF(e helpers.Environment) { var batchBHSAddress common.Address if len(*batchBHSAddressStr) == 0 { fmt.Println("\nDeploying Batch BHS...") - batchBHSAddress = deployBatchBHS(e, bhsContractAddress) + batchBHSAddress = DeployBatchBHS(e, bhsContractAddress) } else { batchBHSAddress = common.HexToAddress(*batchBHSAddressStr) } @@ -136,7 +113,7 @@ func smokeTestVRF(e helpers.Environment) { var coordinatorAddress common.Address if len(*coordinatorAddressStr) == 0 { fmt.Println("\nDeploying Coordinator...") - coordinatorAddress = deployCoordinator(e, *linkAddress, bhsContractAddress.String(), *linkEthAddress) + coordinatorAddress = DeployCoordinator(e, *linkAddress, bhsContractAddress.String(), *linkEthAddress) } else { coordinatorAddress = common.HexToAddress(*coordinatorAddressStr) } @@ -147,14 +124,14 @@ func smokeTestVRF(e helpers.Environment) { var batchCoordinatorAddress common.Address if len(*batchCoordinatorAddressStr) == 0 { fmt.Println("\nDeploying Batch Coordinator...") - batchCoordinatorAddress = deployBatchCoordinatorV2(e, coordinatorAddress) + batchCoordinatorAddress = DeployBatchCoordinatorV2(e, coordinatorAddress) } else { batchCoordinatorAddress = common.HexToAddress(*batchCoordinatorAddressStr) } if !*skipConfig { fmt.Println("\nSetting Coordinator Config...") - setCoordinatorConfig( + SetCoordinatorConfig( e, *coordinator, uint16(*minConfs), @@ -170,7 +147,7 @@ func smokeTestVRF(e helpers.Environment) { } fmt.Println("\nConfig set, getting current config from deployed contract...") - printCoordinatorConfig(coordinator) + PrintCoordinatorConfig(coordinator) // Generate compressed public key and key hash uncompressed, err := key.PublicKey.StringUncompressed() @@ -250,20 +227,20 @@ func smokeTestVRF(e helpers.Environment) { } fmt.Println("\nDeploying consumer...") - consumerAddress := eoaDeployConsumer(e, coordinatorAddress.String(), *linkAddress) + consumerAddress := EoaDeployConsumer(e, coordinatorAddress.String(), *linkAddress) fmt.Println("\nAdding subscription...") - eoaCreateSub(e, *coordinator) + EoaCreateSub(e, *coordinator) - subID := findSubscriptionID(e, coordinator) + subID := FindSubscriptionID(e, coordinator) helpers.PanicErr(err) fmt.Println("\nAdding consumer to subscription...") - eoaAddConsumerToSub(e, *coordinator, subID, consumerAddress.String()) + EoaAddConsumerToSub(e, *coordinator, subID, consumerAddress.String()) if subscriptionBalance.Cmp(big.NewInt(0)) > 0 { fmt.Println("\nFunding subscription with", subscriptionBalance, "juels...") - eoaFundSubscription(e, *coordinator, *linkAddress, subscriptionBalance, subID) + EoaFundSubWithLink(e, *coordinator, *linkAddress, subscriptionBalance, subID) } else { fmt.Println("Subscription", subID, "NOT getting funded. You must fund the subscription in order to use it!") } @@ -378,7 +355,7 @@ func smokeTestVRF(e helpers.Environment) { fmt.Println("\nfulfillment successful") } -func smokeTestBHS(e helpers.Environment) { +func SmokeTestBHS(e helpers.Environment) { smokeCmd := flag.NewFlagSet("smoke-bhs", flag.ExitOnError) // optional args @@ -390,7 +367,7 @@ func smokeTestBHS(e helpers.Environment) { var bhsContractAddress common.Address if len(*bhsAddress) == 0 { fmt.Println("\nDeploying BHS...") - bhsContractAddress = deployBHS(e) + bhsContractAddress = DeployBHS(e) } else { bhsContractAddress = common.HexToAddress(*bhsAddress) } @@ -398,7 +375,7 @@ func smokeTestBHS(e helpers.Environment) { var batchBHSContractAddress common.Address if len(*batchBHSAddress) == 0 { fmt.Println("\nDeploying Batch BHS...") - batchBHSContractAddress = deployBatchBHS(e, bhsContractAddress) + batchBHSContractAddress = DeployBatchBHS(e, bhsContractAddress) } else { batchBHSContractAddress = common.HexToAddress(*batchBHSAddress) } @@ -486,117 +463,183 @@ func sendTx(e helpers.Environment, to common.Address, data []byte) (*types.Recei e.ChainID, "send tx", signedTx.Hash().String(), "to", to.String()), signedTx.Hash() } -func deployUniverse(e helpers.Environment) { +func DeployUniverseViaCLI(e helpers.Environment) { deployCmd := flag.NewFlagSet("deploy-universe", flag.ExitOnError) // required flags - linkAddress := deployCmd.String("link-address", "", "address of link token") - linkEthAddress := deployCmd.String("link-eth-feed", "", "address of link eth feed") - bhsAddress := deployCmd.String("bhs-address", "", "address of blockhash store") - batchBHSAddress := deployCmd.String("batch-bhs-address", "", "address of batch blockhash store") - subscriptionBalanceString := deployCmd.String("subscription-balance", "1e19", "amount to fund subscription") + linkAddress := *deployCmd.String("link-address", "", "address of link token") + linkEthAddress := *deployCmd.String("link-eth-feed", "", "address of link eth feed") + bhsContractAddressString := *deployCmd.String("bhs-address", "", "address of BHS contract") + batchBHSAddressString := *deployCmd.String("batch-bhs-address", "", "address of Batch BHS contract") + coordinatorAddressString := *deployCmd.String("coordinator-address", "", "address of VRF Coordinator contract") + batchCoordinatorAddressString := *deployCmd.String("batch-coordinator-address", "", "address Batch VRF Coordinator contract") + subscriptionBalanceJuelsString := deployCmd.String("subscription-balance", "1e19", "amount to fund subscription with Link token (Juels)") + subscriptionBalanceNativeWeiString := deployCmd.String("subscription-balance-native", "1e18", "amount to fund subscription with native token (Wei)") + + batchFulfillmentEnabled := deployCmd.Bool("batch-fulfillment-enabled", constants.BatchFulfillmentEnabled, "whether send randomness fulfillments in batches inside one tx from CL node") // optional flags fallbackWeiPerUnitLinkString := deployCmd.String("fallback-wei-per-unit-link", "6e16", "fallback wei/link ratio") registerKeyUncompressedPubKey := deployCmd.String("uncompressed-pub-key", "", "uncompressed public key") - registerKeyOracleAddress := deployCmd.String("oracle-address", "", "oracle sender address") - minConfs := deployCmd.Int("min-confs", 3, "min confs") - oracleFundingAmount := deployCmd.Int64("oracle-funding-amount", assets.GWei(100_000_000).Int64(), "amount to fund sending oracle") - maxGasLimit := deployCmd.Int64("max-gas-limit", 2.5e6, "max gas limit") - stalenessSeconds := deployCmd.Int64("staleness-seconds", 86400, "staleness in seconds") - gasAfterPayment := deployCmd.Int64("gas-after-payment", 33285, "gas after payment calculation") - flatFeeLinkPPM := deployCmd.Int64("flat-fee-link-ppm", 500, "fulfillment flat fee LINK ppm") - flatFeeEthPPM := deployCmd.Int64("flat-fee-eth-ppm", 500, "fulfillment flat fee ETH ppm") + vrfPrimaryNodeSendingKeysString := deployCmd.String("vrf-primary-node-sending-keys", "", "VRF Primary Node sending keys") + minConfs := deployCmd.Int("min-confs", constants.MinConfs, "min confs") + nodeSendingKeyFundingAmount := deployCmd.String("sending-key-funding-amount", constants.NodeSendingKeyFundingAmount, "CL node sending key funding amount") + maxGasLimit := deployCmd.Int64("max-gas-limit", constants.MaxGasLimit, "max gas limit") + stalenessSeconds := deployCmd.Int64("staleness-seconds", constants.StalenessSeconds, "staleness in seconds") + gasAfterPayment := deployCmd.Int64("gas-after-payment", constants.GasAfterPayment, "gas after payment calculation") + flatFeeLinkPPM := deployCmd.Int64("flat-fee-link-ppm", constants.FlatFeeLinkPPM, "fulfillment flat fee LINK ppm") + flatFeeEthPPM := deployCmd.Int64("flat-fee-eth-ppm", constants.FlatFeeNativePPM, "fulfillment flat fee ETH ppm") - helpers.ParseArgs(deployCmd, os.Args[2:]) + helpers.ParseArgs( + deployCmd, os.Args[2:], + ) fallbackWeiPerUnitLink := decimal.RequireFromString(*fallbackWeiPerUnitLinkString).BigInt() - subscriptionBalance := decimal.RequireFromString(*subscriptionBalanceString).BigInt() + subscriptionBalanceJuels := decimal.RequireFromString(*subscriptionBalanceJuelsString).BigInt() + subscriptionBalanceNativeWei := decimal.RequireFromString(*subscriptionBalanceNativeWeiString).BigInt() + fundingAmount := decimal.RequireFromString(*nodeSendingKeyFundingAmount).BigInt() + + feeConfig := vrf_coordinator_v2_5.VRFCoordinatorV25FeeConfig{ + FulfillmentFlatFeeLinkPPM: uint32(*flatFeeLinkPPM), + FulfillmentFlatFeeNativePPM: uint32(*flatFeeEthPPM), + } + vrfPrimaryNodeSendingKeys := strings.Split(*vrfPrimaryNodeSendingKeysString, ",") + + nodesMap := make(map[string]model.Node) + + nodesMap[model.VRFPrimaryNodeName] = model.Node{ + SendingKeys: util.MapToSendingKeyArr(vrfPrimaryNodeSendingKeys), + SendingKeyFundingAmount: fundingAmount, + } + + bhsContractAddress := common.HexToAddress(bhsContractAddressString) + batchBHSAddress := common.HexToAddress(batchBHSAddressString) + coordinatorAddress := common.HexToAddress(coordinatorAddressString) + batchCoordinatorAddress := common.HexToAddress(batchCoordinatorAddressString) + + contractAddresses := model.ContractAddresses{ + LinkAddress: linkAddress, + LinkEthAddress: linkEthAddress, + BhsContractAddress: bhsContractAddress, + BatchBHSAddress: batchBHSAddress, + CoordinatorAddress: coordinatorAddress, + BatchCoordinatorAddress: batchCoordinatorAddress, + } + + coordinatorConfig := CoordinatorConfigV2Plus{ + MinConfs: minConfs, + MaxGasLimit: maxGasLimit, + StalenessSeconds: stalenessSeconds, + GasAfterPayment: gasAfterPayment, + FallbackWeiPerUnitLink: fallbackWeiPerUnitLink, + FeeConfig: feeConfig, + } + + VRFV2PlusDeployUniverse( + e, + subscriptionBalanceJuels, + subscriptionBalanceNativeWei, + registerKeyUncompressedPubKey, + contractAddresses, + coordinatorConfig, + *batchFulfillmentEnabled, + nodesMap, + ) + + vrfPrimaryNode := nodesMap[model.VRFPrimaryNodeName] + fmt.Println("Funding node's sending keys...") + for _, sendingKey := range vrfPrimaryNode.SendingKeys { + helpers.FundNode(e, sendingKey.Address, vrfPrimaryNode.SendingKeyFundingAmount) + } +} + +func VRFV2PlusDeployUniverse(e helpers.Environment, + subscriptionBalanceJuels *big.Int, + subscriptionBalanceNativeWei *big.Int, + registerKeyUncompressedPubKey *string, + contractAddresses model.ContractAddresses, + coordinatorConfig CoordinatorConfigV2Plus, + batchFulfillmentEnabled bool, + nodesMap map[string]model.Node, +) model.JobSpecs { // Put key in ECDSA format if strings.HasPrefix(*registerKeyUncompressedPubKey, "0x") { *registerKeyUncompressedPubKey = strings.Replace(*registerKeyUncompressedPubKey, "0x", "04", 1) } - if len(*linkAddress) == 0 { + // Generate compressed public key and key hash + pubBytes, err := hex.DecodeString(*registerKeyUncompressedPubKey) + helpers.PanicErr(err) + pk, err := crypto.UnmarshalPubkey(pubBytes) + helpers.PanicErr(err) + var pkBytes []byte + if big.NewInt(0).Mod(pk.Y, big.NewInt(2)).Uint64() != 0 { + pkBytes = append(pk.X.Bytes(), 1) + } else { + pkBytes = append(pk.X.Bytes(), 0) + } + var newPK secp256k1.PublicKey + copy(newPK[:], pkBytes) + + compressedPkHex := hexutil.Encode(pkBytes) + keyHash, err := newPK.Hash() + helpers.PanicErr(err) + + if len(contractAddresses.LinkAddress) == 0 { fmt.Println("\nDeploying LINK Token...") - address := helpers.DeployLinkToken(e).String() - linkAddress = &address + contractAddresses.LinkAddress = helpers.DeployLinkToken(e).String() } - if len(*linkEthAddress) == 0 { + if len(contractAddresses.LinkEthAddress) == 0 { fmt.Println("\nDeploying LINK/ETH Feed...") - address := helpers.DeployLinkEthFeed(e, *linkAddress, fallbackWeiPerUnitLink).String() - linkEthAddress = &address + contractAddresses.LinkEthAddress = helpers.DeployLinkEthFeed(e, contractAddresses.LinkAddress, coordinatorConfig.FallbackWeiPerUnitLink).String() } - var bhsContractAddress common.Address - if len(*bhsAddress) == 0 { + if contractAddresses.BhsContractAddress.String() == "0x0000000000000000000000000000000000000000" { fmt.Println("\nDeploying BHS...") - bhsContractAddress = deployBHS(e) - } else { - bhsContractAddress = common.HexToAddress(*bhsAddress) + contractAddresses.BhsContractAddress = DeployBHS(e) } - var batchBHSContractAddress common.Address - if len(*batchBHSAddress) == 0 { + if contractAddresses.BatchBHSAddress.String() == "0x0000000000000000000000000000000000000000" { fmt.Println("\nDeploying Batch BHS...") - batchBHSContractAddress = deployBatchBHS(e, bhsContractAddress) - } else { - batchBHSContractAddress = common.HexToAddress(*batchBHSAddress) + contractAddresses.BatchBHSAddress = DeployBatchBHS(e, contractAddresses.BhsContractAddress) } - var coordinatorAddress common.Address - fmt.Println("\nDeploying Coordinator...") - coordinatorAddress = deployCoordinator(e, *linkAddress, bhsContractAddress.String(), *linkEthAddress) + if contractAddresses.CoordinatorAddress.String() == "0x0000000000000000000000000000000000000000" { + fmt.Println("\nDeploying Coordinator...") + contractAddresses.CoordinatorAddress = DeployCoordinator(e, contractAddresses.LinkAddress, contractAddresses.BhsContractAddress.String(), contractAddresses.LinkEthAddress) + } - coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(coordinatorAddress, e.Ec) + coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(contractAddresses.CoordinatorAddress, e.Ec) helpers.PanicErr(err) - fmt.Println("\nDeploying Batch Coordinator...") - batchCoordinatorAddress := deployBatchCoordinatorV2(e, coordinatorAddress) + if contractAddresses.BatchCoordinatorAddress.String() == "0x0000000000000000000000000000000000000000" { + fmt.Println("\nDeploying Batch Coordinator...") + contractAddresses.BatchCoordinatorAddress = DeployBatchCoordinatorV2(e, contractAddresses.CoordinatorAddress) + } fmt.Println("\nSetting Coordinator Config...") - setCoordinatorConfig( + SetCoordinatorConfig( e, *coordinator, - uint16(*minConfs), - uint32(*maxGasLimit), - uint32(*stalenessSeconds), - uint32(*gasAfterPayment), - fallbackWeiPerUnitLink, - vrf_coordinator_v2_5.VRFCoordinatorV25FeeConfig{ - FulfillmentFlatFeeLinkPPM: uint32(*flatFeeLinkPPM), - FulfillmentFlatFeeNativePPM: uint32(*flatFeeEthPPM), - }, + uint16(*coordinatorConfig.MinConfs), + uint32(*coordinatorConfig.MaxGasLimit), + uint32(*coordinatorConfig.StalenessSeconds), + uint32(*coordinatorConfig.GasAfterPayment), + coordinatorConfig.FallbackWeiPerUnitLink, + coordinatorConfig.FeeConfig, ) fmt.Println("\nConfig set, getting current config from deployed contract...") - printCoordinatorConfig(coordinator) - - var compressedPkHex string - var keyHash common.Hash - if len(*registerKeyUncompressedPubKey) > 0 && len(*registerKeyOracleAddress) > 0 { - // Generate compressed public key and key hash - pubBytes, err := hex.DecodeString(*registerKeyUncompressedPubKey) - helpers.PanicErr(err) - pk, err := crypto.UnmarshalPubkey(pubBytes) - helpers.PanicErr(err) - var pkBytes []byte - if big.NewInt(0).Mod(pk.Y, big.NewInt(2)).Uint64() != 0 { - pkBytes = append(pk.X.Bytes(), 1) - } else { - pkBytes = append(pk.X.Bytes(), 0) - } - var newPK secp256k1.PublicKey - copy(newPK[:], pkBytes) - - compressedPkHex = hexutil.Encode(pkBytes) - keyHash, err = newPK.Hash() - helpers.PanicErr(err) + PrintCoordinatorConfig(coordinator) + if len(*registerKeyUncompressedPubKey) > 0 { fmt.Println("\nRegistering proving key...") - registerCoordinatorProvingKey(e, *coordinator, *registerKeyUncompressedPubKey, *registerKeyOracleAddress) + + //NOTE - register proving key against EOA account, and not against Oracle's sending address in other to be able + // easily withdraw funds from Coordinator contract back to EOA account + RegisterCoordinatorProvingKey(e, *coordinator, *registerKeyUncompressedPubKey, e.Owner.From.String()) fmt.Println("\nProving key registered, getting proving key hashes from deployed contract...") _, _, provingKeyHashes, configErr := coordinator.GetRequestConfig(nil) @@ -607,22 +650,28 @@ func deployUniverse(e helpers.Environment) { } fmt.Println("\nDeploying consumer...") - consumerAddress := eoaDeployConsumer(e, coordinatorAddress.String(), *linkAddress) + consumerAddress := EoaV2PlusLoadTestConsumerWithMetricsDeploy(e, contractAddresses.CoordinatorAddress.String()) fmt.Println("\nAdding subscription...") - eoaCreateSub(e, *coordinator) + EoaCreateSub(e, *coordinator) - subID := findSubscriptionID(e, coordinator) + subID := FindSubscriptionID(e, coordinator) helpers.PanicErr(err) fmt.Println("\nAdding consumer to subscription...") - eoaAddConsumerToSub(e, *coordinator, subID, consumerAddress.String()) + EoaAddConsumerToSub(e, *coordinator, subID, consumerAddress.String()) - if subscriptionBalance.Cmp(big.NewInt(0)) > 0 { - fmt.Println("\nFunding subscription with", subscriptionBalance, "juels...") - eoaFundSubscription(e, *coordinator, *linkAddress, subscriptionBalance, subID) + if subscriptionBalanceJuels.Cmp(big.NewInt(0)) > 0 { + fmt.Println("\nFunding subscription with Link Token.", subscriptionBalanceJuels, "juels...") + EoaFundSubWithLink(e, *coordinator, contractAddresses.LinkAddress, subscriptionBalanceJuels, subID) } else { - fmt.Println("Subscription", subID, "NOT getting funded. You must fund the subscription in order to use it!") + fmt.Println("Subscription", subID, "NOT getting funded with Link Token. You must fund the subscription in order to use it!") + } + if subscriptionBalanceNativeWei.Cmp(big.NewInt(0)) > 0 { + fmt.Println("\nFunding subscription with Native Token.", subscriptionBalanceNativeWei, "wei...") + EoaFundSubWithNative(e, coordinator.Address(), subID, subscriptionBalanceNativeWei) + } else { + fmt.Println("Subscription", subID, "NOT getting funded with Native Token. You must fund the subscription in order to use it!") } fmt.Println("\nSubscribed and (possibly) funded, retrieving subscription from deployed contract...") @@ -630,45 +679,94 @@ func deployUniverse(e helpers.Environment) { helpers.PanicErr(err) fmt.Printf("Subscription %+v\n", s) - if len(*registerKeyOracleAddress) > 0 && *oracleFundingAmount > 0 { - fmt.Println("\nFunding oracle...") - helpers.FundNodes(e, []string{*registerKeyOracleAddress}, big.NewInt(*oracleFundingAmount)) - } - - formattedJobSpec := fmt.Sprintf( - formattedVRFJob, - coordinatorAddress, - batchCoordinatorAddress, - false, - compressedPkHex, - e.ChainID, - *registerKeyOracleAddress, - coordinatorAddress, - coordinatorAddress, - coordinatorAddress, + formattedVrfV2PlusPrimaryJobSpec := fmt.Sprintf( + jobs.VRFV2PlusJobFormatted, + contractAddresses.CoordinatorAddress, //coordinatorAddress + contractAddresses.BatchCoordinatorAddress, //batchCoordinatorAddress + batchFulfillmentEnabled, //batchFulfillmentEnabled + compressedPkHex, //publicKey + *coordinatorConfig.MinConfs, //minIncomingConfirmations + e.ChainID, //evmChainID + strings.Join(util.MapToAddressArr(nodesMap[model.VRFPrimaryNodeName].SendingKeys), "\",\""), //fromAddresses + contractAddresses.CoordinatorAddress, + nodesMap[model.VRFPrimaryNodeName].SendingKeys[0].Address, + contractAddresses.CoordinatorAddress, + contractAddresses.CoordinatorAddress, + ) + + formattedVrfV2PlusBackupJobSpec := fmt.Sprintf( + jobs.VRFV2PlusJobFormatted, + contractAddresses.CoordinatorAddress, //coordinatorAddress + contractAddresses.BatchCoordinatorAddress, //batchCoordinatorAddress + batchFulfillmentEnabled, //batchFulfillmentEnabled + compressedPkHex, //publicKey + 100, //minIncomingConfirmations + e.ChainID, //evmChainID + strings.Join(util.MapToAddressArr(nodesMap[model.VRFBackupNodeName].SendingKeys), "\",\""), //fromAddresses + contractAddresses.CoordinatorAddress, + nodesMap[model.VRFPrimaryNodeName].SendingKeys[0], + contractAddresses.CoordinatorAddress, + contractAddresses.CoordinatorAddress, + ) + + formattedBHSJobSpec := fmt.Sprintf( + jobs.BHSJobFormatted, + contractAddresses.CoordinatorAddress, //coordinatorAddress + 30, //waitBlocks + 200, //lookbackBlocks + contractAddresses.BhsContractAddress, //bhs address + e.ChainID, //chain id + strings.Join(util.MapToAddressArr(nodesMap[model.BHSNodeName].SendingKeys), "\",\""), //sending addresses + ) + + formattedBHSBackupJobSpec := fmt.Sprintf( + jobs.BHSJobFormatted, + contractAddresses.CoordinatorAddress, //coordinatorAddress + 100, //waitBlocks + 200, //lookbackBlocks + contractAddresses.BhsContractAddress, //bhs adreess + e.ChainID, //chain id + strings.Join(util.MapToAddressArr(nodesMap[model.BHSBackupNodeName].SendingKeys), "\",\""), //sending addresses + ) + + formattedBHFJobSpec := fmt.Sprintf( + jobs.BHFJobFormatted, + contractAddresses.CoordinatorAddress, //coordinatorAddress + contractAddresses.BhsContractAddress, //bhs adreess + contractAddresses.BatchBHSAddress, //batchBHS + e.ChainID, //chain id + strings.Join(util.MapToAddressArr(nodesMap[model.BHFNodeName].SendingKeys), "\",\""), //sending addresses ) fmt.Println( - "\n----------------------------", "\nDeployment complete.", - "\nLINK Token contract address:", *linkAddress, - "\nLINK/ETH Feed contract address:", *linkEthAddress, - "\nBlockhash Store contract address:", bhsContractAddress, - "\nBatch Blockhash Store contract address:", batchBHSContractAddress, - "\nVRF Coordinator Address:", coordinatorAddress, - "\nBatch VRF Coordinator Address:", batchCoordinatorAddress, + "\nLINK Token contract address:", contractAddresses.LinkAddress, + "\nLINK/ETH Feed contract address:", contractAddresses.LinkEthAddress, + "\nBlockhash Store contract address:", contractAddresses.BhsContractAddress, + "\nBatch Blockhash Store contract address:", contractAddresses.BatchBHSAddress, + "\nVRF Coordinator Address:", contractAddresses.CoordinatorAddress, + "\nBatch VRF Coordinator Address:", contractAddresses.BatchCoordinatorAddress, "\nVRF Consumer Address:", consumerAddress, "\nVRF Subscription Id:", subID, - "\nVRF Subscription Balance:", *subscriptionBalanceString, + "\nVRF Subscription Balance:", *subscriptionBalanceJuels, "\nPossible VRF Request command: ", - fmt.Sprintf("go run . eoa-request --consumer-address %s --sub-id %d --key-hash %s", consumerAddress, subID, keyHash), + 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: ", + fmt.Sprintf("go run . eoa-load-test-read-metrics --consumer-address=%s", consumerAddress), "\nA node can now be configured to run a VRF job with the below job spec :\n", - formattedJobSpec, - "\n----------------------------", + formattedVrfV2PlusPrimaryJobSpec, ) + + return model.JobSpecs{ + VRFPrimaryNode: formattedVrfV2PlusPrimaryJobSpec, + VRFBackupyNode: formattedVrfV2PlusBackupJobSpec, + BHSNode: formattedBHSJobSpec, + BHSBackupNode: formattedBHSBackupJobSpec, + BHFNode: formattedBHFJobSpec, + } } -func deployWrapperUniverse(e helpers.Environment) { +func DeployWrapperUniverse(e helpers.Environment) { cmd := flag.NewFlagSet("wrapper-universe-deploy", flag.ExitOnError) linkAddress := cmd.String("link-address", "", "address of link token") linkETHFeedAddress := cmd.String("link-eth-feed", "", "address of link-eth-feed") @@ -691,12 +789,12 @@ func deployWrapperUniverse(e helpers.Environment) { panic(fmt.Sprintf("failed to parse top up amount '%s'", *subFunding)) } - wrapper, subID := wrapperDeploy(e, + wrapper, subID := WrapperDeploy(e, common.HexToAddress(*linkAddress), common.HexToAddress(*linkETHFeedAddress), common.HexToAddress(*coordinatorAddress)) - wrapperConfigure(e, + WrapperConfigure(e, wrapper, *wrapperGasOverhead, *coordinatorGasOverhead, @@ -709,14 +807,14 @@ func deployWrapperUniverse(e helpers.Environment) { uint32(*fulfillmentFlatFeeNativePPM), ) - consumer := wrapperConsumerDeploy(e, + consumer := WrapperConsumerDeploy(e, common.HexToAddress(*linkAddress), wrapper) coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(common.HexToAddress(*coordinatorAddress), e.Ec) helpers.PanicErr(err) - eoaFundSubscription(e, *coordinator, *linkAddress, amount, subID) + EoaFundSubWithLink(e, *coordinator, *linkAddress, amount, subID) link, err := link_token_interface.NewLinkToken(common.HexToAddress(*linkAddress), e.Ec) helpers.PanicErr(err) diff --git a/core/scripts/vrfv2plus/testnet/util.go b/core/scripts/vrfv2plus/testnet/v2plusscripts/util.go similarity index 79% rename from core/scripts/vrfv2plus/testnet/util.go rename to core/scripts/vrfv2plus/testnet/v2plusscripts/util.go index 2aeb71bd598..ebe881a9951 100644 --- a/core/scripts/vrfv2plus/testnet/util.go +++ b/core/scripts/vrfv2plus/testnet/v2plusscripts/util.go @@ -1,9 +1,10 @@ -package main +package v2plusscripts import ( "context" "encoding/hex" "fmt" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_v2plus_load_test_with_metrics" "math/big" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -22,19 +23,19 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/utils" ) -func deployBHS(e helpers.Environment) (blockhashStoreAddress common.Address) { +func DeployBHS(e helpers.Environment) (blockhashStoreAddress common.Address) { _, tx, _, err := blockhash_store.DeployBlockhashStore(e.Owner, e.Ec) helpers.PanicErr(err) return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) } -func deployBatchBHS(e helpers.Environment, bhsAddress common.Address) (batchBHSAddress common.Address) { +func DeployBatchBHS(e helpers.Environment, bhsAddress common.Address) (batchBHSAddress common.Address) { _, tx, _, err := batch_blockhash_store.DeployBatchBlockhashStore(e.Owner, e.Ec, bhsAddress) helpers.PanicErr(err) return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) } -func deployCoordinator( +func DeployCoordinator( e helpers.Environment, linkAddress string, bhsAddress string, @@ -58,27 +59,31 @@ func deployCoordinator( return coordinatorAddress } -func deployBatchCoordinatorV2(e helpers.Environment, coordinatorAddress common.Address) (batchCoordinatorAddress common.Address) { +func DeployBatchCoordinatorV2(e helpers.Environment, coordinatorAddress common.Address) (batchCoordinatorAddress common.Address) { _, tx, _, err := batch_vrf_coordinator_v2plus.DeployBatchVRFCoordinatorV2Plus(e.Owner, e.Ec, coordinatorAddress) helpers.PanicErr(err) return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) } -func eoaAddConsumerToSub(e helpers.Environment, - coordinator vrf_coordinator_v2_5.VRFCoordinatorV25, subID *big.Int, consumerAddress string) { +func EoaAddConsumerToSub( + e helpers.Environment, + coordinator vrf_coordinator_v2_5.VRFCoordinatorV25, + subID *big.Int, + consumerAddress string, +) { txadd, err := coordinator.AddConsumer(e.Owner, subID, common.HexToAddress(consumerAddress)) helpers.PanicErr(err) helpers.ConfirmTXMined(context.Background(), e.Ec, txadd, e.ChainID) } -func eoaCreateSub(e helpers.Environment, coordinator vrf_coordinator_v2_5.VRFCoordinatorV25) { +func EoaCreateSub(e helpers.Environment, coordinator vrf_coordinator_v2_5.VRFCoordinatorV25) { tx, err := coordinator.CreateSubscription(e.Owner) helpers.PanicErr(err) helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) } // returns subscription ID that belongs to the given owner. Returns result found first -func findSubscriptionID(e helpers.Environment, coordinator *vrf_coordinator_v2_5.VRFCoordinatorV25) *big.Int { +func FindSubscriptionID(e helpers.Environment, coordinator *vrf_coordinator_v2_5.VRFCoordinatorV25) *big.Int { // Use most recent 500 blocks as search window. head, err := e.Ec.BlockNumber(context.Background()) helpers.PanicErr(err) @@ -95,7 +100,7 @@ func findSubscriptionID(e helpers.Environment, coordinator *vrf_coordinator_v2_5 return subscriptionIterator.Event.SubId } -func eoaDeployConsumer(e helpers.Environment, +func EoaDeployConsumer(e helpers.Environment, coordinatorAddress string, linkAddress string) ( consumerAddress common.Address) { @@ -108,13 +113,17 @@ func eoaDeployConsumer(e helpers.Environment, return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) } -func eoaFundSubscription(e helpers.Environment, - coordinator vrf_coordinator_v2_5.VRFCoordinatorV25, linkAddress string, amount, subID *big.Int) { +func EoaFundSubWithLink( + e helpers.Environment, + coordinator vrf_coordinator_v2_5.VRFCoordinatorV25, + linkAddress string, amount, + subID *big.Int, +) { linkToken, err := link_token_interface.NewLinkToken(common.HexToAddress(linkAddress), e.Ec) helpers.PanicErr(err) bal, err := linkToken.BalanceOf(nil, e.Owner.From) helpers.PanicErr(err) - fmt.Println("Initial account balance:", bal, e.Owner.From.String(), "Funding amount:", amount.String()) + fmt.Println("Initial account balance (Juels):", bal, e.Owner.From.String(), "Funding amount:", amount.String()) b, err := utils.ABIEncode(`[{"type":"uint256"}]`, subID) helpers.PanicErr(err) tx, err := linkToken.TransferAndCall(e.Owner, coordinator.Address(), amount, b) @@ -122,7 +131,16 @@ func eoaFundSubscription(e helpers.Environment, helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID, fmt.Sprintf("sub ID: %d", subID)) } -func printCoordinatorConfig(coordinator *vrf_coordinator_v2_5.VRFCoordinatorV25) { +func EoaFundSubWithNative(e helpers.Environment, coordinatorAddress common.Address, subID *big.Int, amount *big.Int) { + coordinator, err := vrf_coordinator_v2_5.NewVRFCoordinatorV25(coordinatorAddress, e.Ec) + helpers.PanicErr(err) + e.Owner.Value = amount + tx, err := coordinator.FundSubscriptionWithNative(e.Owner, subID) + helpers.PanicErr(err) + helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) +} + +func PrintCoordinatorConfig(coordinator *vrf_coordinator_v2_5.VRFCoordinatorV25) { cfg, err := coordinator.SConfig(nil) helpers.PanicErr(err) @@ -133,7 +151,7 @@ func printCoordinatorConfig(coordinator *vrf_coordinator_v2_5.VRFCoordinatorV25) fmt.Printf("Coordinator fee config: %+v\n", feeConfig) } -func setCoordinatorConfig( +func SetCoordinatorConfig( e helpers.Environment, coordinator vrf_coordinator_v2_5.VRFCoordinatorV25, minConfs uint16, @@ -156,7 +174,7 @@ func setCoordinatorConfig( helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) } -func registerCoordinatorProvingKey(e helpers.Environment, +func RegisterCoordinatorProvingKey(e helpers.Environment, coordinator vrf_coordinator_v2_5.VRFCoordinatorV25, uncompressed string, oracleAddress string) { pubBytes, err := hex.DecodeString(uncompressed) helpers.PanicErr(err) @@ -176,7 +194,7 @@ func registerCoordinatorProvingKey(e helpers.Environment, ) } -func wrapperDeploy( +func WrapperDeploy( e helpers.Environment, link, linkEthFeed, coordinator common.Address, ) (common.Address, *big.Int) { @@ -199,7 +217,7 @@ func wrapperDeploy( return address, subID } -func wrapperConfigure( +func WrapperConfigure( e helpers.Environment, wrapperAddress common.Address, wrapperGasOverhead, coordinatorGasOverhead, premiumPercentage uint, @@ -230,7 +248,7 @@ func wrapperConfigure( helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID) } -func wrapperConsumerDeploy( +func WrapperConsumerDeploy( e helpers.Environment, link, wrapper common.Address, ) common.Address { @@ -243,3 +261,13 @@ func wrapperConsumerDeploy( fmt.Printf("VRFV2WrapperConsumerExample address: %s\n", address) return address } + +func EoaV2PlusLoadTestConsumerWithMetricsDeploy(e helpers.Environment, consumerCoordinator string) (consumerAddress common.Address) { + _, tx, _, err := vrf_v2plus_load_test_with_metrics.DeployVRFV2PlusLoadTestWithMetrics( + e.Owner, + e.Ec, + common.HexToAddress(consumerCoordinator), + ) + helpers.PanicErr(err) + return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) +} From a4154c752af09eb02df961ffdac6b5bec1434fa3 Mon Sep 17 00:00:00 2001 From: george-dorin <120329946+george-dorin@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:28:52 +0300 Subject: [PATCH 2/9] Set aliveLoopSub (#10893) --- core/chains/evm/client/node_lifecycle.go | 1 + 1 file changed, 1 insertion(+) diff --git a/core/chains/evm/client/node_lifecycle.go b/core/chains/evm/client/node_lifecycle.go index d55df58d6ef..609d1522ea5 100644 --- a/core/chains/evm/client/node_lifecycle.go +++ b/core/chains/evm/client/node_lifecycle.go @@ -97,6 +97,7 @@ func (n *node) aliveLoop() { n.declareUnreachable() return } + n.aliveLoopSub = sub defer sub.Unsubscribe() var outOfSyncT *time.Ticker From 743ee499821a8238bc5b7212b2b31979162a1d6b Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Tue, 10 Oct 2023 07:29:55 -0500 Subject: [PATCH 3/9] shadow: declaration of X shadows declaration at line 913 (govet) (#10890) --- core/chains/evm/txmgr/confirmer_test.go | 155 ++++++++++-------------- core/cmd/admin_commands.go | 5 +- core/cmd/ocr2vrf_configure_commands.go | 93 ++++++++------ core/cmd/shell_local.go | 3 +- core/internal/cltest/cltest.go | 10 +- 5 files changed, 126 insertions(+), 140 deletions(-) diff --git a/core/chains/evm/txmgr/confirmer_test.go b/core/chains/evm/txmgr/confirmer_test.go index e0070e35b17..6a1c50d1949 100644 --- a/core/chains/evm/txmgr/confirmer_test.go +++ b/core/chains/evm/txmgr/confirmer_test.go @@ -187,8 +187,7 @@ func TestEthConfirmer_CheckForReceipts(t *testing.T) { _, fromAddress := cltest.MustAddRandomKeyToKeystore(t, ethKeyStore) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) - require.NoError(t, err) + ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) nonce := int64(0) ctx := testutils.Context(t) @@ -605,9 +604,7 @@ func TestEthConfirmer_CheckForReceipts_batching(t *testing.T) { evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) - require.NoError(t, err) - + ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) etx := cltest.MustInsertUnconfirmedEthTx(t, txStore, 0, fromAddress) @@ -667,8 +664,7 @@ func TestEthConfirmer_CheckForReceipts_HandlesNonFwdTxsWithForwardingEnabled(t * evmcfg := evmtest.NewChainScopedConfig(t, cfg) _, fromAddress := cltest.MustInsertRandomKeyReturningState(t, ethKeyStore, 0) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) - require.NoError(t, err) + ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) // tx is not forwarded and doesn't have meta set. EthConfirmer should handle nil meta values etx := cltest.MustInsertUnconfirmedEthTx(t, txStore, 0, fromAddress) @@ -721,9 +717,7 @@ func TestEthConfirmer_CheckForReceipts_only_likely_confirmed(t *testing.T) { evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) - require.NoError(t, err) - + ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) var attempts []txmgr.TxAttempt @@ -777,9 +771,7 @@ func TestEthConfirmer_CheckForReceipts_should_not_check_for_likely_unconfirmed(t ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) - require.NoError(t, err) - + ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) ctx := testutils.Context(t) etx := cltest.MustInsertUnconfirmedEthTx(t, txStore, 1, fromAddress) @@ -811,8 +803,7 @@ func TestEthConfirmer_CheckForReceipts_confirmed_missing_receipt_scoped_to_key(t ethClient.On("SequenceAt", mock.Anything, mock.Anything, mock.Anything).Return(evmtypes.Nonce(20), nil) evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) - require.NoError(t, err) + ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) // STATE @@ -879,9 +870,7 @@ func TestEthConfirmer_CheckForReceipts_confirmed_missing_receipt(t *testing.T) { evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) - require.NoError(t, err) - + ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) // STATE @@ -961,7 +950,8 @@ func TestEthConfirmer_CheckForReceipts_confirmed_missing_receipt(t *testing.T) { // Expected state is that the "top" eth_tx is now confirmed, with the // two below it "confirmed_missing_receipt" and the "bottom" eth_tx also confirmed - etx3, err := txStore.FindTxWithAttempts(etx3.ID) + var err error + etx3, err = txStore.FindTxWithAttempts(etx3.ID) require.NoError(t, err) require.Equal(t, txmgrcommon.TxConfirmed, etx3.State) @@ -1021,7 +1011,8 @@ func TestEthConfirmer_CheckForReceipts_confirmed_missing_receipt(t *testing.T) { // Expected state is that the "top" two eth_txes are now confirmed, with the // one below it still "confirmed_missing_receipt" and the bottom one remains confirmed - etx3, err := txStore.FindTxWithAttempts(etx3.ID) + var err error + etx3, err = txStore.FindTxWithAttempts(etx3.ID) require.NoError(t, err) require.Equal(t, txmgrcommon.TxConfirmed, etx3.State) etx2, err = txStore.FindTxWithAttempts(etx2.ID) @@ -1065,7 +1056,8 @@ func TestEthConfirmer_CheckForReceipts_confirmed_missing_receipt(t *testing.T) { // Expected state is that the "top" two eth_txes are now confirmed, with the // one below it still "confirmed_missing_receipt" and the bottom one remains confirmed - etx3, err := txStore.FindTxWithAttempts(etx3.ID) + var err error + etx3, err = txStore.FindTxWithAttempts(etx3.ID) require.NoError(t, err) require.Equal(t, txmgrcommon.TxConfirmed, etx3.State) etx2, err = txStore.FindTxWithAttempts(etx2.ID) @@ -1105,7 +1097,8 @@ func TestEthConfirmer_CheckForReceipts_confirmed_missing_receipt(t *testing.T) { // Expected state is that the "top" two eth_txes are now confirmed, with the // one below it marked as "fatal_error" and the bottom one remains confirmed - etx3, err := txStore.FindTxWithAttempts(etx3.ID) + var err error + etx3, err = txStore.FindTxWithAttempts(etx3.ID) require.NoError(t, err) require.Equal(t, txmgrcommon.TxConfirmed, etx3.State) etx2, err = txStore.FindTxWithAttempts(etx2.ID) @@ -1137,9 +1130,7 @@ func TestEthConfirmer_CheckConfirmedMissingReceipt(t *testing.T) { evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) - require.NoError(t, err) - + ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) // STATE @@ -1182,6 +1173,7 @@ func TestEthConfirmer_CheckConfirmedMissingReceipt(t *testing.T) { // Expected state is that the "top" eth_tx is untouched but the other two // are marked as unconfirmed + var err error etx0, err = txStore.FindTxWithAttempts(etx0.ID) assert.NoError(t, err) assert.Equal(t, txmgrcommon.TxConfirmedMissingReceipt, etx0.State) @@ -1217,9 +1209,7 @@ func TestEthConfirmer_CheckConfirmedMissingReceipt_batchSendTransactions_fails(t evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) - require.NoError(t, err) - + ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) // STATE @@ -1250,6 +1240,7 @@ func TestEthConfirmer_CheckConfirmedMissingReceipt_batchSendTransactions_fails(t require.NoError(t, ec.CheckConfirmedMissingReceipt(ctx)) // Expected state is that all txes are marked as unconfirmed, since the batch call had failed + var err error etx0, err = txStore.FindTxWithAttempts(etx0.ID) assert.NoError(t, err) assert.Equal(t, txmgrcommon.TxUnconfirmed, etx0.State) @@ -1282,9 +1273,7 @@ func TestEthConfirmer_CheckConfirmedMissingReceipt_smallEvmRPCBatchSize_middleBa evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) - require.NoError(t, err) - + ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) ctx := testutils.Context(t) // STATE @@ -1321,6 +1310,7 @@ func TestEthConfirmer_CheckConfirmedMissingReceipt_smallEvmRPCBatchSize_middleBa require.NoError(t, ec.CheckConfirmedMissingReceipt(ctx)) // Expected state is that all transactions since failed batch will be unconfirmed + var err error etx0, err = txStore.FindTxWithAttempts(etx0.ID) assert.NoError(t, err) assert.Equal(t, txmgrcommon.TxConfirmedMissingReceipt, etx0.State) @@ -1365,8 +1355,7 @@ func TestEthConfirmer_FindTxsRequiringRebroadcast(t *testing.T) { lggr := logger.TestLogger(t) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) - require.NoError(t, err) + ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) t.Run("returns nothing when there are no transactions", func(t *testing.T) { etxs, err := ec.FindTxsRequiringRebroadcast(testutils.Context(t), lggr, evmFromAddress, currentHead, gasBumpThreshold, 10, 0, &cltest.FixtureChainID) @@ -1747,8 +1736,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { addresses := []gethCommon.Address{fromAddress} kst.On("EnabledAddressesForChain", &cltest.FixtureChainID).Return(addresses, nil).Maybe() // Use a mock keystore for this test - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) - require.NoError(t, err) + ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) currentHead := int64(30) oldEnough := int64(19) nonce := int64(0) @@ -1773,7 +1761,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { mock.Anything).Return(nil, errors.New("signing error")).Once() // Do the thing - err = ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead) + err := ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead) require.Error(t, err) require.Contains(t, err.Error(), "signing error") @@ -1804,7 +1792,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { // Do the thing require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) - + var err error etx, err = txStore.FindTxWithAttempts(etx.ID) require.NoError(t, err) @@ -1836,7 +1824,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { // Do the thing require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) - + var err error etx, err = txStore.FindTxWithAttempts(etx.ID) require.NoError(t, err) @@ -1875,7 +1863,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { // Do the thing require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) - + var err error etx, err = txStore.FindTxWithAttempts(etx.ID) require.NoError(t, err) @@ -1891,7 +1879,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { t.Run("does nothing if there is an attempt without BroadcastBeforeBlockNum set", func(t *testing.T) { // Do the thing require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) - + var err error etx, err = txStore.FindTxWithAttempts(etx.ID) require.NoError(t, err) @@ -1921,7 +1909,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { // Do the thing require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) - + var err error etx, err = txStore.FindTxWithAttempts(etx.ID) require.NoError(t, err) @@ -1961,7 +1949,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { // Do the thing require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) - + var err error etx, err = txStore.FindTxWithAttempts(etx.ID) require.NoError(t, err) @@ -2012,7 +2000,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { }), fromAddress).Return(clienttypes.Unknown, errors.New("some network error")).Once() // Do the thing - err = ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead) + err := ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead) require.Error(t, err) require.Contains(t, err.Error(), "some network error") @@ -2080,6 +2068,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { // Creates new attempt as normal if currentHead is not high enough require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) + var err error etx2, err = txStore.FindTxWithAttempts(etx2.ID) require.NoError(t, err) assert.Equal(t, txmgrcommon.TxConfirmedMissingReceipt, etx2.State) @@ -2120,7 +2109,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { // Do the thing require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) - + var err error etx3, err = txStore.FindTxWithAttempts(etx3.ID) require.NoError(t, err) @@ -2157,7 +2146,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { // Do the thing require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) - + var err error etx3, err = txStore.FindTxWithAttempts(etx3.ID) require.NoError(t, err) @@ -2196,7 +2185,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { // Do the thing require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) - + var err error etx3, err = txStore.FindTxWithAttempts(etx3.ID) require.NoError(t, err) @@ -2217,8 +2206,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { c.EVM[0].GasEstimator.PriceMax = assets.NewWeiI(60500000000) }) newCfg := evmtest.NewChainScopedConfig(t, gcfg) - ec2, err := cltest.NewEthConfirmer(t, txStore, ethClient, newCfg, ethKeyStore, nil) - require.NoError(t, err) + ec2 := cltest.NewEthConfirmer(t, txStore, ethClient, newCfg, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return evmtypes.Nonce(tx.Nonce()) == *etx3.Sequence && gasPrice.Cmp(tx.GasPrice()) == 0 @@ -2226,7 +2214,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { // Do the thing require.NoError(t, ec2.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) - + var err error etx3, err = txStore.FindTxWithAttempts(etx3.ID) require.NoError(t, err) @@ -2248,8 +2236,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { c.EVM[0].GasEstimator.PriceMax = assets.NewWeiI(60480000000) }) newCfg := evmtest.NewChainScopedConfig(t, gcfg) - ec2, err := cltest.NewEthConfirmer(t, txStore, ethClient, newCfg, ethKeyStore, nil) - require.NoError(t, err) + ec2 := cltest.NewEthConfirmer(t, txStore, ethClient, newCfg, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return evmtypes.Nonce(tx.Nonce()) == *etx3.Sequence && gasPrice.Cmp(tx.GasPrice()) == 0 @@ -2257,7 +2244,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { // Do the thing require.NoError(t, ec2.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) - + var err error etx3, err = txStore.FindTxWithAttempts(etx3.ID) require.NoError(t, err) @@ -2294,7 +2281,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { return evmtypes.Nonce(tx.Nonce()) == *etx4.Sequence && gasTipCap.ToInt().Cmp(tx.GasTipCap()) == 0 }), fromAddress).Return(clienttypes.Successful, nil).Once() require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) - + var err error etx4, err = txStore.FindTxWithAttempts(etx4.ID) require.NoError(t, err) @@ -2317,8 +2304,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { c.EVM[0].GasEstimator.PriceMax = assets.GWei(1000) }) newCfg := evmtest.NewChainScopedConfig(t, gcfg) - ec2, err := cltest.NewEthConfirmer(t, txStore, ethClient, newCfg, ethKeyStore, nil) - require.NoError(t, err) + ec2 := cltest.NewEthConfirmer(t, txStore, ethClient, newCfg, ethKeyStore, nil) // Third attempt failed to bump, resubmits old one instead ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { @@ -2326,7 +2312,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { }), fromAddress).Return(clienttypes.Successful, nil).Once() require.NoError(t, ec2.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) - + var err error etx4, err = txStore.FindTxWithAttempts(etx4.ID) require.NoError(t, err) @@ -2364,7 +2350,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary(t *testing.T) { // Do it require.NoError(t, ec.RebroadcastWhereNecessary(testutils.Context(t), currentHead)) - + var err error etx4, err = txStore.FindTxWithAttempts(etx4.ID) require.NoError(t, err) @@ -2405,8 +2391,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_TerminallyUnderpriced_ThenGoesTh t.Run("terminally underpriced transaction with in_progress attempt is retried with more gas", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) - require.NoError(t, err) + ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) originalBroadcastAt := time.Unix(1616509100, 0) etx := cltest.MustInsertUnconfirmedEthTxWithAttemptState(t, txStore, nonce, fromAddress, txmgrtypes.TxAttemptInProgress, originalBroadcastAt) @@ -2432,8 +2417,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_TerminallyUnderpriced_ThenGoesTh t.Run("multiple gas bumps with existing broadcast attempts are retried with more gas until success in legacy mode", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) - require.NoError(t, err) + ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) etx := cltest.MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t, txStore, nonce, fromAddress) nonce++ @@ -2465,8 +2449,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_TerminallyUnderpriced_ThenGoesTh t.Run("multiple gas bumps with existing broadcast attempts are retried with more gas until success in EIP-1559 mode", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) - require.NoError(t, err) + ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, kst, nil) etx := cltest.MustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt(t, txStore, nonce, fromAddress) nonce++ @@ -2531,8 +2514,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WhenOutOfEth(t *testing.T) { insufficientEthError := errors.New("insufficient funds for gas * price + value") t.Run("saves attempt with state 'insufficient_eth' if eth node returns this error", func(t *testing.T) { - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) - require.NoError(t, err) + ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) expectedBumpedGasPrice := big.NewInt(20000000000) require.Greater(t, expectedBumpedGasPrice.Int64(), attempt1_1.TxFee.Legacy.ToInt().Int64()) @@ -2558,8 +2540,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WhenOutOfEth(t *testing.T) { }) t.Run("does not bump gas when previous error was 'out of eth', instead resubmits existing transaction", func(t *testing.T) { - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) - require.NoError(t, err) + ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) expectedBumpedGasPrice := big.NewInt(20000000000) require.Greater(t, expectedBumpedGasPrice.Int64(), attempt1_1.TxFee.Legacy.ToInt().Int64()) @@ -2584,8 +2565,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WhenOutOfEth(t *testing.T) { }) t.Run("saves the attempt as broadcast after node wallet has been topped up with sufficient balance", func(t *testing.T) { - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) - require.NoError(t, err) + ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) expectedBumpedGasPrice := big.NewInt(20000000000) require.Greater(t, expectedBumpedGasPrice.Int64(), attempt1_1.TxFee.Legacy.ToInt().Int64()) @@ -2617,8 +2597,7 @@ func TestEthConfirmer_RebroadcastWhereNecessary_WhenOutOfEth(t *testing.T) { c.EVM[0].GasEstimator.BumpTxDepth = ptr(uint32(depth)) }) evmcfg := evmtest.NewChainScopedConfig(t, cfg) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) - require.NoError(t, err) + ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, nil) for i := 0; i < etxCount; i++ { n := nonce @@ -2653,8 +2632,7 @@ func TestEthConfirmer_EnsureConfirmedTransactionsInLongestChain(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) config := newTestChainScopedConfig(t) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) - require.NoError(t, err) + ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) head := evmtypes.Head{ Hash: utils.NewHash(), @@ -2835,8 +2813,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { t.Run("rebroadcasts one eth_tx if it falls within in nonce range", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) - require.NoError(t, err) + ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return tx.Nonce() == uint64(*etx1.Sequence) && @@ -2851,8 +2828,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { t.Run("uses default gas limit if overrideGasLimit is 0", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) - require.NoError(t, err) + ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return tx.Nonce() == uint64(*etx1.Sequence) && @@ -2867,8 +2843,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { t.Run("rebroadcasts several eth_txes in nonce range", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) - require.NoError(t, err) + ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return tx.Nonce() == uint64(*etx1.Sequence) && tx.GasPrice().Int64() == gasPriceWei.Legacy.Int64() && tx.Gas() == uint64(overrideGasLimit) @@ -2882,8 +2857,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { t.Run("broadcasts zero transactions if eth_tx doesn't exist for that nonce", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) - require.NoError(t, err) + ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return tx.Nonce() == uint64(1) @@ -2909,8 +2883,7 @@ func TestEthConfirmer_ForceRebroadcast(t *testing.T) { t.Run("zero transactions use default gas limit if override wasn't specified", func(t *testing.T) { ethClient := evmtest.NewEthClientMockWithDefaultChain(t) - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) - require.NoError(t, err) + ec := cltest.NewEthConfirmer(t, txStore, ethClient, config, ethKeyStore, nil) ethClient.On("SendTransactionReturnCode", mock.Anything, mock.MatchedBy(func(tx *types.Transaction) bool { return tx.Nonce() == uint64(0) && tx.GasPrice().Int64() == gasPriceWei.Legacy.Int64() && uint32(tx.Gas()) == config.EVM().GasEstimator().LimitDefault() @@ -2954,11 +2927,10 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { pgtest.MustExec(t, db, `SET CONSTRAINTS pipeline_runs_pipeline_spec_id_fkey DEFERRED`) t.Run("doesn't process task runs that are not suspended (possibly already previously resumed)", func(t *testing.T) { - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(uuid.UUID, interface{}, error) error { + ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(uuid.UUID, interface{}, error) error { t.Fatal("No value expected") return nil }) - require.NoError(t, err) run := cltest.MustInsertPipelineRun(t, db) tr := cltest.MustInsertUnfinishedPipelineTaskRun(t, db, run.ID) @@ -2967,17 +2939,16 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { cltest.MustInsertEthReceipt(t, txStore, head.Number-minConfirmations, head.Hash, etx.TxAttempts[0].Hash) pgtest.MustExec(t, db, `UPDATE evm.txes SET pipeline_task_run_id = $1, min_confirmations = $2 WHERE id = $3`, &tr.ID, minConfirmations, etx.ID) - err = ec.ResumePendingTaskRuns(testutils.Context(t), &head) + err := ec.ResumePendingTaskRuns(testutils.Context(t), &head) require.NoError(t, err) }) t.Run("doesn't process task runs where the receipt is younger than minConfirmations", func(t *testing.T) { - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(uuid.UUID, interface{}, error) error { + ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(uuid.UUID, interface{}, error) error { t.Fatal("No value expected") return nil }) - require.NoError(t, err) run := cltest.MustInsertPipelineRun(t, db) tr := cltest.MustInsertUnfinishedPipelineTaskRun(t, db, run.ID) @@ -2987,7 +2958,7 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { pgtest.MustExec(t, db, `UPDATE evm.txes SET pipeline_task_run_id = $1, min_confirmations = $2 WHERE id = $3`, &tr.ID, minConfirmations, etx.ID) - err = ec.ResumePendingTaskRuns(testutils.Context(t), &head) + err := ec.ResumePendingTaskRuns(testutils.Context(t), &head) require.NoError(t, err) }) @@ -2995,12 +2966,11 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { t.Run("processes eth_txes with receipts older than minConfirmations", func(t *testing.T) { ch := make(chan interface{}) var err error - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(id uuid.UUID, value interface{}, thisErr error) error { + ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(id uuid.UUID, value interface{}, thisErr error) error { err = thisErr ch <- value return nil }) - require.NoError(t, err) run := cltest.MustInsertPipelineRun(t, db) tr := cltest.MustInsertUnfinishedPipelineTaskRun(t, db, run.ID) @@ -3035,12 +3005,11 @@ func TestEthConfirmer_ResumePendingRuns(t *testing.T) { t.Run("processes eth_txes with receipt older than minConfirmations that reverted", func(t *testing.T) { ch := make(chan interface{}) var err error - ec, err := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(id uuid.UUID, value interface{}, thisErr error) error { + ec := cltest.NewEthConfirmer(t, txStore, ethClient, evmcfg, ethKeyStore, func(id uuid.UUID, value interface{}, thisErr error) error { err = thisErr ch <- value return nil }) - require.NoError(t, err) run := cltest.MustInsertPipelineRun(t, db) tr := cltest.MustInsertUnfinishedPipelineTaskRun(t, db, run.ID) diff --git a/core/cmd/admin_commands.go b/core/cmd/admin_commands.go index 6ff7a5f6312..5daf5b4b1e6 100644 --- a/core/cmd/admin_commands.go +++ b/core/cmd/admin_commands.go @@ -204,7 +204,7 @@ func (s *Shell) CreateUser(c *cli.Context) (err error) { }() var links jsonapi.Links var users AdminUsersPresenters - if err := s.deserializeAPIResponse(resp, &users, &links); err != nil { + if err = s.deserializeAPIResponse(resp, &users, &links); err != nil { return s.errorOut(err) } for _, user := range users { @@ -316,8 +316,7 @@ func (s *Shell) Profile(c *cli.Context) error { genDir := filepath.Join(baseDir, fmt.Sprintf("debuginfo-%s", time.Now().Format(time.RFC3339))) - err := os.Mkdir(genDir, 0o755) - if err != nil { + if err := os.Mkdir(genDir, 0o755); err != nil { return s.errorOut(err) } var wgPprof sync.WaitGroup diff --git a/core/cmd/ocr2vrf_configure_commands.go b/core/cmd/ocr2vrf_configure_commands.go index 01bfd89c32b..c218485c96a 100644 --- a/core/cmd/ocr2vrf_configure_commands.go +++ b/core/cmd/ocr2vrf_configure_commands.go @@ -14,6 +14,8 @@ import ( "github.com/pkg/errors" "github.com/urfave/cli" + "github.com/smartcontractkit/sqlx" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/forwarders" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/authorized_forwarder" "github.com/smartcontractkit/chainlink/v2/core/logger" @@ -202,47 +204,12 @@ func (s *Shell) ConfigureOCR2VRFNode(c *cli.Context, owner *bind.TransactOpts, e } if useForwarder { - // Replace the transmitter ID with the forwarder address. - forwarderAddress := c.String("forwarder-address") - - ks := app.GetKeyStore().Eth() - // Add extra sending keys if using a forwarder. - for i := 0; i < forwarderAdditionalEOACount; i++ { - - // Create the sending key in the keystore. - k, err := ks.Create() - if err != nil { - return nil, err - } - - // Enable the sending key for the current chain. - err = ks.Enable(k.Address, big.NewInt(chainID)) - if err != nil { - return nil, err - } - - sendingKeys = append(sendingKeys, k.Address.String()) - sendingKeysAddresses = append(sendingKeysAddresses, k.Address) - } - - // We have to set the authorized senders on-chain here, otherwise the job spawner will fail as the - // forwarder will not be recognized. - ctx, cancel := context.WithTimeout(context.Background(), 300*time.Second) - defer cancel() - f, err := authorized_forwarder.NewAuthorizedForwarder(common.HexToAddress(forwarderAddress), ec) - tx, err := f.SetAuthorizedSenders(owner, sendingKeysAddresses) + sendingKeys, sendingKeysAddresses, err = s.appendForwarders(chainID, app.GetKeyStore().Eth(), sendingKeys, sendingKeysAddresses) if err != nil { return nil, err } - _, err = bind.WaitMined(ctx, ec, tx) - if err != nil { - return nil, err - } - - // Create forwarder for management in forwarder_manager.go. - orm := forwarders.NewORM(ldb.DB(), lggr, s.Config.Database()) - _, err = orm.CreateForwarder(common.HexToAddress(forwarderAddress), *utils.NewBigI(chainID)) + err = s.authorizeForwarder(c, ldb.DB(), lggr, chainID, ec, owner, sendingKeysAddresses) if err != nil { return nil, err } @@ -331,6 +298,58 @@ func (s *Shell) ConfigureOCR2VRFNode(c *cli.Context, owner *bind.TransactOpts, e }, nil } +func (s *Shell) appendForwarders(chainID int64, ks keystore.Eth, sendingKeys []string, sendingKeysAddresses []common.Address) ([]string, []common.Address, error) { + for i := 0; i < forwarderAdditionalEOACount; i++ { + // Create the sending key in the keystore. + k, err := ks.Create() + if err != nil { + return nil, nil, err + } + + // Enable the sending key for the current chain. + err = ks.Enable(k.Address, big.NewInt(chainID)) + if err != nil { + return nil, nil, err + } + + sendingKeys = append(sendingKeys, k.Address.String()) + sendingKeysAddresses = append(sendingKeysAddresses, k.Address) + } + + return sendingKeys, sendingKeysAddresses, nil +} + +func (s *Shell) authorizeForwarder(c *cli.Context, db *sqlx.DB, lggr logger.Logger, chainID int64, ec *ethclient.Client, owner *bind.TransactOpts, sendingKeysAddresses []common.Address) error { + // Replace the transmitter ID with the forwarder address. + forwarderAddress := c.String("forwarder-address") + + // We have to set the authorized senders on-chain here, otherwise the job spawner will fail as the + // forwarder will not be recognized. + ctx, cancel := context.WithTimeout(context.Background(), 300*time.Second) + defer cancel() + f, err := authorized_forwarder.NewAuthorizedForwarder(common.HexToAddress(forwarderAddress), ec) + if err != nil { + return err + } + tx, err := f.SetAuthorizedSenders(owner, sendingKeysAddresses) + if err != nil { + return err + } + _, err = bind.WaitMined(ctx, ec, tx) + if err != nil { + return err + } + + // Create forwarder for management in forwarder_manager.go. + orm := forwarders.NewORM(db, lggr, s.Config.Database()) + _, err = orm.CreateForwarder(common.HexToAddress(forwarderAddress), *utils.NewBigI(chainID)) + if err != nil { + return err + } + + return nil +} + func setupKeystore(cli *Shell, app chainlink.Application, keyStore keystore.Master) error { err := cli.KeyStoreAuthenticator.authenticate(keyStore, cli.Config.Password()) if err != nil { diff --git a/core/cmd/shell_local.go b/core/cmd/shell_local.go index 372aad01384..613e8f5a6e0 100644 --- a/core/cmd/shell_local.go +++ b/core/cmd/shell_local.go @@ -292,8 +292,7 @@ func (s *Shell) runNode(c *cli.Context) error { s.Config.LogConfiguration(lggr.Debugf) - err := s.Config.Validate() - if err != nil { + if err := s.Config.Validate(); err != nil { return errors.Wrap(err, "config validation failed") } diff --git a/core/internal/cltest/cltest.go b/core/internal/cltest/cltest.go index 671d4072816..4f573078587 100644 --- a/core/internal/cltest/cltest.go +++ b/core/internal/cltest/cltest.go @@ -33,14 +33,15 @@ import ( p2ppeer "github.com/libp2p/go-libp2p-core/peer" "github.com/manyminds/api2go/jsonapi" "github.com/onsi/gomega" - ocrtypes "github.com/smartcontractkit/libocr/offchainreporting/types" - "github.com/smartcontractkit/sqlx" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "github.com/tidwall/gjson" "github.com/urfave/cli" + ocrtypes "github.com/smartcontractkit/libocr/offchainreporting/types" + "github.com/smartcontractkit/sqlx" + "github.com/smartcontractkit/chainlink-relay/pkg/loop" clienttypes "github.com/smartcontractkit/chainlink/v2/common/chains/client" @@ -209,8 +210,7 @@ func NewEventBroadcaster(t testing.TB, dbURL url.URL) pg.EventBroadcaster { return pg.NewEventBroadcaster(dbURL, 0, 0, lggr, uuid.New()) } -func NewEthConfirmer(t testing.TB, txStore txmgr.EvmTxStore, ethClient evmclient.Client, config evmconfig.ChainScopedConfig, ks keystore.Eth, fn txmgrcommon.ResumeCallback) (*txmgr.Confirmer, error) { - t.Helper() +func NewEthConfirmer(t testing.TB, txStore txmgr.EvmTxStore, ethClient evmclient.Client, config evmconfig.ChainScopedConfig, ks keystore.Eth, fn txmgrcommon.ResumeCallback) *txmgr.Confirmer { lggr := logger.TestLogger(t) ge := config.EVM().GasEstimator() estimator := gas.NewWrappedEvmEstimator(gas.NewFixedPriceEstimator(ge, ge.BlockHistory(), lggr), ge.EIP1559DynamicFees(), nil) @@ -218,7 +218,7 @@ func NewEthConfirmer(t testing.TB, txStore txmgr.EvmTxStore, ethClient evmclient ec := txmgr.NewEvmConfirmer(txStore, txmgr.NewEvmTxmClient(ethClient), txmgr.NewEvmTxmConfig(config.EVM()), txmgr.NewEvmTxmFeeConfig(ge), config.EVM().Transactions(), config.Database(), ks, txBuilder, lggr) ec.SetResumeCallback(fn) require.NoError(t, ec.Start(testutils.Context(t))) - return ec, nil + return ec } // TestApplication holds the test application and test servers From 2ce9e60414c57b80a289ceaa5beb9d8052e330b6 Mon Sep 17 00:00:00 2001 From: Rens Rooimans Date: Tue, 10 Oct 2023 15:42:35 +0200 Subject: [PATCH 4/9] bump foundry version (#10889) * bump foundry version * bump forge-std 1.6.1 -> 1.7.1 * fix snapshot and rm failfast CI * turn off failing tests with TODO * bump foundry version * bump foundry version (#10896) * run prettier * fix wrong prettier --------- Co-authored-by: Makram --- .github/workflows/solidity-foundry.yml | 3 +- contracts/GNUmakefile | 2 +- contracts/foundry-lib/forge-std | 2 +- .../gas-snapshots/functions.gas-snapshot | 12 ++-- .../gas-snapshots/llo-feeds.gas-snapshot | 32 +++++------ .../test/v0.8/foundry/vrf/VRFV2Plus.t.sol | 56 +++++++++---------- 6 files changed, 54 insertions(+), 53 deletions(-) diff --git a/.github/workflows/solidity-foundry.yml b/.github/workflows/solidity-foundry.yml index 8f0181640ea..38b6a511127 100644 --- a/.github/workflows/solidity-foundry.yml +++ b/.github/workflows/solidity-foundry.yml @@ -30,6 +30,7 @@ jobs: tests: strategy: + fail-fast: false matrix: product: [vrf, automation, llo-feeds, functions, shared] needs: [changes] @@ -54,7 +55,7 @@ jobs: uses: foundry-rs/foundry-toolchain@v1 with: # Has to match the `make foundry` version. - version: nightly-ca67d15f4abd46394b324c50e21e66f306a1162d + version: nightly-e0722a10b45859892ec3b998df958a9edc77c202 - name: Run Forge build run: | diff --git a/contracts/GNUmakefile b/contracts/GNUmakefile index 328c921545c..5e9397e2b0e 100644 --- a/contracts/GNUmakefile +++ b/contracts/GNUmakefile @@ -38,7 +38,7 @@ mockery: $(mockery) ## Install mockery. .PHONY: foundry foundry: ## Install foundry. - foundryup --version nightly-ca67d15f4abd46394b324c50e21e66f306a1162d + foundryup --version nightly-e0722a10b45859892ec3b998df958a9edc77c202 .PHONY: foundry-refresh foundry-refresh: foundry diff --git a/contracts/foundry-lib/forge-std b/contracts/foundry-lib/forge-std index 1d9650e9512..f73c73d2018 160000 --- a/contracts/foundry-lib/forge-std +++ b/contracts/foundry-lib/forge-std @@ -1 +1 @@ -Subproject commit 1d9650e951204a0ddce9ff89c32f1997984cef4d +Subproject commit f73c73d2018eb6a111f35e4dae7b4f27401e9421 diff --git a/contracts/gas-snapshots/functions.gas-snapshot b/contracts/gas-snapshots/functions.gas-snapshot index 0c3caa6522e..b2ef072c1f7 100644 --- a/contracts/gas-snapshots/functions.gas-snapshot +++ b/contracts/gas-snapshots/functions.gas-snapshot @@ -95,9 +95,9 @@ FunctionsSubscriptions_CancelSubscription:test_CancelSubscription_RevertIfNotAll FunctionsSubscriptions_CancelSubscription:test_CancelSubscription_RevertIfNotSubscriptionOwner() (gas: 89316) FunctionsSubscriptions_CancelSubscription:test_CancelSubscription_RevertIfPaused() (gas: 20191) FunctionsSubscriptions_CancelSubscription:test_CancelSubscription_RevertIfPendingRequests() (gas: 193222) -FunctionsSubscriptions_CancelSubscription:test_CancelSubscription_SuccessForfeitAllBalanceAsDeposit() (gas: 113352) -FunctionsSubscriptions_CancelSubscription:test_CancelSubscription_SuccessForfeitSomeBalanceAsDeposit() (gas: 124604) -FunctionsSubscriptions_CancelSubscription:test_CancelSubscription_SuccessRecieveDeposit() (gas: 310090) +FunctionsSubscriptions_CancelSubscription:test_CancelSubscription_SuccessForfeitAllBalanceAsDeposit() (gas: 114636) +FunctionsSubscriptions_CancelSubscription:test_CancelSubscription_SuccessForfeitSomeBalanceAsDeposit() (gas: 125891) +FunctionsSubscriptions_CancelSubscription:test_CancelSubscription_SuccessRecieveDeposit() (gas: 311988) FunctionsSubscriptions_Constructor:test_Constructor_Success() (gas: 7654) FunctionsSubscriptions_CreateSubscriptionWithConsumer:test_CreateSubscriptionWithConsumer_RevertIfNotAllowedSender() (gas: 28637) FunctionsSubscriptions_CreateSubscriptionWithConsumer:test_CreateSubscriptionWithConsumer_RevertIfPaused() (gas: 17948) @@ -106,8 +106,8 @@ FunctionsSubscriptions_GetConsumer:test_GetConsumer_Success() (gas: 16225) FunctionsSubscriptions_GetFlags:test_GetFlags_Success() (gas: 40858) FunctionsSubscriptions_GetSubscription:test_GetSubscription_Success() (gas: 30959) FunctionsSubscriptions_GetSubscriptionCount:test_GetSubscriptionCount_Success() (gas: 12967) -FunctionsSubscriptions_GetSubscriptionsInRange:test_GetSubscriptionsInRange_RevertIfEndIsAfterLastSubscription() (gas: 14949) -FunctionsSubscriptions_GetSubscriptionsInRange:test_GetSubscriptionsInRange_RevertIfStartIsAfterEnd() (gas: 11863) +FunctionsSubscriptions_GetSubscriptionsInRange:test_GetSubscriptionsInRange_RevertIfEndIsAfterLastSubscription() (gas: 16523) +FunctionsSubscriptions_GetSubscriptionsInRange:test_GetSubscriptionsInRange_RevertIfStartIsAfterEnd() (gas: 13436) FunctionsSubscriptions_GetSubscriptionsInRange:test_GetSubscriptionsInRange_Success() (gas: 59568) FunctionsSubscriptions_GetTotalBalance:test_GetTotalBalance_Success() (gas: 15032) FunctionsSubscriptions_OnTokenTransfer:test_OnTokenTransfer_RevertIfCallerIsNoCalldata() (gas: 27594) @@ -124,7 +124,7 @@ FunctionsSubscriptions_OracleWithdraw:test_OracleWithdraw_SuccessSetsBalanceToZe FunctionsSubscriptions_OwnerCancelSubscription:test_OwnerCancelSubscription_RevertIfNoSubscription() (gas: 12818) FunctionsSubscriptions_OwnerCancelSubscription:test_OwnerCancelSubscription_RevertIfNotOwner() (gas: 15549) FunctionsSubscriptions_OwnerCancelSubscription:test_OwnerCancelSubscription_Success() (gas: 54867) -FunctionsSubscriptions_OwnerCancelSubscription:test_OwnerCancelSubscription_SuccessDeletesSubscription() (gas: 48362) +FunctionsSubscriptions_OwnerCancelSubscription:test_OwnerCancelSubscription_SuccessDeletesSubscription() (gas: 49624) FunctionsSubscriptions_OwnerCancelSubscription:test_OwnerCancelSubscription_SuccessSubOwnerRefunded() (gas: 50896) FunctionsSubscriptions_OwnerCancelSubscription:test_OwnerCancelSubscription_SuccessWhenRequestInFlight() (gas: 163867) FunctionsSubscriptions_OwnerWithdraw:test_OwnerWithdraw_RevertIfAmountMoreThanBalance() (gas: 17924) diff --git a/contracts/gas-snapshots/llo-feeds.gas-snapshot b/contracts/gas-snapshots/llo-feeds.gas-snapshot index 74b9a9f9258..a9877fbe33c 100644 --- a/contracts/gas-snapshots/llo-feeds.gas-snapshot +++ b/contracts/gas-snapshots/llo-feeds.gas-snapshot @@ -20,7 +20,7 @@ FeeManagerProcessFeeTest:test_discountIsNoLongerAppliedAfterRemoving() (gas: 459 FeeManagerProcessFeeTest:test_discountIsNotAppliedForInvalidTokenAddress() (gas: 17546) FeeManagerProcessFeeTest:test_discountIsNotAppliedToOtherFeeds() (gas: 54241) FeeManagerProcessFeeTest:test_discountIsReturnedForLink() (gas: 49252) -FeeManagerProcessFeeTest:test_emptyQuoteRevertsWithError() (gas: 11286) +FeeManagerProcessFeeTest:test_emptyQuoteRevertsWithError() (gas: 12152) FeeManagerProcessFeeTest:test_eventIsEmittedAfterSurchargeIsSet() (gas: 41348) FeeManagerProcessFeeTest:test_eventIsEmittedIfNotEnoughLink() (gas: 172711) FeeManagerProcessFeeTest:test_eventIsEmittedUponWithdraw() (gas: 68984) @@ -87,7 +87,7 @@ FeeManagerProcessFeeTest:test_surchargeIsAppliedForNativeFeeWithDiscount() (gas: FeeManagerProcessFeeTest:test_surchargeIsNoLongerAppliedAfterRemoving() (gas: 46503) FeeManagerProcessFeeTest:test_surchargeIsNotAppliedForLinkFee() (gas: 49585) FeeManagerProcessFeeTest:test_surchargeIsNotAppliedWith100PercentDiscount() (gas: 77890) -FeeManagerProcessFeeTest:test_testRevertIfReportHasExpired() (gas: 14042) +FeeManagerProcessFeeTest:test_testRevertIfReportHasExpired() (gas: 14908) RewardManagerClaimTest:test_claimAllRecipients() (gas: 275763) RewardManagerClaimTest:test_claimMultipleRecipients() (gas: 153306) RewardManagerClaimTest:test_claimRewardsWithDuplicatePoolIdsDoesNotPayoutTwice() (gas: 328345) @@ -123,7 +123,7 @@ RewardManagerRecipientClaimMultiplePoolsTest:test_claimSingleUniqueRecipient() ( RewardManagerRecipientClaimMultiplePoolsTest:test_claimUnevenAmountRoundsDown() (gas: 576289) RewardManagerRecipientClaimMultiplePoolsTest:test_claimUnregisteredRecipient() (gas: 63555) RewardManagerRecipientClaimMultiplePoolsTest:test_getAvailableRewardsCursorAndTotalPoolsEqual() (gas: 10202) -RewardManagerRecipientClaimMultiplePoolsTest:test_getAvailableRewardsCursorCannotBeGreaterThanTotalPools() (gas: 11107) +RewardManagerRecipientClaimMultiplePoolsTest:test_getAvailableRewardsCursorCannotBeGreaterThanTotalPools() (gas: 12680) RewardManagerRecipientClaimMultiplePoolsTest:test_getAvailableRewardsCursorSingleResult() (gas: 19606) RewardManagerRecipientClaimMultiplePoolsTest:test_getRewardsAvailableToRecipientInBothPools() (gas: 29052) RewardManagerRecipientClaimMultiplePoolsTest:test_getRewardsAvailableToRecipientInBothPoolsWhereAlreadyClaimed() (gas: 147218) @@ -181,11 +181,11 @@ VerifierBulkVerifyBillingReport:test_verifyWithBulkNativeUnwrappedReturnsChange( VerifierConstructorTest:test_revertsIfInitializedWithEmptyVerifierProxy() (gas: 59967) VerifierConstructorTest:test_setsTheCorrectProperties() (gas: 1815769) VerifierDeactivateFeedWithVerifyTest:test_currentReportAllowsVerification() (gas: 192062) -VerifierDeactivateFeedWithVerifyTest:test_currentReportFailsVerification() (gas: 111727) +VerifierDeactivateFeedWithVerifyTest:test_currentReportFailsVerification() (gas: 113377) VerifierDeactivateFeedWithVerifyTest:test_previousReportAllowsVerification() (gas: 99613) -VerifierDeactivateFeedWithVerifyTest:test_previousReportFailsVerification() (gas: 68305) +VerifierDeactivateFeedWithVerifyTest:test_previousReportFailsVerification() (gas: 69932) VerifierProxyAccessControlledVerificationTest:test_proxiesToTheVerifierIfHasAccess() (gas: 205796) -VerifierProxyAccessControlledVerificationTest:test_revertsIfNoAccess() (gas: 110688) +VerifierProxyAccessControlledVerificationTest:test_revertsIfNoAccess() (gas: 112334) VerifierProxyConstructorTest:test_correctlySetsTheCorrectAccessControllerInterface() (gas: 1482522) VerifierProxyConstructorTest:test_correctlySetsTheOwner() (gas: 1462646) VerifierProxyConstructorTest:test_correctlySetsVersion() (gas: 6873) @@ -207,7 +207,7 @@ VerifierProxyUnsetVerifierTest:test_revertsIfNotAdmin() (gas: 14965) VerifierProxyUnsetVerifierWithPreviouslySetVerifierTest:test_correctlyUnsetsVerifier() (gas: 12720) VerifierProxyUnsetVerifierWithPreviouslySetVerifierTest:test_emitsAnEventAfterUnsettingVerifier() (gas: 17965) VerifierProxyVerifyTest:test_proxiesToTheCorrectVerifier() (gas: 201609) -VerifierProxyVerifyTest:test_revertsIfNoVerifierConfigured() (gas: 115615) +VerifierProxyVerifyTest:test_revertsIfNoVerifierConfigured() (gas: 117256) VerifierSetConfigFromSourceMultipleDigestsTest:test_correctlySetsConfigWhenDigestsAreRemoved() (gas: 538896) VerifierSetConfigFromSourceMultipleDigestsTest:test_correctlyUpdatesDigestsOnMultipleVerifiersInTheProxy() (gas: 964726) VerifierSetConfigFromSourceMultipleDigestsTest:test_correctlyUpdatesTheDigestInTheProxy() (gas: 520480) @@ -230,17 +230,17 @@ VerifierTestBillingReport:test_verifyWithNativeUnwrapped() (gas: 317892) VerifierTestBillingReport:test_verifyWithNativeUnwrappedReturnsChange() (gas: 324958) VerifierVerifyMultipleConfigDigestTest:test_canVerifyNewerReportsWithNewerConfigs() (gas: 131228) VerifierVerifyMultipleConfigDigestTest:test_canVerifyOlderReportsWithOlderConfigs() (gas: 187132) -VerifierVerifyMultipleConfigDigestTest:test_revertsIfAReportIsVerifiedWithAnExistingButIncorrectDigest() (gas: 86566) -VerifierVerifyMultipleConfigDigestTest:test_revertsIfVerifyingWithAnUnsetDigest() (gas: 126411) +VerifierVerifyMultipleConfigDigestTest:test_revertsIfAReportIsVerifiedWithAnExistingButIncorrectDigest() (gas: 88205) +VerifierVerifyMultipleConfigDigestTest:test_revertsIfVerifyingWithAnUnsetDigest() (gas: 128062) VerifierVerifySingleConfigDigestTest:test_emitsAnEventIfReportVerified() (gas: 186945) VerifierVerifySingleConfigDigestTest:test_returnsThePriceAndBlockNumIfReportVerified() (gas: 187114) -VerifierVerifySingleConfigDigestTest:test_revertsIfConfigDigestNotSet() (gas: 114479) -VerifierVerifySingleConfigDigestTest:test_revertsIfDuplicateSignersHaveSigned() (gas: 180665) -VerifierVerifySingleConfigDigestTest:test_revertsIfMismatchedSignatureLength() (gas: 51479) -VerifierVerifySingleConfigDigestTest:test_revertsIfReportHasUnconfiguredFeedID() (gas: 102318) -VerifierVerifySingleConfigDigestTest:test_revertsIfVerifiedByNonProxy() (gas: 99348) -VerifierVerifySingleConfigDigestTest:test_revertsIfVerifiedWithIncorrectAddresses() (gas: 182416) -VerifierVerifySingleConfigDigestTest:test_revertsIfWrongNumberOfSigners() (gas: 108382) +VerifierVerifySingleConfigDigestTest:test_revertsIfConfigDigestNotSet() (gas: 116130) +VerifierVerifySingleConfigDigestTest:test_revertsIfDuplicateSignersHaveSigned() (gas: 182315) +VerifierVerifySingleConfigDigestTest:test_revertsIfMismatchedSignatureLength() (gas: 53037) +VerifierVerifySingleConfigDigestTest:test_revertsIfReportHasUnconfiguredFeedID() (gas: 103976) +VerifierVerifySingleConfigDigestTest:test_revertsIfVerifiedByNonProxy() (gas: 100992) +VerifierVerifySingleConfigDigestTest:test_revertsIfVerifiedWithIncorrectAddresses() (gas: 184066) +VerifierVerifySingleConfigDigestTest:test_revertsIfWrongNumberOfSigners() (gas: 110031) VerifierVerifySingleConfigDigestTest:test_setsTheCorrectEpoch() (gas: 194270) Verifier_accessControlledVerify:testVerifyWithAccessControl_gas() (gas: 212066) Verifier_bulkVerifyWithFee:testBulkVerifyProxyWithLinkFeeSuccess_gas() (gas: 519368) diff --git a/contracts/test/v0.8/foundry/vrf/VRFV2Plus.t.sol b/contracts/test/v0.8/foundry/vrf/VRFV2Plus.t.sol index 13d52b676c5..90b3d460fe2 100644 --- a/contracts/test/v0.8/foundry/vrf/VRFV2Plus.t.sol +++ b/contracts/test/v0.8/foundry/vrf/VRFV2Plus.t.sol @@ -282,15 +282,15 @@ contract VRFV2Plus is BaseTest { // Store the previous block's blockhash, and assert that it is as expected. vm.roll(requestBlock + 1); s_bhs.store(requestBlock); - assertEq(hex"c65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a8", s_bhs.getBlockhash(requestBlock)); + assertEq(hex"000000000000000000000000000000000000000000000000000000000000000a", s_bhs.getBlockhash(requestBlock)); // Fulfill the request. // Proof generated via the generate-proof-v2-plus script command. Example usage: /* go run . generate-proof-v2-plus \ -key-hash 0x9f2353bde94264dbc3d554a94cceba2d7d2b4fdce4304d3e09a1fea9fbeb1528 \ - -pre-seed 53391429126065232382402681707515137895470547057819816488254124798726362946635 \ - -block-hash 0xc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a8 \ + -pre-seed 93724884573574303181157854277074121673523280784530506403108144933983063023487 \ + -block-hash 0x000000000000000000000000000000000000000000000000000000000000000a \ -block-num 10 \ -sender 0x90A8820424CC8a819d14cBdE54D12fD3fbFa9bb2 \ -native-payment true @@ -301,22 +301,22 @@ contract VRFV2Plus is BaseTest { 62070622898698443831883535403436258712770888294397026493185421712108624767191 ], gamma: [ - 2973102176083872659982988645522968133664529102555885971868619302367987919116, - 43610558806647181042154132372309425100765955827430056035281841579494767100593 + 51111463251706978184511913295560024261167135799300172382907308330135472647507, + 41885656274025752055847945432737871864088659248922821023734315208027501951872 ], - c: 44558436621153210954487996771157467729629491520915192177070584116261579650304, - s: 18447217702001910909971999949841419857536434117467121546901211519652998560328, - seed: 53391429126065232382402681707515137895470547057819816488254124798726362946635, - uWitness: 0x61e70839187C12Fe136bdcC78D1D3765BecA245d, + c: 96917856581077810363012153828220232197567408835708926581335248000925197916153, + s: 103298896676233752268329042222773891728807677368628421408380318882272184455566, + seed: 93724884573574303181157854277074121673523280784530506403108144933983063023487, + uWitness: 0xFCaA10875C6692f6CcC86c64300eb0b52f2D4323, cGammaWitness: [ - 57868024672571504735938309170346165090467827794150592801232968679608710558443, - 19249635816589941728350586356475545703589085434839461964712223344491075318152 + 61463607927970680172418313129927007099021056249775757132623753443657677198526, + 48686021866486086188742596461341782400160109177829661164208082534005682984658 ], sHashWitness: [ - 61151023867440095994162103308586528914977848168432699421313437043942463394142, - 107161674609768447269383119603000260750848712436031813376573304048979100187696 + 91508089836242281395929619352465003226819385335975246221498243754781593857533, + 63571625936444669399167157725633389238098818902162172059681813608664564703308 ], - zInv: 92231836131549905872346812799402691650433126386650679876913933650318463342041 + zInv: 97568175302326019383632009699686265453584842953005404815285123863099260038246 }); VRFCoordinatorV2_5.RequestCommitment memory rc = VRFCoordinatorV2_5.RequestCommitment({ blockNum: requestBlock, @@ -399,15 +399,15 @@ contract VRFV2Plus is BaseTest { // Store the previous block's blockhash, and assert that it is as expected. vm.roll(requestBlock + 1); s_bhs.store(requestBlock); - assertEq(hex"ce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ec", s_bhs.getBlockhash(requestBlock)); + assertEq(hex"0000000000000000000000000000000000000000000000000000000000000014", s_bhs.getBlockhash(requestBlock)); // Fulfill the request. // Proof generated via the generate-proof-v2-plus script command. Example usage: /* go run . generate-proof-v2-plus \ -key-hash 0x9f2353bde94264dbc3d554a94cceba2d7d2b4fdce4304d3e09a1fea9fbeb1528 \ - -pre-seed 14817911724325909152780695848148728017190840227899344848185245004944693487904 \ - -block-hash 0xce6d7b5282bd9a3661ae061feed1dbda4e52ab073b1f9285be6e155d9c38d4ec \ + -pre-seed 108233140904510496268355288815996296196427471042093167619305836589216327096601 \ + -block-hash 0x0000000000000000000000000000000000000000000000000000000000000014 \ -block-num 20 \ -sender 0x90A8820424CC8a819d14cBdE54D12fD3fbFa9bb2 */ @@ -417,22 +417,22 @@ contract VRFV2Plus is BaseTest { 62070622898698443831883535403436258712770888294397026493185421712108624767191 ], gamma: [ - 33866404953216897461413961842321788789902210776565180957857448351149268461878, - 115311460432520855364215812517921508651759645277579047898967111537639679255245 + 49785247270467418393187938018746488660500261614113251546613288843777654841004, + 8320717868018488740308781441198484312662094766876176838868269181386589318272 ], - c: 32561838617228634441320154326890637858849550728945663611942735469609183032389, - s: 55806041637816588920133401262818662941786708593795051215322306020699218819370, - seed: 14817911724325909152780695848148728017190840227899344848185245004944693487904, - uWitness: 0x917554f18dB75eac206Ae5366B80c0b6A87b5996, + c: 41596204381278553342984662603150353549780558761307588910860350083645227536604, + s: 81592778991188138734863787790226463602813498664606420860910885269124681994753, + seed: 108233140904510496268355288815996296196427471042093167619305836589216327096601, + uWitness: 0x56920892EE71E624d369dCc8dc63B6878C85Ca70, cGammaWitness: [ - 84076069514674055711740813040098459867759972960517070154541804330775196519927, - 23456142794899412334950030002327578074149212885334118042147040122102091306080 + 28250667431035633903490940933503696927659499415200427260709034207157951953043, + 105660182690338773283351292037478192732977803900032569393220726139772041021018 ], sHashWitness: [ - 67919054534004130885903575144858988177160334233773664996450084407340736891592, - 82934864721844704662104532515068228502043057799129930869203380251475000254135 + 18420263847278540234821121001488166570853056146131705862117248292063859054211, + 15740432967529684573970722302302642068194042971767150190061244675457227502736 ], - zInv: 37397948970756055003892765560695914630264479979131589134478580629419519112029 + zInv: 100579074451139970455673776933943662313989441807178260211316504761358492254052 }); VRFCoordinatorV2_5.RequestCommitment memory rc = VRFCoordinatorV2_5.RequestCommitment({ blockNum: requestBlock, From e66a735dbfbff2c901749269304f07f6288fe0cd Mon Sep 17 00:00:00 2001 From: Makram Date: Tue, 10 Oct 2023 17:38:40 +0300 Subject: [PATCH 5/9] chore: move dev vrf contracts into v0.8/vrf (#10894) * chore: move dev vrf contracts into v0.8/vrf * chore: fix imports * fix: forge tests * chore: update native_solc_compile_all_vrf * Revert "fix: forge tests" This reverts commit 6efb6b78c1c6555ce8969e86335e7218de0c982c. Was using the wrong foundry version locally * fix: native_solc_compile_all_automation * fix: solhint * chore: bump changelog * update warning count on solhintignore --------- Co-authored-by: Rens Rooimans --- contracts/.solhintignore | 7 +- contracts/CHANGELOG.md | 3 +- .../native_solc_compile_all_automation | 3 - contracts/scripts/native_solc_compile_all_vrf | 52 ++++++------ contracts/src/v0.8/dev/BlockhashStore.sol | 81 ------------------- .../src/v0.8/{ => vrf}/KeepersVRFConsumer.sol | 10 ++- contracts/src/v0.8/vrf/VRFCoordinatorV2.sol | 4 +- contracts/src/v0.8/vrf/VRFV2Wrapper.sol | 4 +- .../src/v0.8/vrf/VRFV2WrapperConsumerBase.sol | 2 +- .../dev}/BatchVRFCoordinatorV2Plus.sol | 2 +- .../{dev/vrf => vrf/dev}/BlockhashStore.sol | 0 .../{dev/vrf => vrf/dev}/SubscriptionAPI.sol | 2 +- .../vrf => vrf/dev}/TrustedBlockhashStore.sol | 0 .../vrf => vrf/dev}/VRFConsumerBaseV2Plus.sol | 4 +- .../dev/VRFConsumerBaseV2Upgradeable.sol | 0 .../vrf => vrf/dev}/VRFCoordinatorV2_5.sol | 6 +- .../dev/VRFSubscriptionBalanceMonitor.sol | 6 +- .../{dev/vrf => vrf/dev}/VRFV2PlusWrapper.sol | 4 +- .../dev}/VRFV2PlusWrapperConsumerBase.sol | 2 +- .../dev/interfaces/IVRFCoordinatorV2Plus.sol | 2 +- .../IVRFCoordinatorV2PlusInternal.sol | 0 .../IVRFCoordinatorV2PlusMigration.sol | 0 .../IVRFMigratableConsumerV2Plus.sol | 0 .../dev/interfaces/IVRFSubscriptionV2Plus.sol | 0 .../dev/interfaces/IVRFV2PlusMigrate.sol | 0 .../dev/interfaces/IVRFV2PlusWrapper.sol | 0 .../dev}/libraries/VRFV2PlusClient.sol | 0 .../testhelpers/ExposedVRFCoordinatorV2_5.sol | 0 .../VRFConsumerV2PlusUpgradeableExample.sol | 4 +- .../VRFCoordinatorV2PlusUpgradedVersion.sol | 6 +- .../VRFCoordinatorV2Plus_V2Example.sol | 2 +- .../VRFMaliciousConsumerV2Plus.sol | 2 +- .../testhelpers/VRFV2PlusConsumerExample.sol | 2 +- .../VRFV2PlusExternalSubOwnerExample.sol | 2 +- .../VRFV2PlusLoadTestWithMetrics.sol | 0 .../VRFV2PlusMaliciousMigrator.sol | 4 +- .../testhelpers/VRFV2PlusRevertingExample.sol | 2 +- .../VRFV2PlusSingleConsumerExample.sol | 2 +- .../VRFV2PlusWrapperConsumerExample.sol | 0 .../VRFV2PlusWrapperLoadTestConsumer.sol | 2 +- .../interfaces/BlockhashStoreInterface.sol | 0 .../interfaces/VRFCoordinatorV2Interface.sol | 0 .../interfaces/VRFV2WrapperInterface.sol | 0 .../{ => vrf}/mocks/VRFCoordinatorMock.sol | 9 ++- .../{ => vrf}/mocks/VRFCoordinatorV2Mock.sol | 23 +++--- .../src/v0.8/vrf/testhelpers/VRFConsumer.sol | 3 +- .../v0.8/vrf/testhelpers/VRFConsumerV2.sol | 10 +-- .../VRFConsumerV2UpgradeableExample.sol | 8 +- .../VRFCoordinatorV2TestHelper.sol | 4 +- .../VRFExternalSubOwnerExample.sol | 12 +-- .../VRFLoadTestExternalSubOwner.sol | 8 +- .../VRFLoadTestOwnerlessConsumer.sol | 4 +- .../testhelpers/VRFMaliciousConsumerV2.sol | 12 +-- .../VRFOwnerlessConsumerExample.sol | 4 +- .../VRFRequestIDBaseTestHelper.sol | 2 +- .../testhelpers/VRFSingleConsumerExample.sol | 10 +-- .../VRFSubscriptionBalanceMonitorExposed.sol | 2 +- .../v0.8/vrf/testhelpers/VRFTestHelper.sol | 2 +- .../testhelpers/VRFV2LoadTestWithMetrics.sol | 10 +-- .../testhelpers/VRFV2OwnerTestConsumer.sol | 11 ++- .../vrf/testhelpers/VRFV2RevertingExample.sol | 13 +-- .../VRFV2WrapperConsumerExample.sol | 6 +- .../VRFV2WrapperOutOfGasConsumerExample.sol | 6 +- .../VRFV2WrapperRevertingConsumerExample.sol | 6 +- .../VRFV2WrapperUnderFundingConsumer.sol | 6 +- contracts/test/v0.8/VRFD20.test.ts | 2 +- .../v0.8/dev/VRFCoordinatorV2Mock.test.ts | 2 +- .../transmission/EIP_712_1014_4337.t.sol | 2 +- .../foundry/vrf/TrustedBlockhashStore.t.sol | 2 +- .../foundry/vrf/VRFCoordinatorV2Mock.t.sol | 2 +- .../vrf/VRFCoordinatorV2Plus_Migration.t.sol | 12 +-- .../test/v0.8/foundry/vrf/VRFV2Plus.t.sol | 12 +-- .../vrf/VRFV2PlusSubscriptionAPI.t.sol | 4 +- .../test/v0.8/foundry/vrf/VRFV2Wrapper.t.sol | 12 +-- .../foundry/vrf/VRFV2Wrapper_Migration.t.sol | 16 ++-- 75 files changed, 197 insertions(+), 262 deletions(-) delete mode 100644 contracts/src/v0.8/dev/BlockhashStore.sol rename contracts/src/v0.8/{ => vrf}/KeepersVRFConsumer.sol (88%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/BatchVRFCoordinatorV2Plus.sol (98%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/BlockhashStore.sol (100%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/SubscriptionAPI.sol (99%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/TrustedBlockhashStore.sol (100%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/VRFConsumerBaseV2Plus.sol (97%) rename contracts/src/v0.8/{ => vrf}/dev/VRFConsumerBaseV2Upgradeable.sol (100%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/VRFCoordinatorV2_5.sol (98%) rename contracts/src/v0.8/{ => vrf}/dev/VRFSubscriptionBalanceMonitor.sol (97%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/VRFV2PlusWrapper.sol (99%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/VRFV2PlusWrapperConsumerBase.sol (98%) rename contracts/src/v0.8/{ => vrf}/dev/interfaces/IVRFCoordinatorV2Plus.sol (96%) rename contracts/src/v0.8/{ => vrf}/dev/interfaces/IVRFCoordinatorV2PlusInternal.sol (100%) rename contracts/src/v0.8/{ => vrf}/dev/interfaces/IVRFCoordinatorV2PlusMigration.sol (100%) rename contracts/src/v0.8/{ => vrf}/dev/interfaces/IVRFMigratableConsumerV2Plus.sol (100%) rename contracts/src/v0.8/{ => vrf}/dev/interfaces/IVRFSubscriptionV2Plus.sol (100%) rename contracts/src/v0.8/{ => vrf}/dev/interfaces/IVRFV2PlusMigrate.sol (100%) rename contracts/src/v0.8/{ => vrf}/dev/interfaces/IVRFV2PlusWrapper.sol (100%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/libraries/VRFV2PlusClient.sol (100%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/testhelpers/ExposedVRFCoordinatorV2_5.sol (100%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/testhelpers/VRFConsumerV2PlusUpgradeableExample.sol (94%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/testhelpers/VRFCoordinatorV2PlusUpgradedVersion.sol (99%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/testhelpers/VRFCoordinatorV2Plus_V2Example.sol (98%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/testhelpers/VRFMaliciousConsumerV2Plus.sol (96%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/testhelpers/VRFV2PlusConsumerExample.sol (98%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/testhelpers/VRFV2PlusExternalSubOwnerExample.sol (96%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/testhelpers/VRFV2PlusLoadTestWithMetrics.sol (100%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/testhelpers/VRFV2PlusMaliciousMigrator.sol (82%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/testhelpers/VRFV2PlusRevertingExample.sol (97%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/testhelpers/VRFV2PlusSingleConsumerExample.sol (98%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/testhelpers/VRFV2PlusWrapperConsumerExample.sol (100%) rename contracts/src/v0.8/{dev/vrf => vrf/dev}/testhelpers/VRFV2PlusWrapperLoadTestConsumer.sol (98%) rename contracts/src/v0.8/{ => vrf}/interfaces/BlockhashStoreInterface.sol (100%) rename contracts/src/v0.8/{ => vrf}/interfaces/VRFCoordinatorV2Interface.sol (100%) rename contracts/src/v0.8/{ => vrf}/interfaces/VRFV2WrapperInterface.sol (100%) rename contracts/src/v0.8/{ => vrf}/mocks/VRFCoordinatorMock.sol (77%) rename contracts/src/v0.8/{ => vrf}/mocks/VRFCoordinatorV2Mock.sol (92%) diff --git a/contracts/.solhintignore b/contracts/.solhintignore index 88ad92c6b87..91a58b34e5b 100644 --- a/contracts/.solhintignore +++ b/contracts/.solhintignore @@ -1,13 +1,12 @@ -# 368 warnings +# 351 warnings #./src/v0.8/automation -# 302 warnings +# 60 warnings #./src/v0.8/dev # 91 warnings #./src/v0.8/functions # 91 warnings #./src/v0.8/l2ep/dev -# 116 warnings -#./src/v0.8/vrf + # Temp ignore the following files as they contain issues. ./src/v0.8/ChainlinkClient.sol diff --git a/contracts/CHANGELOG.md b/contracts/CHANGELOG.md index 1cb2e0e905b..3b21f5405ac 100644 --- a/contracts/CHANGELOG.md +++ b/contracts/CHANGELOG.md @@ -2,7 +2,8 @@ ## Unreleased -... +- Moved `VRFCoordinatorV2Mock.sol` to src/v0.8/vrf/mocks +- Moved `VRFCoordinatorMock.sol` to src/v0.8/vrf/mocks ## 0.8.0 - 2023-10-04 diff --git a/contracts/scripts/native_solc_compile_all_automation b/contracts/scripts/native_solc_compile_all_automation index 005570f4c12..7e0b6058aed 100755 --- a/contracts/scripts/native_solc_compile_all_automation +++ b/contracts/scripts/native_solc_compile_all_automation @@ -39,9 +39,6 @@ compileContract automation/UpkeepTranscoder.sol compileContract automation/mocks/MockAggregatorProxy.sol compileContract automation/testhelpers/LogUpkeepCounter.sol -# Keepers x VRF v2 -compileContract KeepersVRFConsumer.sol - compileContract automation/mocks/KeeperRegistrar1_2Mock.sol compileContract automation/mocks/KeeperRegistryCheckUpkeepGasUsageWrapper1_2Mock.sol diff --git a/contracts/scripts/native_solc_compile_all_vrf b/contracts/scripts/native_solc_compile_all_vrf index fd9f1b91539..302dc18d2fe 100755 --- a/contracts/scripts/native_solc_compile_all_vrf +++ b/contracts/scripts/native_solc_compile_all_vrf @@ -36,7 +36,7 @@ compileContract vrf/VRFRequestIDBase.sol compileContract vrf/VRFConsumerBase.sol compileContract vrf/testhelpers/VRFConsumer.sol compileContract vrf/testhelpers/VRFRequestIDBaseTestHelper.sol -compileContract mocks/VRFCoordinatorMock.sol +compileContract vrf/mocks/VRFCoordinatorMock.sol # VRF V2 compileContract vrf/VRFConsumerBaseV2.sol @@ -52,34 +52,35 @@ compileContract vrf/BatchBlockhashStore.sol compileContract vrf/BatchVRFCoordinatorV2.sol compileContract vrf/testhelpers/VRFCoordinatorV2TestHelper.sol compileContractAltOpts vrf/VRFCoordinatorV2.sol 10000 -compileContract mocks/VRFCoordinatorV2Mock.sol +compileContract vrf/mocks/VRFCoordinatorV2Mock.sol compileContract vrf/VRFOwner.sol -compileContract dev/VRFSubscriptionBalanceMonitor.sol +compileContract vrf/dev/VRFSubscriptionBalanceMonitor.sol +compileContract vrf/KeepersVRFConsumer.sol # VRF V2Plus -compileContract dev/interfaces/IVRFCoordinatorV2PlusInternal.sol -compileContract dev/vrf/testhelpers/VRFV2PlusConsumerExample.sol -compileContractAltOpts dev/vrf/VRFCoordinatorV2_5.sol 50 -compileContract dev/vrf/BatchVRFCoordinatorV2Plus.sol -compileContract dev/vrf/VRFV2PlusWrapper.sol -compileContract dev/vrf/testhelpers/VRFConsumerV2PlusUpgradeableExample.sol -compileContract dev/vrf/testhelpers/VRFMaliciousConsumerV2Plus.sol -compileContract dev/vrf/testhelpers/VRFV2PlusExternalSubOwnerExample.sol -compileContract dev/vrf/testhelpers/VRFV2PlusSingleConsumerExample.sol -compileContract dev/vrf/testhelpers/VRFV2PlusWrapperConsumerExample.sol -compileContract dev/vrf/testhelpers/VRFV2PlusRevertingExample.sol -compileContract dev/vrf/testhelpers/VRFConsumerV2PlusUpgradeableExample.sol -compileContract dev/vrf/testhelpers/VRFV2PlusMaliciousMigrator.sol -compileContract dev/vrf/libraries/VRFV2PlusClient.sol -compileContract dev/vrf/testhelpers/VRFCoordinatorV2Plus_V2Example.sol -compileContract dev/vrf/TrustedBlockhashStore.sol -compileContract dev/vrf/testhelpers/VRFV2PlusLoadTestWithMetrics.sol -compileContractAltOpts dev/vrf/testhelpers/VRFCoordinatorV2PlusUpgradedVersion.sol 5 -compileContract dev/vrf/testhelpers/VRFV2PlusWrapperLoadTestConsumer.sol +compileContract vrf/dev/interfaces/IVRFCoordinatorV2PlusInternal.sol +compileContract vrf/dev/testhelpers/VRFV2PlusConsumerExample.sol +compileContractAltOpts vrf/dev/VRFCoordinatorV2_5.sol 50 +compileContract vrf/dev/BatchVRFCoordinatorV2Plus.sol +compileContract vrf/dev/VRFV2PlusWrapper.sol +compileContract vrf/dev/testhelpers/VRFConsumerV2PlusUpgradeableExample.sol +compileContract vrf/dev/testhelpers/VRFMaliciousConsumerV2Plus.sol +compileContract vrf/dev/testhelpers/VRFV2PlusExternalSubOwnerExample.sol +compileContract vrf/dev/testhelpers/VRFV2PlusSingleConsumerExample.sol +compileContract vrf/dev/testhelpers/VRFV2PlusWrapperConsumerExample.sol +compileContract vrf/dev/testhelpers/VRFV2PlusRevertingExample.sol +compileContract vrf/dev/testhelpers/VRFConsumerV2PlusUpgradeableExample.sol +compileContract vrf/dev/testhelpers/VRFV2PlusMaliciousMigrator.sol +compileContract vrf/dev/libraries/VRFV2PlusClient.sol +compileContract vrf/dev/testhelpers/VRFCoordinatorV2Plus_V2Example.sol +compileContract vrf/dev/TrustedBlockhashStore.sol +compileContract vrf/dev/testhelpers/VRFV2PlusLoadTestWithMetrics.sol +compileContractAltOpts vrf/dev/testhelpers/VRFCoordinatorV2PlusUpgradedVersion.sol 5 +compileContract vrf/dev/testhelpers/VRFV2PlusWrapperLoadTestConsumer.sol # VRF V2 Wrapper compileContract vrf/VRFV2Wrapper.sol -compileContract interfaces/VRFV2WrapperInterface.sol +compileContract vrf/interfaces/VRFV2WrapperInterface.sol compileContract vrf/VRFV2WrapperConsumerBase.sol compileContract vrf/testhelpers/VRFV2WrapperConsumerExample.sol @@ -91,3 +92,8 @@ compileContract vrf/testhelpers/VRFLoadTestOwnerlessConsumer.sol compileContract vrf/testhelpers/VRFLoadTestExternalSubOwner.sol compileContract vrf/testhelpers/VRFV2LoadTestWithMetrics.sol compileContract vrf/testhelpers/VRFV2OwnerTestConsumer.sol + +# Helper contracts +compileContract vrf/interfaces/IAuthorizedReceiver.sol +compileContract vrf/interfaces/VRFCoordinatorV2Interface.sol +compileContract vrf/interfaces/VRFV2WrapperInterface.sol diff --git a/contracts/src/v0.8/dev/BlockhashStore.sol b/contracts/src/v0.8/dev/BlockhashStore.sol deleted file mode 100644 index 4104be77ed7..00000000000 --- a/contracts/src/v0.8/dev/BlockhashStore.sol +++ /dev/null @@ -1,81 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.6; - -import {ChainSpecificUtil} from "../ChainSpecificUtil.sol"; - -/** - * @title BlockhashStore - * @notice This contract provides a way to access blockhashes older than - * the 256 block limit imposed by the BLOCKHASH opcode. - * You may assume that any blockhash stored by the contract is correct. - * Note that the contract depends on the format of serialized Ethereum - * blocks. If a future hardfork of Ethereum changes that format, the - * logic in this contract may become incorrect and an updated version - * would have to be deployed. - */ -contract BlockhashStore { - mapping(uint256 => bytes32) internal s_blockhashes; - - /** - * @notice stores blockhash of a given block, assuming it is available through BLOCKHASH - * @param n the number of the block whose blockhash should be stored - */ - function store(uint256 n) public { - bytes32 h = ChainSpecificUtil.getBlockhash(uint64(n)); - // solhint-disable-next-line custom-errors - require(h != 0x0, "blockhash(n) failed"); - s_blockhashes[n] = h; - } - - /** - * @notice stores blockhash of the earliest block still available through BLOCKHASH. - */ - function storeEarliest() external { - store(ChainSpecificUtil.getBlockNumber() - 256); - } - - /** - * @notice stores blockhash after verifying blockheader of child/subsequent block - * @param n the number of the block whose blockhash should be stored - * @param header the rlp-encoded blockheader of block n+1. We verify its correctness by checking - * that it hashes to a stored blockhash, and then extract parentHash to get the n-th blockhash. - */ - function storeVerifyHeader(uint256 n, bytes memory header) public { - // solhint-disable-next-line custom-errors - require(keccak256(header) == s_blockhashes[n + 1], "header has unknown blockhash"); - - // At this point, we know that header is the correct blockheader for block n+1. - - // The header is an rlp-encoded list. The head item of that list is the 32-byte blockhash of the parent block. - // Based on how rlp works, we know that blockheaders always have the following form: - // 0xf9____a0PARENTHASH... - // ^ ^ ^ - // | | | - // | | +--- PARENTHASH is 32 bytes. rlpenc(PARENTHASH) is 0xa || PARENTHASH. - // | | - // | +--- 2 bytes containing the sum of the lengths of the encoded list items - // | - // +--- 0xf9 because we have a list and (sum of lengths of encoded list items) fits exactly into two bytes. - // - // As a consequence, the PARENTHASH is always at offset 4 of the rlp-encoded block header. - - bytes32 parentHash; - assembly { - parentHash := mload(add(header, 36)) // 36 = 32 byte offset for length prefix of ABI-encoded array - // + 4 byte offset of PARENTHASH (see above) - } - - s_blockhashes[n] = parentHash; - } - - /** - * @notice gets a blockhash from the store. If no hash is known, this function reverts. - * @param n the number of the block whose blockhash should be returned - */ - function getBlockhash(uint256 n) external view returns (bytes32) { - bytes32 h = s_blockhashes[n]; - // solhint-disable-next-line custom-errors - require(h != 0x0, "blockhash not found in store"); - return h; - } -} diff --git a/contracts/src/v0.8/KeepersVRFConsumer.sol b/contracts/src/v0.8/vrf/KeepersVRFConsumer.sol similarity index 88% rename from contracts/src/v0.8/KeepersVRFConsumer.sol rename to contracts/src/v0.8/vrf/KeepersVRFConsumer.sol index 21fd26290a4..438696c7f4d 100644 --- a/contracts/src/v0.8/KeepersVRFConsumer.sol +++ b/contracts/src/v0.8/vrf/KeepersVRFConsumer.sol @@ -1,9 +1,12 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.6; -import "./automation/KeeperCompatible.sol"; -import "./vrf/VRFConsumerBaseV2.sol"; -import "./interfaces/VRFCoordinatorV2Interface.sol"; +import {AutomationCompatibleInterface as KeeperCompatibleInterface} from "../automation/interfaces/AutomationCompatibleInterface.sol"; +import {VRFConsumerBaseV2} from "./VRFConsumerBaseV2.sol"; +import {VRFCoordinatorV2Interface} from "./interfaces/VRFCoordinatorV2Interface.sol"; + +// solhint-disable chainlink-solidity/prefix-immutable-variables-with-i +// solhint-disable chainlink-solidity/prefix-internal-functions-with-underscore /** * @title KeepersVRFConsumer @@ -85,6 +88,7 @@ contract KeepersVRFConsumer is KeeperCompatibleInterface, VRFConsumerBaseV2 { function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal override { // Check that the request exists. If not, revert. RequestRecord memory record = s_requests[requestId]; + // solhint-disable-next-line custom-errors require(record.requestId == requestId, "request ID not found in map"); // Update the randomness in the record, and increment the response counter. diff --git a/contracts/src/v0.8/vrf/VRFCoordinatorV2.sol b/contracts/src/v0.8/vrf/VRFCoordinatorV2.sol index 92cb0cdb324..0df99bdb081 100644 --- a/contracts/src/v0.8/vrf/VRFCoordinatorV2.sol +++ b/contracts/src/v0.8/vrf/VRFCoordinatorV2.sol @@ -2,9 +2,9 @@ pragma solidity ^0.8.4; import {LinkTokenInterface} from "../shared/interfaces/LinkTokenInterface.sol"; -import {BlockhashStoreInterface} from "../interfaces/BlockhashStoreInterface.sol"; +import {BlockhashStoreInterface} from "./interfaces/BlockhashStoreInterface.sol"; import {AggregatorV3Interface} from "../interfaces/AggregatorV3Interface.sol"; -import {VRFCoordinatorV2Interface} from "../interfaces/VRFCoordinatorV2Interface.sol"; +import {VRFCoordinatorV2Interface} from "./interfaces/VRFCoordinatorV2Interface.sol"; import {TypeAndVersionInterface} from "../interfaces/TypeAndVersionInterface.sol"; import {IERC677Receiver} from "../shared/interfaces/IERC677Receiver.sol"; import {VRF} from "./VRF.sol"; diff --git a/contracts/src/v0.8/vrf/VRFV2Wrapper.sol b/contracts/src/v0.8/vrf/VRFV2Wrapper.sol index 3573b972276..7f066762d3f 100644 --- a/contracts/src/v0.8/vrf/VRFV2Wrapper.sol +++ b/contracts/src/v0.8/vrf/VRFV2Wrapper.sol @@ -7,8 +7,8 @@ import {TypeAndVersionInterface} from "../interfaces/TypeAndVersionInterface.sol import {VRFConsumerBaseV2} from "./VRFConsumerBaseV2.sol"; import {LinkTokenInterface} from "../shared/interfaces/LinkTokenInterface.sol"; import {AggregatorV3Interface} from "../interfaces/AggregatorV3Interface.sol"; -import {VRFCoordinatorV2Interface} from "../interfaces/VRFCoordinatorV2Interface.sol"; -import {VRFV2WrapperInterface} from "../interfaces/VRFV2WrapperInterface.sol"; +import {VRFCoordinatorV2Interface} from "./interfaces/VRFCoordinatorV2Interface.sol"; +import {VRFV2WrapperInterface} from "./interfaces/VRFV2WrapperInterface.sol"; import {VRFV2WrapperConsumerBase} from "./VRFV2WrapperConsumerBase.sol"; import {ChainSpecificUtil} from "../ChainSpecificUtil.sol"; diff --git a/contracts/src/v0.8/vrf/VRFV2WrapperConsumerBase.sol b/contracts/src/v0.8/vrf/VRFV2WrapperConsumerBase.sol index a9c8e5568a9..2876b19dd7b 100644 --- a/contracts/src/v0.8/vrf/VRFV2WrapperConsumerBase.sol +++ b/contracts/src/v0.8/vrf/VRFV2WrapperConsumerBase.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {LinkTokenInterface} from "../shared/interfaces/LinkTokenInterface.sol"; -import {VRFV2WrapperInterface} from "../interfaces/VRFV2WrapperInterface.sol"; +import {VRFV2WrapperInterface} from "./interfaces/VRFV2WrapperInterface.sol"; /** ******************************************************************************* * @notice Interface for contracts using VRF randomness through the VRF V2 wrapper diff --git a/contracts/src/v0.8/dev/vrf/BatchVRFCoordinatorV2Plus.sol b/contracts/src/v0.8/vrf/dev/BatchVRFCoordinatorV2Plus.sol similarity index 98% rename from contracts/src/v0.8/dev/vrf/BatchVRFCoordinatorV2Plus.sol rename to contracts/src/v0.8/vrf/dev/BatchVRFCoordinatorV2Plus.sol index 9247cc21dd5..34b5ff6f189 100644 --- a/contracts/src/v0.8/dev/vrf/BatchVRFCoordinatorV2Plus.sol +++ b/contracts/src/v0.8/vrf/dev/BatchVRFCoordinatorV2Plus.sol @@ -2,7 +2,7 @@ // solhint-disable-next-line one-contract-per-file pragma solidity 0.8.6; -import {VRFTypes} from "../../vrf/VRFTypes.sol"; +import {VRFTypes} from "../VRFTypes.sol"; /** * @title BatchVRFCoordinatorV2Plus diff --git a/contracts/src/v0.8/dev/vrf/BlockhashStore.sol b/contracts/src/v0.8/vrf/dev/BlockhashStore.sol similarity index 100% rename from contracts/src/v0.8/dev/vrf/BlockhashStore.sol rename to contracts/src/v0.8/vrf/dev/BlockhashStore.sol diff --git a/contracts/src/v0.8/dev/vrf/SubscriptionAPI.sol b/contracts/src/v0.8/vrf/dev/SubscriptionAPI.sol similarity index 99% rename from contracts/src/v0.8/dev/vrf/SubscriptionAPI.sol rename to contracts/src/v0.8/vrf/dev/SubscriptionAPI.sol index d79b6daf844..478ff4cce4a 100644 --- a/contracts/src/v0.8/dev/vrf/SubscriptionAPI.sol +++ b/contracts/src/v0.8/vrf/dev/SubscriptionAPI.sol @@ -6,7 +6,7 @@ import {LinkTokenInterface} from "../../shared/interfaces/LinkTokenInterface.sol import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; import {AggregatorV3Interface} from "../../interfaces/AggregatorV3Interface.sol"; import {IERC677Receiver} from "../../shared/interfaces/IERC677Receiver.sol"; -import {IVRFSubscriptionV2Plus} from "../interfaces/IVRFSubscriptionV2Plus.sol"; +import {IVRFSubscriptionV2Plus} from "./interfaces/IVRFSubscriptionV2Plus.sol"; abstract contract SubscriptionAPI is ConfirmedOwner, IERC677Receiver, IVRFSubscriptionV2Plus { using EnumerableSet for EnumerableSet.UintSet; diff --git a/contracts/src/v0.8/dev/vrf/TrustedBlockhashStore.sol b/contracts/src/v0.8/vrf/dev/TrustedBlockhashStore.sol similarity index 100% rename from contracts/src/v0.8/dev/vrf/TrustedBlockhashStore.sol rename to contracts/src/v0.8/vrf/dev/TrustedBlockhashStore.sol diff --git a/contracts/src/v0.8/dev/vrf/VRFConsumerBaseV2Plus.sol b/contracts/src/v0.8/vrf/dev/VRFConsumerBaseV2Plus.sol similarity index 97% rename from contracts/src/v0.8/dev/vrf/VRFConsumerBaseV2Plus.sol rename to contracts/src/v0.8/vrf/dev/VRFConsumerBaseV2Plus.sol index c256630f7c6..fdfbcebaaa2 100644 --- a/contracts/src/v0.8/dev/vrf/VRFConsumerBaseV2Plus.sol +++ b/contracts/src/v0.8/vrf/dev/VRFConsumerBaseV2Plus.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; -import {IVRFCoordinatorV2Plus} from "../interfaces/IVRFCoordinatorV2Plus.sol"; -import {IVRFMigratableConsumerV2Plus} from "../interfaces/IVRFMigratableConsumerV2Plus.sol"; +import {IVRFCoordinatorV2Plus} from "./interfaces/IVRFCoordinatorV2Plus.sol"; +import {IVRFMigratableConsumerV2Plus} from "./interfaces/IVRFMigratableConsumerV2Plus.sol"; import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; /** **************************************************************************** diff --git a/contracts/src/v0.8/dev/VRFConsumerBaseV2Upgradeable.sol b/contracts/src/v0.8/vrf/dev/VRFConsumerBaseV2Upgradeable.sol similarity index 100% rename from contracts/src/v0.8/dev/VRFConsumerBaseV2Upgradeable.sol rename to contracts/src/v0.8/vrf/dev/VRFConsumerBaseV2Upgradeable.sol diff --git a/contracts/src/v0.8/dev/vrf/VRFCoordinatorV2_5.sol b/contracts/src/v0.8/vrf/dev/VRFCoordinatorV2_5.sol similarity index 98% rename from contracts/src/v0.8/dev/vrf/VRFCoordinatorV2_5.sol rename to contracts/src/v0.8/vrf/dev/VRFCoordinatorV2_5.sol index d69fa38c096..3bccf50c6ea 100644 --- a/contracts/src/v0.8/dev/vrf/VRFCoordinatorV2_5.sol +++ b/contracts/src/v0.8/vrf/dev/VRFCoordinatorV2_5.sol @@ -1,15 +1,15 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; -import {BlockhashStoreInterface} from "../../interfaces/BlockhashStoreInterface.sol"; +import {BlockhashStoreInterface} from "../interfaces/BlockhashStoreInterface.sol"; import {VRF} from "../../vrf/VRF.sol"; import {VRFConsumerBaseV2Plus, IVRFMigratableConsumerV2Plus} from "./VRFConsumerBaseV2Plus.sol"; import {ChainSpecificUtil} from "../../ChainSpecificUtil.sol"; import {SubscriptionAPI} from "./SubscriptionAPI.sol"; import {VRFV2PlusClient} from "./libraries/VRFV2PlusClient.sol"; -import {IVRFCoordinatorV2PlusMigration} from "../interfaces/IVRFCoordinatorV2PlusMigration.sol"; +import {IVRFCoordinatorV2PlusMigration} from "./interfaces/IVRFCoordinatorV2PlusMigration.sol"; // solhint-disable-next-line no-unused-import -import {IVRFCoordinatorV2Plus, IVRFSubscriptionV2Plus} from "../interfaces/IVRFCoordinatorV2Plus.sol"; +import {IVRFCoordinatorV2Plus, IVRFSubscriptionV2Plus} from "./interfaces/IVRFCoordinatorV2Plus.sol"; // solhint-disable-next-line contract-name-camelcase contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus { diff --git a/contracts/src/v0.8/dev/VRFSubscriptionBalanceMonitor.sol b/contracts/src/v0.8/vrf/dev/VRFSubscriptionBalanceMonitor.sol similarity index 97% rename from contracts/src/v0.8/dev/VRFSubscriptionBalanceMonitor.sol rename to contracts/src/v0.8/vrf/dev/VRFSubscriptionBalanceMonitor.sol index 958ecdc1bad..2dd44c8b1a8 100644 --- a/contracts/src/v0.8/dev/VRFSubscriptionBalanceMonitor.sol +++ b/contracts/src/v0.8/vrf/dev/VRFSubscriptionBalanceMonitor.sol @@ -2,10 +2,10 @@ pragma solidity 0.8.6; -import {ConfirmedOwner} from "../shared/access/ConfirmedOwner.sol"; -import {AutomationCompatibleInterface as KeeperCompatibleInterface} from "../automation/interfaces/AutomationCompatibleInterface.sol"; +import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; +import {AutomationCompatibleInterface as KeeperCompatibleInterface} from "../../automation/interfaces/AutomationCompatibleInterface.sol"; import {VRFCoordinatorV2Interface} from "../interfaces/VRFCoordinatorV2Interface.sol"; -import {LinkTokenInterface} from "../shared/interfaces/LinkTokenInterface.sol"; +import {LinkTokenInterface} from "../../shared/interfaces/LinkTokenInterface.sol"; import {Pausable} from "@openzeppelin/contracts/security/Pausable.sol"; /** diff --git a/contracts/src/v0.8/dev/vrf/VRFV2PlusWrapper.sol b/contracts/src/v0.8/vrf/dev/VRFV2PlusWrapper.sol similarity index 99% rename from contracts/src/v0.8/dev/vrf/VRFV2PlusWrapper.sol rename to contracts/src/v0.8/vrf/dev/VRFV2PlusWrapper.sol index 29573aa2363..6953d2eb6e5 100644 --- a/contracts/src/v0.8/dev/vrf/VRFV2PlusWrapper.sol +++ b/contracts/src/v0.8/vrf/dev/VRFV2PlusWrapper.sol @@ -3,12 +3,12 @@ pragma solidity ^0.8.6; import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; import {TypeAndVersionInterface} from "../../interfaces/TypeAndVersionInterface.sol"; -import {IVRFV2PlusMigrate} from "../interfaces/IVRFV2PlusMigrate.sol"; +import {IVRFV2PlusMigrate} from "./interfaces/IVRFV2PlusMigrate.sol"; import {VRFConsumerBaseV2Plus} from "./VRFConsumerBaseV2Plus.sol"; import {LinkTokenInterface} from "../../shared/interfaces/LinkTokenInterface.sol"; import {AggregatorV3Interface} from "../../interfaces/AggregatorV3Interface.sol"; import {VRFV2PlusClient} from "./libraries/VRFV2PlusClient.sol"; -import {IVRFV2PlusWrapper} from "../interfaces/IVRFV2PlusWrapper.sol"; +import {IVRFV2PlusWrapper} from "./interfaces/IVRFV2PlusWrapper.sol"; import {VRFV2PlusWrapperConsumerBase} from "./VRFV2PlusWrapperConsumerBase.sol"; import {ChainSpecificUtil} from "../../ChainSpecificUtil.sol"; diff --git a/contracts/src/v0.8/dev/vrf/VRFV2PlusWrapperConsumerBase.sol b/contracts/src/v0.8/vrf/dev/VRFV2PlusWrapperConsumerBase.sol similarity index 98% rename from contracts/src/v0.8/dev/vrf/VRFV2PlusWrapperConsumerBase.sol rename to contracts/src/v0.8/vrf/dev/VRFV2PlusWrapperConsumerBase.sol index e800753af2b..dd450c9f94a 100644 --- a/contracts/src/v0.8/dev/vrf/VRFV2PlusWrapperConsumerBase.sol +++ b/contracts/src/v0.8/vrf/dev/VRFV2PlusWrapperConsumerBase.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {LinkTokenInterface} from "../../shared/interfaces/LinkTokenInterface.sol"; -import {IVRFV2PlusWrapper} from "../interfaces/IVRFV2PlusWrapper.sol"; +import {IVRFV2PlusWrapper} from "./interfaces/IVRFV2PlusWrapper.sol"; /** * diff --git a/contracts/src/v0.8/dev/interfaces/IVRFCoordinatorV2Plus.sol b/contracts/src/v0.8/vrf/dev/interfaces/IVRFCoordinatorV2Plus.sol similarity index 96% rename from contracts/src/v0.8/dev/interfaces/IVRFCoordinatorV2Plus.sol rename to contracts/src/v0.8/vrf/dev/interfaces/IVRFCoordinatorV2Plus.sol index 20c60b593da..846da0b1edc 100644 --- a/contracts/src/v0.8/dev/interfaces/IVRFCoordinatorV2Plus.sol +++ b/contracts/src/v0.8/vrf/dev/interfaces/IVRFCoordinatorV2Plus.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import {VRFV2PlusClient} from "../vrf/libraries/VRFV2PlusClient.sol"; +import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; import {IVRFSubscriptionV2Plus} from "./IVRFSubscriptionV2Plus.sol"; // Interface that enables consumers of VRFCoordinatorV2Plus to be future-proof for upgrades diff --git a/contracts/src/v0.8/dev/interfaces/IVRFCoordinatorV2PlusInternal.sol b/contracts/src/v0.8/vrf/dev/interfaces/IVRFCoordinatorV2PlusInternal.sol similarity index 100% rename from contracts/src/v0.8/dev/interfaces/IVRFCoordinatorV2PlusInternal.sol rename to contracts/src/v0.8/vrf/dev/interfaces/IVRFCoordinatorV2PlusInternal.sol diff --git a/contracts/src/v0.8/dev/interfaces/IVRFCoordinatorV2PlusMigration.sol b/contracts/src/v0.8/vrf/dev/interfaces/IVRFCoordinatorV2PlusMigration.sol similarity index 100% rename from contracts/src/v0.8/dev/interfaces/IVRFCoordinatorV2PlusMigration.sol rename to contracts/src/v0.8/vrf/dev/interfaces/IVRFCoordinatorV2PlusMigration.sol diff --git a/contracts/src/v0.8/dev/interfaces/IVRFMigratableConsumerV2Plus.sol b/contracts/src/v0.8/vrf/dev/interfaces/IVRFMigratableConsumerV2Plus.sol similarity index 100% rename from contracts/src/v0.8/dev/interfaces/IVRFMigratableConsumerV2Plus.sol rename to contracts/src/v0.8/vrf/dev/interfaces/IVRFMigratableConsumerV2Plus.sol diff --git a/contracts/src/v0.8/dev/interfaces/IVRFSubscriptionV2Plus.sol b/contracts/src/v0.8/vrf/dev/interfaces/IVRFSubscriptionV2Plus.sol similarity index 100% rename from contracts/src/v0.8/dev/interfaces/IVRFSubscriptionV2Plus.sol rename to contracts/src/v0.8/vrf/dev/interfaces/IVRFSubscriptionV2Plus.sol diff --git a/contracts/src/v0.8/dev/interfaces/IVRFV2PlusMigrate.sol b/contracts/src/v0.8/vrf/dev/interfaces/IVRFV2PlusMigrate.sol similarity index 100% rename from contracts/src/v0.8/dev/interfaces/IVRFV2PlusMigrate.sol rename to contracts/src/v0.8/vrf/dev/interfaces/IVRFV2PlusMigrate.sol diff --git a/contracts/src/v0.8/dev/interfaces/IVRFV2PlusWrapper.sol b/contracts/src/v0.8/vrf/dev/interfaces/IVRFV2PlusWrapper.sol similarity index 100% rename from contracts/src/v0.8/dev/interfaces/IVRFV2PlusWrapper.sol rename to contracts/src/v0.8/vrf/dev/interfaces/IVRFV2PlusWrapper.sol diff --git a/contracts/src/v0.8/dev/vrf/libraries/VRFV2PlusClient.sol b/contracts/src/v0.8/vrf/dev/libraries/VRFV2PlusClient.sol similarity index 100% rename from contracts/src/v0.8/dev/vrf/libraries/VRFV2PlusClient.sol rename to contracts/src/v0.8/vrf/dev/libraries/VRFV2PlusClient.sol diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/ExposedVRFCoordinatorV2_5.sol b/contracts/src/v0.8/vrf/dev/testhelpers/ExposedVRFCoordinatorV2_5.sol similarity index 100% rename from contracts/src/v0.8/dev/vrf/testhelpers/ExposedVRFCoordinatorV2_5.sol rename to contracts/src/v0.8/vrf/dev/testhelpers/ExposedVRFCoordinatorV2_5.sol diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFConsumerV2PlusUpgradeableExample.sol b/contracts/src/v0.8/vrf/dev/testhelpers/VRFConsumerV2PlusUpgradeableExample.sol similarity index 94% rename from contracts/src/v0.8/dev/vrf/testhelpers/VRFConsumerV2PlusUpgradeableExample.sol rename to contracts/src/v0.8/vrf/dev/testhelpers/VRFConsumerV2PlusUpgradeableExample.sol index 1211014cd2f..aeaaf4ba266 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFConsumerV2PlusUpgradeableExample.sol +++ b/contracts/src/v0.8/vrf/dev/testhelpers/VRFConsumerV2PlusUpgradeableExample.sol @@ -2,8 +2,8 @@ pragma solidity ^0.8.0; import {LinkTokenInterface} from "../../../shared/interfaces/LinkTokenInterface.sol"; -import {IVRFCoordinatorV2Plus} from "../../interfaces/IVRFCoordinatorV2Plus.sol"; -import {VRFConsumerBaseV2Upgradeable} from "../../VRFConsumerBaseV2Upgradeable.sol"; +import {IVRFCoordinatorV2Plus} from "../interfaces/IVRFCoordinatorV2Plus.sol"; +import {VRFConsumerBaseV2Upgradeable} from "../VRFConsumerBaseV2Upgradeable.sol"; import {Initializable} from "@openzeppelin/contracts-upgradeable-4.7.3/proxy/utils/Initializable.sol"; import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFCoordinatorV2PlusUpgradedVersion.sol b/contracts/src/v0.8/vrf/dev/testhelpers/VRFCoordinatorV2PlusUpgradedVersion.sol similarity index 99% rename from contracts/src/v0.8/dev/vrf/testhelpers/VRFCoordinatorV2PlusUpgradedVersion.sol rename to contracts/src/v0.8/vrf/dev/testhelpers/VRFCoordinatorV2PlusUpgradedVersion.sol index 07b55388e10..5b2e2322285 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFCoordinatorV2PlusUpgradedVersion.sol +++ b/contracts/src/v0.8/vrf/dev/testhelpers/VRFCoordinatorV2PlusUpgradedVersion.sol @@ -1,15 +1,15 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; -import {BlockhashStoreInterface} from "../../../interfaces/BlockhashStoreInterface.sol"; +import {BlockhashStoreInterface} from "../../interfaces/BlockhashStoreInterface.sol"; // solhint-disable-next-line no-unused-import -import {IVRFCoordinatorV2Plus, IVRFSubscriptionV2Plus} from "../../interfaces/IVRFCoordinatorV2Plus.sol"; +import {IVRFCoordinatorV2Plus, IVRFSubscriptionV2Plus} from "../interfaces/IVRFCoordinatorV2Plus.sol"; import {VRF} from "../../../vrf/VRF.sol"; import {VRFConsumerBaseV2Plus, IVRFMigratableConsumerV2Plus} from "../VRFConsumerBaseV2Plus.sol"; import {ChainSpecificUtil} from "../../../ChainSpecificUtil.sol"; import {SubscriptionAPI} from "../SubscriptionAPI.sol"; import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; -import {IVRFCoordinatorV2PlusMigration} from "../../interfaces/IVRFCoordinatorV2PlusMigration.sol"; +import {IVRFCoordinatorV2PlusMigration} from "../interfaces/IVRFCoordinatorV2PlusMigration.sol"; import {EnumerableSet} from "../../../vendor/openzeppelin-solidity/v4.7.3/contracts/utils/structs/EnumerableSet.sol"; contract VRFCoordinatorV2PlusUpgradedVersion is diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFCoordinatorV2Plus_V2Example.sol b/contracts/src/v0.8/vrf/dev/testhelpers/VRFCoordinatorV2Plus_V2Example.sol similarity index 98% rename from contracts/src/v0.8/dev/vrf/testhelpers/VRFCoordinatorV2Plus_V2Example.sol rename to contracts/src/v0.8/vrf/dev/testhelpers/VRFCoordinatorV2Plus_V2Example.sol index 7306931570a..af49abbf6b5 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFCoordinatorV2Plus_V2Example.sol +++ b/contracts/src/v0.8/vrf/dev/testhelpers/VRFCoordinatorV2Plus_V2Example.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.4; -import {IVRFCoordinatorV2PlusMigration} from "../../interfaces/IVRFCoordinatorV2PlusMigration.sol"; +import {IVRFCoordinatorV2PlusMigration} from "../interfaces/IVRFCoordinatorV2PlusMigration.sol"; import {VRFConsumerBaseV2Plus} from "../VRFConsumerBaseV2Plus.sol"; import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFMaliciousConsumerV2Plus.sol b/contracts/src/v0.8/vrf/dev/testhelpers/VRFMaliciousConsumerV2Plus.sol similarity index 96% rename from contracts/src/v0.8/dev/vrf/testhelpers/VRFMaliciousConsumerV2Plus.sol rename to contracts/src/v0.8/vrf/dev/testhelpers/VRFMaliciousConsumerV2Plus.sol index cc3e465bc0c..7ddbb448ab9 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFMaliciousConsumerV2Plus.sol +++ b/contracts/src/v0.8/vrf/dev/testhelpers/VRFMaliciousConsumerV2Plus.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {LinkTokenInterface} from "../../../shared/interfaces/LinkTokenInterface.sol"; -import {IVRFCoordinatorV2Plus} from "../../interfaces/IVRFCoordinatorV2Plus.sol"; +import {IVRFCoordinatorV2Plus} from "../interfaces/IVRFCoordinatorV2Plus.sol"; import {VRFConsumerBaseV2Plus} from "../VRFConsumerBaseV2Plus.sol"; import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusConsumerExample.sol b/contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusConsumerExample.sol similarity index 98% rename from contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusConsumerExample.sol rename to contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusConsumerExample.sol index 8acc0ce6d0b..6898e101f82 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusConsumerExample.sol +++ b/contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusConsumerExample.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {LinkTokenInterface} from "../../../shared/interfaces/LinkTokenInterface.sol"; -import {IVRFCoordinatorV2Plus} from "../../interfaces/IVRFCoordinatorV2Plus.sol"; +import {IVRFCoordinatorV2Plus} from "../interfaces/IVRFCoordinatorV2Plus.sol"; import {VRFConsumerBaseV2Plus} from "../VRFConsumerBaseV2Plus.sol"; import {ConfirmedOwner} from "../../../shared/access/ConfirmedOwner.sol"; import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusExternalSubOwnerExample.sol b/contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusExternalSubOwnerExample.sol similarity index 96% rename from contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusExternalSubOwnerExample.sol rename to contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusExternalSubOwnerExample.sol index 384a5890018..4fe7381b5f2 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusExternalSubOwnerExample.sol +++ b/contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusExternalSubOwnerExample.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {LinkTokenInterface} from "../../../shared/interfaces/LinkTokenInterface.sol"; -import {IVRFCoordinatorV2Plus} from "../../interfaces/IVRFCoordinatorV2Plus.sol"; +import {IVRFCoordinatorV2Plus} from "../interfaces/IVRFCoordinatorV2Plus.sol"; import {VRFConsumerBaseV2Plus} from "../VRFConsumerBaseV2Plus.sol"; import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusLoadTestWithMetrics.sol b/contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusLoadTestWithMetrics.sol similarity index 100% rename from contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusLoadTestWithMetrics.sol rename to contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusLoadTestWithMetrics.sol diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusMaliciousMigrator.sol b/contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusMaliciousMigrator.sol similarity index 82% rename from contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusMaliciousMigrator.sol rename to contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusMaliciousMigrator.sol index 2be0024ae71..16797bb9390 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusMaliciousMigrator.sol +++ b/contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusMaliciousMigrator.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.0; -import {IVRFMigratableConsumerV2Plus} from "../../interfaces/IVRFMigratableConsumerV2Plus.sol"; -import {IVRFCoordinatorV2Plus} from "../../interfaces/IVRFCoordinatorV2Plus.sol"; +import {IVRFMigratableConsumerV2Plus} from "../interfaces/IVRFMigratableConsumerV2Plus.sol"; +import {IVRFCoordinatorV2Plus} from "../interfaces/IVRFCoordinatorV2Plus.sol"; import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; contract VRFV2PlusMaliciousMigrator is IVRFMigratableConsumerV2Plus { diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusRevertingExample.sol b/contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusRevertingExample.sol similarity index 97% rename from contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusRevertingExample.sol rename to contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusRevertingExample.sol index 170ff9dd6e9..10c79a1af5c 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusRevertingExample.sol +++ b/contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusRevertingExample.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.0; import {LinkTokenInterface} from "../../../shared/interfaces/LinkTokenInterface.sol"; -import {IVRFCoordinatorV2Plus} from "../../interfaces/IVRFCoordinatorV2Plus.sol"; +import {IVRFCoordinatorV2Plus} from "../interfaces/IVRFCoordinatorV2Plus.sol"; import {VRFConsumerBaseV2Plus} from "../VRFConsumerBaseV2Plus.sol"; import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusSingleConsumerExample.sol b/contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusSingleConsumerExample.sol similarity index 98% rename from contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusSingleConsumerExample.sol rename to contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusSingleConsumerExample.sol index b190ebc8715..5d16a9674d2 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusSingleConsumerExample.sol +++ b/contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusSingleConsumerExample.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.0; import {LinkTokenInterface} from "../../../shared/interfaces/LinkTokenInterface.sol"; -import {IVRFCoordinatorV2Plus} from "../../interfaces/IVRFCoordinatorV2Plus.sol"; +import {IVRFCoordinatorV2Plus} from "../interfaces/IVRFCoordinatorV2Plus.sol"; import {VRFConsumerBaseV2Plus} from "../VRFConsumerBaseV2Plus.sol"; import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusWrapperConsumerExample.sol b/contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusWrapperConsumerExample.sol similarity index 100% rename from contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusWrapperConsumerExample.sol rename to contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusWrapperConsumerExample.sol diff --git a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusWrapperLoadTestConsumer.sol b/contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusWrapperLoadTestConsumer.sol similarity index 98% rename from contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusWrapperLoadTestConsumer.sol rename to contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusWrapperLoadTestConsumer.sol index 7b6df2c563e..7293c9a2041 100644 --- a/contracts/src/v0.8/dev/vrf/testhelpers/VRFV2PlusWrapperLoadTestConsumer.sol +++ b/contracts/src/v0.8/vrf/dev/testhelpers/VRFV2PlusWrapperLoadTestConsumer.sol @@ -5,7 +5,7 @@ import {VRFV2PlusWrapperConsumerBase} from "../VRFV2PlusWrapperConsumerBase.sol" import {ConfirmedOwner} from "../../../shared/access/ConfirmedOwner.sol"; import {ChainSpecificUtil} from "../../../ChainSpecificUtil.sol"; import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol"; -import {IVRFV2PlusWrapper} from "../../interfaces/IVRFV2PlusWrapper.sol"; +import {IVRFV2PlusWrapper} from "../interfaces/IVRFV2PlusWrapper.sol"; contract VRFV2PlusWrapperLoadTestConsumer is VRFV2PlusWrapperConsumerBase, ConfirmedOwner { uint256 public s_responseCount; diff --git a/contracts/src/v0.8/interfaces/BlockhashStoreInterface.sol b/contracts/src/v0.8/vrf/interfaces/BlockhashStoreInterface.sol similarity index 100% rename from contracts/src/v0.8/interfaces/BlockhashStoreInterface.sol rename to contracts/src/v0.8/vrf/interfaces/BlockhashStoreInterface.sol diff --git a/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol b/contracts/src/v0.8/vrf/interfaces/VRFCoordinatorV2Interface.sol similarity index 100% rename from contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol rename to contracts/src/v0.8/vrf/interfaces/VRFCoordinatorV2Interface.sol diff --git a/contracts/src/v0.8/interfaces/VRFV2WrapperInterface.sol b/contracts/src/v0.8/vrf/interfaces/VRFV2WrapperInterface.sol similarity index 100% rename from contracts/src/v0.8/interfaces/VRFV2WrapperInterface.sol rename to contracts/src/v0.8/vrf/interfaces/VRFV2WrapperInterface.sol diff --git a/contracts/src/v0.8/mocks/VRFCoordinatorMock.sol b/contracts/src/v0.8/vrf/mocks/VRFCoordinatorMock.sol similarity index 77% rename from contracts/src/v0.8/mocks/VRFCoordinatorMock.sol rename to contracts/src/v0.8/vrf/mocks/VRFCoordinatorMock.sol index 7e179d5a445..6695e79b052 100644 --- a/contracts/src/v0.8/mocks/VRFCoordinatorMock.sol +++ b/contracts/src/v0.8/vrf/mocks/VRFCoordinatorMock.sol @@ -1,15 +1,17 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../shared/interfaces/LinkTokenInterface.sol"; -import "../vrf/VRFConsumerBase.sol"; +import {LinkTokenInterface} from "../../shared/interfaces/LinkTokenInterface.sol"; +import {VRFConsumerBase} from "../../vrf/VRFConsumerBase.sol"; + +// solhint-disable custom-errors contract VRFCoordinatorMock { LinkTokenInterface public LINK; event RandomnessRequest(address indexed sender, bytes32 indexed keyHash, uint256 indexed seed, uint256 fee); - constructor(address linkAddress) public { + constructor(address linkAddress) { LINK = LinkTokenInterface(linkAddress); } @@ -23,6 +25,7 @@ contract VRFCoordinatorMock { bytes memory resp = abi.encodeWithSelector(v.rawFulfillRandomness.selector, requestId, randomness); uint256 b = 206000; require(gasleft() >= b, "not enough gas for consumer"); + // solhint-disable-next-line avoid-low-level-calls, no-unused-vars (bool success, ) = consumerContract.call(resp); } diff --git a/contracts/src/v0.8/mocks/VRFCoordinatorV2Mock.sol b/contracts/src/v0.8/vrf/mocks/VRFCoordinatorV2Mock.sol similarity index 92% rename from contracts/src/v0.8/mocks/VRFCoordinatorV2Mock.sol rename to contracts/src/v0.8/vrf/mocks/VRFCoordinatorV2Mock.sol index a263a3be500..b605815f7eb 100644 --- a/contracts/src/v0.8/mocks/VRFCoordinatorV2Mock.sol +++ b/contracts/src/v0.8/vrf/mocks/VRFCoordinatorV2Mock.sol @@ -2,10 +2,13 @@ // A mock for testing code that relies on VRFCoordinatorV2. pragma solidity ^0.8.4; -import "../shared/interfaces/LinkTokenInterface.sol"; -import "../interfaces/VRFCoordinatorV2Interface.sol"; -import "../vrf/VRFConsumerBaseV2.sol"; -import "../shared/access/ConfirmedOwner.sol"; +import {VRFCoordinatorV2Interface} from "../interfaces/VRFCoordinatorV2Interface.sol"; +import {VRFConsumerBaseV2} from "../VRFConsumerBaseV2.sol"; +import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; + +// solhint-disable chainlink-solidity/prefix-immutable-variables-with-i +// solhint-disable custom-errors +// solhint-disable avoid-low-level-calls contract VRFCoordinatorV2Mock is VRFCoordinatorV2Interface, ConfirmedOwner { uint96 public immutable BASE_FEE; @@ -43,22 +46,22 @@ contract VRFCoordinatorV2Mock is VRFCoordinatorV2Interface, ConfirmedOwner { bool reentrancyLock; } Config private s_config; - uint64 s_currentSubId; - uint256 s_nextRequestId = 1; - uint256 s_nextPreSeed = 100; + uint64 internal s_currentSubId; + uint256 internal s_nextRequestId = 1; + uint256 internal s_nextPreSeed = 100; struct Subscription { address owner; uint96 balance; } - mapping(uint64 => Subscription) s_subscriptions; /* subId */ /* subscription */ - mapping(uint64 => address[]) s_consumers; /* subId */ /* consumers */ + mapping(uint64 => Subscription) internal s_subscriptions; /* subId */ /* subscription */ + mapping(uint64 => address[]) internal s_consumers; /* subId */ /* consumers */ struct Request { uint64 subId; uint32 callbackGasLimit; uint32 numWords; } - mapping(uint256 => Request) s_requests; /* requestId */ /* request */ + mapping(uint256 => Request) internal s_requests; /* requestId */ /* request */ constructor(uint96 _baseFee, uint96 _gasPriceLink) ConfirmedOwner(msg.sender) { BASE_FEE = _baseFee; diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFConsumer.sol b/contracts/src/v0.8/vrf/testhelpers/VRFConsumer.sol index 2f063e67267..eaac0be11b1 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFConsumer.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFConsumer.sol @@ -1,8 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../shared/interfaces/LinkTokenInterface.sol"; -import "../VRFConsumerBase.sol"; +import {VRFConsumerBase} from "../VRFConsumerBase.sol"; contract VRFConsumer is VRFConsumerBase { uint256 public randomnessOutput; diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFConsumerV2.sol b/contracts/src/v0.8/vrf/testhelpers/VRFConsumerV2.sol index 466451c7b6a..e2502fad3ed 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFConsumerV2.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFConsumerV2.sol @@ -1,15 +1,15 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../shared/interfaces/LinkTokenInterface.sol"; -import "../../interfaces/VRFCoordinatorV2Interface.sol"; -import "../VRFConsumerBaseV2.sol"; +import {LinkTokenInterface} from "../../shared/interfaces/LinkTokenInterface.sol"; +import {VRFCoordinatorV2Interface} from "../interfaces/VRFCoordinatorV2Interface.sol"; +import {VRFConsumerBaseV2} from "../VRFConsumerBaseV2.sol"; contract VRFConsumerV2 is VRFConsumerBaseV2 { uint256[] public s_randomWords; uint256 public s_requestId; - VRFCoordinatorV2Interface COORDINATOR; - LinkTokenInterface LINKTOKEN; + VRFCoordinatorV2Interface internal COORDINATOR; + LinkTokenInterface internal LINKTOKEN; uint64 public s_subId; uint256 public s_gasAvailable; diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFConsumerV2UpgradeableExample.sol b/contracts/src/v0.8/vrf/testhelpers/VRFConsumerV2UpgradeableExample.sol index b99abedf3c7..1bd11fc2249 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFConsumerV2UpgradeableExample.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFConsumerV2UpgradeableExample.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../shared/interfaces/LinkTokenInterface.sol"; -import "../../interfaces/VRFCoordinatorV2Interface.sol"; -import "../../dev/VRFConsumerBaseV2Upgradeable.sol"; -import "@openzeppelin/contracts-upgradeable-4.7.3/proxy/utils/Initializable.sol"; +import {LinkTokenInterface} from "../../shared/interfaces/LinkTokenInterface.sol"; +import {VRFCoordinatorV2Interface} from "../interfaces/VRFCoordinatorV2Interface.sol"; +import {VRFConsumerBaseV2Upgradeable} from "../dev/VRFConsumerBaseV2Upgradeable.sol"; +import {Initializable} from "@openzeppelin/contracts-upgradeable-4.7.3/proxy/utils/Initializable.sol"; contract VRFConsumerV2UpgradeableExample is Initializable, VRFConsumerBaseV2Upgradeable { uint256[] public s_randomWords; diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFCoordinatorV2TestHelper.sol b/contracts/src/v0.8/vrf/testhelpers/VRFCoordinatorV2TestHelper.sol index 5d336594e5e..f9385329686 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFCoordinatorV2TestHelper.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFCoordinatorV2TestHelper.sol @@ -1,12 +1,12 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../interfaces/AggregatorV3Interface.sol"; +import {AggregatorV3Interface} from "../../interfaces/AggregatorV3Interface.sol"; // Ideally this contract should inherit from VRFCoordinatorV2 and delegate calls to VRFCoordinatorV2 // However, due to exceeding contract size limit, the logic from VRFCoordinatorV2 is ported over to this contract contract VRFCoordinatorV2TestHelper { - uint96 s_paymentAmount; + uint96 internal s_paymentAmount; AggregatorV3Interface public immutable LINK_ETH_FEED; diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFExternalSubOwnerExample.sol b/contracts/src/v0.8/vrf/testhelpers/VRFExternalSubOwnerExample.sol index f6b171cb508..ee2a71df71b 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFExternalSubOwnerExample.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFExternalSubOwnerExample.sol @@ -1,17 +1,17 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../shared/interfaces/LinkTokenInterface.sol"; -import "../../interfaces/VRFCoordinatorV2Interface.sol"; -import "../VRFConsumerBaseV2.sol"; +import {LinkTokenInterface} from "../../shared/interfaces/LinkTokenInterface.sol"; +import {VRFCoordinatorV2Interface} from "../interfaces/VRFCoordinatorV2Interface.sol"; +import {VRFConsumerBaseV2} from "../VRFConsumerBaseV2.sol"; contract VRFExternalSubOwnerExample is VRFConsumerBaseV2 { - VRFCoordinatorV2Interface COORDINATOR; - LinkTokenInterface LINKTOKEN; + VRFCoordinatorV2Interface internal COORDINATOR; + LinkTokenInterface internal LINKTOKEN; uint256[] public s_randomWords; uint256 public s_requestId; - address s_owner; + address internal s_owner; constructor(address vrfCoordinator, address link) VRFConsumerBaseV2(vrfCoordinator) { COORDINATOR = VRFCoordinatorV2Interface(vrfCoordinator); diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFLoadTestExternalSubOwner.sol b/contracts/src/v0.8/vrf/testhelpers/VRFLoadTestExternalSubOwner.sol index b4bf37990d7..0193e3f67f0 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFLoadTestExternalSubOwner.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFLoadTestExternalSubOwner.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../shared/interfaces/LinkTokenInterface.sol"; -import "../../interfaces/VRFCoordinatorV2Interface.sol"; -import "../VRFConsumerBaseV2.sol"; -import "../../shared/access/ConfirmedOwner.sol"; +import {LinkTokenInterface} from "../../shared/interfaces/LinkTokenInterface.sol"; +import {VRFCoordinatorV2Interface} from "../interfaces/VRFCoordinatorV2Interface.sol"; +import {VRFConsumerBaseV2} from "../VRFConsumerBaseV2.sol"; +import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; /** * @title The VRFLoadTestExternalSubOwner contract. diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFLoadTestOwnerlessConsumer.sol b/contracts/src/v0.8/vrf/testhelpers/VRFLoadTestOwnerlessConsumer.sol index 93c75298d9e..a967c8a565e 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFLoadTestOwnerlessConsumer.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFLoadTestOwnerlessConsumer.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../VRFConsumerBase.sol"; -import "../../shared/interfaces/IERC677Receiver.sol"; +import {VRFConsumerBase} from "../VRFConsumerBase.sol"; +import {IERC677Receiver} from "../../shared/interfaces/IERC677Receiver.sol"; /** * @title The VRFLoadTestOwnerlessConsumer contract. diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFMaliciousConsumerV2.sol b/contracts/src/v0.8/vrf/testhelpers/VRFMaliciousConsumerV2.sol index f11fcc0b7d0..be416e9a5cf 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFMaliciousConsumerV2.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFMaliciousConsumerV2.sol @@ -1,18 +1,18 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../shared/interfaces/LinkTokenInterface.sol"; -import "../../interfaces/VRFCoordinatorV2Interface.sol"; -import "../VRFConsumerBaseV2.sol"; +import {LinkTokenInterface} from "../../shared/interfaces/LinkTokenInterface.sol"; +import {VRFCoordinatorV2Interface} from "../interfaces/VRFCoordinatorV2Interface.sol"; +import {VRFConsumerBaseV2} from "../VRFConsumerBaseV2.sol"; contract VRFMaliciousConsumerV2 is VRFConsumerBaseV2 { uint256[] public s_randomWords; uint256 public s_requestId; - VRFCoordinatorV2Interface COORDINATOR; - LinkTokenInterface LINKTOKEN; + VRFCoordinatorV2Interface internal COORDINATOR; + LinkTokenInterface internal LINKTOKEN; uint64 public s_subId; uint256 public s_gasAvailable; - bytes32 s_keyHash; + bytes32 internal s_keyHash; constructor(address vrfCoordinator, address link) VRFConsumerBaseV2(vrfCoordinator) { COORDINATOR = VRFCoordinatorV2Interface(vrfCoordinator); diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFOwnerlessConsumerExample.sol b/contracts/src/v0.8/vrf/testhelpers/VRFOwnerlessConsumerExample.sol index 0eeb5ebc8f1..a641267597c 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFOwnerlessConsumerExample.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFOwnerlessConsumerExample.sol @@ -3,8 +3,8 @@ // contract. pragma solidity ^0.8.4; -import "../VRFConsumerBase.sol"; -import "../../shared/interfaces/IERC677Receiver.sol"; +import {VRFConsumerBase} from "../VRFConsumerBase.sol"; +import {IERC677Receiver} from "../../shared/interfaces/IERC677Receiver.sol"; contract VRFOwnerlessConsumerExample is VRFConsumerBase, IERC677Receiver { uint256 public s_randomnessOutput; diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFRequestIDBaseTestHelper.sol b/contracts/src/v0.8/vrf/testhelpers/VRFRequestIDBaseTestHelper.sol index b97a835a94d..344797f0df3 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFRequestIDBaseTestHelper.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFRequestIDBaseTestHelper.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../VRFRequestIDBase.sol"; +import {VRFRequestIDBase} from "../VRFRequestIDBase.sol"; contract VRFRequestIDBaseTestHelper is VRFRequestIDBase { function makeVRFInputSeed_( diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFSingleConsumerExample.sol b/contracts/src/v0.8/vrf/testhelpers/VRFSingleConsumerExample.sol index d4dd7b9087a..303394ee888 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFSingleConsumerExample.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFSingleConsumerExample.sol @@ -2,13 +2,13 @@ // Example of a single consumer contract which owns the subscription. pragma solidity ^0.8.0; -import "../../shared/interfaces/LinkTokenInterface.sol"; -import "../../interfaces/VRFCoordinatorV2Interface.sol"; -import "../VRFConsumerBaseV2.sol"; +import {LinkTokenInterface} from "../../shared/interfaces/LinkTokenInterface.sol"; +import {VRFCoordinatorV2Interface} from "../interfaces/VRFCoordinatorV2Interface.sol"; +import {VRFConsumerBaseV2} from "../VRFConsumerBaseV2.sol"; contract VRFSingleConsumerExample is VRFConsumerBaseV2 { - VRFCoordinatorV2Interface COORDINATOR; - LinkTokenInterface LINKTOKEN; + VRFCoordinatorV2Interface internal COORDINATOR; + LinkTokenInterface internal LINKTOKEN; struct RequestConfig { uint64 subId; diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFSubscriptionBalanceMonitorExposed.sol b/contracts/src/v0.8/vrf/testhelpers/VRFSubscriptionBalanceMonitorExposed.sol index e2c276615a9..471b6f99301 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFSubscriptionBalanceMonitorExposed.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFSubscriptionBalanceMonitorExposed.sol @@ -2,7 +2,7 @@ pragma solidity 0.8.6; -import "../../dev/VRFSubscriptionBalanceMonitor.sol"; +import {VRFSubscriptionBalanceMonitor} from "../dev/VRFSubscriptionBalanceMonitor.sol"; contract VRFSubscriptionBalanceMonitorExposed is VRFSubscriptionBalanceMonitor { constructor( diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFTestHelper.sol b/contracts/src/v0.8/vrf/testhelpers/VRFTestHelper.sol index 56a1058bf03..e3f9ee04824 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFTestHelper.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFTestHelper.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../VRF.sol"; +import {VRF} from "../VRF.sol"; /** *********************************************************************** @notice Testing harness for VRF.sol, exposing its internal methods. Not to diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFV2LoadTestWithMetrics.sol b/contracts/src/v0.8/vrf/testhelpers/VRFV2LoadTestWithMetrics.sol index 3fd3f4e4038..d7b9f9d1084 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFV2LoadTestWithMetrics.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFV2LoadTestWithMetrics.sol @@ -1,10 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../interfaces/VRFCoordinatorV2Interface.sol"; -import "../VRFConsumerBaseV2.sol"; -import "../../shared/access/ConfirmedOwner.sol"; -import "../../ChainSpecificUtil.sol"; +import {VRFCoordinatorV2Interface} from "../interfaces/VRFCoordinatorV2Interface.sol"; +import {VRFConsumerBaseV2} from "../VRFConsumerBaseV2.sol"; +import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; +import {ChainSpecificUtil} from "../../ChainSpecificUtil.sol"; /** * @title The VRFLoadTestExternalSubOwner contract. @@ -19,7 +19,7 @@ contract VRFV2LoadTestWithMetrics is VRFConsumerBaseV2, ConfirmedOwner { uint256 public s_slowestFulfillment = 0; uint256 public s_fastestFulfillment = 999; uint256 public s_lastRequestId; - mapping(uint256 => uint256) requestHeights; // requestIds to block number when rand request was made + mapping(uint256 => uint256) internal requestHeights; // requestIds to block number when rand request was made struct RequestStatus { bool fulfilled; diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFV2OwnerTestConsumer.sol b/contracts/src/v0.8/vrf/testhelpers/VRFV2OwnerTestConsumer.sol index 361c32706f4..43a1e0e0150 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFV2OwnerTestConsumer.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFV2OwnerTestConsumer.sol @@ -1,11 +1,10 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../interfaces/VRFCoordinatorV2Interface.sol"; -import "../VRFConsumerBaseV2.sol"; -import "../../shared/access/ConfirmedOwner.sol"; -import "../../ChainSpecificUtil.sol"; -import "../../shared/interfaces/LinkTokenInterface.sol"; +import {VRFCoordinatorV2Interface} from "../interfaces/VRFCoordinatorV2Interface.sol"; +import {VRFConsumerBaseV2} from "../VRFConsumerBaseV2.sol"; +import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; +import {ChainSpecificUtil} from "../../ChainSpecificUtil.sol"; contract VRFV2OwnerTestConsumer is VRFConsumerBaseV2, ConfirmedOwner { VRFCoordinatorV2Interface public COORDINATOR; @@ -16,7 +15,7 @@ contract VRFV2OwnerTestConsumer is VRFConsumerBaseV2, ConfirmedOwner { uint256 public s_slowestFulfillment = 0; uint256 public s_fastestFulfillment = 999; uint256 public s_lastRequestId; - mapping(uint256 => uint256) requestHeights; // requestIds to block number when rand request was made + mapping(uint256 => uint256) internal requestHeights; // requestIds to block number when rand request was made struct RequestStatus { bool fulfilled; diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFV2RevertingExample.sol b/contracts/src/v0.8/vrf/testhelpers/VRFV2RevertingExample.sol index 72be535a000..4eccafa37ef 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFV2RevertingExample.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFV2RevertingExample.sol @@ -1,16 +1,16 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../shared/interfaces/LinkTokenInterface.sol"; -import "../../interfaces/VRFCoordinatorV2Interface.sol"; -import "../VRFConsumerBaseV2.sol"; +import {LinkTokenInterface} from "../../shared/interfaces/LinkTokenInterface.sol"; +import {VRFCoordinatorV2Interface} from "../interfaces/VRFCoordinatorV2Interface.sol"; +import {VRFConsumerBaseV2} from "../VRFConsumerBaseV2.sol"; // VRFV2RevertingExample will always revert. Used for testing only, useless in prod. contract VRFV2RevertingExample is VRFConsumerBaseV2 { uint256[] public s_randomWords; uint256 public s_requestId; - VRFCoordinatorV2Interface COORDINATOR; - LinkTokenInterface LINKTOKEN; + VRFCoordinatorV2Interface internal COORDINATOR; + LinkTokenInterface internal LINKTOKEN; uint64 public s_subId; uint256 public s_gasAvailable; @@ -20,6 +20,7 @@ contract VRFV2RevertingExample is VRFConsumerBaseV2 { } function fulfillRandomWords(uint256, uint256[] memory) internal pure override { + // solhint-disable-next-line custom-errors, reason-string revert(); } @@ -33,12 +34,14 @@ contract VRFV2RevertingExample is VRFConsumerBaseV2 { } function topUpSubscription(uint96 amount) external { + // solhint-disable-next-line custom-errors require(s_subId != 0, "sub not set"); // Approve the link transfer. LINKTOKEN.transferAndCall(address(COORDINATOR), amount, abi.encode(s_subId)); } function updateSubscription(address[] memory consumers) external { + // solhint-disable-next-line custom-errors require(s_subId != 0, "subID not set"); for (uint256 i = 0; i < consumers.length; i++) { COORDINATOR.addConsumer(s_subId, consumers[i]); diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFV2WrapperConsumerExample.sol b/contracts/src/v0.8/vrf/testhelpers/VRFV2WrapperConsumerExample.sol index 7ab54ee9fa3..563a5b09288 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFV2WrapperConsumerExample.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFV2WrapperConsumerExample.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.6; -import "../VRFV2WrapperConsumerBase.sol"; -import "../../shared/access/ConfirmedOwner.sol"; +import {VRFV2WrapperConsumerBase} from "../VRFV2WrapperConsumerBase.sol"; +import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; contract VRFV2WrapperConsumerExample is VRFV2WrapperConsumerBase, ConfirmedOwner { event WrappedRequestFulfilled(uint256 requestId, uint256[] randomWords, uint256 payment); @@ -33,6 +33,7 @@ contract VRFV2WrapperConsumerExample is VRFV2WrapperConsumerBase, ConfirmedOwner } function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal override { + // solhint-disable-next-line custom-errors require(s_requests[_requestId].paid > 0, "request not found"); s_requests[_requestId].fulfilled = true; s_requests[_requestId].randomWords = _randomWords; @@ -42,6 +43,7 @@ contract VRFV2WrapperConsumerExample is VRFV2WrapperConsumerBase, ConfirmedOwner function getRequestStatus( uint256 _requestId ) external view returns (uint256 paid, bool fulfilled, uint256[] memory randomWords) { + // solhint-disable-next-line custom-errors require(s_requests[_requestId].paid > 0, "request not found"); RequestStatus memory request = s_requests[_requestId]; return (request.paid, request.fulfilled, request.randomWords); diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFV2WrapperOutOfGasConsumerExample.sol b/contracts/src/v0.8/vrf/testhelpers/VRFV2WrapperOutOfGasConsumerExample.sol index e6747820fdb..353027d5570 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFV2WrapperOutOfGasConsumerExample.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFV2WrapperOutOfGasConsumerExample.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.6; -import "../VRFV2WrapperConsumerBase.sol"; -import "../../shared/access/ConfirmedOwner.sol"; +import {VRFV2WrapperConsumerBase} from "../VRFV2WrapperConsumerBase.sol"; +import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; contract VRFV2WrapperOutOfGasConsumerExample is VRFV2WrapperConsumerBase, ConfirmedOwner { constructor( @@ -18,7 +18,7 @@ contract VRFV2WrapperOutOfGasConsumerExample is VRFV2WrapperConsumerBase, Confir return requestRandomness(_callbackGasLimit, _requestConfirmations, _numWords); } - function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal view override { + function fulfillRandomWords(uint256 /* _requestId */, uint256[] memory /* _randomWords */) internal view override { while (gasleft() > 0) {} } } diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFV2WrapperRevertingConsumerExample.sol b/contracts/src/v0.8/vrf/testhelpers/VRFV2WrapperRevertingConsumerExample.sol index c3699a1d74b..d78992acfd8 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFV2WrapperRevertingConsumerExample.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFV2WrapperRevertingConsumerExample.sol @@ -1,8 +1,8 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.6; -import "../VRFV2WrapperConsumerBase.sol"; -import "../../shared/access/ConfirmedOwner.sol"; +import {VRFV2WrapperConsumerBase} from "../VRFV2WrapperConsumerBase.sol"; +import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; contract VRFV2WrapperRevertingConsumerExample is VRFV2WrapperConsumerBase, ConfirmedOwner { constructor( @@ -18,7 +18,7 @@ contract VRFV2WrapperRevertingConsumerExample is VRFV2WrapperConsumerBase, Confi return requestRandomness(_callbackGasLimit, _requestConfirmations, _numWords); } - function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal pure override { + function fulfillRandomWords(uint256 /* _requestId */, uint256[] memory /* _randomWords */) internal pure override { revert("reverting example"); } } diff --git a/contracts/src/v0.8/vrf/testhelpers/VRFV2WrapperUnderFundingConsumer.sol b/contracts/src/v0.8/vrf/testhelpers/VRFV2WrapperUnderFundingConsumer.sol index ae0f9eac83c..3bae36f58f1 100644 --- a/contracts/src/v0.8/vrf/testhelpers/VRFV2WrapperUnderFundingConsumer.sol +++ b/contracts/src/v0.8/vrf/testhelpers/VRFV2WrapperUnderFundingConsumer.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.0; -import "../../shared/access/ConfirmedOwner.sol"; -import "../../shared/interfaces/LinkTokenInterface.sol"; -import "../../interfaces/VRFV2WrapperInterface.sol"; +import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol"; +import {LinkTokenInterface} from "../../shared/interfaces/LinkTokenInterface.sol"; +import {VRFV2WrapperInterface} from "../interfaces/VRFV2WrapperInterface.sol"; contract VRFV2WrapperUnderFundingConsumer is ConfirmedOwner { LinkTokenInterface internal immutable LINK; diff --git a/contracts/test/v0.8/VRFD20.test.ts b/contracts/test/v0.8/VRFD20.test.ts index 6183658336f..f1c1278b89a 100644 --- a/contracts/test/v0.8/VRFD20.test.ts +++ b/contracts/test/v0.8/VRFD20.test.ts @@ -34,7 +34,7 @@ before(async () => { roles.defaultAccount, ) vrfCoordinatorMockFactory = await ethers.getContractFactory( - 'src/v0.8/mocks/VRFCoordinatorMock.sol:VRFCoordinatorMock', + 'src/v0.8/vrf/mocks/VRFCoordinatorMock.sol:VRFCoordinatorMock', roles.defaultAccount, ) vrfD20Factory = await ethers.getContractFactory( diff --git a/contracts/test/v0.8/dev/VRFCoordinatorV2Mock.test.ts b/contracts/test/v0.8/dev/VRFCoordinatorV2Mock.test.ts index b0a2a10b201..04771e4ef7f 100644 --- a/contracts/test/v0.8/dev/VRFCoordinatorV2Mock.test.ts +++ b/contracts/test/v0.8/dev/VRFCoordinatorV2Mock.test.ts @@ -23,7 +23,7 @@ describe('VRFCoordinatorV2Mock', () => { random = accounts[2] const vrfCoordinatorV2MockFactory = await ethers.getContractFactory( - 'src/v0.8/mocks/VRFCoordinatorV2Mock.sol:VRFCoordinatorV2Mock', + 'src/v0.8/vrf/mocks/VRFCoordinatorV2Mock.sol:VRFCoordinatorV2Mock', accounts[0], ) vrfCoordinatorV2Mock = await vrfCoordinatorV2MockFactory.deploy( diff --git a/contracts/test/v0.8/foundry/transmission/EIP_712_1014_4337.t.sol b/contracts/test/v0.8/foundry/transmission/EIP_712_1014_4337.t.sol index acdc6773642..ad7b2999c90 100644 --- a/contracts/test/v0.8/foundry/transmission/EIP_712_1014_4337.t.sol +++ b/contracts/test/v0.8/foundry/transmission/EIP_712_1014_4337.t.sol @@ -12,7 +12,7 @@ import "../../../../src/v0.8/vendor/entrypoint/interfaces/IEntryPoint.sol"; import "../../../../src/v0.8/dev/transmission/ERC-4337/SCALibrary.sol"; import "../../../../src/v0.8/mocks/MockLinkToken.sol"; import "../../../../src/v0.8/shared/interfaces/LinkTokenInterface.sol"; -import "../../../../src/v0.8/mocks/VRFCoordinatorMock.sol"; +import "../../../../src/v0.8/vrf/mocks/VRFCoordinatorMock.sol"; import "../../../../src/v0.8/tests/MockV3Aggregator.sol"; import "../../../../src/v0.8/vrf/testhelpers/VRFConsumer.sol"; diff --git a/contracts/test/v0.8/foundry/vrf/TrustedBlockhashStore.t.sol b/contracts/test/v0.8/foundry/vrf/TrustedBlockhashStore.t.sol index 47fff7ea900..4f3ea40d828 100644 --- a/contracts/test/v0.8/foundry/vrf/TrustedBlockhashStore.t.sol +++ b/contracts/test/v0.8/foundry/vrf/TrustedBlockhashStore.t.sol @@ -1,7 +1,7 @@ pragma solidity 0.8.6; import "../BaseTest.t.sol"; -import {TrustedBlockhashStore} from "../../../../src/v0.8/dev/vrf/TrustedBlockhashStore.sol"; +import {TrustedBlockhashStore} from "../../../../src/v0.8/vrf/dev/TrustedBlockhashStore.sol"; import {console} from "forge-std/console.sol"; contract TrustedBlockhashStoreTest is BaseTest { diff --git a/contracts/test/v0.8/foundry/vrf/VRFCoordinatorV2Mock.t.sol b/contracts/test/v0.8/foundry/vrf/VRFCoordinatorV2Mock.t.sol index dd607f2ce7b..6378d40167b 100644 --- a/contracts/test/v0.8/foundry/vrf/VRFCoordinatorV2Mock.t.sol +++ b/contracts/test/v0.8/foundry/vrf/VRFCoordinatorV2Mock.t.sol @@ -4,7 +4,7 @@ import "../BaseTest.t.sol"; import {VRF} from "../../../../src/v0.8/vrf/VRF.sol"; import {MockLinkToken} from "../../../../src/v0.8/mocks/MockLinkToken.sol"; import {MockV3Aggregator} from "../../../../src/v0.8/tests/MockV3Aggregator.sol"; -import {VRFCoordinatorV2Mock} from "../../../../src/v0.8/mocks/VRFCoordinatorV2Mock.sol"; +import {VRFCoordinatorV2Mock} from "../../../../src/v0.8/vrf/mocks/VRFCoordinatorV2Mock.sol"; import {VRFConsumerV2} from "../../../../src/v0.8/vrf/testhelpers/VRFConsumerV2.sol"; contract VRFCoordinatorV2MockTest is BaseTest { diff --git a/contracts/test/v0.8/foundry/vrf/VRFCoordinatorV2Plus_Migration.t.sol b/contracts/test/v0.8/foundry/vrf/VRFCoordinatorV2Plus_Migration.t.sol index a847bd5beee..d7a54d6223c 100644 --- a/contracts/test/v0.8/foundry/vrf/VRFCoordinatorV2Plus_Migration.t.sol +++ b/contracts/test/v0.8/foundry/vrf/VRFCoordinatorV2Plus_Migration.t.sol @@ -1,14 +1,14 @@ pragma solidity 0.8.6; import "../BaseTest.t.sol"; -import {VRFCoordinatorV2Plus_V2Example} from "../../../../src/v0.8/dev/vrf/testhelpers/VRFCoordinatorV2Plus_V2Example.sol"; -import {ExposedVRFCoordinatorV2_5} from "../../../../src/v0.8/dev/vrf/testhelpers/ExposedVRFCoordinatorV2_5.sol"; -import {VRFCoordinatorV2_5} from "../../../../src/v0.8/dev/vrf/VRFCoordinatorV2_5.sol"; -import {SubscriptionAPI} from "../../../../src/v0.8/dev/vrf/SubscriptionAPI.sol"; -import {VRFV2PlusConsumerExample} from "../../../../src/v0.8/dev/vrf/testhelpers/VRFV2PlusConsumerExample.sol"; +import {VRFCoordinatorV2Plus_V2Example} from "../../../../src/v0.8/vrf/dev/testhelpers/VRFCoordinatorV2Plus_V2Example.sol"; +import {ExposedVRFCoordinatorV2_5} from "../../../../src/v0.8/vrf/dev/testhelpers/ExposedVRFCoordinatorV2_5.sol"; +import {VRFCoordinatorV2_5} from "../../../../src/v0.8/vrf/dev/VRFCoordinatorV2_5.sol"; +import {SubscriptionAPI} from "../../../../src/v0.8/vrf/dev/SubscriptionAPI.sol"; +import {VRFV2PlusConsumerExample} from "../../../../src/v0.8/vrf/dev/testhelpers/VRFV2PlusConsumerExample.sol"; import {MockLinkToken} from "../../../../src/v0.8/mocks/MockLinkToken.sol"; import {MockV3Aggregator} from "../../../../src/v0.8/tests/MockV3Aggregator.sol"; -import {VRFV2PlusMaliciousMigrator} from "../../../../src/v0.8/dev/vrf/testhelpers/VRFV2PlusMaliciousMigrator.sol"; +import {VRFV2PlusMaliciousMigrator} from "../../../../src/v0.8/vrf/dev/testhelpers/VRFV2PlusMaliciousMigrator.sol"; contract VRFCoordinatorV2Plus_Migration is BaseTest { uint256 internal constant DEFAULT_LINK_FUNDING = 10 ether; // 10 LINK diff --git a/contracts/test/v0.8/foundry/vrf/VRFV2Plus.t.sol b/contracts/test/v0.8/foundry/vrf/VRFV2Plus.t.sol index 90b3d460fe2..e2734f17288 100644 --- a/contracts/test/v0.8/foundry/vrf/VRFV2Plus.t.sol +++ b/contracts/test/v0.8/foundry/vrf/VRFV2Plus.t.sol @@ -4,12 +4,12 @@ import "../BaseTest.t.sol"; import {VRF} from "../../../../src/v0.8/vrf/VRF.sol"; import {MockLinkToken} from "../../../../src/v0.8/mocks/MockLinkToken.sol"; import {MockV3Aggregator} from "../../../../src/v0.8/tests/MockV3Aggregator.sol"; -import {ExposedVRFCoordinatorV2_5} from "../../../../src/v0.8/dev/vrf/testhelpers/ExposedVRFCoordinatorV2_5.sol"; -import {VRFCoordinatorV2_5} from "../../../../src/v0.8/dev/vrf/VRFCoordinatorV2_5.sol"; -import {SubscriptionAPI} from "../../../../src/v0.8/dev/vrf/SubscriptionAPI.sol"; -import {BlockhashStore} from "../../../../src/v0.8/dev/BlockhashStore.sol"; -import {VRFV2PlusConsumerExample} from "../../../../src/v0.8/dev/vrf/testhelpers/VRFV2PlusConsumerExample.sol"; -import {VRFV2PlusClient} from "../../../../src/v0.8/dev/vrf/libraries/VRFV2PlusClient.sol"; +import {ExposedVRFCoordinatorV2_5} from "../../../../src/v0.8/vrf/dev/testhelpers/ExposedVRFCoordinatorV2_5.sol"; +import {VRFCoordinatorV2_5} from "../../../../src/v0.8/vrf/dev/VRFCoordinatorV2_5.sol"; +import {SubscriptionAPI} from "../../../../src/v0.8/vrf/dev/SubscriptionAPI.sol"; +import {BlockhashStore} from "../../../../src/v0.8/vrf/dev/BlockhashStore.sol"; +import {VRFV2PlusConsumerExample} from "../../../../src/v0.8/vrf/dev/testhelpers/VRFV2PlusConsumerExample.sol"; +import {VRFV2PlusClient} from "../../../../src/v0.8/vrf/dev/libraries/VRFV2PlusClient.sol"; import {console} from "forge-std/console.sol"; import {VmSafe} from "forge-std/Vm.sol"; import "@openzeppelin/contracts/utils/math/Math.sol"; // for Math.ceilDiv diff --git a/contracts/test/v0.8/foundry/vrf/VRFV2PlusSubscriptionAPI.t.sol b/contracts/test/v0.8/foundry/vrf/VRFV2PlusSubscriptionAPI.t.sol index db9e11e059e..335e64ff7ef 100644 --- a/contracts/test/v0.8/foundry/vrf/VRFV2PlusSubscriptionAPI.t.sol +++ b/contracts/test/v0.8/foundry/vrf/VRFV2PlusSubscriptionAPI.t.sol @@ -1,8 +1,8 @@ pragma solidity 0.8.6; import "../BaseTest.t.sol"; -import {ExposedVRFCoordinatorV2_5} from "../../../../src/v0.8/dev/vrf/testhelpers/ExposedVRFCoordinatorV2_5.sol"; -import {SubscriptionAPI} from "../../../../src/v0.8/dev/vrf/SubscriptionAPI.sol"; +import {ExposedVRFCoordinatorV2_5} from "../../../../src/v0.8/vrf/dev/testhelpers/ExposedVRFCoordinatorV2_5.sol"; +import {SubscriptionAPI} from "../../../../src/v0.8/vrf/dev/SubscriptionAPI.sol"; import {MockLinkToken} from "../../../../src/v0.8/mocks/MockLinkToken.sol"; import {MockV3Aggregator} from "../../../../src/v0.8/tests/MockV3Aggregator.sol"; import "@openzeppelin/contracts/utils/Strings.sol"; // for Strings.toString diff --git a/contracts/test/v0.8/foundry/vrf/VRFV2Wrapper.t.sol b/contracts/test/v0.8/foundry/vrf/VRFV2Wrapper.t.sol index 4cb02991da1..462db4447fd 100644 --- a/contracts/test/v0.8/foundry/vrf/VRFV2Wrapper.t.sol +++ b/contracts/test/v0.8/foundry/vrf/VRFV2Wrapper.t.sol @@ -4,12 +4,12 @@ import "../BaseTest.t.sol"; import {VRF} from "../../../../src/v0.8/vrf/VRF.sol"; import {MockLinkToken} from "../../../../src/v0.8/mocks/MockLinkToken.sol"; import {MockV3Aggregator} from "../../../../src/v0.8/tests/MockV3Aggregator.sol"; -import {ExposedVRFCoordinatorV2_5} from "../../../../src/v0.8/dev/vrf/testhelpers/ExposedVRFCoordinatorV2_5.sol"; -import {VRFV2PlusWrapperConsumerBase} from "../../../../src/v0.8/dev/vrf/VRFV2PlusWrapperConsumerBase.sol"; -import {VRFV2PlusWrapperConsumerExample} from "../../../../src/v0.8/dev/vrf/testhelpers/VRFV2PlusWrapperConsumerExample.sol"; -import {VRFCoordinatorV2_5} from "../../../../src/v0.8/dev/vrf/VRFCoordinatorV2_5.sol"; -import {VRFV2PlusWrapper} from "../../../../src/v0.8/dev/vrf/VRFV2PlusWrapper.sol"; -import {VRFV2PlusClient} from "../../../../src/v0.8/dev/vrf/libraries/VRFV2PlusClient.sol"; +import {ExposedVRFCoordinatorV2_5} from "../../../../src/v0.8/vrf/dev/testhelpers/ExposedVRFCoordinatorV2_5.sol"; +import {VRFV2PlusWrapperConsumerBase} from "../../../../src/v0.8/vrf/dev/VRFV2PlusWrapperConsumerBase.sol"; +import {VRFV2PlusWrapperConsumerExample} from "../../../../src/v0.8/vrf/dev/testhelpers/VRFV2PlusWrapperConsumerExample.sol"; +import {VRFCoordinatorV2_5} from "../../../../src/v0.8/vrf/dev/VRFCoordinatorV2_5.sol"; +import {VRFV2PlusWrapper} from "../../../../src/v0.8/vrf/dev/VRFV2PlusWrapper.sol"; +import {VRFV2PlusClient} from "../../../../src/v0.8/vrf/dev/libraries/VRFV2PlusClient.sol"; import {console} from "forge-std/console.sol"; contract VRFV2PlusWrapperTest is BaseTest { diff --git a/contracts/test/v0.8/foundry/vrf/VRFV2Wrapper_Migration.t.sol b/contracts/test/v0.8/foundry/vrf/VRFV2Wrapper_Migration.t.sol index e4c8a40172f..91eedb585e9 100644 --- a/contracts/test/v0.8/foundry/vrf/VRFV2Wrapper_Migration.t.sol +++ b/contracts/test/v0.8/foundry/vrf/VRFV2Wrapper_Migration.t.sol @@ -4,14 +4,14 @@ import "../BaseTest.t.sol"; import {VRF} from "../../../../src/v0.8/vrf/VRF.sol"; import {MockLinkToken} from "../../../../src/v0.8/mocks/MockLinkToken.sol"; import {MockV3Aggregator} from "../../../../src/v0.8/tests/MockV3Aggregator.sol"; -import {ExposedVRFCoordinatorV2_5} from "../../../../src/v0.8/dev/vrf/testhelpers/ExposedVRFCoordinatorV2_5.sol"; -import {VRFCoordinatorV2Plus_V2Example} from "../../../../src/v0.8/dev/vrf/testhelpers/VRFCoordinatorV2Plus_V2Example.sol"; -import {VRFV2PlusWrapperConsumerBase} from "../../../../src/v0.8/dev/vrf/VRFV2PlusWrapperConsumerBase.sol"; -import {VRFV2PlusWrapperConsumerExample} from "../../../../src/v0.8/dev/vrf/testhelpers/VRFV2PlusWrapperConsumerExample.sol"; -import {SubscriptionAPI} from "../../../../src/v0.8/dev/vrf/SubscriptionAPI.sol"; -import {VRFCoordinatorV2_5} from "../../../../src/v0.8/dev/vrf/VRFCoordinatorV2_5.sol"; -import {VRFV2PlusWrapper} from "../../../../src/v0.8/dev/vrf/VRFV2PlusWrapper.sol"; -import {VRFV2PlusClient} from "../../../../src/v0.8/dev/vrf/libraries/VRFV2PlusClient.sol"; +import {ExposedVRFCoordinatorV2_5} from "../../../../src/v0.8/vrf/dev/testhelpers/ExposedVRFCoordinatorV2_5.sol"; +import {VRFCoordinatorV2Plus_V2Example} from "../../../../src/v0.8/vrf/dev/testhelpers/VRFCoordinatorV2Plus_V2Example.sol"; +import {VRFV2PlusWrapperConsumerBase} from "../../../../src/v0.8/vrf/dev/VRFV2PlusWrapperConsumerBase.sol"; +import {VRFV2PlusWrapperConsumerExample} from "../../../../src/v0.8/vrf/dev/testhelpers/VRFV2PlusWrapperConsumerExample.sol"; +import {SubscriptionAPI} from "../../../../src/v0.8/vrf/dev/SubscriptionAPI.sol"; +import {VRFCoordinatorV2_5} from "../../../../src/v0.8/vrf/dev/VRFCoordinatorV2_5.sol"; +import {VRFV2PlusWrapper} from "../../../../src/v0.8/vrf/dev/VRFV2PlusWrapper.sol"; +import {VRFV2PlusClient} from "../../../../src/v0.8/vrf/dev/libraries/VRFV2PlusClient.sol"; contract VRFV2PlusWrapperTest is BaseTest { address internal constant LINK_WHALE = 0xD883a6A1C22fC4AbFE938a5aDF9B2Cc31b1BF18B; From 5efd686a0a17d53feb22ee92a30647c4a19f3df8 Mon Sep 17 00:00:00 2001 From: Anirudh Warrier <12178754+anirudhwarrier@users.noreply.github.com> Date: Tue, 10 Oct 2023 19:42:03 +0400 Subject: [PATCH 6/9] [AUTO-5283] Fix on demand test CI (#10883) * Fix on demand test CI * Increase test timeout to 1h * Increase parallel nodes for upgrade test * Replace utils.GetEnv with os.GetEnv * reduce nodes to 1 for node upgrade test * increase nodes to 3 and increase runner size for node upgrade test * throw error if upgrade envs not set --------- Co-authored-by: anirudhwarrier --- .github/workflows/automation-ondemand-tests.yml | 12 +++++++----- integration-tests/smoke/automation_test.go | 10 +++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/automation-ondemand-tests.yml b/.github/workflows/automation-ondemand-tests.yml index 71cd08eaf45..1693e001634 100644 --- a/.github/workflows/automation-ondemand-tests.yml +++ b/.github/workflows/automation-ondemand-tests.yml @@ -140,8 +140,8 @@ jobs: command: -run ^TestAutomationReorg$ ./reorg - name: upgrade suite: smoke - nodes: 1 - os: ubuntu-latest + nodes: 3 + os: ubuntu20.04-8cores-32GB pyroscope_env: ci-automation-on-demand-upgrade network: SIMULATED command: -run ^TestAutomationNodeUpgrade$ ./smoke @@ -160,10 +160,12 @@ jobs: echo "image=${{ env.CHAINLINK_IMAGE }}" >>$GITHUB_OUTPUT echo "version=${{ github.sha }}" >>$GITHUB_OUTPUT echo "upgrade_version=${{ github.sha }}" >>$GITHUB_OUTPUT + echo "upgrade_image=${{ env.CHAINLINK_IMAGE }}" >>$GITHUB_OUTPUT else echo "image=${{ inputs.chainlinkImage }}" >>$GITHUB_OUTPUT echo "version=${{ inputs.chainlinkVersion }}" >>$GITHUB_OUTPUT echo "upgrade_version=${{ inputs.chainlinkVersion }}" >>$GITHUB_OUTPUT + echo "upgrade_image=${{ inputs.chainlinkImage }}" >>$GITHUB_OUTPUT fi if [[ "${{ matrix.tests.name }}" == "upgrade" ]]; then echo "image=${{ inputs.chainlinkImageUpdate }}" >>$GITHUB_OUTPUT @@ -177,10 +179,10 @@ jobs: PYROSCOPE_KEY: ${{ secrets.QA_PYROSCOPE_KEY }} SELECTED_NETWORKS: ${{ matrix.tests.network }} TEST_SUITE: ${{ matrix.tests.suite }} - TEST_UPGRADE_VERSION: ${{ steps.determine-build.outputs.upgrade_version }} - TEST_UPGRADE_IMAGE: ${{ env.CHAINLINK_IMAGE }} + UPGRADE_VERSION: ${{ steps.determine-build.outputs.upgrade_version }} + UPGRADE_IMAGE: ${{ steps.determine-build.outputs.upgrade_image }} with: - test_command_to_run: make test_need_operator_assets && cd ./integration-tests && go test -timeout 30m -count=1 -json -test.parallel=${{ matrix.tests.nodes }} ${{ matrix.tests.command }} 2>&1 | tee /tmp/gotest.log | gotestfmt + test_command_to_run: make test_need_operator_assets && cd ./integration-tests && go test -timeout 60m -count=1 -json -test.parallel=${{ matrix.tests.nodes }} ${{ matrix.tests.command }} 2>&1 | tee /tmp/gotest.log | gotestfmt test_download_vendor_packages_command: cd ./integration-tests && go mod download cl_repo: ${{ steps.determine-build.outputs.image }} cl_image_tag: ${{ steps.determine-build.outputs.version }} diff --git a/integration-tests/smoke/automation_test.go b/integration-tests/smoke/automation_test.go index db34cb28e1e..b7aba624e4c 100644 --- a/integration-tests/smoke/automation_test.go +++ b/integration-tests/smoke/automation_test.go @@ -16,7 +16,6 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink-testing-framework/logging" "github.com/smartcontractkit/chainlink-testing-framework/networks" - "github.com/smartcontractkit/chainlink-testing-framework/utils" "github.com/smartcontractkit/chainlink/integration-tests/actions" "github.com/smartcontractkit/chainlink/integration-tests/client" @@ -105,10 +104,11 @@ func SetupAutomationBasic(t *testing.T, nodeUpgrade bool) { testName = "basic-upkeep" ) if nodeUpgrade { - upgradeImage, err = utils.GetEnv("UPGRADE_IMAGE") - require.NoError(t, err, "Error getting upgrade image") - upgradeVersion, err = utils.GetEnv("UPGRADE_VERSION") - require.NoError(t, err, "Error getting upgrade version") + upgradeImage = os.Getenv("UPGRADE_IMAGE") + upgradeVersion = os.Getenv("UPGRADE_VERSION") + if len(upgradeImage) == 0 || len(upgradeVersion) == 0 { + t.Fatal("UPGRADE_IMAGE and UPGRADE_VERSION must be set to upgrade nodes") + } testName = "node-upgrade" } chainClient, _, contractDeployer, linkToken, registry, registrar, testEnv := setupAutomationTestDocker( From 9fe119d2c66c191c9e4bd8053c9d9f2e5527a81b Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Tue, 10 Oct 2023 10:59:53 -0500 Subject: [PATCH 7/9] core/internal/testutils: use github.com/hashicorp/consul/sdk/freeport (#10895) --- core/internal/features/features_test.go | 32 +++++++++++-------- .../features/ocr2/features_ocr2_test.go | 15 +++++---- core/internal/testutils/testutils.go | 14 -------- core/scripts/go.sum | 2 ++ .../v0/internal/testutils.go | 9 +++--- .../v1/internal/testutils.go | 9 +++--- .../ocr2/plugins/mercury/helpers_test.go | 19 +++++------ .../ocr2/plugins/mercury/integration_test.go | 31 ++++++++++-------- .../plugins/ocr2keeper/integration_21_test.go | 15 +++++---- .../plugins/ocr2keeper/integration_test.go | 18 +++++++---- .../internal/ocr2vrf_integration_test.go | 8 +++-- go.mod | 1 + go.sum | 6 ++-- integration-tests/go.sum | 4 +-- 14 files changed, 99 insertions(+), 84 deletions(-) diff --git a/core/internal/features/features_test.go b/core/internal/features/features_test.go index 489f744cdef..82b335927cf 100644 --- a/core/internal/features/features_test.go +++ b/core/internal/features/features_test.go @@ -24,6 +24,7 @@ import ( "github.com/ethereum/go-ethereum/eth/ethconfig" "github.com/ethereum/go-ethereum/rpc" "github.com/google/uuid" + "github.com/hashicorp/consul/sdk/freeport" "github.com/onsi/gomega" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -670,7 +671,7 @@ func setupOCRContracts(t *testing.T) (*bind.TransactOpts, *backends.SimulatedBac return owner, b, ocrContractAddress, ocrContract, flagsContract, flagsContractAddress } -func setupNode(t *testing.T, owner *bind.TransactOpts, portV1, portV2 uint16, dbName string, +func setupNode(t *testing.T, owner *bind.TransactOpts, portV1, portV2 int, dbName string, b *backends.SimulatedBackend, ns ocrnetworking.NetworkingStack, overrides func(c *chainlink.Config, s *chainlink.Secrets), ) (*cltest.TestApplication, string, common.Address, ocrkey.KeyV2) { p2pKey, err := p2pkey.NewV2() @@ -743,7 +744,7 @@ func setupForwarderEnabledNode( t *testing.T, owner *bind.TransactOpts, portV1, - portV2 uint16, + portV2 int, dbName string, b *backends.SimulatedBackend, ns ocrnetworking.NetworkingStack, @@ -856,8 +857,9 @@ func TestIntegration_OCR(t *testing.T) { for _, tt := range tests { test := tt t.Run(test.name, func(t *testing.T) { - bootstrapNodePortV1 := testutils.GetFreePort(t) - bootstrapNodePortV2 := testutils.GetFreePort(t) + t.Parallel() + bootstrapNodePortV1 := freeport.GetOne(t) + bootstrapNodePortV2 := freeport.GetOne(t) g := gomega.NewWithT(t) owner, b, ocrContractAddress, ocrContract, flagsContract, flagsContractAddress := setupOCRContracts(t) @@ -870,9 +872,10 @@ func TestIntegration_OCR(t *testing.T) { keys []ocrkey.KeyV2 apps []*cltest.TestApplication ) + ports := freeport.GetN(t, 2*numOracles) for i := 0; i < numOracles; i++ { - portV1 := testutils.GetFreePort(t) - portV2 := testutils.GetFreePort(t) + portV1 := ports[2*i] + portV2 := ports[2*i+1] app, peerID, transmitter, key := setupNode(t, owner, portV1, portV2, fmt.Sprintf("o%d_%d", i, test.id), b, test.ns, func(c *chainlink.Config, s *chainlink.Secrets) { c.EVM[0].FlagsContractAddress = ptr(ethkey.EIP55AddressFromAddress(flagsContractAddress)) c.EVM[0].GasEstimator.EIP1559DynamicFees = ptr(test.eip1559) @@ -891,10 +894,10 @@ func TestIntegration_OCR(t *testing.T) { OracleIdentity: confighelper.OracleIdentity{ OnChainSigningAddress: ocrtypes.OnChainSigningAddress(key.OnChainSigning.Address()), TransmitAddress: transmitter, - OffchainPublicKey: ocrtypes.OffchainPublicKey(key.PublicKeyOffChain()), + OffchainPublicKey: key.PublicKeyOffChain(), PeerID: peerID, }, - SharedSecretEncryptionPublicKey: ocrtypes.SharedSecretEncryptionPublicKey(key.PublicKeyConfig()), + SharedSecretEncryptionPublicKey: key.PublicKeyConfig(), }) } @@ -1080,8 +1083,8 @@ func TestIntegration_OCR_ForwarderFlow(t *testing.T) { t.Parallel() numOracles := 4 t.Run("ocr_forwarder_flow", func(t *testing.T) { - bootstrapNodePortV1 := testutils.GetFreePort(t) - bootstrapNodePortV2 := testutils.GetFreePort(t) + bootstrapNodePortV1 := freeport.GetOne(t) + bootstrapNodePortV2 := freeport.GetOne(t) g := gomega.NewWithT(t) owner, b, ocrContractAddress, ocrContract, flagsContract, flagsContractAddress := setupOCRContracts(t) @@ -1096,9 +1099,10 @@ func TestIntegration_OCR_ForwarderFlow(t *testing.T) { keys []ocrkey.KeyV2 apps []*cltest.TestApplication ) + ports := freeport.GetN(t, 2*numOracles) for i := 0; i < numOracles; i++ { - portV1 := testutils.GetFreePort(t) - portV2 := testutils.GetFreePort(t) + portV1 := ports[2*i] + portV2 := ports[2*i+1] app, peerID, transmitter, forwarder, key := setupForwarderEnabledNode(t, owner, portV1, portV2, fmt.Sprintf("o%d_%d", i, 1), b, ocrnetworking.NetworkingStackV2, func(c *chainlink.Config, s *chainlink.Secrets) { c.Feature.LogPoller = ptr(true) c.EVM[0].FlagsContractAddress = ptr(ethkey.EIP55AddressFromAddress(flagsContractAddress)) @@ -1117,10 +1121,10 @@ func TestIntegration_OCR_ForwarderFlow(t *testing.T) { OracleIdentity: confighelper.OracleIdentity{ OnChainSigningAddress: ocrtypes.OnChainSigningAddress(key.OnChainSigning.Address()), TransmitAddress: forwarder, - OffchainPublicKey: ocrtypes.OffchainPublicKey(key.PublicKeyOffChain()), + OffchainPublicKey: key.PublicKeyOffChain(), PeerID: peerID, }, - SharedSecretEncryptionPublicKey: ocrtypes.SharedSecretEncryptionPublicKey(key.PublicKeyConfig()), + SharedSecretEncryptionPublicKey: key.PublicKeyConfig(), }) } diff --git a/core/internal/features/ocr2/features_ocr2_test.go b/core/internal/features/ocr2/features_ocr2_test.go index f31f19a4f2d..bde0fa3533f 100644 --- a/core/internal/features/ocr2/features_ocr2_test.go +++ b/core/internal/features/ocr2/features_ocr2_test.go @@ -22,6 +22,7 @@ import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/eth/ethconfig" + "github.com/hashicorp/consul/sdk/freeport" "github.com/onsi/gomega" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -103,7 +104,7 @@ func setupOCR2Contracts(t *testing.T) (*bind.TransactOpts, *backends.SimulatedBa func setupNodeOCR2( t *testing.T, owner *bind.TransactOpts, - port uint16, + port int, dbName string, useForwarder bool, b *backends.SimulatedBackend, @@ -192,7 +193,7 @@ func TestIntegration_OCR2(t *testing.T) { owner, b, ocrContractAddress, ocrContract := setupOCR2Contracts(t) lggr := logger.TestLogger(t) - bootstrapNodePort := testutils.GetFreePort(t) + bootstrapNodePort := freeport.GetOne(t) bootstrapNode := setupNodeOCR2(t, owner, bootstrapNodePort, "bootstrap", false /* useForwarders */, b, nil) var ( @@ -201,8 +202,9 @@ func TestIntegration_OCR2(t *testing.T) { kbs []ocr2key.KeyBundle apps []*cltest.TestApplication ) - for i := uint16(0); i < 4; i++ { - node := setupNodeOCR2(t, owner, bootstrapNodePort+1+i, fmt.Sprintf("oracle%d", i), false /* useForwarders */, b, []commontypes.BootstrapperLocator{ + ports := freeport.GetN(t, 4) + for i := 0; i < 4; i++ { + node := setupNodeOCR2(t, owner, ports[i], fmt.Sprintf("oracle%d", i), false /* useForwarders */, b, []commontypes.BootstrapperLocator{ // Supply the bootstrap IP and port as a V2 peer address {PeerID: bootstrapNode.peerID, Addrs: []string{fmt.Sprintf("127.0.0.1:%d", bootstrapNodePort)}}, }) @@ -461,7 +463,7 @@ func TestIntegration_OCR2_ForwarderFlow(t *testing.T) { owner, b, ocrContractAddress, ocrContract := setupOCR2Contracts(t) lggr := logger.TestLogger(t) - bootstrapNodePort := testutils.GetFreePort(t) + bootstrapNodePort := freeport.GetOne(t) bootstrapNode := setupNodeOCR2(t, owner, bootstrapNodePort, "bootstrap", true /* useForwarders */, b, nil) var ( @@ -471,8 +473,9 @@ func TestIntegration_OCR2_ForwarderFlow(t *testing.T) { kbs []ocr2key.KeyBundle apps []*cltest.TestApplication ) + ports := freeport.GetN(t, 4) for i := uint16(0); i < 4; i++ { - node := setupNodeOCR2(t, owner, bootstrapNodePort+1+i, fmt.Sprintf("oracle%d", i), true /* useForwarders */, b, []commontypes.BootstrapperLocator{ + node := setupNodeOCR2(t, owner, ports[i], fmt.Sprintf("oracle%d", i), true /* useForwarders */, b, []commontypes.BootstrapperLocator{ // Supply the bootstrap IP and port as a V2 peer address {PeerID: bootstrapNode.peerID, Addrs: []string{fmt.Sprintf("127.0.0.1:%d", bootstrapNodePort)}}, }) diff --git a/core/internal/testutils/testutils.go b/core/internal/testutils/testutils.go index 0d4e710b497..938d814b9eb 100644 --- a/core/internal/testutils/testutils.go +++ b/core/internal/testutils/testutils.go @@ -10,7 +10,6 @@ import ( "math" "math/big" mrand "math/rand" - "net" "net/http" "net/http/httptest" "net/url" @@ -452,16 +451,3 @@ func MustDecodeBase64(s string) (b []byte) { } return } - -// GetFreePort returns a free port. -// NOTE: This approach is technically incorrect because the returned port -// can still be taken by the time the caller attempts to bind to it. -// Unfortunately, we can't specify zero port in P2P.V2.ListenAddresses at the moment. -func GetFreePort(t *testing.T) uint16 { - addr, err := net.ResolveTCPAddr("tcp", "localhost:0") - require.NoError(t, err) - listener, err := net.ListenTCP("tcp", addr) - require.NoError(t, err) - require.NoError(t, listener.Close()) - return uint16(listener.Addr().(*net.TCPAddr).Port) -} diff --git a/core/scripts/go.sum b/core/scripts/go.sum index 640e5dd1982..4dd0f0545c7 100644 --- a/core/scripts/go.sum +++ b/core/scripts/go.sum @@ -655,6 +655,8 @@ github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfm github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +github.com/hashicorp/consul/sdk v0.14.1 h1:ZiwE2bKb+zro68sWzZ1SgHF3kRMBZ94TwOCFRF4ylPs= +github.com/hashicorp/consul/sdk v0.14.1/go.mod h1:vFt03juSzocLRFo59NkeQHHmQa6+g7oU0pfzdI1mUhg= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= diff --git a/core/services/ocr2/plugins/functions/integration_tests/v0/internal/testutils.go b/core/services/ocr2/plugins/functions/integration_tests/v0/internal/testutils.go index a36b3cd3ea7..5feddbda75d 100644 --- a/core/services/ocr2/plugins/functions/integration_tests/v0/internal/testutils.go +++ b/core/services/ocr2/plugins/functions/integration_tests/v0/internal/testutils.go @@ -20,6 +20,7 @@ import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/eth/ethconfig" + "github.com/hashicorp/consul/sdk/freeport" "github.com/onsi/gomega" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -228,7 +229,7 @@ type Node struct { func StartNewNode( t *testing.T, owner *bind.TransactOpts, - port uint16, + port int, dbName string, b *backends.SimulatedBackend, maxGas uint32, @@ -469,11 +470,12 @@ func CreateFunctionsNodes( require.Fail(t, "ocr2Keystores and thresholdKeyShares must have the same length") } - bootstrapPort := testutils.GetFreePort(t) + bootstrapPort := freeport.GetOne(t) bootstrapNode = StartNewNode(t, owner, bootstrapPort, "bootstrap", b, uint32(maxGas), nil, nil, "") AddBootstrapJob(t, bootstrapNode.App, oracleContractAddress) // oracle nodes with jobs, bridges and mock EAs + ports := freeport.GetN(t, nOracleNodes) for i := 0; i < nOracleNodes; i++ { var thresholdKeyShare string if len(thresholdKeyShares) == 0 { @@ -487,8 +489,7 @@ func CreateFunctionsNodes( } else { ocr2Keystore = ocr2Keystores[i] } - nodePort := testutils.GetFreePort(t) - oracleNode := StartNewNode(t, owner, nodePort, fmt.Sprintf("oracle%d", i), b, uint32(maxGas), []commontypes.BootstrapperLocator{ + oracleNode := StartNewNode(t, owner, ports[i], fmt.Sprintf("oracle%d", i), b, uint32(maxGas), []commontypes.BootstrapperLocator{ {PeerID: bootstrapNode.PeerID, Addrs: []string{fmt.Sprintf("127.0.0.1:%d", bootstrapPort)}}, }, ocr2Keystore, thresholdKeyShare) oracleNodes = append(oracleNodes, oracleNode.App) diff --git a/core/services/ocr2/plugins/functions/integration_tests/v1/internal/testutils.go b/core/services/ocr2/plugins/functions/integration_tests/v1/internal/testutils.go index 0970ea7c482..fb0fe4e2478 100644 --- a/core/services/ocr2/plugins/functions/integration_tests/v1/internal/testutils.go +++ b/core/services/ocr2/plugins/functions/integration_tests/v1/internal/testutils.go @@ -21,6 +21,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/eth/ethconfig" + "github.com/hashicorp/consul/sdk/freeport" "github.com/onsi/gomega" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -300,7 +301,7 @@ type Node struct { func StartNewNode( t *testing.T, owner *bind.TransactOpts, - port uint16, + port int, dbName string, b *backends.SimulatedBackend, maxGas uint32, @@ -549,11 +550,12 @@ func CreateFunctionsNodes( require.Fail(t, "ocr2Keystores and thresholdKeyShares must have the same length") } - bootstrapPort := testutils.GetFreePort(t) + bootstrapPort := freeport.GetOne(t) bootstrapNode = StartNewNode(t, owner, bootstrapPort, "bootstrap", b, uint32(maxGas), nil, nil, "") AddBootstrapJob(t, bootstrapNode.App, routerAddress) // oracle nodes with jobs, bridges and mock EAs + ports := freeport.GetN(t, nOracleNodes) for i := 0; i < nOracleNodes; i++ { var thresholdKeyShare string if len(thresholdKeyShares) == 0 { @@ -567,8 +569,7 @@ func CreateFunctionsNodes( } else { ocr2Keystore = ocr2Keystores[i] } - nodePort := testutils.GetFreePort(t) - oracleNode := StartNewNode(t, owner, nodePort, fmt.Sprintf("oracle%d", i), b, uint32(maxGas), []commontypes.BootstrapperLocator{ + oracleNode := StartNewNode(t, owner, ports[i], fmt.Sprintf("oracle%d", i), b, uint32(maxGas), []commontypes.BootstrapperLocator{ {PeerID: bootstrapNode.PeerID, Addrs: []string{fmt.Sprintf("127.0.0.1:%d", bootstrapPort)}}, }, ocr2Keystore, thresholdKeyShare) oracleNodes = append(oracleNodes, oracleNode.App) diff --git a/core/services/ocr2/plugins/mercury/helpers_test.go b/core/services/ocr2/plugins/mercury/helpers_test.go index 97b86cfc561..ce4e0895164 100644 --- a/core/services/ocr2/plugins/mercury/helpers_test.go +++ b/core/services/ocr2/plugins/mercury/helpers_test.go @@ -13,14 +13,15 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind/backends" "github.com/ethereum/go-ethereum/common" - "github.com/smartcontractkit/wsrpc" - "github.com/smartcontractkit/wsrpc/credentials" - "github.com/smartcontractkit/wsrpc/peer" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" "go.uber.org/zap/zaptest/observer" + "github.com/smartcontractkit/wsrpc" + "github.com/smartcontractkit/wsrpc/credentials" + "github.com/smartcontractkit/wsrpc/peer" + "github.com/smartcontractkit/libocr/offchainreporting2/chains/evmutil" ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" @@ -150,14 +151,14 @@ func (node *Node) AddBootstrapJob(t *testing.T, spec string) { func setupNode( t *testing.T, - port int64, + port int, dbName string, backend *backends.SimulatedBackend, csaKey csakey.KeyV2, ) (app chainlink.Application, peerID string, clientPubKey credentials.StaticSizedPublicKey, ocr2kb ocr2key.KeyBundle, observedLogs *observer.ObservedLogs) { - k := big.NewInt(port) // keys unique to port + k := big.NewInt(int64(port)) // keys unique to port p2pKey := p2pkey.MustNewV2XXXTestingOnly(k) - rdr := keystest.NewRandReaderFromSeed(port) + rdr := keystest.NewRandReaderFromSeed(int64(port)) ocr2kb = ocr2key.MustNewInsecure(rdr, chaintype.EVM) p2paddresses := []string{fmt.Sprintf("127.0.0.1:%d", port)} @@ -241,7 +242,7 @@ func addV1MercuryJob( i int, verifierAddress common.Address, bootstrapPeerID string, - bootstrapNodePort int64, + bootstrapNodePort int, bmBridge, bidBridge, askBridge, @@ -324,7 +325,7 @@ func addV2MercuryJob( i int, verifierAddress common.Address, bootstrapPeerID string, - bootstrapNodePort int64, + bootstrapNodePort int, bmBridge, serverURL string, serverPubKey, @@ -389,7 +390,7 @@ func addV3MercuryJob( i int, verifierAddress common.Address, bootstrapPeerID string, - bootstrapNodePort int64, + bootstrapNodePort int, bmBridge, bidBridge, askBridge, diff --git a/core/services/ocr2/plugins/mercury/integration_test.go b/core/services/ocr2/plugins/mercury/integration_test.go index fa3aef0451a..e7e059289a2 100644 --- a/core/services/ocr2/plugins/mercury/integration_test.go +++ b/core/services/ocr2/plugins/mercury/integration_test.go @@ -22,16 +22,18 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/eth/ethconfig" + "github.com/hashicorp/consul/sdk/freeport" "github.com/shopspring/decimal" - "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper" - "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper" - ocr2types "github.com/smartcontractkit/libocr/offchainreporting2plus/types" - "github.com/smartcontractkit/wsrpc/credentials" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" "go.uber.org/zap/zaptest/observer" + "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper" + "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper" + ocr2types "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + "github.com/smartcontractkit/wsrpc/credentials" + relaymercury "github.com/smartcontractkit/chainlink-relay/pkg/reportingplugins/mercury" relaycodecv1 "github.com/smartcontractkit/chainlink-relay/pkg/reportingplugins/mercury/v1" relaycodecv2 "github.com/smartcontractkit/chainlink-relay/pkg/reportingplugins/mercury/v2" @@ -172,7 +174,7 @@ func TestIntegration_MercuryV1(t *testing.T) { steve, backend, verifier, verifierAddress := setupBlockchain(t) // Setup bootstrap + oracle nodes - bootstrapNodePort := int64(19700) + bootstrapNodePort := freeport.GetOne(t) appBootstrap, bootstrapPeerID, _, bootstrapKb, observedLogs := setupNode(t, bootstrapNodePort, "bootstrap_mercury", backend, clientCSAKeys[n]) bootstrapNode := Node{App: appBootstrap, KeyBundle: bootstrapKb} logObservers = append(logObservers, observedLogs) @@ -182,8 +184,9 @@ func TestIntegration_MercuryV1(t *testing.T) { oracles []confighelper.OracleIdentityExtra nodes []Node ) - for i := int64(0); i < int64(n); i++ { - app, peerID, transmitter, kb, observedLogs := setupNode(t, bootstrapNodePort+i+1, fmt.Sprintf("oracle_mercury%d", i), backend, clientCSAKeys[i]) + ports := freeport.GetN(t, n) + for i := 0; i < n; i++ { + app, peerID, transmitter, kb, observedLogs := setupNode(t, ports[i], fmt.Sprintf("oracle_mercury%d", i), backend, clientCSAKeys[i]) nodes = append(nodes, Node{ app, transmitter, kb, @@ -520,7 +523,7 @@ func TestIntegration_MercuryV2(t *testing.T) { steve, backend, verifier, verifierAddress := setupBlockchain(t) // Setup bootstrap + oracle nodes - bootstrapNodePort := int64(20700) + bootstrapNodePort := freeport.GetOne(t) appBootstrap, bootstrapPeerID, _, bootstrapKb, observedLogs := setupNode(t, bootstrapNodePort, "bootstrap_mercury", backend, clientCSAKeys[n]) bootstrapNode := Node{App: appBootstrap, KeyBundle: bootstrapKb} logObservers = append(logObservers, observedLogs) @@ -530,8 +533,9 @@ func TestIntegration_MercuryV2(t *testing.T) { oracles []confighelper.OracleIdentityExtra nodes []Node ) - for i := int64(0); i < int64(n); i++ { - app, peerID, transmitter, kb, observedLogs := setupNode(t, bootstrapNodePort+i+1, fmt.Sprintf("oracle_mercury%d", i), backend, clientCSAKeys[i]) + ports := freeport.GetN(t, n) + for i := 0; i < n; i++ { + app, peerID, transmitter, kb, observedLogs := setupNode(t, ports[i], fmt.Sprintf("oracle_mercury%d", i), backend, clientCSAKeys[i]) nodes = append(nodes, Node{ app, transmitter, kb, @@ -795,7 +799,7 @@ func TestIntegration_MercuryV3(t *testing.T) { steve, backend, verifier, verifierAddress := setupBlockchain(t) // Setup bootstrap + oracle nodes - bootstrapNodePort := int64(21700) + bootstrapNodePort := freeport.GetOne(t) appBootstrap, bootstrapPeerID, _, bootstrapKb, observedLogs := setupNode(t, bootstrapNodePort, "bootstrap_mercury", backend, clientCSAKeys[n]) bootstrapNode := Node{App: appBootstrap, KeyBundle: bootstrapKb} logObservers = append(logObservers, observedLogs) @@ -805,8 +809,9 @@ func TestIntegration_MercuryV3(t *testing.T) { oracles []confighelper.OracleIdentityExtra nodes []Node ) - for i := int64(0); i < int64(n); i++ { - app, peerID, transmitter, kb, observedLogs := setupNode(t, bootstrapNodePort+i+1, fmt.Sprintf("oracle_mercury%d", i), backend, clientCSAKeys[i]) + ports := freeport.GetN(t, n) + for i := 0; i < n; i++ { + app, peerID, transmitter, kb, observedLogs := setupNode(t, ports[i], fmt.Sprintf("oracle_mercury%d", i), backend, clientCSAKeys[i]) nodes = append(nodes, Node{ app, transmitter, kb, diff --git a/core/services/ocr2/plugins/ocr2keeper/integration_21_test.go b/core/services/ocr2/plugins/ocr2keeper/integration_21_test.go index e864b0d7e2f..15280de73cf 100644 --- a/core/services/ocr2/plugins/ocr2keeper/integration_21_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/integration_21_test.go @@ -20,15 +20,17 @@ import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/eth/ethconfig" + "github.com/hashicorp/consul/sdk/freeport" "github.com/onsi/gomega" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/umbracle/ethgo/abi" + "github.com/smartcontractkit/libocr/commontypes" "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper" "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper" ocrTypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" "github.com/smartcontractkit/ocr2keepers/pkg/v3/config" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/umbracle/ethgo/abi" relaytypes "github.com/smartcontractkit/chainlink-relay/pkg/types" "github.com/smartcontractkit/chainlink/v2/core/assets" @@ -476,7 +478,7 @@ func setupNodes(t *testing.T, nodeKeys [5]ethkey.KeyV2, registry *iregistry21.IK mServer.Start() // Setup bootstrap + oracle nodes - bootstrapNodePort := int64(19599) + bootstrapNodePort := freeport.GetOne(t) appBootstrap, bootstrapPeerID, bootstrapTransmitter, bootstrapKb := setupNode(t, bootstrapNodePort, "bootstrap_keeper_ocr", nodeKeys[0], backend, nil, mServer) bootstrapNode := Node{ appBootstrap, bootstrapTransmitter, bootstrapKb, @@ -486,8 +488,9 @@ func setupNodes(t *testing.T, nodeKeys [5]ethkey.KeyV2, registry *iregistry21.IK nodes []Node ) // Set up the minimum 4 oracles all funded - for i := int64(0); i < 4; i++ { - app, peerID, transmitter, kb := setupNode(t, bootstrapNodePort+i+1, fmt.Sprintf("oracle_keeper%d", i), nodeKeys[i+1], backend, []commontypes.BootstrapperLocator{ + ports := freeport.GetN(t, 4) + for i := 0; i < 4; i++ { + app, peerID, transmitter, kb := setupNode(t, ports[i], fmt.Sprintf("oracle_keeper%d", i), nodeKeys[i+1], backend, []commontypes.BootstrapperLocator{ // Supply the bootstrap IP and port as a V2 peer address {PeerID: bootstrapPeerID, Addrs: []string{fmt.Sprintf("127.0.0.1:%d", bootstrapNodePort)}}, }, mServer) diff --git a/core/services/ocr2/plugins/ocr2keeper/integration_test.go b/core/services/ocr2/plugins/ocr2keeper/integration_test.go index eea9c1574cf..bf10fa482fd 100644 --- a/core/services/ocr2/plugins/ocr2keeper/integration_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/integration_test.go @@ -21,8 +21,10 @@ import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/eth/ethconfig" + "github.com/hashicorp/consul/sdk/freeport" "github.com/onsi/gomega" "github.com/pkg/errors" + "github.com/smartcontractkit/libocr/commontypes" "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper" ocrTypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" @@ -108,7 +110,7 @@ func deployKeeper20Registry( func setupNode( t *testing.T, - port int64, + port int, dbName string, nodeKey ethkey.KeyV2, backend *backends.SimulatedBackend, @@ -238,7 +240,7 @@ func TestIntegration_KeeperPluginBasic(t *testing.T) { registry := deployKeeper20Registry(t, steve, backend, linkAddr, linkFeedAddr, gasFeedAddr) // Setup bootstrap + oracle nodes - bootstrapNodePort := int64(19599) + bootstrapNodePort := freeport.GetOne(t) appBootstrap, bootstrapPeerID, bootstrapTransmitter, bootstrapKb := setupNode(t, bootstrapNodePort, "bootstrap_keeper_ocr", nodeKeys[0], backend, nil, NewSimulatedMercuryServer()) bootstrapNode := Node{ appBootstrap, bootstrapTransmitter, bootstrapKb, @@ -248,8 +250,9 @@ func TestIntegration_KeeperPluginBasic(t *testing.T) { nodes []Node ) // Set up the minimum 4 oracles all funded - for i := int64(0); i < 4; i++ { - app, peerID, transmitter, kb := setupNode(t, bootstrapNodePort+i+1, fmt.Sprintf("oracle_keeper%d", i), nodeKeys[i+1], backend, []commontypes.BootstrapperLocator{ + ports := freeport.GetN(t, 4) + for i := 0; i < 4; i++ { + app, peerID, transmitter, kb := setupNode(t, ports[i], fmt.Sprintf("oracle_keeper%d", i), nodeKeys[i+1], backend, []commontypes.BootstrapperLocator{ // Supply the bootstrap IP and port as a V2 peer address {PeerID: bootstrapPeerID, Addrs: []string{fmt.Sprintf("127.0.0.1:%d", bootstrapNodePort)}}, }, NewSimulatedMercuryServer()) @@ -498,7 +501,7 @@ func TestIntegration_KeeperPluginForwarderEnabled(t *testing.T) { effectiveTransmitters := make([]common.Address, 0) // Setup bootstrap + oracle nodes - bootstrapNodePort := int64(19599) + bootstrapNodePort := freeport.GetOne(t) appBootstrap, bootstrapPeerID, bootstrapTransmitter, bootstrapKb := setupNode(t, bootstrapNodePort, "bootstrap_keeper_ocr", nodeKeys[0], backend, nil, NewSimulatedMercuryServer()) bootstrapNode := Node{ @@ -509,8 +512,9 @@ func TestIntegration_KeeperPluginForwarderEnabled(t *testing.T) { nodes []Node ) // Set up the minimum 4 oracles all funded - for i := int64(0); i < 4; i++ { - app, peerID, transmitter, kb := setupNode(t, bootstrapNodePort+i+1, fmt.Sprintf("oracle_keeper%d", i), nodeKeys[i+1], backend, []commontypes.BootstrapperLocator{ + ports := freeport.GetN(t, 4) + for i := 0; i < 4; i++ { + app, peerID, transmitter, kb := setupNode(t, ports[i], fmt.Sprintf("oracle_keeper%d", i), nodeKeys[i+1], backend, []commontypes.BootstrapperLocator{ // Supply the bootstrap IP and port as a V2 peer address {PeerID: bootstrapPeerID, Addrs: []string{fmt.Sprintf("127.0.0.1:%d", bootstrapNodePort)}}, }, NewSimulatedMercuryServer()) diff --git a/core/services/ocr2/plugins/ocr2vrf/internal/ocr2vrf_integration_test.go b/core/services/ocr2/plugins/ocr2vrf/internal/ocr2vrf_integration_test.go index 852017dffa9..9ae025d50cf 100644 --- a/core/services/ocr2/plugins/ocr2vrf/internal/ocr2vrf_integration_test.go +++ b/core/services/ocr2/plugins/ocr2vrf/internal/ocr2vrf_integration_test.go @@ -18,6 +18,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/eth/ethconfig" + "github.com/hashicorp/consul/sdk/freeport" "github.com/onsi/gomega" "github.com/stretchr/testify/require" "go.dedis.ch/kyber/v3" @@ -217,7 +218,7 @@ func setupOCR2VRFContracts( func setupNodeOCR2( t *testing.T, owner *bind.TransactOpts, - port uint16, + port int, dbName string, b *backends.SimulatedBackend, useForwarders bool, @@ -336,7 +337,7 @@ func runOCR2VRFTest(t *testing.T, useForwarders bool) { t.Log("Creating bootstrap node") - bootstrapNodePort := testutils.GetFreePort(t) + bootstrapNodePort := freeport.GetOne(t) bootstrapNode := setupNodeOCR2(t, uni.owner, bootstrapNodePort, "bootstrap", uni.backend, false, nil) numNodes := 5 @@ -354,6 +355,7 @@ func runOCR2VRFTest(t *testing.T, useForwarders bool) { dkgSigners []dkgsignkey.Key sendingKeys [][]string ) + ports := freeport.GetN(t, numNodes) for i := 0; i < numNodes; i++ { // Supply the bootstrap IP and port as a V2 peer address bootstrappers := []commontypes.BootstrapperLocator{ @@ -361,7 +363,7 @@ func runOCR2VRFTest(t *testing.T, useForwarders bool) { fmt.Sprintf("127.0.0.1:%d", bootstrapNodePort), }}, } - node := setupNodeOCR2(t, uni.owner, testutils.GetFreePort(t), fmt.Sprintf("ocr2vrforacle%d", i), uni.backend, useForwarders, bootstrappers) + node := setupNodeOCR2(t, uni.owner, ports[i], fmt.Sprintf("ocr2vrforacle%d", i), uni.backend, useForwarders, bootstrappers) sendingKeys = append(sendingKeys, node.sendingKeys) dkgSignKey, err := node.app.GetKeyStore().DKGSign().Create() diff --git a/go.mod b/go.mod index 5ffcb338675..fc58d0df7ff 100644 --- a/go.mod +++ b/go.mod @@ -33,6 +33,7 @@ require ( github.com/grafana/pyroscope-go v1.0.2 github.com/graph-gophers/dataloader v5.0.0+incompatible github.com/graph-gophers/graphql-go v1.3.0 + github.com/hashicorp/consul/sdk v0.14.1 github.com/hashicorp/go-plugin v1.5.2 github.com/hdevalence/ed25519consensus v0.1.0 github.com/jackc/pgconn v1.14.1 diff --git a/go.sum b/go.sum index 8df4ccfc30c..241cf6618b7 100644 --- a/go.sum +++ b/go.sum @@ -652,6 +652,8 @@ github.com/gxed/hashland/keccakpg v0.0.1/go.mod h1:kRzw3HkwxFU1mpmPP8v1WyQzwdGfm github.com/gxed/hashland/murmur3 v0.0.1/go.mod h1:KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +github.com/hashicorp/consul/sdk v0.14.1 h1:ZiwE2bKb+zro68sWzZ1SgHF3kRMBZ94TwOCFRF4ylPs= +github.com/hashicorp/consul/sdk v0.14.1/go.mod h1:vFt03juSzocLRFo59NkeQHHmQa6+g7oU0pfzdI1mUhg= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -681,8 +683,8 @@ github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerX github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE= -github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= +github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 802011b54ed..f215e54fdff 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -1402,8 +1402,8 @@ github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBt github.com/hashicorp/consul/api v1.21.0 h1:WMR2JiyuaQWRAMFaOGiYfY4Q4HRpyYRe/oYQofjyduM= github.com/hashicorp/consul/api v1.21.0/go.mod h1:f8zVJwBcLdr1IQnfdfszjUM0xzp31Zl3bpws3pL9uFM= github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= -github.com/hashicorp/consul/sdk v0.13.1 h1:EygWVWWMczTzXGpO93awkHFzfUka6hLYJ0qhETd+6lY= -github.com/hashicorp/consul/sdk v0.13.1/go.mod h1:SW/mM4LbKfqmMvcFu8v+eiQQ7oitXEFeiBe9StxERb0= +github.com/hashicorp/consul/sdk v0.14.1 h1:ZiwE2bKb+zro68sWzZ1SgHF3kRMBZ94TwOCFRF4ylPs= +github.com/hashicorp/consul/sdk v0.14.1/go.mod h1:vFt03juSzocLRFo59NkeQHHmQa6+g7oU0pfzdI1mUhg= github.com/hashicorp/cronexpr v1.1.1 h1:NJZDd87hGXjoZBdvyCF9mX4DCq5Wy7+A/w+A7q0wn6c= github.com/hashicorp/cronexpr v1.1.1/go.mod h1:P4wA0KBl9C5q2hABiMO7cp6jcIg96CDh1Efb3g1PWA4= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= From f512ca51326f7c3d53f55435f4d4cd465961f402 Mon Sep 17 00:00:00 2001 From: Adam Hamrick Date: Tue, 10 Oct 2023 12:07:52 -0400 Subject: [PATCH 8/9] [TT-619] Poly zkEVM Compatibility (#10877) * Fix imports * Fixes bad gas estimation --- .../contracts/contract_deployer.go | 11 +++++++-- .../contracts/contract_loader.go | 5 ++++ .../contracts/contract_vrf_models.go | 10 ++++---- .../contracts/ethereum_contracts.go | 23 +++++++++---------- .../contracts/ethereum_contracts_local.go | 4 +++- .../contracts/ethereum_keeper_contracts.go | 5 ++-- .../contracts/ethereum_ocr2vrf_contracts.go | 6 +++-- .../contracts/ethereum_vrfv2_contracts.go | 7 ++++-- .../contracts/ethereum_vrfv2plus_contracts.go | 1 + integration-tests/docker/test_env/cl_node.go | 6 ++++- integration-tests/go.mod | 2 +- integration-tests/go.sum | 4 ++-- 12 files changed, 52 insertions(+), 32 deletions(-) diff --git a/integration-tests/contracts/contract_deployer.go b/integration-tests/contracts/contract_deployer.go index e92b3870faf..6389c75271d 100644 --- a/integration-tests/contracts/contract_deployer.go +++ b/integration-tests/contracts/contract_deployer.go @@ -11,12 +11,11 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/rs/zerolog" "github.com/rs/zerolog/log" - "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/libocr/gethwrappers/offchainaggregator" "github.com/smartcontractkit/libocr/gethwrappers2/ocr2aggregator" ocrConfigHelper "github.com/smartcontractkit/libocr/offchainreporting/confighelper" - eth_contracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum" + "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/functions/generated/functions_load_test_client" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/functions/generated/functions_v1_events_mock" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/automation_consumer_benchmark" @@ -56,6 +55,8 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/verifier" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/verifier_proxy" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/werc20_mock" + + eth_contracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum" ) // ContractDeployer is an interface for abstracting the contract deployment methods across network implementations @@ -154,6 +155,8 @@ func NewContractDeployer(bcClient blockchain.EVMClient, logger zerolog.Logger) ( return &BSCContractDeployer{NewEthereumContractDeployer(clientImpl, logger)}, nil case *blockchain.ScrollClient: return &ScrollContractDeployer{NewEthereumContractDeployer(clientImpl, logger)}, nil + case *blockchain.PolygonZkEvmClient: + return &PolygonZkEvmContractDeployer{NewEthereumContractDeployer(clientImpl, logger)}, nil } return nil, errors.New("unknown blockchain client implementation for contract deployer, register blockchain client in NewContractDeployer") } @@ -209,6 +212,10 @@ type ScrollContractDeployer struct { *EthereumContractDeployer } +type PolygonZkEvmContractDeployer struct { + *EthereumContractDeployer +} + // NewEthereumContractDeployer returns an instantiated instance of the ETH contract deployer func NewEthereumContractDeployer(ethClient blockchain.EVMClient, logger zerolog.Logger) *EthereumContractDeployer { return &EthereumContractDeployer{ diff --git a/integration-tests/contracts/contract_loader.go b/integration-tests/contracts/contract_loader.go index fc0272b107e..ded570cbdc9 100644 --- a/integration-tests/contracts/contract_loader.go +++ b/integration-tests/contracts/contract_loader.go @@ -56,6 +56,8 @@ func NewContractLoader(bcClient blockchain.EVMClient, logger zerolog.Logger) (Co return &PolygonContractLoader{NewEthereumContractLoader(clientImpl, logger)}, nil case *blockchain.OptimismClient: return &OptimismContractLoader{NewEthereumContractLoader(clientImpl, logger)}, nil + case *blockchain.PolygonZkEvmClient: + return &PolygonZkEvmContractLoader{NewEthereumContractLoader(clientImpl, logger)}, nil } return nil, errors.New("unknown blockchain client implementation for contract Loader, register blockchain client in NewContractLoader") } @@ -90,6 +92,9 @@ type PolygonContractLoader struct { type OptimismContractLoader struct { *EthereumContractLoader } +type PolygonZkEvmContractLoader struct { + *EthereumContractLoader +} // NewEthereumContractLoader returns an instantiated instance of the ETH contract Loader func NewEthereumContractLoader(ethClient blockchain.EVMClient, logger zerolog.Logger) *EthereumContractLoader { diff --git a/integration-tests/contracts/contract_vrf_models.go b/integration-tests/contracts/contract_vrf_models.go index 2b623469aa4..f766ee7e3a0 100644 --- a/integration-tests/contracts/contract_vrf_models.go +++ b/integration-tests/contracts/contract_vrf_models.go @@ -2,20 +2,18 @@ package contracts import ( "context" - "math/big" "time" - "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_load_test_consumer" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "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/chainlink/v2/core/gethwrappers/generated/vrf_load_test_with_metrics" + "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_load_test_consumer" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ocr2vrf/generated/dkg" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ocr2vrf/generated/vrf_beacon" ) diff --git a/integration-tests/contracts/ethereum_contracts.go b/integration-tests/contracts/ethereum_contracts.go index fdeccfedad1..5f1f1eb8bb5 100644 --- a/integration-tests/contracts/ethereum_contracts.go +++ b/integration-tests/contracts/ethereum_contracts.go @@ -5,27 +5,19 @@ import ( "encoding/hex" "fmt" "math/big" + "strings" "time" "github.com/ethereum/go-ethereum" + "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/pkg/errors" "github.com/rs/zerolog" "github.com/rs/zerolog/log" - "github.com/smartcontractkit/chainlink-testing-framework/blockchain" - "github.com/smartcontractkit/libocr/gethwrappers/offchainaggregator" - "github.com/smartcontractkit/libocr/gethwrappers2/ocr2aggregator" - ocrConfigHelper "github.com/smartcontractkit/libocr/offchainreporting/confighelper" - ocrTypes "github.com/smartcontractkit/libocr/offchainreporting/types" - - "strings" - "github.com/ethereum/go-ethereum/accounts/abi" - "github.com/pkg/errors" - - "github.com/smartcontractkit/chainlink/integration-tests/client" - eth_contracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum" + "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/functions/generated/functions_coordinator" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/functions/generated/functions_load_test_client" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/functions/generated/functions_router" @@ -52,6 +44,13 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/verifier" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/verifier_proxy" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/werc20_mock" + "github.com/smartcontractkit/libocr/gethwrappers/offchainaggregator" + "github.com/smartcontractkit/libocr/gethwrappers2/ocr2aggregator" + ocrConfigHelper "github.com/smartcontractkit/libocr/offchainreporting/confighelper" + ocrTypes "github.com/smartcontractkit/libocr/offchainreporting/types" + + "github.com/smartcontractkit/chainlink/integration-tests/client" + eth_contracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum" ) // EthereumOracle oracle for "directrequest" job tests diff --git a/integration-tests/contracts/ethereum_contracts_local.go b/integration-tests/contracts/ethereum_contracts_local.go index aba6bc354e1..316658a791e 100644 --- a/integration-tests/contracts/ethereum_contracts_local.go +++ b/integration-tests/contracts/ethereum_contracts_local.go @@ -3,11 +3,13 @@ package contracts import ( "encoding/hex" "fmt" + "github.com/ethereum/go-ethereum/common" "github.com/rs/zerolog/log" - "github.com/smartcontractkit/chainlink/integration-tests/client" ocrConfigHelper "github.com/smartcontractkit/libocr/offchainreporting/confighelper" ocrTypes "github.com/smartcontractkit/libocr/offchainreporting/types" + + "github.com/smartcontractkit/chainlink/integration-tests/client" ) // SetConfigLocal sets the payees and the offchain reporting protocol configuration diff --git a/integration-tests/contracts/ethereum_keeper_contracts.go b/integration-tests/contracts/ethereum_keeper_contracts.go index afb6550bd2c..91cffd10e1e 100644 --- a/integration-tests/contracts/ethereum_keeper_contracts.go +++ b/integration-tests/contracts/ethereum_keeper_contracts.go @@ -11,14 +11,12 @@ import ( geth "github.com/ethereum/go-ethereum" "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/rs/zerolog" - "github.com/smartcontractkit/chainlink-testing-framework/blockchain" - goabi "github.com/umbracle/ethgo/abi" + "github.com/smartcontractkit/chainlink-testing-framework/blockchain" cltypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/automation_consumer_benchmark" registrar21 "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/automation_registrar_wrapper2_1" @@ -34,6 +32,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/log_upkeep_counter_wrapper" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/upkeep_transcoder" "github.com/smartcontractkit/chainlink/v2/core/utils" + goabi "github.com/umbracle/ethgo/abi" "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum" "github.com/smartcontractkit/chainlink/integration-tests/testreporters" diff --git a/integration-tests/contracts/ethereum_ocr2vrf_contracts.go b/integration-tests/contracts/ethereum_ocr2vrf_contracts.go index 11606de53e5..e8149b21251 100644 --- a/integration-tests/contracts/ethereum_ocr2vrf_contracts.go +++ b/integration-tests/contracts/ethereum_ocr2vrf_contracts.go @@ -4,11 +4,15 @@ import ( "context" "encoding/hex" "fmt" + "math/big" + "time" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/pkg/errors" "github.com/rs/zerolog/log" + "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/batch_blockhash_store" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/solidity_vrf_coordinator_interface" @@ -16,8 +20,6 @@ import ( "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" - "math/big" - "time" ) // EthereumDKG represents DKG contract diff --git a/integration-tests/contracts/ethereum_vrfv2_contracts.go b/integration-tests/contracts/ethereum_vrfv2_contracts.go index 88dfe58eb2f..5d8f03ae77b 100644 --- a/integration-tests/contracts/ethereum_vrfv2_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2_contracts.go @@ -3,17 +3,20 @@ package contracts import ( "context" "encoding/hex" + "math/big" + "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" - eth_contracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_consumer_v2" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_load_test_with_metrics" - "math/big" + + eth_contracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum" ) // EthereumVRFCoordinatorV2 represents VRFV2 coordinator contract diff --git a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go index 4ca5c0fec45..0543eb1d985 100644 --- a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go @@ -10,6 +10,7 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "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_5" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_v2plus_load_test_with_metrics" diff --git a/integration-tests/docker/test_env/cl_node.go b/integration-tests/docker/test_env/cl_node.go index d6ebaa69d81..7ff811df0c8 100644 --- a/integration-tests/docker/test_env/cl_node.go +++ b/integration-tests/docker/test_env/cl_node.go @@ -232,12 +232,16 @@ func (n *ClNode) Fund(evmClient blockchain.EVMClient, amount *big.Float) error { if err != nil { return err } - gasEstimates, err := evmClient.EstimateGas(ethereum.CallMsg{}) + toAddr := common.HexToAddress(toAddress) + gasEstimates, err := evmClient.EstimateGas(ethereum.CallMsg{ + To: &toAddr, + }) if err != nil { return err } return evmClient.Fund(toAddress, amount, gasEstimates) } + func (n *ClNode) StartContainer() error { err := n.PostgresDb.StartContainer() if err != nil { diff --git a/integration-tests/go.mod b/integration-tests/go.mod index b9a4641eaf6..f960e8998d7 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -20,7 +20,7 @@ require ( github.com/rs/zerolog v1.30.0 github.com/slack-go/slack v0.12.2 github.com/smartcontractkit/chainlink-env v0.38.1 - github.com/smartcontractkit/chainlink-testing-framework v1.17.6 + github.com/smartcontractkit/chainlink-testing-framework v1.17.7 github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000 github.com/smartcontractkit/libocr v0.0.0-20230922131214-122accb19ea6 github.com/smartcontractkit/ocr2keepers v0.7.27 diff --git a/integration-tests/go.sum b/integration-tests/go.sum index f215e54fdff..6ef96a4141b 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -2370,8 +2370,8 @@ github.com/smartcontractkit/chainlink-solana v1.0.3-0.20230831134610-680240b97ac github.com/smartcontractkit/chainlink-solana v1.0.3-0.20230831134610-680240b97aca/go.mod h1:RIUJXn7EVp24TL2p4FW79dYjyno23x5mjt1nKN+5WEk= github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20230901115736-bbabe542a918 h1:ByVauKFXphRlSNG47lNuxZ9aicu+r8AoNp933VRPpCw= github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20230901115736-bbabe542a918/go.mod h1:/yp/sqD8Iz5GU5fcercjrw0ivJF7HDcupYg+Gjr7EPg= -github.com/smartcontractkit/chainlink-testing-framework v1.17.6 h1:hcsP1eyzrqQf3veK4xh0T37PFkq5AasDwlgJfl11atY= -github.com/smartcontractkit/chainlink-testing-framework v1.17.6/go.mod h1:rypNxetVFh6bwaoHn05bsd4vCtgdEsF+1Vdyy/AhAR8= +github.com/smartcontractkit/chainlink-testing-framework v1.17.7 h1:VvxVDyj1eC/a5ZdOGa07U8VrfXUL/ecFEyO8KMvLaCw= +github.com/smartcontractkit/chainlink-testing-framework v1.17.7/go.mod h1:rypNxetVFh6bwaoHn05bsd4vCtgdEsF+1Vdyy/AhAR8= 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 7b926c8864605f57299a01c68f2c511fd9137ca6 Mon Sep 17 00:00:00 2001 From: Adam Hamrick Date: Tue, 10 Oct 2023 13:36:32 -0400 Subject: [PATCH 9/9] [TT-619] zkEVM Integration and Gas Fixes (#10898) * Fix imports * Fix more imports * Fix gas estimations * Fix version * Fix To address --- integration-tests/actions/actions.go | 15 +++- .../actions/ocr_helpers_local.go | 5 +- .../contracts/contract_deployer.go | 6 +- .../contracts/contract_loader.go | 5 ++ .../contracts/ethereum_contracts.go | 73 +++++++++++-------- .../contracts/ethereum_keeper_contracts.go | 2 +- .../contracts/ethereum_vrf_contracts.go | 8 +- .../contracts/ethereum_vrfv2_contracts.go | 4 +- .../contracts/ethereum_vrfv2plus_contracts.go | 4 +- integration-tests/go.mod | 2 +- integration-tests/go.sum | 4 +- 11 files changed, 82 insertions(+), 46 deletions(-) diff --git a/integration-tests/actions/actions.go b/integration-tests/actions/actions.go index b09782e9e8a..dcdca91cc78 100644 --- a/integration-tests/actions/actions.go +++ b/integration-tests/actions/actions.go @@ -72,7 +72,10 @@ func FundChainlinkNodesAddress( if err != nil { return err } - gasEstimates, err := client.EstimateGas(ethereum.CallMsg{}) + toAddr := common.HexToAddress(toAddress[keyIndex]) + gasEstimates, err := client.EstimateGas(ethereum.CallMsg{ + To: &toAddr, + }) if err != nil { return err } @@ -96,7 +99,10 @@ func FundChainlinkNodesAddresses( return err } for _, addr := range toAddress { - gasEstimates, err := client.EstimateGas(ethereum.CallMsg{}) + toAddr := common.HexToAddress(addr) + gasEstimates, err := client.EstimateGas(ethereum.CallMsg{ + To: &toAddr, + }) if err != nil { return err } @@ -379,7 +385,10 @@ func ReturnFunds(chainlinkNodes []*client.ChainlinkK8sClient, blockchainClient b // FundAddresses will fund a list of addresses with an amount of native currency func FundAddresses(blockchain blockchain.EVMClient, amount *big.Float, addresses ...string) error { for _, address := range addresses { - gasEstimates, err := blockchain.EstimateGas(ethereum.CallMsg{}) + toAddr := common.HexToAddress(address) + gasEstimates, err := blockchain.EstimateGas(ethereum.CallMsg{ + To: &toAddr, + }) if err != nil { return err } diff --git a/integration-tests/actions/ocr_helpers_local.go b/integration-tests/actions/ocr_helpers_local.go index 4d8afc52c49..8bb4e834794 100644 --- a/integration-tests/actions/ocr_helpers_local.go +++ b/integration-tests/actions/ocr_helpers_local.go @@ -35,7 +35,10 @@ func FundChainlinkNodesLocal( if err != nil { return err } - gasEstimates, err := client.EstimateGas(ethereum.CallMsg{}) + toAddr := common.HexToAddress(toAddress) + gasEstimates, err := client.EstimateGas(ethereum.CallMsg{ + To: &toAddr, + }) if err != nil { return err } diff --git a/integration-tests/contracts/contract_deployer.go b/integration-tests/contracts/contract_deployer.go index 6389c75271d..c267a82d94f 100644 --- a/integration-tests/contracts/contract_deployer.go +++ b/integration-tests/contracts/contract_deployer.go @@ -11,9 +11,6 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/rs/zerolog" "github.com/rs/zerolog/log" - "github.com/smartcontractkit/libocr/gethwrappers/offchainaggregator" - "github.com/smartcontractkit/libocr/gethwrappers2/ocr2aggregator" - ocrConfigHelper "github.com/smartcontractkit/libocr/offchainreporting/confighelper" "github.com/smartcontractkit/chainlink-testing-framework/blockchain" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/functions/generated/functions_load_test_client" @@ -55,6 +52,9 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/verifier" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/verifier_proxy" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/werc20_mock" + "github.com/smartcontractkit/libocr/gethwrappers/offchainaggregator" + "github.com/smartcontractkit/libocr/gethwrappers2/ocr2aggregator" + ocrConfigHelper "github.com/smartcontractkit/libocr/offchainreporting/confighelper" eth_contracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum" ) diff --git a/integration-tests/contracts/contract_loader.go b/integration-tests/contracts/contract_loader.go index ded570cbdc9..be5a9aa5e8f 100644 --- a/integration-tests/contracts/contract_loader.go +++ b/integration-tests/contracts/contract_loader.go @@ -96,6 +96,11 @@ type PolygonZkEvmContractLoader struct { *EthereumContractLoader } +// PolygonZKEVMContractLoader wraps for Polygon zkEVM +type PolygonZKEVMContractLoader struct { + *EthereumContractLoader +} + // NewEthereumContractLoader returns an instantiated instance of the ETH contract Loader func NewEthereumContractLoader(ethClient blockchain.EVMClient, logger zerolog.Logger) *EthereumContractLoader { return &EthereumContractLoader{ diff --git a/integration-tests/contracts/ethereum_contracts.go b/integration-tests/contracts/ethereum_contracts.go index 5f1f1eb8bb5..5b3a93fe0c2 100644 --- a/integration-tests/contracts/ethereum_contracts.go +++ b/integration-tests/contracts/ethereum_contracts.go @@ -65,7 +65,9 @@ func (e *EthereumOracle) Address() string { } func (e *EthereumOracle) Fund(ethAmount *big.Float) error { - gasEstimates, err := e.client.EstimateGas(ethereum.CallMsg{}) + gasEstimates, err := e.client.EstimateGas(ethereum.CallMsg{ + To: e.address, + }) if err != nil { return err } @@ -105,7 +107,9 @@ func (e *EthereumAPIConsumer) RoundID(ctx context.Context) (*big.Int, error) { } func (e *EthereumAPIConsumer) Fund(ethAmount *big.Float) error { - gasEstimates, err := e.client.EstimateGas(ethereum.CallMsg{}) + gasEstimates, err := e.client.EstimateGas(ethereum.CallMsg{ + To: e.address, + }) if err != nil { return err } @@ -157,7 +161,9 @@ func (f *EthereumStaking) Address() string { // Fund sends specified currencies to the contract func (f *EthereumStaking) Fund(ethAmount *big.Float) error { - gasEstimates, err := f.client.EstimateGas(ethereum.CallMsg{}) + gasEstimates, err := f.client.EstimateGas(ethereum.CallMsg{ + To: f.address, + }) if err != nil { return err } @@ -901,7 +907,9 @@ func (f *EthereumFluxAggregator) Address() string { // Fund sends specified currencies to the contract func (f *EthereumFluxAggregator) Fund(ethAmount *big.Float) error { - gasEstimates, err := f.client.EstimateGas(ethereum.CallMsg{}) + gasEstimates, err := f.client.EstimateGas(ethereum.CallMsg{ + To: f.address, + }) if err != nil { return err } @@ -1192,7 +1200,9 @@ type EthereumLinkToken struct { // Fund the LINK Token contract with ETH to distribute the token func (l *EthereumLinkToken) Fund(ethAmount *big.Float) error { - gasEstimates, err := l.client.EstimateGas(ethereum.CallMsg{}) + gasEstimates, err := l.client.EstimateGas(ethereum.CallMsg{ + To: &l.address, + }) if err != nil { return err } @@ -1289,7 +1299,9 @@ type EthereumOffchainAggregator struct { // Fund sends specified currencies to the contract func (o *EthereumOffchainAggregator) Fund(ethAmount *big.Float) error { - gasEstimates, err := o.client.EstimateGas(ethereum.CallMsg{}) + gasEstimates, err := o.client.EstimateGas(ethereum.CallMsg{ + To: o.address, + }) if err != nil { return err } @@ -1959,7 +1971,9 @@ func (e *EthereumOffchainAggregatorV2) Address() string { } func (e *EthereumOffchainAggregatorV2) Fund(nativeAmount *big.Float) error { - gasEstimates, err := e.client.EstimateGas(ethereum.CallMsg{}) + gasEstimates, err := e.client.EstimateGas(ethereum.CallMsg{ + To: e.address, + }) if err != nil { return err } @@ -2237,10 +2251,7 @@ func (e *EthereumFunctionsLoadTestClient) ResetStats() error { if err != nil { return err } - if err := e.client.ProcessTransaction(tx); err != nil { - return err - } - return nil + return e.client.ProcessTransaction(tx) } func (e *EthereumFunctionsLoadTestClient) SendRequest(times uint32, source string, encryptedSecretsReferences []byte, args []string, subscriptionId uint64, jobId [32]byte) error { @@ -2432,66 +2443,66 @@ func (e *EthereumWERC20Mock) Address() common.Address { return e.address } -func (l *EthereumWERC20Mock) Approve(to string, amount *big.Int) error { - opts, err := l.client.TransactionOpts(l.client.GetDefaultWallet()) +func (e *EthereumWERC20Mock) Approve(to string, amount *big.Int) error { + opts, err := e.client.TransactionOpts(e.client.GetDefaultWallet()) if err != nil { return err } - l.l.Info(). - Str("From", l.client.GetDefaultWallet().Address()). + e.l.Info(). + Str("From", e.client.GetDefaultWallet().Address()). Str("To", to). Str("Amount", amount.String()). Uint64("Nonce", opts.Nonce.Uint64()). Msg("Approving LINK Transfer") - tx, err := l.instance.Approve(opts, common.HexToAddress(to), amount) + tx, err := e.instance.Approve(opts, common.HexToAddress(to), amount) if err != nil { return err } - return l.client.ProcessTransaction(tx) + return e.client.ProcessTransaction(tx) } -func (l *EthereumWERC20Mock) BalanceOf(ctx context.Context, addr string) (*big.Int, error) { +func (e *EthereumWERC20Mock) BalanceOf(ctx context.Context, addr string) (*big.Int, error) { opts := &bind.CallOpts{ - From: common.HexToAddress(l.client.GetDefaultWallet().Address()), + From: common.HexToAddress(e.client.GetDefaultWallet().Address()), Context: ctx, } - balance, err := l.instance.BalanceOf(opts, common.HexToAddress(addr)) + balance, err := e.instance.BalanceOf(opts, common.HexToAddress(addr)) if err != nil { return nil, err } return balance, nil } -func (l *EthereumWERC20Mock) Transfer(to string, amount *big.Int) error { - opts, err := l.client.TransactionOpts(l.client.GetDefaultWallet()) +func (e *EthereumWERC20Mock) Transfer(to string, amount *big.Int) error { + opts, err := e.client.TransactionOpts(e.client.GetDefaultWallet()) if err != nil { return err } - l.l.Info(). - Str("From", l.client.GetDefaultWallet().Address()). + e.l.Info(). + Str("From", e.client.GetDefaultWallet().Address()). Str("To", to). Str("Amount", amount.String()). Uint64("Nonce", opts.Nonce.Uint64()). Msg("EthereumWERC20Mock.Transfer()") - tx, err := l.instance.Transfer(opts, common.HexToAddress(to), amount) + tx, err := e.instance.Transfer(opts, common.HexToAddress(to), amount) if err != nil { return err } - return l.client.ProcessTransaction(tx) + return e.client.ProcessTransaction(tx) } -func (l *EthereumWERC20Mock) Mint(account common.Address, amount *big.Int) (*types.Transaction, error) { - opts, err := l.client.TransactionOpts(l.client.GetDefaultWallet()) +func (e *EthereumWERC20Mock) Mint(account common.Address, amount *big.Int) (*types.Transaction, error) { + opts, err := e.client.TransactionOpts(e.client.GetDefaultWallet()) if err != nil { return nil, err } - l.l.Info(). + e.l.Info(). Str("account", account.Hex()). Str("amount", amount.String()). Msg("EthereumWERC20Mock.Mint()") - tx, err := l.instance.Mint(opts, account, amount) + tx, err := e.instance.Mint(opts, account, amount) if err != nil { return tx, err } - return tx, l.client.ProcessTransaction(tx) + return tx, e.client.ProcessTransaction(tx) } diff --git a/integration-tests/contracts/ethereum_keeper_contracts.go b/integration-tests/contracts/ethereum_keeper_contracts.go index 91cffd10e1e..eea0a36aceb 100644 --- a/integration-tests/contracts/ethereum_keeper_contracts.go +++ b/integration-tests/contracts/ethereum_keeper_contracts.go @@ -15,6 +15,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/rs/zerolog" + goabi "github.com/umbracle/ethgo/abi" "github.com/smartcontractkit/chainlink-testing-framework/blockchain" cltypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" @@ -32,7 +33,6 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/log_upkeep_counter_wrapper" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/upkeep_transcoder" "github.com/smartcontractkit/chainlink/v2/core/utils" - goabi "github.com/umbracle/ethgo/abi" "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum" "github.com/smartcontractkit/chainlink/integration-tests/testreporters" diff --git a/integration-tests/contracts/ethereum_vrf_contracts.go b/integration-tests/contracts/ethereum_vrf_contracts.go index f97ba86d975..4e7ba45d55b 100644 --- a/integration-tests/contracts/ethereum_vrf_contracts.go +++ b/integration-tests/contracts/ethereum_vrf_contracts.go @@ -175,7 +175,9 @@ func (v *EthereumVRFConsumer) Address() string { } func (v *EthereumVRFConsumer) Fund(ethAmount *big.Float) error { - gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{}) + gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{ + To: v.address, + }) if err != nil { return err } @@ -277,7 +279,9 @@ func (f *VRFConsumerRoundConfirmer) Wait() error { // Fund sends specified currencies to the contract func (v *EthereumVRF) Fund(ethAmount *big.Float) error { - gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{}) + gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{ + To: v.address, + }) if err != nil { return err } diff --git a/integration-tests/contracts/ethereum_vrfv2_contracts.go b/integration-tests/contracts/ethereum_vrfv2_contracts.go index 5d8f03ae77b..1bcd460c399 100644 --- a/integration-tests/contracts/ethereum_vrfv2_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2_contracts.go @@ -289,7 +289,9 @@ func (v *EthereumVRFConsumerV2) GasAvailable() (*big.Int, error) { } func (v *EthereumVRFConsumerV2) Fund(ethAmount *big.Float) error { - gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{}) + gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{ + To: v.address, + }) if err != nil { return err } diff --git a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go index 0543eb1d985..15a9770f4e5 100644 --- a/integration-tests/contracts/ethereum_vrfv2plus_contracts.go +++ b/integration-tests/contracts/ethereum_vrfv2plus_contracts.go @@ -786,7 +786,9 @@ func (v *EthereumVRFV2PlusWrapper) GetSubID(ctx context.Context) (*big.Int, erro } func (v *EthereumVRFV2PlusWrapperLoadTestConsumer) Fund(ethAmount *big.Float) error { - gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{}) + gasEstimates, err := v.client.EstimateGas(ethereum.CallMsg{ + To: v.address, + }) if err != nil { return err } diff --git a/integration-tests/go.mod b/integration-tests/go.mod index f960e8998d7..e82de0d4567 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -20,7 +20,7 @@ require ( github.com/rs/zerolog v1.30.0 github.com/slack-go/slack v0.12.2 github.com/smartcontractkit/chainlink-env v0.38.1 - github.com/smartcontractkit/chainlink-testing-framework v1.17.7 + github.com/smartcontractkit/chainlink-testing-framework v1.17.8 github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000 github.com/smartcontractkit/libocr v0.0.0-20230922131214-122accb19ea6 github.com/smartcontractkit/ocr2keepers v0.7.27 diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 6ef96a4141b..af8a8b573fe 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -2370,8 +2370,8 @@ github.com/smartcontractkit/chainlink-solana v1.0.3-0.20230831134610-680240b97ac github.com/smartcontractkit/chainlink-solana v1.0.3-0.20230831134610-680240b97aca/go.mod h1:RIUJXn7EVp24TL2p4FW79dYjyno23x5mjt1nKN+5WEk= github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20230901115736-bbabe542a918 h1:ByVauKFXphRlSNG47lNuxZ9aicu+r8AoNp933VRPpCw= github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20230901115736-bbabe542a918/go.mod h1:/yp/sqD8Iz5GU5fcercjrw0ivJF7HDcupYg+Gjr7EPg= -github.com/smartcontractkit/chainlink-testing-framework v1.17.7 h1:VvxVDyj1eC/a5ZdOGa07U8VrfXUL/ecFEyO8KMvLaCw= -github.com/smartcontractkit/chainlink-testing-framework v1.17.7/go.mod h1:rypNxetVFh6bwaoHn05bsd4vCtgdEsF+1Vdyy/AhAR8= +github.com/smartcontractkit/chainlink-testing-framework v1.17.8 h1:/VEMK3biV/Ml8Liswn5M6pVrRoTnHdLvsoqKr/Cq1f8= +github.com/smartcontractkit/chainlink-testing-framework v1.17.8/go.mod h1:rypNxetVFh6bwaoHn05bsd4vCtgdEsF+1Vdyy/AhAR8= 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=