Move forum test to its own js file
This commit is contained in:
parent
1668ceeda3
commit
e20a864738
|
@ -6,83 +6,4 @@
|
||||||
<body>
|
<body>
|
||||||
<div id="forum-test"></div>
|
<div id="forum-test"></div>
|
||||||
</body>
|
</body>
|
||||||
<script type="module">
|
<script type="module" src="./forum/forum.test.js"></script>
|
||||||
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 }]);
|
|
||||||
await addPost(expert3, 'Post 3', 10, [{ postId: postId1, weight: -1 }]);
|
|
||||||
await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]);
|
|
||||||
</script>
|
|
||||||
|
|
|
@ -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 }]);
|
Loading…
Reference in New Issue