diff --git a/contracts/DSTContract.sol b/contracts/DSTContract.sol index d9216ad..180d6cc 100644 --- a/contracts/DSTContract.sol +++ b/contracts/DSTContract.sol @@ -7,245 +7,245 @@ pragma solidity ^0.4.2; /* * DSTContract - DST stands for decentralized startup team. * the contract ensures funding for a decentralized - * team in 2 phases: + * team in 2 phases: * - * +. Funding by HKG during the hackathon event. - * +. Funding by Ether after the event is over. + * +. Funding by HKG during the hackathon event. + * +. Funding by Ether after the event is over. * - * After the funds been collected there is a governence + * After the funds been collected there are a governance * mechanism managed by proposition to withdraw funds - * for development usage. + * for development usage. * * The DST ensures that backers of the projects keeps * some influence on the project by ability to reject - * propositions they find as non effective. + * propositions they find as non effective. * - * In very radical occasions the backers may loose - * the trust in the team completelly, in that case + * In very radical occasions the backers may loose + * the trust in the team completely, in that case * there is an option to propose impeachment process - * completelly removing the execute and assigning new - * person to manage the funds. + * completely removing the executive and assigning new + * person to manage the funds. * */ contract DSTContract is StandardToken{ address selfAddress; - address executive; - + address executive; + EventInfo eventInfo; - - // Indicateds where the DST is threaded + + // Indicates where the DST is traded address virtualExchangeAddress; - + HackerGold hackerGold; - + mapping (address => uint256) votingRights; // 1 - HKG => DST qty; tokens for 1 HKG uint hkgPrice; - + // 1 - Ether => DST qty; tokens for 1 Ether uint etherPrice; - - string public name = "..."; - uint8 public decimals = 3; + + string public name = "..."; + uint8 public decimals = 3; string public symbol = "..."; - - bool ableToIssueTokens = true; - + + bool ableToIssueTokens = true; + uint preferedQtySold; - uint collectedHKG; - uint collectedEther; - + uint collectedHKG; + uint collectedEther; + // Proposal of the funds spending mapping (bytes32 => Proposal) proposals; enum ProposalCurrency { HKG, ETHER } ProposalCurrency enumDeclaration; - - + + struct Proposal{ - + bytes32 id; uint value; string urlDetails; uint votindEndTS; - + uint votesObjecting; - + address submitter; bool redeemed; ProposalCurrency proposalCurrency; - + mapping (address => bool) voted; } uint counterProposals; uint timeOfLastProposal; - + Proposal[] listProposals; - + /** * Impeachment process proposals - */ + */ struct ImpeachmentProposal{ - + string urlDetails; - + address newExecutive; - uint votindEndTS; + uint votindEndTS; uint votesSupporting; - - mapping (address => bool) voted; + + mapping (address => bool) voted; } ImpeachmentProposal lastImpeachmentProposal; - + /** - * - * DSTContract: ctor for DST token and governence contract * - * @param eventInfoAddr EventInfo: address of object denotes events - * milestones + * DSTContract: ctor for DST token and governance contract + * + * @param eventInfoAddr EventInfo: address of object denotes events + * milestones * @param hackerGoldAddr HackerGold: address of HackerGold token * * @param dstName string: dstName: real name of the team * - * @param dstSymbol string: 3 letter symbold of the team + * @param dstSymbol string: 3 letter symbol of the team * - */ + */ function DSTContract(EventInfo eventInfoAddr, HackerGold hackerGoldAddr, string dstName, string dstSymbol){ - - selfAddress = this; - executive = msg.sender; + + selfAddress = this; + executive = msg.sender; name = dstName; symbol = dstSymbol; hackerGold = HackerGold(hackerGoldAddr); eventInfo = EventInfo(eventInfoAddr); } - + function() payable { - - // If the hack event is not over return + + // If the hack event is not over return // sent ether. if (now < eventInfo.getEventEnd()) { throw; } - - // there is tokens left from hackathon + + // there is tokens left from hackathon if (etherPrice == 0) throw; - + uint tokens = msg.value / (1 finney) * etherPrice; - - // check if demand of tokens is - // overflow the suply + + // check if demand of tokens is + // overflow the supply if (balances[this] < tokens){ - + tokens = balances[this]; uint retEther = msg.value - tokens / etherPrice * (1 finney); - - // return left ether + + // return left ether if (!msg.sender.send(retEther)) throw; } - - + + // do transfer balances[msg.sender] += tokens; balances[this] -= tokens; - - // count collected ether - collectedEther += msg.value; - + + // count collected ether + collectedEther += msg.value; + // rise event BuyForEtherTransaction(msg.sender, collectedEther, balances[this], etherPrice, tokens); - + } - - + + /** * setHKGPrice - set price: 1HKG => DST tokens qty * * @param qtyForOneHKG uint: DST tokens for 1 HKG - * - */ + * + */ function setHKGPrice(uint qtyForOneHKG) onlyExecutive { - + hkgPrice = qtyForOneHKG; PriceHKGChange(qtyForOneHKG); } - - - + + + /** - * - * issuePreferedTokens - prefered tokens issued on the hackathon event + * + * issuePreferedTokens - preferred tokens issued at the hackathon event * grant special rights * * @param qtyForOneHKG uint: price DST tokens for one 1 HKG - * @param qtyToEmit uint: new supply of tokens - * + * @param qtyToEmit uint: new supply of tokens + * */ - function issuePreferedTokens(uint qtyForOneHKG, - uint qtyToEmit) onlyExecutive + function issuePreferedTokens(uint qtyForOneHKG, + uint qtyToEmit) onlyExecutive onlyIfAbleToIssueTokens onlyBeforeEnd onlyAfterTradingStart { - - // the issuer of the token disabled futer issuance + + // the issuer of the token disabled further issuance if (!ableToIssueTokens) { throw; - } - - // no issuence is allowed before enlisted on the - // exchange + } + + // no issuance is allowed before enlisted on the + // exchange if (virtualExchangeAddress == 0x0) throw; - + totalSupply += qtyToEmit; balances[this] += qtyToEmit; hkgPrice = qtyForOneHKG; - - - // now spender can use balance in - // ammount of value from owner balance + + + // now spender can use balance in + // amount of value from owner balance allowed[this][virtualExchangeAddress] += qtyToEmit; - + // rise event about the transaction Approval(this, virtualExchangeAddress, qtyToEmit); - - // rise event + + // rise event DstTokensIssued(hkgPrice, preferedQtySold, balances[this], qtyToEmit); } - - - + + + /** - * - * buyForHackerGold - on the hack event this function is available - * the buyer for hacker gold will gain votes to + * + * buyForHackerGold - on the hack event this function is available + * the buyer for hacker gold will gain votes to * influence future proposals on the DST - * - * @param hkgValue - qty of this DST tokens for 1 HKG - * + * + * @param hkgValue - qty of this DST tokens for 1 HKG + * */ - function buyForHackerGold(uint hkgValue) onlyBeforeEnd + function buyForHackerGold(uint hkgValue) onlyBeforeEnd returns (bool success) { - - // validate that the caller is official accelerator HKG Exchange + + // validate that the caller is the official accelerator HKG Exchange if (msg.sender != virtualExchangeAddress) throw; - - - // transfer token + + + // transfer token address sender = tx.origin; uint tokensQty = hkgValue * hkgPrice; @@ -255,233 +255,233 @@ contract DSTContract is StandardToken{ collectedHKG += hkgValue; // do actual transfer - transferFrom(this, + transferFrom(this, virtualExchangeAddress, tokensQty); - transfer(sender, tokensQty); - - // rise event + transfer(sender, tokensQty); + + // rise event BuyForHKGTransaction(sender, preferedQtySold, balances[this], hkgPrice, tokensQty); - + return true; } - - + + /** - * - * issueTokens - function will issue tokens after the - * event, able to sell for 1 ether - * + * + * issueTokens - function will issue tokens after the + * event, able to sell for 1 ether + * * @param qtyForOneEther uint: DST tokens for 1 ETH * @param qtyToEmit uint: new tokens supply * */ - function issueTokens(uint qtyForOneEther, - uint qtyToEmit) onlyAfterEnd + function issueTokens(uint qtyForOneEther, + uint qtyToEmit) onlyAfterEnd onlyExecutive { - - // If the user already declared end + + // If the user already declared end // of issuence if (!ableToIssueTokens) { throw; } - + balances[this] += qtyToEmit; etherPrice = qtyForOneEther; totalSupply += qtyToEmit; - - // rise event + + // rise event DstTokensIssued(qtyForOneEther, totalSupply, balances[this], qtyToEmit); } - - + + /** * setEtherPrice - change the token price * * @param qtyForOneEther uint: new price - DST tokens for 1 ETH - */ + */ function setEtherPrice(uint qtyForOneEther) onlyAfterEnd onlyExecutive { - etherPrice = qtyForOneEther; + etherPrice = qtyForOneEther; // rise event for this NewEtherPrice(qtyForOneEther); - } - + } + /** - * disableTokenIssuance - function will disable any - * option for future token + * disableTokenIssuance - function will disable any + * option for future token * issuence */ function disableTokenIssuance() onlyExecutive { ableToIssueTokens = false; - + DisableTokenIssuance(); } - + /** * burnRemainToken - eliminated all available for sale - * tokens. + * tokens. */ function burnRemainToken() onlyExecutive { - + totalSupply -= balances[this]; balances[this] = 0; - + // rise event for this BurnedAllRemainedTokens(); } - + /** - * submitEtherProposal: submit proposal to use part of the + * submitEtherProposal: submit proposal to use part of the * collected ether funds * - * @param requestValue uint: value in wei - * @param url string: details of the proposal - */ - function submitEtherProposal(uint requestValue, string url) onlyAfterEnd - onlyExecutive returns (bytes32 resultId, bool resultSucces) { - - // ensure there is no more issuence available + * @param requestValue uint: value in wei + * @param url string: details of the proposal + */ + function submitEtherProposal(uint requestValue, string url) onlyAfterEnd + onlyExecutive returns (bytes32 resultId, bool resultSucces) { + + // ensure there is no more issuence available if (ableToIssueTokens) throw; - - // ensure there is no more tokens available + + // ensure there is no more tokens available if (balanceOf(this) > 0) throw; - // Possible to submit a proposal once 2 weeks + // Possible to submit a proposal once 2 weeks if (now < (timeOfLastProposal + 2 weeks)) throw; - + uint percent = collectedEther / 100; - + if (requestValue > 20 * percent) throw; // if remained value is less than requested gain all. - if (requestValue > this.balance) - requestValue = this.balance; - + if (requestValue > this.balance) + requestValue = this.balance; + // set id of the proposal // submit proposal to the map bytes32 id = sha3(msg.data, now); - uint timeEnds = now + 10 days; - + uint timeEnds = now + 10 days; + Proposal memory newProposal = Proposal(id, requestValue, url, timeEnds, 0, msg.sender, false, ProposalCurrency.ETHER); proposals[id] = newProposal; listProposals.push(newProposal); - - timeOfLastProposal = now; + + timeOfLastProposal = now; ProposalRequestSubmitted(id, requestValue, timeEnds, url, msg.sender); - + return (id, true); } - - - + + + /** - * - * submitHKGProposal - submit proposal to request for - * partial HKG funds collected - * - * @param requestValue uint: value in HKG to request. - * @param url string: url with details on the proposition + * + * submitHKGProposal - submit proposal to request for + * partial HKG funds collected + * + * @param requestValue uint: value in HKG to request. + * @param url string: url with details on the proposition */ function submitHKGProposal(uint requestValue, string url) onlyAfterEnd onlyExecutive returns (bytes32 resultId, bool resultSucces){ - + // If there is no 2 months over since the last event. // There is no posible to get any HKG. After 2 months - // all the HKG is available. + // all the HKG is available. if (now < (eventInfo.getEventEnd() + 8 weeks)) { throw; } - // Possible to submit a proposal once 2 weeks + // Possible to submit a proposal once 2 weeks if (now < (timeOfLastProposal + 2 weeks)) throw; uint percent = preferedQtySold / 100; - + // validate the ammount is legit - // first 5 proposals should be less than 20% - if (counterProposals <= 5 && + // first 5 proposals should be less than 20% + if (counterProposals <= 5 && requestValue > 20 * percent) throw; - - // if remained value is less than requested + + // if remained value is less than requested // gain all. - if (requestValue > getHKGOwned()) + if (requestValue > getHKGOwned()) requestValue = getHKGOwned(); - - + + // set id of the proposal // submit proposal to the map bytes32 id = sha3(msg.data, now); - uint timeEnds = now + 10 days; - + uint timeEnds = now + 10 days; + Proposal memory newProposal = Proposal(id, requestValue, url, timeEnds, 0, msg.sender, false, ProposalCurrency.HKG); proposals[id] = newProposal; listProposals.push(newProposal); - + ++counterProposals; - timeOfLastProposal = now; - + timeOfLastProposal = now; + ProposalRequestSubmitted(id, requestValue, timeEnds, url, msg.sender); - - return (id, true); - } - - - + + return (id, true); + } + + + /** - * objectProposal - object previously submitted proposal, - * the objection right is obtained by - * purchasing prefered tokens on time of + * objectProposal - object previously submitted proposal, + * the objection right is obtained by + * purchasing preferred tokens on time of * the hackathon. - * - * @param id bytes32 : the id of the proposla to redeem + * + * @param id bytes32 : the id of the proposal to redeem */ function objectProposal(bytes32 id){ - + Proposal memory proposal = proposals[id]; - - // check proposal exist + + // check proposal exist if (proposals[id].id == 0) throw; // check already redeemed if (proposals[id].redeemed) throw; - + // ensure objection time if (now >= proposals[id].votindEndTS) throw; - - // ensure not voted + + // ensure not voted if (proposals[id].voted[msg.sender]) throw; - + // submit votes uint votes = votingRights[msg.sender]; proposals[id].votesObjecting += votes; - - // mark voted - proposals[id].voted[msg.sender] = true; - + + // mark voted + proposals[id].voted[msg.sender] = true; + uint idx = getIndexByProposalId(id); - listProposals[idx] = proposals[id]; + listProposals[idx] = proposals[id]; - ObjectedVote(id, msg.sender, votes); + ObjectedVote(id, msg.sender, votes); } - - + + function getIndexByProposalId(bytes32 id) returns (uint result){ - + for (uint i = 0; i < listProposals.length; ++i){ if (id == listProposals[i].id) return i; } } - - - + + + /** - * redeemProposalFunds - redeem funds requested by prior - * submitted proposal - * + * redeemProposalFunds - redeem funds requested by prior + * submitted proposal + * * @param id bytes32: the id of the proposal to redeem */ function redeemProposalFunds(bytes32 id) onlyExecutive { @@ -491,150 +491,150 @@ contract DSTContract is StandardToken{ // ensure objection time if (now < proposals[id].votindEndTS) throw; - - + + // check already redeemed if (proposals[id].redeemed) throw; // check votes objection => 55% of total votes uint objectionThreshold = preferedQtySold / 100 * 55; if (proposals[id].votesObjecting > objectionThreshold) throw; - - + + if (proposals[id].proposalCurrency == ProposalCurrency.HKG){ - - // send hacker gold - hackerGold.transfer(proposals[id].submitter, proposals[id].value); - + + // send hacker gold + hackerGold.transfer(proposals[id].submitter, proposals[id].value); + } else { - - // send ether - bool success = proposals[id].submitter.send(proposals[id].value); + + // send ether + bool success = proposals[id].submitter.send(proposals[id].value); // rise event - EtherRedeemAccepted(proposals[id].submitter, proposals[id].value); + EtherRedeemAccepted(proposals[id].submitter, proposals[id].value); } - - // execute the proposal - proposals[id].redeemed = true; + + // execute the proposal + proposals[id].redeemed = true; } - - + + /** - * getAllTheFunds - to ensure there is no deadlock can - * can happen, and no case that voting + * getAllTheFunds - to ensure there is no deadlock can + * can happen, and no case that voting * structure will freeze the funds forever * the startup will be able to get all the * funds without a proposal required after * 6 months. - * - * - */ + * + * + */ function getAllTheFunds() onlyExecutive { - + // If there is a deadlock in voting participates // the funds can be redeemed completelly in 6 months if (now < (eventInfo.getEventEnd() + 24 weeks)) { throw; - } - + } + // all the Ether - bool success = msg.sender.send(this.balance); - + bool success = msg.sender.send(this.balance); + // all the HKG - hackerGold.transfer(msg.sender, getHKGOwned()); + hackerGold.transfer(msg.sender, getHKGOwned()); } - - + + /** - * submitImpeachmentProposal - submit request to switch + * submitImpeachmentProposal - submit request to switch * executive. - * - * @param urlDetails - details of the impeachment proposal - * @param newExecutive - address of the new executive - * - */ + * + * @param urlDetails - details of the impeachment proposal + * @param newExecutive - address of the new executive + * + */ function submitImpeachmentProposal(string urlDetails, address newExecutive){ - - // to offer impeachment you should have + + // to offer impeachment you should have // voting rights if (votingRights[msg.sender] == 0) throw; - - // the submission of the first impeachment + + // the submission of the first impeachment // proposal is possible only after 3 months // since the hackathon is over if (now < (eventInfo.getEventEnd() + 12 weeks)) throw; - - + + // check there is 1 months over since last one - if (lastImpeachmentProposal.votindEndTS != 0 && + if (lastImpeachmentProposal.votindEndTS != 0 && lastImpeachmentProposal.votindEndTS + 2 weeks > now) throw; // submit impeachment proposal - // add the votes of the submitter + // add the votes of the submitter // to the proposal right away lastImpeachmentProposal = ImpeachmentProposal(urlDetails, newExecutive, now + 2 weeks, votingRights[msg.sender]); lastImpeachmentProposal.voted[msg.sender] = true; - + // rise event ImpeachmentProposed(msg.sender, urlDetails, now + 2 weeks, newExecutive); } - - + + /** - * supportImpeachment - vote for impeachment proposal + * supportImpeachment - vote for impeachment proposal * that is currently in progress * */ function supportImpeachment(){ - // ensure that support is for exist proposal + // ensure that support is for exist proposal if (lastImpeachmentProposal.newExecutive == 0x0) throw; - - // to offer impeachment you should have + + // to offer impeachment you should have // voting rights if (votingRights[msg.sender] == 0) throw; - - // check if not voted already + + // check if not voted already if (lastImpeachmentProposal.voted[msg.sender]) throw; - - // check if not finished the 2 weeks of voting + + // check if not finished the 2 weeks of voting if (lastImpeachmentProposal.votindEndTS + 2 weeks <= now) throw; - + // support the impeachment lastImpeachmentProposal.voted[msg.sender] = true; lastImpeachmentProposal.votesSupporting += votingRights[msg.sender]; // rise impeachment suppporting event ImpeachmentSupport(msg.sender, votingRights[msg.sender]); - - // if the vote is over 70% execute the switch - uint percent = preferedQtySold / 100; - + + // if the vote is over 70% execute the switch + uint percent = preferedQtySold / 100; + if (lastImpeachmentProposal.votesSupporting >= 70 * percent){ executive = lastImpeachmentProposal.newExecutive; - + // impeachment event ImpeachmentAccepted(executive); } - - } - - - + + } + + + // **************************** // // * Constant Getters * // // **************************** // - + function votingRightsOf(address _owner) constant returns (uint256 result) { result = votingRights[_owner]; } - + function getPreferedQtySold() constant returns (uint result){ return preferedQtySold; } - + function setVirtualExchange(address virtualExchangeAddr){ virtualExchangeAddress = virtualExchangeAddr; } @@ -642,15 +642,15 @@ contract DSTContract is StandardToken{ function getHKGOwned() constant returns (uint result){ return hackerGold.balanceOf(this); } - + function getEtherValue() constant returns (uint result){ return this.balance; } - + function getExecutive() constant returns (address result){ return executive; } - + function getHKGPrice() constant returns (uint result){ return hkgPrice; } @@ -658,42 +658,42 @@ contract DSTContract is StandardToken{ function getEtherPrice() constant returns (uint result){ return etherPrice; } - + function getDSTName() constant returns(string result){ return name; - } - + } + function getDSTNameBytes() constant returns(bytes32 result){ return convert(name); - } + } function getDSTSymbol() constant returns(string result){ return symbol; - } - + } + function getDSTSymbolBytes() constant returns(bytes32 result){ return convert(symbol); - } + } function getAddress() constant returns (address result) { return selfAddress; } - + function getTotalSupply() constant returns (uint result) { return totalSupply; - } - - function getCollectedEther() constant returns (uint results) { + } + + function getCollectedEther() constant returns (uint results) { return collectedEther; } - + function getCounterProposals() constant returns (uint result){ return counterProposals; } - + function getProposalIdByIndex(uint i) constant returns (bytes32 result){ return listProposals[i].id; - } + } function getProposalObjectionByIndex(uint i) constant returns (uint result){ return listProposals[i].votesObjecting; @@ -701,71 +701,68 @@ contract DSTContract is StandardToken{ function getProposalValueByIndex(uint i) constant returns (uint result){ return listProposals[i].value; - } - + } + function getCurrentImpeachmentUrlDetails() constant returns (string result){ return lastImpeachmentProposal.urlDetails; } - - + + function getCurrentImpeachmentVotesSupporting() constant returns (uint result){ return lastImpeachmentProposal.votesSupporting; } - + function convert(string key) returns (bytes32 ret) { if (bytes(key).length > 32) { throw; - } + } assembly { ret := mload(add(key, 32)) } - } - - - + } + + + // ********************* // // * Modifiers * // - // ********************* // - + // ********************* // + modifier onlyBeforeEnd() { if (now >= eventInfo.getEventEnd()) throw; _; } modifier onlyAfterEnd() { if (now < eventInfo.getEventEnd()) throw; _; } - + modifier onlyAfterTradingStart() { if (now < eventInfo.getTradingStart()) throw; _; } - + modifier onlyExecutive() { if (msg.sender != executive) throw; _; } - - modifier onlyIfAbleToIssueTokens() { if (!ableToIssueTokens) throw; _; } - + + modifier onlyIfAbleToIssueTokens() { if (!ableToIssueTokens) throw; _; } + // ****************** // // * Events * // - // ****************** // + // ****************** // + - event PriceHKGChange(uint qtyForOneHKG); event BuyForHKGTransaction(address indexed buyer, uint indexed tokensSold, uint indexed totalSupply, uint qtyForOneHKG, uint tokensAmount); event BuyForEtherTransaction(address indexed buyer, uint indexed tokensSold, uint indexed totalSupply, uint qtyForOneEther, uint tokensAmount); event DstTokensIssued(uint indexed qtyForOneHKG, uint indexed tokensSold, uint indexed totalSupply, uint qtyToEmit); - + event ProposalRequestSubmitted(bytes32 id, uint value, uint timeEnds, string url, address sender); - + event EtherRedeemAccepted(address sender, uint value); - + event ObjectedVote(bytes32 id, address voter, uint votes); - + event ImpeachmentProposed(address submitter, string urlDetails, uint votindEndTS, address newExecutive); event ImpeachmentSupport(address supportter, uint votes); - + event ImpeachmentAccepted(address newExecutive); event NewEtherPrice(uint newQtyForOneEther); event DisableTokenIssuance(); - - event BurnedAllRemainedTokens(); - -} + event BurnedAllRemainedTokens(); - +} diff --git a/contracts/EventInfo.sol b/contracts/EventInfo.sol index 3fa055b..62c7695 100644 --- a/contracts/EventInfo.sol +++ b/contracts/EventInfo.sol @@ -2,49 +2,49 @@ pragma solidity ^0.4.0; /** - * - * EventInfo - imutable class that denotes + * + * EventInfo - immutable class that denotes * the time of the virtual accelerator hack * event - * + * */ contract EventInfo{ - - + + uint constant HACKATHON_5_WEEKS = 60 * 60 * 24 * 7 * 5; uint constant T_1_WEEK = 60 * 60 * 24 * 7; uint eventStart = 1479391200; // Thu, 17 Nov 2016 14:00:00 GMT uint eventEnd = eventStart + HACKATHON_5_WEEKS; - - + + /** * getEventStart - return the start of the event time - */ - function getEventStart() constant returns (uint result){ + */ + function getEventStart() constant returns (uint result){ return eventStart; - } - + } + /** * getEventEnd - return the end of the event time - */ - function getEventEnd() constant returns (uint result){ + */ + function getEventEnd() constant returns (uint result){ return eventEnd; - } - - + } + + /** - * getVotingStart - the voting starts 1 week after the + * getVotingStart - the voting starts 1 week after the * event starts - */ + */ function getVotingStart() constant returns (uint result){ return eventStart+ T_1_WEEK; } /** - * getTradingStart - the DST tokens trading starts 1 week + * getTradingStart - the DST tokens trading starts 1 week * after the event starts - */ + */ function getTradingStart() constant returns (uint result){ return eventStart+ T_1_WEEK; } @@ -52,8 +52,8 @@ contract EventInfo{ /** * getNow - helper class to check what time the contract see */ - function getNow() constant returns (uint result){ + function getNow() constant returns (uint result){ return now; - } - + } + } diff --git a/contracts/HackerGold.sol b/contracts/HackerGold.sol index 48c2dda..5374ae8 100644 --- a/contracts/HackerGold.sol +++ b/contracts/HackerGold.sol @@ -6,7 +6,7 @@ pragma solidity ^0.4.0; /** * * @title Hacker Gold - * + * * The official token powering the hack.ether.camp virtual accelerator. * This is the only way to acquire tokens from startups during the event. * @@ -15,14 +15,14 @@ pragma solidity ^0.4.0; */ contract HackerGold is StandardToken { - // Name of the token + // Name of the token string public name = "HackerGold"; // Decimal places uint8 public decimals = 3; - // Token abbreviation + // Token abbreviation string public symbol = "HKG"; - + // 1 ether = 200 hkg uint BASE_PRICE = 200; // 1 ether = 150 hkg @@ -33,17 +33,17 @@ contract HackerGold is StandardToken { uint SAFETY_LIMIT = 4000000 ether; // Zeros after the point uint DECIMAL_ZEROS = 1000; - + // Total value in wei uint totalValue; - + // Address of multisig wallet holding ether from sale address wallet; // Structure of sale increase milestones struct milestones_struct { uint p1; - uint p2; + uint p2; uint p3; uint p4; uint p5; @@ -51,135 +51,135 @@ contract HackerGold is StandardToken { } // Milestones instance milestones_struct milestones; - + /** * Constructor of the contract. - * + * * Passes address of the account holding the value. * HackerGold contract itself does not hold any value - * + * * @param multisig address of MultiSig wallet which will hold the value */ function HackerGold(address multisig) { - + wallet = multisig; // set time periods for sale milestones = milestones_struct( - + 1476972000, // P1: GMT: 20-Oct-2016 14:00 => The Sale Starts - 1478181600, // P2: GMT: 03-Nov-2016 14:00 => 1st Price Ladder - 1479391200, // P3: GMT: 17-Nov-2016 14:00 => Price Stable, + 1478181600, // P2: GMT: 03-Nov-2016 14:00 => 1st Price Ladder + 1479391200, // P3: GMT: 17-Nov-2016 14:00 => Price Stable, // Hackathon Starts 1480600800, // P4: GMT: 01-Dec-2016 14:00 => 2nd Price Ladder 1481810400, // P5: GMT: 15-Dec-2016 14:00 => Price Stable 1482415200 // P6: GMT: 22-Dec-2016 14:00 => Sale Ends, Hackathon Ends ); - + } - - + + /** * Fallback function: called on ether sent. - * - * It calls to createHKG function with msg.sender + * + * It calls to createHKG function with msg.sender * as a value for holder argument */ function () payable { createHKG(msg.sender); } - + /** * Creates HKG tokens. - * + * * Runs sanity checks including safety cap * Then calculates current price by getPrice() function, creates HKG tokens * Finally sends a value of transaction to the wallet - * + * * Note: due to lack of floating point types in Solidity, * contract assumes that last 3 digits in tokens amount are stood after the point. * It means that if stored HKG balance is 100000, then its real value is 100 HKG - * + * * @param holder token holder */ function createHKG(address holder) payable { - + if (now < milestones.p1) throw; if (now >= milestones.p6) throw; if (msg.value == 0) throw; - + // safety cap - if (getTotalValue() + msg.value > SAFETY_LIMIT) throw; - + if (getTotalValue() + msg.value > SAFETY_LIMIT) throw; + uint tokens = msg.value * getPrice() * DECIMAL_ZEROS / 1 ether; totalSupply += tokens; balances[holder] += tokens; totalValue += msg.value; - + if (!wallet.send(msg.value)) throw; } - + /** * Denotes complete price structure during the sale. * * @return HKG amount per 1 ETH for the current moment in time */ function getPrice() constant returns (uint result) { - + if (now < milestones.p1) return 0; - + if (now >= milestones.p1 && now < milestones.p2) { - + return BASE_PRICE; } - + if (now >= milestones.p2 && now < milestones.p3) { - - uint days_in = 1 + (now - milestones.p2) / 1 days; + + uint days_in = 1 + (now - milestones.p2) / 1 days; return BASE_PRICE - days_in * 25 / 7; // daily decrease 3.5 } if (now >= milestones.p3 && now < milestones.p4) { - + return MID_PRICE; } - + if (now >= milestones.p4 && now < milestones.p5) { - - days_in = 1 + (now - milestones.p4) / 1 days; + + days_in = 1 + (now - milestones.p4) / 1 days; return MID_PRICE - days_in * 25 / 7; // daily decrease 3.5 } if (now >= milestones.p5 && now < milestones.p6) { - + return FIN_PRICE; } - + if (now >= milestones.p6){ return 0; } } - + /** * Returns total stored HKG amount. - * + * * Contract assumes that last 3 digits of this value are behind the decimal place. i.e. 10001 is 10.001 * Thus, result of this function should be divided by 1000 to get HKG value - * + * * @return result stored HKG amount */ function getTotalSupply() constant returns (uint result) { return totalSupply; - } + } /** * It is used for test purposes. - * + * * Returns the result of 'now' statement of Solidity language - * + * * @return unix timestamp for current moment in time */ function getNow() constant returns (uint result) { @@ -188,10 +188,10 @@ contract HackerGold is StandardToken { /** * Returns total value passed through the contract - * + * * @return result total value in wei */ function getTotalValue() constant returns (uint result) { - return totalValue; + return totalValue; } } diff --git a/contracts/ProjectKudos.sol b/contracts/ProjectKudos.sol index 1a60115..fca0128 100644 --- a/contracts/ProjectKudos.sol +++ b/contracts/ProjectKudos.sol @@ -2,24 +2,24 @@ pragma solidity ^0.4.0; /** * @title Project Kudos - * + * * Events voting system of the Virtual Accelerator. * Includes the voting for both judges and fans. - * + * */ contract ProjectKudos { - + // votes limit for judge uint KUDOS_LIMIT_JUDGE = 1000; // votes limit for regular user uint KUDOS_LIMIT_USER = 10; - // enumerates reasons + // enumerates reasons // which additional votes can be granted for enum GrantReason { Facebook, - Twitter, + Twitter, Fake } @@ -37,36 +37,36 @@ contract ProjectKudos { mapping(uint => bool) grant; } - // keeps links between user's votes + // keeps links between user's votes // and projects he voted for struct UserIndex { bytes32[] projects; uint[] kudos; mapping(bytes32 => uint) kudosIdx; } - - // keeps time frames for vote period + + // keeps time frames for vote period struct VotePeriod { uint start; uint end; } - + // contract creator's address address owner; - + // vote period VotePeriod votePeriod; // user votes mapping mapping(address => UserInfo) users; - // user index, + // user index, // helps to get votes given by one user for every project mapping(address => UserIndex) usersIndex; // project votes mapping mapping(bytes32 => ProjectInfo) projects; - + // emitted when vote is done event Vote( // address of voter @@ -76,15 +76,15 @@ contract ProjectKudos { // votes given uint indexed count ); - + /** * @dev Contract's constructor. * Stores contract's owner and sets up vote period */ function ProjectKudos() { - + owner = msg.sender; - + votePeriod = VotePeriod( 1479996000, // GMT: 24-Nov-2016 14:00, Voting starts, 1st week passed 1482415200 // GMT: 22-Dec-2016 14:00, Voting ends, Hackathon ends @@ -95,25 +95,25 @@ contract ProjectKudos { * @dev Registers voter to the event. * Executable only by contract's owner. * - * @param userAddres address of the user to register + * @param userAddress address of the user to register * @param isJudge should be true if user is judge, false otherwise */ - function register(address userAddres, bool isJudge) onlyOwner { - - UserInfo user = users[userAddres]; + function register(address userAddress, bool isJudge) onlyOwner { + + UserInfo user = users[userAddress]; if (user.kudosLimit > 0) throw; if (isJudge) user.kudosLimit = KUDOS_LIMIT_JUDGE; - else + else user.kudosLimit = KUDOS_LIMIT_USER; - + user.isJudge = isJudge; - - users[userAddres] = user; + + users[userAddress] = user; } - + /** * @dev Gives votes to the project. * Can only be executed within vote period. @@ -123,11 +123,11 @@ contract ProjectKudos { * @param kudos - votes to be given */ function giveKudos(string projectCode, uint kudos) duringVote { - + UserInfo giver = users[msg.sender]; if (giver.kudosGiven + kudos > giver.kudosLimit) throw; - + bytes32 code = strToBytes(projectCode); ProjectInfo project = projects[code]; @@ -137,53 +137,54 @@ contract ProjectKudos { // save index of user voting history updateUsersIndex(code, project.kudosByUser[msg.sender]); - + Vote(msg.sender, sha3(projectCode), kudos); } /** * @dev Grants extra kudos for identity proof. * - * @param userToGrant address of user to grant additional + * @param userToGrant address of user to grant additional * votes for social proof - * - * @param reason granting reason, + * + * @param reason granting reason, * possible reasons are listed in GrantReason enum - */ + */ function grantKudos(address userToGrant, uint reason) onlyOwner { - + UserInfo user = users[userToGrant]; - + if (user.kudosLimit == 0) throw; //probably user does not exist then + GrantReason grantReason = grantUintToReason(reason); - + if (grantReason != GrantReason.Facebook && grantReason != GrantReason.Twitter) throw; - + // if user is judge his identity is known - // not reasonble to grant more kudos for social + // not reasonble to grant more kudos for social // proof. if (user.isJudge) throw; - + // if not granted for that reason yet if (user.grant[reason]) throw; - + // grant 100 votes user.kudosLimit += 100; - - // mark reason + + // mark reason user.grant[reason] = true; } - - + + // ********************* // // * Constant Calls * // // ********************* // - + /** * @dev Returns total votes given to the project - * + * * @param projectCode project's code - * + * * @return number of give votes */ function getProjectKudos(string projectCode) constant returns(uint) { @@ -195,10 +196,10 @@ contract ProjectKudos { /** * @dev Returns an array of votes given to the project * corresponding to array of users passed in function call - * + * * @param projectCode project's code * @param users array of user addresses - * + * * @return array of votes given by passed users */ function getProjectKudosByUsers(string projectCode, address[] users) constant returns(uint[]) { @@ -207,19 +208,19 @@ contract ProjectKudos { mapping(address => uint) kudosByUser = project.kudosByUser; uint[] memory userKudos = new uint[](users.length); for (uint i = 0; i < users.length; i++) { - userKudos[i] = kudosByUser[users[i]]; + userKudos[i] = kudosByUser[users[i]]; } - + return userKudos; } /** - * @dev Returns votes given by speicified user + * @dev Returns votes given by specified user * to the list of projects ever voted by that user - * + * * @param giver user's address * @return projects array of project codes represented by bytes32 array - * @return kudos array of votes given by user, + * @return kudos array of votes given by user, * index of vote corresponds to index of project from projects array */ function getKudosPerProject(address giver) constant returns (bytes32[] projects, uint[] kudos) { @@ -230,7 +231,7 @@ contract ProjectKudos { /** * @dev Returns votes allowed to be given by user - * + * * @param addr user's address * @return number of votes left */ @@ -241,7 +242,7 @@ contract ProjectKudos { /** * @dev Returns votes given by user - * + * * @param addr user's address * @return number of votes given */ @@ -250,22 +251,22 @@ contract ProjectKudos { return user.kudosGiven; } - + // ********************* // // * Private Calls * // // ********************* // - + /** * @dev Private function. Updates users index - * + * * @param code project code represented by bytes32 array * @param kudos votes total given to the project by sender */ function updateUsersIndex(bytes32 code, uint kudos) private { - + UserIndex idx = usersIndex[msg.sender]; uint i = idx.kudosIdx[code]; - + // add new entry to index if (i == 0) { i = idx.projects.length + 1; @@ -277,10 +278,10 @@ contract ProjectKudos { idx.kudos[i - 1] = kudos; } - + /** * @dev Translates GrantReason code to GrantReason - * + * * @param reason the code of the reason * @return GrantReason corresponding to the code */ @@ -289,10 +290,10 @@ contract ProjectKudos { if (reason == 1) return GrantReason.Twitter; return GrantReason.Fake; } - + /** * @dev Translates GrantReason to its code - * + * * @param reason GrantReason instance * @return corresponding reason code */ @@ -301,29 +302,29 @@ contract ProjectKudos { if (reason == GrantReason.Twitter) return 1; return 3; } - + /** * @dev Low level function. * Converts string to bytes32 array. * Throws if string length is more than 32 bytes - * + * * @param str string * @return bytes32 representation of str */ function strToBytes(string str) private returns (bytes32 ret) { - + if (bytes(str).length > 32) throw; - + assembly { ret := mload(add(str, 32)) } - } + } + - // ********************* // // * Modifiers * // // ********************* // - + /** * @dev Throws if called not during the vote period */ @@ -332,11 +333,11 @@ contract ProjectKudos { if (now >= votePeriod.end) throw; _; } - + /** * @dev Throws if called not by contract's owner */ - modifier onlyOwner() { + modifier onlyOwner() { if (msg.sender != owner) throw; _; } diff --git a/contracts/StandardToken.sol b/contracts/StandardToken.sol index 794f47e..df096a3 100644 --- a/contracts/StandardToken.sol +++ b/contracts/StandardToken.sol @@ -4,11 +4,11 @@ import "TokenInterface.sol"; pragma solidity ^0.4.2; /* - * StandardToken - is a smart contract - * for managing common functionality of + * StandardToken - is a smart contract + * for managing common functionality of * a token. * - * ERC.20 Token standard: + * ERC.20 Token standard: * https://github.com/eth ereum/EIPs/issues/20 */ contract StandardToken is TokenInterface { @@ -19,127 +19,127 @@ contract StandardToken is TokenInterface { // spending permision management mapping (address => mapping (address => uint256)) allowed; - - - + + + function StandardToken(){ } - - + + /** - * transfer() - transfer tokens from msg.sender balance + * transfer() - transfer tokens from msg.sender balance * to requested account * * @param to - target address to transfer tokens * @param value - ammount of tokens to transfer * * @return - success / failure of the transaction - */ + */ function transfer(address to, uint256 value) returns (bool success) { - - + + if (balances[msg.sender] >= value && value > 0) { - // do actual tokens transfer + // do actual tokens transfer balances[msg.sender] -= value; balances[to] += value; - + // rise the Transfer event Transfer(msg.sender, to, value); return true; } else { - - return false; + + return false; } } - - - + + + /** - * transferFrom() - + * transferFrom() - * - * @param from - - * @param to - - * @param value - + * @param from - + * @param to - + * @param value - * - * @return + * @return - */ function transferFrom(address from, address to, uint256 value) returns (bool success) { - - if ( balances[from] >= value && - allowed[from][msg.sender] >= value && + + if ( balances[from] >= value && + allowed[from][msg.sender] >= value && value > 0) { - - + + // do the actual transfer - balances[from] -= value; - balances[to] =+ value; - + balances[from] -= value; + balances[to] =+ value; + - // addjust the permision, after part of + // addjust the permision, after part of // permited to spend value was used allowed[from][msg.sender] -= value; - + // rise the Transfer event Transfer(from, to, value); return true; - } else { - - return false; + } else { + + return false; } } - - + + /** * - * balanceOf() - constant function check concrete tokens balance + * balanceOf() - constant function check concrete tokens balance * * @param owner - account owner - * - * @return the value of balance - */ + * + * @return the value of balance + */ function balanceOf(address owner) constant returns (uint256 balance) { return balances[owner]; } - - + + /** * - * approve() - function approves to a person to spend some tokens from - * owner balance. + * approve() - function approves to a person to spend some tokens from + * owner balance. * * @param spender - person whom this right been granted. * @param value - value to spend. - * - * @return true in case of succes, otherwise failure - * + * + * @return true in case of success, otherwise failure + * */ function approve(address spender, uint256 value) returns (bool success) { - - // now spender can use balance in + + // now spender can use balance in // ammount of value from owner balance allowed[msg.sender][spender] = value; - + // rise event about the transaction Approval(msg.sender, spender, value); - + return true; } /** * - * allowance() - constant function to check how mouch is - * permited to spend to 3rd person from owner balance + * allowance() - constant function to check how much is + * permitted to spend to 3rd person from owner balance * * @param owner - owner of the balance - * @param spender - permited to spend from this balance person - * - * @return - remaining right to spend - * + * @param spender - permitted to spend from this balance person + * + * @return - remaining right to spend + * */ function allowance(address owner, address spender) constant returns (uint256 remaining) { return allowed[owner][spender]; diff --git a/contracts/TokenInterface.sol b/contracts/TokenInterface.sol index 4c7cb82..fdad7af 100644 --- a/contracts/TokenInterface.sol +++ b/contracts/TokenInterface.sol @@ -2,56 +2,56 @@ pragma solidity ^0.4.0; /* - * Token - is a smart contract interface - * for managing common functionality of + * Token - is a smart contract interface + * for managing common functionality of * a token. * * ERC.20 Token standard: https://github.com/eth ereum/EIPs/issues/20 */ contract TokenInterface { - + // total amount of tokens uint totalSupply; - + /** * - * balanceOf() - constant function check concrete tokens balance + * balanceOf() - constant function check concrete tokens balance * * @param owner - account owner - * - * @return the value of balance - */ + * + * @return the value of balance + */ function balanceOf(address owner) constant returns (uint256 balance); - + function transfer(address to, uint256 value) returns (bool success); function transferFrom(address from, address to, uint256 value) returns (bool success); /** * - * approve() - function approves to a person to spend some tokens from - * owner balance. + * approve() - function approves to a person to spend some tokens from + * owner balance. * * @param spender - person whom this right been granted. * @param value - value to spend. - * + * * @return true in case of succes, otherwise failure - * + * */ function approve(address spender, uint256 value) returns (bool success); /** * - * allowance() - constant function to check how much is + * allowance() - constant function to check how much is * permitted to spend to 3rd person from owner balance * * @param owner - owner of the balance - * @param spender - permitted to spend from this balance person - * - * @return - remaining right to spend - * + * @param spender - permitted to spend from this balance person + * + * @return - remaining right to spend + * */ function allowance(address owner, address spender) constant returns (uint256 remaining); diff --git a/contracts/VirtualExchange.sol b/contracts/VirtualExchange.sol index 9866004..66a6d68 100644 --- a/contracts/VirtualExchange.sol +++ b/contracts/VirtualExchange.sol @@ -7,35 +7,35 @@ pragma solidity ^0.4.2; /** * VirtualExchange - The exchange is a trading system used - * on hack.ether.camp hackathon event to - * support trading a DST tokens for HKG. - * + * on hack.ether.camp hackathon event to + * support trading a DST tokens for HKG. + * */ contract VirtualExchange{ - address owner; + address owner; EventInfo eventInfo; - + mapping (bytes32 => address) dstListed; - + HackerGold hackerGold; - + function VirtualExchange(address hackerGoldAddr, address eventInfoAddr){ - + owner = msg.sender; hackerGold = HackerGold(hackerGoldAddr); eventInfo = EventInfo(eventInfoAddr); } - - + + /** - * enlist - enlisting one decentralized startup team to - * the hack event virtual exchange, making the + * enlist - enlisting one decentralized startup team to + * the hack event virtual exchange, making the * DST initated tokens available for aquasition. - * - * @param dstAddress - address of the DSTContract - * - */ + * + * @param dstAddress - address of the DSTContract + * + */ function enlist(address dstAddress) onlyBeforeEnd { DSTContract dstContract = DSTContract(dstAddress); @@ -43,106 +43,106 @@ contract VirtualExchange{ /* Don't enlist 2 with the same name */ if (isExistByBytes(dstContract.getDSTSymbolBytes())) throw; - // Only owner of the DST can deploy the DST + // Only owner of the DST can deploy the DST if (dstContract.getExecutive() != msg.sender) throw; // All good enlist the company bytes32 nameBytes = dstContract.getDSTSymbolBytes(); dstListed[nameBytes] = dstAddress; - + // Indicate to DST which Virtual Exchange is enlisted dstContract.setVirtualExchange(address(this)); - + // rise Enlisted event Enlisted(dstAddress); } - - + + /** * - * buy - on the hackathon timeframe that is the function - * that will be the way to buy speciphic tokens for + * buy - on the hackathon timeframe that is the function + * that will be the way to buy speciphic tokens for * startup. - * - * @param companyName - the company that is enlisted on the exchange + * + * @param companyName - the company that is enlisted on the exchange * and the tokens are available - * - * @param hkg - the ammount of hkg to spend for aquastion + * + * @param hkg - the ammount of hkg to spend for aquastion * */ function buy(string companyName, uint hkg) onlyBeforeEnd returns (bool success) { - + bytes32 companyNameBytes = convert(companyName); - // check DST exist + // check DST exist if (!isExistByString(companyName)) throw; - // validate availability + // validate availability DSTContract dstContract = DSTContract(dstListed[companyNameBytes]); uint tokensQty = hkg * dstContract.getHKGPrice(); - address veAddress = address(this); - + address veAddress = address(this); + // ensure that there is HKG balance - uint valueHKGOwned = hackerGold.balanceOf(msg.sender); - if (valueHKGOwned < hkg) throw; - + uint valueHKGOwned = hackerGold.balanceOf(msg.sender); + if (valueHKGOwned < hkg) throw; + // ensure that there is HKG token allowed to be spend uint valueAvailbeOnExchange = hackerGold.allowance(msg.sender, veAddress); if (valueAvailbeOnExchange < hkg) throw; // ensure there is DST tokens for sale uint dstTokens = dstContract.allowance(dstContract, veAddress); - if (dstTokens < hkg * dstContract.getHKGPrice()) throw; - - // Transfer HKG to Virtual Exchange account + if (dstTokens < hkg * dstContract.getHKGPrice()) throw; + + // Transfer HKG to Virtual Exchange account hackerGold.transferFrom(msg.sender, veAddress, hkg); // Transfer to dstCotract ownership - hackerGold.transfer(dstContract.getAddress(), hkg); - - // Call DST to transfer tokens - dstContract.buyForHackerGold(hkg); + hackerGold.transfer(dstContract.getAddress(), hkg); + + // Call DST to transfer tokens + dstContract.buyForHackerGold(hkg); } - - + + function convert(string key) returns (bytes32 ret) { if (bytes(key).length > 32) { throw; - } + } assembly { ret := mload(add(key, 32)) } - } - + } + // **************************** // // * Constant Getters * // - // **************************** // - + // **************************** // + function isExistByBytes(bytes32 companyNameBytes) constant returns (bool result) { - - if (dstListed[companyNameBytes] == 0x0) + + if (dstListed[companyNameBytes] == 0x0) return false; - else - return true; + else + return true; } function isExistByString(string companyName) constant returns (bool result) { - + bytes32 companyNameBytes = convert(companyName); - - if (dstListed[companyNameBytes] == 0x0) + + if (dstListed[companyNameBytes] == 0x0) return false; - else - return true; + else + return true; } - + function getEventStart() constant eventInfoSet returns (uint result){ return eventInfo.getEventStart(); } @@ -150,30 +150,30 @@ contract VirtualExchange{ function getEventEnd() constant eventInfoSet returns (uint result){ return eventInfo.getEventEnd(); } - + function getNow() constant returns (uint result){ return now; } - + // ********************* // // * Modifiers * // - // ********************* // - + // ********************* // + modifier onlyOwner() { if (msg.sender != owner) throw; _; } modifier eventInfoSet() { if (eventInfo == address(0)) throw; _; } - + modifier onlyBeforeEnd() { if (now >= eventInfo.getEventEnd()) throw; _; } modifier onlyAfterEnd() { if (now < eventInfo.getEventEnd()) throw; _; } - + // ****************** // // * Events * // - // ****************** // - + // ****************** // + event Enlisted(address indexed dstContract); - - + + } diff --git a/contracts/wallet.sol b/contracts/wallet.sol index 352cb1b..7ff9c31 100644 --- a/contracts/wallet.sol +++ b/contracts/wallet.sol @@ -64,7 +64,7 @@ contract multiowned { } m_required = _required; } - + // Revokes a prior confirmation of the given operation function revoke(bytes32 _operation) external { uint ownerIndex = m_ownerIndex[uint(msg.sender)]; @@ -78,7 +78,7 @@ contract multiowned { Revoke(msg.sender, _operation); } } - + // Replaces an owner `_from` with another `_to`. function changeOwner(address _from, address _to) onlymanyowners(sha3(msg.data)) external { if (isOwner(_to)) return; @@ -91,7 +91,7 @@ contract multiowned { m_ownerIndex[uint(_to)] = ownerIndex; OwnerChanged(_from, _to); } - + function addOwner(address _owner) onlymanyowners(sha3(msg.data)) external { if (isOwner(_owner)) return; @@ -105,7 +105,7 @@ contract multiowned { m_ownerIndex[uint(_owner)] = m_numOwners; OwnerAdded(_owner); } - + function removeOwner(address _owner) onlymanyowners(sha3(msg.data)) external { uint ownerIndex = m_ownerIndex[uint(_owner)]; if (ownerIndex == 0) return; @@ -117,7 +117,7 @@ contract multiowned { reorganizeOwners(); //make sure m_numOwner is equal to the number of owners and always points to the optimal free slot OwnerRemoved(_owner); } - + function changeRequirement(uint _newRequired) onlymanyowners(sha3(msg.data)) external { if (_newRequired > m_numOwners) return; m_required = _newRequired; @@ -133,7 +133,7 @@ contract multiowned { function isOwner(address _addr) returns (bool) { return m_ownerIndex[uint(_addr)] > 0; } - + function hasConfirmed(bytes32 _operation, address _owner) constant returns (bool) { var pending = m_pending[_operation]; uint ownerIndex = m_ownerIndex[uint(_owner)]; @@ -145,7 +145,7 @@ contract multiowned { uint ownerIndexBit = 2**ownerIndex; return !(pending.ownersDone & ownerIndexBit == 0); } - + // INTERNAL METHODS function confirmAndCheck(bytes32 _operation) internal returns (bool) { @@ -199,7 +199,7 @@ contract multiowned { } } } - + function clearPending() internal { uint length = m_pendingIndex.length; for (uint i = 0; i < length; ++i) @@ -207,14 +207,14 @@ contract multiowned { delete m_pending[m_pendingIndex[i]]; delete m_pendingIndex; } - + // FIELDS // the number of owners that must confirm the same operation before it is run. uint public m_required; // pointer used to find a free slot in m_owners uint public m_numOwners; - + // list of owners uint[256] m_owners; uint constant c_maxOwners = 250; @@ -249,13 +249,13 @@ contract daylimit is multiowned { function setDailyLimit(uint _newLimit) onlymanyowners(sha3(msg.data)) external { m_dailyLimit = _newLimit; } - // resets the amount already spent today. needs many of the owners to confirm. + // resets the amount already spent today. needs many of the owners to confirm. function resetSpentToday() onlymanyowners(sha3(msg.data)) external { m_spentToday = 0; } - + // INTERNAL METHODS - + // checks to see if there is at least `_value` left from the daily limit today. if there is, subtracts it and // returns true. otherwise just returns false. function underLimit(uint _value) internal onlyowner returns (bool) { @@ -265,7 +265,7 @@ contract daylimit is multiowned { m_lastDay = today(); } // check to see if there's enough left - if so, subtract and return true. - // overflow protection // dailyLimit check + // overflow protection // dailyLimit check if (m_spentToday + _value >= m_spentToday && m_spentToday + _value <= m_dailyLimit) { m_spentToday += _value; return true; @@ -296,9 +296,9 @@ contract multisig { event MultiTransact(address owner, bytes32 operation, uint value, address to, bytes data); // Confirmation still needed for a transaction. event ConfirmationNeeded(bytes32 operation, address initiator, uint value, address to, bytes data); - + // FUNCTIONS - + // TODO: document function changeOwner(address _from, address _to) external; function execute(address _to, uint _value, bytes _data) external returns (bytes32); @@ -326,19 +326,19 @@ contract Wallet is multisig, multiowned, daylimit { function Wallet(address[] _owners, uint _required, uint _daylimit) multiowned(_owners, _required) daylimit(_daylimit) { } - + // kills the contract sending everything to `_to`. function kill(address _to) onlymanyowners(sha3(msg.data)) external { suicide(_to); } - + // gets called when no other function matches function() payable { // just being sent some cash? if (msg.value > 0) Deposit(msg.sender, msg.value); } - + // Outside-visible transact entry point. Executes transaction immediately if below daily spend limit. // If not, goes into multisig process. We provide a hash on return to allow the sender to provide // shortcuts for the other confirmations (allowing them to avoid replicating the _to, _value @@ -360,7 +360,7 @@ contract Wallet is multisig, multiowned, daylimit { ConfirmationNeeded(_r, msg.sender, _value, _to, _data); } } - + // confirm a transaction through just the hash. we use the previous transactions map, m_txs, in order // to determine the body of the transaction from the hash provided. function confirm(bytes32 _h) onlymanyowners(_h) returns (bool) { @@ -371,9 +371,9 @@ contract Wallet is multisig, multiowned, daylimit { return true; } } - + // INTERNAL METHODS - + function clearPending() internal { uint length = m_pendingIndex.length; for (uint i = 0; i < length; ++i) diff --git a/test/dst-management/ether-trade-funds-test-1.js b/test/dst-management/ether-trade-funds-test-1.js index 6576783..63e8f17 100644 --- a/test/dst-management/ether-trade-funds-test-1.js +++ b/test/dst-management/ether-trade-funds-test-1.js @@ -7,8 +7,8 @@ var Workbench = require('ethereum-sandbox-workbench'); var workbench = new Workbench({ defaults: { from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826' - }, - + }, + solcVersion: '0.4.2' }); @@ -16,7 +16,7 @@ workbench.startTesting(['StandardToken', 'EventInfo', 'DSTContract', 'VirtualExc var sandbox = workbench.sandbox; -// deployed contracts +// deployed contracts var eventInfo; var hackerGold; var virtualExchange; @@ -33,22 +33,22 @@ var proposal_5; function printDate(){ now = eventInfo.getNow().toNumber(); var date = new Date(now*1000); - - log('\n Date now: ' + date + '\n'); + + log('\n Date now: ' + date + '\n'); } /** - * - * Testing for requesting HKG funds after the event : - * - * 1. - * 2. - * 3. + * + * Testing for requesting HKG funds after the event : + * + * 1. + * 2. + * 3. * * ... todo detailed description */ - + it('event-info-init', function() { log(''); @@ -56,51 +56,51 @@ it('event-info-init', function() { log(' ether-trade-funds-test-1.js'); log(' *****************************'); log(''); - + return contracts.EventInfo.new() .then(function(contract) { - + if (contract.address){ eventInfo = contract; } else { throw new Error('No contract address'); - } - - return true; + } + + return true; }) - + .then(function() { - - printDate(); + + printDate(); return true; }); - + }); - + it('hacker-gold-init', function() { return contracts.HackerGold.new() .then(function(contract) { - + if (contract.address){ hackerGold = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); - + it('roll-time-ve-trading-start', function(){ - - // Roll time to get best price on HKG, - // 1 Ether for 200 HKG + + // Roll time to get best price on HKG, + // 1 Ether for 200 HKG return workbench.rollTimeTo('30-Oct-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -108,35 +108,35 @@ it('roll-time-ve-trading-start', function(){ it('buy-hkg-for-3a7e', function() { log(""); - log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); + log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); return workbench.sendTransaction({ from: '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', to: hackerGold.address, value: sandbox.web3.toWei(500000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; value = Math.ceil(value); - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); assert.equal(100000000, value); - - return true; + + return true; }) - + }); it('roll-time-ve-trading-start', function(){ - + return workbench.rollTimeTo('24-Nov-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -146,42 +146,42 @@ it('roll-time-ve-trading-start', function(){ it('virtual-exchange-init', function() { - return contracts.VirtualExchange.new(hackerGold.address, + return contracts.VirtualExchange.new(hackerGold.address, eventInfo.address) .then(function(contract) { - + if (contract.address){ virtualExchange = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); it('dst-contract-apl-init', function() { - return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", - + return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", + { from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', gas: 4000000, }) - + .then(function(contract) { tx = sandbox.web3.eth.getTransactionReceipt(contract.transactionHash); log("Gas used: " + tx.gasUsed); - + if (contract.address){ dstContract_APL = contract; } else { throw new Error('No contract address'); - } - - return true; + } + + return true; }) }); @@ -192,27 +192,27 @@ it('enlist-apl', function() { log(""); log(" (!) Action: [VE] enlist [APL] for trading"); - return virtualExchange.enlist(dstContract_APL.address, + return virtualExchange.enlist(dstContract_APL.address, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) - + .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) - + .then(function() { - - exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); - + + exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); + log("[APL] => enlisted: " + exist); assert.equal(true, exist); - + return true; }) - + }); @@ -220,23 +220,23 @@ it('enlist-apl', function() { it('issue-apl-tokens-seria-1', function() { log(""); log(" (!) Action: [APL] issue tokens on [VE] balance 1,000,000,000,000.000 APL"); - - return dstContract_APL.issuePreferedTokens(1000, 1000000000000000, + + return dstContract_APL.issuePreferedTokens(1000, 1000000000000000, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) .then(function () { - + dst1Total = dstContract_APL.getTotalSupply().toNumber() / 1000; - - log("[APL] => total suply: " + dst1Total.toFixed(3) + " APL"); - assert(1000000000000000, dst1Total); - - veTokens = dstContract_APL.allowance(dstContract_APL.address, + + log("[APL] => total supply: " + dst1Total.toFixed(3) + " APL"); + assert.equal(1000000000000, dst1Total); + + veTokens = dstContract_APL.allowance(dstContract_APL.address, virtualExchange.address).toNumber() / 1000; log("[APL] => total on VirtualExchange: " + veTokens.toFixed(3) + " APL"); - assert(1000000000000000, veTokens); + assert.equal(1000000000000, veTokens); return true; }) @@ -247,25 +247,25 @@ it('issue-apl-tokens-seria-1', function() { it('approve-hkg-spend-on-exchange-for-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 100000000000, + + return hackerGold.approve(virtualExchange.address, 100000000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; - + log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(100000000, veTokens); - + return true; }) }); @@ -276,57 +276,57 @@ it('buy-apl-by-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] buy tokens [APL] for 50,000,000.000 HKG"); - - return virtualExchange.buy('APL', 5000000000, + + return virtualExchange.buy('APL', 5000000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { dst1Balance = dstContract_APL.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " APL"); assert.equal(5000000000 , dst1Balance); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(5000000000000 , voting); value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; value = Math.ceil(value); - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(95000000, value); - + assert.equal(95000000, value); + log ("[APL] => total: " + total + " votes"); assert.equal(5000000000000, total); - - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(95000000 , veTokens); + assert.equal(95000000 , veTokens); + + availableSupply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available supply: " + availableSupply + " APL"); + assert.equal(995000000000 , availableSupply); - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - assert.equal(995000000000 , availableSuply); - return true; }) }); it('roll-time-va-ends', function(){ - + return workbench.rollTimeTo('22-Dec-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -337,16 +337,16 @@ it('end-event-summary', function() { log("Post Event Summary:"); log("==================="); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - dollarValue = value / 100; + + dollarValue = value / 100; log("[APL] => collected: " + value.toFixed(3) + " HKG" + " = $" + dollarValue); - assert.equal(50000, dollarValue); + assert.equal(50000, dollarValue); leftTokens = dstContract_APL.balanceOf(dstContract_APL.address); log("[APL] => tokens supply left: " + leftTokens + " APL"); - + return true; }); @@ -354,27 +354,27 @@ it('end-event-summary', function() { it('set-ether-price', function() { log(""); log(" (!) Action: [0xcc49] set price in ehter 1,000,000,000 for 1 ether"); - - return dstContract_APL.setEtherPrice(1000000000, + + return dstContract_APL.setEtherPrice(1000000000, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - - currentEtherPrice = dstContract_APL.getEtherPrice().toNumber(); + + currentEtherPrice = dstContract_APL.getEtherPrice().toNumber(); log("[APL] => 1 Ether = " + currentEtherPrice + " APL "); assert.equal(currentEtherPrice, 1000000000); - + return true; }) - + return true; }); @@ -392,18 +392,18 @@ it('send-ether-to-dst-1', function() { .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - + leftTokens = dstContract_APL.balanceOf(dstContract_APL.address); log("[APL] => tokens supply left: " + leftTokens + " APL"); assert.equal(990000000000000, leftTokens); - + return true; }) - + return true; }); @@ -422,18 +422,18 @@ it('send-ether-to-dst-2', function() { .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - + leftTokens = dstContract_APL.balanceOf(dstContract_APL.address); log("[APL] => tokens supply left: " + leftTokens + " APL"); assert.equal(0, leftTokens); - + return true; }) - + return true; }); @@ -444,25 +444,25 @@ it('send-ether-to-dst-2', function() { it('submit-proposal-for-ether-0', function() { log(""); log(" [X] Submit Ether proposal before disabled token issuance "); - - return dstContract_APL.submitEtherProposal( sandbox.web3.toWei(199, 'ether'), + + return dstContract_APL.submitEtherProposal( sandbox.web3.toWei(199, 'ether'), 'http://pastebin.com/raw/w2gSWvgM', { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', gas: 400000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) + return workbench.waitForReceipt(txHash); + }) .then(function (parsed) { - - assert.equal(0, parsed.logs.length) - return true; + + assert.equal(0, parsed.logs.length) + return true; }) - + return true; }); @@ -471,55 +471,55 @@ it('submit-proposal-for-ether-0', function() { it('disable-token-issue-option', function() { log(""); log(" (!) Action: [0xcc49] disable issuance of tokens for [APL]"); - - return dstContract_APL.disableTokenIssuance( + + return dstContract_APL.disableTokenIssuance( { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) + return workbench.waitForReceipt(txHash); + }) .then(function (parsed) { - + log(""); eventName = parsed.logs[0].event; assert.equal('DisableTokenIssuance', eventName); - - return true; + + return true; }) - + .then(function () { - + log(""); - + log("Post Ether Sale Summary:"); log("========================"); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - dollarValue = value / 100; + + dollarValue = value / 100; log("[APL] => collected: " + value.toFixed(3) + " HKG" + " = $" + dollarValue); - assert.equal(50000, dollarValue); + assert.equal(50000, dollarValue); - weiCollected = dstContract_APL.getEtherValue().toNumber(); - etherCollected = sandbox.web3.fromWei(weiCollected, 'ether'); - - dollarValue = etherCollected * 11; + weiCollected = dstContract_APL.getEtherValue().toNumber(); + etherCollected = sandbox.web3.fromWei(weiCollected, 'ether'); + + dollarValue = etherCollected * 11; log("[APL] => collected: " + etherCollected + " Eth" + " = $" + dollarValue); leftTokens = dstContract_APL.balanceOf(dstContract_APL.address); log("[APL] => tokens supply left: " + leftTokens + " APL"); - + return true; }) - + return true; }); @@ -532,25 +532,25 @@ it('disable-token-issue-option', function() { it('submit-proposal-for-ether-0', function() { log(""); log(" [X] Submit proposal for more than 20% of ether "); - - return dstContract_APL.submitEtherProposal( sandbox.web3.toWei(200, 'ether'), + + return dstContract_APL.submitEtherProposal( sandbox.web3.toWei(200, 'ether'), 'http://pastebin.com/raw/w2gSWvgM', { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', gas: 400000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) + return workbench.waitForReceipt(txHash); + }) .then(function (parsed) { - - assert.equal(0, parsed.logs.length) - return true; + + assert.equal(0, parsed.logs.length) + return true; }) - + return true; }); @@ -560,62 +560,62 @@ it('submit-proposal-for-ether-0', function() { it('submit-proposal-for-ether-1', function() { log(""); log(" (!) Action: [0xcc49] ask for 20% of ether "); - - return dstContract_APL.submitEtherProposal( sandbox.web3.toWei(199, 'ether'), + + return dstContract_APL.submitEtherProposal( sandbox.web3.toWei(199, 'ether'), 'http://pastebin.com/raw/w2gSWvgM', { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', gas: 400000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) + return workbench.waitForReceipt(txHash); + }) .then(function (parsed) { - - args = parsed.logs[0].args; - + + args = parsed.logs[0].args; + proposalId = args.id; proposalValue = args.value; - + proposalTimeEnds = args.timeEnds; proposalURL = args.url; proposalSender = args.sender; - + log(""); log("Proposal Submitted"); log("=================="); - + log("proposalId: " + proposalId); log("proposalValue: " + proposalValue); log("proposalTimeEnds: " + proposalTimeEnds); log("proposalURL: " + proposalURL); log("proposalSender: " + proposalSender); - - + + assert.equal(199, sandbox.web3.fromWei(proposalValue, 'ether') ); - + t1 = eventInfo.getNow().toNumber() + 60 * 60 * 24 * 10; t2 = proposalTimeEnds; - assert(t1, t2); + assert.equal(t1, t2); assert.equal(proposalURL, "http://pastebin.com/raw/w2gSWvgM"); assert.equal(proposalSender, "0xcc49bea5129ef2369ff81b0c0200885893979b77"); - + proposal_1 = proposalId; - - return true; + + return true; }) - + return true; }); it('roll-time-proposal_1-redeem', function(){ - + return workbench.rollTimeTo('01-Jan-2017 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -624,63 +624,63 @@ it('roll-time-proposal_1-redeem', function(){ it('redeem-propose-for-ether-1', function() { log(""); log(" (!) Action: [0xcc49] redeem propose_1 "); - - return dstContract_APL.redeemProposalFunds(proposal_1, + + return dstContract_APL.redeemProposalFunds(proposal_1, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', gas: 400000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) + return workbench.waitForReceipt(txHash); + }) .then(function (parsed) { - + log(""); - + // event assertion eventName = parsed.logs[0].event; assert.equal('EtherRedeemAccepted', eventName); - - args = parsed.logs[0].args; - + + args = parsed.logs[0].args; + proposalSender = args.sender; assert.equal('0xcc49bea5129ef2369ff81b0c0200885893979b77', args.sender); - + proposalValue = args.value; assert.equal(199, sandbox.web3.fromWei(proposalValue, 'ether') ); - - return true; + + return true; }) - + .then(function () { - + log(""); - + log("[APL] Funds Summary:"); log("========================"); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - dollarValue = value / 100; + + dollarValue = value / 100; log("[APL] => collected: " + value.toFixed(3) + " HKG" + " = $" + dollarValue); - assert.equal(50000, dollarValue); + assert.equal(50000, dollarValue); - weiCollected = dstContract_APL.getEtherValue().toNumber(); - etherCollected = sandbox.web3.fromWei(weiCollected, 'ether'); - - dollarValue = etherCollected * 11; + weiCollected = dstContract_APL.getEtherValue().toNumber(); + etherCollected = sandbox.web3.fromWei(weiCollected, 'ether'); + + dollarValue = etherCollected * 11; log("[APL] => collected: " + etherCollected + " Eth" + " = $" + dollarValue); leftTokens = dstContract_APL.balanceOf(dstContract_APL.address); log("[APL] => tokens supply left: " + leftTokens + " APL"); - + return true; }) - + return true; }); @@ -693,32 +693,32 @@ it('redeem-propose-for-ether-1', function() { it('submit-proposal-for-ether-0', function() { log(""); log(" [X] Submit proposal for ether before 2 weeks over from last one "); - - return dstContract_APL.submitEtherProposal( sandbox.web3.toWei(199, 'ether'), + + return dstContract_APL.submitEtherProposal( sandbox.web3.toWei(199, 'ether'), 'http://pastebin.com/raw/w2gSWvgM', { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', gas: 400000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) + return workbench.waitForReceipt(txHash); + }) .then(function (parsed) { - - assert.equal(0, parsed.logs.length); - return true; + + assert.equal(0, parsed.logs.length); + return true; }) - + return true; }); it('roll-time-proposal_2-submit', function(){ - + return workbench.rollTimeTo('05-Jan-2017 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -728,55 +728,55 @@ it('roll-time-proposal_2-submit', function(){ it('submit-proposal-for-ether-2', function() { log(""); log(" (!) Action: [0xcc49] ask for 20% of ether "); - - return dstContract_APL.submitEtherProposal( sandbox.web3.toWei(199, 'ether'), + + return dstContract_APL.submitEtherProposal( sandbox.web3.toWei(199, 'ether'), 'http://pastebin.com/raw/w2gSWvgM', { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', gas: 400000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) + return workbench.waitForReceipt(txHash); + }) .then(function (parsed) { - - args = parsed.logs[0].args; - + + args = parsed.logs[0].args; + proposalId = args.id; proposalValue = args.value; - + proposalTimeEnds = args.timeEnds; proposalURL = args.url; proposalSender = args.sender; - + log(""); log("Proposal Submitted"); log("=================="); - + log("proposalId: " + proposalId); log("proposalValue: " + proposalValue); log("proposalTimeEnds: " + proposalTimeEnds); log("proposalURL: " + proposalURL); log("proposalSender: " + proposalSender); - - + + assert.equal(199, sandbox.web3.fromWei(proposalValue, 'ether') ); - + t1 = eventInfo.getNow().toNumber() + 60 * 60 * 24 * 10; t2 = proposalTimeEnds; - assert(t1, t2); + assert.equal(t1, t2); assert.equal(proposalURL, "http://pastebin.com/raw/w2gSWvgM"); assert.equal(proposalSender, "0xcc49bea5129ef2369ff81b0c0200885893979b77"); - + proposal_2 = proposalId; - - return true; + + return true; }) - + return true; }); @@ -784,49 +784,49 @@ it('submit-proposal-for-ether-2', function() { it('object-by-vote-proposal-2', function() { - log(""); + log(""); log(" (!) Action: [0x3a7e] vote to object proposal 2"); - - return dstContract_APL.objectProposal(proposal_2, + + return dstContract_APL.objectProposal(proposal_2, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - gas : 450000, + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + gas : 450000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - + log_1 = parsed.logs[0]; - + total = dstContract_APL.getPreferedQtySold(); - + log("\n"); log(log_1.event + ":"); log("============"); - + log("proposal.id: " + log_1.args.id); log("voter: " + log_1.args.voter); log("votes: " + log_1.args.votes + " share: " + (log_1.args.votes / total * 100).toFixed(2) + "%"); - + voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber(); - + assert.equal(proposal_2, log_1.args.id); assert.equal(log_1.args.voter, "0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d"); assert.equal(log_1.args.votes, voting); - - return true; + + return true; }) }); it('roll-time-proposal_2-redeem', function(){ - + return workbench.rollTimeTo('09-Jan-2017 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -839,59 +839,59 @@ it('roll-time-proposal_2-redeem', function(){ it('redeem-propose-for-ether-2', function() { log(""); log(" [X] Redeem rejected proposal "); - - return dstContract_APL.redeemProposalFunds(proposal_2, + + return dstContract_APL.redeemProposalFunds(proposal_2, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', gas: 400000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) + return workbench.waitForReceipt(txHash); + }) .then(function (parsed) { - + log(""); assert.equal(0, parsed.logs.length); - - return true; + + return true; }) - + .then(function () { - + log(""); - + log("[APL] Funds Summary:"); log("========================"); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - dollarValue = value / 100; + + dollarValue = value / 100; log("[APL] => collected: " + value.toFixed(3) + " HKG" + " = $" + dollarValue); - assert.equal(50000, dollarValue); + assert.equal(50000, dollarValue); + + weiCollected = dstContract_APL.getEtherValue().toNumber(); + etherCollected = sandbox.web3.fromWei(weiCollected, 'ether'); - weiCollected = dstContract_APL.getEtherValue().toNumber(); - etherCollected = sandbox.web3.fromWei(weiCollected, 'ether'); - - dollarValue = etherCollected * 11; + dollarValue = etherCollected * 11; log("[APL] => collected: " + etherCollected + " Eth" + " = $" + dollarValue); leftTokens = dstContract_APL.balanceOf(dstContract_APL.address); log("[APL] => tokens supply left: " + leftTokens + " APL"); - + return true; }) - + return true; }); it('roll-time-for-total-redeem', function(){ - + return workbench.rollTimeTo('22-June-2017 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -900,62 +900,55 @@ it('roll-time-for-total-redeem', function(){ it('collect-all-the-rest-funds', function() { log(""); log(" (!) Action: [0xcc49] collect all the rest of HKG"); - - return dstContract_APL.getAllTheFunds( + + return dstContract_APL.getAllTheFunds( { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) - + .then(function (parsed) { - + assert.equal(1, parsed.logs.length); - args = parsed.logs[0].args; - - assert(dstContract_APL.address, args.from); - assert("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); - assert(500000000, args.value); + args = parsed.logs[0].args; - return true; + assert.equal(dstContract_APL.address, args.from); + assert.equal("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); + assert.equal(5000000000, Number(args.value)); + return true; }) - + .then(function () { - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); assert.equal(5000000, value); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); assert.equal(0, value); - - weiCollected = dstContract_APL.getEtherValue().toNumber(); - assert.equal(0, weiCollected); - - etherCollected = sandbox.web3.fromWei(weiCollected, 'ether'); - - dollarValue = etherCollected * 11; - log("[APL] => collected: " + etherCollected + " Eth" + " = $" + dollarValue); - return true; - }) + weiCollected = dstContract_APL.getEtherValue().toNumber(); + assert.equal(0, weiCollected); -}); + etherCollected = sandbox.web3.fromWei(weiCollected, 'ether'); + dollarValue = etherCollected * 11; + log("[APL] => collected: " + etherCollected + " Eth" + " = $" + dollarValue); + return true; + }) }); - - - +}); diff --git a/test/dst-management/ether-trade-funds-test-2.js b/test/dst-management/ether-trade-funds-test-2.js index 1474265..5cd08fa 100644 --- a/test/dst-management/ether-trade-funds-test-2.js +++ b/test/dst-management/ether-trade-funds-test-2.js @@ -7,8 +7,8 @@ var Workbench = require('ethereum-sandbox-workbench'); var workbench = new Workbench({ defaults: { from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826' - }, - + }, + solcVersion: '0.4.2' }); @@ -16,7 +16,7 @@ workbench.startTesting(['StandardToken', 'EventInfo', 'DSTContract', 'VirtualExc var sandbox = workbench.sandbox; -// deployed contracts +// deployed contracts var eventInfo; var hackerGold; var virtualExchange; @@ -33,22 +33,22 @@ var proposal_5; function printDate(){ now = eventInfo.getNow().toNumber(); var date = new Date(now*1000); - - log('\n Date now: ' + date + '\n'); + + log('\n Date now: ' + date + '\n'); } /** - * - * Testing for requesting HKG funds after the event : - * - * 1. - * 2. - * 3. + * + * Testing for requesting HKG funds after the event : + * + * 1. + * 2. + * 3. * * ... todo detailed description */ - + it('event-info-init', function() { log(''); @@ -56,51 +56,51 @@ it('event-info-init', function() { log(' ether-trade-funds-test-2.js'); log(' *****************************'); log(''); - + return contracts.EventInfo.new() .then(function(contract) { - + if (contract.address){ eventInfo = contract; } else { throw new Error('No contract address'); - } - - return true; + } + + return true; }) - + .then(function() { - - printDate(); + + printDate(); return true; }); - + }); - + it('hacker-gold-init', function() { return contracts.HackerGold.new() .then(function(contract) { - + if (contract.address){ hackerGold = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); - + it('roll-time-ve-trading-start', function(){ - - // Roll time to get best price on HKG, - // 1 Ether for 200 HKG + + // Roll time to get best price on HKG, + // 1 Ether for 200 HKG return workbench.rollTimeTo('30-Oct-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -108,35 +108,35 @@ it('roll-time-ve-trading-start', function(){ it('buy-hkg-for-3a7e', function() { log(""); - log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); + log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); return workbench.sendTransaction({ from: '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', to: hackerGold.address, value: sandbox.web3.toWei(500000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; value = Math.ceil(value); - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); assert.equal(100000000, value); - - return true; + + return true; }) - + }); it('roll-time-ve-trading-start', function(){ - + return workbench.rollTimeTo('24-Nov-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -146,42 +146,42 @@ it('roll-time-ve-trading-start', function(){ it('virtual-exchange-init', function() { - return contracts.VirtualExchange.new(hackerGold.address, + return contracts.VirtualExchange.new(hackerGold.address, eventInfo.address) .then(function(contract) { - + if (contract.address){ virtualExchange = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); it('dst-contract-apl-init', function() { - return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", - + return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", + { from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', gas: 4000000, }) - + .then(function(contract) { tx = sandbox.web3.eth.getTransactionReceipt(contract.transactionHash); log("Gas used: " + tx.gasUsed); - + if (contract.address){ dstContract_APL = contract; } else { throw new Error('No contract address'); - } - - return true; + } + + return true; }) }); @@ -192,27 +192,27 @@ it('enlist-apl', function() { log(""); log(" (!) Action: [VE] enlist [APL] for trading"); - return virtualExchange.enlist(dstContract_APL.address, + return virtualExchange.enlist(dstContract_APL.address, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) - + .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) - + .then(function() { - - exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); - + + exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); + log("[APL] => enlisted: " + exist); assert.equal(true, exist); - + return true; }) - + }); @@ -220,23 +220,23 @@ it('enlist-apl', function() { it('issue-apl-tokens-seria-1', function() { log(""); log(" (!) Action: [APL] issue tokens on [VE] balance 1,000,000,000,000.000 APL"); - - return dstContract_APL.issuePreferedTokens(1000, 1000000000000000, + + return dstContract_APL.issuePreferedTokens(1000, 1000000000000000, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) .then(function () { - + dst1Total = dstContract_APL.getTotalSupply().toNumber() / 1000; - - log("[APL] => total suply: " + dst1Total.toFixed(3) + " APL"); - assert(1000000000000000, dst1Total); - - veTokens = dstContract_APL.allowance(dstContract_APL.address, + + log("[APL] => total supply: " + dst1Total.toFixed(3) + " APL"); + assert.equal(1000000000000, dst1Total); + + veTokens = dstContract_APL.allowance(dstContract_APL.address, virtualExchange.address).toNumber() / 1000; log("[APL] => total on VirtualExchange: " + veTokens.toFixed(3) + " APL"); - assert(1000000000000000, veTokens); + assert.equal(1000000000000, veTokens); return true; }) @@ -247,25 +247,25 @@ it('issue-apl-tokens-seria-1', function() { it('approve-hkg-spend-on-exchange-for-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 100000000000, + + return hackerGold.approve(virtualExchange.address, 100000000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; - + log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(100000000, veTokens); - + return true; }) }); @@ -276,57 +276,57 @@ it('buy-apl-by-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] buy tokens [APL] for 50,000,000.000 HKG"); - - return virtualExchange.buy('APL', 5000000000, + + return virtualExchange.buy('APL', 5000000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { dst1Balance = dstContract_APL.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " APL"); assert.equal(5000000000 , dst1Balance); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(5000000000000 , voting); value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; value = Math.ceil(value); - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(95000000, value); - + assert.equal(95000000, value); + log ("[APL] => total: " + total + " votes"); assert.equal(5000000000000, total); - - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(95000000 , veTokens); + assert.equal(95000000 , veTokens); + + availableSupply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available supply: " + availableSupply + " APL"); + assert.equal(995000000000 , availableSupply); - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - assert.equal(995000000000 , availableSuply); - return true; }) }); it('roll-time-va-ends', function(){ - + return workbench.rollTimeTo('22-Dec-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -337,16 +337,16 @@ it('end-event-summary', function() { log("Post Event Summary:"); log("==================="); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - dollarValue = value / 100; + + dollarValue = value / 100; log("[APL] => collected: " + value.toFixed(3) + " HKG" + " = $" + dollarValue); - assert.equal(50000, dollarValue); + assert.equal(50000, dollarValue); leftTokens = dstContract_APL.balanceOf(dstContract_APL.address); log("[APL] => tokens supply left: " + leftTokens + " APL"); - + return true; }); @@ -356,27 +356,27 @@ it('end-event-summary', function() { it('set-ether-price', function() { log(""); log(" (!) Action: [0xcc49] set price in ehter 1,000,000,000 for 1 ether"); - - return dstContract_APL.setEtherPrice(1000000000, + + return dstContract_APL.setEtherPrice(1000000000, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - - currentEtherPrice = dstContract_APL.getEtherPrice().toNumber(); + + currentEtherPrice = dstContract_APL.getEtherPrice().toNumber(); log("[APL] => 1 Ether = " + currentEtherPrice + " APL "); assert.equal(currentEtherPrice, 1000000000); - + return true; }) - + return true; }); @@ -394,18 +394,18 @@ it('send-ether-to-dst-1', function() { .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - + leftTokens = dstContract_APL.balanceOf(dstContract_APL.address); log("[APL] => tokens supply left: " + leftTokens + " APL"); assert.equal(5000000000000, leftTokens); - + return true; }) - + return true; }); @@ -418,25 +418,25 @@ it('send-ether-to-dst-1', function() { it('submit-proposal-for-ether-0', function() { log(""); log(" [X] Submit Ether proposal while more token for sale remain "); - - return dstContract_APL.submitEtherProposal( sandbox.web3.toWei(199, 'ether'), + + return dstContract_APL.submitEtherProposal( sandbox.web3.toWei(199, 'ether'), 'http://pastebin.com/raw/w2gSWvgM', { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', gas: 400000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) + return workbench.waitForReceipt(txHash); + }) .then(function (parsed) { - - assert.equal(0, parsed.logs.length); - return true; + + assert.equal(0, parsed.logs.length); + return true; }) - + return true; }); @@ -445,27 +445,27 @@ it('submit-proposal-for-ether-0', function() { it('set-ether-price', function() { log(""); log(" (!) Action: [0xcc49] set price in ehter 2,000,000,000 for 1 ether"); - - return dstContract_APL.setEtherPrice(2000000000, + + return dstContract_APL.setEtherPrice(2000000000, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - - currentEtherPrice = dstContract_APL.getEtherPrice().toNumber(); + + currentEtherPrice = dstContract_APL.getEtherPrice().toNumber(); log("[APL] => 1 Ether = " + currentEtherPrice + " APL "); assert.equal(currentEtherPrice, 2000000000); - + return true; }) - + return true; }); @@ -474,36 +474,30 @@ it('set-ether-price', function() { it('burn-rest-of-the-tokens', function() { log(""); log(" (!) Action: [0xcc49] burn remain tokens"); - - return dstContract_APL.burnRemainToken( + + return dstContract_APL.burnRemainToken( { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { leftTokens = dstContract_APL.balanceOf(dstContract_APL.address); log("[APL] => tokens supply left: " + leftTokens + " APL"); - assert.equal(0, leftTokens); - + assert.equal(0, leftTokens); + return true; }) - + return true; }); }); - - - - - - diff --git a/test/dst-management/impeachment-test-1.js b/test/dst-management/impeachment-test-1.js index 4b7c0dc..8d89539 100644 --- a/test/dst-management/impeachment-test-1.js +++ b/test/dst-management/impeachment-test-1.js @@ -1,96 +1,97 @@ -var assert = require('assert'); - -var log = console.log; - -var Workbench = require('ethereum-sandbox-workbench'); -var workbench = new Workbench({ - defaults: { - from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826' - }, - - solcVersion: '0.4.2' -}); - -workbench.startTesting(['StandardToken', 'EventInfo', 'DSTContract', 'VirtualExchange'], function(contracts) { - -var sandbox = workbench.sandbox; - -// deployed contracts -var eventInfo; -var hackerGold; +var assert = require('assert'); + +var log = console.log; + +var Workbench = require('ethereum-sandbox-workbench'); +var workbench = new Workbench({ + defaults: { + from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826' + }, + + solcVersion: '0.4.2' +}); + +workbench.startTesting(['StandardToken', 'EventInfo', 'DSTContract', 'VirtualExchange'], function(contracts) { + +var sandbox = workbench.sandbox; + +// deployed contracts +var eventInfo; +var hackerGold; var virtualExchange; - -var dstContract_APL; // Awesome Poker League - -function printDate(){ - now = eventInfo.getNow().toNumber(); - var date = new Date(now*1000); - - log('\n Date now: ' + date + '\n'); -} - - -/** - * - * Testing for impeachment: - * - * todo ... add more ... description - * - */ - -it('event-info-init', function() { - - log(''); - log(' ***********************'); - log(' impeachment-test-1.js '); - log(' ***********************'); - log(''); - - - return contracts.EventInfo.new() - - .then(function(contract) { - - if (contract.address){ - eventInfo = contract; - } else { - throw new Error('No contract address'); - } - - return true; - }) - - .then(function() { - - printDate(); - return true; - }); - -}); - + +var dstContract_APL; // Awesome Poker League + +function printDate(){ + now = eventInfo.getNow().toNumber(); + var date = new Date(now*1000); + + log('\n Date now: ' + date + '\n'); +} + + +/** + * + * Testing for impeachment: + * + * + * + * todo ... add more ... description + * + */ + +it('event-info-init', function() { + + log(''); + log(' ***********************'); + log(' impeachment-test-1.js '); + log(' ***********************'); + log(''); + + return contracts.EventInfo.new() + + .then(function(contract) { + + if (contract.address){ + eventInfo = contract; + } else { + throw new Error('No contract address'); + } + + return true; + }) + + .then(function() { + + printDate(); + return true; + }); + +}); + it('hacker-gold-init', function() { return contracts.HackerGold.new() .then(function(contract) { - + if (contract.address){ hackerGold = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); - + it('roll-time-ve-trading-start', function(){ - - // Roll time to get best price on HKG, - // 1 Ether for 200 HKG + + // Roll time to get best price on HKG, + // 1 Ether for 200 HKG return workbench.rollTimeTo('30-Oct-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -98,119 +99,119 @@ it('roll-time-ve-trading-start', function(){ it('buy-hkg-for-3a7e', function() { log(""); - log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); + log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); return workbench.sendTransaction({ from: '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', to: hackerGold.address, value: sandbox.web3.toWei(10000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); assert.equal(2000000, value); - - return true; + + return true; }) - + }); it('buy-hkg-for-2980', function() { log(""); - log(" (!) Action: [0x2980] buy [HKG] for 10,000.000 Ether"); + log(" (!) Action: [0x2980] buy [HKG] for 10,000.000 Ether"); return workbench.sendTransaction({ from: '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', to: hackerGold.address, value: sandbox.web3.toWei(10000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; - + log("[0x2980] => balance: " + value.toFixed(3) + " HKG"); assert.equal(2000000, value); - - return true; + + return true; }) - + }); it('buy-hkg-for-696b', function() { log(""); - log(" (!) Action: [0x696b] buy [HKG] for 5000.000 Ether"); + log(" (!) Action: [0x696b] buy [HKG] for 5000.000 Ether"); return workbench.sendTransaction({ from: '0x696ba93ef4254da47ff05b6caa88190db335f1c3', to: hackerGold.address, value: sandbox.web3.toWei(10000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; - + log("[0x696b] => balance: " + value.toFixed(3) + " HKG"); assert.equal(2000000, value); - - return true; + + return true; }) - + }); it('buy-hkg-for-cd2a', function() { log(""); - log(" (!) Action: [0xcd2a] buy [HKG] for 5000.000 Ether"); + log(" (!) Action: [0xcd2a] buy [HKG] for 5000.000 Ether"); return workbench.sendTransaction({ from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', to: hackerGold.address, value: sandbox.web3.toWei(10000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826').toNumber() / 1000; - + log("[0xcd2a] => balance: " + value.toFixed(3) + " HKG"); assert.equal(2000000, value); - - return true; + + return true; }) - + }); it('roll-time-ve-trading-start', function(){ - + return workbench.rollTimeTo('24-Nov-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -220,39 +221,39 @@ it('roll-time-ve-trading-start', function(){ it('virtual-exchange-init', function() { - return contracts.VirtualExchange.new(hackerGold.address, + return contracts.VirtualExchange.new(hackerGold.address, eventInfo.address) .then(function(contract) { - + if (contract.address){ virtualExchange = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); it('dst-contract-apl-init', function() { - return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", - + return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", + { from : '0xcc49bea5129ef2369ff81b0c0200885893979b77' }) .then(function(contract) { - + if (contract.address){ dstContract_APL = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); @@ -261,47 +262,47 @@ it('enlist-apl', function() { log(""); log(" (!) Action: [VE] enlist [APL] for trading"); - return virtualExchange.enlist(dstContract_APL.address, + return virtualExchange.enlist(dstContract_APL.address, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) - + .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) - + .then(function() { - - exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); - + + exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); + log("[APL] => enlisted: " + exist); assert.equal(true, exist); - + return true; }) - + }); it('issue-apl-tokens-seria-1', function() { log(""); log(" (!) Action: [APL] issue tokens on [VE] balance 1,000,000,000,000.000 APL"); - - return dstContract_APL.issuePreferedTokens(1000, 1000000000000, + + return dstContract_APL.issuePreferedTokens(1000, 1000000000000, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) .then(function () { - + dst1Total = dstContract_APL.getTotalSupply().toNumber() / 1000; - + log("[APL] => total suply: " + dst1Total.toFixed(3) + " APL"); assert(1000000000000, dst1Total); - - veTokens = dstContract_APL.allowance(dstContract_APL.address, + + veTokens = dstContract_APL.allowance(dstContract_APL.address, virtualExchange.address).toNumber() / 1000; log("[APL] => total on VirtualExchange: " + veTokens.toFixed(3) + " APL"); assert(1000000000000, veTokens); @@ -309,1048 +310,1035 @@ it('issue-apl-tokens-seria-1', function() { return true; }) }); - - - -it('approve-hkg-spend-on-exchange-for-3a7e', function() { - log(""); - log(" (!) Action: [0x3a7e] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 2000000000, - { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - }) - - .then(function () { - - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - virtualExchange.address).toNumber() / 1000; - - log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(2000000, veTokens); - - return true; - }) -}); - - -it('approve-hkg-spend-on-exchange-for-2980', function() { - log(""); - log(" (!) Action: [0x2980] move to [VE] balance 2,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 2000000000, - { - from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - }) - - .then(function () { - - veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', - virtualExchange.address).toNumber() / 1000; - - log("[0x2980] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(2000000, veTokens); - - return true; - }) -}); - - -it('approve-hkg-spend-on-exchange-for-696b', function() { - log(""); - log(" (!) Action: [0x696b] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 2000000000, - { - from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - }) - - .then(function () { - - veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', - virtualExchange.address).toNumber() / 1000; - - log("[0x696b] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(2000000, veTokens); - - return true; - }) -}); - - - -it('approve-hkg-spend-on-exchange-for-cd2a', function() { - log(""); - log(" (!) Action: [0xcd2a] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 2000000000, - { - from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - }) - - .then(function () { - - veTokens = hackerGold.allowance('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', - virtualExchange.address).toNumber() / 1000; - - log("[0xcd2a] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(2000000, veTokens); - - return true; - }) -}); - - -it('buy-apl-by-3a7e', function() { - log(""); - log(" (!) Action: [0x3a7e] buy tokens [APL] for 300,000.000 HKG"); - - - return virtualExchange.buy('APL', 300000000, - { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - gas: 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function () { - - dst1Balance = dstContract_APL.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - - log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " APL"); - assert.equal(300000000 , dst1Balance); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - - log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(300000000000 , voting); - - value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - - log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(1700000, value); - - log ("[APL] => total: " + total + " votes"); - assert.equal(300000000000, total); - - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - virtualExchange.address).toNumber() / 1000; - log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(1700000 , veTokens); - - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - assert.equal(700000000 , availableSuply); - - return true; - }) -}); - - - - -it('buy-apl-by-2980', function() { - log(""); - log(" (!) Action: [0x2980] buy tokens [APL] for 300,000.000 HKG"); - - - return virtualExchange.buy('APL', 300000000, - { - from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', - gas: 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function () { - - dst1Balance = dstContract_APL.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; - - log("[0x2980] => balance: " + dst1Balance.toFixed(3) + " APL"); - assert.equal(300000000 , dst1Balance); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); - - log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(300000000000 , voting); - - value = hackerGold.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; - - log("[0x2980] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(1700000, value); - - log ("[APL] => total: " + total + " votes"); - - veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', - virtualExchange.address).toNumber() / 1000; - log("[0x2980] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(1700000 , veTokens); - - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - - - log(""); - log(" Voting Summary: "); - log(" =============== "); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - - log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(50, voting / total * 100); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); - - log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(50, voting / total * 100); - - value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => collected: " + value.toFixed(3) + " HKG"); - assert.equal(600000, value); - - return true; - }) -}); - - - - -it('buy-apl-by-696b', function() { - log(""); - log(" (!) Action: [0x696b] buy tokens [APL] for 400,000.000 HKG"); - - - return virtualExchange.buy('APL', 400000000, - { - from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', - gas: 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - }) - - .then(function () { - - dst1Balance = dstContract_APL.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; - - log("[0x696b] => balance: " + dst1Balance.toFixed(3) + " APL"); - assert.equal(400000000 , dst1Balance); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3'); - - log ("[0x696b] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(400000000000 , voting); - - value = hackerGold.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; - - log("[0x696b] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(1600000, value); - - log ("[APL] => total: " + total + " votes"); - - veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', - virtualExchange.address).toNumber() / 1000; - log("[0x696b] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(1600000 , veTokens); - - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - - - log(""); - log(" Voting Summary: "); - log(" =============== "); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - - log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(30, voting / total * 100); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); - - log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(30, voting / total * 100); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3'); - - log ("[0x696b] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(40, voting / total * 100); - - value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => collected: " + value.toFixed(3) + " HKG"); - assert.equal(1000000, value); - - return true; - }) -}); - - - -it('roll-time-va-ends', function(){ - - return workbench.rollTimeTo('22-Dec-2016 14:00 UTC+00') - .then(function(contract) { printDate(); return true; }); -}); - - -it('roll-time-50%-available', function(){ - - return workbench.rollTimeTo('22-Feb-2017 14:00 UTC+00') - .then(function(contract) { printDate(); return true; }); -}); - -it('submit-proposal-1', function() { - log(""); - log(" (!) Action: [0xcc49] ask to recieve 200,000.000 (20%) of the HKG collected"); - - return dstContract_APL.submitHKGProposal(200000000, "http://pastebin.com/raw/6e9PBTeP", - { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 450000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function (parsed) { - - args = parsed.logs[0].args; - - proposalId = args.id; - proposalValue = args.value; - proposalValue = proposalValue / 1000; - - proposalTimeEnds = args.timeEnds; - proposalURL = args.url; - proposalSender = args.sender; - - log(""); - log("Proposal Submitted"); - log("=================="); - - log("proposalId: " + proposalId); - log("proposalValue: " + proposalValue.toFixed(3)); - log("proposalTimeEnds: " + proposalTimeEnds); - log("proposalURL: " + proposalURL); - log("proposalSender: " + proposalSender); - - - assert.equal(200000, proposalValue); - - t1 = eventInfo.getNow().toNumber() + 60 * 60 * 24 * 10; - t2 = proposalTimeEnds; - assert(t1, t2); - - assert.equal(proposalURL, "http://pastebin.com/raw/6e9PBTeP"); - assert.equal(proposalSender, "0xcc49bea5129ef2369ff81b0c0200885893979b77"); - - proposal_1 = proposalId; - - value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(0, value); - - return true; - }) - -}); - - - -it('object-by-vote-proposal-1', function() { - log(""); - log(" (!) Action: [0x3a7e] vote to object proposal 1"); - - return dstContract_APL.objectProposal(proposal_1, - { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - gas : 450000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function (parsed) { - - log_1 = parsed.logs[0]; - - total = dstContract_APL.getPreferedQtySold(); - - log("\n"); - log(log_1.event + ":"); - log("============"); - - log("proposal.id: " + log_1.args.id); - log("voter: " + log_1.args.voter); - log("votes: " + log_1.args.votes + " share: " + (log_1.args.votes / total * 100).toFixed(2) + "%"); - - voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber(); - - assert.equal(proposal_1, log_1.args.id); - assert.equal(log_1.args.voter, "0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d"); - assert.equal(log_1.args.votes, voting); - - return true; - }) - -}); - - -it('roll-time-proposal-redeem', function(){ - - return workbench.rollTimeTo('04-Mar-2017 14:00 UTC+00') - .then(function(contract) { printDate(); return true; }); -}); - - -it('redeem-proposal-1', function() { - log(""); - log(" (!) Action: [0xcc49] collect 1,000.000 HKG value of proposal 1"); - - return dstContract_APL.redeemProposalFunds(proposal_1, - { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function (parsed) { - - assert.equal(1, parsed.logs.length); - - args = parsed.logs[0].args; - - assert(dstContract_APL.address, args.from); - assert("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); - assert(200000000, args.value); - - return true; - }) - - .then(function () { - - value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(200000, value); - - value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(800000, value); - - return true; - }) - -}); - -// -// [X] Submit impeachment less than 3 months from the event finish -// - -it('impeachment-proposal-less-time-from-event-end', function() { - log(""); - log(" [X] Submit impeachment less than 3 months from the event finish"); - - return dstContract_APL.submitImpeachmentProposal("http://pastebin.com/raw/Ehet8yVf", '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', - { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - gas : 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function (parsed) { - - log(""); - log("No impeachment was submitted"); - assert.equal(parsed.logs.length, 0); - - return true; - }) - - .then(function () { - - totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); - impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); - - impSupport = (impeachmentSupport / totalPreferred) * 100 - - log(""); - - log("Support for impeachment: " + impSupport + "%"); - assert.equal(0, impSupport); - - log("Executive for now: " + dstContract_APL.getExecutive()); - assert.equal('0xcc49bea5129ef2369ff81b0c0200885893979b77' ,dstContract_APL.getExecutive()); - - return true; - }) - -}); - - - -it('roll-time-to-start-impeachment', function(){ - - return workbench.rollTimeTo('22-Mar-2017 14:00 UTC+00') - .then(function(contract) { printDate(); return true; }); -}); - - -// -// [X] Submit impeachment by non voter -// - -it('impeachment-proposal-by-non-voter', function() { - log(""); - log(" [X] Action: submit impeachment by non voter"); - - return dstContract_APL.submitImpeachmentProposal("http://pastebin.com/raw/Ehet8yVf", '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', - { - from : '0x36cef404bd674e1aa6ba6b444c9ef458460c9871', - gas : 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function (parsed) { - - log(""); - log("No impeachment was submitted"); - assert.equal(parsed.logs.length, 0); - - return true; - }) - - .then(function () { - - totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); - impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); - - impSupport = (impeachmentSupport / totalPreferred) * 100 - - log(""); - - log("Support for impeachment: " + impSupport + "%"); - assert.equal(0, impSupport); - - log("Executive for now: " + dstContract_APL.getExecutive()); - assert.equal('0xcc49bea5129ef2369ff81b0c0200885893979b77' ,dstContract_APL.getExecutive()); - - return true; - }) - -}); - - - -it('impeachment-proposal-submit-1', function() { - log(""); - log(" (!) Action: [0x3a7e] submit impeachment proposal"); - - return dstContract_APL.submitImpeachmentProposal("http://pastebin.com/raw/Ehet8yVf", '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', - { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - gas : 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function (parsed) { - - args = parsed.logs[0].args; - - log(""); - - log("ImpeachmentProposed (event)"); - log("==================="); - - - assert.equal("ImpeachmentProposed", parsed.logs[0].event); - - log("Submited by: " + args.submitter); - assert.equal("0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d", args.submitter); - - assert.equal("http://pastebin.com/raw/Ehet8yVf", args.urlDetails); - assert.equal("0xdedb49385ad5b94a16f236a6890cf9e0b1e30392", args.newExecutive); - - expectedEndTime = new Date('05-Apr-2017 14:00 UTC+00').getTime() / 1000; - assert.equal(expectedEndTime, args.votindEndTS); - - return true; - }) - - .then(function () { - - totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); - impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); - - impSupport = (impeachmentSupport / totalPreferred) * 100 - - log(""); - - log("Support for impeachment: " + impSupport + "%"); - assert.equal(30, impSupport); - - log("Executive for now: " + dstContract_APL.getExecutive()); - assert.equal('0xcc49bea5129ef2369ff81b0c0200885893979b77' ,dstContract_APL.getExecutive()); - - return true; - }) - -}); - - - - -it('impeachment-proposal-support-1', function() { - log(""); - log(" (!) Action: [0x2980] support impeachment proposal"); - - return dstContract_APL.supportImpeachment( - { - from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', - gas : 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function (parsed) { - - args = parsed.logs[0].args; - - log(""); - - log("ImpeachmentSupport (event)"); - log("=================="); - - assert.equal("ImpeachmentSupport", parsed.logs[0].event); - - log("Submited by: " + args.supportter); - assert.equal("0x29805ff5b946e7a7c5871c1fb071f740f767cf41", args.supportter); - - log("[0x2980] submited " + args.votes + " votes"); - assert.equal(300000000000, args.votes.toNumber()); - - return true; - }) - - .then(function () { - - totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); - impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); - - impSupport = (impeachmentSupport / totalPreferred) * 100 - - log(""); - - log("Support for impeachment: " + impSupport + "%"); - assert.equal(60, impSupport); - - log("Executive for now: " + dstContract_APL.getExecutive()); - assert.equal('0xcc49bea5129ef2369ff81b0c0200885893979b77' ,dstContract_APL.getExecutive()); - - return true; - }) - -}); - -// -// [X] Support impeachment by a non voter -// - -it('impeachment-proposal-support-by-non-voter', function() { - log(""); - log(" [X] Support impeachment by a non voter"); - - return dstContract_APL.supportImpeachment( - { - from : '0x36cef404bd674e1aa6ba6b444c9ef458460c9871', - gas : 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function (parsed) { - - assert.equal(parsed.logs.length, 0); - log(""); - - log("No support event generated"); - - return true; - }) - - .then(function () { - - totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); - impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); - - impSupport = (impeachmentSupport / totalPreferred) * 100 - - log(""); - - log("Support for impeachment: " + impSupport + "%"); - assert.equal(60, impSupport); - - log("Executive for now: " + dstContract_APL.getExecutive()); - assert.equal('0xcc49bea5129ef2369ff81b0c0200885893979b77' ,dstContract_APL.getExecutive()); - - return true; - }) - -}); - - - -// -// [X] Support impeachment by a an already voted voter -// - -it('impeachment-proposal-support-by-already-voter', function() { - log(""); - log(" [X] Support impeachment by a an already voted voter "); - - return dstContract_APL.supportImpeachment( - { - from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', - gas : 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function (parsed) { - - assert.equal(parsed.logs.length, 0); - log(""); - - log("No support event generated"); - - return true; - }) - - .then(function () { - - totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); - impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); - - impSupport = (impeachmentSupport / totalPreferred) * 100 - - log(""); - - log("Support for impeachment: " + impSupport + "%"); - assert.equal(60, impSupport); - - log("Executive for now: " + dstContract_APL.getExecutive()); - assert.equal('0xcc49bea5129ef2369ff81b0c0200885893979b77' ,dstContract_APL.getExecutive()); - - return true; - }) - -}); - - -it('impeachment-proposal-support-2', function() { - log(""); - log(" (!) Action: [0x696b] support impeachment proposal"); - - return dstContract_APL.supportImpeachment( - { - from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', - gas : 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - }) - - .then(function (parsed) { - - args = parsed.logs[0].args; - - log(""); - - log("ImpeachmentSupport (event)"); - log("=================="); - - assert.equal("ImpeachmentSupport", parsed.logs[0].event); - - log("Submited by: " + args.supportter); - assert.equal("0x696ba93ef4254da47ff05b6caa88190db335f1c3", args.supportter); - - log("[0x696b] submited " + args.votes + " votes"); - assert.equal(400000000000, args.votes.toNumber()); - - return true; - }) - - .then(function () { - - - totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); - impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); - - impSupport = (impeachmentSupport / totalPreferred) * 100 - - log(""); - - log("Support for impeachment: " + impSupport + "%"); - assert.equal(100, impSupport); - - log("New executive appointed: " + dstContract_APL.getExecutive()); - assert.equal('0xdedb49385ad5b94a16f236a6890cf9e0b1e30392' ,dstContract_APL.getExecutive()); - - return true; - }) - -}); - - - -it('roll-time-to-start-2nd-impeachment', function(){ - - return workbench.rollTimeTo('22-Apr-2017 14:00 UTC+00') - .then(function(contract) { printDate(); return true; }); -}); - - -it('impeachment-proposal-submit-2', function() { - log(""); - log(" (!) Action: [0x3a7e] submit impeachment proposal"); - - return dstContract_APL.submitImpeachmentProposal("http://pastebin.com/raw/Ehet8yVf", '0xcc49bea5129ef2369ff81b0c0200885893979b77', - { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - gas : 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function (parsed) { - - args = parsed.logs[0].args; - - log(""); - - log("ImpeachmentProposed (event)"); - log("==================="); - - - assert.equal("ImpeachmentProposed", parsed.logs[0].event); - - log("Submited by: " + args.submitter); - assert.equal("0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d", args.submitter); - - assert.equal("http://pastebin.com/raw/Ehet8yVf", args.urlDetails); - assert.equal("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.newExecutive); - - expectedEndTime = new Date('06-May-2017 14:00 UTC+00').getTime() / 1000; - assert.equal(expectedEndTime, args.votindEndTS); - - return true; - }) - - .then(function () { - - totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); - impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); - - impSupport = (impeachmentSupport / totalPreferred) * 100 - - log(""); - - log("Support for impeachment: " + impSupport + "%"); - assert.equal(30, impSupport); - - log("Executive for now: " + dstContract_APL.getExecutive()); - assert.equal('0xdedb49385ad5b94a16f236a6890cf9e0b1e30392' ,dstContract_APL.getExecutive()); - - return true; - }) - -}); - - -it('roll-time-to-end-voting-2nd-impeachment', function(){ - - return workbench.rollTimeTo('06-May-2017 14:00 UTC+00') - .then(function(contract) { printDate(); return true; }); -}); - - -// -// [X] Support impeachment after the time for voting ended -// - -it('support-impeachment-after-timeover', function() { - log(""); - log(" [X] Support impeachment after the time for voting ended "); - - return dstContract_APL.supportImpeachment( - { - from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', - gas : 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function (parsed) { - - assert.equal(parsed.logs.length, 0); - log(""); - - log("No support event generated"); - - return true; - }) - - .then(function () { - - totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); - impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); - - impSupport = (impeachmentSupport / totalPreferred) * 100 - - log(""); - - log("Support for impeachment: " + impSupport + "%"); - assert.equal(30, impSupport); - - log("Executive for now: " + dstContract_APL.getExecutive()); - assert.equal('0xdedb49385ad5b94a16f236a6890cf9e0b1e30392' ,dstContract_APL.getExecutive()); - - return true; - }) - -}); - - -// -// [X] Submit another impeachment before 1 month from the last passed -// - -it('impeachment-proposal-submit-3', function() { - log(""); - log(" [X] Submit another impeachment before 1 month from the last passed"); - - return dstContract_APL.submitImpeachmentProposal("http://pastebin.com/raw/Ehet8yVf", '0xcc49bea5129ef2369ff81b0c0200885893979b77', - { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - gas : 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function (parsed) { - - assert.equal(parsed.logs.length, 0); - log(""); - - log("Rejected to accept new submission proposal"); - - return true; - }) - - .then(function () { - return true; - }) - -}); - - -}); - - - - - - + + + +it('approve-hkg-spend-on-exchange-for-3a7e', function() { + log(""); + log(" (!) Action: [0x3a7e] move to [VE] balance 1,000,000.000 HKG"); + + return hackerGold.approve(virtualExchange.address, 2000000000, + { + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function () { + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + virtualExchange.address).toNumber() / 1000; + + log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(2000000, veTokens); + + return true; + }) +}); + + +it('approve-hkg-spend-on-exchange-for-2980', function() { + log(""); + log(" (!) Action: [0x2980] move to [VE] balance 2,000,000.000 HKG"); + + return hackerGold.approve(virtualExchange.address, 2000000000, + { + from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function () { + + veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + virtualExchange.address).toNumber() / 1000; + + log("[0x2980] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(2000000, veTokens); + + return true; + }) +}); + + +it('approve-hkg-spend-on-exchange-for-696b', function() { + log(""); + log(" (!) Action: [0x696b] move to [VE] balance 1,000,000.000 HKG"); + + return hackerGold.approve(virtualExchange.address, 2000000000, + { + from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function () { + + veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', + virtualExchange.address).toNumber() / 1000; + + log("[0x696b] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(2000000, veTokens); + + return true; + }) +}); + + + +it('approve-hkg-spend-on-exchange-for-cd2a', function() { + log(""); + log(" (!) Action: [0xcd2a] move to [VE] balance 1,000,000.000 HKG"); + + return hackerGold.approve(virtualExchange.address, 2000000000, + { + from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function () { + + veTokens = hackerGold.allowance('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + virtualExchange.address).toNumber() / 1000; + + log("[0xcd2a] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(2000000, veTokens); + + return true; + }) +}); + + +it('buy-apl-by-3a7e', function() { + log(""); + log(" (!) Action: [0x3a7e] buy tokens [APL] for 300,000.000 HKG"); + + + return virtualExchange.buy('APL', 300000000, + { + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + gas: 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function () { + + dst1Balance = dstContract_APL.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; + + log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " APL"); + assert.equal(300000000 , dst1Balance); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); + + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(300000000000 , voting); + + value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; + + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(1700000, value); + + log ("[APL] => total: " + total + " votes"); + assert.equal(300000000000, total); + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + virtualExchange.address).toNumber() / 1000; + log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(1700000 , veTokens); + + availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available suply: " + availableSuply + " APL"); + assert.equal(700000000 , availableSuply); + + return true; + }) +}); + + + + +it('buy-apl-by-2980', function() { + log(""); + log(" (!) Action: [0x2980] buy tokens [APL] for 300,000.000 HKG"); + + + return virtualExchange.buy('APL', 300000000, + { + from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + gas: 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function () { + + dst1Balance = dstContract_APL.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; + + log("[0x2980] => balance: " + dst1Balance.toFixed(3) + " APL"); + assert.equal(300000000 , dst1Balance); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); + + log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(300000000000 , voting); + + value = hackerGold.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; + + log("[0x2980] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(1700000, value); + + log ("[APL] => total: " + total + " votes"); + + veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + virtualExchange.address).toNumber() / 1000; + log("[0x2980] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(1700000 , veTokens); + + availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available suply: " + availableSuply + " APL"); + + + log(""); + log(" Voting Summary: "); + log(" =============== "); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); + + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(50, voting / total * 100); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); + + log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(50, voting / total * 100); + + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => collected: " + value.toFixed(3) + " HKG"); + assert.equal(600000, value); + + return true; + }) +}); + + + + +it('buy-apl-by-696b', function() { + log(""); + log(" (!) Action: [0x696b] buy tokens [APL] for 400,000.000 HKG"); + + + return virtualExchange.buy('APL', 400000000, + { + from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', + gas: 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function () { + + dst1Balance = dstContract_APL.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; + + log("[0x696b] => balance: " + dst1Balance.toFixed(3) + " APL"); + assert.equal(400000000 , dst1Balance); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3'); + + log ("[0x696b] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(400000000000 , voting); + + value = hackerGold.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; + + log("[0x696b] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(1600000, value); + + log ("[APL] => total: " + total + " votes"); + + veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', + virtualExchange.address).toNumber() / 1000; + log("[0x696b] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(1600000 , veTokens); + + availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available suply: " + availableSuply + " APL"); + + + log(""); + log(" Voting Summary: "); + log(" =============== "); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); + + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(30, voting / total * 100); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); + + log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(30, voting / total * 100); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3'); + + log ("[0x696b] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(40, voting / total * 100); + + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => collected: " + value.toFixed(3) + " HKG"); + assert.equal(1000000, value); + + return true; + }) +}); + + +//TODO: if impeachment files are the same until here we should refactor +it('roll-time-50%-available', function(){ + + return workbench.rollTimeTo('22-Feb-2017 14:00 UTC+00') + .then(function(contract) { printDate(); return true; }); +}); + +it('submit-proposal-1', function() { + log(""); + log(" (!) Action: [0xcc49] ask to recieve 200,000.000 (20%) of the HKG collected"); + + return dstContract_APL.submitHKGProposal(200000000, "http://pastebin.com/raw/6e9PBTeP", + { + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 450000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + args = parsed.logs[0].args; + + proposalId = args.id; + proposalValue = args.value; + proposalValue = proposalValue / 1000; + + proposalTimeEnds = args.timeEnds; + proposalURL = args.url; + proposalSender = args.sender; + + log(""); + log("Proposal Submitted"); + log("=================="); + + log("proposalId: " + proposalId); + log("proposalValue: " + proposalValue.toFixed(3)); + log("proposalTimeEnds: " + proposalTimeEnds); + log("proposalURL: " + proposalURL); + log("proposalSender: " + proposalSender); + + + assert.equal(200000, proposalValue); + + t1 = eventInfo.getNow().toNumber() + 60 * 60 * 24 * 10; + t2 = proposalTimeEnds; + assert(t1, t2); + + assert.equal(proposalURL, "http://pastebin.com/raw/6e9PBTeP"); + assert.equal(proposalSender, "0xcc49bea5129ef2369ff81b0c0200885893979b77"); + + proposal_1 = proposalId; + + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(0, value); + + return true; + }) + +}); + + + +it('object-by-vote-proposal-1', function() { + log(""); + log(" (!) Action: [0x3a7e] vote to object proposal 1"); + + return dstContract_APL.objectProposal(proposal_1, + { + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + gas : 450000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + log_1 = parsed.logs[0]; + + total = dstContract_APL.getPreferedQtySold(); + + log("\n"); + log(log_1.event + ":"); + log("============"); + + log("proposal.id: " + log_1.args.id); + log("voter: " + log_1.args.voter); + log("votes: " + log_1.args.votes + " share: " + (log_1.args.votes / total * 100).toFixed(2) + "%"); + + voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber(); + + assert.equal(proposal_1, log_1.args.id); + assert.equal(log_1.args.voter, "0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d"); + assert.equal(log_1.args.votes, voting); + + return true; + }) + +}); + + +it('roll-time-proposal-redeem', function(){ + + return workbench.rollTimeTo('04-Mar-2017 14:00 UTC+00') + .then(function(contract) { printDate(); return true; }); +}); + + +it('redeem-proposal-1', function() { + log(""); + log(" (!) Action: [0xcc49] collect 1,000.000 HKG value of proposal 1"); + + return dstContract_APL.redeemProposalFunds(proposal_1, + { + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + assert.equal(1, parsed.logs.length); + + args = parsed.logs[0].args; + + assert(dstContract_APL.address, args.from); + assert("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); + assert(200000000, args.value); + + return true; + }) + + .then(function () { + + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(200000, value); + + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(800000, value); + + return true; + }) + +}); + +// +// [X] Submit impeachment less than 3 months from the event finish +// + +it('impeachment-proposal-less-time-from-event-end', function() { + log(""); + log(" [X] Submit impeachment less than 3 months from the event finish"); + + return dstContract_APL.submitImpeachmentProposal("http://pastebin.com/raw/Ehet8yVf", '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', + { + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + gas : 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + log(""); + log("No impeachment was submitted"); + assert.equal(parsed.logs.length, 0); + + return true; + }) + + .then(function () { + + totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); + impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); + + impSupport = (impeachmentSupport / totalPreferred) * 100 + + log(""); + + log("Support for impeachment: " + impSupport + "%"); + assert.equal(0, impSupport); + + log("Executive for now: " + dstContract_APL.getExecutive()); + assert.equal('0xcc49bea5129ef2369ff81b0c0200885893979b77' ,dstContract_APL.getExecutive()); + + return true; + }) + +}); + + + +it('roll-time-to-start-impeachment', function(){ + + return workbench.rollTimeTo('22-Mar-2017 14:00 UTC+00') + .then(function(contract) { printDate(); return true; }); +}); + + +// +// [X] Submit impeachment by non voter +// + +it('impeachment-proposal-by-non-voter', function() { + log(""); + log(" [X] Action: submit impeachment by non voter"); + + return dstContract_APL.submitImpeachmentProposal("http://pastebin.com/raw/Ehet8yVf", '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', + { + from : '0x36cef404bd674e1aa6ba6b444c9ef458460c9871', + gas : 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + log(""); + log("No impeachment was submitted"); + assert.equal(parsed.logs.length, 0); + + return true; + }) + + .then(function () { + + totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); + impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); + + impSupport = (impeachmentSupport / totalPreferred) * 100 + + log(""); + + log("Support for impeachment: " + impSupport + "%"); + assert.equal(0, impSupport); + + log("Executive for now: " + dstContract_APL.getExecutive()); + assert.equal('0xcc49bea5129ef2369ff81b0c0200885893979b77' ,dstContract_APL.getExecutive()); + + return true; + }) + +}); + + + +it('impeachment-proposal-submit-1', function() { + log(""); + log(" (!) Action: [0x3a7e] submit impeachment proposal"); + + return dstContract_APL.submitImpeachmentProposal("http://pastebin.com/raw/Ehet8yVf", '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', + { + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + gas : 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + args = parsed.logs[0].args; + + log(""); + + log("ImpeachmentProposed (event)"); + log("==================="); + + + assert.equal("ImpeachmentProposed", parsed.logs[0].event); + + log("Submited by: " + args.submitter); + assert.equal("0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d", args.submitter); + + assert.equal("http://pastebin.com/raw/Ehet8yVf", args.urlDetails); + assert.equal("0xdedb49385ad5b94a16f236a6890cf9e0b1e30392", args.newExecutive); + + expectedEndTime = new Date('05-Apr-2017 14:00 UTC+00').getTime() / 1000; + assert.equal(expectedEndTime, args.votindEndTS); + + return true; + }) + + .then(function () { + + totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); + impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); + + impSupport = (impeachmentSupport / totalPreferred) * 100 + + log(""); + + log("Support for impeachment: " + impSupport + "%"); + assert.equal(30, impSupport); + + log("Executive for now: " + dstContract_APL.getExecutive()); + assert.equal('0xcc49bea5129ef2369ff81b0c0200885893979b77' ,dstContract_APL.getExecutive()); + + return true; + }) + +}); + + + + +it('impeachment-proposal-support-1', function() { + log(""); + log(" (!) Action: [0x2980] support impeachment proposal"); + + return dstContract_APL.supportImpeachment( + { + from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + gas : 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + args = parsed.logs[0].args; + + log(""); + + log("ImpeachmentSupport (event)"); + log("=================="); + + assert.equal("ImpeachmentSupport", parsed.logs[0].event); + + log("Submited by: " + args.supportter); + assert.equal("0x29805ff5b946e7a7c5871c1fb071f740f767cf41", args.supportter); + + log("[0x2980] submited " + args.votes + " votes"); + assert.equal(300000000000, args.votes.toNumber()); + + return true; + }) + + .then(function () { + + totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); + impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); + + impSupport = (impeachmentSupport / totalPreferred) * 100 + + log(""); + + log("Support for impeachment: " + impSupport + "%"); + assert.equal(60, impSupport); + + log("Executive for now: " + dstContract_APL.getExecutive()); + assert.equal('0xcc49bea5129ef2369ff81b0c0200885893979b77' ,dstContract_APL.getExecutive()); + + return true; + }) + +}); + +// +// [X] Support impeachment by a non voter +// + +it('impeachment-proposal-support-by-non-voter', function() { + log(""); + log(" [X] Support impeachment by a non voter"); + + return dstContract_APL.supportImpeachment( + { + from : '0x36cef404bd674e1aa6ba6b444c9ef458460c9871', + gas : 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + assert.equal(parsed.logs.length, 0); + log(""); + + log("No support event generated"); + + return true; + }) + + .then(function () { + + totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); + impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); + + impSupport = (impeachmentSupport / totalPreferred) * 100 + + log(""); + + log("Support for impeachment: " + impSupport + "%"); + assert.equal(60, impSupport); + + log("Executive for now: " + dstContract_APL.getExecutive()); + assert.equal('0xcc49bea5129ef2369ff81b0c0200885893979b77' ,dstContract_APL.getExecutive()); + + return true; + }) + +}); + + + +// +// [X] Support impeachment by a an already voted voter +// + +it('impeachment-proposal-support-by-already-voter', function() { + log(""); + log(" [X] Support impeachment by a an already voted voter "); + + return dstContract_APL.supportImpeachment( + { + from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + gas : 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + assert.equal(parsed.logs.length, 0); + log(""); + + log("No support event generated"); + + return true; + }) + + .then(function () { + + totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); + impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); + + impSupport = (impeachmentSupport / totalPreferred) * 100 + + log(""); + + log("Support for impeachment: " + impSupport + "%"); + assert.equal(60, impSupport); + + log("Executive for now: " + dstContract_APL.getExecutive()); + assert.equal('0xcc49bea5129ef2369ff81b0c0200885893979b77' ,dstContract_APL.getExecutive()); + + return true; + }) + +}); + + +it('impeachment-proposal-support-2', function() { + log(""); + log(" (!) Action: [0x696b] support impeachment proposal"); + + return dstContract_APL.supportImpeachment( + { + from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', + gas : 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function (parsed) { + + args = parsed.logs[0].args; + + log(""); + + log("ImpeachmentSupport (event)"); + log("=================="); + + assert.equal("ImpeachmentSupport", parsed.logs[0].event); + + log("Submited by: " + args.supportter); + assert.equal("0x696ba93ef4254da47ff05b6caa88190db335f1c3", args.supportter); + + log("[0x696b] submited " + args.votes + " votes"); + assert.equal(400000000000, args.votes.toNumber()); + + return true; + }) + + .then(function () { + + + totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); + impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); + + impSupport = (impeachmentSupport / totalPreferred) * 100 + + log(""); + + log("Support for impeachment: " + impSupport + "%"); + assert.equal(100, impSupport); + + log("New executive appointed: " + dstContract_APL.getExecutive()); + assert.equal('0xdedb49385ad5b94a16f236a6890cf9e0b1e30392' ,dstContract_APL.getExecutive()); + + return true; + }) + +}); + + + +it('roll-time-to-start-2nd-impeachment', function(){ + + return workbench.rollTimeTo('22-Apr-2017 14:00 UTC+00') + .then(function(contract) { printDate(); return true; }); +}); + + +it('impeachment-proposal-submit-2', function() { + log(""); + log(" (!) Action: [0x3a7e] submit impeachment proposal"); + + return dstContract_APL.submitImpeachmentProposal("http://pastebin.com/raw/Ehet8yVf", '0xcc49bea5129ef2369ff81b0c0200885893979b77', + { + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + gas : 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + args = parsed.logs[0].args; + + log(""); + + log("ImpeachmentProposed (event)"); + log("==================="); + + + assert.equal("ImpeachmentProposed", parsed.logs[0].event); + + log("Submited by: " + args.submitter); + assert.equal("0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d", args.submitter); + + assert.equal("http://pastebin.com/raw/Ehet8yVf", args.urlDetails); + assert.equal("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.newExecutive); + + expectedEndTime = new Date('06-May-2017 14:00 UTC+00').getTime() / 1000; + assert.equal(expectedEndTime, args.votindEndTS); + + return true; + }) + + .then(function () { + + totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); + impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); + + impSupport = (impeachmentSupport / totalPreferred) * 100 + + log(""); + + log("Support for impeachment: " + impSupport + "%"); + assert.equal(30, impSupport); + + log("Executive for now: " + dstContract_APL.getExecutive()); + assert.equal('0xdedb49385ad5b94a16f236a6890cf9e0b1e30392' ,dstContract_APL.getExecutive()); + + return true; + }) + +}); + + +it('roll-time-to-end-voting-2nd-impeachment', function(){ + + return workbench.rollTimeTo('06-May-2017 14:00 UTC+00') + .then(function(contract) { printDate(); return true; }); +}); + + +// +// [X] Support impeachment after the time for voting ended +// + +it('support-impeachment-after-timeover', function() { + log(""); + log(" [X] Support impeachment after the time for voting ended "); + + return dstContract_APL.supportImpeachment( + { + from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + gas : 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + assert.equal(parsed.logs.length, 0); + log(""); + + log("No support event generated"); + + return true; + }) + + .then(function () { + + totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); + impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); + + impSupport = (impeachmentSupport / totalPreferred) * 100 + + log(""); + + log("Support for impeachment: " + impSupport + "%"); + assert.equal(30, impSupport); + + log("Executive for now: " + dstContract_APL.getExecutive()); + assert.equal('0xdedb49385ad5b94a16f236a6890cf9e0b1e30392' ,dstContract_APL.getExecutive()); + + return true; + }) + +}); + + +// +// [X] Submit another impeachment before 1 month from the last passed +// + +it('impeachment-proposal-submit-3', function() { + log(""); + log(" [X] Submit another impeachment before 1 month from the last passed"); + + return dstContract_APL.submitImpeachmentProposal("http://pastebin.com/raw/Ehet8yVf", '0xcc49bea5129ef2369ff81b0c0200885893979b77', + { + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + gas : 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + assert.equal(parsed.logs.length, 0); + log(""); + + log("Rejected to accept new submission proposal"); + + return true; + }) + + .then(function () { + return true; + }) + +}); + + +}); diff --git a/test/dst-management/impeachment-test-2.js b/test/dst-management/impeachment-test-2.js index 63830d1..83b963c 100644 --- a/test/dst-management/impeachment-test-2.js +++ b/test/dst-management/impeachment-test-2.js @@ -1,97 +1,97 @@ -var assert = require('assert'); - -var log = console.log; - -var Workbench = require('ethereum-sandbox-workbench'); -var workbench = new Workbench({ - defaults: { - from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826' - }, - - solcVersion: '0.4.2' -}); - -workbench.startTesting(['StandardToken', 'EventInfo', 'DSTContract', 'VirtualExchange'], function(contracts) { - -var sandbox = workbench.sandbox; - -// deployed contracts -var eventInfo; -var hackerGold; +var assert = require('assert'); + +var log = console.log; + +var Workbench = require('ethereum-sandbox-workbench'); +var workbench = new Workbench({ + defaults: { + from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826' + }, + + solcVersion: '0.4.2' +}); + +workbench.startTesting(['StandardToken', 'EventInfo', 'DSTContract', 'VirtualExchange'], function(contracts) { + +var sandbox = workbench.sandbox; + +// deployed contracts +var eventInfo; +var hackerGold; var virtualExchange; - -var dstContract_APL; // Awesome Poker League - -function printDate(){ - now = eventInfo.getNow().toNumber(); - var date = new Date(now*1000); - - log('\n Date now: ' + date + '\n'); -} - - -/** - * - * Testing for impeachment: - * - * 1. Voting structure 30%, 30%, 30%, 10% - * 2. Submit impeachment proposal - * 3. Support the impeachment proposal by 70% - * - */ - -it('event-info-init', function() { - - log(''); - log(' ***********************'); - log(' impeachment-test-1.js '); - log(' ***********************'); - log(''); - - return contracts.EventInfo.new() - - .then(function(contract) { - - if (contract.address){ - eventInfo = contract; - } else { - throw new Error('No contract address'); - } - - return true; - }) - - .then(function() { - - printDate(); - return true; - }); - -}); - + +var dstContract_APL; // Awesome Poker League + +function printDate(){ + now = eventInfo.getNow().toNumber(); + var date = new Date(now*1000); + + log('\n Date now: ' + date + '\n'); +} + + +/** + * + * Testing for impeachment: + * + * 1. Voting structure 30%, 30%, 30%, 10% + * 2. Submit impeachment proposal + * 3. Support the impeachment proposal by 70% + * + */ + +it('event-info-init', function() { + + log(''); + log(' ***********************'); + log(' impeachment-test-1.js '); + log(' ***********************'); + log(''); + + return contracts.EventInfo.new() + + .then(function(contract) { + + if (contract.address){ + eventInfo = contract; + } else { + throw new Error('No contract address'); + } + + return true; + }) + + .then(function() { + + printDate(); + return true; + }); + +}); + it('hacker-gold-init', function() { return contracts.HackerGold.new() .then(function(contract) { - + if (contract.address){ hackerGold = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); - + it('roll-time-ve-trading-start', function(){ - - // Roll time to get best price on HKG, - // 1 Ether for 200 HKG + + // Roll time to get best price on HKG, + // 1 Ether for 200 HKG return workbench.rollTimeTo('30-Oct-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -99,119 +99,119 @@ it('roll-time-ve-trading-start', function(){ it('buy-hkg-for-3a7e', function() { log(""); - log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); + log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); return workbench.sendTransaction({ from: '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', to: hackerGold.address, value: sandbox.web3.toWei(10000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); assert.equal(2000000, value); - - return true; + + return true; }) - + }); it('buy-hkg-for-2980', function() { log(""); - log(" (!) Action: [0x2980] buy [HKG] for 10,000.000 Ether"); + log(" (!) Action: [0x2980] buy [HKG] for 10,000.000 Ether"); return workbench.sendTransaction({ from: '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', to: hackerGold.address, value: sandbox.web3.toWei(10000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; - + log("[0x2980] => balance: " + value.toFixed(3) + " HKG"); assert.equal(2000000, value); - - return true; + + return true; }) - + }); it('buy-hkg-for-696b', function() { log(""); - log(" (!) Action: [0x696b] buy [HKG] for 5000.000 Ether"); + log(" (!) Action: [0x696b] buy [HKG] for 5000.000 Ether"); return workbench.sendTransaction({ from: '0x696ba93ef4254da47ff05b6caa88190db335f1c3', to: hackerGold.address, value: sandbox.web3.toWei(10000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; - + log("[0x696b] => balance: " + value.toFixed(3) + " HKG"); assert.equal(2000000, value); - - return true; + + return true; }) - + }); it('buy-hkg-for-cd2a', function() { log(""); - log(" (!) Action: [0xcd2a] buy [HKG] for 5000.000 Ether"); + log(" (!) Action: [0xcd2a] buy [HKG] for 5000.000 Ether"); return workbench.sendTransaction({ from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', to: hackerGold.address, value: sandbox.web3.toWei(10000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826').toNumber() / 1000; - + log("[0xcd2a] => balance: " + value.toFixed(3) + " HKG"); assert.equal(2000000, value); - - return true; + + return true; }) - + }); it('roll-time-ve-trading-start', function(){ - + return workbench.rollTimeTo('24-Nov-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -221,39 +221,39 @@ it('roll-time-ve-trading-start', function(){ it('virtual-exchange-init', function() { - return contracts.VirtualExchange.new(hackerGold.address, + return contracts.VirtualExchange.new(hackerGold.address, eventInfo.address) .then(function(contract) { - + if (contract.address){ virtualExchange = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); it('dst-contract-apl-init', function() { - return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", - + return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", + { from : '0xcc49bea5129ef2369ff81b0c0200885893979b77' }) .then(function(contract) { - + if (contract.address){ dstContract_APL = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); @@ -262,47 +262,47 @@ it('enlist-apl', function() { log(""); log(" (!) Action: [VE] enlist [APL] for trading"); - return virtualExchange.enlist(dstContract_APL.address, + return virtualExchange.enlist(dstContract_APL.address, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) - + .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) - + .then(function() { - - exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); - + + exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); + log("[APL] => enlisted: " + exist); assert.equal(true, exist); - + return true; }) - + }); it('issue-apl-tokens-seria-1', function() { log(""); log(" (!) Action: [APL] issue tokens on [VE] balance 1,000,000,000,000.000 APL"); - - return dstContract_APL.issuePreferedTokens(1000, 1000000000000, + + return dstContract_APL.issuePreferedTokens(1000, 1000000000000, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) .then(function () { - + dst1Total = dstContract_APL.getTotalSupply().toNumber() / 1000; - + log("[APL] => total suply: " + dst1Total.toFixed(3) + " APL"); assert(1000000000000, dst1Total); - - veTokens = dstContract_APL.allowance(dstContract_APL.address, + + veTokens = dstContract_APL.allowance(dstContract_APL.address, virtualExchange.address).toNumber() / 1000; log("[APL] => total on VirtualExchange: " + veTokens.toFixed(3) + " APL"); assert(1000000000000, veTokens); @@ -310,764 +310,758 @@ it('issue-apl-tokens-seria-1', function() { return true; }) }); - - - -it('approve-hkg-spend-on-exchange-for-3a7e', function() { - log(""); - log(" (!) Action: [0x3a7e] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 2000000000, - { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - }) - - .then(function () { - - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - virtualExchange.address).toNumber() / 1000; - - log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(2000000, veTokens); - - return true; - }) -}); - - -it('approve-hkg-spend-on-exchange-for-2980', function() { - log(""); - log(" (!) Action: [0x2980] move to [VE] balance 2,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 2000000000, - { - from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - }) - - .then(function () { - - veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', - virtualExchange.address).toNumber() / 1000; - - log("[0x2980] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(2000000, veTokens); - - return true; - }) -}); - - -it('approve-hkg-spend-on-exchange-for-696b', function() { - log(""); - log(" (!) Action: [0x696b] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 2000000000, - { - from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - }) - - .then(function () { - - veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', - virtualExchange.address).toNumber() / 1000; - - log("[0x696b] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(2000000, veTokens); - - return true; - }) -}); - - - -it('approve-hkg-spend-on-exchange-for-cd2a', function() { - log(""); - log(" (!) Action: [0xcd2a] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 2000000000, - { - from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - }) - - .then(function () { - - veTokens = hackerGold.allowance('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', - virtualExchange.address).toNumber() / 1000; - - log("[0xcd2a] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(2000000, veTokens); - - return true; - }) -}); - - -it('buy-apl-by-3a7e', function() { - log(""); - log(" (!) Action: [0x3a7e] buy tokens [APL] for 300,000.000 HKG"); - - - return virtualExchange.buy('APL', 300000000, - { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - gas: 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function () { - - dst1Balance = dstContract_APL.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - - log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " APL"); - assert.equal(300000000 , dst1Balance); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - - log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(300000000000 , voting); - - value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - - log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(1700000, value); - - log ("[APL] => total: " + total + " votes"); - assert.equal(300000000000, total); - - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - virtualExchange.address).toNumber() / 1000; - log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(1700000 , veTokens); - - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - assert.equal(700000000 , availableSuply); - - return true; - }) -}); - - - - -it('buy-apl-by-2980', function() { - log(""); - log(" (!) Action: [0x2980] buy tokens [APL] for 300,000.000 HKG"); - - - return virtualExchange.buy('APL', 300000000, - { - from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', - gas: 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function () { - - dst1Balance = dstContract_APL.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; - - log("[0x2980] => balance: " + dst1Balance.toFixed(3) + " APL"); - assert.equal(300000000 , dst1Balance); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); - - log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(300000000000 , voting); - - value = hackerGold.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; - - log("[0x2980] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(1700000, value); - - log ("[APL] => total: " + total + " votes"); - - veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', - virtualExchange.address).toNumber() / 1000; - log("[0x2980] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(1700000 , veTokens); - - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - - - log(""); - log(" Voting Summary: "); - log(" =============== "); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - - log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(50, voting / total * 100); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); - - log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(50, voting / total * 100); - - value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => collected: " + value.toFixed(3) + " HKG"); - assert.equal(600000, value); - - return true; - }) -}); - - - - -it('buy-apl-by-696b', function() { - log(""); - log(" (!) Action: [0x696b] buy tokens [APL] for 300,000.000 HKG"); - - - return virtualExchange.buy('APL', 300000000, - { - from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', - gas: 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - }) - - .then(function () { - - dst1Balance = dstContract_APL.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; - - log("[0x696b] => balance: " + dst1Balance.toFixed(3) + " APL"); - assert.equal(300000000 , dst1Balance); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3'); - - log ("[0x696b] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(300000000000 , voting); - - value = hackerGold.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; - - log("[0x696b] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(1700000, value); - - log ("[APL] => total: " + total + " votes"); - - veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', - virtualExchange.address).toNumber() / 1000; - log("[0x696b] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(1700000 , veTokens); - - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - - - log(""); - log(" Voting Summary: "); - log(" =============== "); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - - log ("[0x3a7e] => voting: " + voting + " votes - " + (voting / total * 100).toFixed(2) + "%"); - assert.equal(33.33, (voting / total * 100).toFixed(2)); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); - - log ("[0x2980] => voting: " + voting + " votes - " + (voting / total * 100).toFixed(2) + "%"); - assert.equal(33.33, (voting / total * 100).toFixed(2)); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3'); - - log ("[0x696b] => voting: " + voting + " votes - " + (voting / total * 100).toFixed(2) + "%"); - assert.equal(33.33, (voting / total * 100).toFixed(2)); - - value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => collected: " + value.toFixed(3) + " HKG"); - assert.equal(900000, value); - - return true; - }) -}); - - - -it('buy-apl-by-cd2a', function() { - log(""); - log(" (!) Action: [cd2a] buy tokens [APL] for 100,000.000 HKG"); - - - return virtualExchange.buy('APL', 100000000, - { - from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', - gas: 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - }) - - .then(function () { - - dst1Balance = dstContract_APL.balanceOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826').toNumber() / 1000; - - log("[0xcd2a] => balance: " + dst1Balance.toFixed(3) + " APL"); - assert.equal(100000000 , dst1Balance); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826'); - - log ("[0xcd2a] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(100000000000 , voting); - - value = hackerGold.balanceOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826').toNumber() / 1000; - - log("[0xcd2a] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(1900000, value); - - log ("[APL] => total: " + total + " votes"); - - veTokens = hackerGold.allowance('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', - virtualExchange.address).toNumber() / 1000; - log("[0xcd2a] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(1900000 , veTokens); - - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - - - log(""); - log(" Voting Summary: "); - log(" =============== "); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - - log ("[0x3a7e] => voting: " + voting + " votes - " + (voting / total * 100) + "%"); - assert.equal(30, (voting / total * 100).toFixed(2)); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); - - log ("[0x2980] => voting: " + voting + " votes - " + (voting / total * 100) + "%"); - assert.equal(30, (voting / total * 100).toFixed(2)); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3'); - - log ("[0x696b] => voting: " + voting + " votes - " + (voting / total * 100) + "%"); - assert.equal(30, (voting / total * 100).toFixed(2)); - - total = dstContract_APL.getPreferedQtySold(); - voting = dstContract_APL.votingRightsOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826'); - - log ("[0xcd2a] => voting: " + voting + " votes - " + (voting / total * 100) + "%"); - assert.equal(10, (voting / total * 100).toFixed(2)); - - value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => collected: " + value.toFixed(3) + " HKG"); - assert.equal(1000000, value); - - return true; - }) -}); - - -it('roll-time-va-ends', function(){ - - return workbench.rollTimeTo('22-Dec-2016 14:00 UTC+00') - .then(function(contract) { printDate(); return true; }); -}); - - -it('roll-time-50%-available', function(){ - - return workbench.rollTimeTo('22-Feb-2017 14:00 UTC+00') - .then(function(contract) { printDate(); return true; }); -}); - -it('submit-proposal-1', function() { - log(""); - log(" (!) Action: [0xcc49] ask to recieve 200,000.000 (20%) of the HKG collected"); - - return dstContract_APL.submitHKGProposal(200000000, "http://pastebin.com/raw/6e9PBTeP", - { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 450000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function (parsed) { - - args = parsed.logs[0].args; - - proposalId = args.id; - proposalValue = args.value; - proposalValue = proposalValue / 1000; - - proposalTimeEnds = args.timeEnds; - proposalURL = args.url; - proposalSender = args.sender; - - log(""); - log("Proposal Submitted"); - log("=================="); - - log("proposalId: " + proposalId); - log("proposalValue: " + proposalValue.toFixed(3)); - log("proposalTimeEnds: " + proposalTimeEnds); - log("proposalURL: " + proposalURL); - log("proposalSender: " + proposalSender); - - - assert.equal(200000, proposalValue); - - t1 = eventInfo.getNow().toNumber() + 60 * 60 * 24 * 10; - t2 = proposalTimeEnds; - assert(t1, t2); - - assert.equal(proposalURL, "http://pastebin.com/raw/6e9PBTeP"); - assert.equal(proposalSender, "0xcc49bea5129ef2369ff81b0c0200885893979b77"); - - proposal_1 = proposalId; - - value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(0, value); - - return true; - }) - -}); - - - -it('object-by-vote-proposal-1', function() { - log(""); - log(" (!) Action: [0x3a7e] vote to object proposal 1"); - - return dstContract_APL.objectProposal(proposal_1, - { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - gas : 450000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function (parsed) { - - log_1 = parsed.logs[0]; - - total = dstContract_APL.getPreferedQtySold(); - - log("\n"); - log(log_1.event + ":"); - log("============"); - - log("proposal.id: " + log_1.args.id); - log("voter: " + log_1.args.voter); - log("votes: " + log_1.args.votes + " share: " + (log_1.args.votes / total * 100).toFixed(2) + "%"); - - voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber(); - - assert.equal(proposal_1, log_1.args.id); - assert.equal(log_1.args.voter, "0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d"); - assert.equal(log_1.args.votes, voting); - - return true; - }) - -}); - - -it('roll-time-proposal-redeem', function(){ - - return workbench.rollTimeTo('04-Mar-2017 14:00 UTC+00') - .then(function(contract) { printDate(); return true; }); -}); - - -it('redeem-proposal-1', function() { - log(""); - log(" (!) Action: [0xcc49] collect 1,000.000 HKG value of proposal 1"); - - return dstContract_APL.redeemProposalFunds(proposal_1, - { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function (parsed) { - - assert.equal(1, parsed.logs.length); - - args = parsed.logs[0].args; - - assert(dstContract_APL.address, args.from); - assert("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); - assert(200000000, args.value); - - return true; - }) - - .then(function () { - - value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(200000, value); - - value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(800000, value); - - return true; - }) - -}); - - - -it('roll-time-to-start-impeachment', function(){ - return workbench.rollTimeTo('22-Mar-2017 14:00 UTC+00') - .then(function(contract) { printDate(); return true; }); -}); - - - -it('impeachment-proposal-submit-1', function() { - log(""); - log(" (!) Action: [0x3a7e] submit impeachment proposal"); - - return dstContract_APL.submitImpeachmentProposal("http://pastebin.com/raw/Ehet8yVf", '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', - { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - gas : 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function (parsed) { - - args = parsed.logs[0].args; - - log(""); - - log("ImpeachmentProposed (event)"); - log("==================="); - - - assert.equal("ImpeachmentProposed", parsed.logs[0].event); - - log("Submited by: " + args.submitter); - assert.equal("0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d", args.submitter); - - assert.equal("http://pastebin.com/raw/Ehet8yVf", args.urlDetails); - assert.equal("0xdedb49385ad5b94a16f236a6890cf9e0b1e30392", args.newExecutive); - - expectedEndTime = new Date('05-Apr-2017 14:00 UTC+00').getTime() / 1000; - assert.equal(expectedEndTime, args.votindEndTS); - - return true; - }) - - .then(function () { - - totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); - impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); - - impSupport = (impeachmentSupport / totalPreferred) * 100 - - log(""); - - log("Support for impeachment: " + impSupport + "%"); - assert.equal(30, impSupport); - - log("Executive for now: " + dstContract_APL.getExecutive()); - assert.equal('0xcc49bea5129ef2369ff81b0c0200885893979b77' ,dstContract_APL.getExecutive()); - - return true; - }) - -}); - - -it('impeachment-proposal-support-1', function() { - log(""); - log(" (!) Action: [0x2980] support impeachment proposal"); - - return dstContract_APL.supportImpeachment( - { - from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', - gas : 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function (parsed) { - - args = parsed.logs[0].args; - - log(""); - - log("ImpeachmentSupport (event)"); - log("=================="); - - assert.equal("ImpeachmentSupport", parsed.logs[0].event); - - log("Submited by: " + args.supportter); - assert.equal("0x29805ff5b946e7a7c5871c1fb071f740f767cf41", args.supportter); - - log("[0x2980] submited " + args.votes + " votes"); - assert.equal(300000000000, args.votes.toNumber()); - - return true; - }) - - .then(function () { - - totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); - impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); - - impSupport = (impeachmentSupport / totalPreferred) * 100 - - log(""); - - log("Support for impeachment: " + impSupport + "%"); - assert.equal(60, impSupport); - - log("Executive for now: " + dstContract_APL.getExecutive()); - assert.equal('0xcc49bea5129ef2369ff81b0c0200885893979b77' ,dstContract_APL.getExecutive()); - - return true; - }) -}); - - - -it('impeachment-proposal-support-2', function() { - log(""); - log(" (!) Action: [0xcd2a] support impeachment proposal"); - - return dstContract_APL.supportImpeachment( - { - from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', - gas : 250000, - }) - - .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - - }) - - .then(function (parsed) { - - args = parsed.logs[0].args; - - log(""); - - log("ImpeachmentSupport (event)"); - log("=================="); - - assert.equal("ImpeachmentSupport", parsed.logs[0].event); - - log("Submited by: " + args.supportter); - assert.equal("0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826", args.supportter); - - log("[0x2980] submited " + args.votes + " votes"); - assert.equal(100000000000, args.votes.toNumber()); - - return true; - }) - - .then(function () { - - totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); - impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); - - impSupport = (impeachmentSupport / totalPreferred) * 100 - - log(""); - - log("Support for impeachment: " + impSupport + "%"); - assert.equal(70, impSupport); - - log("Executive for now: " + dstContract_APL.getExecutive()); - assert.equal('0xdedb49385ad5b94a16f236a6890cf9e0b1e30392' ,dstContract_APL.getExecutive()); - - return true; - }) - -}); - - - - -}); - - - - - - + + + +it('approve-hkg-spend-on-exchange-for-3a7e', function() { + log(""); + log(" (!) Action: [0x3a7e] move to [VE] balance 1,000,000.000 HKG"); + + return hackerGold.approve(virtualExchange.address, 2000000000, + { + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function () { + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + virtualExchange.address).toNumber() / 1000; + + log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(2000000, veTokens); + + return true; + }) +}); + + +it('approve-hkg-spend-on-exchange-for-2980', function() { + log(""); + log(" (!) Action: [0x2980] move to [VE] balance 2,000,000.000 HKG"); + + return hackerGold.approve(virtualExchange.address, 2000000000, + { + from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function () { + + veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + virtualExchange.address).toNumber() / 1000; + + log("[0x2980] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(2000000, veTokens); + + return true; + }) +}); + + +it('approve-hkg-spend-on-exchange-for-696b', function() { + log(""); + log(" (!) Action: [0x696b] move to [VE] balance 1,000,000.000 HKG"); + + return hackerGold.approve(virtualExchange.address, 2000000000, + { + from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function () { + + veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', + virtualExchange.address).toNumber() / 1000; + + log("[0x696b] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(2000000, veTokens); + + return true; + }) +}); + + + +it('approve-hkg-spend-on-exchange-for-cd2a', function() { + log(""); + log(" (!) Action: [0xcd2a] move to [VE] balance 1,000,000.000 HKG"); + + return hackerGold.approve(virtualExchange.address, 2000000000, + { + from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function () { + + veTokens = hackerGold.allowance('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + virtualExchange.address).toNumber() / 1000; + + log("[0xcd2a] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(2000000, veTokens); + + return true; + }) +}); + + +it('buy-apl-by-3a7e', function() { + log(""); + log(" (!) Action: [0x3a7e] buy tokens [APL] for 300,000.000 HKG"); + + + return virtualExchange.buy('APL', 300000000, + { + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + gas: 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function () { + + dst1Balance = dstContract_APL.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; + + log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " APL"); + assert.equal(300000000 , dst1Balance); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); + + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(300000000000 , voting); + + value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; + + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(1700000, value); + + log ("[APL] => total: " + total + " votes"); + assert.equal(300000000000, total); + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + virtualExchange.address).toNumber() / 1000; + log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(1700000 , veTokens); + + availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available suply: " + availableSuply + " APL"); + assert.equal(700000000 , availableSuply); + + return true; + }) +}); + + + + +it('buy-apl-by-2980', function() { + log(""); + log(" (!) Action: [0x2980] buy tokens [APL] for 300,000.000 HKG"); + + + return virtualExchange.buy('APL', 300000000, + { + from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + gas: 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function () { + + dst1Balance = dstContract_APL.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; + + log("[0x2980] => balance: " + dst1Balance.toFixed(3) + " APL"); + assert.equal(300000000 , dst1Balance); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); + + log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(300000000000 , voting); + + value = hackerGold.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; + + log("[0x2980] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(1700000, value); + + log ("[APL] => total: " + total + " votes"); + + veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + virtualExchange.address).toNumber() / 1000; + log("[0x2980] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(1700000 , veTokens); + + availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available suply: " + availableSuply + " APL"); + + + log(""); + log(" Voting Summary: "); + log(" =============== "); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); + + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(50, voting / total * 100); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); + + log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(50, voting / total * 100); + + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => collected: " + value.toFixed(3) + " HKG"); + assert.equal(600000, value); + + return true; + }) +}); + + + + +it('buy-apl-by-696b', function() { + log(""); + log(" (!) Action: [0x696b] buy tokens [APL] for 300,000.000 HKG"); + + + return virtualExchange.buy('APL', 300000000, + { + from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', + gas: 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function () { + + dst1Balance = dstContract_APL.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; + + log("[0x696b] => balance: " + dst1Balance.toFixed(3) + " APL"); + assert.equal(300000000 , dst1Balance); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3'); + + log ("[0x696b] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(300000000000 , voting); + + value = hackerGold.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; + + log("[0x696b] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(1700000, value); + + log ("[APL] => total: " + total + " votes"); + + veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', + virtualExchange.address).toNumber() / 1000; + log("[0x696b] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(1700000 , veTokens); + + availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available suply: " + availableSuply + " APL"); + + + log(""); + log(" Voting Summary: "); + log(" =============== "); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); + + log ("[0x3a7e] => voting: " + voting + " votes - " + (voting / total * 100).toFixed(2) + "%"); + assert.equal(33.33, (voting / total * 100).toFixed(2)); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); + + log ("[0x2980] => voting: " + voting + " votes - " + (voting / total * 100).toFixed(2) + "%"); + assert.equal(33.33, (voting / total * 100).toFixed(2)); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3'); + + log ("[0x696b] => voting: " + voting + " votes - " + (voting / total * 100).toFixed(2) + "%"); + assert.equal(33.33, (voting / total * 100).toFixed(2)); + + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => collected: " + value.toFixed(3) + " HKG"); + assert.equal(900000, value); + + return true; + }) +}); + + +//TODO: if impeachment files are the same until here we should refactor +it('buy-apl-by-cd2a', function() { + log(""); + log(" (!) Action: [cd2a] buy tokens [APL] for 100,000.000 HKG"); + + + return virtualExchange.buy('APL', 100000000, + { + from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + gas: 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function () { + + dst1Balance = dstContract_APL.balanceOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826').toNumber() / 1000; + + log("[0xcd2a] => balance: " + dst1Balance.toFixed(3) + " APL"); + assert.equal(100000000 , dst1Balance); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826'); + + log ("[0xcd2a] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(100000000000 , voting); + + value = hackerGold.balanceOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826').toNumber() / 1000; + + log("[0xcd2a] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(1900000, value); + + log ("[APL] => total: " + total + " votes"); + + veTokens = hackerGold.allowance('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + virtualExchange.address).toNumber() / 1000; + log("[0xcd2a] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(1900000 , veTokens); + + availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available suply: " + availableSuply + " APL"); + + + log(""); + log(" Voting Summary: "); + log(" =============== "); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); + + log ("[0x3a7e] => voting: " + voting + " votes - " + (voting / total * 100) + "%"); + assert.equal(30, (voting / total * 100).toFixed(2)); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); + + log ("[0x2980] => voting: " + voting + " votes - " + (voting / total * 100) + "%"); + assert.equal(30, (voting / total * 100).toFixed(2)); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3'); + + log ("[0x696b] => voting: " + voting + " votes - " + (voting / total * 100) + "%"); + assert.equal(30, (voting / total * 100).toFixed(2)); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826'); + + log ("[0xcd2a] => voting: " + voting + " votes - " + (voting / total * 100) + "%"); + assert.equal(10, (voting / total * 100).toFixed(2)); + + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => collected: " + value.toFixed(3) + " HKG"); + assert.equal(1000000, value); + + return true; + }) +}); + + +it('roll-time-va-ends', function(){ + + return workbench.rollTimeTo('22-Dec-2016 14:00 UTC+00') + .then(function(contract) { printDate(); return true; }); +}); + + +it('roll-time-50%-available', function(){ + + return workbench.rollTimeTo('22-Feb-2017 14:00 UTC+00') + .then(function(contract) { printDate(); return true; }); +}); + +it('submit-proposal-1', function() { + log(""); + log(" (!) Action: [0xcc49] ask to recieve 200,000.000 (20%) of the HKG collected"); + + return dstContract_APL.submitHKGProposal(200000000, "http://pastebin.com/raw/6e9PBTeP", + { + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 450000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + args = parsed.logs[0].args; + + proposalId = args.id; + proposalValue = args.value; + proposalValue = proposalValue / 1000; + + proposalTimeEnds = args.timeEnds; + proposalURL = args.url; + proposalSender = args.sender; + + log(""); + log("Proposal Submitted"); + log("=================="); + + log("proposalId: " + proposalId); + log("proposalValue: " + proposalValue.toFixed(3)); + log("proposalTimeEnds: " + proposalTimeEnds); + log("proposalURL: " + proposalURL); + log("proposalSender: " + proposalSender); + + + assert.equal(200000, proposalValue); + + t1 = eventInfo.getNow().toNumber() + 60 * 60 * 24 * 10; + t2 = proposalTimeEnds; + assert(t1, t2); + + assert.equal(proposalURL, "http://pastebin.com/raw/6e9PBTeP"); + assert.equal(proposalSender, "0xcc49bea5129ef2369ff81b0c0200885893979b77"); + + proposal_1 = proposalId; + + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(0, value); + + return true; + }) + +}); + + + +it('object-by-vote-proposal-1', function() { + log(""); + log(" (!) Action: [0x3a7e] vote to object proposal 1"); + + return dstContract_APL.objectProposal(proposal_1, + { + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + gas : 450000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + log_1 = parsed.logs[0]; + + total = dstContract_APL.getPreferedQtySold(); + + log("\n"); + log(log_1.event + ":"); + log("============"); + + log("proposal.id: " + log_1.args.id); + log("voter: " + log_1.args.voter); + log("votes: " + log_1.args.votes + " share: " + (log_1.args.votes / total * 100).toFixed(2) + "%"); + + voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber(); + + assert.equal(proposal_1, log_1.args.id); + assert.equal(log_1.args.voter, "0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d"); + assert.equal(log_1.args.votes, voting); + + return true; + }) + +}); + + +it('roll-time-proposal-redeem', function(){ + + return workbench.rollTimeTo('04-Mar-2017 14:00 UTC+00') + .then(function(contract) { printDate(); return true; }); +}); + + +it('redeem-proposal-1', function() { + log(""); + log(" (!) Action: [0xcc49] collect 1,000.000 HKG value of proposal 1"); + + return dstContract_APL.redeemProposalFunds(proposal_1, + { + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + assert.equal(1, parsed.logs.length); + + args = parsed.logs[0].args; + + assert(dstContract_APL.address, args.from); + assert("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); + assert(200000000, args.value); + + return true; + }) + + .then(function () { + + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(200000, value); + + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(800000, value); + + return true; + }) + +}); + + + +it('roll-time-to-start-impeachment', function(){ + return workbench.rollTimeTo('22-Mar-2017 14:00 UTC+00') + .then(function(contract) { printDate(); return true; }); +}); + + + +it('impeachment-proposal-submit-1', function() { + log(""); + log(" (!) Action: [0x3a7e] submit impeachment proposal"); + + return dstContract_APL.submitImpeachmentProposal("http://pastebin.com/raw/Ehet8yVf", '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', + { + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + gas : 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + args = parsed.logs[0].args; + + log(""); + + log("ImpeachmentProposed (event)"); + log("==================="); + + + assert.equal("ImpeachmentProposed", parsed.logs[0].event); + + log("Submited by: " + args.submitter); + assert.equal("0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d", args.submitter); + + assert.equal("http://pastebin.com/raw/Ehet8yVf", args.urlDetails); + assert.equal("0xdedb49385ad5b94a16f236a6890cf9e0b1e30392", args.newExecutive); + + expectedEndTime = new Date('05-Apr-2017 14:00 UTC+00').getTime() / 1000; + assert.equal(expectedEndTime, args.votindEndTS); + + return true; + }) + + .then(function () { + + totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); + impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); + + impSupport = (impeachmentSupport / totalPreferred) * 100 + + log(""); + + log("Support for impeachment: " + impSupport + "%"); + assert.equal(30, impSupport); + + log("Executive for now: " + dstContract_APL.getExecutive()); + assert.equal('0xcc49bea5129ef2369ff81b0c0200885893979b77' ,dstContract_APL.getExecutive()); + + return true; + }) + +}); + + +it('impeachment-proposal-support-1', function() { + log(""); + log(" (!) Action: [0x2980] support impeachment proposal"); + + return dstContract_APL.supportImpeachment( + { + from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + gas : 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + args = parsed.logs[0].args; + + log(""); + + log("ImpeachmentSupport (event)"); + log("=================="); + + assert.equal("ImpeachmentSupport", parsed.logs[0].event); + + log("Submited by: " + args.supportter); + assert.equal("0x29805ff5b946e7a7c5871c1fb071f740f767cf41", args.supportter); + + log("[0x2980] submited " + args.votes + " votes"); + assert.equal(300000000000, args.votes.toNumber()); + + return true; + }) + + .then(function () { + + totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); + impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); + + impSupport = (impeachmentSupport / totalPreferred) * 100 + + log(""); + + log("Support for impeachment: " + impSupport + "%"); + assert.equal(60, impSupport); + + log("Executive for now: " + dstContract_APL.getExecutive()); + assert.equal('0xcc49bea5129ef2369ff81b0c0200885893979b77' ,dstContract_APL.getExecutive()); + + return true; + }) +}); + + + +it('impeachment-proposal-support-2', function() { + log(""); + log(" (!) Action: [0xcd2a] support impeachment proposal"); + + return dstContract_APL.supportImpeachment( + { + from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + gas : 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + args = parsed.logs[0].args; + + log(""); + + log("ImpeachmentSupport (event)"); + log("=================="); + + assert.equal("ImpeachmentSupport", parsed.logs[0].event); + + log("Submited by: " + args.supportter); + assert.equal("0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826", args.supportter); + + log("[0x2980] submited " + args.votes + " votes"); + assert.equal(100000000000, args.votes.toNumber()); + + return true; + }) + + .then(function () { + + totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); + impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); + + impSupport = (impeachmentSupport / totalPreferred) * 100 + + log(""); + + log("Support for impeachment: " + impSupport + "%"); + assert.equal(70, impSupport); + + log("Executive for now: " + dstContract_APL.getExecutive()); + assert.equal('0xdedb49385ad5b94a16f236a6890cf9e0b1e30392' ,dstContract_APL.getExecutive()); + + return true; + }) + +}); + + + + +}); diff --git a/test/dst-management/impeachment-test-3.js b/test/dst-management/impeachment-test-3.js new file mode 100644 index 0000000..7bcb088 --- /dev/null +++ b/test/dst-management/impeachment-test-3.js @@ -0,0 +1,841 @@ +var assert = require('assert'); + +var log = console.log; + +var Workbench = require('ethereum-sandbox-workbench'); +var workbench = new Workbench({ + defaults: { + from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826' + }, + + solcVersion: '0.4.2' +}); + +workbench.startTesting(['StandardToken', 'EventInfo', 'DSTContract', 'VirtualExchange'], function(contracts) { + +var sandbox = workbench.sandbox; + +// deployed contracts +var eventInfo; +var hackerGold; +var virtualExchange; + +var dstContract_APL; // Awesome Poker League + +function printDate(){ + now = eventInfo.getNow().toNumber(); + var date = new Date(now*1000); + + log('\n Date now: ' + date + '\n'); +} + + +/** + * + * Testing for self-impeachment: + * + * + * + * todo ... add more ... description + * + */ + +it('event-info-init', function() { + + log(''); + log(' ***********************'); + log(' impeachment-test-3.js '); + log(' ***********************'); + log(''); + + return contracts.EventInfo.new() + + .then(function(contract) { + + if (contract.address){ + eventInfo = contract; + } else { + throw new Error('No contract address'); + } + + return true; + }) + + .then(function() { + + printDate(); + return true; + }); + +}); + + +it('hacker-gold-init', function() { + + return contracts.HackerGold.new() + + .then(function(contract) { + + if (contract.address){ + hackerGold = contract; + } else { + throw new Error('No contract address'); + } + + return true; + }); +}); + + + +it('roll-time-ve-trading-start', function(){ + + // Roll time to get best price on HKG, + // 1 Ether for 200 HKG + return workbench.rollTimeTo('30-Oct-2016 14:00 UTC+00') + .then(function(contract) { printDate(); return true; }); +}); + + +it('buy-hkg-for-3a7e', function() { + log(""); + log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); + + return workbench.sendTransaction({ + from: '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + to: hackerGold.address, + value: sandbox.web3.toWei(10000, 'ether') + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function (txHash) { + + value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; + + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(2000000, value); + + return true; + }) + +}); + +it('buy-hkg-for-cc49', function() { + log(""); + log(" (!) Action: [0xcc49] buy [HKG] for 10000 Ether"); + + return workbench.sendTransaction({ + from: '0xcc49bea5129ef2369ff81b0c0200885893979b77', + to: hackerGold.address, + value: sandbox.web3.toWei(10000, 'ether') + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function (txHash) { + + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(2000000, value); + + return true; + }) + +}); + + +it('buy-hkg-for-2980', function() { + log(""); + log(" (!) Action: [0x2980] buy [HKG] for 10,000.000 Ether"); + + return workbench.sendTransaction({ + from: '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + to: hackerGold.address, + value: sandbox.web3.toWei(10000, 'ether') + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function (txHash) { + + value = hackerGold.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; + + log("[0x2980] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(2000000, value); + + return true; + }) + +}); + + +it('buy-hkg-for-696b', function() { + log(""); + log(" (!) Action: [0x696b] buy [HKG] for 5000.000 Ether"); + + return workbench.sendTransaction({ + from: '0x696ba93ef4254da47ff05b6caa88190db335f1c3', + to: hackerGold.address, + value: sandbox.web3.toWei(10000, 'ether') + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function (txHash) { + + value = hackerGold.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; + + log("[0x696b] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(2000000, value); + + return true; + }) + +}); + + +it('buy-hkg-for-cd2a', function() { + log(""); + log(" (!) Action: [0xcd2a] buy [HKG] for 5000.000 Ether"); + + return workbench.sendTransaction({ + from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + to: hackerGold.address, + value: sandbox.web3.toWei(10000, 'ether') + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function (txHash) { + + value = hackerGold.balanceOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826').toNumber() / 1000; + + log("[0xcd2a] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(2000000, value); + + return true; + }) + +}); + + + +it('roll-time-ve-trading-start', function(){ + + return workbench.rollTimeTo('24-Nov-2016 14:00 UTC+00') + .then(function(contract) { printDate(); return true; }); +}); + + + + +it('virtual-exchange-init', function() { + + return contracts.VirtualExchange.new(hackerGold.address, + eventInfo.address) + .then(function(contract) { + + if (contract.address){ + virtualExchange = contract; + } else { + throw new Error('No contract address'); + } + + return true; + }); +}); + + +it('dst-contract-apl-init', function() { + + return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", + + { + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77' + }) + + .then(function(contract) { + + if (contract.address){ + dstContract_APL = contract; + } else { + throw new Error('No contract address'); + } + + return true; + }); +}); + + + +it('enlist-apl', function() { + log(""); + log(" (!) Action: [VE] enlist [APL] for trading"); + + return virtualExchange.enlist(dstContract_APL.address, + { + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + }) + + .then(function(txHash) { + + // we are waiting for blockchain to accept the transaction + return workbench.waitForReceipt(txHash); + }) + + .then(function() { + + exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); + + log("[APL] => enlisted: " + exist); + assert.equal(true, exist); + + return true; + }) + +}); + + +it('issue-apl-tokens-seria-1', function() { + log(""); + log(" (!) Action: [APL] issue tokens on [VE] balance 1,000,000,000,000.000 APL"); + + return dstContract_APL.issuePreferedTokens(1000, 1000000000000, + { + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + }) + + .then(function () { + + dst1Total = dstContract_APL.getTotalSupply().toNumber() / 1000; + + log("[APL] => total suply: " + dst1Total.toFixed(3) + " APL"); + assert(1000000000000, dst1Total); + + veTokens = dstContract_APL.allowance(dstContract_APL.address, + virtualExchange.address).toNumber() / 1000; + log("[APL] => total on VirtualExchange: " + veTokens.toFixed(3) + " APL"); + assert(1000000000000, veTokens); + + return true; + }) +}); + + + +it('approve-hkg-spend-on-exchange-for-3a7e', function() { + log(""); + log(" (!) Action: [0x3a7e] move to [VE] balance 1,000,000.000 HKG"); + + return hackerGold.approve(virtualExchange.address, 2000000000, + { + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function () { + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + virtualExchange.address).toNumber() / 1000; + + log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(2000000, veTokens); + + return true; + }) +}); + + +it('approve-hkg-spend-on-exchange-for-2980', function() { + log(""); + log(" (!) Action: [0x2980] move to [VE] balance 2,000,000.000 HKG"); + + return hackerGold.approve(virtualExchange.address, 2000000000, + { + from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function () { + + veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + virtualExchange.address).toNumber() / 1000; + + log("[0x2980] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(2000000, veTokens); + + return true; + }) +}); + + +it('approve-hkg-spend-on-exchange-for-696b', function() { + log(""); + log(" (!) Action: [0x696b] move to [VE] balance 1,000,000.000 HKG"); + + return hackerGold.approve(virtualExchange.address, 2000000000, + { + from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function () { + + veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', + virtualExchange.address).toNumber() / 1000; + + log("[0x696b] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(2000000, veTokens); + + return true; + }) +}); + + + +it('approve-hkg-spend-on-exchange-for-cd2a', function() { + log(""); + log(" (!) Action: [0xcd2a] move to [VE] balance 1,000,000.000 HKG"); + + return hackerGold.approve(virtualExchange.address, 2000000000, + { + from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + }) + + .then(function () { + + veTokens = hackerGold.allowance('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + virtualExchange.address).toNumber() / 1000; + + log("[0xcd2a] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(2000000, veTokens); + + return true; + }) +}); + + +it('buy-apl-by-3a7e', function() { + log(""); + log(" (!) Action: [0x3a7e] buy tokens [APL] for 300,000.000 HKG"); + + + return virtualExchange.buy('APL', 300000000, + { + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + gas: 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function () { + + dst1Balance = dstContract_APL.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; + + log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " APL"); + assert.equal(300000000 , dst1Balance); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); + + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(300000000000 , voting); + + value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; + + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(1700000, value); + + log ("[APL] => total: " + total + " votes"); + assert.equal(300000000000, total); + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + virtualExchange.address).toNumber() / 1000; + log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(1700000 , veTokens); + + availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available suply: " + availableSuply + " APL"); + assert.equal(700000000 , availableSuply); + + return true; + }) +}); + + + + +it('buy-apl-by-2980', function() { + log(""); + log(" (!) Action: [0x2980] buy tokens [APL] for 300,000.000 HKG"); + + + return virtualExchange.buy('APL', 300000000, + { + from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + gas: 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function () { + + dst1Balance = dstContract_APL.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; + + log("[0x2980] => balance: " + dst1Balance.toFixed(3) + " APL"); + assert.equal(300000000 , dst1Balance); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); + + log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(300000000000 , voting); + + value = hackerGold.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; + + log("[0x2980] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(1700000, value); + + log ("[APL] => total: " + total + " votes"); + + veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + virtualExchange.address).toNumber() / 1000; + log("[0x2980] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); + assert.equal(1700000 , veTokens); + + availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available suply: " + availableSuply + " APL"); + + + log(""); + log(" Voting Summary: "); + log(" =============== "); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); + + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(50, voting / total * 100); + + total = dstContract_APL.getPreferedQtySold(); + voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); + + log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(50, voting / total * 100); + + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => collected: " + value.toFixed(3) + " HKG"); + assert.equal(600000, value); + + return true; + }) +}); + +it('buy-apl-by-cc49', function() { + log(""); + log(" (!) Action: [0x2980] buy tokens [APL] for 200,000.000 HKG"); + + + return virtualExchange.buy('APL', 2000000, + { + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas: 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + console.log("logs:" ,parsed.logs[0].args); + dst1Balance = dstContract_APL.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; + voting = dstContract_APL.votingRightsOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber(); + + log ("[0xcc49] => voting: " + voting + " votes - " + voting / total * 100 + "%"); + assert.equal(2000000000 , voting); + }) +}); + + + + + +//TODO: if impeachment files are the same until here we should refactor +it('roll-time-50%-available', function(){ + + return workbench.rollTimeTo('22-Feb-2017 14:00 UTC+00') + .then(function(contract) { printDate(); return true; }); +}); + +it('submit-proposal-1', function() { + log(""); + log(" (!) Action: [0xcc49] ask to recieve 200,000.000 (20%) of the HKG collected"); + + return dstContract_APL.submitHKGProposal(200000000, "http://pastebin.com/raw/6e9PBTeP", + { + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 450000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + args = parsed.logs[0].args; + + proposalId = args.id; + proposalValue = args.value; + proposalValue = proposalValue / 1000; + + proposalTimeEnds = args.timeEnds; + proposalURL = args.url; + proposalSender = args.sender; + + log(""); + log("Proposal Submitted"); + log("=================="); + + log("proposalId: " + proposalId); + log("proposalValue: " + proposalValue.toFixed(3)); + log("proposalTimeEnds: " + proposalTimeEnds); + log("proposalURL: " + proposalURL); + log("proposalSender: " + proposalSender); + + + assert.equal(200000, proposalValue); + + t1 = eventInfo.getNow().toNumber() + 60 * 60 * 24 * 10; + t2 = proposalTimeEnds; + assert(t1, t2); + + assert.equal(proposalURL, "http://pastebin.com/raw/6e9PBTeP"); + assert.equal(proposalSender, "0xcc49bea5129ef2369ff81b0c0200885893979b77"); + + proposal_1 = proposalId; + + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(2000000, value); + + return true; + }) + +}); + + + +it('object-by-vote-proposal-1', function() { + log(""); + log(" (!) Action: [0x3a7e] vote to object proposal 1"); + + return dstContract_APL.objectProposal(proposal_1, + { + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + gas : 450000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + log_1 = parsed.logs[0]; + + total = dstContract_APL.getPreferedQtySold(); + + log("\n"); + log(log_1.event + ":"); + log("============"); + + log("proposal.id: " + log_1.args.id); + log("voter: " + log_1.args.voter); + log("votes: " + log_1.args.votes + " share: " + (log_1.args.votes / total * 100).toFixed(2) + "%"); + + voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber(); + + assert.equal(proposal_1, log_1.args.id); + assert.equal(log_1.args.voter, "0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d"); + assert.equal(log_1.args.votes, voting); + + return true; + }) + +}); + + +it('roll-time-proposal-redeem', function(){ + + return workbench.rollTimeTo('04-Mar-2017 14:00 UTC+00') + .then(function(contract) { printDate(); return true; }); +}); + + +it('redeem-proposal-1', function() { + log(""); + log(" (!) Action: [0xcc49] collect 1,000.000 HKG value of proposal 1"); + + return dstContract_APL.redeemProposalFunds(proposal_1, + { + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + + assert.equal(1, parsed.logs.length); + + args = parsed.logs[0].args; + + assert(dstContract_APL.address, args.from); + assert("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); + assert(2200000, args.value); + + return true; + }) + + .then(function () { + + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(2200000, value); + + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(400000, value); + + return true; + }) + +}); + + +it('roll-time-to-start-impeachment', function(){ + + return workbench.rollTimeTo('22-Mar-2017 14:00 UTC+00') + .then(function(contract) { printDate(); return true; }); +}); + + +it('self-impeachment-proposal-submit-1', function() { + log(""); + log(" (!) Action: [0x3a7e] submit impeachment proposal"); + + return dstContract_APL.submitImpeachmentProposal("http://pastebin.com/raw/Ehet8yVf", '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', + { + from : "0xcc49bea5129ef2369ff81b0c0200885893979b77", + gas : 250000, + }) + + .then(function (txHash) { + + return workbench.waitForReceipt(txHash); + + }) + + .then(function (parsed) { + console.log(parsed); + args = parsed.logs[0].args; + + log(""); + + log("ImpeachmentProposed (event)"); + log("==================="); + + + assert.equal("ImpeachmentProposed", parsed.logs[0].event); + + log("Submited by: " + args.submitter); + assert.equal("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.submitter); + + assert.equal("http://pastebin.com/raw/Ehet8yVf", args.urlDetails); + assert.equal("0xdedb49385ad5b94a16f236a6890cf9e0b1e30392", args.newExecutive); + + expectedEndTime = new Date('05-Apr-2017 14:00 UTC+00').getTime() / 1000; + assert.equal(expectedEndTime, args.votindEndTS); + + return true; + }) + + .then(function () { + + totalPreferred = dstContract_APL.getPreferedQtySold().toNumber(); + impeachmentSupport = dstContract_APL.getCurrentImpeachmentVotesSupporting().toNumber(); + + impSupport = (impeachmentSupport / totalPreferred) * 100 + + log(""); + + log("Support for impeachment: " + impSupport + "%"); + assert.equal(30, impSupport); + + log("Executive for now: " + dstContract_APL.getExecutive()); + assert.equal('0xcc49bea5129ef2369ff81b0c0200885893979b77' ,dstContract_APL.getExecutive()); + + return true; + }) + +}); + + + +}); diff --git a/test/dst-management/initiate-tokens-test-1.js b/test/dst-management/initiate-tokens-test-1.js index fbcbbe8..52cda8b 100644 --- a/test/dst-management/initiate-tokens-test-1.js +++ b/test/dst-management/initiate-tokens-test-1.js @@ -6,8 +6,8 @@ var Workbench = require('ethereum-sandbox-workbench'); var workbench = new Workbench({ defaults: { from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826' - }, - + }, + solcVersion: '0.4.2' }); @@ -15,7 +15,7 @@ workbench.startTesting(['StandardToken', 'EventInfo', 'DSTContract', 'VirtualExc var sandbox = workbench.sandbox; -// deployed contracts +// deployed contracts var eventInfo; var hackerGold; var virtualExchange; @@ -25,58 +25,58 @@ var dstContract2; function printDate(){ now = eventInfo.getNow().toNumber(); var date = new Date(now*1000); - - log('\n Date now: ' + date + '\n'); + + log('\n Date now: ' + date + '\n'); } /** * - * Testing for issue project token series: - * + * Testing for issue project token series: + * * [MK3] * - * 1. issue 150.000 preffered 1.000 HKG for 1.000 MK3 + * 1. issue 150.000 preffered 1.000 HKG for 1.000 MK3 * 2. issue 1250.000 preffered 1.000 HKG for 2.000 MK3 * 3. issue 1000.000 1.0 Ether for 1.000 MK3 * 4. disabled any issuence of the tokens * */ - + it('event-info-init', function() { - + log(''); log(' ***************************'); log(' initiate-tokens-test-1.js '); log(' ***************************'); log(''); - - + + return contracts.EventInfo.new() .then(function(contract) { - + if (contract.address){ eventInfo = contract; } else { throw new Error('No contract address'); - } - - return true; + } + + return true; }) - + .then(function() { - - printDate(); + + printDate(); return true; }); - + }); - + it('roll-time-ve-trading-start', function(){ - + return workbench.rollTimeTo('24-Nov-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -88,54 +88,54 @@ it('hacker-gold-init', function() { return contracts.HackerGold.new() .then(function(contract) { - + if (contract.address){ hackerGold = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); it('virtual-exchange-init', function() { - return contracts.VirtualExchange.new(hackerGold.address, + return contracts.VirtualExchange.new(hackerGold.address, eventInfo.address) .then(function(contract) { - + if (contract.address){ virtualExchange = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); it('dst-contract-mk3-init', function() { - return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "MerkleTree", "MK3", - + return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "MerkleTree", "MK3", + { from : '0xcc49bea5129ef2369ff81b0c0200885893979b77' }) .then(function(contract) { - + if (contract.address){ dstContract1 = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); @@ -144,27 +144,27 @@ it('enlist-mk3', function() { log(""); log(" (!) Action: [VE] enlist [MK3] for trading"); - return virtualExchange.enlist(dstContract1.address, + return virtualExchange.enlist(dstContract1.address, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) - + .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) - + .then(function() { - - exist = virtualExchange.isExistByString(dstContract1.getDSTSymbol()); - + + exist = virtualExchange.isExistByString(dstContract1.getDSTSymbol()); + log("[MK3] => enlisted: " + exist); assert.equal(true, exist); - + return true; }) - + }); @@ -172,23 +172,23 @@ it('enlist-mk3', function() { it('issue-mk3-tokens-seria-1', function() { log(""); log(" (!) Action: [MK3] issue tokens on [VE] balance 150.000 MK3"); - - return dstContract1.issuePreferedTokens(1, 150000, + + return dstContract1.issuePreferedTokens(1, 150000, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) .then(function () { - + dst1Total = dstContract1.getTotalSupply().toNumber() / 1000; - - log("[MK3] => total suply: " + dst1Total.toFixed(3) + " MK3"); - assert(150, dst1Total); - - veTokens = dstContract1.allowance(dstContract1.address, + + log("[MK3] => total supply: " + dst1Total.toFixed(3) + " MK3"); + assert.equal(150, dst1Total); + + veTokens = dstContract1.allowance(dstContract1.address, virtualExchange.address).toNumber() / 1000; log("[MK3] => total on VirtualExchange: " + veTokens.toFixed(3) + " MK3"); - assert(150, veTokens); + assert.equal(150, veTokens); return true; }) @@ -198,29 +198,29 @@ it('issue-mk3-tokens-seria-1', function() { it('buy-hkg-for-3a7e', function() { log(""); - log(" (!) Action: [0x3a7e] buy [HKG] for 1500.000 Ether"); + log(" (!) Action: [0x3a7e] buy [HKG] for 1500.000 Ether"); return workbench.sendTransaction({ from: '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', to: hackerGold.address, value: sandbox.web3.toWei(1500, 'ether') }) - + .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); assert.equal(225000, value); - - return true; + + return true; }) - + }); @@ -228,24 +228,24 @@ it('buy-hkg-for-3a7e', function() { it('approve-hkg-spend-on-exchange-1', function() { log(""); log(" (!) Action: [0x3a7e] move to [VE] balance 150.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 150000, + + return hackerGold.approve(virtualExchange.address, 150000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(150, veTokens); - + return true; }) }); @@ -253,48 +253,48 @@ it('approve-hkg-spend-on-exchange-1', function() { -it('buy-all-dst-suply-seria-1', function() { +it('buy-all-dst-supply-seria-1', function() { log(""); log(" (!) Action: [0x3a7e] buy tokens [MK3] for 150.000 HKG"); - - return virtualExchange.buy('MK3', 150000, + + return virtualExchange.buy('MK3', 150000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { dst1Balance = dstContract1.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " MK3"); assert.equal(150 , dst1Balance); - + total = dstContract1.getPreferedQtySold(); voting = dstContract1.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(150000 , voting); value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); assert.equal(224850, value); - + log ("[MK3] => total: " + total + " votes"); - - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(0 , veTokens); - + return true; }) }); @@ -305,24 +305,24 @@ it('approve-hkg-spend-on-exchange-2', function() { log(""); log(" (!) Action: [0x3a7e] move to [VE] balance 1000.000 HKG"); - return hackerGold.approve(virtualExchange.address, 1000000, + return hackerGold.approve(virtualExchange.address, 1000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber(); log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(1000000 , veTokens); - + return true; }) }); @@ -334,78 +334,78 @@ it('issue-mk3-tokens-seria-2', function() { log(""); log(" (!) Action: [MK3] issue tokens on [VE] balance 1250.000 MK3"); - return dstContract1.issuePreferedTokens(2, 1250000, + return dstContract1.issuePreferedTokens(2, 1250000, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) .then(function () { - + dst1Total = dstContract1.getTotalSupply().toNumber() / 1000; log("[MK3] => total: " + dst1Total.toFixed(3) + " MK3"); assert.equal(1400 , dst1Total); - veTokens = dstContract1.allowance(dstContract1.address, + veTokens = dstContract1.allowance(dstContract1.address, virtualExchange.address).toNumber() / 1000; log("[MK3] => VirtualExchange balance: " + veTokens.toFixed(3) + " MK3"); assert.equal(1250, veTokens); - + total = dstContract1.getPreferedQtySold(); voting = dstContract1.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(150000, voting); - + log("[MK3] => total: " + total + " votes"); assert.equal(150000, total); - + return true; }) }); -it('buy-all-dst-suply-seria-2-1', function() { +it('buy-all-dst-supply-seria-2-1', function() { log(""); log(" (!) Action: [0x3a7e] buy [MK3] for 500.000 HKG"); - - return virtualExchange.buy('MK3', 500000, + + return virtualExchange.buy('MK3', 500000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { mk3Balance = dstContract1.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; log("[0x3a7e] => balance: " + mk3Balance.toFixed(3) + " MK3"); assert.equal(1150, mk3Balance); - + total = dstContract1.getPreferedQtySold(); voting = dstContract1.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - - + + log("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); - + log ("[MK3] => total: " + total + " votes"); - - - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber(); log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - - veTokens = dstContract1.allowance(dstContract1.address, + + veTokens = dstContract1.allowance(dstContract1.address, virtualExchange.address).toNumber(); log("[MK3] VirtualExchange total: " + veTokens.toFixed(3) + " MK3"); - + return true; }) }); @@ -413,55 +413,55 @@ it('buy-all-dst-suply-seria-2-1', function() { -it('buy-all-dst-suply-seria-2-2', function() { +it('buy-all-dst-supply-seria-2-2', function() { log(""); log(" (!) Action: [0x3a7e] buy [MK3] for 125.000 HKG"); - - return virtualExchange.buy('MK3', 125000, + + return virtualExchange.buy('MK3', 125000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { mk3Balance = dstContract1.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; log("[0x3a7e] => balance: " + mk3Balance.toFixed(3) + " MK3"); assert.equal(1400, mk3Balance); - + total = dstContract1.getPreferedQtySold(); voting = dstContract1.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); - - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber(); log("[0x3a7e] VirtualExchange balance: " + veTokens + " HKG (???) "); - - veTokens = dstContract1.allowance(dstContract1.address, + + veTokens = dstContract1.allowance(dstContract1.address, virtualExchange.address).toNumber(); log("[MK3] VirtualExchange total: " + veTokens.toFixed(3) + " MK3"); hkgCollected = hackerGold.balanceOf(dstContract1.address).toNumber() / 1000; - + log("[MK3] colected balance: " + hkgCollected.toFixed(3) + " HKG"); - + return true; }) }); it('roll-time-event-stops', function(){ - + return workbench.rollTimeTo('22-Dec-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -471,29 +471,29 @@ it('issue-mk3-tokens-seria-3', function() { log(""); log(" (!) Action: [MK3] issue tokens: 1000.000 MK3"); - return dstContract1.issueTokens(1, 1000000, + return dstContract1.issueTokens(1, 1000000, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) .then(function () { log("[The event is over]"); - + dst1Total = dstContract1.getTotalSupply().toNumber() / 1000; log("[MK3] => total: " + dst1Total.toFixed(3) + " MK3"); assert.equal(2400 , dst1Total); - + issued = dstContract1.balanceOf(dstContract1.address).toNumber() / 1000; - log("[MK3] => total suply: " + issued.toFixed(3) + " MK3"); + log("[MK3] => total supply: " + issued.toFixed(3) + " MK3"); assert.equal(1000 , issued); - + return true; }) }); -it('buy-all-dst-suply-seria-3-1', function() { +it('buy-all-dst-supply-seria-3-1', function() { log(""); log(" (!) Action: [0x3a7e] buy [MK3] tokens for: 990.000 Ether"); @@ -502,10 +502,10 @@ it('buy-all-dst-suply-seria-3-1', function() { to: dstContract1.address, value: sandbox.web3.toWei(990, 'ether') }) - + .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { @@ -513,25 +513,25 @@ it('buy-all-dst-suply-seria-3-1', function() { dst1Total = dstContract1.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; log("[0x3a7e] => balance: " + dst1Total + " MK3"); assert.equal(2390 , dst1Total); - + total = dstContract1.getPreferedQtySold(); voting = dstContract1.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(1400000 , voting); - - tokensSuply = dstContract1.balanceOf(dstContract1.address).toNumber(); - log("[MK3] available suply: " + tokensSuply + " MK3"); - assert.equal(10000 , tokensSuply); - - return true; - }) - + + tokensSupply = dstContract1.balanceOf(dstContract1.address).toNumber(); + log("[MK3] available supply: " + tokensSupply + " MK3"); + assert.equal(10000 , tokensSupply); + + return true; + }) + }); -it('buy-all-dst-suply-seria-3-2', function() { +it('buy-all-dst-supply-seria-3-2', function() { log(""); log(" (!) Action: [0x3a7e] buy [MK3] tokens for: 10.000 Ether"); @@ -540,10 +540,10 @@ it('buy-all-dst-suply-seria-3-2', function() { to: dstContract1.address, value: sandbox.web3.toWei(10, 'ether') }) - + .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { @@ -551,64 +551,81 @@ it('buy-all-dst-suply-seria-3-2', function() { dst1Total = dstContract1.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; log("[0x3a7e] balance: " + dst1Total + " MK3"); assert.equal(2400 , dst1Total); - + value = dstContract1.getPreferedQtySold(); voting = dstContract1.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(1400000 , voting); - - tokensSuply = dstContract1.balanceOf(dstContract1.address).toNumber(); - log("[MK3] available suply: " + tokensSuply + " MK3"); - assert.equal(0 , tokensSuply); - - return true; - }) - + assert.equal(1400000 , voting); + + tokensSupply = dstContract1.balanceOf(dstContract1.address).toNumber(); + log("[MK3] available supply: " + tokensSupply + " MK3"); + assert.equal(0 , tokensSupply); + + return true; + }) + }); it('disable-token-issuance', function() { log(""); log(" (!) Action: [0x3a7e] disable [MK3] tokens issueance option"); - - return dstContract1.disableTokenIssuance( + + return dstContract1.disableTokenIssuance( { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) .then(function () { - + dst1Total = dstContract1.getTotalSupply().toNumber() / 1000; - log("[MK3] => total issued: " + dst1Total + " MK3"); - assert.equal(2400, dst1Total); - - etherCollected = + log("[MK3] => total issued: " + dst1Total + " MK3"); + assert.equal(2400, dst1Total); + + etherCollected = dstContract1.getEtherValue().toNumber() / 1000000000000000000; - + log("[MK3] => balance: " + etherCollected + " Ether"); assert.equal(1000, etherCollected); - + hkgCollected = hackerGold.balanceOf(dstContract1.address).toNumber() / 1000; log("[MK3] => collected balance: " + hkgCollected.toFixed(3) + " HKG"); assert.equal(775, hkgCollected); total = dstContract1.getPreferedQtySold(); voting = dstContract1.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(1400000, voting); - + return true; }) }); +it('issue-mk3-tokens-seria-1-edge-1', function() { + log(""); + log(" (!) Action: [MK3] issue tokens on [VE] balance 150.000 MK3"); + return dstContract1.issuePreferedTokens(0, 15000, + { + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + }) -}); + .then(function () { + dst1Total = dstContract1.getTotalSupply().toNumber() / 1000; + log("[MK3] => total supply: " + dst1Total.toFixed(3) + " MK3"); + assert.equal(2400, dst1Total); + veTokens = dstContract1.allowance(dstContract1.address, virtualExchange.address).toNumber() / 1000; + log("[MK3] => total on VirtualExchange: " + veTokens.toFixed(3) + " MK3"); + assert.equal(0, veTokens); + return true; + }) +}); +}); diff --git a/test/dst-management/initiate-tokens-test-2.js b/test/dst-management/initiate-tokens-test-2.js index e81a3c2..cc24d1e 100644 --- a/test/dst-management/initiate-tokens-test-2.js +++ b/test/dst-management/initiate-tokens-test-2.js @@ -6,8 +6,8 @@ var Workbench = require('ethereum-sandbox-workbench'); var workbench = new Workbench({ defaults: { from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826' - }, - + }, + solcVersion: '0.4.2' }); @@ -15,7 +15,7 @@ workbench.startTesting(['StandardToken', 'EventInfo', 'DSTContract', 'VirtualExc var sandbox = workbench.sandbox; -// deployed contracts +// deployed contracts var eventInfo; var hackerGold; var virtualExchange; @@ -26,78 +26,78 @@ var dstContract_APL; // Awesome Poker League function printDate(){ now = eventInfo.getNow().toNumber(); var date = new Date(now*1000); - - log('\n Date now: ' + date + '\n'); + + log('\n Date now: ' + date + '\n'); } /** * - * Testing for issue project DST token series: - * + * Testing for issue project DST token series: + * * 1. Enlist the APL token - * 2. Issue 1,000,000,000,000.000 APL tokens - * 3. [0x3a7e] Buy 250,000,000.000 APL => 25% + * 2. Issue 1,000,000,000,000.000 APL tokens + * 3. [0x3a7e] Buy 250,000,000.000 APL => 25% * 4. [0x2980] Buy 300,000,000.000 APL => 30% * 5. [0x696b] Buy 50,000,000.000 APL => 5% * 6. [0xcd2a] Buy 400,000,000.000 APL => 40% - * + * */ - + it('event-info-init', function() { - + log(''); log(' ***************************'); log(' initiate-tokens-test-2.js '); log(' ***************************'); log(''); - - + + return contracts.EventInfo.new() .then(function(contract) { - + if (contract.address){ eventInfo = contract; } else { throw new Error('No contract address'); - } - - return true; + } + + return true; }) - + .then(function() { - - printDate(); + + printDate(); return true; }); - + }); - + it('hacker-gold-init', function() { return contracts.HackerGold.new() .then(function(contract) { - + if (contract.address){ hackerGold = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); - + it('roll-time-ve-trading-start', function(){ - - // Roll time to get best price on HKG, - // 1 Ether for 200 HKG + + // Roll time to get best price on HKG, + // 1 Ether for 200 HKG return workbench.rollTimeTo('30-Oct-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -105,119 +105,119 @@ it('roll-time-ve-trading-start', function(){ it('buy-hkg-for-3a7e', function() { log(""); - log(" (!) Action: [0x3a7e] buy [HKG] for 5000.000 Ether"); + log(" (!) Action: [0x3a7e] buy [HKG] for 5000.000 Ether"); return workbench.sendTransaction({ from: '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', to: hackerGold.address, value: sandbox.web3.toWei(5000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); assert.equal(1000000, value); - - return true; + + return true; }) - + }); it('buy-hkg-for-2980', function() { log(""); - log(" (!) Action: [0x2980] buy [HKG] for 5000.000 Ether"); + log(" (!) Action: [0x2980] buy [HKG] for 5000.000 Ether"); return workbench.sendTransaction({ from: '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', to: hackerGold.address, value: sandbox.web3.toWei(5000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; - + log("[0x2980] => balance: " + value.toFixed(3) + " HKG"); assert.equal(1000000, value); - - return true; + + return true; }) - + }); it('buy-hkg-for-696b', function() { log(""); - log(" (!) Action: [0x696b] buy [HKG] for 5000.000 Ether"); + log(" (!) Action: [0x696b] buy [HKG] for 5000.000 Ether"); return workbench.sendTransaction({ from: '0x696ba93ef4254da47ff05b6caa88190db335f1c3', to: hackerGold.address, value: sandbox.web3.toWei(5000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; - + log("[0x696b] => balance: " + value.toFixed(3) + " HKG"); assert.equal(1000000, value); - - return true; + + return true; }) - + }); it('buy-hkg-for-cd2a', function() { log(""); - log(" (!) Action: [0xcd2a] buy [HKG] for 5000.000 Ether"); + log(" (!) Action: [0xcd2a] buy [HKG] for 5000.000 Ether"); return workbench.sendTransaction({ from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', to: hackerGold.address, value: sandbox.web3.toWei(5000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826').toNumber() / 1000; - + log("[0xcd2a] => balance: " + value.toFixed(3) + " HKG"); assert.equal(1000000, value); - - return true; + + return true; }) - + }); it('roll-time-ve-trading-start', function(){ - + return workbench.rollTimeTo('24-Nov-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -227,39 +227,39 @@ it('roll-time-ve-trading-start', function(){ it('virtual-exchange-init', function() { - return contracts.VirtualExchange.new(hackerGold.address, + return contracts.VirtualExchange.new(hackerGold.address, eventInfo.address) .then(function(contract) { - + if (contract.address){ virtualExchange = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); it('dst-contract-apl-init', function() { - return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", - + return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", + { from : '0xcc49bea5129ef2369ff81b0c0200885893979b77' }) .then(function(contract) { - + if (contract.address){ dstContract_APL = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); // ... @@ -270,25 +270,25 @@ it('enlist-not-by-the-owner', function() { log(""); log(" [X] Action [VE] enlist not by the owner"); - return virtualExchange.enlist(dstContract_APL.address, + return virtualExchange.enlist(dstContract_APL.address, { - from : '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', + from : '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', }) - + .then(function(txHash) { return workbench.waitForReceipt(txHash); }) - + .then(function() { - - exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); - + + exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); + log("[APL] => enlisted: " + exist); assert.equal(false, exist); - + return true; }) - + }); @@ -296,27 +296,27 @@ it('enlist-apl', function() { log(""); log(" (!) Action: [VE] enlist [APL] for trading"); - return virtualExchange.enlist(dstContract_APL.address, + return virtualExchange.enlist(dstContract_APL.address, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) - + .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) - + .then(function() { - - exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); - + + exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); + log("[APL] => enlisted: " + exist); assert.equal(true, exist); - + return true; }) - + }); @@ -324,25 +324,25 @@ it('enlist-apl', function() { it('approve-hkg-spend-on-exchange-for-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 1000000000, + + return hackerGold.approve(virtualExchange.address, 1000000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; - + log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(1000000, veTokens); - + return true; }) }); @@ -351,25 +351,25 @@ it('approve-hkg-spend-on-exchange-for-3a7e', function() { it('approve-hkg-spend-on-exchange-for-2980', function() { log(""); log(" (!) Action: [0x2980] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 1000000000, + + return hackerGold.approve(virtualExchange.address, 1000000000, { - from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', virtualExchange.address).toNumber() / 1000; - + log("[0x2980] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(1000000, veTokens); - + return true; }) }); @@ -378,25 +378,25 @@ it('approve-hkg-spend-on-exchange-for-2980', function() { it('approve-hkg-spend-on-exchange-for-696b', function() { log(""); log(" (!) Action: [0x696b] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 1000000000, + + return hackerGold.approve(virtualExchange.address, 1000000000, { - from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', + from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', + veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', virtualExchange.address).toNumber() / 1000; - + log("[0x696b] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(1000000, veTokens); - + return true; }) }); @@ -406,25 +406,25 @@ it('approve-hkg-spend-on-exchange-for-696b', function() { it('approve-hkg-spend-on-exchange-for-cd2a', function() { log(""); log(" (!) Action: [0xcd2a] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 1000000000, + + return hackerGold.approve(virtualExchange.address, 1000000000, { - from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - veTokens = hackerGold.allowance('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + veTokens = hackerGold.allowance('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', virtualExchange.address).toNumber() / 1000; - + log("[0xcd2a] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(1000000, veTokens); - + return true; }) }); @@ -438,23 +438,23 @@ it('approve-hkg-spend-on-exchange-for-cd2a', function() { it('issue-apl-tokens-not-by-the-owner', function() { log(""); log(" [X] Action [0xdedb] issue tokens for [APL] not by the owner"); - - return dstContract_APL.issuePreferedTokens(1000, 1000000000000, + + return dstContract_APL.issuePreferedTokens(1000, 1000000000000, { - from : '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', + from : '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', }) .then(function () { - + dst1Total = dstContract_APL.getTotalSupply().toNumber() / 1000; - - log("[APL] => total suply: " + dst1Total.toFixed(3) + " APL"); - assert("0.000", dst1Total.toFixed(3)); - - veTokens = dstContract_APL.allowance(dstContract_APL.address, + + log("[APL] => total supply: " + dst1Total.toFixed(3) + " APL"); + assert.equal("0.000", dst1Total.toFixed(3)); + + veTokens = dstContract_APL.allowance(dstContract_APL.address, virtualExchange.address).toNumber() / 1000; log("[APL] => total on VirtualExchange: " + veTokens.toFixed(3) + " APL"); - assert("0.000", dst1Total.toFixed(3)); + assert.equal("0.000", dst1Total.toFixed(3)); return true; }) @@ -465,23 +465,23 @@ it('issue-apl-tokens-not-by-the-owner', function() { it('issue-apl-tokens-seria-1', function() { log(""); log(" (!) Action: [APL] issue tokens on [VE] balance 1,000,000,000,000.000 APL"); - - return dstContract_APL.issuePreferedTokens(1000, 1000000000000, + + return dstContract_APL.issuePreferedTokens(1000, 1000000000000, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) .then(function () { - + dst1Total = dstContract_APL.getTotalSupply().toNumber() / 1000; - - log("[APL] => total suply: " + dst1Total.toFixed(3) + " APL"); - assert(1000000000000, dst1Total); - - veTokens = dstContract_APL.allowance(dstContract_APL.address, + + log("[APL] => total supply: " + dst1Total.toFixed(3) + " APL"); + assert.equal(1000000000, dst1Total); + + veTokens = dstContract_APL.allowance(dstContract_APL.address, virtualExchange.address).toNumber() / 1000; log("[APL] => total on VirtualExchange: " + veTokens.toFixed(3) + " APL"); - assert(1000000000000, veTokens); + assert.equal(1000000000, veTokens); return true; }) @@ -490,31 +490,31 @@ it('issue-apl-tokens-seria-1', function() { // ... // [X] Action [0xdedb] buy [APL] tokens on [VE] with no HKG . -// ... +// ... it('buy-apl-by-3a7e', function() { log(""); log(" [X] Action [0xdedb] buy [APL] tokens on [VE] with no HKG"); - - return virtualExchange.buy('APL', 10000, + + return virtualExchange.buy('APL', 10000, { - from : '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', + from : '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { dst1Balance = dstContract_APL.balanceOf('0xdedb49385ad5b94a16f236a6890cf9e0b1e30392').toNumber() / 1000; - + log("[0xdedb] => balance: " + dst1Balance.toFixed(3) + " APL"); assert.equal(0, dst1Balance); - + return true; }) }); @@ -525,49 +525,49 @@ it('buy-apl-by-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] buy tokens [APL] for 250,000.000 HKG"); - - return virtualExchange.buy('APL', 250000000, + + return virtualExchange.buy('APL', 250000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { dst1Balance = dstContract_APL.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " APL"); assert.equal(250000000 , dst1Balance); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(250000000000 , voting); value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(750000, value); - + assert.equal(750000, value); + log ("[APL] => total: " + total + " votes"); assert.equal(250000000000, total); - - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(750000 , veTokens); - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - assert.equal(750000000 , availableSuply); - + availableSupply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available supply: " + availableSupply + " APL"); + assert.equal(750000000 , availableSupply); + return true; }) }); @@ -579,46 +579,46 @@ it('buy-apl-by-2980', function() { log(""); log(" (!) Action: [0x2980] buy tokens [APL] for 300,000.000 HKG"); - - return virtualExchange.buy('APL', 300000000, + + return virtualExchange.buy('APL', 300000000, { - from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { dst1Balance = dstContract_APL.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; - + log("[0x2980] => balance: " + dst1Balance.toFixed(3) + " APL"); assert.equal(300000000 , dst1Balance); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); - + log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(300000000000 , voting); value = hackerGold.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; - + log("[0x2980] => balance: " + value.toFixed(3) + " HKG"); assert.equal(700000, value); - + log ("[APL] => total: " + total + " votes"); - - veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + + veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', virtualExchange.address).toNumber() / 1000; log("[0x2980] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(700000 , veTokens); - - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); + + availableSupply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available supply: " + availableSupply + " APL"); return true; }) @@ -630,46 +630,46 @@ it('buy-apl-by-696b', function() { log(""); log(" (!) Action: [0x696b] buy tokens [APL] for 50,000.000 HKG"); - - return virtualExchange.buy('APL', 50000000, + + return virtualExchange.buy('APL', 50000000, { - from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', + from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { dst1Balance = dstContract_APL.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; - + log("[0x696b] => balance: " + dst1Balance.toFixed(3) + " APL"); assert.equal(50000000 , dst1Balance); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3'); - + log ("[0x696b] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(50000000000 , voting); value = hackerGold.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; - + log("[0x696b] => balance: " + value.toFixed(3) + " HKG"); assert.equal(950000, value); - + log ("[APL] => total: " + total + " votes"); - - veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', + + veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', virtualExchange.address).toNumber() / 1000; log("[0x2980] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(950000 , veTokens); - - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); + + availableSupply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available supply: " + availableSupply + " APL"); return true; }) @@ -681,46 +681,46 @@ it('buy-apl-by-cd2a', function() { log(""); log(" (!) Action: [0xcd2a] buy tokens [APL] for 400,000.000 HKG"); - - return virtualExchange.buy('APL', 400000000, + + return virtualExchange.buy('APL', 400000000, { - from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { dst1Balance = dstContract_APL.balanceOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826').toNumber() / 1000; - + log("[0xcd2a] => balance: " + dst1Balance.toFixed(3) + " APL"); assert.equal(400000000 , dst1Balance); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826'); - + log ("[0xcd2a] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(400000000000 , voting); value = hackerGold.balanceOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826').toNumber() / 1000; - + log("[0xcd2a] => balance: " + value.toFixed(3) + " HKG"); assert.equal(600000, value); - + log ("[APL] => total: " + total + " votes"); - - veTokens = hackerGold.allowance('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + + veTokens = hackerGold.allowance('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', virtualExchange.address).toNumber() / 1000; log("[0xcd2a] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(600000, veTokens); - - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); + + availableSupply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available supply: " + availableSupply + " APL"); return true; }) @@ -730,59 +730,59 @@ it('buy-apl-by-cd2a', function() { log(""); log(" Voting Summary: "); log(" =============== "); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(25, voting / total * 100); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); - + log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(30, voting / total * 100); total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3'); - + log ("[0x696b] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(5, voting / total * 100); total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826'); - + log ("[0xcd2a] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(40, voting / total * 100); log ("[APL] => total: " + total + " votes"); assert.equal(1000000000000, total); - - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - assert.equal(0, availableSuply); + + availableSupply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available supply: " + availableSupply + " APL"); + assert.equal(0, availableSupply); - etherCollected = + etherCollected = dstContract_APL.getEtherValue().toNumber() / 1000000000000000000; log("[APL] => balance: " + etherCollected + " Ether"); assert.equal(0, etherCollected); - + hkgCollected = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; log("[APL] => collected balance: " + hkgCollected.toFixed(3) + " HKG"); assert.equal(1000000, hkgCollected); - - return true; - }) - - + return true; + + }) + + }); it('roll-time-event-stops', function(){ - + return workbench.rollTimeTo('22-Dec-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -794,9 +794,9 @@ it('issue-apl-tokens-seria-2', function() { log(""); log(" (!) Action: [APL] issue tokens: 1000000.000 APL"); - return dstContract_APL.issueTokens(100, 1000000000, + return dstContract_APL.issueTokens(100, 1000000000, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) .then(function () { @@ -804,18 +804,18 @@ it('issue-apl-tokens-seria-2', function() { dst1Total = dstContract_APL.getTotalSupply().toNumber() / 1000; log("[APL] => total: " + dst1Total.toFixed(3) + " APL"); assert.equal(1001000000 , dst1Total); - + issued = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + issued.toFixed(3) + " APL"); + log("[APL] => available supply: " + issued.toFixed(3) + " APL"); assert.equal(1000000 , issued); - + return true; }) }); -it('buy-all-apl-suply-seria-2', function() { +it('buy-all-apl-supply-seria-2', function() { log(""); log(" (!) Action: [0x3a7e] buy [APL] tokens for: 10000.000 Ether"); @@ -824,43 +824,43 @@ it('buy-all-apl-suply-seria-2', function() { to: dstContract_APL.address, value: sandbox.web3.toWei(10000, 'ether') }) - + .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { - + dst1Total = dstContract_APL.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; log("[0x3a7e] => balance: " + dst1Total + " APL"); assert.equal(251000000 , dst1Total); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(25, voting / total * 100); - - tokensSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber(); - log("[APL] => available suply: " + tokensSuply + " APL"); - assert.equal(0, tokensSuply); + + tokensSupply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber(); + log("[APL] => available supply: " + tokensSupply + " APL"); + assert.equal(0, tokensSupply); log(""); - - etherCollected = + + etherCollected = dstContract_APL.getEtherValue().toNumber() / 1000000000000000000; log("[APL] => balance: " + etherCollected + " Ether"); assert.equal(10000, etherCollected); - + hkgCollected = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; log("[APL] => collected balance: " + hkgCollected.toFixed(3) + " HKG"); assert.equal(1000000, hkgCollected); - - - return true; + + + return true; }) - + }); @@ -877,10 +877,10 @@ it('buy-tokens-with-no-ether', function() { to: dstContract_APL.address, value: sandbox.web3.toWei(1, 'ether') }) - + .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { @@ -888,10 +888,10 @@ it('buy-tokens-with-no-ether', function() { dst1Total = dstContract_APL.balanceOf('0x36cef404bd674e1aa6ba6b444c9ef458460c9871').toNumber() / 1000; log("[0x36ce] => balance: " + dst1Total + " APL"); assert.equal(0, dst1Total); - - return true; + + return true; }) - + }); @@ -899,32 +899,26 @@ it('buy-tokens-with-no-ether', function() { it('disable-token-issuance', function() { log(""); log(" (!) Action: [0x3a7e] disable [APL] tokens issueance option"); - - return dstContract_APL.disableTokenIssuance( + + return dstContract_APL.disableTokenIssuance( { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) .then(function () { - - etherCollected = + + etherCollected = dstContract_APL.getEtherValue().toNumber() / 1000000000000000000; log("[APL] => balance: " + etherCollected + " Ether"); assert.equal(10000, etherCollected); - + hkgCollected = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; log("[APL] => collected balance: " + hkgCollected.toFixed(3) + " HKG"); assert.equal(1000000, hkgCollected); - + return true; }) }); }); - - - - - - diff --git a/test/dst-management/initiate-tokens-test-3.js b/test/dst-management/initiate-tokens-test-3.js index 1fe26dd..1684950 100644 --- a/test/dst-management/initiate-tokens-test-3.js +++ b/test/dst-management/initiate-tokens-test-3.js @@ -6,8 +6,8 @@ var Workbench = require('ethereum-sandbox-workbench'); var workbench = new Workbench({ defaults: { from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826' - }, - + }, + solcVersion: '0.4.2' }); @@ -15,7 +15,7 @@ workbench.startTesting(['StandardToken', 'EventInfo', 'DSTContract', 'VirtualExc var sandbox = workbench.sandbox; -// deployed contracts +// deployed contracts var eventInfo; var hackerGold; var virtualExchange; @@ -28,76 +28,76 @@ var dstContract_AMZ; // Auto Motor Zone function printDate(){ now = eventInfo.getNow().toNumber(); var date = new Date(now*1000); - - log('\n Date now: ' + date + '\n'); + + log('\n Date now: ' + date + '\n'); } /** - * - * Testing for issue project token series: - * - * 1. - * 2. - * 3. + * + * Testing for issue project token series: + * + * 1. + * 2. + * 3. * * ... todo detailed description */ - + it('event-info-init', function() { - + log(''); log(' ***************************'); log(' initiate-tokens-test-3.js '); log(' ***************************'); log(''); - - + + return contracts.EventInfo.new() .then(function(contract) { - + if (contract.address){ eventInfo = contract; } else { throw new Error('No contract address'); - } - - return true; + } + + return true; }) - + .then(function() { - - printDate(); + + printDate(); return true; }); - + }); - + it('hacker-gold-init', function() { return contracts.HackerGold.new() .then(function(contract) { - + if (contract.address){ hackerGold = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); - + it('roll-time-ve-trading-start', function(){ - - // Roll time to get best price on HKG, - // 1 Ether for 200 HKG + + // Roll time to get best price on HKG, + // 1 Ether for 200 HKG return workbench.rollTimeTo('30-Oct-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -105,119 +105,119 @@ it('roll-time-ve-trading-start', function(){ it('buy-hkg-for-3a7e', function() { log(""); - log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); + log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); return workbench.sendTransaction({ from: '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', to: hackerGold.address, value: sandbox.web3.toWei(10000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); assert.equal(2000000, value); - - return true; + + return true; }) - + }); it('buy-hkg-for-2980', function() { log(""); - log(" (!) Action: [0x2980] buy [HKG] for 10,000.000 Ether"); + log(" (!) Action: [0x2980] buy [HKG] for 10,000.000 Ether"); return workbench.sendTransaction({ from: '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', to: hackerGold.address, value: sandbox.web3.toWei(10000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; - + log("[0x2980] => balance: " + value.toFixed(3) + " HKG"); assert.equal(2000000, value); - - return true; + + return true; }) - + }); it('buy-hkg-for-696b', function() { log(""); - log(" (!) Action: [0x696b] buy [HKG] for 5000.000 Ether"); + log(" (!) Action: [0x696b] buy [HKG] for 5000.000 Ether"); return workbench.sendTransaction({ from: '0x696ba93ef4254da47ff05b6caa88190db335f1c3', to: hackerGold.address, value: sandbox.web3.toWei(10000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; - + log("[0x696b] => balance: " + value.toFixed(3) + " HKG"); assert.equal(2000000, value); - - return true; + + return true; }) - + }); it('buy-hkg-for-cd2a', function() { log(""); - log(" (!) Action: [0xcd2a] buy [HKG] for 5000.000 Ether"); + log(" (!) Action: [0xcd2a] buy [HKG] for 5000.000 Ether"); return workbench.sendTransaction({ from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', to: hackerGold.address, value: sandbox.web3.toWei(10000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826').toNumber() / 1000; - + log("[0xcd2a] => balance: " + value.toFixed(3) + " HKG"); assert.equal(2000000, value); - - return true; + + return true; }) - + }); it('roll-time-ve-trading-start', function(){ - + return workbench.rollTimeTo('24-Nov-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -227,102 +227,102 @@ it('roll-time-ve-trading-start', function(){ it('virtual-exchange-init', function() { - return contracts.VirtualExchange.new(hackerGold.address, + return contracts.VirtualExchange.new(hackerGold.address, eventInfo.address) .then(function(contract) { - + if (contract.address){ virtualExchange = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); it('dst-contract-apl-init', function() { - return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", - + return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", + { from : '0xcc49bea5129ef2369ff81b0c0200885893979b77' }) .then(function(contract) { - + if (contract.address){ dstContract_APL = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); it('dst-contract-fbx-init', function() { - return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Filmbox", "FBX", - + return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Filmbox", "FBX", + { from : '0xcf22908ca26c5291502432044575ea7b900bf395' }) .then(function(contract) { - + if (contract.address){ dstContract_FBX = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); it('dst-contract-gog-init', function() { - return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Gog and Magog", "GOG", - + return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Gog and Magog", "GOG", + { from : '0xba33cc5dd6a60c891bcf93fbac8f13ee7512435f' }) .then(function(contract) { - + if (contract.address){ dstContract_GOG = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); it('dst-contract-amz-init', function() { - return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Gog and Maamz", "AMZ", - + return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Gog and Maamz", "AMZ", + { from : '0xdb5918d9282f0b280aac6bde061b92e903e11d18' }) .then(function(contract) { - + if (contract.address){ dstContract_AMZ = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); @@ -331,27 +331,27 @@ it('enlist-apl', function() { log(""); log(" (!) Action: [VE] enlist [APL] for trading"); - return virtualExchange.enlist(dstContract_APL.address, + return virtualExchange.enlist(dstContract_APL.address, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) - + .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) - + .then(function() { - - exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); - + + exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); + log("[APL] => enlisted: " + exist); assert.equal(true, exist); - + return true; }) - + }); @@ -359,27 +359,27 @@ it('enlist-fbx', function() { log(""); log(" (!) Action: [VE] enlist [FBX] for trading"); - return virtualExchange.enlist(dstContract_FBX.address, + return virtualExchange.enlist(dstContract_FBX.address, { - from : '0xcf22908ca26c5291502432044575ea7b900bf395', + from : '0xcf22908ca26c5291502432044575ea7b900bf395', }) - + .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) - + .then(function() { - - exist = virtualExchange.isExistByString(dstContract_FBX.getDSTSymbol()); - + + exist = virtualExchange.isExistByString(dstContract_FBX.getDSTSymbol()); + log("[FBX] => enlisted: " + exist); assert.equal(true, exist); - + return true; }) - + }); @@ -387,27 +387,27 @@ it('enlist-gog', function() { log(""); log(" (!) Action: [VE] enlist [GOG] for trading"); - return virtualExchange.enlist(dstContract_GOG.address, + return virtualExchange.enlist(dstContract_GOG.address, { - from : '0xba33cc5dd6a60c891bcf93fbac8f13ee7512435f', + from : '0xba33cc5dd6a60c891bcf93fbac8f13ee7512435f', }) - + .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) - + .then(function() { - - exist = virtualExchange.isExistByString(dstContract_GOG.getDSTSymbol()); - + + exist = virtualExchange.isExistByString(dstContract_GOG.getDSTSymbol()); + log("[GOG] => enlisted: " + exist); assert.equal(true, exist); - + return true; }) - + }); @@ -416,27 +416,27 @@ it('enlist-amz', function() { log(""); log(" (!) Action: [VE] enlist [AMZ] for trading"); - return virtualExchange.enlist(dstContract_AMZ.address, + return virtualExchange.enlist(dstContract_AMZ.address, { - from : '0xdb5918d9282f0b280aac6bde061b92e903e11d18', + from : '0xdb5918d9282f0b280aac6bde061b92e903e11d18', }) - + .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) - + .then(function() { - - exist = virtualExchange.isExistByString(dstContract_AMZ.getDSTSymbol()); - + + exist = virtualExchange.isExistByString(dstContract_AMZ.getDSTSymbol()); + log("[AMZ] => enlisted: " + exist); assert.equal(true, exist); - + return true; }) - + }); @@ -444,23 +444,23 @@ it('enlist-amz', function() { it('issue-apl-tokens-seria-1', function() { log(""); log(" (!) Action: [APL] issue tokens on [VE] balance 1,000,000,000,000.000 APL"); - - return dstContract_APL.issuePreferedTokens(1000, 1000000000000, + + return dstContract_APL.issuePreferedTokens(1000, 1000000000000, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) .then(function () { - + dst1Total = dstContract_APL.getTotalSupply().toNumber() / 1000; - - log("[APL] => total suply: " + dst1Total.toFixed(3) + " APL"); - assert(1000000000000, dst1Total); - - veTokens = dstContract_APL.allowance(dstContract_APL.address, + + log("[APL] => total supply: " + dst1Total.toFixed(3) + " APL"); + assert.equal(1000000000, dst1Total); + + veTokens = dstContract_APL.allowance(dstContract_APL.address, virtualExchange.address).toNumber() / 1000; log("[APL] => total on VirtualExchange: " + veTokens.toFixed(3) + " APL"); - assert(1000000000000, veTokens); + assert.equal(1000000000, veTokens); return true; }) @@ -470,23 +470,23 @@ it('issue-apl-tokens-seria-1', function() { it('issue-fbx-tokens-seria-1', function() { log(""); log(" (!) Action: [FBX] issue tokens on [VE] balance 1,000,000,000,000.000 FBX"); - - return dstContract_FBX.issuePreferedTokens(1000, 1000000000000, + + return dstContract_FBX.issuePreferedTokens(1000, 1000000000000, { - from : '0xcf22908ca26c5291502432044575ea7b900bf395', + from : '0xcf22908ca26c5291502432044575ea7b900bf395', }) .then(function () { - + dst1Total = dstContract_FBX.getTotalSupply().toNumber() / 1000; - - log("[FBX] => total suply: " + dst1Total.toFixed(3) + " FBX"); - assert(1000000000000, dst1Total); - - veTokens = dstContract_FBX.allowance(dstContract_FBX.address, + + log("[FBX] => total supply: " + dst1Total.toFixed(3) + " FBX"); + assert.equal(1000000000, dst1Total); + + veTokens = dstContract_FBX.allowance(dstContract_FBX.address, virtualExchange.address).toNumber() / 1000; log("[FBX] => total on VirtualExchange: " + veTokens.toFixed(3) + " FBX"); - assert(1000000000000, veTokens); + assert.equal(1000000000, veTokens); return true; }) @@ -496,23 +496,23 @@ it('issue-fbx-tokens-seria-1', function() { it('issue-gog-tokens-seria-1', function() { log(""); log(" (!) Action: [GOG] issue tokens on [VE] balance 1,000,000,000,000.000 GOG"); - - return dstContract_GOG.issuePreferedTokens(1000, 1000000000000, + + return dstContract_GOG.issuePreferedTokens(1000, 1000000000000, { - from : '0xba33cc5dd6a60c891bcf93fbac8f13ee7512435f', + from : '0xba33cc5dd6a60c891bcf93fbac8f13ee7512435f', }) .then(function () { - + dst1Total = dstContract_GOG.getTotalSupply().toNumber() / 1000; - - log("[GOG] => total suply: " + dst1Total.toFixed(3) + " GOG"); - assert(1000000000000, dst1Total); - - veTokens = dstContract_GOG.allowance(dstContract_GOG.address, + + log("[GOG] => total supply: " + dst1Total.toFixed(3) + " GOG"); + assert.equal(1000000000, dst1Total); + + veTokens = dstContract_GOG.allowance(dstContract_GOG.address, virtualExchange.address).toNumber() / 1000; log("[GOG] => total on VirtualExchange: " + veTokens.toFixed(3) + " GOG"); - assert(1000000000000, veTokens); + assert.equal(1000000000, veTokens); return true; }) @@ -524,23 +524,23 @@ it('issue-gog-tokens-seria-1', function() { it('issue-amz-tokens-seria-1', function() { log(""); log(" (!) Action: [AMZ] issue tokens on [VE] balance 1,000,000,000,000.000 AMZ"); - - return dstContract_AMZ.issuePreferedTokens(1000, 1000000000000, + + return dstContract_AMZ.issuePreferedTokens(1000, 1000000000000, { - from : '0xdb5918d9282f0b280aac6bde061b92e903e11d18', + from : '0xdb5918d9282f0b280aac6bde061b92e903e11d18', }) .then(function () { - + dst1Total = dstContract_AMZ.getTotalSupply().toNumber() / 1000; - - log("[AMZ] => total suply: " + dst1Total.toFixed(3) + " AMZ"); - assert(1000000000000, dst1Total); - - veTokens = dstContract_AMZ.allowance(dstContract_AMZ.address, + + log("[AMZ] => total supply: " + dst1Total.toFixed(3) + " AMZ"); + assert.equal(1000000000, dst1Total); + + veTokens = dstContract_AMZ.allowance(dstContract_AMZ.address, virtualExchange.address).toNumber() / 1000; log("[AMZ] => total on VirtualExchange: " + veTokens.toFixed(3) + " AMZ"); - assert(1000000000000, veTokens); + assert.equal(1000000000, veTokens); return true; }) @@ -551,25 +551,25 @@ it('issue-amz-tokens-seria-1', function() { it('approve-hkg-spend-on-exchange-for-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 2000000000, + + return hackerGold.approve(virtualExchange.address, 2000000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; - + log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(2000000, veTokens); - + return true; }) }); @@ -578,25 +578,25 @@ it('approve-hkg-spend-on-exchange-for-3a7e', function() { it('approve-hkg-spend-on-exchange-for-2980', function() { log(""); log(" (!) Action: [0x2980] move to [VE] balance 2,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 2000000000, + + return hackerGold.approve(virtualExchange.address, 2000000000, { - from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', virtualExchange.address).toNumber() / 1000; - + log("[0x2980] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(2000000, veTokens); - + return true; }) }); @@ -605,25 +605,25 @@ it('approve-hkg-spend-on-exchange-for-2980', function() { it('approve-hkg-spend-on-exchange-for-696b', function() { log(""); log(" (!) Action: [0x696b] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 2000000000, + + return hackerGold.approve(virtualExchange.address, 2000000000, { - from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', + from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', + veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', virtualExchange.address).toNumber() / 1000; - + log("[0x696b] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(2000000, veTokens); - + return true; }) }); @@ -633,25 +633,25 @@ it('approve-hkg-spend-on-exchange-for-696b', function() { it('approve-hkg-spend-on-exchange-for-cd2a', function() { log(""); log(" (!) Action: [0xcd2a] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 2000000000, + + return hackerGold.approve(virtualExchange.address, 2000000000, { - from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - veTokens = hackerGold.allowance('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + veTokens = hackerGold.allowance('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', virtualExchange.address).toNumber() / 1000; - + log("[0xcd2a] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(2000000, veTokens); - + return true; }) }); @@ -661,49 +661,49 @@ it('buy-apl-by-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] buy tokens [APL] for 300,000.000 HKG"); - - return virtualExchange.buy('APL', 300000000, + + return virtualExchange.buy('APL', 300000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { dst1Balance = dstContract_APL.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " APL"); assert.equal(300000000 , dst1Balance); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(300000000000 , voting); value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(1700000, value); - + assert.equal(1700000, value); + log ("[APL] => total: " + total + " votes"); assert.equal(300000000000, total); - - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(1700000 , veTokens); - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - assert.equal(700000000 , availableSuply); - + availableSupply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available supply: " + availableSupply + " APL"); + assert.equal(700000000 , availableSupply); + return true; }) }); @@ -714,21 +714,21 @@ it('buy-apl-by-3a7e', function() { it('issue-apl-tokens-seria-1', function() { log(""); log(" (!) Action: [APL] price change to 0.5 APL for 1 HKG "); - - return dstContract_APL.setHKGPrice(500, + + return dstContract_APL.setHKGPrice(500, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) .then(function () { - + qtyForOneHkg = dstContract_APL.getHKGPrice().toNumber() / 1000; - + log("[APL] => price 1 HKG = " + qtyForOneHkg + " APL"); - + //...todo check the event - + return true; }) }); @@ -742,16 +742,16 @@ it('issue-apl-tokens-seria-1', function() { it('issue-apl-tokens-seria-1', function() { log(""); log(" [X] Action: [APL] price change by mal actor "); - - return dstContract_APL.setHKGPrice(50000, + + return dstContract_APL.setHKGPrice(50000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', }) .then(function () { - + qtyForOneHkg = dstContract_APL.getHKGPrice().toNumber() / 1000; - + log("[APL] => price 1 HKG = " + qtyForOneHkg + " APL"); return true; @@ -764,68 +764,68 @@ it('buy-apl-by-2980', function() { log(""); log(" (!) Action: [0x2980] buy tokens [APL] for 1,400,000.000 HKG"); - - return virtualExchange.buy('APL', 1400000000, + + return virtualExchange.buy('APL', 1400000000, { - from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { dst1Balance = dstContract_APL.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; - + log("[0x2980] => balance: " + dst1Balance.toFixed(3) + " APL"); assert.equal(700000000 , dst1Balance); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); - + log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(700000000000 , voting); value = hackerGold.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; - + log("[0x2980] => balance: " + value.toFixed(3) + " HKG"); assert.equal(600000, value); - + log ("[APL] => total: " + total + " votes"); - - veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + + veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', virtualExchange.address).toNumber() / 1000; log("[0x2980] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(600000 , veTokens); - - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - + + availableSupply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available supply: " + availableSupply + " APL"); + log(""); log(" Voting Summary: "); log(" =============== "); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(30, voting / total * 100); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); - + log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(70, voting / total * 100); + assert.equal(70, voting / total * 100); value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; log("[APL] => collected: " + value.toFixed(3) + " HKG"); - assert.equal(1700000, value); - + assert.equal(1700000, value); + return true; }) }); @@ -837,49 +837,49 @@ it('buy-fbx-by-696b', function() { log(""); log(" (!) Action: [0x696b] buy tokens [FBX] for 480,000.000 HKG"); - - return virtualExchange.buy('FBX', 480000000, + + return virtualExchange.buy('FBX', 480000000, { - from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', + from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { dst1Balance = dstContract_FBX.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; - + log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " FBX"); assert.equal(480000000 , dst1Balance); - + total = dstContract_FBX.getPreferedQtySold(); voting = dstContract_FBX.votingRightsOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(480000000000 , voting); value = hackerGold.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(1520000, value); - + assert.equal(1520000, value); + log ("[FBX] => total: " + total + " votes"); assert.equal(480000000000, total); - - veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', + + veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', virtualExchange.address).toNumber() / 1000; log("[0x696b] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(1520000 , veTokens); - availableSuply = dstContract_FBX.balanceOf(dstContract_FBX.address).toNumber() / 1000; - log("[FBX] => available suply: " + availableSuply + " FBX"); - assert.equal(520000000 , availableSuply); - + availableSupply = dstContract_FBX.balanceOf(dstContract_FBX.address).toNumber() / 1000; + log("[FBX] => available supply: " + availableSupply + " FBX"); + assert.equal(520000000 , availableSupply); + return true; }) }); @@ -890,69 +890,69 @@ it('buy-fbx-by-0xcd2a', function() { log(""); log(" (!) Action: [0xcd2a] buy tokens [FBX] for 520,000.000 HKG"); - - return virtualExchange.buy('FBX', 520000000, + + return virtualExchange.buy('FBX', 520000000, { - from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { dst1Balance = dstContract_FBX.balanceOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826').toNumber() / 1000; - + log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " FBX"); assert.equal(520000000 , dst1Balance); - + total = dstContract_FBX.getPreferedQtySold(); voting = dstContract_FBX.votingRightsOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(520000000000 , voting); value = hackerGold.balanceOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826').toNumber() / 1000; - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(1480000, value); - + assert.equal(1480000, value); + log ("[FBX] => total: " + total + " votes"); assert.equal(1000000000000, total); - - veTokens = hackerGold.allowance('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + + veTokens = hackerGold.allowance('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', virtualExchange.address).toNumber() / 1000; log("[0x696b] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(1480000 , veTokens); - availableSuply = dstContract_FBX.balanceOf(dstContract_FBX.address).toNumber() / 1000; - log("[FBX] => available suply: " + availableSuply + " FBX"); - assert.equal(0 , availableSuply); - + availableSupply = dstContract_FBX.balanceOf(dstContract_FBX.address).toNumber() / 1000; + log("[FBX] => available supply: " + availableSupply + " FBX"); + assert.equal(0 , availableSupply); + log(""); log(" Voting Summary: "); log(" =============== "); - + total = dstContract_FBX.getPreferedQtySold(); voting = dstContract_FBX.votingRightsOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(48, voting / total * 100); - + total = dstContract_FBX.getPreferedQtySold(); voting = dstContract_FBX.votingRightsOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826'); - + log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(52, voting / total * 100); + assert.equal(52, voting / total * 100); value = hackerGold.balanceOf(dstContract_FBX.address).toNumber() / 1000; log("[FBX] => collected: " + value.toFixed(3) + " HKG"); - assert.equal(1000000, value); - + assert.equal(1000000, value); + return true; }) }); @@ -962,49 +962,49 @@ it('buy-gog-by-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] buy tokens [GOG] for 100,000.000 HKG"); - - return virtualExchange.buy('GOG', 100000000, + + return virtualExchange.buy('GOG', 100000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { dst1Balance = dstContract_GOG.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " GOG"); - assert.equal(100000000 , dst1Balance); - + assert.equal(100000000 , dst1Balance); + total = dstContract_GOG.getPreferedQtySold(); voting = dstContract_GOG.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(100000000000 , voting); value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(1600000, value); - + assert.equal(1600000, value); + log ("[GOG] => total: " + total + " votes"); assert.equal(100000000000, total); - - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(1600000 , veTokens); - availableSuply = dstContract_GOG.balanceOf(dstContract_GOG.address).toNumber() / 1000; - log("[GOG] => available suply: " + availableSuply + " GOG"); - assert.equal(900000000 , availableSuply); - + availableSupply = dstContract_GOG.balanceOf(dstContract_GOG.address).toNumber() / 1000; + log("[GOG] => available supply: " + availableSupply + " GOG"); + assert.equal(900000000 , availableSupply); + return true; }) }); @@ -1014,21 +1014,21 @@ it('buy-gog-by-3a7e', function() { it('change-price-gog-tokens-seria-1', function() { log(""); log(" (!) Action: [GOG] price change to 2 GOG for 1 HKG "); - - return dstContract_GOG.setHKGPrice(2000, + + return dstContract_GOG.setHKGPrice(2000, { - from : '0xba33cc5dd6a60c891bcf93fbac8f13ee7512435f', + from : '0xba33cc5dd6a60c891bcf93fbac8f13ee7512435f', }) .then(function () { - + qtyForOneHkg = dstContract_GOG.getHKGPrice().toNumber() / 1000; - + log("[GOG] => price 1 HKG = " + qtyForOneHkg + " GOG"); assert.equal(2, qtyForOneHkg.toFixed(3)); - + //...todo check the event - + return true; }) }); @@ -1038,49 +1038,49 @@ it('buy-gog-by-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] buy tokens [GOG] for 300,000.000 HKG"); - - return virtualExchange.buy('GOG', 300000000, + + return virtualExchange.buy('GOG', 300000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { dst1Balance = dstContract_GOG.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " GOG"); - assert.equal(700000000 , dst1Balance); - + assert.equal(700000000 , dst1Balance); + total = dstContract_GOG.getPreferedQtySold(); voting = dstContract_GOG.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(700000000000 , voting); value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(1300000, value); - + assert.equal(1300000, value); + log ("[GOG] => total: " + total + " votes"); assert.equal(700000000000, total); - - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(1300000 , veTokens); - availableSuply = dstContract_GOG.balanceOf(dstContract_GOG.address).toNumber() / 1000; - log("[GOG] => available suply: " + availableSuply + " GOG"); - assert.equal(300000000 , availableSuply); - + availableSupply = dstContract_GOG.balanceOf(dstContract_GOG.address).toNumber() / 1000; + log("[GOG] => available supply: " + availableSupply + " GOG"); + assert.equal(300000000 , availableSupply); + return true; }) }); @@ -1090,21 +1090,21 @@ it('buy-gog-by-3a7e', function() { it('change-price-gog-tokens-seria-1', function() { log(""); log(" (!) Action: [GOG] price change to 1 GOG for 1 HKG "); - - return dstContract_GOG.setHKGPrice(1000, + + return dstContract_GOG.setHKGPrice(1000, { - from : '0xba33cc5dd6a60c891bcf93fbac8f13ee7512435f', + from : '0xba33cc5dd6a60c891bcf93fbac8f13ee7512435f', }) .then(function () { - + qtyForOneHkg = dstContract_GOG.getHKGPrice().toNumber() / 1000; - + log("[GOG] => price 1 HKG = " + qtyForOneHkg + " GOG"); assert.equal(1, qtyForOneHkg.toFixed(3)); - + //...todo check the event - + return true; }) }); @@ -1116,62 +1116,62 @@ it('buy-gog-by-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] buy tokens [GOG] for 300,000.000 HKG"); - - return virtualExchange.buy('GOG', 300000000, + + return virtualExchange.buy('GOG', 300000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { dst1Balance = dstContract_GOG.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " GOG"); - assert.equal(1000000000 , dst1Balance); - + assert.equal(1000000000 , dst1Balance); + total = dstContract_GOG.getPreferedQtySold(); voting = dstContract_GOG.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(1000000000000 , voting); value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(1000000, value); - + assert.equal(1000000, value); + log ("[GOG] => total: " + total + " votes"); assert.equal(1000000000000, total); - - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(1000000 , veTokens); - availableSuply = dstContract_GOG.balanceOf(dstContract_GOG.address).toNumber() / 1000; - log("[GOG] => available suply: " + availableSuply + " GOG"); - assert.equal(0 , availableSuply); - - + availableSupply = dstContract_GOG.balanceOf(dstContract_GOG.address).toNumber() / 1000; + log("[GOG] => available supply: " + availableSupply + " GOG"); + assert.equal(0 , availableSupply); + + log(""); log(" Voting Summary: "); log(" =============== "); - + total = dstContract_GOG.getPreferedQtySold(); voting = dstContract_GOG.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(100, voting / total * 100); - - - - + + + + return true; }) }); @@ -1179,7 +1179,7 @@ it('buy-gog-by-3a7e', function() { it('roll-time-va-ends', function(){ - + return workbench.rollTimeTo('22-Dec-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -1189,7 +1189,7 @@ it('roll-time-va-ends', function(){ it('end-event-summary', function() { log(""); - + //var dstContract_APL; // Awesome Poker League //var dstContract_FBX; // Filmbox //var dstContract_GOG; // Gog and Magog @@ -1197,33 +1197,33 @@ it('end-event-summary', function() { log("Post Event Summary:"); log("==================="); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - dollarValue = value / 100; + + dollarValue = value / 100; log("[APL] => collected: " + value.toFixed(3) + " HKG" + " = $" + dollarValue); - assert.equal(17000, dollarValue); + assert.equal(17000, dollarValue); value = hackerGold.balanceOf(dstContract_FBX.address).toNumber() / 1000; - - dollarValue = value / 100; + + dollarValue = value / 100; log("[FBX] => collected: " + value.toFixed(3) + " HKG" + " = $" + dollarValue); - assert.equal(10000, dollarValue); + assert.equal(10000, dollarValue); value = hackerGold.balanceOf(dstContract_GOG.address).toNumber() / 1000; - dollarValue = value / 100; + dollarValue = value / 100; log("[GOG] => collected: " + value.toFixed(3) + " HKG" + " = $" + dollarValue); - assert.equal(7000, dollarValue); - - + assert.equal(7000, dollarValue); + + value = hackerGold.balanceOf(dstContract_AMZ.address).toNumber() / 1000; - - dollarValue = value / 100; + + dollarValue = value / 100; log("[AMZ] => collected: " + value.toFixed(3) + " HKG" + " = $" + dollarValue); - assert.equal(0, dollarValue); - - + assert.equal(0, dollarValue); + + return true; }); @@ -1234,9 +1234,9 @@ it('issue-apl-tokens-seria-2', function() { log(""); log(" (!) Action: [APL] issue tokens: 1000000.000 APL"); - return dstContract_APL.issueTokens(100, 1000000000, + return dstContract_APL.issueTokens(100, 1000000000, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) .then(function () { @@ -1244,11 +1244,11 @@ it('issue-apl-tokens-seria-2', function() { dst1Total = dstContract_APL.getTotalSupply().toNumber() / 1000; log("[APL] => total: " + dst1Total.toFixed(3) + " APL"); assert.equal(1001000000 , dst1Total); - + issued = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + issued.toFixed(3) + " APL"); + log("[APL] => available supply: " + issued.toFixed(3) + " APL"); assert.equal(1000000 , issued); - + return true; }) }); @@ -1259,9 +1259,9 @@ it('issue-fbx-tokens-seria-2', function() { log(""); log(" (!) Action: [FBX] issue tokens: 1000000.000 FBX"); - return dstContract_FBX.issueTokens(20, 1000000000, + return dstContract_FBX.issueTokens(20, 1000000000, { - from : '0xcf22908ca26c5291502432044575ea7b900bf395', + from : '0xcf22908ca26c5291502432044575ea7b900bf395', }) .then(function () { @@ -1269,11 +1269,11 @@ it('issue-fbx-tokens-seria-2', function() { dst1Total = dstContract_FBX.getTotalSupply().toNumber() / 1000; log("[FBX] => total: " + dst1Total.toFixed(3) + " FBX"); assert.equal(1001000000 , dst1Total); - + issued = dstContract_FBX.balanceOf(dstContract_FBX.address).toNumber() / 1000; - log("[FBX] => available suply: " + issued.toFixed(3) + " FBX"); + log("[FBX] => available supply: " + issued.toFixed(3) + " FBX"); assert.equal(1000000 , issued); - + return true; }) }); @@ -1284,9 +1284,9 @@ it('issue-gog-tokens-seria-2', function() { log(""); log(" (!) Action: [GOG] issue tokens: 1000000.000 GOG"); - return dstContract_GOG.issueTokens(250, 1000000000, + return dstContract_GOG.issueTokens(250, 1000000000, { - from : '0xba33cc5dd6a60c891bcf93fbac8f13ee7512435f', + from : '0xba33cc5dd6a60c891bcf93fbac8f13ee7512435f', }) .then(function () { @@ -1294,11 +1294,11 @@ it('issue-gog-tokens-seria-2', function() { dst1Total = dstContract_GOG.getTotalSupply().toNumber() / 1000; log("[GOG] => total: " + dst1Total.toFixed(3) + " GOG"); assert.equal(1001000000 , dst1Total); - + issued = dstContract_GOG.balanceOf(dstContract_GOG.address).toNumber() / 1000; - log("[GOG] => available suply: " + issued.toFixed(3) + " GOG"); + log("[GOG] => available supply: " + issued.toFixed(3) + " GOG"); assert.equal(1000000 , issued); - + return true; }) }); @@ -1307,7 +1307,7 @@ it('issue-gog-tokens-seria-2', function() { -it('buy-all-apl-suply-seria-2', function() { +it('buy-all-apl-supply-seria-2', function() { log(""); log(" (!) Action: [0xdedb] buy [APL] tokens for: 10000.000 Ether"); @@ -1316,42 +1316,42 @@ it('buy-all-apl-suply-seria-2', function() { to: dstContract_APL.address, value: sandbox.web3.toWei(10000, 'ether') }) - + .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { - + dst1Total = dstContract_APL.balanceOf('0xdedb49385ad5b94a16f236a6890cf9e0b1e30392').toNumber() / 1000; log("[0xdedb] => balance: " + dst1Total + " APL"); assert.equal(1000000 , dst1Total); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0xdedb49385ad5b94a16f236a6890cf9e0b1e30392'); - + log("[0xdedb] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(0, voting / total * 100); - - tokensSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber(); - log("[APL] => available suply: " + tokensSuply + " APL"); - assert.equal(0, tokensSuply); + + tokensSupply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber(); + log("[APL] => available supply: " + tokensSupply + " APL"); + assert.equal(0, tokensSupply); log(""); - - etherCollected = + + etherCollected = dstContract_APL.getEtherValue().toNumber() / 1000000000000000000; log("[APL] => balance: " + etherCollected + " Ether"); assert.equal(10000, etherCollected); - + hkgCollected = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; log("[APL] => collected balance: " + hkgCollected.toFixed(3) + " HKG"); assert.equal(1700000, hkgCollected); - - return true; + + return true; }) - + }); @@ -1360,7 +1360,7 @@ it('buy-all-apl-suply-seria-2', function() { -it('buy-all-fbx-suply-seria-2', function() { +it('buy-all-fbx-supply-seria-2', function() { log(""); log(" (!) Action: [0xdedb] buy [FBX] tokens for: 50000.000 Ether"); @@ -1369,52 +1369,52 @@ it('buy-all-fbx-suply-seria-2', function() { to: dstContract_FBX.address, value: sandbox.web3.toWei(50001, 'ether') }) - + .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { - + dst1Total = dstContract_FBX.balanceOf('0xdedb49385ad5b94a16f236a6890cf9e0b1e30392').toNumber() / 1000; dst1Total = Math.ceil(dst1Total); - + log("[0xdedb] => balance: " + dst1Total + " FBX"); assert.equal(1000000 , dst1Total); - + total = dstContract_FBX.getPreferedQtySold(); voting = dstContract_FBX.votingRightsOf('0xdedb49385ad5b94a16f236a6890cf9e0b1e30392'); - + log("[0xdedb] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(0, voting / total * 100); - - tokensSuply = dstContract_FBX.balanceOf(dstContract_FBX.address).toNumber(); - log("[FBX] => available suply: " + tokensSuply + " FBX"); - assert.equal(0, tokensSuply); + + tokensSupply = dstContract_FBX.balanceOf(dstContract_FBX.address).toNumber(); + log("[FBX] => available supply: " + tokensSupply + " FBX"); + assert.equal(0, tokensSupply); log(""); - - etherCollected = + + etherCollected = dstContract_FBX.getEtherValue().toNumber() / 1000000000000000000; etherCollected = Math.ceil(etherCollected) log("[FBX] => balance: " + etherCollected + " Ether"); - + assert.equal(50000, etherCollected); - + hkgCollected = hackerGold.balanceOf(dstContract_FBX.address).toNumber() / 1000; log("[FBX] => collected balance: " + hkgCollected.toFixed(3) + " HKG"); assert.equal(1000000, hkgCollected); - - return true; + + return true; }) - + }); -it('buy-all-gog-suply-seria-2', function() { +it('buy-all-gog-supply-seria-2', function() { log(""); log(" (!) Action: [0xdedb] buy [GOG] tokens for: 4000 Ether"); @@ -1422,54 +1422,54 @@ it('buy-all-gog-suply-seria-2', function() { from: '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', to: dstContract_GOG.address, value: sandbox.web3.toWei(4000, 'ether') - }) - + }) + .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { - + dst1Total = dstContract_GOG.balanceOf('0xdedb49385ad5b94a16f236a6890cf9e0b1e30392').toNumber() / 1000; dst1Total = Math.ceil(dst1Total); - + log("[0xdedb] => balance: " + dst1Total + " GOG"); assert.equal(1000000 , dst1Total); - + total = dstContract_GOG.getPreferedQtySold(); voting = dstContract_GOG.votingRightsOf('0xdedb49385ad5b94a16f236a6890cf9e0b1e30392'); - + log("[0xdedb] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(0, voting / total * 100); - - tokensSuply = dstContract_GOG.balanceOf(dstContract_GOG.address).toNumber(); - log("[GOG] => available suply: " + tokensSuply + " GOG"); - assert.equal(0, tokensSuply); + + tokensSupply = dstContract_GOG.balanceOf(dstContract_GOG.address).toNumber(); + log("[GOG] => available supply: " + tokensSupply + " GOG"); + assert.equal(0, tokensSupply); log(""); - - etherCollected = + + etherCollected = dstContract_GOG.getEtherValue().toNumber() / 1000000000000000000; etherCollected = Math.ceil(etherCollected) log("[GOG] => balance: " + etherCollected + " Ether"); - + assert.equal(4000, etherCollected); - + hkgCollected = hackerGold.balanceOf(dstContract_GOG.address).toNumber() / 1000; log("[GOG] => collected balance: " + hkgCollected.toFixed(3) + " HKG"); assert.equal(700000, hkgCollected); - - return true; + + return true; }) - + }); it('end-sale-summary', function() { log(""); - + //var dstContract_APL; // Awesome Poker League //var dstContract_FBX; // Filmbox //var dstContract_GOG; // Gog and Magog @@ -1477,57 +1477,51 @@ it('end-sale-summary', function() { log("Post Event Summary:"); log("==================="); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - dollarValue = value / 100; + + dollarValue = value / 100; log("[APL] => collected: " + value.toFixed(3) + " HKG" + " = $" + dollarValue); - assert.equal(17000, dollarValue); - - etherCollected = + assert.equal(17000, dollarValue); + + etherCollected = dstContract_APL.getEtherValue().toNumber() / 1000000000000000000; log("[APL] => collected: " + etherCollected + " Ether" + " = $" + etherCollected * 12); - assert.equal(10000, etherCollected); - + assert.equal(10000, etherCollected); + log(""); value = hackerGold.balanceOf(dstContract_FBX.address).toNumber() / 1000; - - dollarValue = value / 100; + + dollarValue = value / 100; log("[FBX] => collected: " + value.toFixed(3) + " HKG" + " = $" + dollarValue); - assert.equal(10000, dollarValue); + assert.equal(10000, dollarValue); value = hackerGold.balanceOf(dstContract_GOG.address).toNumber() / 1000; - etherCollected = + etherCollected = dstContract_FBX.getEtherValue().toNumber() / 1000000000000000000; etherCollected = Math.ceil(etherCollected); - + log("[FBX] => collected: " + etherCollected + " Ether" + " = $" + etherCollected * 12); - assert.equal(50000, etherCollected); - + assert.equal(50000, etherCollected); + log(""); - - dollarValue = value / 100; + + dollarValue = value / 100; log("[GOG] => collected: " + value.toFixed(3) + " HKG" + " = $" + dollarValue); - assert.equal(7000, dollarValue); - - etherCollected = + assert.equal(7000, dollarValue); + + etherCollected = dstContract_GOG.getEtherValue().toNumber() / 1000000000000000000; etherCollected = Math.ceil(etherCollected); - + log("[GOG] => collected: " + etherCollected + " Ether" + " = $" + etherCollected * 12); - assert.equal(4000, etherCollected); - + assert.equal(4000, etherCollected); + return true; }); }); - - - - - - diff --git a/test/dst-management/requesting-funds-test-1.js b/test/dst-management/requesting-funds-test-1.js index e2e515a..d3790fd 100644 --- a/test/dst-management/requesting-funds-test-1.js +++ b/test/dst-management/requesting-funds-test-1.js @@ -7,8 +7,8 @@ var Workbench = require('ethereum-sandbox-workbench'); var workbench = new Workbench({ defaults: { from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826' - }, - + }, + solcVersion: '0.4.2' }); @@ -16,7 +16,7 @@ workbench.startTesting(['StandardToken', 'EventInfo', 'DSTContract', 'VirtualExc var sandbox = workbench.sandbox; -// deployed contracts +// deployed contracts var eventInfo; var hackerGold; var virtualExchange; @@ -33,74 +33,74 @@ var proposal_5; function printDate(){ now = eventInfo.getNow().toNumber(); var date = new Date(now*1000); - - log('\n Date now: ' + date + '\n'); + + log('\n Date now: ' + date + '\n'); } /** - * - * Testing for requesting HKG funds after the event : - * - * 1. - * 2. - * 3. + * + * Testing for requesting HKG funds after the event : + * + * 1. + * 2. + * 3. * * ... todo detailed description */ - + it('event-info-init', function() { - + log(''); log(' *****************************'); log(' requesting-funds-test-1.js '); log(' *****************************'); - log(''); - + log(''); + return contracts.EventInfo.new() .then(function(contract) { - + if (contract.address){ eventInfo = contract; } else { throw new Error('No contract address'); - } - - return true; + } + + return true; }) - + .then(function() { - - printDate(); + + printDate(); return true; }); - + }); - + it('hacker-gold-init', function() { return contracts.HackerGold.new() .then(function(contract) { - + if (contract.address){ hackerGold = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); - + it('roll-time-ve-trading-start', function(){ - - // Roll time to get best price on HKG, - // 1 Ether for 200 HKG + + // Roll time to get best price on HKG, + // 1 Ether for 200 HKG return workbench.rollTimeTo('30-Oct-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -108,35 +108,35 @@ it('roll-time-ve-trading-start', function(){ it('buy-hkg-for-3a7e', function() { log(""); - log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); + log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); return workbench.sendTransaction({ from: '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', to: hackerGold.address, value: sandbox.web3.toWei(500000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; value = Math.ceil(value); - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); assert.equal(100000000, value); - - return true; + + return true; }) - + }); it('roll-time-ve-trading-start', function(){ - + return workbench.rollTimeTo('24-Nov-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -146,39 +146,39 @@ it('roll-time-ve-trading-start', function(){ it('virtual-exchange-init', function() { - return contracts.VirtualExchange.new(hackerGold.address, + return contracts.VirtualExchange.new(hackerGold.address, eventInfo.address) .then(function(contract) { - + if (contract.address){ virtualExchange = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); it('dst-contract-apl-init', function() { - return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", - + return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", + { from : '0xcc49bea5129ef2369ff81b0c0200885893979b77' }) .then(function(contract) { - + if (contract.address){ dstContract_APL = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); @@ -187,27 +187,27 @@ it('enlist-apl', function() { log(""); log(" (!) Action: [VE] enlist [APL] for trading"); - return virtualExchange.enlist(dstContract_APL.address, + return virtualExchange.enlist(dstContract_APL.address, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) - + .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) - + .then(function() { - - exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); - + + exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); + log("[APL] => enlisted: " + exist); assert.equal(true, exist); - + return true; }) - + }); @@ -215,23 +215,23 @@ it('enlist-apl', function() { it('issue-apl-tokens-seria-1', function() { log(""); log(" (!) Action: [APL] issue tokens on [VE] balance 1,000,000,000,000.000 APL"); - - return dstContract_APL.issuePreferedTokens(1000, 1000000000000000, + + return dstContract_APL.issuePreferedTokens(1000, 1000000000000000, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) .then(function () { - + dst1Total = dstContract_APL.getTotalSupply().toNumber() / 1000; - - log("[APL] => total suply: " + dst1Total.toFixed(3) + " APL"); - assert(1000000000000000, dst1Total); - - veTokens = dstContract_APL.allowance(dstContract_APL.address, + + log("[APL] => total supply: " + dst1Total.toFixed(3) + " APL"); + assert.equal(1000000000000, dst1Total); + + veTokens = dstContract_APL.allowance(dstContract_APL.address, virtualExchange.address).toNumber() / 1000; log("[APL] => total on VirtualExchange: " + veTokens.toFixed(3) + " APL"); - assert(1000000000000000, veTokens); + assert.equal(1000000000000, veTokens); return true; }) @@ -242,25 +242,25 @@ it('issue-apl-tokens-seria-1', function() { it('approve-hkg-spend-on-exchange-for-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 100000000000, + + return hackerGold.approve(virtualExchange.address, 100000000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; - + log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(100000000, veTokens); - + return true; }) }); @@ -271,50 +271,50 @@ it('buy-apl-by-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] buy tokens [APL] for 50,000,000.000 HKG"); - - return virtualExchange.buy('APL', 5000000000, + + return virtualExchange.buy('APL', 5000000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { dst1Balance = dstContract_APL.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " APL"); assert.equal(5000000000 , dst1Balance); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(5000000000000 , voting); value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; value = Math.ceil(value); - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(95000000, value); - + assert.equal(95000000, value); + log ("[APL] => total: " + total + " votes"); assert.equal(5000000000000, total); - - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(95000000 , veTokens); + assert.equal(95000000 , veTokens); + + availableSupply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available supply: " + availableSupply + " APL"); + assert.equal(995000000000 , availableSupply); - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - assert.equal(995000000000 , availableSuply); - return true; }) }); @@ -322,7 +322,7 @@ it('buy-apl-by-3a7e', function() { it('roll-time-va-ends', function(){ - + return workbench.rollTimeTo('22-Dec-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -332,16 +332,16 @@ it('roll-time-va-ends', function(){ it('end-event-summary', function() { log(""); - + log("Post Event Summary:"); log("==================="); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - dollarValue = value / 100; + + dollarValue = value / 100; log("[APL] => collected: " + value.toFixed(3) + " HKG" + " = $" + dollarValue); - assert.equal(50000, dollarValue); + assert.equal(50000, dollarValue); return true; }); @@ -349,7 +349,7 @@ it('end-event-summary', function() { it('roll-time-50%-available', function(){ - + return workbench.rollTimeTo('22-Feb-2017 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -359,59 +359,59 @@ it('roll-time-50%-available', function(){ it('submit-proposal-1', function() { log(""); log(" (!) Action: [0xcc49] ask to recieve 1,000,000.000 (20%) of the HKG collected"); - - return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", + + return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 450000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 450000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - - args = parsed.logs[0].args; - + + args = parsed.logs[0].args; + proposalId = args.id; proposalValue = args.value; proposalValue = proposalValue / 1000; - + proposalTimeEnds = args.timeEnds; proposalURL = args.url; proposalSender = args.sender; - + log(""); log("Proposal Submitted"); log("=================="); - + log("proposalId: " + proposalId); log("proposalValue: " + proposalValue.toFixed(3)); log("proposalTimeEnds: " + proposalTimeEnds); log("proposalURL: " + proposalURL); log("proposalSender: " + proposalSender); - - + + assert.equal(1000000, proposalValue); - + t1 = eventInfo.getNow().toNumber() + 60 * 60 * 24 * 10; t2 = proposalTimeEnds; - assert(t1, t2); + assert.equal(t1, t2); assert.equal(proposalURL, "http://pastebin.com/raw/6e9PBTeP"); assert.equal(proposalSender, "0xcc49bea5129ef2369ff81b0c0200885893979b77"); - + proposal_1 = proposalId; - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(0, value); - return true; + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(0, value); + + return true; }) }); @@ -419,7 +419,7 @@ it('submit-proposal-1', function() { it('roll-time-proposal-redeem', function(){ - + return workbench.rollTimeTo('04-Mar-2017 14:01 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -429,43 +429,43 @@ it('roll-time-proposal-redeem', function(){ it('redeem-proposal-1', function() { log(""); log(" (!) Action: [0xcc49] collect 1,000,000.000 HKG value of proposal 1"); - - return dstContract_APL.redeemProposalFunds(proposal_1, + + return dstContract_APL.redeemProposalFunds(proposal_1, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - - args = parsed.logs[0].args; - - assert(dstContract_APL.address, args.from); - assert("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); - assert(1000000000, args.value); - - return true; - }) - + + args = parsed.logs[0].args; + + assert.equal(dstContract_APL.address, args.from); + assert.equal("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); + assert.equal(1000000000, args.value); + + return true; + }) + .then(function () { - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); assert.equal(1000000, value); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); assert.equal(4000000, value); - return true; + return true; }) }); @@ -474,7 +474,7 @@ it('redeem-proposal-1', function() { it('roll-time-for-new-proposal-submit', function(){ - + return workbench.rollTimeTo('08-Mar-2017 14:02 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -484,67 +484,67 @@ it('roll-time-for-new-proposal-submit', function(){ it('submit-proposal-2', function() { log(""); log(" (!) Action: [0xcc49] ask to recieve 1,000,000.000 (20%) of the HKG collected"); - - return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", + + return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 450000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 450000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - - - args = parsed.logs[0].args; - + + + args = parsed.logs[0].args; + proposalId = args.id; proposalValue = args.value; proposalValue = proposalValue / 1000; - + proposalTimeEnds = args.timeEnds; proposalURL = args.url; proposalSender = args.sender; - + log(""); log("Proposal Submitted"); log("=================="); - + log("proposalId: " + proposalId); log("proposalValue: " + proposalValue.toFixed(3)); log("proposalTimeEnds: " + proposalTimeEnds); log("proposalURL: " + proposalURL); log("proposalSender: " + proposalSender); - - + + assert.equal(1000000, proposalValue); - + t1 = eventInfo.getNow().toNumber() + 60 * 60 * 24 * 10; t2 = proposalTimeEnds; - assert(t1, t2); + assert.equal(t1, t2); assert.equal(proposalURL, "http://pastebin.com/raw/6e9PBTeP"); assert.equal(proposalSender, "0xcc49bea5129ef2369ff81b0c0200885893979b77"); - + proposal_2 = proposalId; - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(1000000, value); - return true; + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(1000000, value); + + return true; }) }); it('roll-time-proposal-redeem', function(){ - + return workbench.rollTimeTo('18-Mar-2017 14:03 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -554,43 +554,43 @@ it('roll-time-proposal-redeem', function(){ it('redeem-proposal-2', function() { log(""); log(" (!) Action: [0xcc49] collect 1,000,000.000 HKG value of proposal 2"); - - return dstContract_APL.redeemProposalFunds(proposal_2, + + return dstContract_APL.redeemProposalFunds(proposal_2, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { /* - args = parsed.logs[0].args; - - assert(dstContract_APL.address, args.from); - assert("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); - assert(1000000000, args.value); + args = parsed.logs[0].args; + + assert.equal(dstContract_APL.address, args.from); + assert.equal("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); + assert.equal(1000000000, args.value); */ - return true; + return true; }) - + .then(function () { - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); assert.equal(2000000, value); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); assert.equal(3000000, value); - return true; + return true; }) }); @@ -599,7 +599,7 @@ it('redeem-proposal-2', function() { it('roll-time-for-new-proposal-submit', function(){ - + return workbench.rollTimeTo('22-Mar-2017 14:04 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -609,67 +609,67 @@ it('roll-time-for-new-proposal-submit', function(){ it('submit-proposal-3', function() { log(""); log(" (!) Action: [0xcc49] ask to recieve 1,000,000.000 (20%) of the HKG collected"); - - return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", + + return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 450000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 450000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - - args = parsed.logs[0].args; - + + args = parsed.logs[0].args; + proposalId = args.id; proposalValue = args.value; proposalValue = proposalValue / 1000; - + proposalTimeEnds = args.timeEnds; proposalURL = args.url; proposalSender = args.sender; - + log(""); log("Proposal Submitted"); log("=================="); - + log("proposalId: " + proposalId); log("proposalValue: " + proposalValue.toFixed(3)); log("proposalTimeEnds: " + proposalTimeEnds); log("proposalURL: " + proposalURL); log("proposalSender: " + proposalSender); - - + + assert.equal(1000000, proposalValue); - + t1 = eventInfo.getNow().toNumber() + 60 * 60 * 24 * 10; t2 = proposalTimeEnds; - assert(t1, t2); + assert.equal(t1, t2); assert.equal(proposalURL, "http://pastebin.com/raw/6e9PBTeP"); assert.equal(proposalSender, "0xcc49bea5129ef2369ff81b0c0200885893979b77"); - + proposal_3 = proposalId; - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(2000000, value); - - return true; + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(2000000, value); + + return true; }) }); it('roll-time-proposal-redeem', function(){ - + return workbench.rollTimeTo('01-Apr-2017 14:05 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -679,43 +679,43 @@ it('roll-time-proposal-redeem', function(){ it('redeem-proposal-3', function() { log(""); log(" (!) Action: [0xcc49] collect 1,000,000.000 HKG value of proposal 3"); - - return dstContract_APL.redeemProposalFunds(proposal_3, + + return dstContract_APL.redeemProposalFunds(proposal_3, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - - args = parsed.logs[0].args; - - assert(dstContract_APL.address, args.from); - assert("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); - assert(1000000000, args.value); - - return true; - }) - + + args = parsed.logs[0].args; + + assert.equal(dstContract_APL.address, args.from); + assert.equal("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); + assert.equal(1000000000, args.value); + + return true; + }) + .then(function () { - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); assert.equal(3000000, value); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); assert.equal(2000000, value); - return true; + return true; }) }); @@ -725,7 +725,7 @@ it('redeem-proposal-3', function() { it('roll-time-for-new-proposal-submit', function(){ - + return workbench.rollTimeTo('05-Apr-2017 14:06 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -735,66 +735,66 @@ it('roll-time-for-new-proposal-submit', function(){ it('submit-proposal-4', function() { log(""); log(" (!) Action: [0xcc49] ask to recieve 1,000,000.000 (20%) of the HKG collected"); - - return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", + + return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 450000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 450000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - args = parsed.logs[0].args; - + args = parsed.logs[0].args; + proposalId = args.id; proposalValue = args.value; proposalValue = proposalValue / 1000; - + proposalTimeEnds = args.timeEnds; proposalURL = args.url; proposalSender = args.sender; - + log(""); log("Proposal Submitted"); log("=================="); - + log("proposalId: " + proposalId); log("proposalValue: " + proposalValue.toFixed(3)); log("proposalTimeEnds: " + proposalTimeEnds); log("proposalURL: " + proposalURL); log("proposalSender: " + proposalSender); - - + + assert.equal(1000000, proposalValue); - + t1 = eventInfo.getNow().toNumber() + 60 * 60 * 24 * 10; t2 = proposalTimeEnds; - assert(t1, t2); + assert.equal(t1, t2); assert.equal(proposalURL, "http://pastebin.com/raw/6e9PBTeP"); assert.equal(proposalSender, "0xcc49bea5129ef2369ff81b0c0200885893979b77"); - + proposal_4 = proposalId; - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(3000000, value); - return true; + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(3000000, value); + + return true; }) }); it('roll-time-proposal-redeem', function(){ - + return workbench.rollTimeTo('15-Apr-2017 14:07 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -804,43 +804,43 @@ it('roll-time-proposal-redeem', function(){ it('redeem-proposal-4', function() { log(""); log(" (!) Action: [0xcc49] collect 1,000,000.000 HKG value of proposal 4"); - - return dstContract_APL.redeemProposalFunds(proposal_4, + + return dstContract_APL.redeemProposalFunds(proposal_4, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - - args = parsed.logs[0].args; - - assert(dstContract_APL.address, args.from); - assert("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); - assert(1000000000, args.value); - - return true; - }) - + + args = parsed.logs[0].args; + + assert.equal(dstContract_APL.address, args.from); + assert.equal("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); + assert.equal(1000000000, args.value); + + return true; + }) + .then(function () { - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); assert.equal(4000000, value); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); assert.equal(1000000, value); - return true; + return true; }) }); @@ -849,7 +849,7 @@ it('redeem-proposal-4', function() { it('roll-time-for-new-proposal-submit', function(){ - + return workbench.rollTimeTo('19-Apr-2017 14:08 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -859,66 +859,66 @@ it('roll-time-for-new-proposal-submit', function(){ it('submit-proposal-5', function() { log(""); log(" (!) Action: [0xcc49] ask to recieve 1,000,000.000 (20%) of the HKG collected"); - - return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", + + return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 450000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 450000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - args = parsed.logs[0].args; - + args = parsed.logs[0].args; + proposalId = args.id; proposalValue = args.value; proposalValue = proposalValue / 1000; - + proposalTimeEnds = args.timeEnds; proposalURL = args.url; proposalSender = args.sender; - + log(""); log("Proposal Submitted"); log("=================="); - + log("proposalId: " + proposalId); log("proposalValue: " + proposalValue.toFixed(3)); log("proposalTimeEnds: " + proposalTimeEnds); log("proposalURL: " + proposalURL); log("proposalSender: " + proposalSender); - - + + assert.equal(1000000, proposalValue); - + t1 = eventInfo.getNow().toNumber() + 60 * 60 * 24 * 10; t2 = proposalTimeEnds; - assert(t1, t2); + assert.equal(t1, t2); assert.equal(proposalURL, "http://pastebin.com/raw/6e9PBTeP"); assert.equal(proposalSender, "0xcc49bea5129ef2369ff81b0c0200885893979b77"); - + proposal_5 = proposalId; - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(4000000, value); - - return true; + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(4000000, value); + + return true; }) }); it('roll-time-proposal-redeem', function(){ - + return workbench.rollTimeTo('29-Apr-2017 14:09 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -928,43 +928,43 @@ it('roll-time-proposal-redeem', function(){ it('redeem-proposal-5', function() { log(""); log(" (!) Action: [0xcc49] collect 1,000,000.000 HKG value of proposal 5"); - - return dstContract_APL.redeemProposalFunds(proposal_5, + + return dstContract_APL.redeemProposalFunds(proposal_5, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - - args = parsed.logs[0].args; - - assert(dstContract_APL.address, args.from); - assert("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); - assert(1000000000, args.value); - - return true; - }) - + + args = parsed.logs[0].args; + + assert.equal(dstContract_APL.address, args.from); + assert.equal("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); + assert.equal(1000000000, args.value); + + return true; + }) + .then(function () { - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); assert.equal(5000000, value); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); assert.equal(0, value); - return true; + return true; }) }); @@ -973,9 +973,3 @@ it('redeem-proposal-5', function() { }); - - - - - - diff --git a/test/dst-management/requesting-funds-test-2.js b/test/dst-management/requesting-funds-test-2.js index 4812047..f4db1b1 100644 --- a/test/dst-management/requesting-funds-test-2.js +++ b/test/dst-management/requesting-funds-test-2.js @@ -8,8 +8,8 @@ var Workbench = require('ethereum-sandbox-workbench'); var workbench = new Workbench({ defaults: { from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826' - }, - + }, + solcVersion: '0.4.2' }); @@ -17,7 +17,7 @@ workbench.startTesting(['StandardToken', 'EventInfo', 'DSTContract', 'VirtualExc var sandbox = workbench.sandbox; -// deployed contracts +// deployed contracts var eventInfo; var hackerGold; var virtualExchange; @@ -34,22 +34,22 @@ var proposal_5; function printDate(){ now = eventInfo.getNow().toNumber(); var date = new Date(now*1000); - - log('\n Date now: ' + date + '\n'); + + log('\n Date now: ' + date + '\n'); } /** - * - * Testing for requesting HKG funds after the event : - * - * 1. - * 2. - * 3. + * + * Testing for requesting HKG funds after the event : + * + * 1. + * 2. + * 3. * * ... todo detailed description */ - + it('event-info-init', function() { log(''); @@ -57,51 +57,51 @@ it('event-info-init', function() { log(' requesting-funds-test-2.js '); log(' *****************************'); log(''); - + return contracts.EventInfo.new() .then(function(contract) { - + if (contract.address){ eventInfo = contract; } else { throw new Error('No contract address'); - } - - return true; + } + + return true; }) - + .then(function() { - - printDate(); + + printDate(); return true; }); - + }); - + it('hacker-gold-init', function() { return contracts.HackerGold.new() .then(function(contract) { - + if (contract.address){ hackerGold = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); - + it('roll-time-ve-trading-start', function(){ - - // Roll time to get best price on HKG, - // 1 Ether for 200 HKG + + // Roll time to get best price on HKG, + // 1 Ether for 200 HKG return workbench.rollTimeTo('30-Oct-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -109,35 +109,35 @@ it('roll-time-ve-trading-start', function(){ it('buy-hkg-for-3a7e', function() { log(""); - log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); + log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); return workbench.sendTransaction({ from: '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', to: hackerGold.address, value: sandbox.web3.toWei(500000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; value = Math.ceil(value); - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); assert.equal(100000000, value); - - return true; + + return true; }) - + }); it('roll-time-ve-trading-start', function(){ - + return workbench.rollTimeTo('24-Nov-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -147,39 +147,39 @@ it('roll-time-ve-trading-start', function(){ it('virtual-exchange-init', function() { - return contracts.VirtualExchange.new(hackerGold.address, + return contracts.VirtualExchange.new(hackerGold.address, eventInfo.address) .then(function(contract) { - + if (contract.address){ virtualExchange = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); it('dst-contract-apl-init', function() { - return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", - + return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", + { from : '0xcc49bea5129ef2369ff81b0c0200885893979b77' }) .then(function(contract) { - + if (contract.address){ dstContract_APL = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); @@ -188,27 +188,27 @@ it('enlist-apl', function() { log(""); log(" (!) Action: [VE] enlist [APL] for trading"); - return virtualExchange.enlist(dstContract_APL.address, + return virtualExchange.enlist(dstContract_APL.address, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) - + .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) - + .then(function() { - - exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); - + + exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); + log("[APL] => enlisted: " + exist); assert.equal(true, exist); - + return true; }) - + }); @@ -216,23 +216,23 @@ it('enlist-apl', function() { it('issue-apl-tokens-seria-1', function() { log(""); log(" (!) Action: [APL] issue tokens on [VE] balance 1,000,000,000,000.000 APL"); - - return dstContract_APL.issuePreferedTokens(1000, 1000000000000000, + + return dstContract_APL.issuePreferedTokens(1000, 1000000000000000, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) .then(function () { - + dst1Total = dstContract_APL.getTotalSupply().toNumber() / 1000; - - log("[APL] => total suply: " + dst1Total.toFixed(3) + " APL"); - assert(1000000000000000, dst1Total); - - veTokens = dstContract_APL.allowance(dstContract_APL.address, + + log("[APL] => total supply: " + dst1Total.toFixed(3) + " APL"); + assert.equal(1000000000000, dst1Total); + + veTokens = dstContract_APL.allowance(dstContract_APL.address, virtualExchange.address).toNumber() / 1000; log("[APL] => total on VirtualExchange: " + veTokens.toFixed(3) + " APL"); - assert(1000000000000000, veTokens); + assert.equal(1000000000000, veTokens); return true; }) @@ -243,25 +243,25 @@ it('issue-apl-tokens-seria-1', function() { it('approve-hkg-spend-on-exchange-for-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 100000000000, + + return hackerGold.approve(virtualExchange.address, 100000000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; - + log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(100000000, veTokens); - + return true; }) }); @@ -272,50 +272,50 @@ it('buy-apl-by-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] buy tokens [APL] for 50,000,000.000 HKG"); - - return virtualExchange.buy('APL', 5000000000, + + return virtualExchange.buy('APL', 5000000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { dst1Balance = dstContract_APL.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " APL"); assert.equal(5000000000 , dst1Balance); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(5000000000000 , voting); value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; value = Math.ceil(value); - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(95000000, value); - + assert.equal(95000000, value); + log ("[APL] => total: " + total + " votes"); assert.equal(5000000000000, total); - - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(95000000 , veTokens); + assert.equal(95000000 , veTokens); + + availableSupply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available supply: " + availableSupply + " APL"); + assert.equal(995000000000 , availableSupply); - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - assert.equal(995000000000 , availableSuply); - return true; }) }); @@ -323,7 +323,7 @@ it('buy-apl-by-3a7e', function() { it('roll-time-va-ends', function(){ - + return workbench.rollTimeTo('22-Dec-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -333,16 +333,16 @@ it('roll-time-va-ends', function(){ it('end-event-summary', function() { log(""); - + log("Post Event Summary:"); log("==================="); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - dollarValue = value / 100; + + dollarValue = value / 100; log("[APL] => collected: " + value.toFixed(3) + " HKG" + " = $" + dollarValue); - assert.equal(50000, dollarValue); + assert.equal(50000, dollarValue); return true; }); @@ -351,31 +351,31 @@ it('end-event-summary', function() { // ... // [X] Submit proposal before 2 months over from hackathon end -// ... +// ... it('submit-proposal-0', function() { log(""); log(" [X] Submit proposal before 2 months over from hackathon end."); - - return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", + + return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) - + .then(function (parsed) { - + counter = dstContract_APL.getCounterProposals(); - + log("Submitted Proposals: " + counter); assert.equal(0, counter); - - return true; + + return true; }) }); @@ -383,7 +383,7 @@ it('submit-proposal-0', function() { it('roll-time-50%-available', function(){ - + return workbench.rollTimeTo('22-Feb-2017 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -393,31 +393,31 @@ it('roll-time-50%-available', function(){ // ... // [X] Submit proposal for more than 20% -// ... +// ... it('submit-proposal-larger-than-20%', function() { log(""); log(" [X] Submit proposal for more than 20%."); - - return dstContract_APL.submitHKGProposal(2000000000, "http://pastebin.com/raw/6e9PBTeP", + + return dstContract_APL.submitHKGProposal(2000000000, "http://pastebin.com/raw/6e9PBTeP", { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) - + .then(function (parsed) { - + counter = dstContract_APL.getCounterProposals(); - + log("Submitted Proposals: " + counter); assert.equal(0, counter); - - return true; + + return true; }) }); @@ -427,31 +427,31 @@ it('submit-proposal-larger-than-20%', function() { // ... // [X] Submit proposal by non executive. -// ... +// ... it('submit-proposal-0', function() { log(""); log(" [X] Submit proposal by non executive."); - - return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", + + return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", { - from : '0xdb5918d9282f0b280aac6bde061b92e903e11d18', - gas : 350000, + from : '0xdb5918d9282f0b280aac6bde061b92e903e11d18', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) - + .then(function (parsed) { - + counter = dstContract_APL.getCounterProposals(); - + log("Submitted Proposals: " + counter); assert.equal(0, counter); - - return true; + + return true; }) }); @@ -462,66 +462,66 @@ it('submit-proposal-0', function() { it('submit-proposal-1', function() { log(""); log(" (!) Action: [0xcc49] ask to recieve 1,000,000.000 (20%) of the HKG collected"); - - return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", + + return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 450000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 450000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - - args = parsed.logs[0].args; - + + args = parsed.logs[0].args; + proposalId = args.id; proposalValue = args.value; proposalValue = proposalValue / 1000; - + proposalTimeEnds = args.timeEnds; proposalURL = args.url; proposalSender = args.sender; - + log(""); log("Proposal Submitted"); log("=================="); - + log("proposalId: " + proposalId); log("proposalValue: " + proposalValue.toFixed(3)); log("proposalTimeEnds: " + proposalTimeEnds); log("proposalURL: " + proposalURL); log("proposalSender: " + proposalSender); - - + + assert.equal(1000000, proposalValue); - + t1 = eventInfo.getNow().toNumber() + 60 * 60 * 24 * 10; t2 = proposalTimeEnds; - assert(t1, t2); + assert.equal(t1, t2); assert.equal(proposalURL, "http://pastebin.com/raw/6e9PBTeP"); assert.equal(proposalSender, "0xcc49bea5129ef2369ff81b0c0200885893979b77"); - + proposal_1 = proposalId; - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(0, value); - - return true; + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(0, value); + + return true; }) }); it('roll-time-not-enough-to-redeem', function(){ - + return workbench.rollTimeTo('03-Mar-2017 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -529,84 +529,84 @@ it('roll-time-not-enough-to-redeem', function(){ // ... // [X] Redeem before 10 days for rejection is over -// ... +// ... it('redeem-proposal-to-early', function() { log(""); log(" [X] Redeem before 10 days for rejection is over"); - - return dstContract_APL.redeemProposalFunds(proposal_1, + + return dstContract_APL.redeemProposalFunds(proposal_1, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - - + + .then(function () { - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); assert.equal(0, value); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); assert.equal(5000000, value); - return true; + return true; }) }); it('roll-time-proposal-redeem', function(){ - + return workbench.rollTimeTo('04-Mar-2017 14:01 UTC+00') .then(function(contract) { printDate(); return true; }); }); // ... -// [X] Redeem non exist proposal -// ... +// [X] Redeem non exist proposal +// ... it('redeem-non-exist-proposal', function() { log(""); log(" [X] Redeem non exist proposal "); - - return dstContract_APL.redeemProposalFunds('0x0000000000000000000000000000000000000000000000000000000000000001', + + return dstContract_APL.redeemProposalFunds('0x0000000000000000000000000000000000000000000000000000000000000001', { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function () { - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); assert.equal(0, value); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); assert.equal(5000000, value); - return true; + return true; }) }); @@ -615,38 +615,38 @@ it('redeem-non-exist-proposal', function() { // ... // [X] Redeem by non submitter -// ... +// ... it('redeem-by-non-submitter-proposal', function() { log(""); log(" [X] Redeem by non submitter "); - - return dstContract_APL.redeemProposalFunds(proposal_1, + + return dstContract_APL.redeemProposalFunds(proposal_1, { - from : '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', - gas : 350000, + from : '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function () { - + value = hackerGold.balanceOf('0xdedb49385ad5b94a16f236a6890cf9e0b1e30392').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); assert.equal(0, value); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); assert.equal(5000000, value); - return true; + return true; }) }); @@ -656,50 +656,50 @@ it('redeem-by-non-submitter-proposal', function() { it('redeem-proposal-1', function() { log(""); log(" (!) Action: [0xcc49] collect 1,000,000.000 HKG value of proposal 1"); - - return dstContract_APL.redeemProposalFunds(proposal_1, + + return dstContract_APL.redeemProposalFunds(proposal_1, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - - args = parsed.logs[0].args; - - assert(dstContract_APL.address, args.from); - assert("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); - assert(1000000000, args.value); - - return true; - }) - + + args = parsed.logs[0].args; + + assert.equal(dstContract_APL.address, args.from); + assert.equal("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); + assert.equal(1000000000, args.value); + + return true; + }) + .then(function () { - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); assert.equal(1000000, value); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); assert.equal(4000000, value); - return true; + return true; }) }); it('roll-time-one-day', function(){ - + return workbench.rollTimeTo('05-Mar-2017 14:01 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -708,39 +708,39 @@ it('roll-time-one-day', function(){ // ... // [X] Redeem the same proposal twice. -// ... +// ... it('redeem-proposal-twice', function() { log(""); log(" [X] Redeem the same proposal twice."); - - return dstContract_APL.redeemProposalFunds(proposal_1, + + return dstContract_APL.redeemProposalFunds(proposal_1, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - - + + .then(function () { - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); assert.equal(1000000, value); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); assert.equal(4000000, value); - return true; + return true; }) }); @@ -748,31 +748,31 @@ it('redeem-proposal-twice', function() { // ... // [X] Submit proposal before 2 weeks since last one. -// ... +// ... it('submit-proposal-off-time', function() { log(""); log(" [X] Submit proposal before 2 weeks since last one."); - - return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", + + return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) - + .then(function (parsed) { - + counter = dstContract_APL.getCounterProposals(); - + log("Submitted Proposals: " + counter); assert.equal(1, counter); - - return true; + + return true; }) }); @@ -782,9 +782,3 @@ it('submit-proposal-off-time', function() { }); - - - - - - diff --git a/test/dst-management/requesting-funds-test-3.js b/test/dst-management/requesting-funds-test-3.js index 5b64aaf..e1689e3 100644 --- a/test/dst-management/requesting-funds-test-3.js +++ b/test/dst-management/requesting-funds-test-3.js @@ -7,8 +7,8 @@ var Workbench = require('ethereum-sandbox-workbench'); var workbench = new Workbench({ defaults: { from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826' - }, - + }, + solcVersion: '0.4.2' }); @@ -16,7 +16,7 @@ workbench.startTesting(['StandardToken', 'EventInfo', 'DSTContract', 'VirtualExc var sandbox = workbench.sandbox; -// deployed contracts +// deployed contracts var eventInfo; var hackerGold; var virtualExchange; @@ -33,73 +33,73 @@ var proposal_5; function printDate(){ now = eventInfo.getNow().toNumber(); var date = new Date(now*1000); - - log('\n Date now: ' + date + '\n'); + + log('\n Date now: ' + date + '\n'); } /** - * - * Testing for requesting HKG funds after the event : - * + * + * Testing for requesting HKG funds after the event : + * * 1. After the event [0xcc49] submit proposal to get funds * 2. Proposal is rejected by [0x3a7e] - * 3. No option to redeem funds. + * 3. No option to redeem funds. * */ - + it('event-info-init', function() { - + log(''); log(' *****************************'); log(' requesting-funds-test-3.js '); log(' *****************************'); - log(''); - + log(''); + return contracts.EventInfo.new() .then(function(contract) { - + if (contract.address){ eventInfo = contract; } else { throw new Error('No contract address'); - } - - return true; + } + + return true; }) - + .then(function() { - - printDate(); + + printDate(); return true; }); - + }); - + it('hacker-gold-init', function() { return contracts.HackerGold.new() .then(function(contract) { - + if (contract.address){ hackerGold = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); - + it('roll-time-ve-trading-start', function(){ - - // Roll time to get best price on HKG, - // 1 Ether for 200 HKG + + // Roll time to get best price on HKG, + // 1 Ether for 200 HKG return workbench.rollTimeTo('30-Oct-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -107,35 +107,35 @@ it('roll-time-ve-trading-start', function(){ it('buy-hkg-for-3a7e', function() { log(""); - log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); + log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); return workbench.sendTransaction({ from: '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', to: hackerGold.address, value: sandbox.web3.toWei(500000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; value = Math.ceil(value); - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); assert.equal(100000000, value); - - return true; + + return true; }) - + }); it('roll-time-ve-trading-start', function(){ - + return workbench.rollTimeTo('24-Nov-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -145,39 +145,39 @@ it('roll-time-ve-trading-start', function(){ it('virtual-exchange-init', function() { - return contracts.VirtualExchange.new(hackerGold.address, + return contracts.VirtualExchange.new(hackerGold.address, eventInfo.address) .then(function(contract) { - + if (contract.address){ virtualExchange = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); it('dst-contract-apl-init', function() { - return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", - + return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", + { from : '0xcc49bea5129ef2369ff81b0c0200885893979b77' }) .then(function(contract) { - + if (contract.address){ dstContract_APL = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); @@ -186,27 +186,27 @@ it('enlist-apl', function() { log(""); log(" (!) Action: [VE] enlist [APL] for trading"); - return virtualExchange.enlist(dstContract_APL.address, + return virtualExchange.enlist(dstContract_APL.address, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) - + .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) - + .then(function() { - - exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); - + + exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); + log("[APL] => enlisted: " + exist); assert.equal(true, exist); - + return true; }) - + }); @@ -214,23 +214,23 @@ it('enlist-apl', function() { it('issue-apl-tokens-seria-1', function() { log(""); log(" (!) Action: [APL] issue tokens on [VE] balance 1,000,000,000,000.000 APL"); - - return dstContract_APL.issuePreferedTokens(1000, 1000000000000000, + + return dstContract_APL.issuePreferedTokens(1000, 1000000000000000, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) .then(function () { - + dst1Total = dstContract_APL.getTotalSupply().toNumber() / 1000; - - log("[APL] => total suply: " + dst1Total.toFixed(3) + " APL"); - assert(1000000000000000, dst1Total); - - veTokens = dstContract_APL.allowance(dstContract_APL.address, + + log("[APL] => total supply: " + dst1Total.toFixed(3) + " APL"); + assert.equal(1000000000000, dst1Total); + + veTokens = dstContract_APL.allowance(dstContract_APL.address, virtualExchange.address).toNumber() / 1000; log("[APL] => total on VirtualExchange: " + veTokens.toFixed(3) + " APL"); - assert(1000000000000000, veTokens); + assert.equal(1000000000000, veTokens); return true; }) @@ -241,25 +241,25 @@ it('issue-apl-tokens-seria-1', function() { it('approve-hkg-spend-on-exchange-for-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 100000000000, + + return hackerGold.approve(virtualExchange.address, 100000000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; - + log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(100000000, veTokens); - + return true; }) }); @@ -270,50 +270,50 @@ it('buy-apl-by-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] buy tokens [APL] for 50,000,000.000 HKG"); - - return virtualExchange.buy('APL', 5000000000, + + return virtualExchange.buy('APL', 5000000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { dst1Balance = dstContract_APL.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " APL"); assert.equal(5000000000 , dst1Balance); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(5000000000000 , voting); value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; value = Math.ceil(value); - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(95000000, value); - + assert.equal(95000000, value); + log ("[APL] => total: " + total + " votes"); assert.equal(5000000000000, total); - - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); - assert.equal(95000000 , veTokens); + assert.equal(95000000 , veTokens); + + availableSupply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available supply: " + availableSupply + " APL"); + assert.equal(995000000000 , availableSupply); - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - assert.equal(995000000000 , availableSuply); - return true; }) }); @@ -321,7 +321,7 @@ it('buy-apl-by-3a7e', function() { it('roll-time-va-ends', function(){ - + return workbench.rollTimeTo('22-Dec-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -331,16 +331,16 @@ it('roll-time-va-ends', function(){ it('end-event-summary', function() { log(""); - + log("Post Event Summary:"); log("==================="); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - dollarValue = value / 100; + + dollarValue = value / 100; log("[APL] => collected: " + value.toFixed(3) + " HKG" + " = $" + dollarValue); - assert.equal(50000, dollarValue); + assert.equal(50000, dollarValue); return true; }); @@ -348,7 +348,7 @@ it('end-event-summary', function() { it('roll-time-50%-available', function(){ - + return workbench.rollTimeTo('22-Feb-2017 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -358,59 +358,59 @@ it('roll-time-50%-available', function(){ it('submit-proposal-1', function() { log(""); log(" (!) Action: [0xcc49] ask to recieve 1,000,000.000 (20%) of the HKG collected"); - - return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", + + return dstContract_APL.submitHKGProposal(1000000000, "http://pastebin.com/raw/6e9PBTeP", { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 450000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 450000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - - args = parsed.logs[0].args; - + + args = parsed.logs[0].args; + proposalId = args.id; proposalValue = args.value; proposalValue = proposalValue / 1000; - + proposalTimeEnds = args.timeEnds; proposalURL = args.url; proposalSender = args.sender; - + log(""); log("Proposal Submitted"); log("=================="); - + log("proposalId: " + proposalId); log("proposalValue: " + proposalValue.toFixed(3)); log("proposalTimeEnds: " + proposalTimeEnds); log("proposalURL: " + proposalURL); log("proposalSender: " + proposalSender); - - + + assert.equal(1000000, proposalValue); - + t1 = eventInfo.getNow().toNumber() + 60 * 60 * 24 * 10; t2 = proposalTimeEnds; - assert(t1, t2); + assert.equal(t1, t2); assert.equal(proposalURL, "http://pastebin.com/raw/6e9PBTeP"); assert.equal(proposalSender, "0xcc49bea5129ef2369ff81b0c0200885893979b77"); - + proposal_1 = proposalId; - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(0, value); - - return true; + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(0, value); + + return true; }) }); @@ -418,43 +418,43 @@ it('submit-proposal-1', function() { it('object-by-vote-proposal-1', function() { - log(""); + log(""); log(" (!) Action: [0x3a7e] vote to object proposal 1"); - - return dstContract_APL.objectProposal(proposal_1, + + return dstContract_APL.objectProposal(proposal_1, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - gas : 450000, + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + gas : 450000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - + log_1 = parsed.logs[0]; log(log_1.args); - + total = dstContract_APL.getPreferedQtySold(); - + log("\n"); log(log_1.event + ":"); log("============"); - + log("proposal.id: " + log_1.args.id); log("voter: " + log_1.args.voter); log("votes: " + log_1.args.votes + " share: " + (log_1.args.votes / total * 100).toFixed(2) + "%"); - + voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber(); - + assert.equal(proposal_1, log_1.args.id); assert.equal(log_1.args.voter, "0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d"); assert.equal(log_1.args.votes, voting); - - return true; + + return true; }) }); @@ -462,7 +462,7 @@ it('object-by-vote-proposal-1', function() { it('roll-time-proposal-redeem', function(){ - + return workbench.rollTimeTo('04-Mar-2017 14:01 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -471,39 +471,39 @@ it('roll-time-proposal-redeem', function(){ it('redeem-proposal-1', function() { log(""); log(" (!) Action: [0xcc49] collect 1,000,000.000 HKG value of proposal 1"); - - return dstContract_APL.redeemProposalFunds(proposal_1, + + return dstContract_APL.redeemProposalFunds(proposal_1, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - - assert.equal(0, parsed.logs.length); - return true; + + assert.equal(0, parsed.logs.length); + return true; }) - + .then(function () { - - // ensure that the proposal is rejected and cannot be reddemed + + // ensure that the proposal is rejected and cannot be reddemed value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); assert.equal(0, value); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); assert.equal(5000000, value); - return true; + return true; }) }); @@ -511,9 +511,3 @@ it('redeem-proposal-1', function() { }); - - - - - - diff --git a/test/dst-management/requesting-funds-test-4.js b/test/dst-management/requesting-funds-test-4.js index cade08b..081e623 100644 --- a/test/dst-management/requesting-funds-test-4.js +++ b/test/dst-management/requesting-funds-test-4.js @@ -6,8 +6,8 @@ var Workbench = require('ethereum-sandbox-workbench'); var workbench = new Workbench({ defaults: { from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826' - }, - + }, + solcVersion: '0.4.2' }); @@ -15,7 +15,7 @@ workbench.startTesting(['StandardToken', 'EventInfo', 'DSTContract', 'VirtualExc var sandbox = workbench.sandbox; -// deployed contracts +// deployed contracts var eventInfo; var hackerGold; var virtualExchange; @@ -25,74 +25,74 @@ var dstContract_APL; // Awesome Poker League function printDate(){ now = eventInfo.getNow().toNumber(); var date = new Date(now*1000); - - log('\n Date now: ' + date + '\n'); + + log('\n Date now: ' + date + '\n'); } /** - * - * Testing for issue project token series: - * - * 1. Create structure of DST 30% / 30% / 40% - owners - * 2. Object 1st proposal by 30% => the proposal is go through + * + * Testing for issue project token series: + * + * 1. Create structure of DST 30% / 30% / 40% - owners + * 2. Object 1st proposal by 30% => the proposal is go through * 3. Object 2st proposal by 70% => the proposal is rejected - * 4. Roll 6 months and collect all the funds. + * 4. Roll 6 months and collect all the funds. * */ - + it('event-info-init', function() { - + log(''); log(' *****************************'); log(' requesting-funds-test-4.js '); log(' *****************************'); log(''); - + return contracts.EventInfo.new() .then(function(contract) { - + if (contract.address){ eventInfo = contract; } else { throw new Error('No contract address'); - } - - return true; + } + + return true; }) - + .then(function() { - - printDate(); + + printDate(); return true; }); - + }); - + it('hacker-gold-init', function() { return contracts.HackerGold.new() .then(function(contract) { - + if (contract.address){ hackerGold = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); - + it('roll-time-ve-trading-start', function(){ - - // Roll time to get best price on HKG, - // 1 Ether for 200 HKG + + // Roll time to get best price on HKG, + // 1 Ether for 200 HKG return workbench.rollTimeTo('30-Oct-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -100,119 +100,119 @@ it('roll-time-ve-trading-start', function(){ it('buy-hkg-for-3a7e', function() { log(""); - log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); + log(" (!) Action: [0x3a7e] buy [HKG] for 10000 Ether"); return workbench.sendTransaction({ from: '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', to: hackerGold.address, value: sandbox.web3.toWei(10000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); assert.equal(2000000, value); - - return true; + + return true; }) - + }); it('buy-hkg-for-2980', function() { log(""); - log(" (!) Action: [0x2980] buy [HKG] for 10,000.000 Ether"); + log(" (!) Action: [0x2980] buy [HKG] for 10,000.000 Ether"); return workbench.sendTransaction({ from: '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', to: hackerGold.address, value: sandbox.web3.toWei(10000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; - + log("[0x2980] => balance: " + value.toFixed(3) + " HKG"); assert.equal(2000000, value); - - return true; + + return true; }) - + }); it('buy-hkg-for-696b', function() { log(""); - log(" (!) Action: [0x696b] buy [HKG] for 5000.000 Ether"); + log(" (!) Action: [0x696b] buy [HKG] for 5000.000 Ether"); return workbench.sendTransaction({ from: '0x696ba93ef4254da47ff05b6caa88190db335f1c3', to: hackerGold.address, value: sandbox.web3.toWei(10000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; - + log("[0x696b] => balance: " + value.toFixed(3) + " HKG"); assert.equal(2000000, value); - - return true; + + return true; }) - + }); it('buy-hkg-for-cd2a', function() { log(""); - log(" (!) Action: [0xcd2a] buy [HKG] for 5000.000 Ether"); + log(" (!) Action: [0xcd2a] buy [HKG] for 5000.000 Ether"); return workbench.sendTransaction({ from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', to: hackerGold.address, value: sandbox.web3.toWei(10000, 'ether') }) - + .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) .then(function (txHash) { value = hackerGold.balanceOf('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826').toNumber() / 1000; - + log("[0xcd2a] => balance: " + value.toFixed(3) + " HKG"); assert.equal(2000000, value); - - return true; + + return true; }) - + }); it('roll-time-ve-trading-start', function(){ - + return workbench.rollTimeTo('24-Nov-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -222,39 +222,39 @@ it('roll-time-ve-trading-start', function(){ it('virtual-exchange-init', function() { - return contracts.VirtualExchange.new(hackerGold.address, + return contracts.VirtualExchange.new(hackerGold.address, eventInfo.address) .then(function(contract) { - + if (contract.address){ virtualExchange = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); it('dst-contract-apl-init', function() { - return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", - + return contracts.DSTContract.new(eventInfo.address, hackerGold.address, "Awesome Poker League", "APL", + { from : '0xcc49bea5129ef2369ff81b0c0200885893979b77' }) .then(function(contract) { - + if (contract.address){ dstContract_APL = contract; } else { throw new Error('No contract address'); - } - - return true; - }); + } + + return true; + }); }); @@ -263,50 +263,50 @@ it('enlist-apl', function() { log(""); log(" (!) Action: [VE] enlist [APL] for trading"); - return virtualExchange.enlist(dstContract_APL.address, + return virtualExchange.enlist(dstContract_APL.address, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) - + .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) - + .then(function() { - - exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); - + + exist = virtualExchange.isExistByString(dstContract_APL.getDSTSymbol()); + log("[APL] => enlisted: " + exist); assert.equal(true, exist); - + return true; }) - + }); it('issue-apl-tokens-seria-1', function() { log(""); log(" (!) Action: [APL] issue tokens on [VE] balance 1,000,000,000,000.000 APL"); - - return dstContract_APL.issuePreferedTokens(1000, 1000000000000, + + return dstContract_APL.issuePreferedTokens(1000, 1000000000000, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) .then(function () { - + dst1Total = dstContract_APL.getTotalSupply().toNumber() / 1000; - - log("[APL] => total suply: " + dst1Total.toFixed(3) + " APL"); - assert(1000000000000, dst1Total); - - veTokens = dstContract_APL.allowance(dstContract_APL.address, + + log("[APL] => total supply: " + dst1Total.toFixed(3) + " APL"); + assert.equal(1000000000, dst1Total); + + veTokens = dstContract_APL.allowance(dstContract_APL.address, virtualExchange.address).toNumber() / 1000; log("[APL] => total on VirtualExchange: " + veTokens.toFixed(3) + " APL"); - assert(1000000000000, veTokens); + assert.equal(1000000000, veTokens); return true; }) @@ -317,25 +317,25 @@ it('issue-apl-tokens-seria-1', function() { it('approve-hkg-spend-on-exchange-for-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 2000000000, + + return hackerGold.approve(virtualExchange.address, 2000000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; - + log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(2000000, veTokens); - + return true; }) }); @@ -344,25 +344,25 @@ it('approve-hkg-spend-on-exchange-for-3a7e', function() { it('approve-hkg-spend-on-exchange-for-2980', function() { log(""); log(" (!) Action: [0x2980] move to [VE] balance 2,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 2000000000, + + return hackerGold.approve(virtualExchange.address, 2000000000, { - from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', virtualExchange.address).toNumber() / 1000; - + log("[0x2980] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(2000000, veTokens); - + return true; }) }); @@ -371,25 +371,25 @@ it('approve-hkg-spend-on-exchange-for-2980', function() { it('approve-hkg-spend-on-exchange-for-696b', function() { log(""); log(" (!) Action: [0x696b] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 2000000000, + + return hackerGold.approve(virtualExchange.address, 2000000000, { - from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', + from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', + veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', virtualExchange.address).toNumber() / 1000; - + log("[0x696b] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(2000000, veTokens); - + return true; }) }); @@ -399,25 +399,25 @@ it('approve-hkg-spend-on-exchange-for-696b', function() { it('approve-hkg-spend-on-exchange-for-cd2a', function() { log(""); log(" (!) Action: [0xcd2a] move to [VE] balance 1,000,000.000 HKG"); - - return hackerGold.approve(virtualExchange.address, 2000000000, + + return hackerGold.approve(virtualExchange.address, 2000000000, { - from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { - veTokens = hackerGold.allowance('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', + veTokens = hackerGold.allowance('0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', virtualExchange.address).toNumber() / 1000; - + log("[0xcd2a] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(2000000, veTokens); - + return true; }) }); @@ -427,49 +427,49 @@ it('buy-apl-by-3a7e', function() { log(""); log(" (!) Action: [0x3a7e] buy tokens [APL] for 300,000.000 HKG"); - - return virtualExchange.buy('APL', 300000000, + + return virtualExchange.buy('APL', 300000000, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { dst1Balance = dstContract_APL.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + dst1Balance.toFixed(3) + " APL"); assert.equal(300000000 , dst1Balance); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(300000000000 , voting); value = hackerGold.balanceOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber() / 1000; - + log("[0x3a7e] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(1700000, value); - + assert.equal(1700000, value); + log ("[APL] => total: " + total + " votes"); assert.equal(300000000000, total); - - veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + + veTokens = hackerGold.allowance('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', virtualExchange.address).toNumber() / 1000; log("[0x3a7e] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(1700000 , veTokens); - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - assert.equal(700000000 , availableSuply); - + availableSupply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available supply: " + availableSupply + " APL"); + assert.equal(700000000 , availableSupply); + return true; }) }); @@ -481,68 +481,68 @@ it('buy-apl-by-2980', function() { log(""); log(" (!) Action: [0x2980] buy tokens [APL] for 300,000.000 HKG"); - - return virtualExchange.buy('APL', 300000000, + + return virtualExchange.buy('APL', 300000000, { - from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + from : '0x29805ff5b946e7a7c5871c1fb071f740f767cf41', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); + return workbench.waitForReceipt(txHash); + + }) - }) - .then(function () { dst1Balance = dstContract_APL.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; - + log("[0x2980] => balance: " + dst1Balance.toFixed(3) + " APL"); assert.equal(300000000 , dst1Balance); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); - + log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(300000000000 , voting); value = hackerGold.balanceOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41').toNumber() / 1000; - + log("[0x2980] => balance: " + value.toFixed(3) + " HKG"); assert.equal(1700000, value); - + log ("[APL] => total: " + total + " votes"); - - veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', + + veTokens = hackerGold.allowance('0x29805ff5b946e7a7c5871c1fb071f740f767cf41', virtualExchange.address).toNumber() / 1000; log("[0x2980] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(1700000 , veTokens); - - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - + + availableSupply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available supply: " + availableSupply + " APL"); + log(""); log(" Voting Summary: "); log(" =============== "); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(50, voting / total * 100); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); - + log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(50, voting / total * 100); + assert.equal(50, voting / total * 100); value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; log("[APL] => collected: " + value.toFixed(3) + " HKG"); - assert.equal(600000, value); - + assert.equal(600000, value); + return true; }) }); @@ -554,73 +554,73 @@ it('buy-apl-by-696b', function() { log(""); log(" (!) Action: [0x696b] buy tokens [APL] for 400,000.000 HKG"); - - return virtualExchange.buy('APL', 400000000, + + return virtualExchange.buy('APL', 400000000, { - from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', + from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', gas: 250000, }) .then(function (txHash) { - return workbench.waitForReceipt(txHash); - }) - + return workbench.waitForReceipt(txHash); + }) + .then(function () { dst1Balance = dstContract_APL.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; - + log("[0x696b] => balance: " + dst1Balance.toFixed(3) + " APL"); assert.equal(400000000 , dst1Balance); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3'); - + log ("[0x696b] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(400000000000 , voting); value = hackerGold.balanceOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber() / 1000; - + log("[0x696b] => balance: " + value.toFixed(3) + " HKG"); assert.equal(1600000, value); - + log ("[APL] => total: " + total + " votes"); - - veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', + + veTokens = hackerGold.allowance('0x696ba93ef4254da47ff05b6caa88190db335f1c3', virtualExchange.address).toNumber() / 1000; log("[0x696b] => VirtualExchange balance: " + veTokens.toFixed(3) + " HKG"); assert.equal(1600000 , veTokens); - - availableSuply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; - log("[APL] => available suply: " + availableSuply + " APL"); - + + availableSupply = dstContract_APL.balanceOf(dstContract_APL.address).toNumber() / 1000; + log("[APL] => available supply: " + availableSupply + " APL"); + log(""); log(" Voting Summary: "); log(" =============== "); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d'); - + log ("[0x3a7e] => voting: " + voting + " votes - " + voting / total * 100 + "%"); assert.equal(30, voting / total * 100); - + total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x29805ff5b946e7a7c5871c1fb071f740f767cf41'); - + log ("[0x2980] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(30, voting / total * 100); + assert.equal(30, voting / total * 100); total = dstContract_APL.getPreferedQtySold(); voting = dstContract_APL.votingRightsOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3'); - + log ("[0x696b] => voting: " + voting + " votes - " + voting / total * 100 + "%"); - assert.equal(40, voting / total * 100); + assert.equal(40, voting / total * 100); value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; log("[APL] => collected: " + value.toFixed(3) + " HKG"); - assert.equal(1000000, value); - + assert.equal(1000000, value); + return true; }) }); @@ -628,74 +628,74 @@ it('buy-apl-by-696b', function() { it('roll-time-va-ends', function(){ - + return workbench.rollTimeTo('22-Dec-2016 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); it('roll-time-50%-available', function(){ - + return workbench.rollTimeTo('22-Feb-2017 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); it('submit-proposal-1', function() { - log(""); + log(""); log(" (!) Action: [0xcc49] ask to recieve 200,000.000 (20%) of the HKG collected"); - - return dstContract_APL.submitHKGProposal(200000000, "http://pastebin.com/raw/6e9PBTeP", + + return dstContract_APL.submitHKGProposal(200000000, "http://pastebin.com/raw/6e9PBTeP", { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 450000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 450000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - - args = parsed.logs[0].args; - + + args = parsed.logs[0].args; + proposalId = args.id; proposalValue = args.value; proposalValue = proposalValue / 1000; - + proposalTimeEnds = args.timeEnds; proposalURL = args.url; proposalSender = args.sender; - + log(""); log("Proposal Submitted"); log("=================="); - + log("proposalId: " + proposalId); log("proposalValue: " + proposalValue.toFixed(3)); log("proposalTimeEnds: " + proposalTimeEnds); log("proposalURL: " + proposalURL); log("proposalSender: " + proposalSender); - - + + assert.equal(200000, proposalValue); - + t1 = eventInfo.getNow().toNumber() + 60 * 60 * 24 * 10; t2 = proposalTimeEnds; - assert(t1, t2); + assert.equal(t1, t2); assert.equal(proposalURL, "http://pastebin.com/raw/6e9PBTeP"); assert.equal(proposalSender, "0xcc49bea5129ef2369ff81b0c0200885893979b77"); - + proposal_1 = proposalId; - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(0, value); - - return true; + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(0, value); + + return true; }) }); @@ -703,49 +703,49 @@ it('submit-proposal-1', function() { it('object-by-vote-proposal-1', function() { - log(""); + log(""); log(" (!) Action: [0x3a7e] vote to object proposal 1"); - - return dstContract_APL.objectProposal(proposal_1, + + return dstContract_APL.objectProposal(proposal_1, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - gas : 450000, + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + gas : 450000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - + log_1 = parsed.logs[0]; - + total = dstContract_APL.getPreferedQtySold(); - + log("\n"); log(log_1.event + ":"); log("============"); - + log("proposal.id: " + log_1.args.id); log("voter: " + log_1.args.voter); log("votes: " + log_1.args.votes + " share: " + (log_1.args.votes / total * 100).toFixed(2) + "%"); - + voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber(); - + assert.equal(proposal_1, log_1.args.id); assert.equal(log_1.args.voter, "0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d"); assert.equal(log_1.args.votes, voting); - - return true; + + return true; }) }); it('roll-time-proposal-redeem', function(){ - + return workbench.rollTimeTo('04-Mar-2017 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -754,45 +754,45 @@ it('roll-time-proposal-redeem', function(){ it('redeem-proposal-1', function() { log(""); log(" (!) Action: [0xcc49] collect 1,000.000 HKG value of proposal 1"); - - return dstContract_APL.redeemProposalFunds(proposal_1, + + return dstContract_APL.redeemProposalFunds(proposal_1, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, - }) + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, + }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - + assert.equal(1, parsed.logs.length); - args = parsed.logs[0].args; - - assert(dstContract_APL.address, args.from); - assert("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); - assert(200000000, args.value); - - return true; + args = parsed.logs[0].args; + + assert.equal(dstContract_APL.address, args.from); + assert.equal("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); + assert.equal(200000000, args.value); + + return true; }) - + .then(function () { - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); assert.equal(200000, value); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); assert.equal(800000, value); - return true; + return true; }) }); @@ -800,7 +800,7 @@ it('redeem-proposal-1', function() { it('roll-time-for-new-proposal-submit', function(){ - + return workbench.rollTimeTo('08-Mar-2017 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -810,149 +810,149 @@ it('roll-time-for-new-proposal-submit', function(){ it('submit-proposal-2', function() { log(""); log(" (!) Action: [0xcc49] ask to recieve 200,000.000 (20%) of the HKG collected"); - - return dstContract_APL.submitHKGProposal(200000000, "http://pastebin.com/raw/6e9PBTeP", + + return dstContract_APL.submitHKGProposal(200000000, "http://pastebin.com/raw/6e9PBTeP", { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 450000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 450000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - - - args = parsed.logs[0].args; - + + + args = parsed.logs[0].args; + proposalId = args.id; proposalValue = args.value; proposalValue = proposalValue / 1000; - + proposalTimeEnds = args.timeEnds; proposalURL = args.url; proposalSender = args.sender; - + log(""); log("Proposal Submitted"); log("=================="); - + log("proposalId: " + proposalId); log("proposalValue: " + proposalValue.toFixed(3)); log("proposalTimeEnds: " + proposalTimeEnds); log("proposalURL: " + proposalURL); log("proposalSender: " + proposalSender); - - + + assert.equal(200000, proposalValue); - + t1 = eventInfo.getNow().toNumber() + 60 * 60 * 24 * 10; t2 = proposalTimeEnds; - assert(t1, t2); + assert.equal(t1, t2); assert.equal(proposalURL, "http://pastebin.com/raw/6e9PBTeP"); assert.equal(proposalSender, "0xcc49bea5129ef2369ff81b0c0200885893979b77"); - + proposal_2 = proposalId; - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); - assert.equal(200000, value); - return true; + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + assert.equal(200000, value); + + return true; }) }); it('object-by-vote-proposal-2-voter-3a7e', function() { - log(""); + log(""); log(" (!) Action: [0x3a7e] vote to object proposal 1"); - - return dstContract_APL.objectProposal(proposal_2, + + return dstContract_APL.objectProposal(proposal_2, { - from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', - gas : 450000, + from : '0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d', + gas : 450000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - + log_1 = parsed.logs[0]; - + total = dstContract_APL.getPreferedQtySold(); - + log("\n"); log(log_1.event + ":"); log("============"); - + log("proposal.id: " + log_1.args.id); log("voter: " + log_1.args.voter); log("votes: " + log_1.args.votes + " share: " + (log_1.args.votes / total * 100).toFixed(2) + "%"); - + voting = dstContract_APL.votingRightsOf('0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d').toNumber(); - + assert.equal(proposal_2, log_1.args.id); assert.equal(log_1.args.voter, "0x3a7e663c871351bbe7b6dd006cb4a46d75cce61d"); assert.equal(log_1.args.votes, voting); - - return true; + + return true; }) }); it('object-by-vote-proposal-2-voter-696b', function() { - log(""); + log(""); log(" (!) Action: [0x696b] vote to object proposal 1"); - - return dstContract_APL.objectProposal(proposal_2, + + return dstContract_APL.objectProposal(proposal_2, { - from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', - gas : 450000, + from : '0x696ba93ef4254da47ff05b6caa88190db335f1c3', + gas : 450000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - + log_1 = parsed.logs[0]; - + total = dstContract_APL.getPreferedQtySold(); - + log("\n"); log(log_1.event + ":"); log("============"); - + log("proposal.id: " + log_1.args.id); log("voter: " + log_1.args.voter); log("votes: " + log_1.args.votes + " share: " + (log_1.args.votes / total * 100).toFixed(2) + "%"); - + voting = dstContract_APL.votingRightsOf('0x696ba93ef4254da47ff05b6caa88190db335f1c3').toNumber(); - + assert.equal(proposal_2, log_1.args.id); assert.equal(log_1.args.voter, "0x696ba93ef4254da47ff05b6caa88190db335f1c3"); assert.equal(log_1.args.votes, voting); - + totalObjected = dstContract_APL.getProposalObjectionByIndex(1); - + log(""); - log("Proposal objected: " + totalObjected / total * 100 + "%"); - - return true; + log("Proposal objected: " + totalObjected / total * 100 + "%"); + + return true; }) }); @@ -960,7 +960,7 @@ it('object-by-vote-proposal-2-voter-696b', function() { it('roll-time-proposal-redeem', function(){ - + return workbench.rollTimeTo('18-Mar-2017 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -970,38 +970,38 @@ it('roll-time-proposal-redeem', function(){ it('redeem-proposal-2', function() { log(""); log(" (!) Action: [0xcc49] collect 200,000.000 HKG value of proposal 2"); - - return dstContract_APL.redeemProposalFunds(proposal_2, + + return dstContract_APL.redeemProposalFunds(proposal_2, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); - + + return workbench.waitForReceipt(txHash); + }) - + .then(function (parsed) { - - assert.equal(0, parsed.logs.length); - return true; + + assert.equal(0, parsed.logs.length); + return true; }) - + .then(function () { - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); assert.equal(200000, value); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); assert.equal(800000, value); - return true; + return true; }) }); @@ -1014,45 +1014,45 @@ it('redeem-proposal-2', function() { it('collect-all-the-rest-funds-before-time', function() { log(""); log(" [X] Action: [0xcc49] collect all the rest of HKG before 6 months over"); - - return dstContract_APL.getAllTheFunds( + + return dstContract_APL.getAllTheFunds( { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) - + .then(function (parsed) { - + assert.equal(0, parsed.logs.length); - return true; + return true; }) - + .then(function () { - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); assert.equal(200000, value); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); assert.equal(800000, value); - return true; + return true; }) }); it('roll-time-for-total-redeem', function(){ - + return workbench.rollTimeTo('22-June-2017 14:00 UTC+00') .then(function(contract) { printDate(); return true; }); }); @@ -1066,38 +1066,38 @@ it('roll-time-for-total-redeem', function(){ it('collect-all-the-rest-funds-before-time', function() { log(""); log(" [X] Action: [0xdedb] collect all the rest of HKG by non executive"); - - return dstContract_APL.getAllTheFunds( + + return dstContract_APL.getAllTheFunds( { - from : '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', - gas : 350000, + from : '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) - + .then(function (parsed) { - + assert.equal(0, parsed.logs.length); - return true; + return true; }) - + .then(function () { - + value = hackerGold.balanceOf('0xdedb49385ad5b94a16f236a6890cf9e0b1e30392').toNumber() / 1000; - - log("[0xdedb] => balance: " + value.toFixed(3) + " HKG"); + + log("[0xdedb] => balance: " + value.toFixed(3) + " HKG"); assert.equal(0, value); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); assert.equal(800000, value); - return true; + return true; }) }); @@ -1106,44 +1106,44 @@ it('collect-all-the-rest-funds-before-time', function() { it('collect-all-the-rest-funds', function() { log(""); log(" (!) Action: [0xcc49] collect all the rest of HKG"); - - return dstContract_APL.getAllTheFunds( + + return dstContract_APL.getAllTheFunds( { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', - gas : 350000, + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + gas : 350000, }) .then(function (txHash) { - - return workbench.waitForReceipt(txHash); + + return workbench.waitForReceipt(txHash); }) - + .then(function (parsed) { - + assert.equal(1, parsed.logs.length); - args = parsed.logs[0].args; - - assert(dstContract_APL.address, args.from); - assert("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); - assert(800000000, args.value); + args = parsed.logs[0].args; - return true; + assert.equal(dstContract_APL.address, args.from); + assert.equal("0xcc49bea5129ef2369ff81b0c0200885893979b77", args.to); + assert.equal(800000000, args.value); + + return true; }) - + .then(function () { - + value = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber() / 1000; - - log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); + + log("[0xcc49] => balance: " + value.toFixed(3) + " HKG"); assert.equal(1000000, value); - + value = hackerGold.balanceOf(dstContract_APL.address).toNumber() / 1000; - - log("[APL] => balance: " + value.toFixed(3) + " HKG"); + + log("[APL] => balance: " + value.toFixed(3) + " HKG"); assert.equal(0, value); - return true; + return true; }) }); @@ -1151,9 +1151,3 @@ it('collect-all-the-rest-funds', function() { }); - - - - - - diff --git a/test/hacker-gold-sale/sale-1-test.js b/test/hacker-gold-sale/sale-1-test.js index f9d58d9..2561c18 100644 --- a/test/hacker-gold-sale/sale-1-test.js +++ b/test/hacker-gold-sale/sale-1-test.js @@ -52,10 +52,10 @@ it('init', function() { .then(function(){ var balance = hackerGold.balanceOf('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber(); - var totalSuply = hackerGold.getTotalSupply().toNumber(); + var totalSupply = hackerGold.getTotalSupply().toNumber(); assert.equal(balance, 0) - assert.equal(totalSuply, 0) + assert.equal(totalSupply, 0) return true; }) diff --git a/test/project-kudos/voters-registration.js b/test/project-kudos/voters-registration.js index 8451a6a..36ebfaf 100644 --- a/test/project-kudos/voters-registration.js +++ b/test/project-kudos/voters-registration.js @@ -19,15 +19,15 @@ it('setup', function() { return contracts.ProjectKudos.new() .then(function(contract) { - + if (contract.address){ projectKudos = contract; log('Deployed'); } else { throw new Error('No contract address'); - } - - return true; + } + + return true; }) }); @@ -36,20 +36,20 @@ it('register-voter', function() { // only owner can call to register - return projectKudos.register('0xcc49bea5129ef2369ff81b0c0200885893979b77', false, + return projectKudos.register('0xcc49bea5129ef2369ff81b0c0200885893979b77', false, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) - + .then(function(txHash) { return workbench.waitForReceipt(txHash); }) .then(function() { - + kudosLeft = projectKudos.getKudosLeft('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber(); assert.equal(kudosLeft, 0); - + return true; }) @@ -63,15 +63,15 @@ it('register-voter', function() { }) .then(function() { - + kudosLeft = projectKudos.getKudosLeft('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber(); assert.equal(kudosLeft, 10); - + return true; }) // register user once again - + .then(function() { return projectKudos.register('0xcc49bea5129ef2369ff81b0c0200885893979b77', false) .then(function(txHash) { @@ -80,28 +80,47 @@ it('register-voter', function() { }) .then(function() { - + kudosLeft = projectKudos.getKudosLeft('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber(); assert.equal(kudosLeft, 10); - + return true; }) + // re-register as judge should fail + + + .then(function() { + return projectKudos.register('0xcc49bea5129ef2369ff81b0c0200885893979b77', true) + .then(function(txHash) { + return workbench.waitForReceipt(txHash); + }); + }) + + .then(function() { + + kudosLeft = projectKudos.getKudosLeft('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber(); + assert.equal(kudosLeft, 10); //still no judge + + return true; + }) + + }); it('register-judge', function() { return projectKudos.register('0x211b1b6e61e475ace9bf13ae79373ddb419b5f72', true) - + .then(function(txHash) { return workbench.waitForReceipt(txHash); }) .then(function() { - + kudosLeft = projectKudos.getKudosLeft('0x211b1b6e61e475ace9bf13ae79373ddb419b5f72').toNumber(); assert.equal(kudosLeft, 1000); - + return true; }) }); @@ -111,20 +130,20 @@ it('grant-voter-social-proof', function() { // only owner can call to grantKudos - return projectKudos.grantKudos('0xcc49bea5129ef2369ff81b0c0200885893979b77', 0, + return projectKudos.grantKudos('0xcc49bea5129ef2369ff81b0c0200885893979b77', 0, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) - + .then(function(txHash) { return workbench.waitForReceipt(txHash); }) .then(function() { - + kudosLeft = projectKudos.getKudosLeft('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber(); assert.equal(kudosLeft, 10); - + return true; }) @@ -138,10 +157,10 @@ it('grant-voter-social-proof', function() { }) .then(function() { - + kudosLeft = projectKudos.getKudosLeft('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber(); assert.equal(kudosLeft, 110); - + return true; }) @@ -155,10 +174,10 @@ it('grant-voter-social-proof', function() { }) .then(function() { - + kudosLeft = projectKudos.getKudosLeft('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber(); assert.equal(kudosLeft, 110); - + return true; }) @@ -172,17 +191,17 @@ it('grant-voter-social-proof', function() { }) .then(function() { - + kudosLeft = projectKudos.getKudosLeft('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber(); assert.equal(kudosLeft, 210); - + return true; }) }); it('grant-voter-fake-proof', function() { - + return projectKudos.register('0x8b737a5c37007216e0f391694fc0ce9eb36cae26', false) .then(function(txHash) { @@ -190,44 +209,62 @@ it('grant-voter-fake-proof', function() { }); then(function () { - return projectKudos.grantKudos('0x8b737a5c37007216e0f391694fc0ce9eb36cae26', 3); + return projectKudos.grantKudos('0x8b737a5c37007216e0f391694fc0ce9eb36cae26', 3); }) .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) .then(function() { - + kudosLeft = projectKudos.getKudosLeft('0x8b737a5c37007216e0f391694fc0ce9eb36cae26').toNumber(); assert.equal(kudosLeft, 10); - + return true; - }) -}); - + }) +}); + it('grant-judge-social-proof', function() { return projectKudos.grantKudos('0x211b1b6e61e475ace9bf13ae79373ddb419b5f72', 0) - + .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) .then(function() { - + kudosLeft = projectKudos.getKudosLeft('0x211b1b6e61e475ace9bf13ae79373ddb419b5f72').toNumber(); assert.equal(kudosLeft, 1000); - + return true; - }) + }) +}); + +it('grant-non-existing-user', function() { + + return projectKudos.grantKudos('0xa74476443119A942dE498590Fe1f2454d7D4aC0d', 0) + + .then(function(txHash) { + + // we are waiting for blockchain to accept the transaction + return workbench.waitForReceipt(txHash); + }) + + .then(function() { + + kudosLeft = projectKudos.getKudosLeft('0xa74476443119A942dE498590Fe1f2454d7D4aC0d').toNumber(); + assert.equal(kudosLeft, 0); + + return true; + }) +}); + + }); - - - -}); diff --git a/test/project-kudos/voting-projects.js b/test/project-kudos/voting-projects.js index 170dda4..751dfdc 100644 --- a/test/project-kudos/voting-projects.js +++ b/test/project-kudos/voting-projects.js @@ -36,60 +36,60 @@ it('setup', function() { return contracts.ProjectKudos.new() .then(function(contract) { - + if (contract.address){ projectKudos = contract; } else { throw new Error('No contract address'); - } - - return true; + } + + return true; }) - - .then(function (){ return workbench.rollTimeTo('23-aug-2016'); }); + + .then(function (){ return workbench.rollTimeTo('23-aug-2016'); }); }); it('register-voter', function() { return projectKudos.register('0xcc49bea5129ef2369ff81b0c0200885893979b77', false) - + .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) .then(function() { - + kudosLeft = projectKudos.getKudosLeft('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber(); assert.equal(kudosLeft, 10); - + return true; - }) + }) }); it('register-judge', function() { - return projectKudos.register('0x211b1b6e61e475ace9bf13ae79373ddb419b5f72', true, + return projectKudos.register('0x211b1b6e61e475ace9bf13ae79373ddb419b5f72', true, { from : '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826', }) - + .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) .then(function() { - + kudosLeft = projectKudos.getKudosLeft('0x211b1b6e61e475ace9bf13ae79373ddb419b5f72').toNumber(); assert.equal(kudosLeft, 1000); - + return true; - }) + }) }); it('vote-before-the-period', function() { @@ -97,26 +97,26 @@ it('vote-before-the-period', function() { return workbench.rollTimeTo('24-Nov-2016 13:59 UTC+00') .then(function() { - return projectKudos.giveKudos('TST', 10, + return projectKudos.giveKudos('TST', 10, { from : '0x211b1b6e61e475ace9bf13ae79373ddb419b5f72' }) }) - + .then(function(txHash) { return workbench.waitForReceipt(txHash); }) .then(function() { - + kudosLeft = projectKudos.getKudosLeft('0x211b1b6e61e475ace9bf13ae79373ddb419b5f72').toNumber(); kudosGiven = projectKudos.getKudosGiven('0x211b1b6e61e475ace9bf13ae79373ddb419b5f72').toNumber(); prjKudos = projectKudos.getProjectKudos('TST').toNumber(); - + assert.equal(kudosLeft, 1000); assert.equal(kudosGiven, 0); assert.equal(prjKudos, 0); - + return true; }) @@ -127,26 +127,26 @@ it('vote-after-the-period', function() { return workbench.rollTimeTo('22-Dec-2016 14:00 UTC+00') .then(function() { - return projectKudos.giveKudos('TST', 10, + return projectKudos.giveKudos('TST', 10, { from : '0xcc49bea5129ef2369ff81b0c0200885893979b77' }) }) - + .then(function(txHash) { return workbench.waitForReceipt(txHash); }) .then(function() { - + kudosLeft = projectKudos.getKudosLeft('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber(); kudosGiven = projectKudos.getKudosGiven('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber(); kudosForProject = projectKudos.getProjectKudos('TST').toNumber(); - + assert.equal(kudosLeft, 10); assert.equal(kudosGiven, 0); assert.equal(kudosForProject, 0); - + return true; }) @@ -157,28 +157,28 @@ it('vote-during-the-period-1', function() { return workbench.rollTimeTo('30-Nov-2016 14:00') .then(function() { - return projectKudos.giveKudos('TST', 10, + return projectKudos.giveKudos('TST', 10, { - from : '0x211b1b6e61e475ace9bf13ae79373ddb419b5f72', + from : '0x211b1b6e61e475ace9bf13ae79373ddb419b5f72', }) }) - + .then(function(txHash) { - - // we are waiting for blockchain to accept the transaction + + // we are waiting for blockchain to accept the transaction return workbench.waitForReceipt(txHash); }) .then(function() { - + kudosLeft = projectKudos.getKudosLeft('0x211b1b6e61e475ace9bf13ae79373ddb419b5f72').toNumber(); kudosGiven = projectKudos.getKudosGiven('0x211b1b6e61e475ace9bf13ae79373ddb419b5f72').toNumber(); kudosForProject = projectKudos.getProjectKudos('TST').toNumber(); - + assert.equal(kudosLeft, 990); assert.equal(kudosGiven, 10); assert.equal(kudosForProject, 10); - + return true; }); @@ -186,25 +186,25 @@ it('vote-during-the-period-1', function() { it('vote-by-unregistered-user', function() { - return projectKudos.giveKudos('TST', 10, + return projectKudos.giveKudos('TST', 10, { - from : '0x8b737a5c37007216e0f391694fc0ce9eb36cae26', + from : '0x8b737a5c37007216e0f391694fc0ce9eb36cae26', }) - + .then(function(txHash) { return workbench.waitForReceipt(txHash); }) .then(function() { - + kudosLeft = projectKudos.getKudosLeft('0x8b737a5c37007216e0f391694fc0ce9eb36cae26').toNumber(); kudosGiven = projectKudos.getKudosGiven('0x8b737a5c37007216e0f391694fc0ce9eb36cae26').toNumber(); kudosForProject = projectKudos.getProjectKudos('TST').toNumber(); - + assert.equal(kudosLeft, 0); assert.equal(kudosGiven, 0); assert.equal(kudosForProject, 10); - + return true; }); @@ -212,25 +212,25 @@ it('vote-by-unregistered-user', function() { it('vote-for-project-over-the-limit', function() { - return projectKudos.giveKudos('TST', 1790, + return projectKudos.giveKudos('TST', 1790, { - from : '0x211b1b6e61e475ace9bf13ae79373ddb419b5f72', + from : '0x211b1b6e61e475ace9bf13ae79373ddb419b5f72', }) - + .then(function(txHash) { return workbench.waitForReceipt(txHash); }) .then(function() { - + kudosLeft = projectKudos.getKudosLeft('0x211b1b6e61e475ace9bf13ae79373ddb419b5f72').toNumber(); kudosGiven = projectKudos.getKudosGiven('0x211b1b6e61e475ace9bf13ae79373ddb419b5f72').toNumber(); kudosForProject = projectKudos.getProjectKudos('TST').toNumber(); - + assert.equal(kudosLeft, 990); assert.equal(kudosGiven, 10); assert.equal(kudosForProject, 10); - + return true; }); @@ -238,11 +238,11 @@ it('vote-for-project-over-the-limit', function() { it('vote-during-the-period-2', function() { - return projectKudos.giveKudos('TST', 4, + return projectKudos.giveKudos('TST', 4, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }) - + .then(function(txHash) { return workbench.waitForReceipt(txHash); }) @@ -251,7 +251,7 @@ it('vote-during-the-period-2', function() { .then(function(parsed) { args = parsed.logs[0].args; - + assert.equal(args.voter, '0xcc49bea5129ef2369ff81b0c0200885893979b77'); assert.equal(args.count.toNumber(), 4); assert.equal(args.projectCode, ethUtil.bufferToHex(ethUtil.sha3('TST'))); @@ -260,34 +260,34 @@ it('vote-during-the-period-2', function() { }) .then(function() { - return projectKudos.giveKudos('DEM', 5, + return projectKudos.giveKudos('DEM', 5, { - from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', + from : '0xcc49bea5129ef2369ff81b0c0200885893979b77', }).then(function(txHash) { return workbench.waitForReceipt(txHash); }) }) .then(function() { - return projectKudos.giveKudos('DEM', 150, + return projectKudos.giveKudos('DEM', 150, { - from : '0x211b1b6e61e475ace9bf13ae79373ddb419b5f72', + from : '0x211b1b6e61e475ace9bf13ae79373ddb419b5f72', }).then(function(txHash) { return workbench.waitForReceipt(txHash); }) }) .then(function() { - return projectKudos.giveKudos('DEM', 150, + return projectKudos.giveKudos('DEM', 150, { - from : '0x211b1b6e61e475ace9bf13ae79373ddb419b5f72', + from : '0x211b1b6e61e475ace9bf13ae79373ddb419b5f72', }).then(function(txHash) { return workbench.waitForReceipt(txHash); }) }) .then(function() { - + kudosLeft = projectKudos.getKudosLeft('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber(); kudosGiven = projectKudos.getKudosGiven('0xcc49bea5129ef2369ff81b0c0200885893979b77').toNumber(); @@ -296,7 +296,15 @@ it('vote-during-the-period-2', function() { userKudos = projectKudos.getKudosPerProject('0xcc49bea5129ef2369ff81b0c0200885893979b77'); judgeKudos = projectKudos.getKudosPerProject('0x211b1b6e61e475ace9bf13ae79373ddb419b5f72'); - + + kudosByUsers = projectKudos.getProjectKudosByUsers('TST', []); + assert.equal(kudosByUsers.length, 0); + + kudosByUsers = projectKudos.getProjectKudosByUsers('TST', ['0xcc49bea5129ef2369ff81b0c0200885893979b77']); + // check kudosByUsers equal to userKudos + assert.equal(kudosByUsers.length, 1); + assert.equal(Number(kudosByUsers[0]), Number(userKudos[1][0])); + assert.equal(kudosLeft, 1); assert.equal(kudosGiven, 9); @@ -320,10 +328,10 @@ it('vote-during-the-period-2', function() { assert.equal(projects[1], string2Bytes32('DEM')); assert.equal(votes[0], 10); assert.equal(votes[1], 300); - + return true; }) - + }); -}); +});