From e20a8647384693fe43538b45f8566dcace84222f Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Sat, 28 Jan 2023 14:17:50 -0600 Subject: [PATCH] Move forum test to its own js file --- forum-network/src/tests/forum.html | 81 +-------------------- forum-network/src/tests/forum/forum.test.js | 79 ++++++++++++++++++++ 2 files changed, 80 insertions(+), 80 deletions(-) create mode 100644 forum-network/src/tests/forum/forum.test.js diff --git a/forum-network/src/tests/forum.html b/forum-network/src/tests/forum.html index bc3b16e..511012f 100644 --- a/forum-network/src/tests/forum.html +++ b/forum-network/src/tests/forum.html @@ -6,83 +6,4 @@
- + diff --git a/forum-network/src/tests/forum/forum.test.js b/forum-network/src/tests/forum/forum.test.js new file mode 100644 index 0000000..70acbf3 --- /dev/null +++ b/forum-network/src/tests/forum/forum.test.js @@ -0,0 +1,79 @@ +import { Box } from '../../classes/box.js'; +import { Scene } from '../../classes/scene.js'; +import { Expert } from '../../classes/expert.js'; +import { Bench } from '../../classes/bench.js'; +import { delay } from '../../util.js'; +import { Forum } from '../../classes/forum.js'; +import { PostContent } from '../../classes/post-content.js'; +import params from '../../params.js'; + +const DEFAULT_DELAY_INTERVAL = 500; + +const rootElement = document.getElementById('forum-test'); +const rootBox = new Box('rootBox', rootElement).flex(); + +const scene = (window.scene = new Scene('Forum test', rootBox)); +scene.withSequenceDiagram(); +scene.withFlowchart(); +scene.withTable(); + +scene.addDisplayValue('c3. stakeForAuthor').set(params.stakeForAuthor); +scene.addDisplayValue('q2. revaluationLimit').set(params.revaluationLimit); +scene + .addDisplayValue('q3. referenceChainLimit') + .set(params.referenceChainLimit); +scene.addDisplayValue('q4. leachingValue').set(params.leachingValue); +scene.addDisplayValue(' '); + +const experts = (window.experts = []); +const newExpert = async () => { + const index = experts.length; + const name = `Expert${index + 1}`; + const expert = await new Expert(name, scene).initialize(); + experts.push(expert); + return expert; +}; + +const forum = (window.forum = new Forum('Forum', scene)); +const bench = (window.bench = new Bench(forum, 'Bench', scene)); +const expert1 = await newExpert(); +const expert2 = await newExpert(); +const expert3 = await newExpert(); + +bench.addValue('total rep', () => bench.reputation.getTotal()); +forum.addValue('total value', () => forum.getTotalValue()); + +for (const expert of experts) { + expert.addValue('rep', () => bench.reputation.valueOwnedBy(expert.reputationPublicKey)); +} + +const addPost = async (author, title, fee, citations = []) => { + await scene.startSection(); + + const postContent = new PostContent({}).setTitle(title); + for (const { postId, weight } of citations) { + postContent.addCitation(postId, weight); + } + + const { pool, postId } = await author.submitPostWithFee( + bench, + forum, + postContent, + { + fee, + duration: 1000, + tokenLossRatio: 1, + }, + ); + await delay(1000); + await pool.evaluateWinningConditions(); + await scene.endSection(); + await delay(DEFAULT_DELAY_INTERVAL); + return postId; +}; + +const postId1 = await addPost(expert1, 'Post 1', 20); +const postId2 = await addPost(expert2, 'Post 2', 10, [{ postId: postId1, weight: 0.5 }]); +const postId3 = await addPost(expert3, 'Post 3', 10, [{ postId: postId1, weight: -1 }]); +await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]); +await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]);