@vechain/vebetterdao-contracts
Version:
Open-source repository that houses the smart contracts powering the decentralized VeBetterDAO on the VeChain Thor blockchain.
72 lines (71 loc) • 4.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const mocha_1 = require("mocha");
const hardhat_1 = require("hardhat");
const helpers_1 = require("../../scripts/helpers");
const helpers_2 = require("../helpers");
(0, mocha_1.describe)("RelayerRewardsPool - V2 Upgrade - @shard18", function () {
let b3tr;
let emissions;
let xAllocationVoting;
let owner;
let minterAccount;
let relayer1;
let user1;
(0, mocha_1.beforeEach)(async function () {
const config = await (0, helpers_2.getOrDeployContractInstances)({
forceDeploy: true,
});
if (!config)
throw new Error("Failed to deploy contracts");
b3tr = config.b3tr;
emissions = config.emissions;
xAllocationVoting = config.xAllocationVoting;
owner = config.owner;
minterAccount = config.minterAccount;
relayer1 = config.otherAccounts[2];
user1 = config.otherAccounts[4];
await b3tr.connect(owner).grantRole(await b3tr.MINTER_ROLE(), owner.address);
await b3tr.connect(owner).grantRole(await b3tr.MINTER_ROLE(), await emissions.getAddress());
await emissions.connect(minterAccount).bootstrap();
await emissions.connect(minterAccount).start();
});
(0, mocha_1.it)("should preserve v1 state through V1 → V2 → V3 upgrade path", async function () {
const relayerRewardsPoolV1 = (await (0, helpers_1.deployProxy)("RelayerRewardsPoolV1", [
owner.address,
owner.address,
await b3tr.getAddress(),
await emissions.getAddress(),
await xAllocationVoting.getAddress(),
]));
(0, chai_1.expect)(await relayerRewardsPoolV1.version()).to.equal("1");
await relayerRewardsPoolV1.registerRelayer(relayer1.address);
await relayerRewardsPoolV1.setEarlyAccessBlocks(123);
await relayerRewardsPoolV1.setTotalActionsForRound(1, 2);
const depositAmount = hardhat_1.ethers.parseEther("10");
await b3tr.connect(owner).mint(owner.address, depositAmount);
await b3tr.connect(owner).approve(await relayerRewardsPoolV1.getAddress(), depositAmount);
await relayerRewardsPoolV1.deposit(depositAmount, 1);
await (0, helpers_2.waitForNextCycle)(emissions);
// V1 → V2
const relayerRewardsPoolV2 = (await (0, helpers_1.upgradeProxy)("RelayerRewardsPoolV1", "RelayerRewardsPoolV2", await relayerRewardsPoolV1.getAddress(), [], { version: 2 }));
(0, chai_1.expect)(await relayerRewardsPoolV2.version()).to.equal("2");
(0, chai_1.expect)(await relayerRewardsPoolV2.isRegisteredRelayer(relayer1.address)).to.equal(true);
(0, chai_1.expect)(await relayerRewardsPoolV2.getEarlyAccessBlocks()).to.equal(123);
(0, chai_1.expect)(await relayerRewardsPoolV2.totalActions(1)).to.equal(4);
(0, chai_1.expect)(await relayerRewardsPoolV2.getTotalRewards(1)).to.equal(depositAmount);
// V2 → V3 (current)
const relayerRewardsPoolV3 = (await (0, helpers_1.upgradeProxy)("RelayerRewardsPoolV2", "RelayerRewardsPool", await relayerRewardsPoolV2.getAddress(), [], { version: 3 }));
(0, chai_1.expect)(await relayerRewardsPoolV3.version()).to.equal("3");
(0, chai_1.expect)(await relayerRewardsPoolV3.isRegisteredRelayer(relayer1.address)).to.equal(true);
(0, chai_1.expect)(await relayerRewardsPoolV3.getEarlyAccessBlocks()).to.equal(123);
(0, chai_1.expect)(await relayerRewardsPoolV3.totalActions(1)).to.equal(4);
(0, chai_1.expect)(await relayerRewardsPoolV3.getTotalRewards(1)).to.equal(depositAmount);
(0, chai_1.expect)(await relayerRewardsPoolV3.getPreferredRelayer(user1.address)).to.equal(hardhat_1.ethers.ZeroAddress);
await (0, chai_1.expect)(relayerRewardsPoolV3.connect(user1).setPreferredRelayer(relayer1.address))
.to.emit(relayerRewardsPoolV3, "PreferredRelayerSet")
.withArgs(user1.address, relayer1.address);
(0, chai_1.expect)(await relayerRewardsPoolV3.getPreferredRelayer(user1.address)).to.equal(relayer1.address);
});
});