proposal-46/test/Proposal.js
2024-01-31 10:12:30 +00:00

83 lines
3.0 KiB
JavaScript

const { expect } = require("chai");
const contentHash = require('content-hash')
const {
resetStateBeforeProposal,
deployAndExecuteProposal,
governanceAddr,
getProxyImplAddr,
getGovernance,
getEnsResolver
} = require("./utils");
describe("Proposal results check", function () {
beforeEach(resetStateBeforeProposal);
it("IPFS contenthashes on ENS should be correct", async function(){
await deployAndExecuteProposal();
const docsEns = "docs.tornadocash.eth";
const docsSourceEns = "docs.sources.tornadocash.eth";
const docsIpfs = "QmYjBe2bNTGQzgdqAi7hkdNJ9BBrAgf4e8teRWLa4oN6Y6";
const docsSourceIpfs = "QmcdTqAMD4nvDhAfWkEnKCQHhFk8K7XmFDouextcfrjWif";
const ensResolver = await getEnsResolver(docsEns);
expect(contentHash.decode(await ensResolver.contenthash(ethers.namehash(docsEns)))).to.be.equal(docsIpfs);
expect(contentHash.decode(await ensResolver.contenthash(ethers.namehash(docsSourceEns)))).to.be.equal(docsSourceIpfs);
})
it("Governance implementation should be updated", async function () {
const currentImplAddr = "0xBa178126C28F50Ee60322a82f5EbCd6b3711e101";
const { newGovernanceImplAddr } = await deployAndExecuteProposal();
const implementationAddr = await getProxyImplAddr(governanceAddr);
expect(implementationAddr).to.equal(newGovernanceImplAddr);
expect(implementationAddr).to.not.be.equal(currentImplAddr);
});
it("Governance version should be updated", async function () {
const { governanceContract } = await deployAndExecuteProposal();
expect(await governanceContract.version()).to.be.equal("5.proposal-state-patch");
});
async function getProposalInfo(governance, proposalId) {
const proposalData = await governance.proposals(proposalId);
const state = await governance.state(proposalId);
return { data: proposalData, status: Number(state) };
}
function getProposalQuorum(proposalInfo) {
return proposalInfo.data[4];
}
function isProposalExecuted(proposalInfo) {
return proposalInfo.data[6];
}
it("Proposal states should be correct", async function () {
const governance = await getGovernance();
const lastProposal = await governance.proposalCount();
const oldProposals = await Promise.all(
Array.from({ length: Number(lastProposal) - 1 }, (_, i) => i + 1).map((i) => getProposalInfo(governance, i)),
);
const { governanceContract } = await deployAndExecuteProposal();
const proposals = await Promise.all(
Array.from({ length: Number(lastProposal) - 1 }, (_, i) => i + 1).map((i) =>
getProposalInfo(governanceContract, i),
),
);
for (const [id, proposalInfo] of proposals.entries()) {
const oldProposalInfo = oldProposals[id];
if (
oldProposalInfo.status == 2 &&
getProposalQuorum(oldProposalInfo) > 25000n * 10n ** 18n &&
isProposalExecuted(oldProposalInfo)
) {
expect(proposalInfo.status).to.be.equal(5);
continue;
}
expect(oldProposalInfo.status).to.be.equal(proposalInfo.status);
}
});
});