Skip to content

Commit 9feb70d

Browse files
authored
Competition : Add Redemption period (#770)
* add REDEMPTION_PERIOD * cannot redeem after the redemption period * require error msg * tests * spelling
1 parent ef28d1b commit 9feb70d

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

contracts/schemes/Competition.sol

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import "./ContributionRewardExt.sol";
66
contract Competition {
77
using SafeMath for uint256;
88

9-
uint256 constant public MAX_NUMBER_OF_WINNERS = 100;
10-
119
event NewCompetitionProposal(
1210
bytes32 indexed _proposalId,
1311
uint256 _numberOfWinners,
@@ -81,6 +79,8 @@ contract Competition {
8179
mapping(uint256=>Suggestion) public suggestions;
8280
uint256 public suggestionsCounter;
8381
address payable public contributionRewardExt; //address of the contract to redeem from.
82+
uint256 constant public REDEMPTION_PERIOD = 7776000; //90 days
83+
uint256 constant public MAX_NUMBER_OF_WINNERS = 100;
8484

8585
/**
8686
* @dev initialize
@@ -274,13 +274,9 @@ contract Competition {
274274
*/
275275
function sendLeftOverFunds(bytes32 _proposalId) public {
276276
// solhint-disable-next-line not-rely-on-time
277-
require(proposals[_proposalId].endTime < now, "competition is still on");
277+
require(proposals[_proposalId].endTime.add(REDEMPTION_PERIOD) < now, "redemption period is still on");
278278
require(proposals[_proposalId].maxNumberOfVotesPerVoter > 0, "proposal does not exist");
279279
require(_proposalId != bytes32(0), "proposalId is zero");
280-
uint256[] memory topSuggestions = proposals[_proposalId].topSuggestions;
281-
for (uint256 i = 0; i < topSuggestions.length; i++) {
282-
require(suggestions[topSuggestions[i]].beneficiary == address(0), "not all winning suggestions redeemed");
283-
}
284280

285281
(, , , , , ,
286282
uint256 nativeTokenRewardLeft, ,
@@ -311,6 +307,8 @@ contract Competition {
311307
require(_suggestionId > 0, "suggestionId is zero");
312308
// solhint-disable-next-line not-rely-on-time
313309
require(proposal.endTime < now, "competition is still on");
310+
// solhint-disable-next-line not-rely-on-time
311+
require(proposal.endTime.add(REDEMPTION_PERIOD) > now, "redemption period is over");
314312
require(proposal.maxNumberOfVotesPerVoter > 0, "proposal does not exist");
315313
require(suggestions[_suggestionId].beneficiary != address(0),
316314
"suggestion was already redeemed");

test/competition.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,28 @@ contract('Competition', accounts => {
519519

520520
});
521521

522+
it("cannot redeem after the REDEMPTION_PERIOD", async function() {
523+
var testSetup = await setup(accounts);
524+
await testSetup.standardTokenMock.transfer(testSetup.org.avatar.address,30,{from:accounts[1]});
525+
await web3.eth.sendTransaction({from:accounts[0],to:testSetup.org.avatar.address, value:20});
526+
var proposalId = await proposeCompetition(testSetup);
527+
await helpers.increaseTime(20);
528+
await testSetup.competition.suggest(proposalId,"suggestion",helpers.NULL_ADDRESS);
529+
await testSetup.contributionRewardExtParams.votingMachine.absoluteVote.vote(proposalId,1,0,helpers.NULL_ADDRESS,{from:accounts[2]});
530+
await testSetup.contributionRewardExtParams.votingMachine.absoluteVote.vote(proposalId,1,0,helpers.NULL_ADDRESS,{from:accounts[0]});
531+
await testSetup.contributionRewardExt.redeem(proposalId,[true,true,true,true]);
532+
await helpers.increaseTime(650);
533+
await testSetup.competition.vote(1,{from:accounts[1]});
534+
await helpers.increaseTime(650+7776000+1);
535+
try {
536+
await testSetup.competition.redeem(1);
537+
assert(false, 'cannot redeem after the REDEMPTION_PERIOD');
538+
} catch (ex) {
539+
helpers.assertVMException(ex);
540+
}
541+
542+
});
543+
522544
it("negative reputation change is not allowed", async function() {
523545
var testSetup = await setup(accounts);
524546
try {
@@ -606,7 +628,7 @@ contract('Competition', accounts => {
606628

607629
try {
608630
await testSetup.competition.sendLeftOverFunds(proposalId);
609-
assert(false, 'cannot sendLeftOverFunds because not all proposals redeemed yet');
631+
assert(false, 'cannot sendLeftOverFunds because redeemed period is still on');
610632
} catch (ex) {
611633
helpers.assertVMException(ex);
612634
}
@@ -618,7 +640,7 @@ contract('Competition', accounts => {
618640
assert.equal(tx.logs[0].args._rewardPercentage,53);
619641

620642
var proposal = await testSetup.contributionRewardExt.organizationProposals(proposalId);
621-
643+
await helpers.increaseTime(7776000);
622644
tx = await testSetup.competition.sendLeftOverFunds(proposalId);
623645
await testSetup.contributionRewardExt.getPastEvents('RedeemExternalToken', {
624646
fromBlock: tx.blockNumber,

0 commit comments

Comments
 (0)