From 5da710cc14203d64dff4786a51b2051945c90147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Sat, 27 Aug 2022 10:29:56 +0200 Subject: [PATCH] Use uint32 for kreditsWithdrawn Same as the properties and functions in the Contribution contract --- contracts/Contributor.sol | 6 +++--- test/contracts/Contributor.js | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/contracts/Contributor.sol b/contracts/Contributor.sol index f33e337..f2ad60d 100644 --- a/contracts/Contributor.sol +++ b/contracts/Contributor.sol @@ -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; diff --git a/test/contracts/Contributor.js b/test/contracts/Contributor.js index 3639c77..e20c02c 100644 --- a/test/contracts/Contributor.js +++ b/test/contracts/Contributor.js @@ -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 () {