Skip to content

Commit

Permalink
Competition : Add Redemption period (#770)
Browse files Browse the repository at this point in the history
* add REDEMPTION_PERIOD

* cannot redeem after the redemption period

* require error msg

* tests

* spelling
  • Loading branch information
orenyodfat authored Jul 16, 2020
1 parent ef28d1b commit 9feb70d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
12 changes: 5 additions & 7 deletions contracts/schemes/Competition.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import "./ContributionRewardExt.sol";
contract Competition {
using SafeMath for uint256;

uint256 constant public MAX_NUMBER_OF_WINNERS = 100;

event NewCompetitionProposal(
bytes32 indexed _proposalId,
uint256 _numberOfWinners,
Expand Down Expand Up @@ -81,6 +79,8 @@ contract Competition {
mapping(uint256=>Suggestion) public suggestions;
uint256 public suggestionsCounter;
address payable public contributionRewardExt; //address of the contract to redeem from.
uint256 constant public REDEMPTION_PERIOD = 7776000; //90 days
uint256 constant public MAX_NUMBER_OF_WINNERS = 100;

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

(, , , , , ,
uint256 nativeTokenRewardLeft, ,
Expand Down Expand Up @@ -311,6 +307,8 @@ contract Competition {
require(_suggestionId > 0, "suggestionId is zero");
// solhint-disable-next-line not-rely-on-time
require(proposal.endTime < now, "competition is still on");
// solhint-disable-next-line not-rely-on-time
require(proposal.endTime.add(REDEMPTION_PERIOD) > now, "redemption period is over");
require(proposal.maxNumberOfVotesPerVoter > 0, "proposal does not exist");
require(suggestions[_suggestionId].beneficiary != address(0),
"suggestion was already redeemed");
Expand Down
26 changes: 24 additions & 2 deletions test/competition.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,28 @@ contract('Competition', accounts => {

});

it("cannot redeem after the REDEMPTION_PERIOD", async function() {
var testSetup = await setup(accounts);
await testSetup.standardTokenMock.transfer(testSetup.org.avatar.address,30,{from:accounts[1]});
await web3.eth.sendTransaction({from:accounts[0],to:testSetup.org.avatar.address, value:20});
var proposalId = await proposeCompetition(testSetup);
await helpers.increaseTime(20);
await testSetup.competition.suggest(proposalId,"suggestion",helpers.NULL_ADDRESS);
await testSetup.contributionRewardExtParams.votingMachine.absoluteVote.vote(proposalId,1,0,helpers.NULL_ADDRESS,{from:accounts[2]});
await testSetup.contributionRewardExtParams.votingMachine.absoluteVote.vote(proposalId,1,0,helpers.NULL_ADDRESS,{from:accounts[0]});
await testSetup.contributionRewardExt.redeem(proposalId,[true,true,true,true]);
await helpers.increaseTime(650);
await testSetup.competition.vote(1,{from:accounts[1]});
await helpers.increaseTime(650+7776000+1);
try {
await testSetup.competition.redeem(1);
assert(false, 'cannot redeem after the REDEMPTION_PERIOD');
} catch (ex) {
helpers.assertVMException(ex);
}

});

it("negative reputation change is not allowed", async function() {
var testSetup = await setup(accounts);
try {
Expand Down Expand Up @@ -606,7 +628,7 @@ contract('Competition', accounts => {

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

var proposal = await testSetup.contributionRewardExt.organizationProposals(proposalId);

await helpers.increaseTime(7776000);
tx = await testSetup.competition.sendLeftOverFunds(proposalId);
await testSetup.contributionRewardExt.getPastEvents('RedeemExternalToken', {
fromBlock: tx.blockNumber,
Expand Down

0 comments on commit 9feb70d

Please sign in to comment.