Add additional forum test case

This commit is contained in:
Ladd Hoffman 2023-02-01 22:13:25 -06:00
parent 3541802d93
commit be71d4f3cd
4 changed files with 89 additions and 2 deletions

View File

@ -39,12 +39,12 @@ export class Expert extends ReputationHolder {
async submitPost(postContent) { async submitPost(postContent) {
// TODO: Include fee // TODO: Include fee
await this.actions.submitPost.log(this, this.dao.forum); await this.actions.submitPost.log(this, this.dao);
return this.dao.forum.addPost(this.reputationPublicKey, postContent); return this.dao.forum.addPost(this.reputationPublicKey, postContent);
} }
async submitPostWithFee(postContent, poolOptions) { async submitPostWithFee(postContent, poolOptions) {
await this.actions.submitPost.log(this, this.dao.forum); await this.actions.submitPost.log(this, this.dao);
const postId = await this.dao.forum.addPost(this.reputationPublicKey, postContent); const postId = await this.dao.forum.addPost(this.reputationPublicKey, postContent);
const pool = await this.initiateValidationPool({ ...poolOptions, postId }); const pool = await this.initiateValidationPool({ ...poolOptions, postId });
this.tokens.push(pool.tokenId); this.tokens.push(pool.tokenId);

View File

@ -16,6 +16,7 @@
<li><a href="./tests/forum2.test.html">Negative citation of a weaker negative citation</a></li> <li><a href="./tests/forum2.test.html">Negative citation of a weaker negative citation</a></li>
<li><a href="./tests/forum3.test.html">Redistribute power</a></li> <li><a href="./tests/forum3.test.html">Redistribute power</a></li>
<li><a href="./tests/forum4.test.html">Redistribute power through subsequent support</a></li> <li><a href="./tests/forum4.test.html">Redistribute power through subsequent support</a></li>
<li><a href="./tests/forum5.test.html"> Destroy a post after it has received positive citations</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>

View File

@ -0,0 +1,27 @@
<!DOCTYPE html>
<head>
<title>Forum test 5</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
<link type="text/css" rel="stylesheet" href="../index.css" />
</head>
<body>
<div id="mocha"></div>
<div id="scene"></div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/radash/10.7.0/radash.js" integrity="sha512-S207zKWG3iqXqe6msO7/Mr8X3DzzF4u8meFlokHjGtBPTGUhgzVo0lpcqEy0GoiMUdcoct+H+SqzoLsxXbynzg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://unpkg.com/mocha/mocha.js"></script>
<script src="https://unpkg.com/chai/chai.js"></script>
<script type="module" src="./scripts/forum/forum5.test.js"></script>
<script defer class="mocha-init">
mocha.setup({
ui: 'bdd',
globals: ['scene', 'dao', 'experts', 'posts', '__REACT_DEVTOOLS_*'],
});
mocha.checkLeaks();
chai.should();
</script>
<script defer class="mocha-exec">
// TODO: Weird race condition -- resolve this in a better way
setTimeout(() => mocha.run(), 1000);
</script>

View File

@ -0,0 +1,59 @@
import { ForumTest } from './forum.test-util.js';
describe('Forum', () => {
const forumTest = new ForumTest();
before(async () => {
await forumTest.setup();
});
context('Destroy a post after it has received positive citations', async () => {
let forum;
let experts;
let posts;
before(() => {
forum = forumTest.forum;
experts = forumTest.experts;
posts = forumTest.posts;
});
it('Post1', async () => {
await forumTest.addPost(experts[0], 100);
forum.getPost(posts[0]).value.should.equal(100);
});
it('Post2 negatively cites Post1', async () => {
await forumTest.addPost(experts[0], 10, [
{ postId: posts[0], weight: -0.5 },
]);
forum.getPost(posts[0]).value.should.equal(95);
forum.getPost(posts[1]).value.should.equal(15);
});
it('Post3 positively cites Post2', async () => {
await forumTest.addPost(experts[0], 50, [
{ postId: posts[1], weight: 0.5 },
]);
forum.getPost(posts[0]).value.should.equal(95 - 12.5);
forum.getPost(posts[1]).value.should.equal(15 + 25 + 12.5);
forum.getPost(posts[2]).value.should.equal(25);
});
it('Post4 negatively cites Post2', async () => {
await forumTest.addPost(experts[0], 100, [
{ postId: posts[1], weight: -1 },
]);
// forum.getPost(posts[0]).value.should.equal(95 - 12.5);
// forum.getPost(posts[1]).value.should.equal(15 + 25 + 12.5);
// forum.getPost(posts[2]).value.should.equal(25);
});
});
});
// await addPost(experts[0], 10);
// await addPost(experts[0], 10, [{ postId: posts[3], weight: -1 }]);
// await addPost(experts[0], 10, [{ postId: posts[4], weight: -1 }]);
// await addPost(expert3, 'Post 4', 100, [{ postId: postId2, weight: -1 }]);
// await addPost(expert1, 'Post 5', 100, [{ postId: postId3, weight: -1 }]);