Skip to content

Commit

Permalink
Merge pull request #109 from TokenMarketNet/feat/recoverable-crowdsal…
Browse files Browse the repository at this point in the history
…e-token

Feat/recoverable crowdsale token
  • Loading branch information
miohtama committed Feb 26, 2018
2 parents 5c25e9f + 05e2b57 commit 4842075
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
3 changes: 1 addition & 2 deletions contracts/MintableToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import "zeppelin/contracts/token/ERC20.sol";
import "zeppelin/contracts/ownership/Ownable.sol";
import "./StandardTokenExt.sol";
import "./SafeMathLib.sol";

Expand All @@ -18,7 +17,7 @@ pragma solidity ^0.4.6;
* Only mint agents, contracts whitelisted by owner, can mint new tokens.
*
*/
contract MintableToken is StandardTokenExt, Ownable {
contract MintableToken is StandardTokenExt {

using SafeMathLib for uint;

Expand Down
5 changes: 2 additions & 3 deletions contracts/ReleasableToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@

pragma solidity ^0.4.8;

import "zeppelin/contracts/ownership/Ownable.sol";
import "zeppelin/contracts/token/ERC20.sol";
import "./StandardTokenExt.sol";


/**
* Define interface for releasing the token transfer after a successful crowdsale.
*/
contract ReleasableToken is ERC20, Ownable {
contract ReleasableToken is StandardTokenExt {

/* The finalizer contract that allows unlift the transfer limits on this token */
address public releaseAgent;
Expand Down
3 changes: 2 additions & 1 deletion contracts/StandardTokenExt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
pragma solidity ^0.4.14;

import "zeppelin/contracts/token/StandardToken.sol";
import "./Recoverable.sol";


/**
Expand All @@ -15,7 +16,7 @@ import "zeppelin/contracts/token/StandardToken.sol";
* @notice Interface marker is used by crowdsale contracts to validate that addresses point a good token contract.
*
*/
contract StandardTokenExt is StandardToken {
contract StandardTokenExt is Recoverable, StandardToken {

/* Interface declaration */
function isToken() public constant returns (bool weAre) {
Expand Down
46 changes: 46 additions & 0 deletions ico/tests/contracts/test_token.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Token core functionality."""

import datetime
import pytest
from ethereum.tester import TransactionFailed
from web3.contract import Contract
Expand All @@ -14,6 +15,23 @@ def token_new_symbol() -> str:
return "NEW"


@pytest.fixture
def other_token(chain, team_multisig):
args = [
team_multisig,
"OtherToken",
"OTH",
1000000,
0,
int((datetime.datetime(2017, 4, 22, 16, 0) - datetime.datetime(1970, 1, 1)).total_seconds())
]
contract, hash = chain.provider.deploy_contract('CentrallyIssuedToken', deploy_args=args)
assert contract.call().balanceOf(team_multisig) == 1000000

contract.transact({"from": team_multisig}).releaseTokenTransfer()
return contract


def test_token_initialized(token: Contract, team_multisig: str, token_symbol: str, token_name: str, initial_supply: int):
"""Token is initialized with the parameters we want."""
assert token.call().owner() == team_multisig
Expand All @@ -35,3 +53,31 @@ def test_token_rename(token: Contract, team_multisig, token_new_name, token_new_

assert token.call().name() == token_new_name
assert token.call().symbol() == token_new_symbol

def test_own_token_recovery(token: Contract, team_multisig, release_agent):
"""Let's try to recover other tokens from the contract"""
original_balance = token.call().balanceOf(team_multisig)

token.transact({"from": team_multisig}).setReleaseAgent(release_agent.address)
release_agent.transact({"from": team_multisig}).release()

token.transact({"from": team_multisig}).transfer(token.address, 1)
assert token.call().balanceOf(team_multisig) != original_balance

token.transact({"from": team_multisig}).recoverTokens(token.address)

assert token.call().balanceOf(team_multisig) == original_balance

def test_other_token_recovery(token: Contract, other_token: Contract, team_multisig, release_agent):
"""Let's try to recover other tokens from the contract"""
original_balance = other_token.call().balanceOf(team_multisig)

token.transact({"from": team_multisig}).setReleaseAgent(release_agent.address)
release_agent.transact({"from": team_multisig}).release()

other_token.transact({"from": team_multisig}).transfer(token.address, 1)
assert other_token.call().balanceOf(team_multisig) != original_balance

token.transact({"from": team_multisig}).recoverTokens(other_token.address)

assert other_token.call().balanceOf(team_multisig) == original_balance

0 comments on commit 4842075

Please sign in to comment.