Skip to content

Commit

Permalink
unwrapping and delegating voting power
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigoncalves committed Jun 17, 2024
1 parent 5b4e233 commit 438bb27
Showing 1 changed file with 85 additions and 2 deletions.
87 changes: 85 additions & 2 deletions test/VeRIFToken.test.ts
Original file line number Diff line number Diff line change
@@ -39,7 +39,8 @@ describe('VeRIFToken', () => {
expect(await rif.balanceOf(owner.address)).to.equal(ethers.parseUnits('1000000000', 18))

const latestBlock = await ethers.provider.getBlock('latest')
await rif.closeTokenDistribution(latestBlock?.timestamp!)
if (!latestBlock) throw new Error('latest block not found')
await rif.closeTokenDistribution(latestBlock.timestamp)
expect(await rif.distributionTime()).to.not.be.equal(0)
})

@@ -80,7 +81,7 @@ describe('VeRIFToken', () => {
expect(await rif.balanceOf(holder.address)).to.equal(0)
})

it('veRIF now should own RIFs beloged to the holder', async () => {
it('veRIF now should own RIFs belonged to the holder', async () => {
expect(await rif.balanceOf(veRIF.getAddress())).to.equal(votingPower)
})

@@ -112,4 +113,86 @@ describe('VeRIFToken', () => {
expect(await veRIF.getVotes(holder.address)).to.equal(votingPower)
})
})

describe('Unwrapping RIF tokens from veRIF tokens', () => {
/** withdrawTo is a method for burning veRIF tokens */
it('holder should burn veRIF tokens', async () => {
const tx = veRIF.connect(holder).withdrawTo(holder.address, votingPower)
await expect(tx).to.emit(veRIF, 'Transfer').withArgs(holder.address, ethers.ZeroAddress, votingPower)
})

it('holder should no longer own veRIF tokens', async () => {
expect(await veRIF.balanceOf(holder.address)).to.equal(0)
})

it('holder should return his RIFs back', async () => {
expect(await rif.balanceOf(holder.address)).to.equal(votingPower)
})

it('veRIF should no longer own RIFs', async () => {
expect(await rif.balanceOf(await veRIF.getAddress())).to.equal(0)
})

it('veRIF should no longer have allowance for RIFs from the holder', async () => {
expect(await rif.allowance(holder.address, await veRIF.getAddress())).to.equal(0)
})

it('holder should still have the delegate set', async () => {
expect(await veRIF.delegates(holder.address)).to.equal(holder.address)
})

it('holder should no longer have voting power', async () => {
const vp = await veRIF.getVotes(holder.address)
expect(vp).to.equal(0)
})
})

describe('Delegating voting power to a voter address', () => {
it('should already have 2 checkpoints because of delegation and burning operations', async () => {
const numCheckpoints = await veRIF.numCheckpoints(holder.address)
expect(numCheckpoints).to.equal(2)
})

it('holder should mint veRIF again', async () => {
;(await rif.connect(holder).approve(await veRIF.getAddress(), votingPower)).wait()
await expect(veRIF.connect(holder).depositFor(holder.address, votingPower))
.to.emit(veRIF, 'Transfer')
.withArgs(ethers.ZeroAddress, holder.address, votingPower)
const checkPoint2 = await veRIF.checkpoints(holder.address, 2)
expect(checkPoint2._value).to.equal(votingPower)
})

it('should have 3 checkpoints now', async () => {
const numCheckpoints = await veRIF.numCheckpoints(holder.address)
expect(numCheckpoints).to.equal(3)
})

it('holder should still be delegated to vote (from the previous time)', async () => {
expect(await veRIF.delegates(holder.address)).to.equal(holder.address)
})

it('holder should already have vote power', async () => {
expect(await veRIF.getVotes(holder.address)).to.equal(votingPower)
})

it('holder should delegate his voting power to the voter (another address)', async () => {
const tx = veRIF.connect(holder).delegate(voter.address)
await expect(tx)
.to.emit(veRIF, 'DelegateChanged')
.withArgs(holder.address, holder.address, voter.address)
})

it('should have 4 checkpoints now', async () => {
const numCheckpoints = await veRIF.numCheckpoints(holder.address)
expect(numCheckpoints).to.equal(4)
})

it('holder should NOT have vote power any more', async () => {
expect(await veRIF.getVotes(holder.address)).to.equal(0)
})

it("voter should now have holder's voting power", async () => {
expect(await veRIF.getVotes(voter.address)).to.equal(votingPower)
})
})
})

0 comments on commit 438bb27

Please sign in to comment.