From 790ff5db625b612969fe07180c329483968f5058 Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Tue, 26 Mar 2024 18:58:00 -0500 Subject: [PATCH] VP tests refactor --- ethereum/test/DAO.js | 209 ++++++++----------------------------------- 1 file changed, 37 insertions(+), 172 deletions(-) diff --git a/ethereum/test/DAO.js b/ethereum/test/DAO.js index ca81102..8c1434f 100644 --- a/ethereum/test/DAO.js +++ b/ethereum/test/DAO.js @@ -47,22 +47,29 @@ describe('DAO', () => { let account2; const POOL_DURATION = 3600; // 1 hour const POOL_FEE = 100; - const callbackData = ethers.AbiCoder.defaultAbiCoder().encode([], []); + const emptyCallbackData = ethers.AbiCoder.defaultAbiCoder().encode([], []); + + const initiateValidationPool = ({ + postIndex, duration, + quorumNumerator, quorumDenominator, bindingPercent, + redistributeLosingStakes, callbackOnValidate, + callbackData, fee, + } = {}) => dao.initiateValidationPool( + postIndex ?? 0, + duration ?? POOL_DURATION, + quorumNumerator ?? 1, + quorumDenominator ?? 3, + bindingPercent ?? 100, + redistributeLosingStakes ?? true, + callbackOnValidate ?? false, + callbackData ?? emptyCallbackData, + { value: fee ?? POOL_FEE }, + ); beforeEach(async () => { ({ dao, account1, account2 } = await loadFixture(deploy)); await dao.addPost(account1, 'content-id'); - const init = () => dao.initiateValidationPool( - 0, - POOL_DURATION, - 1, - 3, - 100, - true, - false, - callbackData, - { value: POOL_FEE }, - ); + const init = () => initiateValidationPool({ fee: POOL_FEE }); await expect(init()).to.emit(dao, 'ValidationPoolInitiated').withArgs(0); expect(await dao.validationPoolCount()).to.equal(1); expect(await dao.memberCount()).to.equal(0); @@ -72,112 +79,37 @@ describe('DAO', () => { describe('Initiate', () => { it('should not be able to initiate a validation pool without a fee', async () => { - const setup = await loadFixture(deploy); - const init = () => setup.dao.initiateValidationPool( - 0, - POOL_DURATION, - 1, - 3, - 100, - true, - false, - callbackData, - ); + const init = () => initiateValidationPool({ fee: 0 }); await expect(init()).to.be.revertedWith('Fee is required to initiate validation pool'); }); it('should not be able to initiate a validation pool with a quorum below the minimum', async () => { - const setup = await loadFixture(deploy); - const init = () => setup.dao.initiateValidationPool( - 0, - POOL_DURATION, - 1, - 4, - 100, - true, - false, - callbackData, - { value: POOL_FEE }, - ); + const init = () => initiateValidationPool({ quorumNumerator: 1, quorumDenominator: 4 }); await expect(init()).to.be.revertedWith('Quorum is below minimum'); }); it('should not be able to initiate a validation pool with a quorum greater than 1', async () => { - const setup = await loadFixture(deploy); - const init = () => setup.dao.initiateValidationPool( - 0, - POOL_DURATION, - 11, - 10, - 100, - true, - false, - callbackData, - { value: POOL_FEE }, - ); + const init = () => initiateValidationPool({ quorumNumerator: 11, quorumDenominator: 10 }); await expect(init()).to.be.revertedWith('Quorum is greater than one'); }); it('should not be able to initiate a validation pool with duration below minimum', async () => { - const setup = await loadFixture(deploy); - const init = () => setup.dao.initiateValidationPool( - 0, - 0, - 1, - 3, - 100, - true, - false, - callbackData, - { value: POOL_FEE }, - ); + const init = () => initiateValidationPool({ duration: 0 }); await expect(init()).to.be.revertedWith('Duration is too short'); }); it('should not be able to initiate a validation pool with duration above maximum', async () => { - const setup = await loadFixture(deploy); - const init = () => setup.dao.initiateValidationPool( - 0, - 40000000000000, - 1, - 3, - 100, - true, - false, - callbackData, - { value: POOL_FEE }, - ); + const init = () => initiateValidationPool({ duration: 40000000000000 }); await expect(init()).to.be.revertedWith('Duration is too long'); }); it('should not be able to initiate a validation pool with bindingPercent above 100', async () => { - const setup = await loadFixture(deploy); - const init = () => setup.dao.initiateValidationPool( - 0, - POOL_DURATION, - 1, - 3, - 101, - true, - false, - callbackData, - { value: POOL_FEE }, - ); + const init = () => initiateValidationPool({ bindingPercent: 101 }); await expect(init()).to.be.revertedWith('Binding percent must be <= 100'); }); it('should be able to initiate a second validation pool', async () => { - const init = () => dao.initiateValidationPool( - 0, - POOL_DURATION, - 1, - 3, - 100, - true, - false, - callbackData, - { value: POOL_FEE }, - ); + const init = () => initiateValidationPool(); await expect(init()).to.emit(dao, 'ValidationPoolInitiated').withArgs(1); expect(await dao.validationPoolCount()).to.equal(2); }); @@ -200,17 +132,7 @@ describe('DAO', () => { expect(await dao.balanceOf(account1)).to.equal(100); expect(await dao.balanceOf(dao.target)).to.equal(0); console.log('initiating second pool'); - await dao.initiateValidationPool( - 0, - POOL_DURATION, - 1, - 3, - 100, - true, - false, - callbackData, - { value: POOL_FEE }, - ); + await initiateValidationPool(); expect(await dao.balanceOf(dao.target)).to.equal(100); }); @@ -275,7 +197,7 @@ describe('DAO', () => { 100, true, false, - callbackData, + emptyCallbackData, { value: POOL_FEE }, ); await expect(init()).to.emit(dao, 'ValidationPoolInitiated').withArgs(1); @@ -291,17 +213,7 @@ describe('DAO', () => { time.increase(POOL_DURATION + 1); await expect(dao.evaluateOutcome(0)).to.emit(dao, 'ValidationPoolResolved').withArgs(0, true); - const init = () => dao.initiateValidationPool( - 0, - POOL_DURATION, - 1, - 1, - 100, - true, - false, - callbackData, - { value: POOL_FEE }, - ); + const init = () => initiateValidationPool({ quorumNumerator: 1, quorumDenominator: 1 }); await expect(init()).to.emit(dao, 'ValidationPoolInitiated').withArgs(1); expect(await dao.validationPoolCount()).to.equal(2); time.increase(POOL_DURATION + 1); @@ -313,34 +225,14 @@ describe('DAO', () => { time.increase(POOL_DURATION + 1); await dao.evaluateOutcome(0); await dao.addPost(account2, 'content-id'); - const init = () => dao.initiateValidationPool( - 1, - POOL_DURATION, - 1, - 3, - 100, - true, - false, - callbackData, - { value: POOL_FEE }, - ); + const init = () => initiateValidationPool({ postIndex: 1 }); await expect(init()).to.emit(dao, 'ValidationPoolInitiated').withArgs(1); time.increase(POOL_DURATION + 1); await dao.evaluateOutcome(1); }); it('Binding validation pool should redistribute stakes', async () => { - const init = () => dao.initiateValidationPool( - 0, - POOL_DURATION, - 1, - 3, - 100, - true, - false, - callbackData, - { value: POOL_FEE }, - ); + const init = () => initiateValidationPool(); await expect(init()).to.emit(dao, 'ValidationPoolInitiated').withArgs(2); await dao.connect(account1).stake(2, 10, true); await dao.connect(account2).stake(2, 10, false); @@ -355,17 +247,7 @@ describe('DAO', () => { }); it('Non binding validation pool should not redistribute stakes', async () => { - const init = () => dao.initiateValidationPool( - 0, - POOL_DURATION, - 1, - 3, - 0, - true, - false, - callbackData, - { value: POOL_FEE }, - ); + const init = () => initiateValidationPool({ bindingPercent: 0 }); await expect(init()).to.emit(dao, 'ValidationPoolInitiated').withArgs(2); await dao.connect(account1).stake(2, 10, true); await dao.connect(account2).stake(2, 10, false); @@ -380,17 +262,7 @@ describe('DAO', () => { }); it('Partially binding validation pool should redistribute some stakes', async () => { - const init = () => dao.initiateValidationPool( - 0, - POOL_DURATION, - 1, - 3, - 50, - true, - false, - callbackData, - { value: POOL_FEE }, - ); + const init = () => initiateValidationPool({ bindingPercent: 50 }); await expect(init()).to.emit(dao, 'ValidationPoolInitiated').withArgs(2); await dao.connect(account1).stake(2, 10, true); await dao.connect(account2).stake(2, 10, false); @@ -406,17 +278,10 @@ describe('DAO', () => { }); it('If redistributeLosingStakes is false, validation pool should burn binding portion of losing stakes', async () => { - const init = () => dao.initiateValidationPool( - 0, - POOL_DURATION, - 1, - 3, - 50, - false, - false, - callbackData, - { value: POOL_FEE }, - ); + const init = () => initiateValidationPool({ + bindingPercent: 50, + redistributeLosingStakes: false, + }); await expect(init()).to.emit(dao, 'ValidationPoolInitiated').withArgs(2); await dao.connect(account1).stake(2, 10, true); await dao.connect(account2).stake(2, 10, false);