-
-
Save IllIllI000/16c7883c13ec35fd8c050aa25791a163 to your computer and use it in GitHub Desktop.
This file contains 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
diff --git a/test/votingEscrowTest.ts b/test/votingEscrowTest.ts | |
index 7d3163d..8cea188 100644 | |
--- a/test/votingEscrowTest.ts | |
+++ b/test/votingEscrowTest.ts | |
@@ -115,6 +115,50 @@ describe("VotingEscrow Tests", function () { | |
await restoreSnapshot(provider); | |
}); | |
+ | |
+ | |
+ // to run: | |
+ // rm -Rf 2022-08-fiatdao || true && git clone https://github.com/code-423n4/2022-08-fiatdao && cd 2022-08-fiatdao && npm install && npm run build && wget https://gist.githubusercontent.com/IllIllI000/16c7883c13ec35fd8c050aa25791a163/raw/597a1ef490235ff949ae0fa44a02bbd81aa4f648/veFDT_mit_1sec.diff && git apply veFDT_mit_1sec.diff && npx hardhat test --config hardhat.config.test.ts test/votingEscrowTest.ts | |
+ | |
+ | |
+ | |
+ describe("IllIllI Mitigation tests", async () => { | |
+ it("IllIllI - Quit after one second, verify penalty", async () => { | |
+ // alice creates a lock for 1 week | |
+ let lockTime = 1 * WEEK + (await getTimestamp()); | |
+ let amountToLock = BigNumber.from("1000000000000000000000"); | |
+ let balanceStart = await fdtMock.balanceOf(alice.address); | |
+ let timeStart = await getTimestamp(); | |
+ let blockStart = await getBlock() + 1; | |
+ let tx = await ve.connect(alice).createLock(amountToLock, lockTime); | |
+ let resp = await tx.wait(); | |
+ expect(resp.blockNumber).to.equal(blockStart); | |
+ let timeCreated = (await ethers.provider.getBlock(resp.blockNumber)).timestamp; | |
+ let timeLockUsed = (Math.trunc(timeCreated / WEEK) * WEEK); | |
+ console.log("timeCreated:", timeCreated, "timeLockUsed", timeLockUsed); | |
+ | |
+ // alice quits in the next block, one second later | |
+ let tx1 = await ve.connect(alice).quitLock(); | |
+ let resp1 = await tx1.wait(); | |
+ expect(resp1.blockNumber).to.equal(blockStart+1); | |
+ let timeQuit = (await ethers.provider.getBlock(resp1.blockNumber)).timestamp; | |
+ expect(timeQuit - timeCreated).to.equal(1); | |
+ let blockBeforeQuit = resp1.blockNumber - 1; | |
+ console.log("mined:",resp1.blockNumber); | |
+ | |
+ let votes = await ve.balanceOfAt(alice.address, blockBeforeQuit) | |
+ let penalty = await fdtMock.balanceOf(ve.address) | |
+ console.log("votes at block:", votes.toString(), "penalty:", penalty.toString()); | |
+ console.log("votes at start:", (await ve.balanceOfAt(alice.address, blockStart)).toString()); | |
+ console.log("votes at block - penalty:", votes.sub(penalty).toString()); | |
+ console.log("balance change:", balanceStart.sub(await fdtMock.balanceOf(alice.address)).toString(), "vs initial locked", amountToLock.toString()); | |
+ console.log("block start:", blockStart, "block quit:", resp1.blockNumber, "block locked:",resp.blockNumber); | |
+ let oneSecVote = amountToLock.mul(BigNumber.from(1)).div(BigNumber.from(WEEK*52)); | |
+ console.log("vote value of one second:", oneSecVote.toString()); | |
+ expect(votes.sub(oneSecVote)).to.below(penalty); | |
+ }); | |
+ }) | |
+/** | |
describe("Deployment", async () => { | |
it("Initialized properly", async () => { | |
expect(await ve.owner()).to.equal(admin.address); | |
@@ -856,5 +900,5 @@ describe("VotingEscrow Tests", function () { | |
await ve.connect(alice).quitLock(); | |
expect(await fdtMock.balanceOf(alice.address)).to.equal(aliceBalBefore); | |
}); | |
- }); | |
+ });/**/ | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment