Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reentrancy guard to VRFCoordinatorV2Mock to align its behaviour w… #10585

Merged
merged 3 commits into from
Sep 12, 2023

Conversation

kidambisrinivas
Copy link
Collaborator

Motivation

  • Currently, VRFCoordinatorV2Mock contract does not completely mimic the behaviour of VRFCoordinatorV2 as it does not have Reentrancy Guard
  • This would lead to issues during automated and manual testing

Solution

  • Introduce Reentrancy Guard in VRFCoordinatorV2Mock to align its behaviour with VRFCoordinatorV2

Testing

$ pnpm hardhat test --grep VRFCoordinatorV2Mock
...
  VRFCoordinatorV2Mock
    #createSubscription
      ✔ can create a subscription
      ✔ subscription id increments
    #addConsumer
      ✔ can add a consumer to a subscription
      ✔ cannot add a consumer to a nonexistent subscription
      ✔ cannot add more than the consumer maximum (1042ms)
    #removeConsumer
      ✔ can remove a consumer from a subscription
      ✔ cannot remove a consumer from a nonexistent subscription
      ✔ cannot remove a consumer after it is already removed
    #fundSubscription
      ✔ can fund a subscription (42ms)
      ✔ cannot fund a nonexistent subscription
    #cancelSubscription
      ✔ can cancel a subscription (41ms)
    #fulfillRandomWords
      ✔ fails to fulfill without being a valid consumer
      ✔ fails to fulfill with insufficient funds (58ms)
      ✔ can request and fulfill [ @skip-coverage ]
      ✔ Correctly allows for user override of fulfillRandomWords [ @skip-coverage ]


               ⛳ Baseline gas used   : 641560 gas

               Current gas used   : 0 gas

               🚩 Delta : -641560 gas

               ⛳ Par   : 721271 gas

               🏌️  You   : 0 gas

               🚩 Score : -721271 gas

  15 passing (15s)

@github-actions
Copy link
Contributor

I see that you haven't updated any README files. Would it make sense to do so?

@github-actions
Copy link
Contributor

@kidambisrinivas kidambisrinivas requested a review from a team September 11, 2023 17:21
@github-actions
Copy link
Contributor

@@ -262,7 +262,7 @@ describe('VRFCoordinatorV2Mock', () => {
expect(receipt.events[0].args['success']).to.equal(true)
assert(
receipt.events[0].args['payment']
.sub(BigNumber.from('100119017000000000'))
.sub(BigNumber.from('100119403000000000'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have the time, some foundry tests on the mockfile could be nice. However, I don't think it's worth the effort ever adding typescript/hardhat tests, since we don't really plan on working with that software going forward.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll try to add Foundry tests for VRFCoordinatorV2Mock. Shall I add it as a follow up PR to this?

@github-actions
Copy link
Contributor

@cl-sonarqube-production
Copy link

SonarQube Quality Gate

Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@kidambisrinivas kidambisrinivas added this pull request to the merge queue Sep 12, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 12, 2023
@kidambisrinivas kidambisrinivas added this pull request to the merge queue Sep 12, 2023
Merged via the queue into develop with commit 5db043c Sep 12, 2023
@kidambisrinivas kidambisrinivas deleted the VRF-602-mock-coordinator-v2 branch September 12, 2023 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants