From c6aa21a4abc4fee9dd3e217f1d6a3c9d25c3d94d Mon Sep 17 00:00:00 2001 From: Ben DiFrancesco Date: Fri, 24 Apr 2020 17:41:58 -0400 Subject: [PATCH] Tests for basic revocation proposal mechanics --- test/endaoment-test.js | 36 ++++++++++++++++++++++++++++++++++-- test/helpers.js | 6 ++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/test/endaoment-test.js b/test/endaoment-test.js index d0fbc9e..80e5f26 100644 --- a/test/endaoment-test.js +++ b/test/endaoment-test.js @@ -4,7 +4,7 @@ const { time, expectEvent, expectRevert } = require('@openzeppelin/test-helpers' const { expect } = require('chai'); const Moloch = contract.fromArtifact('Moloch'); const GuildBank = contract.fromArtifact('GuildBank'); -const { toWeiDai, stealDai, approveDai } = require('./helpers'); +const { toWeiDai, stealDai, approveDai, daiBalance } = require('./helpers'); const PERIOD_DURATION = 17280; const VOTING_PERIODS = 35; @@ -117,5 +117,37 @@ describe('Moloch', () => { expect(grant.proposalIndex.toString()).to.equal('2'); }); - // TODO: Test proposal fails if ragequitters deplete required funds + it('should allow a revocation proposal', async () => { + await this.instance.submitRevocationProposal(0, "revoke grantee1", {from: summoner}); + const proposal = await this.instance.proposalQueue(3); + expect(proposal.details).to.equal("revoke grantee1"); + }); + + it('should allow members to vote on a revocation proposal', async () => { + await time.increase(PERIOD_DURATION); + + await this.instance.submitVote(3, 2, {from: member1}); + await this.instance.submitVote(3, 1, {from: member2}); + + const proposal = await this.instance.proposalQueue(3); + + expect(proposal.yesVotes.toString()).to.equal('3000'); + expect(proposal.noVotes.toString()).to.equal('2000'); + }); + + it('should process a successful revocation proposal', async () => { + await time.increase(VOTING_DURATION + GRACE_DURATION); + + const initialGuildBalance = await daiBalance(this.guildBank.address); + + await this.instance.processRevocationProposal(3, {from: summoner}); + + const grant = await this.instance.grants(0); + const postGuildBalance = await daiBalance(this.guildBank.address); + + expect(grant.wasRevoked).to.be.true; + expect(postGuildBalance.gt(initialGuildBalance)).to.be.true; + }); + + // TODO: Test grant proposal fails if ragequitters deplete required funds }); diff --git a/test/helpers.js b/test/helpers.js index 43403a3..aaf0023 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -17,3 +17,9 @@ exports.approveDai = async (holder, spender) => { const daiContract = new web3.eth.Contract(daiAbi, daiAddress); await daiContract.methods.approve(spender, this.toWeiDai(1000000000000)).send({from: holder}); } + +exports.daiBalance = async(holder) => { + const daiContract = new web3.eth.Contract(daiAbi, daiAddress); + const stringBalance = await daiContract.methods.balanceOf(holder).call(); + return new web3.utils.BN(stringBalance); +}