UNPKG

@vechain/vebetterdao-contracts

Version:

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

104 lines (103 loc) 5.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chai_1 = require("chai"); const hardhat_1 = require("hardhat"); const helpers_1 = require("../../scripts/helpers"); const libraries_1 = require("../../scripts/libraries"); const STAKE_AMOUNT = hardhat_1.ethers.parseEther("100"); const MIN_BET_AMOUNT = hardhat_1.ethers.parseEther("100"); const INITIAL_BALANCE = hardhat_1.ethers.parseEther("1000"); const APP_1 = hardhat_1.ethers.keccak256(hardhat_1.ethers.toUtf8Bytes("app-1")); const ChallengeKind = { Stake: 0, Sponsored: 1 }; const ChallengeVisibility = { Public: 0, Private: 1 }; const ChallengeType = { MaxActions: 0, SplitWin: 1 }; async function deployV1ThenUpgrade() { const [admin, alice, bob] = await hardhat_1.ethers.getSigners(); const b3tr = (await (await hardhat_1.ethers.getContractFactory("B3TR")).deploy(admin.address, admin.address, admin.address)); await b3tr.waitForDeployment(); const roundGovernor = (await (await hardhat_1.ethers.getContractFactory("MockRoundGovernor")).deploy()); await roundGovernor.waitForDeployment(); const passport = (await (await hardhat_1.ethers.getContractFactory("MockPassportActions")).deploy()); await passport.waitForDeployment(); const x2EarnApps = (await (await hardhat_1.ethers.getContractFactory("MockX2EarnApps")).deploy()); await x2EarnApps.waitForDeployment(); await x2EarnApps.setAppExists(APP_1, true); const ChallengeCoreLogicV1Factory = await hardhat_1.ethers.getContractFactory("ChallengeCoreLogicV1"); const challengeCoreLogicV1 = await ChallengeCoreLogicV1Factory.deploy(); await challengeCoreLogicV1.waitForDeployment(); const ChallengeSettlementLogicV1Factory = await hardhat_1.ethers.getContractFactory("ChallengeSettlementLogicV1", { libraries: { ChallengeCoreLogicV1: await challengeCoreLogicV1.getAddress() }, }); const challengeSettlementLogicV1 = await ChallengeSettlementLogicV1Factory.deploy(); await challengeSettlementLogicV1.waitForDeployment(); const challengesV1 = (await (0, helpers_1.deployProxy)("B3TRChallengesV1", [ { b3trAddress: await b3tr.getAddress(), veBetterPassportAddress: await passport.getAddress(), xAllocationVotingAddress: await roundGovernor.getAddress(), x2EarnAppsAddress: await x2EarnApps.getAddress(), maxChallengeDuration: 4, maxSelectedApps: 5, maxParticipants: 100, minBetAmount: MIN_BET_AMOUNT, }, { admin: admin.address, upgrader: admin.address, contractsAddressManager: admin.address, settingsManager: admin.address, }, ], { ChallengeCoreLogicV1: await challengeCoreLogicV1.getAddress(), ChallengeSettlementLogicV1: await challengeSettlementLogicV1.getAddress(), })); for (const signer of [admin, alice, bob]) { await b3tr.mint(signer.address, INITIAL_BALANCE); await b3tr.connect(signer).approve(await challengesV1.getAddress(), INITIAL_BALANCE); } // Upgrade to V2 with the production libraries. const { ChallengeCoreLogic, ChallengeSettlementLogic } = await (0, libraries_1.challengesLibraries)({ logOutput: false }); const challenges = (await (0, helpers_1.upgradeProxy)("B3TRChallengesV1", "B3TRChallenges", await challengesV1.getAddress(), [], { version: 2, libraries: { ChallengeCoreLogic: await ChallengeCoreLogic.getAddress(), ChallengeSettlementLogic: await ChallengeSettlementLogic.getAddress(), }, })); return { admin, alice, bob, b3tr, roundGovernor, passport, challenges }; } describe("B3TRChallenges - V2 Compatibility - @shard9d", function () { it("V1-era happy path (verified persons) still works end-to-end on V2", async function () { const { admin, alice, bob, b3tr, roundGovernor, passport, challenges } = await deployV1ThenUpgrade(); await roundGovernor.setCurrentRoundId(1); await challenges.createChallenge({ kind: ChallengeKind.Stake, visibility: ChallengeVisibility.Private, challengeType: ChallengeType.MaxActions, stakeAmount: STAKE_AMOUNT, startRound: 2, endRound: 3, threshold: 0, numWinners: 0, appIds: [APP_1], invitees: [alice.address, bob.address], title: "compat", description: "", imageURI: "", metadataURI: "", }); await challenges.connect(alice).joinChallenge(1); await challenges.connect(bob).joinChallenge(1); await passport.setUserRoundActionCountApp(admin.address, 2, APP_1, 1); await passport.setUserRoundActionCountApp(alice.address, 2, APP_1, 10); await passport.setUserRoundActionCountApp(bob.address, 2, APP_1, 7); await roundGovernor.setCurrentRoundId(4); await challenges.completeChallenge(1); const challenge = await challenges.getChallenge(1); (0, chai_1.expect)(challenge.bestScore).to.equal(10n); (0, chai_1.expect)(challenge.bestCount).to.equal(1n); const aliceBalanceBefore = await b3tr.balanceOf(alice.address); await challenges.connect(alice).claimChallengePayout(1); (0, chai_1.expect)(await b3tr.balanceOf(alice.address)).to.equal(aliceBalanceBefore + hardhat_1.ethers.parseEther("300")); }); });