Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TokenVault: Implementing full EIP-20 support and improved tests #175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions contracts/TokenVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pragma solidity ^0.4.8;

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

/**
Expand Down Expand Up @@ -62,7 +62,7 @@ contract TokenVault is Ownable, Recoverable {
uint public tokensPerSecond;

/** We can also define our own token, which will override the ICO one ***/
StandardTokenExt public token;
ERC20 public token;

/** What is our current state.
*
Expand All @@ -89,7 +89,7 @@ contract TokenVault is Ownable, Recoverable {
* @param _tokensToBeAllocated Total number of tokens this vault will hold - including decimal multiplication
* @param _tokensPerSecond Define the tap: how many tokens we permit an user to withdraw per second, 0 to disable
*/
function TokenVault(address _owner, uint _freezeEndsAt, StandardTokenExt _token, uint _tokensToBeAllocated, uint _tokensPerSecond) {
function TokenVault(address _owner, uint _freezeEndsAt, ERC20 _token, uint _tokensToBeAllocated, uint _tokensPerSecond) {

owner = _owner;

Expand All @@ -101,9 +101,8 @@ contract TokenVault is Ownable, Recoverable {
token = _token;

// Check the address looks like a token contract
if(!token.isToken()) {
throw;
}
// ">=" is intentional: 0 is fine, we just want to check if the function is there
require(token.totalSupply() >= 0);

// Give argument
if(_freezeEndsAt == 0) {
Expand Down
63 changes: 63 additions & 0 deletions ico/tests/contracts/test_token_vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class TokenVaultState(enum.IntEnum):
Distributing = 3


@pytest.fixture
def zero_address() -> str:
return "0x0000000000000000000000000000000000000000"


@pytest.fixture
def token(chain, team_multisig):
args = [
Expand Down Expand Up @@ -61,6 +66,13 @@ def token_vault_balances(chain, customer, customer_2) -> list:
]


@pytest.fixture
def non_token(chain, team_multisig, token, freeze_ends_at, token_vault_balances) -> Contract:
"""A test fixture to deploy a non-token."""

contract, hash = chain.provider.deploy_contract('GasStipendTester')
return contract

@pytest.fixture
def token_vault(chain, team_multisig, token, freeze_ends_at, token_vault_balances) -> Contract:
"""A test fixture to deploy a token vault."""
Expand Down Expand Up @@ -339,3 +351,54 @@ def test_tapped_claim(chain, token_vault_tapped, team_multisig, token, customer,
assert token.functions.balanceOf(customer_2).call() == 2000

assert token_vault_tapped.functions.totalClaimed().call() == 2400


def test_vault_nontoken(chain, team_multisig, non_token, freeze_ends_at, token_vault_balances) -> Contract:
"""Testing how a non-token vault works."""

total = 1000 + 2000

args = [
team_multisig,
freeze_ends_at,
non_token.address,
total,
0 # Disable the tap
]

with pytest.raises(TransactionFailed):
contract, hash = chain.provider.deploy_contract('TokenVault', deploy_args=args)


def test_vault_external_account(chain, team_multisig, customer_2, freeze_ends_at, token_vault_balances) -> Contract:
"""Testing how a non-token vault works."""

total = 1000 + 2000

args = [
team_multisig,
freeze_ends_at,
customer_2,
total,
0 # Disable the tap
]

with pytest.raises(TransactionFailed):
contract, hash = chain.provider.deploy_contract('TokenVault', deploy_args=args)


def test_vault_zero_address(chain, team_multisig, zero_address, freeze_ends_at, token_vault_balances) -> Contract:
"""Testing how a non-token vault works."""

total = 1000 + 2000

args = [
team_multisig,
freeze_ends_at,
zero_address,
total,
0 # Disable the tap
]

with pytest.raises(TransactionFailed):
contract, hash = chain.provider.deploy_contract('TokenVault', deploy_args=args)