fixup power redistribution mechanism
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 41s Details

This commit is contained in:
Ladd Hoffman 2024-04-12 18:57:00 -05:00
parent 4a814e6302
commit a54cc86dba
2 changed files with 15 additions and 15 deletions

View File

@ -118,44 +118,40 @@ contract Forum is Reputation {
return amount;
}
Post storage post = posts[postIndex];
int totalOutboundAmount;
// Propagate negative citations first
for (uint i = 0; i < post.citations.length; i++) {
if (post.citations[i].weightPercent < 0) {
int outboundAmount = _handleCitation(
amount -= _handleCitation(
postIndex,
post.citations[i],
amount,
initialNegative,
depth
);
totalOutboundAmount += outboundAmount;
}
}
// Now propagate positive citations
for (uint i = 0; i < post.citations.length; i++) {
if (post.citations[i].weightPercent > 0) {
int outboundAmount = _handleCitation(
amount -= _handleCitation(
postIndex,
post.citations[i],
amount,
initialNegative,
depth
);
totalOutboundAmount += outboundAmount;
}
}
int remaining = amount - totalOutboundAmount;
if (remaining > 0) {
_update(address(this), post.author, uint(remaining));
post.reputation += uint(remaining);
if (amount > 0) {
_update(address(this), post.author, uint(amount));
post.reputation += uint(amount);
} else {
// Prevent reputation from being reduced below zero
if (int(post.reputation) + remaining >= 0) {
_update(post.author, address(this), uint(-remaining));
post.reputation -= uint(-remaining);
if (int(post.reputation) + amount >= 0) {
_update(post.author, address(this), uint(-amount));
post.reputation -= uint(-amount);
} else {
refundToInbound = int(post.reputation) + remaining;
refundToInbound = int(post.reputation) + amount;
_update(post.author, address(this), post.reputation);
post.reputation = 0;
}

View File

@ -96,15 +96,18 @@ describe('Forum', () => {
});
it('should be able to redistribute power via citations', async () => {
console.log('First post');
await dao.addPost(account1, 'content-id', []);
await initiateValidationPool({ postIndex: 0 });
await dao.evaluateOutcome(0);
expect(await dao.balanceOf(account1)).to.equal(100);
console.log('Second post');
await dao.addPost(account2, 'second-content-id', []);
expect(await dao.balanceOf(account2)).to.equal(0);
console.log('Third post');
await dao.addPost(account3, 'third-content-id', [
{ weightPercent: -100, targetPostIndex: 0 },
{ weightPercent: 100, targetPostIndex: 1 },
{ weightPercent: -100, targetPostIndex: 0 },
]);
await initiateValidationPool({ postIndex: 2 });
const pool = await dao.validationPools(1);
@ -112,7 +115,8 @@ describe('Forum', () => {
await time.increase(POOL_DURATION + 1);
await dao.evaluateOutcome(1);
expect(await dao.balanceOf(account1)).to.equal(0);
expect(await dao.balanceOf(account2)).to.equal(100);
expect(await dao.balanceOf(account2)).to.equal(200);
expect(await dao.balanceOf(account3)).to.equal(0);
});
it('should be able to reverse a negative citation with a negative citation', async () => {