From b12759fac87bf584aafd218fbb2df36f2ebeae05 Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Wed, 10 Apr 2024 17:40:17 -0500 Subject: [PATCH] keep track of post reputations --- ethereum/contracts/core/Forum.sol | 3 +++ ethereum/test/Forum.js | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/ethereum/contracts/core/Forum.sol b/ethereum/contracts/core/Forum.sol index dc528d7..73156f1 100644 --- a/ethereum/contracts/core/Forum.sol +++ b/ethereum/contracts/core/Forum.sol @@ -15,6 +15,7 @@ struct Post { address author; string contentId; Citation[] citations; + uint reputation; } contract Forum is Reputation { @@ -73,8 +74,10 @@ contract Forum is Reputation { int remaining = amount - totalOutboundAmount; if (remaining > 0) { _update(address(this), post.author, uint(remaining)); + post.reputation += uint(remaining); } else { _update(post.author, address(this), uint(-remaining)); + post.reputation -= uint(-remaining); } } } diff --git a/ethereum/test/Forum.js b/ethereum/test/Forum.js index f9d46c8..a81b06a 100644 --- a/ethereum/test/Forum.js +++ b/ethereum/test/Forum.js @@ -77,10 +77,13 @@ describe('Forum', () => { it('should be able to leach reputation via citations', async () => { await dao.addPost(account1, 'content-id', []); + expect((await dao.posts(0)).reputation).to.equal(0); await initiateValidationPool({ postIndex: 0 }); await dao.evaluateOutcome(0); expect(await dao.balanceOf(account1)).to.equal(100); + expect((await dao.posts(0)).reputation).to.equal(100); await dao.addPost(account2, 'second-content-id', [{ weightPercent: -50, targetPostIndex: 0 }]); + expect((await dao.posts(1)).reputation).to.equal(0); await initiateValidationPool({ postIndex: 1 }); const pool = await dao.validationPools(1); expect(pool.postIndex).to.equal(1); @@ -88,6 +91,8 @@ describe('Forum', () => { await dao.evaluateOutcome(1); expect(await dao.balanceOf(account1)).to.equal(50); expect(await dao.balanceOf(account2)).to.equal(150); + expect((await dao.posts(0)).reputation).to.equal(50); + expect((await dao.posts(1)).reputation).to.equal(150); }); it('should be able to redistribute power via citations', async () => {