dgf-prototype/ethereum/test/Onboarding.js

155 lines
6.8 KiB
JavaScript
Raw Permalink Normal View History

2024-03-17 21:00:31 -05:00
const {
time,
loadFixture,
} = require('@nomicfoundation/hardhat-toolbox/network-helpers');
const { expect } = require('chai');
const { ethers } = require('hardhat');
describe('Onboarding', () => {
const PRICE = 100;
const STAKE_DURATION = 60;
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);
2024-03-17 21:00:31 -05:00
const Onboarding = await ethers.getContractFactory('Onboarding');
const onboarding = await Onboarding.deploy(dao.target, proposals.target, PRICE);
2024-03-17 21:00:31 -05:00
await dao.addPost([{ weightPPM: 1000000, authorAddress: account1 }], 'content-id', []);
2024-03-17 21:00:31 -05:00
const callbackData = ethers.AbiCoder.defaultAbiCoder().encode([], []);
2024-03-28 15:06:14 -05:00
await dao.initiateValidationPool(
'content-id',
2024-03-28 15:06:14 -05:00
60,
[1, 3],
[1, 2],
100,
true,
false,
callbackData,
{ value: 100 },
);
2024-03-17 21:00:31 -05:00
await time.increase(61);
await dao.evaluateOutcome(0);
expect(await dao.balanceOf(account1)).to.equal(100);
return {
dao, onboarding, account1, account2,
};
}
it('Should deploy', async () => {
const { dao, onboarding, account1 } = await loadFixture(deploy);
expect(dao).to.exist;
expect(onboarding).to.exist;
expect(await dao.memberCount()).to.equal(1);
expect(await dao.balanceOf(account1)).to.equal(100);
expect(await dao.totalSupply()).to.equal(100);
expect(await onboarding.stakeCount()).to.equal(0);
});
2024-03-19 22:22:36 -05:00
describe('Work approval/disapproval', () => {
2024-03-17 21:00:31 -05:00
let dao;
let onboarding;
let account1;
let account2;
beforeEach(async () => {
({
dao, onboarding, account1, account2,
} = await loadFixture(deploy));
await dao.stakeAvailability(onboarding.target, 50, STAKE_DURATION);
});
it('should be able to submit work approval', async () => {
2024-03-19 22:22:36 -05:00
await onboarding.connect(account2).requestWork('req-content-id', { value: PRICE });
2024-04-10 15:47:25 -05:00
await onboarding.submitWorkEvidence(0, 'evidence-content-id', []);
2024-03-17 21:00:31 -05:00
await expect(onboarding.submitWorkApproval(0, true))
.to.emit(dao, 'ValidationPoolInitiated').withArgs(1)
.to.emit(onboarding, 'WorkApprovalSubmitted').withArgs(0, true);
const post = await dao.posts('evidence-content-id');
2024-03-17 21:00:31 -05:00
expect(post.sender).to.equal(onboarding.target);
expect(post.id).to.equal('evidence-content-id');
const postAuthors = await dao.getPostAuthors('evidence-content-id');
expect(postAuthors).to.have.length(1);
expect(postAuthors[0].weightPPM).to.equal(1000000);
expect(postAuthors[0].authorAddress).to.equal(account1);
2024-03-17 21:00:31 -05:00
const pool = await dao.validationPools(1);
expect(pool.postId).to.equal('evidence-content-id');
2024-03-17 21:00:31 -05:00
expect(pool.fee).to.equal(PRICE * 0.9);
expect(pool.sender).to.equal(onboarding.target);
});
it('should be able to submit work disapproval', async () => {
2024-03-19 22:22:36 -05:00
await onboarding.connect(account2).requestWork('req-content-id', { value: PRICE });
2024-04-10 15:47:25 -05:00
await onboarding.submitWorkEvidence(0, 'evidence-content-id', []);
2024-03-17 21:00:31 -05:00
await expect(onboarding.submitWorkApproval(0, false))
.to.emit(dao, 'ValidationPoolInitiated').withArgs(1)
.to.emit(onboarding, 'WorkApprovalSubmitted').withArgs(0, false);
});
it('should not be able to submit work approval/disapproval twice', async () => {
2024-03-19 22:22:36 -05:00
await onboarding.connect(account2).requestWork('req-content-id', { value: PRICE });
2024-04-10 15:47:25 -05:00
await onboarding.submitWorkEvidence(0, 'evidence-content-id', []);
2024-03-17 21:00:31 -05:00
await expect(onboarding.submitWorkApproval(0, true)).to.emit(dao, 'ValidationPoolInitiated').withArgs(1);
await expect(onboarding.submitWorkApproval(0, true)).to.be.revertedWith('Status must be EvidenceSubmitted');
});
it('should not be able to submit work evidence after work approval', async () => {
2024-03-19 22:22:36 -05:00
await onboarding.connect(account2).requestWork('req-content-id', { value: PRICE });
2024-04-10 15:47:25 -05:00
await onboarding.submitWorkEvidence(0, 'evidence-content-id', []);
2024-03-17 21:00:31 -05:00
await expect(onboarding.submitWorkApproval(0, true)).to.emit(dao, 'ValidationPoolInitiated').withArgs(1);
2024-04-10 15:47:25 -05:00
await expect(onboarding.submitWorkEvidence(0, 'evidence-content-id', [])).to.be.revertedWith('Status must be Requested');
2024-03-17 21:00:31 -05:00
});
it('should not be able to submit work approval/disapproval before work evidence', async () => {
2024-03-19 22:22:36 -05:00
await onboarding.connect(account2).requestWork('req-content-id', { value: PRICE });
2024-03-17 21:00:31 -05:00
await expect(onboarding.submitWorkApproval(0, true)).to.be.revertedWith('Status must be EvidenceSubmitted');
});
});
describe('Onboarding followup', () => {
it('resolving the first validation pool should trigger a second pool', async () => {
const {
dao, onboarding, account2,
} = await loadFixture(deploy);
await dao.stakeAvailability(onboarding.target, 50, STAKE_DURATION);
2024-03-19 22:22:36 -05:00
await onboarding.connect(account2).requestWork('req-content-id', { value: PRICE });
2024-04-10 15:47:25 -05:00
await onboarding.submitWorkEvidence(0, 'evidence-content-id', []);
2024-03-17 21:00:31 -05:00
await expect(onboarding.submitWorkApproval(0, true)).to.emit(dao, 'ValidationPoolInitiated').withArgs(1);
await time.increase(86401);
await expect(dao.evaluateOutcome(1)).to.emit(dao, 'ValidationPoolInitiated').withArgs(2);
expect(await dao.postCount()).to.equal(3);
const post = await dao.posts('req-content-id');
2024-03-17 21:00:31 -05:00
expect(post.sender).to.equal(onboarding.target);
expect(post.id).to.equal('req-content-id');
2024-04-20 12:41:21 -05:00
const postAuthors = await dao.getPostAuthors('req-content-id');
expect(postAuthors).to.have.length(1);
expect(postAuthors[0].weightPPM).to.equal(1000000);
2024-04-20 12:41:21 -05:00
expect(postAuthors[0].authorAddress).to.equal(account2);
2024-03-17 21:00:31 -05:00
const pool = await dao.validationPools(2);
expect(pool.postId).to.equal('req-content-id');
2024-03-17 21:00:31 -05:00
expect(pool.fee).to.equal(PRICE * 0.1);
expect(pool.sender).to.equal(onboarding.target);
expect(pool.fee);
});
it('if the first validation pool is rejected it should not trigger a second pool', async () => {
const {
dao, onboarding, account2,
} = await loadFixture(deploy);
2024-03-19 22:22:36 -05:00
await dao.stakeAvailability(onboarding.target, 40, STAKE_DURATION);
await onboarding.connect(account2).requestWork('req-content-id', { value: PRICE });
2024-04-10 15:47:25 -05:00
await onboarding.submitWorkEvidence(0, 'evidence-content-id', []);
2024-03-17 21:00:31 -05:00
await expect(onboarding.submitWorkApproval(0, true)).to.emit(dao, 'ValidationPoolInitiated').withArgs(1);
await dao.stakeOnValidationPool(1, 60, false);
2024-03-17 21:00:31 -05:00
await time.increase(86401);
await expect(dao.evaluateOutcome(1)).not.to.emit(dao, 'ValidationPoolInitiated');
expect(await dao.postCount()).to.equal(2);
});
});
});