Skip to content

Commit

Permalink
Lint warning fixes (#12303)
Browse files Browse the repository at this point in the history
* Lint warning fixes

* Update go wrappers

* Prettier fix
  • Loading branch information
kidambisrinivas committed Mar 18, 2024
1 parent 8054189 commit 77a99ca
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 36 deletions.
10 changes: 10 additions & 0 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ src = 'src/v0.8/vrf'
test = 'test/v0.8/foundry/vrf' # skips tests for no VRF foundry tests
solc_version = '0.8.6'

[profile.vrfv2plus_coordinator]
optimizer_runs = 50
src = 'src/v0.8/vrf'
solc_version = '0.8.6'

[profile.vrfv2plus]
optimizer_runs = 1_000_000
src = 'src/v0.8/vrf'
solc_version = '0.8.6'

[profile.automation]
optimizer_runs = 10000
src = 'src/v0.8/automation'
Expand Down
2 changes: 2 additions & 0 deletions contracts/scripts/native_solc_compile_all_vrfv2plus
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,5 @@ compileContract vrf/dev/TrustedBlockhashStore.sol
compileContract vrf/dev/testhelpers/VRFV2PlusLoadTestWithMetrics.sol
compileContractAltOpts vrf/dev/testhelpers/VRFCoordinatorV2PlusUpgradedVersion.sol 5
compileContract vrf/dev/testhelpers/VRFV2PlusWrapperLoadTestConsumer.sol
compileContract vrf/testhelpers/VRFMockETHLINKAggregator.sol
compileContract vrf/dev/testhelpers/VRFV2PlusLoadTestWithMetrics.sol
6 changes: 3 additions & 3 deletions contracts/src/v0.8/vrf/dev/VRFCoordinatorV2_5.sol
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus {
uint256 weiPerUnitGas,
bool nativePayment,
bool onlyPremium
) internal returns (uint96) {
) internal view returns (uint96) {
if (nativePayment) {
return _calculatePaymentAmountNative(startGas, weiPerUnitGas, onlyPremium);
}
Expand All @@ -514,7 +514,7 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus {
uint256 startGas,
uint256 weiPerUnitGas,
bool onlyPremium
) internal returns (uint96) {
) internal view returns (uint96) {
// Will return non-zero on chains that have this enabled
uint256 l1CostWei = ChainSpecificUtil._getCurrentTxL1GasFees(msg.data);
// calculate the payment without the premium
Expand All @@ -533,7 +533,7 @@ contract VRFCoordinatorV2_5 is VRF, SubscriptionAPI, IVRFCoordinatorV2Plus {
uint256 startGas,
uint256 weiPerUnitGas,
bool onlyPremium
) internal returns (uint96) {
) internal view returns (uint96) {
int256 weiPerUnitLink;
weiPerUnitLink = _getFeedData();
if (weiPerUnitLink <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ contract ExposedVRFCoordinatorV2_5 is VRFCoordinatorV2_5 {
uint256 weiPerUnitGas,
bool nativePayment,
bool onlyPremium
) external returns (uint96) {
) external view returns (uint96) {
return _calculatePaymentAmount(startGas, weiPerUnitGas, nativePayment, onlyPremium);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,23 @@ contract VRFV2PlusLoadTestWithMetrics is VRFConsumerBaseV2Plus {
request.fulfilmentBlockNumber
);
}

function _calculateMetrics(
uint256 _responseTime,
uint256 _fastestResponseTime,
uint256 _slowestResponseTime,
uint256 _averageInMillions,
uint256 _responseCount
) internal pure returns (uint256 slowest, uint256 fastest, uint256 average) {
uint256 _requestDelayInMillions = _responseTime * 1_000_000;
if (_responseTime > _slowestResponseTime) {
_slowestResponseTime = _responseTime;
}
_fastestResponseTime = _responseTime < _fastestResponseTime ? _responseTime : _fastestResponseTime;
uint256 averageInMillions = _responseCount > 0
? (_averageInMillions * _responseCount + _requestDelayInMillions) / (_responseCount + 1)
: _requestDelayInMillions;

return (_slowestResponseTime, _fastestResponseTime, averageInMillions);
}
}
10 changes: 5 additions & 5 deletions contracts/src/v0.8/vrf/testhelpers/VRFMockETHLINKAggregator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ contract VRFMockETHLINKAggregator is AggregatorV3Interface {
int256 public answer;
uint256 private blockTimestampDeduction = 0;

constructor(int256 _answer) public {
constructor(int256 _answer) {
answer = _answer;
}

function decimals() external view override returns (uint8) {
function decimals() external pure override returns (uint8) {
return 18;
}

function description() external view override returns (string memory) {
function description() external pure override returns (string memory) {
return "VRFMockETHLINKAggregator";
}

function version() external view override returns (uint256) {
function version() external pure override returns (uint256) {
return 1;
}

function getRoundData(
uint80 _roundId
uint80 /*_roundId*/
)
external
view
Expand Down
28 changes: 10 additions & 18 deletions contracts/test/v0.8/foundry/vrf/VRFV2Plus.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -410,20 +410,16 @@ contract VRFV2Plus is BaseTest {
vm.roll(requestBlock);
s_linkToken.transfer(address(s_testConsumer), 10 ether);
s_testConsumer.createSubscriptionAndFund(10 ether);
uint256 subId = s_testConsumer.s_subId();
subId = s_testConsumer.s_subId();

// Apply basic configs to contract.
setConfig();
registerProvingKey();

// Request random words.
vm.expectEmit(true, true, false, true);
(uint256 requestId, uint256 preSeed) = s_testCoordinator.computeRequestIdExternal(
vrfKeyHash,
address(s_testConsumer),
subId,
2
);
uint256 preSeed;
(requestId, preSeed) = s_testCoordinator.computeRequestIdExternal(vrfKeyHash, address(s_testConsumer), subId, 2);
emit RandomWordsRequested(
vrfKeyHash,
requestId,
Expand Down Expand Up @@ -460,7 +456,7 @@ contract VRFV2Plus is BaseTest {
-block-num 20 \
-sender 0x90A8820424CC8a819d14cBdE54D12fD3fbFa9bb2
*/
VRF.Proof memory proof = VRF.Proof({
proof = VRF.Proof({
pk: [
72488970228380509287422715226575535698893157273063074627791787432852706183111,
62070622898698443831883535403436258712770888294397026493185421712108624767191
Expand All @@ -483,7 +479,7 @@ contract VRFV2Plus is BaseTest {
],
zInv: 100579074451139970455673776933943662313989441807178260211316504761358492254052
});
VRFCoordinatorV2_5.RequestCommitment memory rc = VRFCoordinatorV2_5.RequestCommitment({
rc = VRFCoordinatorV2_5.RequestCommitment({
blockNum: requestBlock,
subId: subId,
callbackGasLimit: 1000000,
Expand All @@ -501,7 +497,7 @@ contract VRFV2Plus is BaseTest {
uint32 requestBlock = 10;
vm.roll(requestBlock);
s_testConsumer.createSubscriptionAndFund(0);
uint256 subId = s_testConsumer.s_subId();
subId = s_testConsumer.s_subId();
s_testCoordinator.fundSubscriptionWithNative{value: 10 ether}(subId);

// Apply basic configs to contract.
Expand All @@ -510,12 +506,8 @@ contract VRFV2Plus is BaseTest {

// Request random words.
vm.expectEmit(true, true, true, true);
(uint256 requestId, uint256 preSeed) = s_testCoordinator.computeRequestIdExternal(
vrfKeyHash,
address(s_testConsumer),
subId,
2
);
uint256 preSeed;
(requestId, preSeed) = s_testCoordinator.computeRequestIdExternal(vrfKeyHash, address(s_testConsumer), subId, 2);
emit RandomWordsRequested(
vrfKeyHash,
requestId,
Expand Down Expand Up @@ -553,7 +545,7 @@ contract VRFV2Plus is BaseTest {
-sender 0x90A8820424CC8a819d14cBdE54D12fD3fbFa9bb2 \
-native-payment true
*/
VRF.Proof memory proof = VRF.Proof({
proof = VRF.Proof({
pk: [
72488970228380509287422715226575535698893157273063074627791787432852706183111,
62070622898698443831883535403436258712770888294397026493185421712108624767191
Expand All @@ -576,7 +568,7 @@ contract VRFV2Plus is BaseTest {
],
zInv: 97568175302326019383632009699686265453584842953005404815285123863099260038246
});
VRFCoordinatorV2_5.RequestCommitment memory rc = VRFCoordinatorV2_5.RequestCommitment({
rc = VRFCoordinatorV2_5.RequestCommitment({
blockNum: requestBlock,
subId: subId,
callbackGasLimit: 1_000_000,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ vrf_load_test_with_metrics: ../../contracts/solc/v0.8.6/VRFV2LoadTestWithMetrics
vrf_log_emitter: ../../contracts/solc/v0.8.19/VRFLogEmitter/VRFLogEmitter.abi ../../contracts/solc/v0.8.19/VRFLogEmitter/VRFLogEmitter.bin 15f491d445ac4d0c712d1cbe4e5054c759b080bf20de7d54bfe2a82cde4dcf06
vrf_malicious_consumer_v2: ../../contracts/solc/v0.8.6/VRFMaliciousConsumerV2/VRFMaliciousConsumerV2.abi ../../contracts/solc/v0.8.6/VRFMaliciousConsumerV2/VRFMaliciousConsumerV2.bin 9755fa8ffc7f5f0b337d5d413d77b0c9f6cd6f68c31727d49acdf9d4a51bc522
vrf_malicious_consumer_v2_plus: ../../contracts/solc/v0.8.6/VRFMaliciousConsumerV2Plus/VRFMaliciousConsumerV2Plus.abi ../../contracts/solc/v0.8.6/VRFMaliciousConsumerV2Plus/VRFMaliciousConsumerV2Plus.bin e2a72638e11da807b6533d037e7e5aaeed695efd5035777b8e20d2f8973a574c
vrf_mock_ethlink_aggregator: ../../contracts/solc/v0.8.6/VRFMockETHLINKAggregator/VRFMockETHLINKAggregator.abi ../../contracts/solc/v0.8.6/VRFMockETHLINKAggregator/VRFMockETHLINKAggregator.bin a6e753984eeec8107e205ae517f74d4616bf23cffda50a25538ffc16ac4b036f
vrf_mock_ethlink_aggregator: ../../contracts/solc/v0.8.6/VRFMockETHLINKAggregator/VRFMockETHLINKAggregator.abi ../../contracts/solc/v0.8.6/VRFMockETHLINKAggregator/VRFMockETHLINKAggregator.bin 3657f8c552147eb55d7538fa7d8012c1a983d8c5184610de60600834a72e006b
vrf_owner: ../../contracts/solc/v0.8.6/VRFOwner/VRFOwner.abi ../../contracts/solc/v0.8.6/VRFOwner/VRFOwner.bin eccfae5ee295b5850e22f61240c469f79752b8d9a3bac5d64aec7ac8def2f6cb
vrf_owner_test_consumer: ../../contracts/solc/v0.8.6/VRFV2OwnerTestConsumer/VRFV2OwnerTestConsumer.abi ../../contracts/solc/v0.8.6/VRFV2OwnerTestConsumer/VRFV2OwnerTestConsumer.bin 6969de242efe8f366ae4097fc279d9375c8e2d0307aaa322e31f2ce6b8c1909a
vrf_ownerless_consumer_example: ../../contracts/solc/v0.8.6/VRFOwnerlessConsumerExample/VRFOwnerlessConsumerExample.abi ../../contracts/solc/v0.8.6/VRFOwnerlessConsumerExample/VRFOwnerlessConsumerExample.bin 9893b3805863273917fb282eed32274e32aa3d5c2a67a911510133e1218132be
Expand Down
1 change: 1 addition & 0 deletions core/gethwrappers/go_generate_vrfv2plus.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ package gethwrappers
//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFV2PlusLoadTestWithMetrics/VRFV2PlusLoadTestWithMetrics.abi ../../contracts/solc/v0.8.6/VRFV2PlusLoadTestWithMetrics/VRFV2PlusLoadTestWithMetrics.bin VRFV2PlusLoadTestWithMetrics vrf_v2plus_load_test_with_metrics
//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFCoordinatorV2PlusUpgradedVersion/VRFCoordinatorV2PlusUpgradedVersion.abi ../../contracts/solc/v0.8.6/VRFCoordinatorV2PlusUpgradedVersion/VRFCoordinatorV2PlusUpgradedVersion.bin VRFCoordinatorV2PlusUpgradedVersion vrf_v2plus_upgraded_version
//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFV2PlusWrapperLoadTestConsumer/VRFV2PlusWrapperLoadTestConsumer.abi ../../contracts/solc/v0.8.6/VRFV2PlusWrapperLoadTestConsumer/VRFV2PlusWrapperLoadTestConsumer.bin VRFV2PlusWrapperLoadTestConsumer vrfv2plus_wrapper_load_test_consumer
//go:generate go run ./generation/generate/wrap.go ../../contracts/solc/v0.8.6/VRFMockETHLINKAggregator/VRFMockETHLINKAggregator.abi ../../contracts/solc/v0.8.6/VRFMockETHLINKAggregator/VRFMockETHLINKAggregator.bin VRFMockETHLINKAggregator vrf_mock_ethlink_aggregator

0 comments on commit 77a99ca

Please sign in to comment.