Remove claims, add withdrawals #225

Merged
raucao merged 4 commits from feature/184-remove_kredits_claims into feature/export-import 2022-08-30 08:53:55 +00:00
2 changed files with 4 additions and 6 deletions
Showing only changes of commit 5da710cc14 - Show all commits

View File

@ -22,7 +22,7 @@ contract Contributor is Initializable {
uint8 hashFunction;
uint8 hashSize;
bool exists;
uint256 kreditsWithdrawn;
uint32 kreditsWithdrawn;
}
mapping (address => uint32) public contributorIds;
@ -160,8 +160,8 @@ contract Contributor is Initializable {
Contributor storage c = contributors[id];
// TODO check if we need a failsafe for unconfirmed or malicious txs
uint256 confirmedKredits = contributionContract.totalKreditsEarnedByContributor(id, true);
uint256 amountWithdrawable = confirmedKredits - c.kreditsWithdrawn;
uint32 confirmedKredits = contributionContract.totalKreditsEarnedByContributor(id, true);
uint32 amountWithdrawable = confirmedKredits - c.kreditsWithdrawn;
require (amountWithdrawable > 0, "No kredits available");
c.kreditsWithdrawn += amountWithdrawable;
Review

wondering if we should add an assert(c.kreditsWithdrawn <= confirmedKredits) ?

wondering if we should add an `assert(c.kreditsWithdrawn <= confirmedKredits)` ?
Review

That's just the same as the line above, where confirmedKredits - c.kreditsWithdrawn is required to be > 0, no?

That's just the same as the line above, where `confirmedKredits - c.kreditsWithdrawn` is required to be `> 0`, no?

View File

@ -95,10 +95,8 @@ describe("Contributor contract", async function () {
expect(c['balance']).to.equal(0);
await Contributor.connect(addr1).withdraw();
c = await Contributor.getContributorById(2);
// TODO Are we required to use Wei for ERC20 tokens?
expect(c['balance'].toString()).to.equal("6500000000000000000000");
// FIXME This is also a BigNumber (uint256), but stored at Wei reolution
expect(c['kreditsWithdrawn'].toString()).to.equal('6500');
expect(c['kreditsWithdrawn']).to.equal(6500);
});
it("requires the withdrawable amount to be larger than 0", async function () {