fix off-by-one error on VP rewards
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 32s Details

This commit is contained in:
Ladd Hoffman 2024-04-16 18:37:18 -05:00
parent 1d7683ff75
commit ea389dcfd6
2 changed files with 9 additions and 2 deletions

View File

@ -158,6 +158,9 @@ contract ValidationPools is Reputation, Forum {
}
stakedFor += pool.minted / 2;
stakedAgainst += pool.minted / 2;
if (pool.minted % 2 != 0) {
stakedFor += 1;
}
// Special case for early evaluation if dao.totalSupply has been staked
require(
block.timestamp > pool.endTime ||
@ -227,6 +230,9 @@ contract ValidationPools is Reputation, Forum {
// Here we assume a stakeForAuthor ratio of 0.5
// TODO: Make stakeForAuthor an adjustable parameter
totalRewards += pool.minted / 2;
if (pool.minted % 2 != 0) {
totalRewards += 1;
}
// Include the losign portion of the VP initial stake
// Issue rewards to the winners
for (uint i = 0; i < pool.stakeCount; i++) {
@ -244,6 +250,7 @@ contract ValidationPools is Reputation, Forum {
}
// Due to rounding, there may be some excess REP. Award it to the author.
uint remainder = totalRewards - totalAllocated;
// Transfer REP to the forum instead of to the author directly
_onValidatePost(pool.postIndex, pool.minted / 2 + remainder);
} else {

View File

@ -305,10 +305,10 @@ describe('Forum', () => {
expect(await dao.totalSupply()).to.equal(375);
expect(await dao.balanceOf(account1)).to.equal(0);
expect(await dao.balanceOf(account2)).to.equal(250);
expect(await dao.balanceOf(account3)).to.equal(124);
expect(await dao.balanceOf(account3)).to.equal(125);
expect((await dao.posts(0)).reputation).to.equal(26);
expect((await dao.posts(1)).reputation).to.equal(100);
expect((await dao.posts(2)).reputation).to.equal(124);
expect((await dao.posts(2)).reputation).to.equal(125);
});
});
});