Skip to content

Commit

Permalink
feat: Tests for vote delegation (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
CjHare authored Sep 10, 2021
1 parent 4e0c03a commit 9a4b44c
Showing 1 changed file with 62 additions and 11 deletions.
73 changes: 62 additions & 11 deletions test/bitdao.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import {ethers} from 'hardhat'
import {before} from 'mocha'
import {BitDAO} from '../typechain'

const TEN_OCTILLIAN = 10000000000000000000000000000n

describe('BitDAO token contract', async () => {
before(async () => {
adminAccount = await signer()
dao = await bitDao()
admin = await signer(0)
dao = await bitDao(admin)
})

it('name is BitDAO', async () => {
Expand All @@ -22,23 +24,72 @@ describe('BitDAO token contract', async () => {
expect(await dao.symbol()).to.equal('BIT')
})

it('Zero votes for the admin', async () => {
expect(await dao.getCurrentVotes(adminAccount)).to.equal(0)
it('zero votes for the admin by default', async () => {
expect(await dao.getCurrentVotes(admin)).to.equal(0)
})

it('contract creator gets 10 Octillian (1e28 / 1e10 * 1e18) BITs', async () => {
expect(await dao.balanceOf(admin)).to.equal(TEN_OCTILLIAN)
})

let adminAccount: string
describe('delegate', async () => {
beforeEach(async () => {
admin = await signer(0)
delegateOne = await signer(1)
delegateTwo = await signer(2)
dao = await bitDao(admin)
})

it('admin assign ten octillian (all) votes to itself', async () => {
expect(await dao.getCurrentVotes(admin)).to.equal(0)

await dao.delegate(admin)

expect(await dao.getCurrentVotes(admin)).to.equal(TEN_OCTILLIAN)
})

it('admin assign ten octillian (all) votes to a delegate', async () => {
expect(await dao.getCurrentVotes(admin)).to.equal(0)
expect(await dao.getCurrentVotes(delegateOne)).to.equal(0)

await dao.delegate(delegateOne)

expect(await dao.getCurrentVotes(admin)).to.equal(0)
expect(await dao.getCurrentVotes(delegateOne)).to.equal(TEN_OCTILLIAN)
})

it('admin assign ten octillian (all) votes to a delegate, reassigns to another', async () => {
expect(await dao.getCurrentVotes(admin)).to.equal(0)
expect(await dao.getCurrentVotes(delegateOne)).to.equal(0)
expect(await dao.getCurrentVotes(delegateTwo)).to.equal(0)

await dao.delegate(delegateOne)
await dao.delegate(delegateTwo)

expect(await dao.getCurrentVotes(admin)).to.equal(0)
expect(await dao.getCurrentVotes(delegateOne)).to.equal(0)
expect(await dao.getCurrentVotes(delegateTwo)).to.equal(TEN_OCTILLIAN)
})
})

//TODO test minting (might not work)
//TODO test burning (might not work)
//TODO verify emitted events

let admin: string
let dao: BitDAO
let delegateOne: string
let delegateTwo: string
})

async function bitDao(): Promise<BitDAO> {
const adminAccount = await signer()
async function bitDao(creatorAccount: string): Promise<BitDAO> {
const factory = await ethers.getContractFactory('BitDAO')
const dao = <BitDAO>await factory.deploy(adminAccount)
const dao = <BitDAO>await factory.deploy(creatorAccount)
return dao.deployed()
}

async function signer(): Promise<string> {
async function signer(index: number): Promise<string> {
const signers = await ethers.getSigners()
expect(signers.length).is.greaterThan(1)
return signers[0].address
expect(signers.length).is.greaterThan(index)
return signers[index].address
}

0 comments on commit 9a4b44c

Please sign in to comment.