Best JavaScript code snippet using mountebank
simulateDao.js
Source:simulateDao.js
1const a = require('awaiting');2const web3Utils = require('web3-utils');3const MockDgd = artifacts.require('./MockDgd.sol');4const MockBadge = artifacts.require('./MockBadge.sol');5const MockDgxStorage = artifacts.require('./MockDgxStorage.sol');6const MockDgx = artifacts.require('./MockDgx.sol');7const MockDgxDemurrageReporter = artifacts.require('./MockDgxDemurrageReporter.sol');8const ContractResolver = artifacts.require('./ContractResolver.sol');9const DoublyLinkedList = artifacts.require('./DoublyLinkedList.sol');10const DaoIdentityStorage = artifacts.require('./DaoIdentityStorage.sol');11const DaoConfigsStorage = artifacts.require('./MockDaoConfigsStorage.sol');12const DaoStakeStorage = artifacts.require('./DaoStakeStorage.sol');13const DaoPointsStorage = artifacts.require('./DaoPointsStorage.sol');14const DaoStorage = artifacts.require('./DaoStorage.sol');15const DaoUpgradeStorage = artifacts.require('./DaoUpgradeStorage.sol');16const DaoSpecialStorage = artifacts.require('./DaoSpecialStorage.sol');17const DaoRewardsStorage = artifacts.require('./DaoRewardsStorage.sol');18const IntermediateResultsStorage = artifacts.require('./IntermediateResultsStorage.sol');19const DaoListingService = artifacts.require('./DaoListingService.sol');20const DaoCalculatorService = artifacts.require('./DaoCalculatorService.sol');21const DaoIdentity = artifacts.require('./DaoIdentity.sol');22const Dao = artifacts.require('./Dao.sol');23const DaoSpecialProposal = artifacts.require('./DaoSpecialProposal.sol');24const DaoVoting = artifacts.require('./DaoVoting.sol');25const DaoVotingClaims = artifacts.require('./DaoVotingClaims.sol');26const DaoSpecialVotingClaims = artifacts.require('./DaoSpecialVotingClaims.sol');27const DaoStakeLocking = artifacts.require('./DaoStakeLocking.sol');28const DaoFundingManager = artifacts.require('./DaoFundingManager.sol');29const DaoRewardsManager = artifacts.require('./DaoRewardsManager.sol');30/*31 * ---------------------- SIMULATION CONFIGURATION ----------------------------32 *33 * --------------- QUARTER 1 ----------------34 * ------ LOCKING PHASE ------35 * ADDRESS DGD TOKENS DGD BADGE36 * addressOf.badgeHolders[0] 10 * (10 ** 9) 537 * addressOf.badgeHolders[1] 30 * (10 ** 9) 1238 * addressOf.badgeHolders[2] 40 * (10 ** 9) 1539 * addressOf.badgeHolders[3] 20 * (10 ** 9) 1840 * addressOf.dgdHolders[0] 10 * (10 ** 9) 041 * addressOf.dgdHolders[1] 15 * (10 ** 9) 042 * addressOf.dgdHolders[2] 0 * (10 ** 9) 043 * addressOf.dgdHolders[3] 0 * (10 ** 9) 044 * addressOf.dgdHolders[4] 5 * (10 ** 9) 045 * addressOf.dgdHolders[5] 30 * (10 ** 9) 046 *47 * -------- MAIN PHASE -------48 * ADDRESS CONFIG (proposalIds, proposers, ...49 * moreVersions, milestoneDurations, ...50 * milestoneFundings, endorsers)51 * addressOf.proposer1 firstProposal52 * addressOf.proposer2 secondProposal53 * addressOf.proposer3 thirdProposal54 * addressOf.proposer4 fourthProposal55 *56 * -------- DRAFT VOTING --------57 * PROPOSAL ADDRESS DRAFT_VOTES58 * firstProposal addressof.badgeHolders[0] yes59 * firstProposal addressof.badgeHolders[1] yes60 * firstProposal addressof.badgeHolders[2] yes61 * firstProposal addressof.badgeHolders[3] yes62 * ---------------------------63 * secondProposal addressof.badgeHolders[0] no64 * secondProposal addressof.badgeHolders[1] no65 * secondProposal addressof.badgeHolders[2] no66 * secondProposal addressof.badgeHolders[3] no67 * ---------------------------68 * thirdProposal addressof.badgeHolders[0] yes69 * thirdProposal addressof.badgeHolders[1] no70 * thirdProposal addressof.badgeHolders[2] yes71 * thirdProposal addressof.badgeHolders[3] yes72 * ---------------------------73 * fourthProposal addressof.badgeHolders[0] no74 * fourthProposal addressof.badgeHolders[1] yes75 * fourthProposal addressof.badgeHolders[2] yes76 * fourthProposal addressof.badgeHolders[3] yes77 *78 * ----- LOCK MORE DGDs (MAIN PHASE) -----79 * ADDRESS DGD TOKENS80 * addressOf.badgeHolders[0] 10 * (10 ** 9)81 * addressOf.badgeHolders[1] 20 * (10 ** 9)82 * addressOf.badgeHolders[2] 20 * (10 ** 9)83 * addressOf.badgeHolders[3] 55 * (10 ** 9)84 * addressOf.dgdHolders[0] 6 * (10 ** 9)85 * addressOf.dgdHolders[1] 15 * (10 ** 9)86 * addressOf.dgdHolders[2] 10 * (10 ** 9)87 * addressOf.dgdHolders[3] 12 * (10 ** 9)88 * addressOf.dgdHolders[4] 5 * (10 ** 9)89 * addressOf.dgdHolders[5] 10 * (10 ** 9)90 *91 * ------ VOTING ON PROPOSALS ------92 * PROPOSAL ADDRESS DRAFT_VOTES93 * firstProposal addressof.badgeHolders[0] yes94 * firstProposal addressof.badgeHolders[1] yes95 * firstProposal addressof.badgeHolders[2] yes96 * firstProposal addressof.badgeHolders[3] yes97 * firstProposal addressof.dgdHolders[0] yes98 * firstProposal addressof.dgdHolders[1] yes99 * firstProposal addressof.dgdHolders[2] yes100 * firstProposal addressof.dgdHolders[3] yes101 * firstProposal addressof.dgdHolders[4] yes102 * firstProposal addressof.dgdHolders[5] yes103 */104const {105 fundUserAndApproveForStakeLocking,106 lockDGDs,107 getTestProposals,108 getAccountsAndAddressOf,109 assignVotesAndCommits,110 setDummyConfig,111 initialTransferTokens,112 waitForRevealPhase,113 waitForRevealPhaseToGetOver,114 waitFor,115 phaseCorrection,116 initDao,117 addProposal,118 redeemBadges,119 endorseProposal,120 BADGE_HOLDER_COUNT,121 DGD_HOLDER_COUNT,122 modifyProposal,123 printProposalDetails,124} = require('./setup');125const {126 phases,127 quarters,128} = require('./daoHelpers');129const {130 getCurrentTimestamp,131 indexRange,132 randomBytes32,133 randomBytes32s,134} = require('@digix/helpers/lib/helpers');135const bN = web3.toBigNumber;136const dotenv = require('dotenv');137let salts;138let votes;139let votingCommits;140let proposals;141let participants;142const setupMockTokens = async function (contracts, addressOf) {143 dotenv.config();144 contracts.dgdToken = await MockDgd.deployed();145 contracts.badgeToken = await MockBadge.deployed();146 contracts.dgxStorage = await MockDgxStorage.deployed();147 contracts.dgxToken = await MockDgx.deployed();148 await contracts.dgxStorage.setInteractive(contracts.dgxToken.address);149 contracts.demurrageReporter = await MockDgxDemurrageReporter.deployed();150 if (process.env.FIRST_TEST) {151 console.log('transferring initial tokens');152 await initialTransferTokens(contracts, addressOf, bN);153 }154};155const assignDeployedContracts = async function (contracts, libs) {156 contracts.resolver = await ContractResolver.deployed();157 libs.doublyLinkedList = await DoublyLinkedList.deployed();158 contracts.daoIdentityStorage = await DaoIdentityStorage.deployed();159 contracts.daoConfigsStorage = await DaoConfigsStorage.deployed();160 contracts.daoStakeStorage = await DaoStakeStorage.deployed();161 contracts.daoPointsStorage = await DaoPointsStorage.deployed();162 contracts.daoStorage = await DaoStorage.deployed();163 contracts.daoUpgradeStorage = await DaoUpgradeStorage.deployed();164 contracts.daoSpecialStorage = await DaoSpecialStorage.deployed();165 contracts.daoRewardsStorage = await DaoRewardsStorage.deployed();166 contracts.intermediateResultsStorage = await IntermediateResultsStorage.deployed();167 contracts.daoListingService = await DaoListingService.deployed();168 contracts.daoCalculatorService = await DaoCalculatorService.deployed();169 contracts.daoStakeLocking = await DaoStakeLocking.deployed();170 contracts.daoIdentity = await DaoIdentity.deployed();171 contracts.daoFundingManager = await DaoFundingManager.deployed();172 contracts.dao = await Dao.deployed();173 contracts.daoSpecialProposal = await DaoSpecialProposal.deployed();174 contracts.daoVoting = await DaoVoting.deployed();175 contracts.daoVotingClaims = await DaoVotingClaims.deployed();176 contracts.daoSpecialVotingClaims = await DaoSpecialVotingClaims.deployed();177 contracts.daoRewardsManager = await DaoRewardsManager.deployed();178};179const kycProposers = async function (contracts, addressOf) {180 const expiry = getCurrentTimestamp() + 2628000; // KYC valid for 1 month181 await contracts.daoIdentity.updateKyc(proposals[0].proposer, '', expiry, { from: addressOf.kycadmin });182 await contracts.daoIdentity.updateKyc(proposals[1].proposer, '', expiry, { from: addressOf.kycadmin });183 await contracts.daoIdentity.updateKyc(proposals[2].proposer, '', expiry, { from: addressOf.kycadmin });184 await contracts.daoIdentity.updateKyc(proposals[3].proposer, '', expiry, { from: addressOf.kycadmin });185};186const modifyProposals = async function (contracts) {187 await a.map(proposals.slice(0, 3), 20, async (proposal) => {188 await modifyProposal(contracts, proposal, 1);189 });190};191const draftVoting = async function (contracts, addressOf, proposals) {192 await a.map(indexRange(0, 3), 20, async (proposalIndex) => {193 console.log('Draft voting for proposalIndex ', proposalIndex);194 await a.map(indexRange(0, 4), 20, async (badgeHolderIndex) => {195 await contracts.daoVoting.voteOnDraft(196 proposals[proposalIndex].id,197 true,198 { from: addressOf.badgeHolders[badgeHolderIndex] },199 );200 console.log('\t\t Done draft voting by badge holder index ', badgeHolderIndex, ' proposal ', proposalIndex);201 });202 });203 await a.map(indexRange(0, 4), 20, async (badgeHolderIndex) => {204 await contracts.daoVoting.voteOnDraft(205 proposals[3].id,206 true,207 { from: addressOf.badgeHolders[badgeHolderIndex] },208 );209 console.log('\t\t Done draft voting by badge holder index ', badgeHolderIndex, ' proposal ', 3);210 });211};212const claimDraftVotingResult = async function (contracts) {213 // first, third and fourth pass214 // second is reverted (coz its failing)215 // console.log(await contracts.daoVoting)216 const mods = await contracts.daoListingService.listModerators.call(await contracts.daoStakeStorage.readTotalModerators.call(), true);217 console.log(await contracts.daoStorage.readDraftVotingCount.call(proposals[0].id, mods));218 console.log(await contracts.daoStakeStorage.totalModeratorLockedDGDStake.call());219 console.log(await contracts.daoCalculatorService.minimumDraftQuorum.call(proposals[0].id));220 console.log('moderators: ', mods);221 await contracts.daoVotingClaims.claimDraftVotingResult(222 proposals[0].id,223 bN(20),224 { from: proposals[0].proposer },225 );226 await contracts.daoVotingClaims.claimDraftVotingResult(227 proposals[2].id,228 bN(20),229 { from: proposals[2].proposer },230 );231 await contracts.daoVotingClaims.claimDraftVotingResult(232 proposals[3].id,233 bN(20),234 { from: proposals[3].proposer },235 );236};237const votingCommitRound = async function (contracts, addressOf) {238 console.log('now = ', getCurrentTimestamp());239 await a.map(indexRange(0, 4), 20, async (proposalIndex) => {240 if (proposalIndex === 1) return;241 await printProposalDetails(contracts, proposals[proposalIndex]);242 await a.map(indexRange(0, DGD_HOLDER_COUNT + BADGE_HOLDER_COUNT), 20, async (holderIndex) => {243 await contracts.daoVoting.commitVoteOnProposal(244 proposals[proposalIndex].id,245 bN(0),246 votingCommits[proposalIndex][holderIndex],247 { from: addressOf.allParticipants[holderIndex] },248 );249 console.log(`committed vote for holder ${holderIndex} on proposal ${proposalIndex}`);250 });251 });252};253const votingRevealRound = async function (contracts, addressOf, commits) {254 await waitForRevealPhase(contracts, addressOf, proposals[0].id, bN(0), bN, web3);255 await a.map(indexRange(0, 4), 20, async (proposalIndex) => {256 if (proposalIndex === 1) return;257 await a.map(indexRange(0, DGD_HOLDER_COUNT + BADGE_HOLDER_COUNT), 20, async (holderIndex) => {258 await contracts.daoVoting.revealVoteOnProposal(259 proposals[proposalIndex].id,260 bN(0),261 commits.v[proposalIndex][holderIndex],262 commits.s[proposalIndex][holderIndex],263 { from: addressOf.allParticipants[holderIndex] },264 );265 });266 });267};268// const prlApproveProposals = async function (contracts, index, addressOf) {269// await a.map(indexRange(0, 4), 20, async (proposalIndex) => {270// await contracts.dao.updatePRL(271// proposals[proposalIndex].id,272// index,273// true,274// { from: addressOf.prl },275// );276// });277// };278const claimVotingResult = async function (contracts, addressOf) {279 await waitForRevealPhaseToGetOver(contracts, addressOf, proposals[3].id, bN(0), bN, web3);280 await a.map(indexRange(0, 4), 20, async (proposalIndex) => {281 if (proposalIndex === 1) return;282 await contracts.daoVotingClaims.claimProposalVotingResult(283 proposals[proposalIndex].id,284 bN(0),285 bN(30),286 { from: proposals[proposalIndex].proposer },287 );288 });289};290const claimFunding = async function (contracts, index) {291 // const value = index < proposals[0].versions[1].milestoneCount ? proposals[0].versions[1].milestoneFundings[index] : proposals[0].versions[1].finalReward;292 await contracts.daoFundingManager.claimFunding(293 proposals[0].id,294 bN(index),295 { from: proposals[0].proposer },296 );297};298const confirmContinuedParticipation = async function (contracts, addressOf) {299 await a.map(indexRange(0, DGD_HOLDER_COUNT + BADGE_HOLDER_COUNT), 20, async (index) => {300 await contracts.daoStakeLocking.confirmContinuedParticipation({ from: addressOf.allParticipants[index] });301 });302};303const claimDGXs = async function (contracts, addressOf) {304 let total = 0;305 // let totalLockedDGDStake = 0;306 // let totalModeratorLockedDGDStake = 0;307 await a.map(indexRange(0, DGD_HOLDER_COUNT + BADGE_HOLDER_COUNT), 20, async (index) => {308 console.log('Claiming rewards for holder index ', index);309 const claimableDGX = (await contracts.daoRewardsStorage.claimableDGXs.call(addressOf.allParticipants[index])).toNumber();310 // const dgdStake = (await contracts.daoStakeStorage.lockedDGDStake.call(addressOf.allParticipants[index])).toNumber();311 // const isMod = await contracts.dao.isModerator.call(addressOf.allParticipants[index]);312 total += claimableDGX;313 // totalLockedDGDStake += dgdStake;314 // if (isMod) totalModeratorLockedDGDStake += dgdStake;315 console.log('Claimable DGXs = ', claimableDGX);316 // console.log('lockedDGDStake = ', dgdStake);317 await contracts.daoRewardsManager.claimRewards({ from: addressOf.allParticipants[index] });318 });319 console.log('\t\tTotal claimable DGXs = ', total);320 // console.log('totalLockedDGDStake = ', totalLockedDGDStake);321 // console.log('totalModeratorLockedDGDStake = ', totalModeratorLockedDGDStake);322};323const interimVotingCommitRound = async function (contracts, addressOf) {324 // const interimRoundVotingTime4 = await contracts.daoStorage.readProposalVotingTime.call(proposals[3].id, bN(1));325 // const timeNow = getCurrentTimestamp();326 await waitFor(1, addressOf, web3);327 await a.map(indexRange(0, 4), 20, async (proposalIndex) => {328 if (proposalIndex === 1) return;329 console.log('Relative time of start of interim voting time = ', (await contracts.daoStorage.readProposalVotingTime.call(proposals[proposalIndex].id, bN(1))).toNumber() - getCurrentTimestamp());330 await a.map(indexRange(0, DGD_HOLDER_COUNT + BADGE_HOLDER_COUNT), 20, async (holderIndex) => {331 console.log(`\t\tInterim commit Voting by holder index ${holderIndex} on proposal ${proposalIndex}`);332 await contracts.daoVoting.commitVoteOnProposal(333 proposals[proposalIndex].id,334 bN(1),335 votingCommits[proposalIndex][holderIndex],336 { from: addressOf.allParticipants[holderIndex] },337 );338 console.log(`\t\t\tDone interim commit Voting by holder index ${holderIndex} on proposal ${proposalIndex}`);339 });340 });341};342const finishMilestones = async function (contracts) {343 await a.map(indexRange(0, 4), 20, async (proposalIndex) => {344 if (proposalIndex === 1) return;345 await contracts.dao.finishMilestone(proposals[proposalIndex].id, bN(0), { from: proposals[proposalIndex].proposer });346 });347};348const interimVotingRevealRound = async function (contracts, addressOf) {349 await waitForRevealPhase(contracts, addressOf, proposals[0].id, bN(1), bN, web3);350 console.log('Proposal being revealed = ', proposals[0].id);351 await a.map(indexRange(0, DGD_HOLDER_COUNT + BADGE_HOLDER_COUNT), 20, async (holderIndex) => {352 await contracts.daoVoting.revealVoteOnProposal(353 proposals[0].id,354 bN(1),355 votes[0][holderIndex],356 salts[0][holderIndex],357 { from: addressOf.allParticipants[holderIndex] },358 );359 });360};361const interimvotingRoundClaim = async function (contracts) {362 await a.map(indexRange(0, 4), 20, async (proposalIndex) => {363 if (proposalIndex === 1) return;364 console.log('isMainPhase? ', await contracts.daoRewardsManager.isMainPhase.call());365 console.log('interim voting claim for proposal ', proposalIndex, ' id = ', proposals[proposalIndex].id, ' from proposer ', proposals[proposalIndex].proposer);366 await printProposalDetails(contracts, proposals[proposalIndex]);367 await contracts.daoVotingClaims.claimProposalVotingResult(proposals[proposalIndex].id, bN(1), bN(30), { from: proposals[proposalIndex].proposer });368 console.log('Done interim voting claim for proposal ', proposalIndex);369 });370};371const interimCommitRound = async function (contracts, addressOf, proposalIndex, index) {372 await a.map(indexRange(0, DGD_HOLDER_COUNT + BADGE_HOLDER_COUNT), 20, async (holderIndex) => {373 await contracts.daoVoting.commitVoteOnProposal(374 proposals[proposalIndex].id,375 index,376 votingCommits[proposalIndex][holderIndex],377 { from: addressOf.allParticipants[holderIndex] },378 );379 });380};381const interimRevealRound = async function (contracts, addressOf, proposalIndex, index) {382 console.log('Proposal being revealed = ', proposals[proposalIndex].id);383 await a.map(indexRange(0, DGD_HOLDER_COUNT + BADGE_HOLDER_COUNT), 20, async (holderIndex) => {384 await contracts.daoVoting.revealVoteOnProposal(385 proposals[proposalIndex].id,386 index,387 votes[proposalIndex][holderIndex],388 salts[proposalIndex][holderIndex],389 { from: addressOf.allParticipants[holderIndex] },390 );391 });392};393const claimFinalReward = async function (contracts, addressOf, proposalId, proposer, index) {394 console.log(`proposer is ${proposer}, proposalId = ${proposalId}`);395 await contracts.daoFundingManager.claimFunding(396 proposalId,397 bN(index),398 { from: proposer },399 );400};401const specialProposalVoting = async function (contracts, addressOf, specialProposalId) {402 const someSalts = randomBytes32s(10);403 await a.map(indexRange(0, DGD_HOLDER_COUNT + BADGE_HOLDER_COUNT), 20, async (holderIndex) => {404 await contracts.daoVoting.commitVoteOnSpecialProposal(405 specialProposalId,406 web3Utils.soliditySha3({ t: 'address', v: addressOf.allParticipants[holderIndex] }, { t: 'bool', v: true }, { t: 'bytes32', v: someSalts[holderIndex] }),407 { from: addressOf.allParticipants[holderIndex] },408 );409 });410 console.log('committed votes on special proposal');411 await waitFor(11, addressOf, web3); // 10 seconds of commit phase412 await a.map(indexRange(0, DGD_HOLDER_COUNT + BADGE_HOLDER_COUNT), 20, async (holderIndex) => {413 await contracts.daoVoting.revealVoteOnSpecialProposal(414 specialProposalId,415 true,416 someSalts[holderIndex],417 { from: addressOf.allParticipants[holderIndex] },418 );419 });420 console.log('revealed votes on special proposal');421 await waitFor(10, addressOf, web3); // 10 seconds of reveal phase422 await phaseCorrection(web3, contracts, addressOf, phases.MAIN_PHASE);423 console.log('before claiming special proposal');424 await contracts.daoSpecialVotingClaims.claimSpecialProposalVotingResult(specialProposalId, bN(2), { from: addressOf.founderBadgeHolder });425 await contracts.daoSpecialVotingClaims.claimSpecialProposalVotingResult(specialProposalId, bN(100), { from: addressOf.founderBadgeHolder });426 console.log('claimed special proposal');427};428const addAndEndorseProposals = async function (contracts, proposals) {429 await a.map(proposals, 20, async (proposal) => {430 await addProposal(contracts, proposal);431 await endorseProposal(contracts, proposal);432 });433};434const finalizeProposals = async function (contracts, proposals) {435 await a.map(proposals, 20, async (proposal) => {436 await contracts.dao.finalizeProposal(proposal.id, { from: proposal.proposer });437 });438};439module.exports = async function () {440 const addressOf = {};441 const contracts = {};442 const libs = {};443 await web3.eth.getAccounts(async function (e, accounts) {444 // deploy contracts445 getAccountsAndAddressOf(accounts, addressOf);446 console.log('addressOf = ', addressOf);447 participants = [448 {449 address: addressOf.badgeHolders[0],450 redeemingBadge: true,451 dgdToLock: bN(110e9),452 },453 {454 address: addressOf.badgeHolders[1],455 redeemingBadge: true,456 dgdToLock: bN(200e9),457 },458 {459 address: addressOf.badgeHolders[2],460 redeemingBadge: true,461 dgdToLock: bN(200e9),462 },463 {464 address: addressOf.badgeHolders[3],465 redeemingBadge: true,466 dgdToLock: bN(550e9),467 },468 {469 address: addressOf.dgdHolders[0],470 dgdToLock: bN(60e9),471 },472 {473 address: addressOf.dgdHolders[1],474 dgdToLock: bN(150e9),475 },476 {477 address: addressOf.dgdHolders[2],478 dgdToLock: bN(100e9),479 },480 {481 address: addressOf.dgdHolders[3],482 dgdToLock: bN(120e9),483 },484 {485 address: addressOf.dgdHolders[4],486 dgdToLock: bN(50e9),487 },488 {489 address: addressOf.dgdHolders[5],490 dgdToLock: bN(100e9),491 },492 ];493 proposals = getTestProposals(bN, addressOf);494 console.log('got accounts');495 ({ salts, votes, votingCommits } = assignVotesAndCommits(addressOf));496 // get deployed mock tokens497 await setupMockTokens(contracts, addressOf);498 console.log('setup tokens');499 await assignDeployedContracts(contracts, libs);500 console.log('got the deployed contracts');501 // set dummy config for testing502 await setDummyConfig(contracts, bN, 10, 50);503 console.log('setup dummy config');504 // start dao and fund dao505 await initDao(contracts, addressOf, bN, web3);506 console.log('setup and funded dao');507 await fundUserAndApproveForStakeLocking(web3, contracts, bN, participants, addressOf);508 console.log('\tfunded users DGDs and Badges');509 await waitFor(2, addressOf, web3);510 await lockDGDs(web3, contracts, bN, participants, addressOf);511 console.log('\tusers locked DGDs for first quarter');512 await redeemBadges(web3, contracts, bN, participants);513 console.log('\tusers redeemed badges');514 // create some proposals in the main phase, assert that its the same quarter515 await phaseCorrection(web3, contracts, addressOf, phases.MAIN_PHASE, quarters.QUARTER_1);516 await kycProposers(contracts, addressOf);517 console.log('kyc approved proposers');518 await addAndEndorseProposals(contracts, proposals);519 console.log('added and endorsed proposals');520 // modify those proposals slightly, assert that its the same quarter521 await phaseCorrection(web3, contracts, addressOf, phases.MAIN_PHASE, quarters.QUARTER_1);522 await modifyProposals(contracts);523 console.log('modified proposals');524 await finalizeProposals(contracts, proposals);525 console.log('finalized proposals');526 await draftVoting(contracts, addressOf, proposals);527 console.log('done draft voting');528 // its main phase, lock more tokens529 await phaseCorrection(web3, contracts, addressOf, phases.MAIN_PHASE, quarters.QUARTER_1);530 await lockDGDs(web3, contracts, bN, participants, addressOf);531 console.log('locked more dgds in main phase');532 await waitFor(((await contracts.daoStorage.readProposalDraftVotingTime.call(proposals[3].id)).toNumber()533 + 6) - getCurrentTimestamp(), addressOf, web3);534 // claim the voting, assert that its the same quarter535 await phaseCorrection(web3, contracts, addressOf, phases.MAIN_PHASE, quarters.QUARTER_1);536 await claimDraftVotingResult(contracts);537 console.log('claimed draft voting result');538 // PRL approves these proposals539 await phaseCorrection(web3, contracts, addressOf, phases.MAIN_PHASE, quarters.QUARTER_1);540 // await prlApproveProposals(contracts, bN(0), addressOf); // approve first milestone prl541 // console.log('prl approved the proposals');542 // first voting round543 // await phaseCorrection(web3, contracts, addressOf, phases.MAIN_PHASE, quarters.QUARTER_1);544 console.log('before committing votes');545 await votingCommitRound(contracts, addressOf);546 console.log('commit voting has been done');547 await votingRevealRound(contracts, addressOf, { v: votes, s: salts });548 console.log('revealed the committed votes');549 // claim the result of the voting round550 await claimVotingResult(contracts, addressOf);551 console.log('claimed voting result');552 // proposers claim the funding for first milestone553 await claimFunding(contracts, 0);554 console.log('ETH funding has been claimed by the proposer');555 // wait for the quarter to end556 await phaseCorrection(web3, contracts, addressOf, phases.LOCKING_PHASE, quarters.QUARTER_2);557 console.log('in the second quarter (_quarterNumber = 2), locking phase');558 // call the global rewards calculation559 await contracts.dgxToken.mintDgxFor(contracts.daoRewardsManager.address, bN(200 * (10 ** 9)));560 console.log('transferred dgx to rewards manager');561 await contracts.daoRewardsManager.calculateGlobalRewardsBeforeNewQuarter(bN(50), { from: addressOf.founderBadgeHolder });562 console.log('updated the rewards for previous quarter (_quarterNumber = 1)');563 console.log('DGX rewards pool = ', await contracts.daoRewardsStorage.readRewardsPoolOfLastQuarter.call(2));564 console.log('totalEffectiveDGDLastQuarter = ', await contracts.daoRewardsStorage.readTotalEffectiveDGDLastQuarter.call(2));565 console.log('totalEffectiveModeratorDGDLastQuarter = ', await contracts.daoRewardsStorage.readTotalEffectiveModeratorDGDLastQuarter.call(2));566 console.log('\t\t#### Info of users for last quarter: ');567 const printStake = async (user, userString) => {568 console.log(`DGDstake of ${userString} = `, await contracts.daoStakeStorage.lockedDGDStake.call(user));569 console.log(`Badge QP of ${userString}= `, await contracts.daoPointsStorage.getQuarterModeratorPoint.call(user, bN(1)));570 // console.log(`effectiveDGDBalance of ${userString} = `, await contracts.daoRewardsManager.getUserEffectiveDGDBalanceLastQuarter.call(user));571 // console.log(`effective moderator dgd balance of ${userString} = `, await contracts.daoRewardsManager.getUserEffectiveModeratorBalanceLastQuarter.call(user));572 console.log();573 };574 await printStake(addressOf.badgeHolders[0], 'addressOf.badgeHolders[0]');575 await printStake(addressOf.badgeHolders[1], 'addressOf.badgeHolders[1]');576 await printStake(addressOf.badgeHolders[2], 'addressOf.badgeHolders[2]');577 await printStake(addressOf.badgeHolders[3], 'addressOf.badgeHolders[3]');578 // confirm participation for the next quarter579 console.log('Before confirming participation of all members');580 await confirmContinuedParticipation(contracts, addressOf);581 console.log('confirmed participation of all members');582 const printPoints = async (user, userString) => {583 console.log(`Claimable DGX of ${userString} = `, await contracts.daoRewardsStorage.claimableDGXs.call(user));584 console.log(`QP of ${userString}= `, await contracts.daoPointsStorage.getQuarterPoint.call(user, bN(1)));585 console.log(`Badge QP of ${userString}= `, await contracts.daoPointsStorage.getQuarterModeratorPoint.call(user, bN(1)));586 console.log(`RP of ${userString}= `, await contracts.daoPointsStorage.getReputation.call(user));587 console.log();588 };589 await printPoints(addressOf.badgeHolders[0], 'addressOf.badgeHolders[0]');590 await printPoints(addressOf.badgeHolders[1], 'addressOf.badgeHolders[1]');591 await printPoints(addressOf.badgeHolders[2], 'addressOf.badgeHolders[2]');592 await printPoints(addressOf.badgeHolders[3], 'addressOf.badgeHolders[3]');593 await claimDGXs(contracts, addressOf);594 console.log('claimed all dgxs');595 await phaseCorrection(web3, contracts, addressOf, phases.MAIN_PHASE, quarters.QUARTER_2, web3);596 console.log('in the second quarter (_quarterNumber = 2), main phase');597 // create some fake proposals to draft vote on598 await finishMilestones(contracts);599 await interimVotingCommitRound(contracts, addressOf);600 console.log('done with interim voting commit round');601 await interimVotingRevealRound(contracts, addressOf);602 console.log('done with interim voting reveal round');603 await waitForRevealPhaseToGetOver(contracts, addressOf, proposals[3].id, bN(1), bN, web3);604 console.log('done waitForRevealPhaseToGetOver');605 await interimvotingRoundClaim(contracts);606 console.log('done with claiming interim round voting');607 // prlApproveProposals(contracts, bN(1), addressOf); // approve second milestone funding608 await claimFunding(contracts, 1);609 console.log('claimed funding after interim voting phase');610 await phaseCorrection(web3, contracts, addressOf, phases.LOCKING_PHASE, quarters.QUARTER_3, web3);611 console.log('in the third quarter (_quarterNumber = 3), locking phase');612 await contracts.dgxToken.mintDgxFor(contracts.daoRewardsManager.address, bN(25 * (10 ** 9)));613 console.log('transferred dgx to rewards manager');614 await contracts.daoRewardsManager.calculateGlobalRewardsBeforeNewQuarter(bN(50), { from: addressOf.founderBadgeHolder });615 console.log('updated the rewards for previous quarter (_quarterNumber = 2)');616 await confirmContinuedParticipation(contracts, addressOf);617 console.log('confirmed participation of all members');618 await phaseCorrection(web3, contracts, addressOf, phases.MAIN_PHASE, quarters.QUARTER_3, web3);619 console.log('in the main phase, now going for interim voting after last milestone');620 await contracts.dao.finishMilestone(proposals[0].id, bN(1), { from: proposals[0].proposer });621 await interimCommitRound(contracts, addressOf, 0, bN(2));622 console.log('interim commit round is done');623 await waitForRevealPhase(contracts, addressOf, proposals[0].id, bN(2), bN, web3);624 await interimRevealRound(contracts, addressOf, 0, bN(2));625 console.log('interim reveal is done');626 await waitForRevealPhaseToGetOver(contracts, addressOf, proposals[0].id, bN(2), bN, web3);627 console.log('daoFunding balance = ', await web3.eth.getBalance(contracts.daoFundingManager.address));628 await contracts.daoVotingClaims.claimProposalVotingResult(proposals[0].id, bN(2), bN(30), { from: proposals[0].proposer });629 console.log('claimed final voting round');630 console.log('before claimFinalReward');631 await printProposalDetails(contracts, proposals[0]);632 // await contracts.dao.updatePRL(proposals[0].id, bN(2), true, { from: addressOf.prl });633 console.log('claiming final rewards...');634 await claimFinalReward(contracts, addressOf, proposals[0].id, proposals[0].proposer, 2);635 console.log('claimed final rewards');636 // special proposal section637 const uintConfigs = await contracts.daoConfigsStorage.readUintConfigs.call();638 console.log('-------------------------------------------------------------');639 console.log('configs are : ', uintConfigs);640 console.log('qp for milestone : ', uintConfigs[24]);641 console.log('rep point per extra qp : ', uintConfigs[25]);642 console.log('minimal badge participation : ', uintConfigs[40]);643 console.log('-------------------------------------------------------------');644 const specialProposalId = randomBytes32();645 // set quarter point for milestone completion to be 5 (previously 3)646 // set reputation per extra quarter point to be 3 (previously 5)647 // set minimal badge participation to be 2 (previously 3)648 uintConfigs[24] = bN(5);649 uintConfigs[25] = bN(3);650 uintConfigs[40] = bN(2);651 await contracts.daoSpecialProposal.createSpecialProposal(652 specialProposalId,653 uintConfigs,654 [],655 [],656 { from: addressOf.founderBadgeHolder },657 );658 console.log('created special proposal');659 // vote on special proposal everybody660 await contracts.daoSpecialProposal.startSpecialProposalVoting(specialProposalId, { from: addressOf.founderBadgeHolder });661 await waitFor(2, addressOf, web3); // wait for a couple of seconds662 await specialProposalVoting(contracts, addressOf, specialProposalId);663 const uintConfigs2 = await contracts.daoConfigsStorage.readUintConfigs.call();664 console.log('-------------------------------------------------------------');665 console.log('configs are (now) : ', uintConfigs2);666 console.log('qp for milestone (now) : ', uintConfigs[24]);667 console.log('rep point per extra qp (now) : ', uintConfigs[25]);668 console.log('minimal badge participation (now) : ', uintConfigs[40]);669 console.log('-------------------------------------------------------------');670 // end special proposal section671 });...
DaoStakeStorage.js
Source:DaoStakeStorage.js
1const a = require('awaiting');2const {3 deployLibraries,4 deployNewContractResolver,5 getAccountsAndAddressOf,6 deployStorage,7 registerInteractive,8} = require('../setup');9const {10 EMPTY_ADDRESS,11} = require('../daoHelpers');12const {13 randomAddress,14 randomBigNumber,15} = require('@digix/helpers/lib/helpers');16const bN = web3.toBigNumber;17contract('DaoStakeStorage', function (accounts) {18 let libs;19 let addressOf;20 let contracts;21 before(async function () {22 contracts = {};23 libs = {};24 addressOf = {};25 await deployLibraries(libs);26 await deployNewContractResolver(contracts);27 await getAccountsAndAddressOf(accounts, addressOf);28 await deployStorage(libs, contracts, contracts.resolver, addressOf);29 await registerInteractive(contracts.resolver, addressOf);30 });31 describe('Initialization', function () {32 it('[contract key]', async function () {33 assert.deepEqual(await contracts.resolver.get_contract.call('storage:dao:stake'), contracts.daoStakeStorage.address);34 });35 });36 describe('updateTotalLockedDGDStake', function () {37 const totalLockedDGD = randomBigNumber(bN);38 it('[not called from CONTRACT_DAO_STAKE_LOCKING]: revert', async function () {39 assert(await a.failure(contracts.daoStakeStorage.updateTotalLockedDGDStake.call(40 totalLockedDGD,41 { from: accounts[2] },42 )));43 });44 it('[valid call]: verify read functions', async function () {45 await contracts.daoStakeStorage.updateTotalLockedDGDStake(totalLockedDGD);46 assert.deepEqual(await contracts.daoStakeStorage.totalLockedDGDStake.call(), totalLockedDGD);47 const newTotalLockedDGD = randomBigNumber(bN);48 await contracts.daoStakeStorage.updateTotalLockedDGDStake(newTotalLockedDGD);49 assert.deepEqual(await contracts.daoStakeStorage.totalLockedDGDStake.call(), newTotalLockedDGD);50 });51 });52 describe('updateUserDGDStake', function () {53 const randomUser = randomAddress();54 const actualLockedDGD = randomBigNumber(bN);55 const lockedDGDStake = randomBigNumber(bN);56 it('[not called from CONTRACT_DAO_STAKE_LOCKING]: revert', async function () {57 assert(await a.failure(contracts.daoStakeStorage.updateUserDGDStake.call(58 randomUser,59 actualLockedDGD,60 lockedDGDStake,61 { from: accounts[2] },62 )));63 });64 it('[valid call]: verify read functions', async function () {65 await contracts.daoStakeStorage.updateUserDGDStake(randomUser, actualLockedDGD, lockedDGDStake);66 const readRes = await contracts.daoStakeStorage.readUserDGDStake.call(randomUser);67 assert.deepEqual(readRes[0], actualLockedDGD);68 assert.deepEqual(readRes[1], lockedDGDStake);69 });70 });71 describe('addToParticipantList', function () {72 it('[not called from CONTRACT_DAO_STAKE_LOCKING]: revert', async function () {73 assert(await a.failure(contracts.daoStakeStorage.addToParticipantList.call(74 addressOf.dgdHolders[0],75 { from: accounts[2] },76 )));77 });78 it('[valid call]: verify read functions', async function () {79 assert.deepEqual(await contracts.daoStakeStorage.isInParticipantList.call(addressOf.dgdHolders[0]), false);80 assert.deepEqual(await contracts.daoStakeStorage.addToParticipantList.call(addressOf.dgdHolders[0]), true);81 await contracts.daoStakeStorage.addToParticipantList(addressOf.dgdHolders[0]);82 assert.deepEqual(await contracts.daoStakeStorage.isInParticipantList.call(addressOf.dgdHolders[0]), true);83 });84 });85 describe('removeFromParticipantList', function () {86 it('[not called from CONTRACT_DAO_STAKE_LOCKING]: revert', async function () {87 assert(await a.failure(contracts.daoStakeStorage.removeFromParticipantList.call(88 addressOf.dgdHolders[0],89 { from: accounts[2] },90 )));91 });92 it('[valid call]: verify read functions', async function () {93 assert.deepEqual(await contracts.daoStakeStorage.removeFromParticipantList.call(addressOf.dgdHolders[0]), true);94 await contracts.daoStakeStorage.removeFromParticipantList(addressOf.dgdHolders[0]);95 assert.deepEqual(await contracts.daoStakeStorage.isInParticipantList.call(addressOf.dgdHolders[0]), false);96 });97 });98 describe('Read Functions', function () {99 before(async function () {100 await contracts.daoStakeStorage.addToParticipantList(addressOf.dgdHolders[1]);101 await contracts.daoStakeStorage.addToParticipantList(addressOf.dgdHolders[2]);102 await contracts.daoStakeStorage.addToParticipantList(addressOf.dgdHolders[3]);103 await contracts.daoStakeStorage.addToParticipantList(addressOf.dgdHolders[4]);104 await contracts.daoStakeStorage.addToParticipantList(addressOf.dgdHolders[5]);105 });106 it('[readFirstParticipant]', async function () {107 assert.deepEqual(await contracts.daoStakeStorage.readFirstParticipant.call(), addressOf.dgdHolders[1]);108 await contracts.daoStakeStorage.removeFromParticipantList(addressOf.dgdHolders[1]);109 assert.deepEqual(await contracts.daoStakeStorage.readFirstParticipant.call(), addressOf.dgdHolders[2]);110 });111 it('[readLastParticipant]', async function () {112 assert.deepEqual(await contracts.daoStakeStorage.readLastParticipant.call(), addressOf.dgdHolders[5]);113 await contracts.daoStakeStorage.addToParticipantList(addressOf.dgdHolders[1]);114 assert.deepEqual(await contracts.daoStakeStorage.readLastParticipant.call(), addressOf.dgdHolders[1]);115 });116 it('[readNextParticipant]', async function () {117 assert.deepEqual(await contracts.daoStakeStorage.readNextParticipant.call(addressOf.dgdHolders[2]), addressOf.dgdHolders[3]);118 assert.deepEqual(await contracts.daoStakeStorage.readNextParticipant.call(addressOf.dgdHolders[3]), addressOf.dgdHolders[4]);119 assert.deepEqual(await contracts.daoStakeStorage.readNextParticipant.call(addressOf.dgdHolders[4]), addressOf.dgdHolders[5]);120 assert.deepEqual(await contracts.daoStakeStorage.readNextParticipant.call(addressOf.dgdHolders[5]), addressOf.dgdHolders[1]);121 assert.deepEqual(await contracts.daoStakeStorage.readNextParticipant.call(addressOf.dgdHolders[1]), EMPTY_ADDRESS);122 await contracts.daoStakeStorage.removeFromParticipantList(addressOf.dgdHolders[4]);123 assert.deepEqual(await contracts.daoStakeStorage.readNextParticipant.call(addressOf.dgdHolders[3]), addressOf.dgdHolders[5]);124 await contracts.daoStakeStorage.addToParticipantList(addressOf.dgdHolders[4]);125 assert.deepEqual(await contracts.daoStakeStorage.readNextParticipant.call(addressOf.dgdHolders[1]), addressOf.dgdHolders[4]);126 assert.deepEqual(await contracts.daoStakeStorage.readNextParticipant.call(addressOf.dgdHolders[4]), EMPTY_ADDRESS);127 });128 it('[readPreviousParticipant]', async function () {129 assert.deepEqual(await contracts.daoStakeStorage.readPreviousParticipant.call(addressOf.dgdHolders[4]), addressOf.dgdHolders[1]);130 assert.deepEqual(await contracts.daoStakeStorage.readPreviousParticipant.call(addressOf.dgdHolders[1]), addressOf.dgdHolders[5]);131 assert.deepEqual(await contracts.daoStakeStorage.readPreviousParticipant.call(addressOf.dgdHolders[5]), addressOf.dgdHolders[3]);132 assert.deepEqual(await contracts.daoStakeStorage.readPreviousParticipant.call(addressOf.dgdHolders[3]), addressOf.dgdHolders[2]);133 assert.deepEqual(await contracts.daoStakeStorage.readPreviousParticipant.call(addressOf.dgdHolders[2]), EMPTY_ADDRESS);134 await contracts.daoStakeStorage.removeFromParticipantList(addressOf.dgdHolders[3]);135 assert.deepEqual(await contracts.daoStakeStorage.readPreviousParticipant.call(addressOf.dgdHolders[5]), addressOf.dgdHolders[2]);136 await contracts.daoStakeStorage.addToParticipantList(addressOf.dgdHolders[3]);137 assert.deepEqual(await contracts.daoStakeStorage.readPreviousParticipant.call(addressOf.dgdHolders[3]), addressOf.dgdHolders[4]);138 });139 it('[readTotalParticipant]', async function () {140 assert.deepEqual(await contracts.daoStakeStorage.readTotalParticipant.call(), bN(5));141 await contracts.daoStakeStorage.removeFromParticipantList(addressOf.dgdHolders[4]);142 await contracts.daoStakeStorage.removeFromParticipantList(addressOf.dgdHolders[1]);143 assert.deepEqual(await contracts.daoStakeStorage.readTotalParticipant.call(), bN(3));144 await contracts.daoStakeStorage.addToParticipantList(addressOf.dgdHolders[1]);145 assert.deepEqual(await contracts.daoStakeStorage.readTotalParticipant.call(), bN(4));146 });147 });...
StakeLocking.js
Source:StakeLocking.js
1const {2 deployFreshDao,3 readDummyConfig,4 initQuarter,5 initialTransferTokens,6 getStartOfFirstQuarterFor,7 setStartOfFirstQuarterTo,8} = require('./../setup');9const {10 phases,11} = require('./../daoHelpers');12const {13 getCurrentTimestamp,14} = require('@digix/helpers/lib/helpers');15const bN = web3.toBigNumber;16contract('DaoStakeLocking', function (accounts) {17 let dummyConfig;18 const libs = {};19 const contracts = {};20 const addressOf = {};21 before(async function () {22 await deployFreshDao(libs, contracts, addressOf, accounts, bN, web3);23 await initialTransferTokens(contracts, addressOf, bN);24 dummyConfig = await readDummyConfig(contracts);25 });26 describe('lockDGD', function () {27 it('[lockDGD in Q1 | DGD < CONFIG_MINIMUM_LOCKED_DGD]: success | not a participant', async function () {28 const amount = bN(1 * (10 ** 8));29 // approve tokens to be used by contract30 await contracts.dgdToken.approve(contracts.daoStakeLocking.address, amount, { from: addressOf.dgdHolders[0] });31 // addressOf.dgdHolders[0] locks DGDs32 assert.ok(await contracts.daoStakeLocking.lockDGD.call(amount, { from: addressOf.dgdHolders[0] }));33 await contracts.daoStakeLocking.lockDGD(amount, { from: addressOf.dgdHolders[0] });34 // verify states35 assert.deepEqual(await contracts.daoRewardsStorage.lastParticipatedQuarter.call(addressOf.dgdHolders[0]), bN(0));36 assert.deepEqual(await contracts.daoStakeLocking.isParticipant.call(addressOf.dgdHolders[0]), false);37 assert.deepEqual(await contracts.daoStakeStorage.lockedDGDStake.call(addressOf.dgdHolders[0]), amount);38 assert.deepEqual(await contracts.daoStakeStorage.actualLockedDGD.call(addressOf.dgdHolders[0]), amount);39 assert.deepEqual(await contracts.daoRewardsStorage.lastQuarterThatRewardsWasUpdated.call(addressOf.dgdHolders[0]), bN(0));40 assert.deepEqual(await contracts.daoRewardsStorage.lastQuarterThatReputationWasUpdated.call(addressOf.dgdHolders[0]), bN(0));41 });42 it('[lockDGD in Q1 | DGD = CONFIG_MINIMUM_LOCKED_DGD]: success | is a participant', async function () {43 const amount = bN(1 * (10 ** 9));44 // approve tokens to be used by contract45 await contracts.dgdToken.approve(contracts.daoStakeLocking.address, amount, { from: addressOf.dgdHolders[1] });46 // addressOf.dgdHolders[1] locks DGDs47 assert.ok(await contracts.daoStakeLocking.lockDGD.call(amount, { from: addressOf.dgdHolders[1] }));48 await contracts.daoStakeLocking.lockDGD(amount, { from: addressOf.dgdHolders[1] });49 // verify states50 assert.deepEqual(await contracts.daoRewardsStorage.lastParticipatedQuarter.call(addressOf.dgdHolders[1]), bN(1));51 assert.deepEqual(await contracts.daoStakeLocking.isParticipant.call(addressOf.dgdHolders[1]), true);52 assert.deepEqual(await contracts.daoStakeStorage.lockedDGDStake.call(addressOf.dgdHolders[1]), amount);53 assert.deepEqual(await contracts.daoStakeStorage.actualLockedDGD.call(addressOf.dgdHolders[1]), amount);54 assert.deepEqual(await contracts.daoRewardsStorage.lastQuarterThatRewardsWasUpdated.call(addressOf.dgdHolders[1]), bN(0));55 assert.deepEqual(await contracts.daoRewardsStorage.lastQuarterThatReputationWasUpdated.call(addressOf.dgdHolders[1]), bN(0));56 });57 it('[lockDGD in Q2 | DGD >= CONFIG_MINIMUM_LOCKED_DGD]: success | is a participant', async function () {58 // teleport to Q2 locking phase59 const _startOfFirstQuarter = getStartOfFirstQuarterFor(bN(2), phases.LOCKING_PHASE, dummyConfig[0], dummyConfig[1], bN(getCurrentTimestamp()), bN);60 await setStartOfFirstQuarterTo(contracts, addressOf, _startOfFirstQuarter);61 await initQuarter(contracts, bN(2), bN(getCurrentTimestamp()));62 const amount = bN(2 * (10 ** 9));63 // approve tokens to be used by contract64 await contracts.dgdToken.approve(contracts.daoStakeLocking.address, amount, { from: addressOf.dgdHolders[2] });65 // addressOf.dgdHolders[2] locks DGDs66 assert.ok(await contracts.daoStakeLocking.lockDGD.call(amount, { from: addressOf.dgdHolders[2] }));67 await contracts.daoStakeLocking.lockDGD(amount, { from: addressOf.dgdHolders[2] });68 // verify states69 assert.deepEqual(await contracts.daoRewardsStorage.lastParticipatedQuarter.call(addressOf.dgdHolders[2]), bN(2));70 assert.deepEqual(await contracts.daoStakeLocking.isParticipant.call(addressOf.dgdHolders[2]), true);71 assert.deepEqual(await contracts.daoStakeStorage.lockedDGDStake.call(addressOf.dgdHolders[2]), amount);72 assert.deepEqual(await contracts.daoStakeStorage.actualLockedDGD.call(addressOf.dgdHolders[2]), amount);73 // assert.deepEqual(await contracts.daoRewardsStorage.lastQuarterThatRewardsWasUpdated.call(addressOf.dgdHolders[2]), bN(1));74 assert.deepEqual(await contracts.daoRewardsStorage.lastQuarterThatReputationWasUpdated.call(addressOf.dgdHolders[2]), bN(1));75 });76 it('[lockDGD in Q2 | withdraw in Q2 | lock in Q3]', async function () {77 // this user has participated in carbon voting 178 await contracts.carbonVoting1.mock_set_voted(addressOf.dgdHolders[3]);79 const amount = bN(1 * (10 ** 9));80 await contracts.dgdToken.approve(contracts.daoStakeLocking.address, amount.times(bN(2)), { from: addressOf.dgdHolders[3] });81 // even after locking and withdrawing, the user already has received their reputation bonus for carbon voting82 const repInitial = await contracts.daoPointsStorage.getReputation.call(addressOf.dgdHolders[3]);83 await contracts.daoStakeLocking.lockDGD(amount, { from: addressOf.dgdHolders[3] });84 const repAfterLock = await contracts.daoPointsStorage.getReputation.call(addressOf.dgdHolders[3]);85 assert.deepEqual(await contracts.daoRewardsStorage.lastParticipatedQuarter.call(addressOf.dgdHolders[3]), bN(2));86 assert.deepEqual(await contracts.daoRewardsStorage.lastQuarterThatRewardsWasUpdated.call(addressOf.dgdHolders[3]), bN(0));87 assert.deepEqual(await contracts.daoRewardsStorage.lastQuarterThatReputationWasUpdated.call(addressOf.dgdHolders[3]), bN(1));88 assert.deepEqual(await contracts.daoStakeLocking.isParticipant.call(addressOf.dgdHolders[3]), true);89 await contracts.daoStakeLocking.withdrawDGD(amount, { from: addressOf.dgdHolders[3] });90 const repAfterWithdraw = await contracts.daoPointsStorage.getReputation.call(addressOf.dgdHolders[3]);91 assert.deepEqual(await contracts.daoRewardsStorage.lastParticipatedQuarter.call(addressOf.dgdHolders[3]), bN(0));92 assert.deepEqual(await contracts.daoRewardsStorage.lastQuarterThatRewardsWasUpdated.call(addressOf.dgdHolders[3]), bN(0));93 assert.deepEqual(await contracts.daoRewardsStorage.lastQuarterThatReputationWasUpdated.call(addressOf.dgdHolders[3]), bN(1));94 assert.deepEqual(await contracts.daoStakeLocking.isParticipant.call(addressOf.dgdHolders[3]), false);95 // teleport to Q4 locking phase96 const _startOfFirstQuarter = getStartOfFirstQuarterFor(bN(3), phases.LOCKING_PHASE, dummyConfig[0], dummyConfig[1], bN(getCurrentTimestamp()), bN);97 await setStartOfFirstQuarterTo(contracts, addressOf, _startOfFirstQuarter);98 await initQuarter(contracts, bN(3), bN(getCurrentTimestamp()));99 await contracts.daoStakeLocking.lockDGD(amount, { from: addressOf.dgdHolders[3] });100 const repAfterLockAgain = await contracts.daoPointsStorage.getReputation.call(addressOf.dgdHolders[3]);101 // reputation verifying102 assert.deepEqual(repAfterLock, repInitial.plus(bN(35)));103 assert.deepEqual(repAfterWithdraw, repAfterLock);104 // fine for (not locking + max deduction) in Q2105 assert.deepEqual(repAfterLockAgain, repAfterWithdraw.minus(bN(25)));106 });107 });...
Using AI Code Generation
1var mb = require('mountebank');2var imposter = {3 {4 {5 is: {6 }7 }8 }9};10mb.create(imposter).then(function (result) {11 console.log(result.address);12});13var mb = require('mountebank');14var imposter = {15 {16 {17 is: {18 }19 }20 }21};22mb.create(imposter).then(function (result) {23 console.log(mb.addressOf(result));24});
Using AI Code Generation
1var request = require('request');2var options = {3 json: {4 {5 {6 equals: {7 }8 }9 {10 is: {11 }12 }13 }14 }15};16request(options, function (error, response, body) {17 if (!error && response.statusCode == 201) {18 console.log(body);19 var address = body.address;20 console.log(address);21 }22});23var request = require('request');24var options = {25};
Using AI Code Generation
1var mb = require('mountebank');2var imposter = {3 {4 {5 is: {6 }7 }8 }9};10mb.create(imposter).then(function (result) {11});
Using AI Code Generation
1var mb = require('mountebank'),2 {3 {4 is: {5 }6 }7 }8 imposters = [{9 }],10 mbOptions = {11 };12mb.create(mbOptions, imposters).then(function (imposter) {13 console.log('Imposter created at %s:%s', protocol, imposter.port);14 console.log('Address of the imposter is %s', imposter.addressOf(protocol));15}).catch(function (error) {16 console.error('Error creating imposter: %s', error.message);17});
Using AI Code Generation
1const mb = require('mountebank');2const port = 2525;3const protocol = 'http';4const host = 'localhost';5const path = require('path');6const fs = require('fs');7const imposter = JSON.parse(fs.readFileSync(path.join(__dirname, 'imposter.json'), 'utf8'));8const mbPromise = mb.create(port, { allowInjection: true, debug: true });9mbPromise.then(() => {10 mb.post(url, imposter, () => {11 console.log('Imposter created');12 mb.get(`${url}/imposters`, (error, response) => {13 const imposters = JSON.parse(response.body);14 console.log('Imposters are: ', imposters);15 imposters.forEach(imposter => {16 const address = mb.addressOf(imposter.port, imposter.protocol);17 console.log(`Address of imposter ${imposter.port} is ${address}`);18 });19 });20 });21});
Using AI Code Generation
1var mb = require('mountebank');2mb.create({ port: 2525, pidfile: 'mb.pid', logfile: 'mb.log' }).then(function (imposter) {3 console.log('Imposter created on port ' + imposter.port);4 console.log('Imposter pid ' + imposter.pid);5 console.log('Imposter address ' + imposter.address);6 console.log('Imposter protocol ' + imposter.protocol);7 imposter.stop().then(function () {8 console.log('Imposter stopped');9 });10});
Using AI Code Generation
1var mb = require('mountebank');2var fs = require('fs');3var request = require('request');4var assert = require('assert');5var port = 2525;6var host = 'localhost';7var protocol = 'http';8var imposterPort = 4545;9var imposterProtocol = 'http';10var imposterHost = 'localhost';11var imposter = {12 {13 {14 "is": {15 "headers": {16 },17 }18 }19 }20};21var imposter2 = {22 {23 {24 "is": {25 "headers": {26 },27 }28 }29 }30};31mb.create(imposter, port, host, function (error, response) {32 if (error) {33 console.log(error);34 } else {35 console.log(response.statusCode);36 mb.del(response.body.port, port, host, function (error, response) {37 if (error) {38 console.log(error);39 } else {40 console.log(response.statusCode);41 mb.create(imposter2, port, host, function (error, response) {42 if (error) {43 console.log(error);44 } else {45 console.log(response.statusCode);46 mb.del(response.body.port, port, host, function (error, response) {47 if (error) {48 console.log(error);49 } else {50 console.log(response.statusCode);51 }52 });53 }54 });55 }56 });57 }58});59mb.create(imposter, port, host, function (error, response) {60 if (error) {61 console.log(error);62 } else {63 console.log(response.statusCode);64 mb.del(response.body
Using AI Code Generation
1var mb = require('mountebank');2mb.start({port: 2525, pidfile: 'mb.pid', logfile: 'mb.log', ipWhitelist: ['*']}, function () {3 mb.create({port: 4545, protocol: 'http', stubs: [{responses: [{is: {body: 'Hello World'}}]}]}, function () {4 mb.addressOf({port: 4545}, function (error, address) {5 console.log('Imposter running at ' + address);6 mb.stop();7 });8 });9});
Using AI Code Generation
1var mb = require('mountebank');2var request = require('request');3var Q = require('q');4var deferred = Q.defer();5mb.start({}, function (error, imposter) {6 var address = imposter.addressOf(2525);7 console.log(address);8 request.get(address + '/test', function (error, response, body) {9 console.log(body);10 deferred.resolve();11 });12});13module.exports = deferred.promise;
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!