Skip to content

Commit 6132bfe

Browse files
dkent600orenyodfat
authored andcommitted
return reputation rewarded from Redeem function (#566)
* return reputation rewarded * bump version * requested changes * fix eslint error
1 parent 6622a76 commit 6132bfe

File tree

6 files changed

+52
-9
lines changed

6 files changed

+52
-9
lines changed

contracts/schemes/Auction4Reputation.sol

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,21 @@ contract Auction4Reputation is Ownable {
8686
* @dev redeem reputation function
8787
* @param _beneficiary the beneficiary to redeem.
8888
* @param _auctionId the auction id to redeem from.
89-
* @return bool
89+
* @return uint reputation rewarded
9090
*/
91-
function redeem(address _beneficiary, uint _auctionId) public returns(bool) {
91+
function redeem(address _beneficiary, uint _auctionId) public returns(uint reputation) {
9292
// solium-disable-next-line security/no-block-members
9393
require(now > redeemEnableTime, "now > redeemEnableTime");
9494
Auction storage auction = auctions[_auctionId];
9595
uint bid = auction.bids[_beneficiary];
9696
require(bid > 0, "bidding amount should be > 0");
9797
auction.bids[_beneficiary] = 0;
9898
int256 repRelation = int216(bid).toReal().mul(int216(auctionReputationReward).toReal());
99-
uint reputation = uint256(repRelation.div(int216(auction.totalBid).toReal()).fromReal());
99+
reputation = uint256(repRelation.div(int216(auction.totalBid).toReal()).fromReal());
100100
// check that the reputation is sum zero
101101
reputationRewardLeft = reputationRewardLeft.sub(reputation);
102102
require(ControllerInterface(avatar.owner()).mintReputation(reputation, _beneficiary, avatar), "mint reputation should success");
103103
emit Redeem(_auctionId, _beneficiary, reputation);
104-
return true;
105104
}
106105

107106
/**

contracts/schemes/Locking4Reputation.sol

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,22 @@ contract Locking4Reputation {
4343
/**
4444
* @dev redeem reputation function
4545
* @param _beneficiary the beneficiary for the release
46-
* @return bool
46+
* @return uint reputation rewarded
4747
*/
48-
function redeem(address _beneficiary) public returns(bool) {
48+
function redeem(address _beneficiary) public returns(uint reputation) {
4949
// solium-disable-next-line security/no-block-members
5050
require(block.timestamp > redeemEnableTime, "now > redeemEnableTime");
5151
require(scores[_beneficiary] > 0, "score should be > 0");
5252
uint score = scores[_beneficiary];
5353
scores[_beneficiary] = 0;
5454
int256 repRelation = int216(score).toReal().mul(int216(reputationReward).toReal());
55-
uint reputation = uint256(repRelation.div(int216(totalScore).toReal()).fromReal());
55+
reputation = uint256(repRelation.div(int216(totalScore).toReal()).fromReal());
5656

5757
//check that the reputation is sum zero
5858
reputationRewardLeft = reputationRewardLeft.sub(reputation);
5959
require(ControllerInterface(avatar.owner()).mintReputation(reputation, _beneficiary, avatar), "mint reputation should success");
6060

6161
emit Redeem(_beneficiary, reputation);
62-
63-
return true;
6462
}
6563

6664
/**

test/auction4reputation.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,15 @@ contract('Auction4Reputation', accounts => {
337337
helpers.assertVMException(error);
338338
}
339339
});
340+
341+
it("get earned reputation", async () => {
342+
let testSetup = await setup(accounts);
343+
var tx = await testSetup.auction4Reputation.bid(web3.utils.toWei('1', "ether"));
344+
var id = await helpers.getValueFromLogs(tx, '_auctionId',1);
345+
await helpers.increaseTime(3001);
346+
tx = await testSetup.auction4Reputation.redeem.call(accounts[0],id);
347+
const reputation = await testSetup.auction4Reputation.redeem.call(accounts[0], id);
348+
assert.equal(reputation,100);
349+
assert.equal(await testSetup.org.reputation.balanceOf(accounts[0]),1000);
350+
});
340351
});

test/externallocking4reputation.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,12 @@ contract('ExternalLocking4Reputation', accounts => {
266266
{from:accounts[0]});
267267
});
268268

269+
it("get earned reputation", async () => {
270+
let testSetup = await setup(accounts);
271+
await testSetup.externalLocking4Reputation.claim(helpers.NULL_ADDRESS);
272+
await helpers.increaseTime(3001);
273+
const reputation = await testSetup.externalLocking4Reputation.redeem.call(accounts[0]);
274+
assert.equal(reputation,100);
275+
assert.equal(await testSetup.org.reputation.balanceOf(accounts[0]),1000);
276+
});
269277
});

test/lockingeth4reputation.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,4 +281,13 @@ contract('LockingEth4Reputation', accounts => {
281281
100,
282282
6000);
283283
});
284+
285+
it("get earned reputation", async () => {
286+
let testSetup = await setup(accounts);
287+
await testSetup.lockingEth4Reputation.lock(100,{value:web3.utils.toWei('1', "ether")});
288+
await helpers.increaseTime(3001);
289+
const reputation = await testSetup.lockingEth4Reputation.redeem.call(accounts[0]);
290+
assert.equal(reputation,100);
291+
assert.equal(await testSetup.org.reputation.balanceOf(accounts[0]),1000);
292+
});
284293
});

test/lockingtoken4reputation.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ const setup = async function (accounts,
4545
};
4646

4747
contract('LockingToken4Reputation', accounts => {
48+
it("get earned reputation", async () => {
49+
let testSetup = await setup(accounts);
50+
await testSetup.lockingToken4Reputation.lock(web3.utils.toWei('1', "ether"),100,testSetup.lockingToken.address);
51+
await helpers.increaseTime(3001);
52+
const reputation = await testSetup.lockingToken4Reputation.redeem.call(accounts[0]);
53+
assert.equal(reputation,100);
54+
assert.equal(await testSetup.org.reputation.balanceOf(accounts[0]),1000);
55+
});
56+
4857
it("initialize", async () => {
4958
let testSetup = await setup(accounts);
5059
assert.equal(await testSetup.lockingToken4Reputation.reputationReward(),100);
@@ -325,4 +334,13 @@ contract('LockingToken4Reputation', accounts => {
325334
6000,
326335
accounts[1]);
327336
});
337+
338+
it("get earned reputation", async () => {
339+
let testSetup = await setup(accounts);
340+
await testSetup.lockingToken4Reputation.lock(web3.utils.toWei('1', "ether"),100,testSetup.lockingToken.address);
341+
await helpers.increaseTime(3001);
342+
const reputation = await testSetup.lockingToken4Reputation.redeem.call(accounts[0]);
343+
assert.equal(reputation,100);
344+
assert.equal(await testSetup.org.reputation.balanceOf(accounts[0]),1000);
345+
});
328346
});

0 commit comments

Comments
 (0)