UNPKG

@vechain/vebetterdao-contracts

Version:

Open-source repository that houses the smart contracts powering the decentralized VeBetterDAO on the VeChain Thor blockchain.

111 lines (110 loc) 6.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const hardhat_1 = require("hardhat"); const mocha_1 = require("mocha"); const common_1 = require("../helpers/common"); const fixture_test_1 = require("./fixture.test"); (0, mocha_1.describe)("Governance - V9 Compatibility - @shard4h", function () { let governor; let vot3; let b3tr; let b3trContract; let minterAccount; let proposer; let owner; let emissions; let otherAccounts; let veBetterPassport; let xAllocationVoting; beforeEach(async function () { const fixture = await (0, fixture_test_1.setupGovernanceFixtureWithEmissions)(); governor = fixture.governor; vot3 = fixture.vot3; b3tr = fixture.b3tr; b3trContract = fixture.b3trContract; minterAccount = fixture.minterAccount; proposer = fixture.proposer; owner = fixture.owner; otherAccounts = fixture.otherAccounts; emissions = fixture.emissions; veBetterPassport = fixture.veBetterPassport; xAllocationVoting = fixture.xAllocationVoting; await emissions.connect(minterAccount).start(); await (0, fixture_test_1.setupProposer)(proposer, b3tr, vot3, minterAccount); await (0, fixture_test_1.setupVoter)(otherAccounts[0], b3tr, vot3, minterAccount, owner, veBetterPassport); await (0, fixture_test_1.setupVoter)(otherAccounts[1], b3tr, vot3, minterAccount, owner, veBetterPassport); await (0, fixture_test_1.setupVoter)(otherAccounts[2], b3tr, vot3, minterAccount, owner, veBetterPassport); await (0, fixture_test_1.setupVoter)(otherAccounts[3], b3tr, vot3, minterAccount, owner, veBetterPassport); }); (0, mocha_1.describe)("Governance - Latest Version - Proposal Lifecycle", function () { (0, mocha_1.it)("Should be able to create, deposit, and cancel a proposal", async () => { const functionToCall = "tokenDetails"; const encodedFunctionCall = b3trContract.interface.encodeFunctionData(functionToCall, []); const tx = await (0, common_1.createProposal)(b3tr, b3trContract, proposer, `description ${this.title}`, functionToCall, []); const proposalId = await (0, common_1.getProposalIdFromTx)(tx); const stateBeforeCancel = await governor.state(proposalId); (0, chai_1.expect)(stateBeforeCancel).to.equal(0); // pending await governor .connect(proposer) .cancel([await b3tr.getAddress()], [0], [encodedFunctionCall], hardhat_1.ethers.keccak256(hardhat_1.ethers.toUtf8Bytes(`description ${this.title}`)), "reason"); const stateAfterCancel = await governor.state(proposalId); (0, chai_1.expect)(stateAfterCancel).to.equal(2); // cancelled }); (0, mocha_1.it)("Should be able to vote on a proposal", async () => { const functionToCall = "tokenDetails"; const tx = await (0, common_1.createProposal)(b3tr, b3trContract, proposer, `description ${this.title}`, functionToCall, []); const proposalId = await (0, common_1.getProposalIdFromTx)(tx); // Deposit enough to meet threshold const depositThreshold = await governor.proposalDepositThreshold(proposalId); const currentDeposit = await governor.getProposalDeposits(proposalId); if (currentDeposit < depositThreshold) { const remaining = depositThreshold - currentDeposit; await (0, fixture_test_1.setupSupporter)(proposer, vot3, remaining, governor); await governor.connect(proposer).deposit(remaining, proposalId); } // Wait for round to become active await (0, common_1.waitForCurrentRoundToEnd)(); await (0, fixture_test_1.startNewRoundAndGetRoundId)(emissions, xAllocationVoting); // Cast vote const voter = otherAccounts[0]; await governor.connect(voter).castVote(proposalId, 1); // for (0, chai_1.expect)(await governor.hasVoted(proposalId, voter.address)).to.be.true; }); (0, mocha_1.it)("Should be able to mark as in development and completed", async () => { const functionToCall = "tokenDetails"; const encodedFunctionCall = b3trContract.interface.encodeFunctionData(functionToCall, []); const tx = await (0, common_1.createProposal)(b3tr, b3trContract, proposer, `description ${this.title}`, functionToCall, []); const proposalId = await (0, common_1.getProposalIdFromTx)(tx); // Deposit enough to meet threshold const depositThreshold = await governor.proposalDepositThreshold(proposalId); const currentDeposit = await governor.getProposalDeposits(proposalId); if (currentDeposit < depositThreshold) { const remaining = depositThreshold - currentDeposit; await (0, fixture_test_1.setupSupporter)(proposer, vot3, remaining, governor); await governor.connect(proposer).deposit(remaining, proposalId); } await (0, common_1.waitForCurrentRoundToEnd)(); await (0, fixture_test_1.startNewRoundAndGetRoundId)(emissions, xAllocationVoting); // Vote for the proposal for (let i = 0; i < 4; i++) { await governor.connect(otherAccounts[i]).castVote(proposalId, 1); // for } await (0, common_1.waitForCurrentRoundToEnd)(); // Queue and execute const descriptionHash = hardhat_1.ethers.keccak256(hardhat_1.ethers.toUtf8Bytes(`description ${this.title}`)); await governor.queue([await b3tr.getAddress()], [0], [encodedFunctionCall], descriptionHash); await governor.execute([await b3tr.getAddress()], [0], [encodedFunctionCall], descriptionHash); const stateAfterExecute = await governor.state(proposalId); (0, chai_1.expect)(stateAfterExecute).to.equal(6); // Executed // Mark as in development await governor.connect(owner).markAsInDevelopment(proposalId); const stateAfterMarkInDev = await governor.state(proposalId); (0, chai_1.expect)(stateAfterMarkInDev).to.equal(8); // InDevelopment // Mark as completed await governor.connect(owner).markAsCompleted(proposalId); const stateAfterMarkCompleted = await governor.state(proposalId); (0, chai_1.expect)(stateAfterMarkCompleted).to.equal(9); // Completed }); }); });