Skip to content

Commit 51449c8

Browse files
add wrapping tests
1 parent ae3f300 commit 51449c8

File tree

3 files changed

+119
-3
lines changed

3 files changed

+119
-3
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { ethers, upgrades } from 'hardhat'
2+
import { VeRIFToken } from '../typechain-types'
23

34
export const deployVeRif = async (rifTokenAddress: string, deployerAddress: string) => {
45
const VeRIFTokenFactory = await ethers.getContractFactory('VeRIFToken')
5-
const veRIFToken = await upgrades.deployProxy(VeRIFTokenFactory, [rifTokenAddress, deployerAddress], {
6+
const veRIFToken = (await upgrades.deployProxy(VeRIFTokenFactory, [rifTokenAddress, deployerAddress], {
67
initializer: 'initialize',
78
kind: 'uups',
89
timeout: 0, // wait indefinitely
910
unsafeAllow: ['internal-function-storage'],
10-
})
11+
}) as unknown as VeRIFToken)
1112

1213
return await veRIFToken.waitForDeployment()
1314
}

scripts/deploy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ethers } from 'hardhat'
2-
import { deployVeRif } from './deploy-veRif'
2+
import { deployVeRif } from './deploy-verif'
33

44
const deploy = async () => {
55
const rifToken = await ethers.deployContract('RIFToken')

test/VeRIFToken.test.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'
2+
import { loadFixture } from '@nomicfoundation/hardhat-toolbox/network-helpers'
3+
import { expect } from 'chai'
4+
import { ethers } from 'hardhat'
5+
import { deployVeRif } from '../scripts/deploy-verif'
6+
import { RIFToken, VeRIFToken } from '../typechain-types'
7+
8+
describe('VeRIFToken', () => {
9+
let owner: SignerWithAddress, holder: SignerWithAddress, voter: SignerWithAddress
10+
let rif: RIFToken
11+
let veRIF: VeRIFToken
12+
const votingPower = 10n * 10n ** 18n
13+
14+
const deployRif = () => ethers.deployContract('RIFToken')
15+
const deployWrappedRif = async () => deployVeRif(await rif.getAddress(), owner.address)
16+
17+
const deploy = async () => {
18+
rif = await loadFixture(deployRif)
19+
veRIF = await loadFixture(deployWrappedRif)
20+
}
21+
22+
before(async () => {
23+
;[owner, holder, voter] = await ethers.getSigners()
24+
await deploy()
25+
})
26+
27+
it('Should assign the initial balance to the contract itself', async () => {
28+
const contractBalance = await rif.balanceOf(rif)
29+
expect(contractBalance).to.equal(ethers.parseUnits('1000000000', 18))
30+
})
31+
32+
describe('Wrapping RIF tokens to veRIF', () => {
33+
it('holder should NOT initially own RIF tokens', async () => {
34+
expect(await rif.balanceOf(holder.address)).to.equal(0)
35+
})
36+
37+
it('should transfer all RIF tokens to deployer and close distribution', async () => {
38+
await rif.setAuthorizedManagerContract(owner)
39+
expect(await rif.balanceOf(owner.address)).to.equal(ethers.parseUnits('1000000000', 18))
40+
41+
const latestBlock = await ethers.provider.getBlock('latest')
42+
await rif.closeTokenDistribution(latestBlock?.timestamp!)
43+
expect(await rif.distributionTime()).to.not.be.equal(0)
44+
})
45+
46+
it("owner should send some RIFs to holder's address", async () => {
47+
const tx = await rif.transfer(holder.address, votingPower)
48+
await tx.wait()
49+
expect(tx)
50+
.to.emit(rif, 'Transfer')
51+
.withArgs(await rif.getAddress(), holder.address, votingPower)
52+
})
53+
54+
it('holder should approve allowance for veRIF', async () => {
55+
const tx = await rif.connect(holder).approve(veRIF.getAddress(), votingPower)
56+
await tx.wait()
57+
expect(tx).to.emit(rif, 'Approval').withArgs(holder.address, veRIF.getAddress(), votingPower)
58+
})
59+
60+
it('allowance for veRIF should be set on the RIF token', async () => {
61+
expect(await rif.allowance(holder.address, veRIF.getAddress())).to.equal(votingPower)
62+
})
63+
64+
it('veRIF should NOT have any RIF tokens on its balance', async () => {
65+
expect(await rif.balanceOf(veRIF.getAddress())).to.equal(0)
66+
})
67+
68+
it('holder should NOT have any veRIF tokens on his balance', async () => {
69+
expect(await veRIF.balanceOf(holder.address)).to.equal(0)
70+
})
71+
72+
/** depositFor is a method for minting veRIF tokens */
73+
it('holder should deposit underlying tokens and mint the corresponding amount of veRIF tokens', async () => {
74+
await expect(veRIF.connect(holder).depositFor(holder.address, votingPower))
75+
.to.emit(veRIF, 'Transfer')
76+
.withArgs(ethers.ZeroAddress, holder.address, votingPower)
77+
})
78+
79+
it('holder should NOT have RIF tokens anymore', async () => {
80+
expect(await rif.balanceOf(holder.address)).to.equal(0)
81+
})
82+
83+
it('veRIF now should own RIFs beloged to the holder', async () => {
84+
expect(await rif.balanceOf(veRIF.getAddress())).to.equal(votingPower)
85+
})
86+
87+
it('holder should have the same amount of veRIF tokens as the deposited RIF tokens', async () => {
88+
expect(await veRIF.balanceOf(holder.address)).to.equal(votingPower)
89+
})
90+
91+
it('holder should NOT be able to deposit more RIF tokens than he has', async () => {
92+
await expect(veRIF.connect(holder).depositFor(holder.address, votingPower)).to.be.reverted
93+
})
94+
95+
/** delegate */
96+
it('holder should NOT have vote power yet', async () => {
97+
expect(await veRIF.getVotes(holder.address)).to.equal(0)
98+
})
99+
100+
it('holder should delegate vote power to himself', async () => {
101+
const tx = await veRIF.connect(holder).delegate(holder.address)
102+
await expect(tx)
103+
.to.emit(veRIF, 'DelegateChanged')
104+
.withArgs(holder.address, ethers.ZeroAddress, holder.address)
105+
})
106+
107+
it('holder should now have delegate set', async () => {
108+
expect(await veRIF.delegates(holder.address)).to.equal(holder.address)
109+
})
110+
111+
it('holder should have vote power', async () => {
112+
expect(await veRIF.getVotes(holder.address)).to.equal(votingPower)
113+
})
114+
})
115+
})

0 commit comments

Comments
 (0)