Skip to content

Commit

Permalink
added half of the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ryzhak committed Dec 10, 2018
1 parent 423e55c commit 66d0161
Show file tree
Hide file tree
Showing 6 changed files with 386 additions and 58 deletions.
80 changes: 58 additions & 22 deletions contracts/Daico/Daico.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract Daico is Ownable {
uint[] public tapAmounts;
uint[] public tapTimestampsFinishAt;

enum VotingType { ReleaseTap, ReleaseTapDecreasedQuorum, ChangeRoadmap, TerminateProject }
enum VotingType { ReleaseTap, ReleaseTapDecreasedQuorum, ChangeRoadmap, ChangeRoadmapDecreasedQuorum, TerminateProject, TerminateProjectDecreasedQuorum }
enum VotingResult { Accept, Decline, QuorumNotReached, NoDecision }

mapping(uint => mapping(uint => uint)) public tapVotings;
Expand Down Expand Up @@ -157,15 +157,26 @@ contract Daico is Ownable {
return VotingResult.NoDecision;
}

/**
* @dev Checks whether investor already voted in particular voting
* @param _votingIndex voting index
* @param _investorAddress investor address
* @return whether investor has already voted in particular voting
*/
function isInvestorVoted(uint _votingIndex, address _investorAddress) external view validVotingIndex(_votingIndex) returns(bool) {
require(_investorAddress != address(0));
return votings[_votingIndex].voted[_investorAddress];
}

/**
* @dev Checks whether project is terminated
* @return is project terminated
*/
function isProjectTerminated() public view returns(bool) {
bool isTerminated = false;
Voting memory latestVoting = votings[votingsCount.sub(1)];
// if latest voting is of type TerminateProject and result Accept then set isTerminated to true
if((latestVoting.votingType == VotingType.TerminateProject) && (getVotingResult(votingsCount.sub(1)) == VotingResult.Accept)) {
// if latest voting is of type TerminateProject or TerminateProjectDecreasedQuorum and result Accept then set isTerminated to true
if(((latestVoting.votingType == VotingType.TerminateProject) || (latestVoting.votingType == VotingType.TerminateProjectDecreasedQuorum)) && (getVotingResult(votingsCount.sub(1)) == VotingResult.Accept)) {
isTerminated = true;
}
return isTerminated;
Expand All @@ -182,16 +193,8 @@ contract Daico is Ownable {
uint latestVotingIndex = tapVotings[_tapIndex][tapVotingsCount[_tapIndex].sub(1)];
Voting memory voting = votings[latestVotingIndex];
bool isVotingAccepted = getVotingResult(latestVotingIndex) == VotingResult.Accept;
// if voting of type ReleaseTap and result is Accept then set isWithdrawAccepted to true
if((voting.votingType == VotingType.ReleaseTap) && isVotingAccepted) {
isWithdrawAccepted = true;
}
// if voting of type ReleaseTapDecreasedQuorum and result is Accept then set isWithdrawAccepted to true
if((voting.votingType == VotingType.ReleaseTapDecreasedQuorum) && isVotingAccepted) {
isWithdrawAccepted = true;
}
// if voting of type ChangeRoadmap and result is Accept then set isWithdrawAccepted to true
if((voting.votingType == VotingType.ChangeRoadmap) && isVotingAccepted) {
// if voting is of types: ReleaseTap, ReleaseTapDecreasedQuorum, ChangeRoadmap or ChangeRoadmapDecreasedQuorum then set isWithdrawAccepted to true
if(((voting.votingType != VotingType.TerminateProject) && (voting.votingType != VotingType.TerminateProjectDecreasedQuorum)) && isVotingAccepted) {
isWithdrawAccepted = true;
}
return isWithdrawAccepted;
Expand All @@ -202,34 +205,66 @@ contract Daico is Ownable {
*/

/**
* @dev Creates a new voting by investor. Investors can create votings of 2 types: ChangeRoadmap and TerminateProject.
* @dev Creates a new voting by investor. Investors can create votings of 4 types: ChangeRoadmap, ChangeRoadmapDecreasedQuorum, TerminateProject, TerminateProjectDecreasedQuorum.
* @param _tapIndex tap index
* @param _votingType voting type
*/
function createVotingByInvestor(uint _tapIndex, VotingType _votingType) external onlyInvestor validTapIndex(_tapIndex) {
// common validation
require(_votingType == VotingType.ChangeRoadmap || _votingType == VotingType.TerminateProject);
require(_votingType == VotingType.ChangeRoadmap || _votingType == VotingType.ChangeRoadmapDecreasedQuorum || _votingType == VotingType.TerminateProject || _votingType == VotingType.TerminateProjectDecreasedQuorum);
uint latestVotingIndex = tapVotings[_tapIndex][tapVotingsCount[_tapIndex].sub(1)];
Voting memory latestVoting = votings[latestVotingIndex];
VotingResult votingResult = getVotingResult(latestVotingIndex);
// check that last voting is finished
require(now >= latestVoting.finishAt);

// if investor wants to create voting of type ChangeRoadmap
if(_votingType == VotingType.ChangeRoadmap) {
// check that latest voting is of type ReleaseTap or ReleaseTapDecreasedQuorum
require(latestVoting.votingType == VotingType.ReleaseTap || latestVoting.votingType == VotingType.ReleaseTapDecreasedQuorum);
// check that latest voting result is no decision
require(getVotingResult(latestVotingIndex) == VotingResult.NoDecision);
// check that latest voting is of types ReleaseTap, ReleaseTapDecreasedQuorum, TerminateProject, TerminateProjectDecreasedQuorum
require(latestVoting.votingType == VotingType.ReleaseTap || latestVoting.votingType == VotingType.ReleaseTapDecreasedQuorum || latestVoting.votingType == VotingType.TerminateProject || latestVoting.votingType == VotingType.TerminateProjectDecreasedQuorum);
// if latest voting is ReleaseTap
if(latestVoting.votingType == VotingType.ReleaseTap || latestVoting.votingType == VotingType.ReleaseTapDecreasedQuorum) {
// check that latest voting result is no decision
require(votingResult == VotingResult.NoDecision);
}
// if latest voting is TerminateProject
if(latestVoting.votingType == VotingType.TerminateProject || latestVoting.votingType == VotingType.TerminateProjectDecreasedQuorum) {
// check that latest voting result is decline
require(votingResult == VotingResult.Decline);
}
// create a new voting
_createVoting(_tapIndex, minQuorumRate, now + 3 weeks, now + 4 weeks, VotingType.ChangeRoadmap);
}

// if investor wants to create voting of type ChangeRoadmapDecreasedQuorum
if(_votingType == VotingType.ChangeRoadmapDecreasedQuorum) {
// check that latest voting is of type ChangeRoadmap or ChangeRoadmapDecreasedQuorum
require(latestVoting.votingType == VotingType.ChangeRoadmap || latestVoting.votingType == VotingType.ChangeRoadmapDecreasedQuorum);
// check that latest voting result has not reached quorum or has no decision
require((votingResult == VotingResult.QuorumNotReached) || (votingResult == VotingResult.NoDecision));
// create a new voting
_createVoting(_tapIndex, 50, now + 3 weeks, now + 4 weeks, VotingType.ChangeRoadmapDecreasedQuorum);
}

// if investor wants to create voting of type TerminateProject
if(_votingType == VotingType.TerminateProject) {
// check that latest voting is of types: ReleaseTap, ReleaseTapDecreasedQuorum, ChangeRoadmap, ChangeRoadmapDecreasedQuorum
require(latestVoting.votingType == VotingType.ReleaseTap || latestVoting.votingType == VotingType.ReleaseTapDecreasedQuorum || latestVoting.votingType == VotingType.ChangeRoadmap || latestVoting.votingType == VotingType.ChangeRoadmapDecreasedQuorum);
// check that latest voting result is decline
require(getVotingResult(latestVotingIndex) == VotingResult.Decline);
require(votingResult == VotingResult.Decline);
// create a new voting
_createVoting(_tapIndex, minQuorumRate, now, now + 2 weeks, VotingType.TerminateProject);
}

// if investor wants to create voting of type TerminateProjectDecreasedQuorum
if(_votingType == VotingType.TerminateProjectDecreasedQuorum) {
// check that latest voting is of type TerminateProject or TerminateProjectDecreasedQuorum
require(latestVoting.votingType == VotingType.TerminateProject || latestVoting.votingType == VotingType.TerminateProjectDecreasedQuorum);
// check that latest voting result has not reached quorum or has no decision
require((votingResult == VotingResult.QuorumNotReached) || (votingResult == VotingResult.NoDecision));
// create a new voting
_createVoting(_tapIndex, 50, now, now + 2 weeks, VotingType.TerminateProjectDecreasedQuorum);
}
}

/**
Expand All @@ -242,6 +277,7 @@ contract Daico is Ownable {
require(now >= votings[_votingIndex].createdAt);
require(now < votings[_votingIndex].finishAt);
require(!votings[_votingIndex].voted[msg.sender]);
require(!isProjectTerminated());
// vote
votings[_votingIndex].voted[msg.sender] = true;
if(_isYes) {
Expand All @@ -267,8 +303,8 @@ contract Daico is Ownable {
Voting memory latestVoting = votings[latestVotingIndex];
// check that latest voting is finished
require(now >= latestVoting.finishAt);
// check that latest voting is of type ReleaseTap or ReleaseTapDecreasedQuorum or TerminateProject
require(latestVoting.votingType == VotingType.ReleaseTap || latestVoting.votingType == VotingType.ReleaseTapDecreasedQuorum || latestVoting.votingType == VotingType.TerminateProject);
// check that latest voting is of type ReleaseTap or ReleaseTapDecreasedQuorum
require(latestVoting.votingType == VotingType.ReleaseTap || latestVoting.votingType == VotingType.ReleaseTapDecreasedQuorum);
// check that latest voting result is quorum not reached
require(getVotingResult(latestVotingIndex) == VotingResult.QuorumNotReached);
// create a new voting
Expand Down
35 changes: 35 additions & 0 deletions contracts/Daico/DaicoTestable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pragma solidity ^0.4.24;

import "zeppelin-solidity/contracts/token/ERC20/MintableToken.sol";

import "./Daico.sol";

contract DaicoTestable is Daico {

constructor(
address _daiTokenAddress,
address _projectTokenAddress,
address _projectOwnerAddress,
uint _tapsCount,
uint[] _tapAmounts,
uint[] _tapTimestampsFinishAt,
uint _minQuorumRate,
uint _minVoteRate,
uint _tokenHoldersCount
) public Daico(
_daiTokenAddress,
_projectTokenAddress,
_projectOwnerAddress,
_tapsCount,
_tapAmounts,
_tapTimestampsFinishAt,
_minQuorumRate,
_minVoteRate,
_tokenHoldersCount
) {}

function createVoting(uint _tapIndex, uint _quorumRate, uint _createdAt, uint _finishAt, VotingType _votingType) external {
_createVoting(_tapIndex, _quorumRate, _createdAt, _finishAt, _votingType);
}

}
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"dotenv": "^6.0.0",
"ganache-cli": "^6.1.4",
"growl": "^1.10.0",
"moment": "^2.22.2",
"solidity-coverage": "^0.5.5",
"truffle": "^4.1.8",
"truffle-hdwallet-provider": "0.0.5",
Expand Down
36 changes: 0 additions & 36 deletions test/Daico.functional.tests.js

This file was deleted.

Loading

0 comments on commit 66d0161

Please sign in to comment.