-
Notifications
You must be signed in to change notification settings - Fork 53
[SOV-4416] apply reentrancy guard zero #551
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
Open
cwsnt
wants to merge
6
commits into
development
Choose a base branch
from
sov-4416-apply-reentrancy-guard-zero
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| // first run a local forked mainnet node in a separate terminal window: | ||
| // npx hardhat node --fork https://mainnet-dev.sovryn.app/rpc --no-deploy | ||
| // now run the test: | ||
| // npx hardhat test tests-onchain/sip0085.test.js --network rskForkedMainnet | ||
|
|
||
| const { | ||
| impersonateAccount, | ||
| mine, | ||
| time, | ||
| setBalance, | ||
| } = require("@nomicfoundation/hardhat-network-helpers"); | ||
| const hre = require("hardhat"); | ||
| const { getProtocolModules } = require("../deployment/helpers/helpers"); | ||
|
|
||
| const { | ||
| ethers, | ||
| deployments: { createFixture, get }, | ||
| } = hre; | ||
|
|
||
| const MAX_DURATION = ethers.BigNumber.from(24 * 60 * 60).mul(1092); | ||
|
|
||
| const ONE_RBTC = ethers.utils.parseEther("1.0"); | ||
|
|
||
| const getImpersonatedSigner = async (addressToImpersonate) => { | ||
| await impersonateAccount(addressToImpersonate); | ||
| return await ethers.getSigner(addressToImpersonate); | ||
| }; | ||
|
|
||
| describe("SIP-0085 test onchain", () => { | ||
| const getImpersonatedSignerFromJsonRpcProvider = async (addressToImpersonate) => { | ||
| const provider = new ethers.providers.JsonRpcProvider("http://localhost:8545"); | ||
| await provider.send("hardhat_impersonateAccount", [addressToImpersonate]); | ||
| return provider.getSigner(addressToImpersonate); | ||
| }; | ||
|
|
||
| const setupTest = createFixture(async ({ deployments }) => { | ||
| const deployer = (await ethers.getSigners())[0].address; | ||
| const deployerSigner = await ethers.getSigner(deployer); | ||
|
|
||
| const multisigAddress = (await get("MultiSigWallet")).address; | ||
| const multisigSigner = await getImpersonatedSignerFromJsonRpcProvider(multisigAddress); | ||
|
|
||
| await setBalance(deployer, ONE_RBTC.mul(10)); | ||
| await deployments.fixture(["ProtocolModules"], { | ||
| keepExistingDeployments: true, | ||
| }); // start from a fresh deployments | ||
|
|
||
| const staking = await ethers.getContract("Staking", deployerSigner); | ||
| const sovrynProtocol = await ethers.getContract("SovrynProtocol", deployerSigner); | ||
|
|
||
| const god = await deployments.get("GovernorAdmin"); | ||
| const governorAdmin = await ethers.getContractAt( | ||
| "GovernorAlpha", | ||
| god.address, | ||
| deployerSigner | ||
| ); | ||
| const governorAdminSigner = await getImpersonatedSigner(god.address); | ||
|
|
||
| await setBalance(governorAdminSigner.address, ONE_RBTC); | ||
| const timelockOwner = await ethers.getContract("TimelockOwner", governorAdminSigner); | ||
|
|
||
| const timelockOwnerSigner = await getImpersonatedSignerFromJsonRpcProvider( | ||
| timelockOwner.address | ||
| ); | ||
| await setBalance(timelockOwnerSigner._address, ONE_RBTC); | ||
|
|
||
| // | ||
| return { | ||
| deployer, | ||
| deployerSigner, | ||
| staking, | ||
| sovrynProtocol, | ||
| governorAdmin, | ||
| governorAdminSigner, | ||
| timelockOwner, | ||
| timelockOwnerSigner, | ||
| multisigAddress, | ||
| multisigSigner, | ||
| }; | ||
| }); | ||
|
|
||
| describe("SIP-0085 Test creation and execution", () => { | ||
|
||
| it("SIP-0085 is executable and valid", async () => { | ||
| if (!hre.network.tags["forked"]) { | ||
| console.error("ERROR: Must run on a forked net"); | ||
| return; | ||
| } | ||
| await hre.network.provider.request({ | ||
| method: "hardhat_reset", | ||
| params: [ | ||
| { | ||
| forking: { | ||
| jsonRpcUrl: "https://mainnet-dev.sovryn.app/rpc", | ||
| blockNumber: 6926710, | ||
| }, | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| const { | ||
| deployer, | ||
| deployerSigner, | ||
| staking, | ||
| governorAdmin, | ||
| timelockOwnerSigner, | ||
| multisigAddress, | ||
| multisigSigner, | ||
| } = await setupTest(); | ||
|
|
||
| // CREATE PROPOSAL | ||
| const sov = await ethers.getContract("SOV", timelockOwnerSigner); | ||
| const whaleAmount = (await sov.totalSupply()).mul(ethers.BigNumber.from(5)); | ||
| await sov.mint(deployer, whaleAmount); | ||
|
|
||
| await sov.connect(deployerSigner).approve(staking.address, whaleAmount); | ||
|
|
||
| if (await staking.paused()) await staking.connect(multisigSigner).pauseUnpause(false); | ||
| const kickoffTS = await staking.kickoffTS(); | ||
| await staking.stake( | ||
| whaleAmount, | ||
| ethers.BigNumber.from(Date.now()).add(MAX_DURATION), | ||
| deployer, | ||
| deployer | ||
| ); | ||
| await mine(); | ||
|
|
||
| // CREATE PROPOSAL AND VERIFY | ||
| const proposalIdBeforeSIP = await governorAdmin.latestProposalIds(deployer); | ||
| await hre.run("sips:create", { argsFunc: "getArgsSip0085" }); | ||
| const proposalId = await governorAdmin.latestProposalIds(deployer); | ||
| expect( | ||
| proposalId, | ||
| "Proposal was not created. Check the SIP creation is not commented out." | ||
| ).is.gt(proposalIdBeforeSIP); | ||
|
|
||
| // VOTE FOR PROPOSAL | ||
|
|
||
| await mine(); | ||
| await governorAdmin.connect(deployerSigner).castVote(proposalId, true); | ||
|
|
||
| // QUEUE PROPOSAL | ||
| let proposal = await governorAdmin.proposals(proposalId); | ||
| await mine(proposal.endBlock); | ||
| await governorAdmin.queue(proposalId); | ||
|
|
||
| const wrbtc = await ethers.getContract("WRBTC"); | ||
| const priceFeeds = await ethers.getContract("PriceFeeds"); | ||
| const previousWrbtcPriceFeeds = await priceFeeds.pricesFeeds(wrbtc.address); | ||
|
|
||
| console.log(`previous WRBTC priceFeeds: ${previousWrbtcPriceFeeds}`); | ||
|
|
||
| // EXECUTE PROPOSAL | ||
| proposal = await governorAdmin.proposals(proposalId); | ||
| await time.increaseTo(proposal.eta); | ||
| await expect(governorAdmin.execute(proposalId)) | ||
| .to.emit(governorAdmin, "ProposalExecuted") | ||
| .withArgs(proposalId); | ||
|
|
||
| // VERIFY execution | ||
| expect((await governorAdmin.proposals(proposalId)).executed).to.be.true; | ||
|
|
||
| // Validate zero contracs upgrade | ||
| const borrowerOperationsProxy = await ethers.getContract("BorrowerOperations_Proxy"); | ||
| const borrowerOperationsImpl = await get("BorrowerOperations_Implementation"); | ||
|
|
||
| expect(await borrowerOperationsProxy.getImplementation()).to.equal( | ||
| borrowerOperationsImpl.address | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getArgsSIP0085 has been used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not addressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
address in this commit