dgf-prototype/ethereum/test/Onboarding.js

152 lines
6.7 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');
const deployDAO = require('./util/deploy-dao');
2024-03-17 21:00:31 -05:00
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();
2024-06-28 13:44:18 -05:00
const { dao, forum } = await deployDAO();
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');
2024-06-28 13:44:18 -05:00
const onboarding = await Onboarding.deploy(dao.target, forum.target, proposals.target, PRICE);
2024-03-17 21:00:31 -05:00
2024-06-28 13:44:18 -05:00
await forum.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 {
2024-06-28 13:44:18 -05:00
dao, forum, onboarding, account1, account2,
2024-03-17 21:00:31 -05:00
};
}
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;
2024-06-28 13:44:18 -05:00
let forum;
2024-03-17 21:00:31 -05:00
let onboarding;
let account1;
let account2;
beforeEach(async () => {
({
2024-06-28 13:44:18 -05:00
dao, forum, onboarding, account1, account2,
2024-03-17 21:00:31 -05:00
} = 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);
2024-06-28 13:44:18 -05:00
const post = await forum.getPost('evidence-content-id');
2024-03-17 21:00:31 -05:00
expect(post.sender).to.equal(onboarding.target);
2024-06-28 13:44:18 -05:00
expect(post.authors).to.have.length(1);
expect(post.authors[0].weightPPM).to.equal(1000000);
expect(post.authors[0].authorAddress).to.equal(account1);
2024-06-29 12:57:07 -05:00
const pool = await dao.getValidationPool(1);
expect(pool.props.postId).to.equal('evidence-content-id');
expect(pool.props.fee).to.equal(PRICE * 0.9);
2024-03-17 21:00:31 -05:00
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 {
2024-06-28 13:44:18 -05:00
dao, forum, onboarding, account2,
2024-03-17 21:00:31 -05:00
} = 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);
2024-06-28 13:44:18 -05:00
expect(await forum.postCount()).to.equal(3);
const post = await forum.getPost('req-content-id');
2024-03-17 21:00:31 -05:00
expect(post.sender).to.equal(onboarding.target);
2024-06-28 13:44:18 -05:00
expect(post.authors).to.have.length(1);
expect(post.authors[0].weightPPM).to.equal(1000000);
expect(post.authors[0].authorAddress).to.equal(account2);
2024-06-29 12:57:07 -05:00
const pool = await dao.getValidationPool(2);
expect(pool.props.postId).to.equal('req-content-id');
expect(pool.props.fee).to.equal(PRICE * 0.1);
2024-03-17 21:00:31 -05:00
expect(pool.sender).to.equal(onboarding.target);
expect(pool.props.fee);
2024-03-17 21:00:31 -05:00
});
it('if the first validation pool is rejected it should not trigger a second pool', async () => {
const {
2024-06-28 13:44:18 -05:00
dao, forum, onboarding, account2,
2024-03-17 21:00:31 -05:00
} = 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');
2024-06-28 13:44:18 -05:00
expect(await forum.postCount()).to.equal(2);
2024-03-17 21:00:31 -05:00
});
});
});