UNPKG

@vechain/vebetterdao-contracts

Version:

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

128 lines (127 loc) 9.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const mocha_1 = require("mocha"); const chai_1 = require("chai"); const fixture_test_1 = require("./fixture.test"); const common_1 = require("../helpers/common"); const hardhat_1 = require("hardhat"); const local_1 = require("@repo/config/contracts/envs/local"); (0, mocha_1.describe)("Governance - V7 Compatibility & Thresholds - @shard4e", function () { let governor; let vot3; let b3tr; let b3trContract; let minterAccount; let proposer; let owner; let emissions; (0, mocha_1.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; emissions = fixture.emissions; // Setup proposer for all tests await emissions.connect(minterAccount).start(); await (0, fixture_test_1.setupProposer)(proposer, b3tr, vot3, minterAccount); }); (0, mocha_1.describe)("Backward Compatibility", function () { (0, mocha_1.it)("Should maintain backward compatibility with existing proposals", async function () { const description = "coolDescription"; // Create a proposal using the old method (propose) const tx = await (0, common_1.createProposal)(b3tr, b3trContract, proposer, description); const receipt = await tx.wait(); const proposalId = await (0, common_1.getProposalIdFromTx)(tx); // Verify the proposal works exactly as before (0, chai_1.expect)(await governor.state(proposalId)).to.eql(hardhat_1.ethers.toBigInt(0)); // pending (0, chai_1.expect)(await governor.proposalProposer(proposalId)).to.eql(proposer.address); (0, chai_1.expect)(await governor.proposalType(proposalId)).to.eql(fixture_test_1.STANDARD_PROPOSAL_TYPE); // Should default to Standard // Verify both events are emitted even for old method await (0, fixture_test_1.validateProposalEvents)(governor, receipt, Number(fixture_test_1.STANDARD_PROPOSAL_TYPE), proposer.address, description); }); }); (0, mocha_1.describe)("Deposit Threshold Functionality", function () { (0, mocha_1.it)("Should return the correct deposit threshold for a proposal type", async function () { const config = (0, local_1.createLocalConfig)(); // Get the current total supply const totalSupply = await b3tr.totalSupply(); //Calculate expected deposit thresholds considering the cap const standardDepositThresholdCap = hardhat_1.ethers.toBigInt(config.B3TR_GOVERNOR_STANDARD_DEPOSIT_THRESHOLD_CAP); const grantDepositThresholdCap = hardhat_1.ethers.toBigInt(config.B3TR_GOVERNOR_GRANT_DEPOSIT_THRESHOLD_CAP); const expectedStandardDepositThreshold = (hardhat_1.ethers.toBigInt(config.B3TR_GOVERNOR_DEPOSIT_THRESHOLD) * totalSupply) / hardhat_1.ethers.toBigInt(100) > standardDepositThresholdCap ? standardDepositThresholdCap : (hardhat_1.ethers.toBigInt(config.B3TR_GOVERNOR_DEPOSIT_THRESHOLD) * totalSupply) / hardhat_1.ethers.toBigInt(100); const expectedGrantDepositThreshold = (hardhat_1.ethers.toBigInt(config.B3TR_GOVERNOR_GRANT_DEPOSIT_THRESHOLD) * totalSupply) / hardhat_1.ethers.toBigInt(100) > grantDepositThresholdCap ? grantDepositThresholdCap : (hardhat_1.ethers.toBigInt(config.B3TR_GOVERNOR_GRANT_DEPOSIT_THRESHOLD) * totalSupply) / hardhat_1.ethers.toBigInt(100); //Standard threshold percentage remains the same after upgrade const depositThreshold = await governor.depositThresholdByProposalType(fixture_test_1.STANDARD_PROPOSAL_TYPE); (0, chai_1.expect)(depositThreshold).to.eql(expectedStandardDepositThreshold); //Grant threshold percentage remains the same after upgrade const depositThresholdGrant = await governor.depositThresholdByProposalType(fixture_test_1.GRANT_PROPOSAL_TYPE); (0, chai_1.expect)(depositThresholdGrant).to.eql(expectedGrantDepositThreshold); }); (0, mocha_1.it)("Should return the correct deposit threshold for STANDARD proposal type using the old method", async function () { const config = (0, local_1.createLocalConfig)(); // Get the current total supply const totalSupply = await b3tr.totalSupply(); //Calculate expected deposit thresholds considering the cap const standardDepositThresholdCap = hardhat_1.ethers.toBigInt(config.B3TR_GOVERNOR_STANDARD_DEPOSIT_THRESHOLD_CAP); // Calculate expected deposit threshold: (percentage * totalSupply) / 100 const expectedDepositThreshold = (hardhat_1.ethers.toBigInt(config.B3TR_GOVERNOR_DEPOSIT_THRESHOLD) * totalSupply) / hardhat_1.ethers.toBigInt(100) > standardDepositThresholdCap ? standardDepositThresholdCap : (hardhat_1.ethers.toBigInt(config.B3TR_GOVERNOR_DEPOSIT_THRESHOLD) * totalSupply) / hardhat_1.ethers.toBigInt(100); const depositThreshold = await governor.depositThresholdByProposalType(fixture_test_1.STANDARD_PROPOSAL_TYPE); (0, chai_1.expect)(depositThreshold).to.eql(expectedDepositThreshold); }); (0, mocha_1.it)("Should return the max cap for proposals if the percentage based threshold is greater than the max threshold", async function () { const proposalStandardType = hardhat_1.ethers.toBigInt(0); const config = (0, local_1.createLocalConfig)(); const expectedThreshold = hardhat_1.ethers.toBigInt(config.B3TR_GOVERNOR_STANDARD_DEPOSIT_THRESHOLD_CAP); // Set the deposit threshold percentage to 100% await governor.connect(owner).setProposalTypeDepositThresholdPercentage(100, proposalStandardType); // Get the deposit threshold const depositThreshold = await governor.depositThresholdByProposalType(fixture_test_1.STANDARD_PROPOSAL_TYPE); (0, chai_1.expect)(depositThreshold).to.eql(expectedThreshold); }); (0, mocha_1.it)("Proposals should remain unaffected by the deposit threshold cap, if was created before the cap was set", async function () { const description = "coolDescription"; // Create a proposal using the old method (propose) const tx = await (0, common_1.createProposal)(b3tr, b3trContract, proposer, description); const receipt = await tx.wait(); const proposalId = await (0, common_1.getProposalIdFromTx)(tx); // Verify the proposal works exactly as before (0, chai_1.expect)(await governor.state(proposalId)).to.eql(hardhat_1.ethers.toBigInt(0)); // pending (0, chai_1.expect)(await governor.proposalProposer(proposalId)).to.eql(proposer.address); (0, chai_1.expect)(await governor.proposalType(proposalId)).to.eql(fixture_test_1.STANDARD_PROPOSAL_TYPE); // Should default to Standard // Verify both events are emitted even for old method await (0, fixture_test_1.validateProposalEvents)(governor, receipt, Number(fixture_test_1.STANDARD_PROPOSAL_TYPE), proposer.address, description); //Expect the proposal deposit threshold to be the same as in the config const contractDepositThresholdBeforeCapSet = await governor.depositThresholdByProposalType(fixture_test_1.STANDARD_PROPOSAL_TYPE); const proposalDepositThresholdBeforeCapSet = await governor.proposalDepositThreshold(proposalId); (0, chai_1.expect)(proposalDepositThresholdBeforeCapSet).to.eql(contractDepositThresholdBeforeCapSet); // Set the deposit threshold percentage to 100% await governor.connect(owner).setProposalTypeDepositThresholdPercentage(100, fixture_test_1.STANDARD_PROPOSAL_TYPE); // Expect the deposit threshold to be the same as before the cap was set const proposalDepositThresholdAfterCapSet = await governor.proposalDepositThreshold(proposalId); const contractDepositThresholdAfterCapSet = await governor.depositThresholdByProposalType(fixture_test_1.STANDARD_PROPOSAL_TYPE); //The contract deposit threshold should be updated but the proposal deposit threshold should not, so proposals created before the cap was set should remain unaffected by the cap (0, chai_1.expect)(proposalDepositThresholdAfterCapSet).to.eql(proposalDepositThresholdBeforeCapSet); (0, chai_1.expect)(proposalDepositThresholdAfterCapSet).to.not.eql(contractDepositThresholdAfterCapSet); //Create a new proposal using the old method const tx2 = await (0, common_1.createProposal)(b3tr, b3trContract, proposer, `${description} - 2`); await tx2.wait(); const proposalId2 = await (0, common_1.getProposalIdFromTx)(tx2); //Expect the proposal deposit threshold to be for the new proposal to be the same as the contract deposit threshold , which is updated after the cap was set const proposalDepositThresholdAfterCapSet2 = await governor.proposalDepositThreshold(proposalId2); (0, chai_1.expect)(proposalDepositThresholdAfterCapSet2).to.eql(contractDepositThresholdAfterCapSet); }); }); });