From a49b42858aa149e76a59ad16464799a1242e4b95 Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Fri, 12 Apr 2024 18:07:38 -0500 Subject: [PATCH] support incineration --- ethereum/contracts/core/Forum.sol | 9 +++++++++ ethereum/test/Forum.js | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/ethereum/contracts/core/Forum.sol b/ethereum/contracts/core/Forum.sol index 4f540da..cd8589d 100644 --- a/ethereum/contracts/core/Forum.sol +++ b/ethereum/contracts/core/Forum.sol @@ -75,6 +75,15 @@ contract Forum is Reputation { uint depth ) internal returns (int outboundAmount) { outboundAmount = (amount * citation.weightPercent) / 100; + if (citation.targetPostIndex == type(uint256).max) { + // Incineration + require( + outboundAmount >= 0, + "Leaching from incinerator is forbidden" + ); + _burn(address(this), uint(outboundAmount)); + return outboundAmount; + } int balanceToOutbound = _edgeBalances[postIndex][ citation.targetPostIndex ]; diff --git a/ethereum/test/Forum.js b/ethereum/test/Forum.js index ad751f2..4fbf565 100644 --- a/ethereum/test/Forum.js +++ b/ethereum/test/Forum.js @@ -215,5 +215,18 @@ describe('Forum', () => { expect(posts[2].reputation).to.equal(0); expect(posts[3].reputation).to.equal(0); }); + + it('should be able to incinerate reputation', async () => { + await dao.addPost(account1, 'content-id-1', [ + { + weightPercent: 50, + targetPostIndex: ethers.MaxUint256, + }, + ]); + await initiateValidationPool({ postIndex: 0 }); + expect(await dao.totalSupply()).to.equal(100); + await dao.evaluateOutcome(0); + expect((await dao.posts(0)).reputation).to.equal(50); + }); }); });