enfore reference chain limit
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 30s Details

This commit is contained in:
Ladd Hoffman 2024-04-12 17:38:22 -05:00
parent a7f3e5f2e4
commit d8d0122e31
2 changed files with 26 additions and 7 deletions

View File

@ -25,7 +25,9 @@ contract Forum is Reputation {
event PostAdded(uint postIndex);
// TODO: Add forum parameters
// Forum parameters
// TODO: Make depth limit configurable; take as param in _onValidatePost callback
uint depthLimit = 3;
function addPost(
address author,
@ -103,6 +105,9 @@ contract Forum is Reputation {
bool initialNegative,
uint depth
) internal returns (int refundToInbound) {
if (depth >= depthLimit) {
return amount;
}
Post storage post = posts[postIndex];
int totalOutboundAmount;
// Propagate negative citations first

View File

@ -162,14 +162,12 @@ describe('Forum', () => {
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', [{ weightPercent: 50, targetPostIndex: 0 }]);
await initiateValidationPool({ postIndex: 1 });
await time.increase(POOL_DURATION + 1);
await dao.evaluateOutcome(1);
expect(await dao.balanceOf(account1)).to.equal(150);
expect(await dao.balanceOf(account2)).to.equal(50);
console.log('Third post');
await dao.addPost(account3, 'third-content-id', [{ weightPercent: -100, targetPostIndex: 1 }]);
await initiateValidationPool({ postIndex: 2, fee: 200 });
await time.increase(POOL_DURATION + 1);
@ -179,20 +177,17 @@ describe('Forum', () => {
expect(await dao.balanceOf(account3)).to.equal(300);
});
it('should limit effects of negative references', async () => {
console.log('First post');
it('should limit effects of negative references on prior negative references', async () => {
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', [{ weightPercent: -100, targetPostIndex: 0 }]);
await initiateValidationPool({ postIndex: 1 });
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(200);
console.log('Third post');
await dao.addPost(account3, 'third-content-id', [{ weightPercent: -100, targetPostIndex: 1 }]);
await initiateValidationPool({ postIndex: 2, fee: 200 });
await time.increase(POOL_DURATION + 1);
@ -201,5 +196,24 @@ describe('Forum', () => {
expect(await dao.balanceOf(account2)).to.equal(0);
expect(await dao.balanceOf(account3)).to.equal(300);
});
it('should enforce depth limit', async () => {
await dao.addPost(account1, 'content-id-1', []);
await dao.addPost(account1, 'content-id-2', [{ weightPercent: 100, targetPostIndex: 0 }]);
await dao.addPost(account1, 'content-id-3', [{ weightPercent: 100, targetPostIndex: 1 }]);
await dao.addPost(account1, 'content-id-4', [{ weightPercent: 100, targetPostIndex: 2 }]);
await initiateValidationPool({ postIndex: 3 });
await dao.evaluateOutcome(0);
const posts = await Promise.all([
await dao.posts(0),
await dao.posts(1),
await dao.posts(2),
await dao.posts(3),
]);
expect(posts[0].reputation).to.equal(0);
expect(posts[1].reputation).to.equal(100);
expect(posts[2].reputation).to.equal(0);
expect(posts[3].reputation).to.equal(0);
});
});
});