Skip to content

Commit e66d832

Browse files
committed
PayoutContract: Fixing payout distribution, and tests
Problem involving payouts is now fixed, using @voith's math. Now payout tokens can be more or less numerous than the available security tokens. Also, tests are improved to check that payouts are being paid correctly. Both scenarios (where payout tokens are more or less numerous) are tested.
1 parent abf29c2 commit e66d832

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

contracts/security-token/tests/PayoutContract.sol

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ contract PayoutContract is InvestorInteractionContract {
77
ERC20 payoutToken;
88
address from;
99
uint256 initialBalance;
10-
uint256 oneUnit;
1110

1211
function PayoutContract(CheckpointToken _token, ERC20 _payoutToken, KYCInterface _KYC, bytes32 name, bytes32 URI, uint256 _type, uint256 _hash, bytes32[] _options) InvestorInteractionContract(_token, _KYC, name, URI, _type, _hash, 0, _options) {
1312
payoutToken = _payoutToken;
@@ -21,11 +20,10 @@ contract PayoutContract is InvestorInteractionContract {
2120
payoutToken.transferFrom(from, address(this), allowed);
2221

2322
initialBalance = payoutToken.balanceOf(address(this));
24-
oneUnit = initialBalance / maximumSupply;
2523
}
2624

2725
function transferTrigger(address from, address to, uint256 amount) internal {
28-
payoutToken.transfer(from, amount * oneUnit);
26+
payoutToken.transfer(from, (amount * initialBalance) / maximumSupply);
2927
super.transferTrigger(from, to, amount);
3028
}
3129

ico/tests/contracts/test_security_token.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def security_token_url() -> str:
121121
return "http://tokenmarket.net/"
122122

123123
@pytest.fixture
124-
def security_token_initial_supply() -> str:
124+
def security_token_initial_supply() -> int:
125125
return 999999999000000000000000000
126126

127127

@@ -189,18 +189,18 @@ def payout_contract(chain, team_multisig, mock_kyc, security_token, test_token,
189189

190190
@pytest.fixture
191191
def test_token(chain, team_multisig, token_name, token_symbol, security_token_initial_supply, release_agent, customer) -> Contract:
192-
"""Create a Crowdsale token where transfer restrictions have been lifted."""
192+
"""Create a Crowdsale token where transfer restrictions have been lifted. Double the security_token_initial_supply"""
193+
"""Tokens must be minted in the respective testing functions to test different scenarios"""
193194

194-
args = [token_name, token_symbol, security_token_initial_supply, 18, True] # Owner set
195+
args = [token_name, token_symbol, 0, 18, True] # Owner set
195196

196197
tx = {
197198
"from": team_multisig
198199
}
199200

200201
token, hash = chain.provider.deploy_contract('CrowdsaleToken', deploy_args=args, deploy_transaction=tx)
201-
202202
token.transact({"from": team_multisig}).setReleaseAgent(team_multisig)
203-
token.transact({"from": team_multisig}).releaseTokenTransfer()
203+
token.transact({"from": team_multisig}).setMintAgent(team_multisig, True)
204204

205205
return token
206206

@@ -504,10 +504,12 @@ def test_voting_contract(chain, voting_contract, security_token, team_multisig,
504504
check_gas(chain, voting_contract.transact({"from": team_multisig}).transferInvestorTokens(customer, 123))
505505
check_gas(chain, voting_contract.transact({"from": customer}).importInvestor(customer))
506506
check_gas(chain, voting_contract.transact({"from": customer}).act(123))
507-
return
508507

509508

510-
def test_payout_contract(chain, payout_contract, security_token, test_token, team_multisig, customer):
509+
def test_payout_contract(chain, payout_contract, security_token, security_token_initial_supply, test_token, team_multisig, customer):
510+
test_token.transact({"from": team_multisig}).mint(team_multisig, security_token_initial_supply * 2)
511+
test_token.transact({"from": team_multisig}).releaseTokenTransfer()
512+
511513
start_balance = test_token.call().balanceOf(team_multisig)
512514
assert start_balance > 0
513515
check_gas(chain, test_token.transact({"from": team_multisig}).approve(payout_contract.address, start_balance))
@@ -521,8 +523,27 @@ def test_payout_contract(chain, payout_contract, security_token, test_token, tea
521523
assert test_token.call().balanceOf(team_multisig) > initial_balance
522524
# check balance in payout contract
523525
# 0x0000000000000000000000000000000000000064 is default address(100)
524-
assert payout_contract.functions.balanceOf('0x0000000000000000000000000000000000000064').call()
525-
return
526+
assert payout_contract.functions.balanceOf('0x0000000000000000000000000000000000000064').call() == 123
527+
528+
remaining_balance = security_token.call().balanceOf(team_multisig) - 123
529+
check_gas(chain, payout_contract.transact({"from": team_multisig}).act(remaining_balance))
530+
assert payout_contract.functions.balanceOf('0x0000000000000000000000000000000000000064').call() == remaining_balance + 123
531+
532+
assert test_token.call().balanceOf(team_multisig) == start_balance
533+
534+
535+
def test_payout_contract_with_transfer(chain, payout_contract, security_token, security_token_initial_supply, test_token, team_multisig, customer):
536+
test_token.transact({"from": team_multisig}).mint(team_multisig, int(security_token_initial_supply / 2))
537+
test_token.transact({"from": team_multisig}).releaseTokenTransfer()
538+
539+
start_balance = test_token.call().balanceOf(team_multisig)
540+
assert start_balance > 0
541+
check_gas(chain, test_token.transact({"from": team_multisig}).approve(payout_contract.address, start_balance))
542+
check_gas(chain, payout_contract.transact({"from": customer}).fetchTokens())
543+
544+
check_gas(chain, payout_contract.transact({"from": team_multisig}).transfer(customer, security_token.call().balanceOf(team_multisig)))
545+
check_gas(chain, payout_contract.transact({"from": customer}).act(security_token.call().balanceOf(team_multisig)))
546+
assert test_token.call().balanceOf(customer) == start_balance
526547

527548

528549
def test_erc865(chain, security_token, team_multisig, customer, private_key, signer_address):

0 commit comments

Comments
 (0)