Skip to content

Commit

Permalink
cannot redeem after the redemption period (#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-kaufman authored Jul 16, 2020
1 parent 2d69f0d commit 16889ab
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
12 changes: 5 additions & 7 deletions contracts/schemes/Competition.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.so
contract Competition is Initializable, Rewarder {
using SafeMath for uint256;

uint256 constant public MAX_NUMBER_OF_WINNERS = 100;

event NewCompetitionProposal(
bytes32 indexed _proposalId,
uint256 _numberOfWinners,
Expand Down Expand Up @@ -83,6 +81,8 @@ contract Competition is Initializable, Rewarder {
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 @@ -275,13 +275,9 @@ contract Competition is Initializable, Rewarder {
*/
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 @@ -312,6 +308,8 @@ contract Competition is Initializable, Rewarder {
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
24 changes: 23 additions & 1 deletion test/competition.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,27 @@ 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 @@ -658,7 +679,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 @@ -670,6 +691,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', {
Expand Down

0 comments on commit 16889ab

Please sign in to comment.