From 77ae33ce5acfeb07158a6fdee8bb1b3d592c78f4 Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Mon, 13 Feb 2023 10:24:24 -0600 Subject: [PATCH 1/3] more reorganizing --- forum-network/notes/classes.md | 43 ----------------- forum-network/notes/governance.md | 1 + forum-network/src/classes/actors/expert.js | 4 +- forum-network/src/classes/actors/post.js | 46 ------------------ .../classes/{actors => dao}/availability.js | 0 .../src/classes/{actors => dao}/business.js | 0 .../src/classes/{actors => dao}/dao.js | 7 +-- .../src/classes/{actors => dao}/forum.js | 47 ++++++++++++++++++- .../{actors => dao}/validation-pool.js | 2 +- forum-network/src/classes/display/table.js | 4 ++ .../src/classes/forum-network/forum-node.js | 2 +- forum-network/src/classes/ideas/exchange.js | 45 ++++++++++++++++++ forum-network/src/classes/ideas/finance.js | 12 ++--- forum-network/src/classes/ideas/storage.js | 24 ++++++++++ .../reputation-holder.js | 0 .../reputation-token.js | 2 +- .../{contracts => supporting}/erc20.js | 0 .../{contracts => supporting}/erc721.js | 0 forum-network/src/tests/business.test.html | 8 +++- .../src/tests/forum-network.test.html | 8 +++- forum-network/src/tests/reputation.test.html | 4 +- .../src/tests/scripts/availability.test.js | 2 +- .../tests/scripts/forum/forum.test-util.js | 2 +- .../src/tests/scripts/validation-pool.test.js | 2 +- 24 files changed, 146 insertions(+), 119 deletions(-) delete mode 100644 forum-network/notes/classes.md create mode 100644 forum-network/notes/governance.md delete mode 100644 forum-network/src/classes/actors/post.js rename forum-network/src/classes/{actors => dao}/availability.js (100%) rename forum-network/src/classes/{actors => dao}/business.js (100%) rename forum-network/src/classes/{actors => dao}/dao.js (90%) rename forum-network/src/classes/{actors => dao}/forum.js (79%) rename forum-network/src/classes/{actors => dao}/validation-pool.js (99%) rename forum-network/src/classes/{actors => reputation}/reputation-holder.js (100%) rename forum-network/src/classes/{contracts => reputation}/reputation-token.js (98%) rename forum-network/src/classes/{contracts => supporting}/erc20.js (100%) rename forum-network/src/classes/{contracts => supporting}/erc721.js (100%) diff --git a/forum-network/notes/classes.md b/forum-network/notes/classes.md deleted file mode 100644 index 36cb19d..0000000 --- a/forum-network/notes/classes.md +++ /dev/null @@ -1,43 +0,0 @@ -# Primary - -## Forum - -## ValidationPool - -## ReputationToken - -## WDAG - -# Secondary - -## Availability - -## Business - -## ERC721 - -## Expert - -## Bench - -# Tertiary - -## Actor - -## Action - -## Scene - -# To Explore - -## Exchange - -## Storage - -## Network - -## Wallet - -## Agent/UI - -## BlockConsensus diff --git a/forum-network/notes/governance.md b/forum-network/notes/governance.md new file mode 100644 index 0000000..74dd787 --- /dev/null +++ b/forum-network/notes/governance.md @@ -0,0 +1 @@ +Each DAO needs to allocate some of its incoming fees to incentivize development. diff --git a/forum-network/src/classes/actors/expert.js b/forum-network/src/classes/actors/expert.js index b8ecda0..69a1d7c 100644 --- a/forum-network/src/classes/actors/expert.js +++ b/forum-network/src/classes/actors/expert.js @@ -1,7 +1,7 @@ import { Action } from '../display/action.js'; import { PostMessage } from '../forum-network/message.js'; import { CryptoUtil } from '../util/crypto.js'; -import { ReputationHolder } from './reputation-holder.js'; +import { ReputationHolder } from '../reputation/reputation-holder.js'; export class Expert extends ReputationHolder { constructor(dao, name, scene) { @@ -47,7 +47,7 @@ export class Expert extends ReputationHolder { } async initiateValidationPool(poolOptions) { - // For now, directly call bench.initiateValidationPool(); + // For now, make direct call rather than network poolOptions.reputationPublicKey = this.reputationPublicKey; const pool = await this.dao.initiateValidationPool(poolOptions); this.tokens.push(pool.tokenId); diff --git a/forum-network/src/classes/actors/post.js b/forum-network/src/classes/actors/post.js deleted file mode 100644 index a214c6d..0000000 --- a/forum-network/src/classes/actors/post.js +++ /dev/null @@ -1,46 +0,0 @@ -import { Actor } from '../display/actor.js'; -import { displayNumber } from '../../util.js'; -import params from '../../params.js'; - -export class Post extends Actor { - constructor(forum, authorPublicKey, postContent) { - const index = forum.posts.countVertices(); - const name = `Post${index + 1}`; - super(name, forum.scene); - this.id = postContent.id ?? name; - this.authorPublicKey = authorPublicKey; - this.value = 0; - this.initialValue = 0; - this.citations = postContent.citations; - this.title = postContent.title; - const leachingTotal = this.citations - .filter(({ weight }) => weight < 0) - .reduce((total, { weight }) => total += -weight, 0); - const donationTotal = this.citations - .filter(({ weight }) => weight > 0) - .reduce((total, { weight }) => total += weight, 0); - if (leachingTotal > params.revaluationLimit) { - throw new Error('Post leaching total exceeds revaluation limit ' - + `(${leachingTotal} > ${params.revaluationLimit})`); - } - if (donationTotal > params.revaluationLimit) { - throw new Error('Post donation total exceeds revaluation limit ' - + `(${donationTotal} > ${params.revaluationLimit})`); - } - if (this.citations.some(({ weight }) => Math.abs(weight) > params.revaluationLimit)) { - throw new Error(`Each citation magnitude must not exceed revaluation limit ${params.revaluationLimit}`); - } - } - - getLabel() { - return `${this.name} - - - - - - -
initial${displayNumber(this.initialValue)}
value${displayNumber(this.value)}
` - .replaceAll(/\n\s*/g, ''); - } -} diff --git a/forum-network/src/classes/actors/availability.js b/forum-network/src/classes/dao/availability.js similarity index 100% rename from forum-network/src/classes/actors/availability.js rename to forum-network/src/classes/dao/availability.js diff --git a/forum-network/src/classes/actors/business.js b/forum-network/src/classes/dao/business.js similarity index 100% rename from forum-network/src/classes/actors/business.js rename to forum-network/src/classes/dao/business.js diff --git a/forum-network/src/classes/actors/dao.js b/forum-network/src/classes/dao/dao.js similarity index 90% rename from forum-network/src/classes/actors/dao.js rename to forum-network/src/classes/dao/dao.js index ee6f6a3..938d019 100644 --- a/forum-network/src/classes/actors/dao.js +++ b/forum-network/src/classes/dao/dao.js @@ -1,6 +1,6 @@ import params from '../../params.js'; import { Forum } from './forum.js'; -import { ReputationTokenContract } from '../contracts/reputation-token.js'; +import { ReputationTokenContract } from '../reputation/reputation-token.js'; import { ValidationPool } from './validation-pool.js'; import { Availability } from './availability.js'; import { Business } from './business.js'; @@ -72,9 +72,4 @@ export class DAO extends Actor { return pool; } - - async submitPost(reputationPublicKey, postContent) { - const post = await this.forum.addPost(reputationPublicKey, postContent); - return post.id; - } } diff --git a/forum-network/src/classes/actors/forum.js b/forum-network/src/classes/dao/forum.js similarity index 79% rename from forum-network/src/classes/actors/forum.js rename to forum-network/src/classes/dao/forum.js index 41ae511..6a6db0f 100644 --- a/forum-network/src/classes/actors/forum.js +++ b/forum-network/src/classes/dao/forum.js @@ -1,13 +1,56 @@ import { WDAG } from '../supporting/wdag.js'; import { Action } from '../display/action.js'; +import { Actor } from '../display/actor.js'; import params from '../../params.js'; -import { ReputationHolder } from './reputation-holder.js'; +import { ReputationHolder } from '../reputation/reputation-holder.js'; import { displayNumber, EPSILON } from '../../util.js'; -import { Post } from './post.js'; const CITATION = 'citation'; const BALANCE = 'balance'; +class Post extends Actor { + constructor(forum, authorPublicKey, postContent) { + const index = forum.posts.countVertices(); + const name = `Post${index + 1}`; + super(name, forum.scene); + this.id = postContent.id ?? name; + this.authorPublicKey = authorPublicKey; + this.value = 0; + this.initialValue = 0; + this.citations = postContent.citations; + this.title = postContent.title; + const leachingTotal = this.citations + .filter(({ weight }) => weight < 0) + .reduce((total, { weight }) => total += -weight, 0); + const donationTotal = this.citations + .filter(({ weight }) => weight > 0) + .reduce((total, { weight }) => total += weight, 0); + if (leachingTotal > params.revaluationLimit) { + throw new Error('Post leaching total exceeds revaluation limit ' + + `(${leachingTotal} > ${params.revaluationLimit})`); + } + if (donationTotal > params.revaluationLimit) { + throw new Error('Post donation total exceeds revaluation limit ' + + `(${donationTotal} > ${params.revaluationLimit})`); + } + if (this.citations.some(({ weight }) => Math.abs(weight) > params.revaluationLimit)) { + throw new Error(`Each citation magnitude must not exceed revaluation limit ${params.revaluationLimit}`); + } + } + + getLabel() { + return `${this.name} + + + + + + +
initial${displayNumber(this.initialValue)}
value${displayNumber(this.value)}
` + .replaceAll(/\n\s*/g, ''); + } +} + /** * Purpose: * - Forum: Maintain a directed, acyclic, graph of positively and negatively weighted citations. diff --git a/forum-network/src/classes/actors/validation-pool.js b/forum-network/src/classes/dao/validation-pool.js similarity index 99% rename from forum-network/src/classes/actors/validation-pool.js rename to forum-network/src/classes/dao/validation-pool.js index 5accbf6..4781608 100644 --- a/forum-network/src/classes/actors/validation-pool.js +++ b/forum-network/src/classes/dao/validation-pool.js @@ -1,4 +1,4 @@ -import { ReputationHolder } from './reputation-holder.js'; +import { ReputationHolder } from '../reputation/reputation-holder.js'; import { Stake } from '../supporting/stake.js'; import { Voter } from '../supporting/voter.js'; import params from '../../params.js'; diff --git a/forum-network/src/classes/display/table.js b/forum-network/src/classes/display/table.js index 10dbd0b..ee579d4 100644 --- a/forum-network/src/classes/display/table.js +++ b/forum-network/src/classes/display/table.js @@ -42,4 +42,8 @@ export class Table { cell.innerHTML = typeof value === 'number' ? displayNumber(value) : value ?? ''; } } + + listUniqueValueKeys() { + return this.columns; // TODO + } } diff --git a/forum-network/src/classes/forum-network/forum-node.js b/forum-network/src/classes/forum-network/forum-node.js index f36032e..49ae7c5 100644 --- a/forum-network/src/classes/forum-network/forum-node.js +++ b/forum-network/src/classes/forum-network/forum-node.js @@ -4,7 +4,7 @@ import { } from './message.js'; import { ForumView } from './forum-view.js'; import { NetworkNode } from './network-node.js'; -import { randomID } from '../../util.js'; +import { randomID } from '../util/util.js'; export class ForumNode extends NetworkNode { constructor(name, scene) { diff --git a/forum-network/src/classes/ideas/exchange.js b/forum-network/src/classes/ideas/exchange.js index e69de29..2c1021f 100644 --- a/forum-network/src/classes/ideas/exchange.js +++ b/forum-network/src/classes/ideas/exchange.js @@ -0,0 +1,45 @@ +import { DAO } from '../actors/dao.js'; +/** + * An Exchange provides conversion between currencies / facilitates such. + * That means they carry some of the risk of managing these transactions. + * + */ + +class Offer { + constructor({ + _fromType, _toType, _amount, price, + }) { + this.price = price; + // const from = + } +} + +export class Exchange extends DAO { + constructor(name, scene) { + super(name, scene); + this.offersByType = new Map(); // > + } + + getOffers(offerType) { + return this.buyOffersByType.get(offerType) ?? new Map(); // < + } + + addOffer(offerOptions) { + const offer = new Offer(offerOptions); + const { fromType, toType } = offer; + [fromType, toType].forEach((type) => { + this.offersByType.s(); + }); + } + + requestTransaction({ + fromType, toType, amount, price, + }) { + // this. + } + + buy(fromType, toType, _priceParameters) { + const buyOffer = { + }; + } +} diff --git a/forum-network/src/classes/ideas/finance.js b/forum-network/src/classes/ideas/finance.js index 0ca5f53..07e7531 100644 --- a/forum-network/src/classes/ideas/finance.js +++ b/forum-network/src/classes/ideas/finance.js @@ -1,10 +1,6 @@ -export class Token { - constructor(ownerPublicKey) { - this.ownerPublicKey = ownerPublicKey; - } +/** + * Finance does the work of analysis of the dynamics of reputation and currency exchange + */ - transfer(newOwnerPublicKey) { - // TODO: Current owner must sign this request - this.ownerPublicKey = newOwnerPublicKey; - } +export class Finance { } diff --git a/forum-network/src/classes/ideas/storage.js b/forum-network/src/classes/ideas/storage.js index e69de29..e317264 100644 --- a/forum-network/src/classes/ideas/storage.js +++ b/forum-network/src/classes/ideas/storage.js @@ -0,0 +1,24 @@ +import { randomID } from '../util/util.js'; + +class Pledge { + constructor({ stake, duration }) { + this.stake = stake; + this.duration = duration; + } +} + +/** + * Storage work is providing data availability and integrity. + * It probably makes sense to manage it in pledges of finite duration. + */ +export class Storage { + constructor() { + this.pledges = new Map(); + } + + pledge(pledgeOptions) { + const id = randomID(); + this.pledge.set(id, new Pledge(pledgeOptions)); + return id; + } +} diff --git a/forum-network/src/classes/actors/reputation-holder.js b/forum-network/src/classes/reputation/reputation-holder.js similarity index 100% rename from forum-network/src/classes/actors/reputation-holder.js rename to forum-network/src/classes/reputation/reputation-holder.js diff --git a/forum-network/src/classes/contracts/reputation-token.js b/forum-network/src/classes/reputation/reputation-token.js similarity index 98% rename from forum-network/src/classes/contracts/reputation-token.js rename to forum-network/src/classes/reputation/reputation-token.js index c39af4d..c4fec73 100644 --- a/forum-network/src/classes/contracts/reputation-token.js +++ b/forum-network/src/classes/reputation/reputation-token.js @@ -1,4 +1,4 @@ -import { ERC721 } from './erc721.js'; +import { ERC721 } from '../supporting/erc721.js'; import { EPSILON, randomID } from '../../util.js'; diff --git a/forum-network/src/classes/contracts/erc20.js b/forum-network/src/classes/supporting/erc20.js similarity index 100% rename from forum-network/src/classes/contracts/erc20.js rename to forum-network/src/classes/supporting/erc20.js diff --git a/forum-network/src/classes/contracts/erc721.js b/forum-network/src/classes/supporting/erc721.js similarity index 100% rename from forum-network/src/classes/contracts/erc721.js rename to forum-network/src/classes/supporting/erc721.js diff --git a/forum-network/src/tests/business.test.html b/forum-network/src/tests/business.test.html index 03644c7..9a117eb 100644 --- a/forum-network/src/tests/business.test.html +++ b/forum-network/src/tests/business.test.html @@ -15,8 +15,12 @@ - - + + - - + + @@ -32,12 +35,6 @@ - diff --git a/forum-network/src/tests/availability.test.html b/forum-network/src/tests/availability.test.html index a6bdbaf..3efa0df 100644 --- a/forum-network/src/tests/availability.test.html +++ b/forum-network/src/tests/availability.test.html @@ -26,12 +26,6 @@ - diff --git a/forum-network/src/tests/business.test.html b/forum-network/src/tests/business.test.html index 9a117eb..fe8bb01 100644 --- a/forum-network/src/tests/business.test.html +++ b/forum-network/src/tests/business.test.html @@ -25,12 +25,6 @@ - diff --git a/forum-network/src/tests/debounce.test.html b/forum-network/src/tests/debounce.test.html index 219c100..b45f7eb 100644 --- a/forum-network/src/tests/debounce.test.html +++ b/forum-network/src/tests/debounce.test.html @@ -25,12 +25,6 @@ - diff --git a/forum-network/src/tests/forum-network.test.html b/forum-network/src/tests/forum-network.test.html index ce233ab..488950b 100644 --- a/forum-network/src/tests/forum-network.test.html +++ b/forum-network/src/tests/forum-network.test.html @@ -26,12 +26,6 @@ - diff --git a/forum-network/src/tests/forum1.test.html b/forum-network/src/tests/forum1.test.html index 7af331d..4e338af 100644 --- a/forum-network/src/tests/forum1.test.html +++ b/forum-network/src/tests/forum1.test.html @@ -21,12 +21,6 @@ - diff --git a/forum-network/src/tests/forum2.test.html b/forum-network/src/tests/forum2.test.html index ff4d512..29af18a 100644 --- a/forum-network/src/tests/forum2.test.html +++ b/forum-network/src/tests/forum2.test.html @@ -21,12 +21,6 @@ - diff --git a/forum-network/src/tests/forum3.test.html b/forum-network/src/tests/forum3.test.html index 97a8df0..d9e41ed 100644 --- a/forum-network/src/tests/forum3.test.html +++ b/forum-network/src/tests/forum3.test.html @@ -21,12 +21,6 @@ - diff --git a/forum-network/src/tests/forum4.test.html b/forum-network/src/tests/forum4.test.html index 2b451d1..262977e 100644 --- a/forum-network/src/tests/forum4.test.html +++ b/forum-network/src/tests/forum4.test.html @@ -21,12 +21,6 @@ - diff --git a/forum-network/src/tests/forum5.test.html b/forum-network/src/tests/forum5.test.html index 142e468..f99f35e 100644 --- a/forum-network/src/tests/forum5.test.html +++ b/forum-network/src/tests/forum5.test.html @@ -21,12 +21,6 @@ - diff --git a/forum-network/src/tests/mocha.test.html b/forum-network/src/tests/mocha.test.html index 54287d7..174b492 100644 --- a/forum-network/src/tests/mocha.test.html +++ b/forum-network/src/tests/mocha.test.html @@ -20,7 +20,6 @@ mocha.setup({ ui: 'bdd', }); - mocha.checkLeaks(); chai.should(); diff --git a/forum-network/src/tests/scripts/availability.test.js b/forum-network/src/tests/scripts/availability.test.js index 5824672..556da23 100644 --- a/forum-network/src/tests/scripts/availability.test.js +++ b/forum-network/src/tests/scripts/availability.test.js @@ -1,10 +1,11 @@ import { Box } from '../../classes/display/box.js'; import { Scene } from '../../classes/display/scene.js'; import { Expert } from '../../classes/actors/expert.js'; -import { delay } from '../../util.js'; import { DAO } from '../../classes/dao/dao.js'; import { Public } from '../../classes/actors/public.js'; import { PostContent } from '../../classes/util/post-content.js'; +import { delayOrWait } from '../../classes/display/controls.js'; +import { mochaRun } from '../../util.js'; const DELAY_INTERVAL = 100; const POOL_DURATION = 200; @@ -43,7 +44,7 @@ const setup = async () => { await newExpert(); requestor = new Public('Public', scene); - await delay(DELAY_INTERVAL); + await delayOrWait(DELAY_INTERVAL); // Experts gain initial reputation by submitting a post with fee const { postId: postId1, pool: pool1 } = await experts[0].submitPostWithFee( @@ -54,10 +55,10 @@ const setup = async () => { tokenLossRatio: 1, }, ); - await delay(POOL_DURATION); + await delayOrWait(POOL_DURATION); await pool1.evaluateWinningConditions(); - await delay(DELAY_INTERVAL); + await delayOrWait(DELAY_INTERVAL); dao.reputation.valueOwnedBy(experts[0].reputationPublicKey).should.equal(10); @@ -71,10 +72,10 @@ const setup = async () => { tokenLossRatio: 1, }, ); - await delay(POOL_DURATION); + await delayOrWait(POOL_DURATION); await pool2.evaluateWinningConditions(); - await delay(DELAY_INTERVAL); + await delayOrWait(DELAY_INTERVAL); dao.reputation.valueOwnedBy(experts[0].reputationPublicKey).should.equal(15); dao.reputation.valueOwnedBy(experts[1].reputationPublicKey).should.equal(5); @@ -106,7 +107,9 @@ const voteForWorkEvidence = async (worker, pool) => { } }; -describe('Availability + Business', () => { +describe('Availability + Business', function tests() { + this.timeout(0); + before(async () => { await setup(); }); @@ -122,7 +125,7 @@ describe('Availability + Business', () => { it('Experts can register their availability for some duration', async () => { await experts[0].registerAvailability(1, 10000); await experts[1].registerAvailability(1, 10000); - await delay(DELAY_INTERVAL); + await delayOrWait(DELAY_INTERVAL); }); it('Public can submit a work request', async () => { @@ -131,7 +134,7 @@ describe('Availability + Business', () => { { fee: 100 }, { please: 'do some work' }, ); - await delay(DELAY_INTERVAL); + await delayOrWait(DELAY_INTERVAL); }); it('Expert can submit work evidence', async () => { @@ -153,11 +156,11 @@ describe('Availability + Business', () => { await voteForWorkEvidence(worker, pool3); // Wait for validation pool duration to elapse - await delay(POOL_DURATION); + await delayOrWait(POOL_DURATION); // Distribute reputation awards and fees await pool3.evaluateWinningConditions(); - await delay(DELAY_INTERVAL); + await delayOrWait(DELAY_INTERVAL); // This should throw an exception since the pool is already resolved try { @@ -167,3 +170,5 @@ describe('Availability + Business', () => { } }).timeout(10000); }); + +mochaRun(); diff --git a/forum-network/src/tests/scripts/business.test.js b/forum-network/src/tests/scripts/business.test.js index ce87e31..dd3a524 100644 --- a/forum-network/src/tests/scripts/business.test.js +++ b/forum-network/src/tests/scripts/business.test.js @@ -1,8 +1,10 @@ -import { Business } from '../../classes/actors/business.js'; +import { Business } from '../../classes/dao/business.js'; import { Scene } from '../../classes/display/scene.js'; import { Box } from '../../classes/display/box.js'; +import { mochaRun } from '../../util.js'; -describe('Business', () => { +describe('Business', function tests() { + this.timeout(0); let scene; before(async () => { const rootElement = document.getElementById('scene'); @@ -14,3 +16,5 @@ describe('Business', () => { should.exist(business); }); }); + +mochaRun(); diff --git a/forum-network/src/tests/scripts/debounce.test.js b/forum-network/src/tests/scripts/debounce.test.js index 286d310..b0de18e 100644 --- a/forum-network/src/tests/scripts/debounce.test.js +++ b/forum-network/src/tests/scripts/debounce.test.js @@ -2,7 +2,7 @@ import { Box } from '../../classes/display/box.js'; import { Scene } from '../../classes/display/scene.js'; import { Action } from '../../classes/display/action.js'; import { Actor } from '../../classes/display/actor.js'; -import { debounce, delay } from '../../util.js'; +import { debounce, delay, mochaRun } from '../../util.js'; describe('Debounce', () => { let scene; @@ -70,3 +70,5 @@ describe('Debounce', () => { await scene.sequence.endSection(); }); }); + +mochaRun(); diff --git a/forum-network/src/tests/scripts/forum-network.test.js b/forum-network/src/tests/scripts/forum-network.test.js index d1737c8..5cbe692 100644 --- a/forum-network/src/tests/scripts/forum-network.test.js +++ b/forum-network/src/tests/scripts/forum-network.test.js @@ -4,9 +4,12 @@ import { PostContent } from '../../classes/util/post-content.js'; import { Expert } from '../../classes/actors/expert.js'; import { ForumNode } from '../../classes/forum-network/forum-node.js'; import { Network } from '../../classes/forum-network/network.js'; -import { delay, randomID } from '../../util.js'; +import { mochaRun, randomID } from '../../util.js'; +import { delayOrWait } from '../../classes/display/controls.js'; + +describe('Forum Network', function tests() { + this.timeout(0); -describe('Forum Network', () => { let scene; let author1; let author2; @@ -58,19 +61,21 @@ describe('Forum Network', () => { 1.0, ); - await delay(1000); + await delayOrWait(1000); await author1.submitPostViaNetwork( forumNode1, post1, 50, ); - await delay(1000); + await delayOrWait(1000); await author2.submitPostViaNetwork( forumNode2, post2, 100, ); - await delay(1000); + await delayOrWait(1000); }).timeout(10000); }); + +mochaRun(); diff --git a/forum-network/src/tests/scripts/forum/forum.test-util.js b/forum-network/src/tests/scripts/forum/forum.test-util.js index 0ce352a..fea2e8a 100644 --- a/forum-network/src/tests/scripts/forum/forum.test-util.js +++ b/forum-network/src/tests/scripts/forum/forum.test-util.js @@ -2,9 +2,9 @@ import { Box } from '../../../classes/display/box.js'; import { Scene } from '../../../classes/display/scene.js'; import { Expert } from '../../../classes/actors/expert.js'; import { PostContent } from '../../../classes/util/post-content.js'; -import { delay } from '../../../util.js'; import params from '../../../params.js'; import { DAO } from '../../../classes/dao/dao.js'; +import { delayOrWait } from '../../../classes/display/controls.js'; export class ForumTest { constructor(options) { @@ -38,10 +38,10 @@ export class ForumTest { }, ); this.posts.push(postId); - await delay(this.options.poolDurationMs); + await delayOrWait(this.options.poolDurationMs); await pool.evaluateWinningConditions(); await this.scene.sequence.endSection(); - await delay(this.options.defaultDelayMs); + await delayOrWait(this.options.defaultDelayMs); return postId; } diff --git a/forum-network/src/tests/scripts/forum/forum1.test.js b/forum-network/src/tests/scripts/forum/forum1.test.js index 77d52a4..2800972 100644 --- a/forum-network/src/tests/scripts/forum/forum1.test.js +++ b/forum-network/src/tests/scripts/forum/forum1.test.js @@ -1,6 +1,9 @@ +import { mochaRun } from '../../../util.js'; import { ForumTest } from './forum.test-util.js'; -describe('Forum', () => { +describe('Forum', function tests() { + this.timeout(0); + const forumTest = new ForumTest(); before(async () => { @@ -37,3 +40,5 @@ describe('Forum', () => { // await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]); // await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]); + +mochaRun(); diff --git a/forum-network/src/tests/scripts/forum/forum2.test.js b/forum-network/src/tests/scripts/forum/forum2.test.js index b4737a3..6c76676 100644 --- a/forum-network/src/tests/scripts/forum/forum2.test.js +++ b/forum-network/src/tests/scripts/forum/forum2.test.js @@ -1,6 +1,9 @@ +import { mochaRun } from '../../../util.js'; import { ForumTest } from './forum.test-util.js'; -describe('Forum', () => { +describe('Forum', function tests() { + this.timeout(0); + const forumTest = new ForumTest(); before(async () => { @@ -37,3 +40,5 @@ describe('Forum', () => { // await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]); // await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]); + +mochaRun(); diff --git a/forum-network/src/tests/scripts/forum/forum3.test.js b/forum-network/src/tests/scripts/forum/forum3.test.js index e5d5038..ce849ed 100644 --- a/forum-network/src/tests/scripts/forum/forum3.test.js +++ b/forum-network/src/tests/scripts/forum/forum3.test.js @@ -1,6 +1,9 @@ +import { mochaRun } from '../../../util.js'; import { ForumTest } from './forum.test-util.js'; -describe('Forum', () => { +describe('Forum', function tests() { + this.timeout(0); + const forumTest = new ForumTest(); before(async () => { @@ -40,3 +43,5 @@ describe('Forum', () => { // await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]); // await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]); + +mochaRun(); diff --git a/forum-network/src/tests/scripts/forum/forum4.test.js b/forum-network/src/tests/scripts/forum/forum4.test.js index c4c3c55..2349110 100644 --- a/forum-network/src/tests/scripts/forum/forum4.test.js +++ b/forum-network/src/tests/scripts/forum/forum4.test.js @@ -1,6 +1,9 @@ +import { mochaRun } from '../../../util.js'; import { ForumTest } from './forum.test-util.js'; -describe('Forum', () => { +describe('Forum', function tests() { + this.timeout(0); + const forumTest = new ForumTest(); before(async () => { @@ -68,3 +71,5 @@ describe('Forum', () => { // await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]); // await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]); + +mochaRun(); diff --git a/forum-network/src/tests/scripts/forum/forum5.test.js b/forum-network/src/tests/scripts/forum/forum5.test.js index 2274d57..52e819b 100644 --- a/forum-network/src/tests/scripts/forum/forum5.test.js +++ b/forum-network/src/tests/scripts/forum/forum5.test.js @@ -1,6 +1,9 @@ +import { mochaRun } from '../../../util.js'; import { ForumTest } from './forum.test-util.js'; -describe('Forum', () => { +describe('Forum', function tests() { + this.timeout(0); + const forumTest = new ForumTest(); before(async () => { @@ -57,3 +60,5 @@ describe('Forum', () => { // await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]); // await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]); + +mochaRun(); diff --git a/forum-network/src/tests/scripts/validation-pool.test.js b/forum-network/src/tests/scripts/validation-pool.test.js index 865fca0..3d1e8c4 100644 --- a/forum-network/src/tests/scripts/validation-pool.test.js +++ b/forum-network/src/tests/scripts/validation-pool.test.js @@ -2,8 +2,9 @@ import { Box } from '../../classes/display/box.js'; import { Scene } from '../../classes/display/scene.js'; import { Expert } from '../../classes/actors/expert.js'; import { PostContent } from '../../classes/util/post-content.js'; -import { delay } from '../../util.js'; import { DAO } from '../../classes/dao/dao.js'; +import { delayOrWait } from '../../classes/display/controls.js'; +import { mochaRun } from '../../util.js'; const POOL_DURATION_MS = 100; const DEFAULT_DELAY_MS = 100; @@ -35,10 +36,11 @@ async function setup() { await newExpert(); await newExpert(); - await delay(DEFAULT_DELAY_MS); + await delayOrWait(DEFAULT_DELAY_MS); } -describe('Validation Pool', () => { +describe('Validation Pool', function tests() { + this.timeout(0); before(async () => { await setup(); }); @@ -73,9 +75,9 @@ describe('Validation Pool', () => { } } await scene.sequence.endSection(); - await delay(POOL_DURATION_MS); + await delayOrWait(POOL_DURATION_MS); await pool.evaluateWinningConditions(); // Vote passes - await delay(DEFAULT_DELAY_MS); + await delayOrWait(DEFAULT_DELAY_MS); }); it('Failure example: second expert can not self-approve', async () => { @@ -85,9 +87,9 @@ describe('Validation Pool', () => { duration: POOL_DURATION_MS, tokenLossRatio: 1, }); - await delay(POOL_DURATION_MS); + await delayOrWait(POOL_DURATION_MS); await pool.evaluateWinningConditions(); // Quorum not met! - await delay(DEFAULT_DELAY_MS); + await delayOrWait(DEFAULT_DELAY_MS); } catch (e) { e.message.should.match(/Quorum is not met/); } @@ -104,8 +106,10 @@ describe('Validation Pool', () => { amount: 4, lockingTime: 0, }); - await delay(POOL_DURATION_MS); + await delayOrWait(POOL_DURATION_MS); await pool.evaluateWinningConditions(); // Stake passes - await delay(DEFAULT_DELAY_MS); + await delayOrWait(DEFAULT_DELAY_MS); }); }); + +mochaRun(); diff --git a/forum-network/src/tests/scripts/vm.test.js b/forum-network/src/tests/scripts/vm.test.js index 93baac5..ffd1967 100644 --- a/forum-network/src/tests/scripts/vm.test.js +++ b/forum-network/src/tests/scripts/vm.test.js @@ -2,6 +2,7 @@ import { Actor } from '../../classes/display/actor.js'; import { Box } from '../../classes/display/box.js'; import { Scene } from '../../classes/display/scene.js'; import { VM } from '../../classes/supporting/vm.js'; +import { mochaRun } from '../../util.js'; const contractIds = ['contract-id-1', 'contract-id-2']; @@ -29,7 +30,9 @@ class Repeater extends Actor { } } -describe('VM', () => { +describe('VM', function tests() { + this.timeout(0); + let vm; let sender; let vmHandle; @@ -68,3 +71,5 @@ describe('VM', () => { .should.equal('Repeater world: good day'); }); }); + +mochaRun(); diff --git a/forum-network/src/tests/scripts/wdag.test.js b/forum-network/src/tests/scripts/wdag.test.js index 35f453b..4fd1243 100644 --- a/forum-network/src/tests/scripts/wdag.test.js +++ b/forum-network/src/tests/scripts/wdag.test.js @@ -1,12 +1,15 @@ import { Box } from '../../classes/display/box.js'; import { Scene } from '../../classes/display/scene.js'; import { WDAG } from '../../classes/supporting/wdag.js'; +import { mochaRun } from '../../util.js'; const rootElement = document.getElementById('scene'); const rootBox = new Box('rootBox', rootElement).flex(); window.scene = new Scene('WDAG test', rootBox); -describe('Query the graph', () => { +describe('Query the graph', function tests() { + this.timeout(0); + let graph; before(() => { @@ -43,3 +46,5 @@ describe('Query the graph', () => { ]); }); }); + +mochaRun(); diff --git a/forum-network/src/tests/validation-pool.test.html b/forum-network/src/tests/validation-pool.test.html index 7afaac2..4dbe0f1 100644 --- a/forum-network/src/tests/validation-pool.test.html +++ b/forum-network/src/tests/validation-pool.test.html @@ -25,12 +25,6 @@ - diff --git a/forum-network/src/tests/vm.test.html b/forum-network/src/tests/vm.test.html index 8aeff12..f78597e 100644 --- a/forum-network/src/tests/vm.test.html +++ b/forum-network/src/tests/vm.test.html @@ -21,12 +21,6 @@ - diff --git a/forum-network/src/tests/wdag.test.html b/forum-network/src/tests/wdag.test.html index 44190be..49eece4 100644 --- a/forum-network/src/tests/wdag.test.html +++ b/forum-network/src/tests/wdag.test.html @@ -21,13 +21,7 @@ - diff --git a/forum-network/src/util.js b/forum-network/src/util.js index b8a4ac8..2505b93 100644 --- a/forum-network/src/util.js +++ b/forum-network/src/util.js @@ -38,3 +38,9 @@ export const displayNumber = (value, decimals = 2) => (value.toString().length > : value); export const randomID = () => CryptoUtil.randomUUID().replaceAll('-', '').slice(0, 8); + +export const mochaRun = () => { + if (mocha._state !== 'running') { + mocha.run(); + } +};