UNPKG

@vechain/vebetterdao-contracts

Version:

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

181 lines (180 loc) 12.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const hardhat_1 = require("hardhat"); const chai_1 = require("chai"); const helpers_1 = require("./helpers"); const mocha_1 = require("mocha"); const local_1 = require("@repo/config/contracts/envs/local"); (0, mocha_1.describe)("B3TR Token - @shard0", function () { (0, mocha_1.describe)("Deployment", function () { (0, mocha_1.it)("should deploy the contract", async function () { const { b3tr } = await (0, helpers_1.getOrDeployContractInstances)({ forceDeploy: false }); await b3tr.waitForDeployment(); const address = await b3tr.getAddress(); (0, chai_1.expect)(address).not.to.eql(undefined); }); (0, mocha_1.it)("should have the correct name", async function () { const { b3tr } = await (0, helpers_1.getOrDeployContractInstances)({ forceDeploy: false }); const res = await b3tr.name(); (0, chai_1.expect)(res).to.eql("B3TR"); const res2 = await b3tr.symbol(); (0, chai_1.expect)(res2).to.eql("B3TR"); }); (0, mocha_1.it)("should have the correct max supply", async function () { const config = (0, local_1.createLocalConfig)(); const { b3tr } = await (0, helpers_1.getOrDeployContractInstances)({ forceDeploy: false, config }); const cap = await b3tr.cap(); (0, chai_1.expect)(cap).to.eql(hardhat_1.ethers.parseEther("1000243154")); }); (0, mocha_1.it)("admin role is set correctly upon deploy", async function () { const { b3tr, owner } = await (0, helpers_1.getOrDeployContractInstances)({ forceDeploy: false }); const defaultAdminRole = await b3tr.DEFAULT_ADMIN_ROLE(); const res = await b3tr.hasRole(defaultAdminRole, owner); (0, chai_1.expect)(res).to.eql(true); }); (0, mocha_1.it)("minter role is set correctly upon deploy", async function () { const { b3tr, otherAccount, minterAccount } = await (0, helpers_1.getOrDeployContractInstances)({ forceDeploy: false }); const operatorRole = await b3tr.MINTER_ROLE(); const res = await b3tr.hasRole(operatorRole, minterAccount); (0, chai_1.expect)(res).to.eql(true); // test that operator role is not set for other accounts (0, chai_1.expect)(await b3tr.hasRole(operatorRole, otherAccount)).to.eql(false); }); (0, mocha_1.it)("should revert if default admin set to zero address on initilisation", async function () { const { owner, minterAccount } = await (0, helpers_1.getOrDeployContractInstances)({ forceDeploy: false }); const B3trContract = await hardhat_1.ethers.getContractFactory("B3TR"); await (0, chai_1.expect)(B3trContract.deploy(hardhat_1.ethers.ZeroAddress, minterAccount, owner)).to.be.reverted; }); }); (0, mocha_1.describe)("Access Control", function () { (0, mocha_1.it)("only admin can grant minter role", async function () { const { b3tr, owner, otherAccount } = await (0, helpers_1.getOrDeployContractInstances)({ forceDeploy: true, }); const operatorRole = await b3tr.MINTER_ROLE(); (0, chai_1.expect)(await b3tr.hasRole(operatorRole, otherAccount)).to.eql(false); await (0, chai_1.expect)(b3tr.connect(otherAccount).grantRole(operatorRole, otherAccount)).to.be.reverted; await b3tr.connect(owner).grantRole(operatorRole, otherAccount); (0, chai_1.expect)(await b3tr.hasRole(operatorRole, otherAccount)).to.eql(true); }); (0, mocha_1.it)("only admin can revoke minter role", async function () { const { b3tr, owner, otherAccount } = await (0, helpers_1.getOrDeployContractInstances)({ forceDeploy: false }); const operatorRole = await b3tr.MINTER_ROLE(); await b3tr.connect(owner).grantRole(operatorRole, otherAccount); (0, chai_1.expect)(await b3tr.hasRole(operatorRole, otherAccount)).to.eql(true); await (0, chai_1.expect)(b3tr.connect(otherAccount).revokeRole(operatorRole, otherAccount)).to.be.reverted; await b3tr.connect(owner).revokeRole(operatorRole, otherAccount); (0, chai_1.expect)(await b3tr.hasRole(operatorRole, otherAccount)).to.eql(false); }); (0, mocha_1.it)("only admin can grant admin role", async function () { const { b3tr, owner, otherAccount } = await (0, helpers_1.getOrDeployContractInstances)({ forceDeploy: false }); const adminRole = await b3tr.DEFAULT_ADMIN_ROLE(); // at the beginning owner is admin (0, chai_1.expect)(await b3tr.hasRole(adminRole, otherAccount)).to.eql(false); (0, chai_1.expect)(await b3tr.hasRole(adminRole, owner)).to.eql(true); await (0, chai_1.expect)(b3tr.connect(otherAccount).grantRole(adminRole, otherAccount)).to.be.reverted; await b3tr.connect(owner).grantRole(adminRole, otherAccount); (0, chai_1.expect)(await b3tr.hasRole(adminRole, otherAccount)).to.eql(true); // owner is still admin until it is revoked (0, chai_1.expect)(await b3tr.hasRole(adminRole, owner)).to.eql(true); }); (0, mocha_1.it)("only admin can revoke admin role", async function () { const { b3tr, owner, otherAccount, minterAccount } = await (0, helpers_1.getOrDeployContractInstances)({ forceDeploy: false }); const adminRole = await b3tr.DEFAULT_ADMIN_ROLE(); // after last test both owner and otherAccount are admin (0, chai_1.expect)(await b3tr.hasRole(adminRole, otherAccount)).to.eql(true); (0, chai_1.expect)(await b3tr.hasRole(adminRole, owner)).to.eql(true); await (0, chai_1.expect)(b3tr.connect(minterAccount).revokeRole(adminRole, owner)).to.be.reverted; await b3tr.connect(otherAccount).revokeRole(adminRole, owner); // owner is no longer admin (0, chai_1.expect)(await b3tr.hasRole(adminRole, owner)).to.eql(false); // otherAccount is still admin until (0, chai_1.expect)(await b3tr.hasRole(adminRole, otherAccount)).to.eql(true); }); (0, mocha_1.it)("admin transfer admin permissions to another account", async function () { const { b3tr, owner, otherAccounts } = await (0, helpers_1.getOrDeployContractInstances)({ forceDeploy: true, }); const adminRole = await b3tr.DEFAULT_ADMIN_ROLE(); const minterRole = await b3tr.MINTER_ROLE(); const newAdmin = otherAccounts[5]; (0, chai_1.expect)(await b3tr.hasRole(adminRole, owner)).to.eql(true); (0, chai_1.expect)(await b3tr.hasRole(adminRole, newAdmin)).to.eql(false); await b3tr.connect(owner).grantRole(adminRole, newAdmin); (0, chai_1.expect)(await b3tr.hasRole(adminRole, newAdmin)).to.eql(true); await b3tr.connect(owner).renounceRole(adminRole, owner); (0, chai_1.expect)(await b3tr.hasRole(adminRole, owner)).to.eql(false); (0, chai_1.expect)(await b3tr.hasRole(adminRole, newAdmin)).to.eql(true); //can do same stuff as previous owner await b3tr.connect(newAdmin).grantRole(minterRole, otherAccounts[5]); await b3tr.connect(newAdmin).grantRole(adminRole, otherAccounts[5]); }); (0, mocha_1.it)("Only admin with PAUSER_ROLE can toggle pause of b3tr transfers", async function () { const { b3tr, otherAccount, owner } = await (0, helpers_1.getOrDeployContractInstances)({ forceDeploy: true }); (0, chai_1.expect)(await b3tr.hasRole(await b3tr.PAUSER_ROLE(), otherAccount.address)).to.eql(false); await (0, helpers_1.catchRevert)(b3tr.connect(otherAccount).pause()); await (0, helpers_1.catchRevert)(b3tr.connect(otherAccount).unpause()); (0, chai_1.expect)(await b3tr.hasRole(await b3tr.PAUSER_ROLE(), owner.address)).to.eql(true); await b3tr.connect(owner).pause(); (0, chai_1.expect)(await b3tr.paused()).to.eql(true); await b3tr.connect(owner).unpause(); (0, chai_1.expect)(await b3tr.paused()).to.eql(false); }); }); (0, mocha_1.describe)("Max supply", function () { (0, mocha_1.it)("cannot be minted more than max supply", async function () { const { b3tr, otherAccount, owner } = await (0, helpers_1.getOrDeployContractInstances)({ forceDeploy: true }); const operatorRole = await b3tr.MINTER_ROLE(); await b3tr.grantRole(operatorRole, owner); await (0, chai_1.expect)(b3tr.mint(otherAccount, hardhat_1.ethers.parseEther("1000243155"))).to.be.reverted; }); (0, mocha_1.it)("can be minted up to max supply", async function () { const config = (0, local_1.createLocalConfig)(); const { b3tr, otherAccount, owner } = await (0, helpers_1.getOrDeployContractInstances)({ forceDeploy: false, config }); const operatorRole = await b3tr.MINTER_ROLE(); await b3tr.grantRole(operatorRole, owner); await (0, chai_1.expect)(b3tr.mint(otherAccount, hardhat_1.ethers.parseEther("1000243154"))).not.to.be.reverted; const balance = await b3tr.balanceOf(otherAccount); (0, chai_1.expect)(String(balance)).to.eql(hardhat_1.ethers.parseEther("1000243154").toString()); }); }); (0, mocha_1.describe)("Mint", function () { (0, mocha_1.it)("only accounts with minter role can mint", async function () { const { b3tr, otherAccount, owner } = await (0, helpers_1.getOrDeployContractInstances)({ forceDeploy: true }); (0, chai_1.expect)(await b3tr.totalSupply()).to.eql(0n); await (0, chai_1.expect)(b3tr.mint(otherAccount, hardhat_1.ethers.parseEther("1"))).to.be.reverted; (0, chai_1.expect)(await b3tr.totalSupply()).to.eql(0n); const operatorRole = await b3tr.MINTER_ROLE(); await b3tr.grantRole(operatorRole, owner); await (0, chai_1.expect)(b3tr.mint(otherAccount, hardhat_1.ethers.parseEther("1"))).not.to.be.reverted; (0, chai_1.expect)(await b3tr.totalSupply()).to.eql(hardhat_1.ethers.parseEther("1")); const balance = await b3tr.balanceOf(otherAccount); (0, chai_1.expect)(String(balance)).to.eql(hardhat_1.ethers.parseEther("1").toString()); }); (0, mocha_1.it)("Should not be able to mint if transfers are paused", async function () { const { b3tr, otherAccount, owner } = await (0, helpers_1.getOrDeployContractInstances)({ forceDeploy: true }); const operatorRole = await b3tr.MINTER_ROLE(); await b3tr.grantRole(operatorRole, owner); await b3tr.pause(); await (0, helpers_1.catchRevert)(b3tr.mint(otherAccount, hardhat_1.ethers.parseEther("1"))); await b3tr.connect(owner).unpause(); await (0, chai_1.expect)(b3tr.mint(otherAccount, hardhat_1.ethers.parseEther("1"))).not.to.be.reverted; }); }); (0, mocha_1.describe)("Token details", function () { (0, mocha_1.it)("returns expected information", async function () { const { b3tr } = await (0, helpers_1.getOrDeployContractInstances)({ forceDeploy: false }); const name = await b3tr.name(); const symbol = await b3tr.symbol(); const decimals = await b3tr.decimals(); const cap = await b3tr.cap(); const totalSupply = await b3tr.totalSupply(); const tokenDetails = await b3tr.tokenDetails(); (0, chai_1.expect)(tokenDetails[0]).to.eql(name); (0, chai_1.expect)(tokenDetails[1]).to.eql(symbol); (0, chai_1.expect)(tokenDetails[2]).to.eql(decimals); (0, chai_1.expect)(tokenDetails[3]).to.eql(totalSupply); (0, chai_1.expect)(tokenDetails[4]).to.eql(cap); }); }); });