dgf-prototype/ethereum/test/Proposals.js

102 lines
3.5 KiB
JavaScript
Raw Normal View History

2024-03-26 21:32:41 -05:00
const {
time,
loadFixture,
} = require('@nomicfoundation/hardhat-toolbox/network-helpers');
const { expect } = require('chai');
const { ethers } = require('hardhat');
const { beforeEach } = require('mocha');
describe('Proposal', () => {
async function deploy() {
// Contracts are deployed using the first signer/account by default
const [account1, account2] = await ethers.getSigners();
const DAO = await ethers.getContractFactory('DAO');
const dao = await DAO.deploy();
const Proposals = await ethers.getContractFactory('Proposals');
const proposals = await Proposals.deploy(dao.target);
await dao.addPost(account1, 'some-content-id');
await dao.addPost(account2, 'some-other-content-id');
const callbackData = ethers.AbiCoder.defaultAbiCoder().encode([], []);
await dao.initiateValidationPool(0, 60, 1, 3, 100, true, false, callbackData, { value: 100 });
await dao.initiateValidationPool(1, 60, 1, 3, 100, true, false, callbackData, { value: 100 });
await time.increase(61);
await dao.evaluateOutcome(0);
await dao.evaluateOutcome(1);
return {
dao, proposals, account1, account2,
};
}
it('Should deploy', async () => {
const { dao, proposals, account1 } = await loadFixture(deploy);
expect(dao).to.exist;
expect(proposals).to.exist;
expect(await dao.memberCount()).to.equal(2);
expect(await dao.balanceOf(account1)).to.equal(100);
expect(await dao.totalSupply()).to.equal(200);
expect(await proposals.proposalCount()).to.equal(0);
});
describe('Attestation', () => {
let dao;
let proposals;
let account1;
// let account2;
let proposal;
beforeEach(async () => {
({
dao,
proposals,
account1,
// account2,
} = await loadFixture(deploy));
console.log('postCount', await dao.postCount());
await dao.addPost(account1, 'proposal-content-id');
const postIndex = await dao.postCount() - BigInt(1);
const post = await dao.posts(postIndex);
expect(await post.contentId).to.equal('proposal-content-id');
await proposals.propose(postIndex, 20, 20, 20, { value: 100 });
expect(await proposals.proposalCount()).to.equal(1);
proposal = await proposals.proposals(0);
expect(proposal.postIndex).to.equal(postIndex);
expect(proposal.stage).to.equal(0);
});
it('Can submit a proposal', async () => {
// Nothing to do here -- this just tests our beforeEach
});
it('Can attest for a proposal', async () => {
await proposals.connect(account1).attest(0, 50);
// Nonbinding, non-encumbering
expect(await dao.balanceOf(account1)).to.equal(100);
});
describe('Evaluate attestation', () => {
it('when threshold is met, advance to referendum 0% binding', async () => {
await proposals.attest(0, 20);
await proposals.evaluateAttestation(0);
proposal = await proposals.proposals(0);
expect(proposal.stage).to.equal(1);
});
it('when threshold is not met, and duration has not elapsed, do nothing', async () => {
await proposals.evaluateAttestation(0);
expect(proposal.stage).to.equal(0);
});
it('when threshold is not met, and duration has elapsed, close the proposal', async () => {
await time.increase(365 * 86400 + 1); // 1 year + 1 second
await proposals.evaluateAttestation(0);
proposal = await proposals.proposals(0);
expect(proposal.stage).to.equal(4); // Stage.Closed
});
});
});
});