dgf-prototype/ethereum/test/Proposals.js

142 lines
4.4 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([], []);
2024-03-28 15:06:14 -05:00
await dao.initiateValidationPool(
0,
60,
[1, 3],
[1, 2],
100,
true,
false,
callbackData,
{ value: 100 },
);
await dao.initiateValidationPool(
1,
60,
[1, 3],
[1, 2],
100,
true,
false,
callbackData,
{ value: 100 },
);
2024-03-26 21:32:41 -05:00
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;
2024-03-26 21:43:46 -05:00
let account2;
2024-03-26 21:32:41 -05:00
let proposal;
2024-03-26 21:43:46 -05:00
let postIndex;
2024-03-26 21:32:41 -05:00
beforeEach(async () => {
({
dao,
proposals,
account1,
2024-03-26 21:43:46 -05:00
account2,
2024-03-26 21:32:41 -05:00
} = await loadFixture(deploy));
await dao.addPost(account1, 'proposal-content-id');
2024-03-26 21:43:46 -05:00
postIndex = await dao.postCount() - BigInt(1);
2024-03-26 21:32:41 -05:00
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 () => {
2024-03-26 21:43:46 -05:00
console.log('total REP', await dao.totalSupply());
2024-03-26 21:32:41 -05:00
await proposals.attest(0, 20);
2024-03-26 21:43:46 -05:00
await expect(proposals.evaluateAttestation(0)).to.emit(dao, 'ValidationPoolInitiated').withArgs(postIndex);
proposal = await proposals.proposals(0);
expect(proposal.stage).to.equal(1);
});
it('threshold may be met by accumulation of attestations', async () => {
await proposals.connect(account1).attest(0, 10);
await proposals.connect(account2).attest(0, 20);
await expect(proposals.evaluateAttestation(0)).to.emit(dao, 'ValidationPoolInitiated').withArgs(postIndex);
2024-03-26 21:32:41 -05:00
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
});
});
2024-03-26 21:43:46 -05:00
describe('Referendum 0% binding', () => {
beforeEach(async () => {
await proposals.attest(0, 20);
await expect(proposals.evaluateAttestation(0)).to.emit(dao, 'ValidationPoolInitiated').withArgs(postIndex);
});
it('', async () => {
});
});
2024-03-26 21:32:41 -05:00
});
});