-
Notifications
You must be signed in to change notification settings - Fork 559
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding burnable token, centrally issued token, payment forwarder tests.
- Loading branch information
Showing
7 changed files
with
172 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
pragma solidity ^0.4.8; | ||
|
||
import 'zeppelin/contracts/token/StandardToken.sol'; | ||
|
||
|
||
contract BurnableToken is StandardToken { | ||
|
||
address public constant BURN_ADDRESS = 0; | ||
|
||
/** How many tokens we burned */ | ||
event Burned(address burner, uint burnedAmount); | ||
|
||
/** | ||
* Burn extra tokens from a balance. | ||
* | ||
*/ | ||
function burn(uint burnAmount) { | ||
address burner = msg.sender; | ||
balances[burner] = safeSub(balances[burner], burnAmount); | ||
totalSupply = safeSub(totalSupply, burnAmount); | ||
Burned(burner, burnAmount); | ||
|
||
// Keep exchanges happy by sending the burned amount to | ||
// "burn address" | ||
Transfer(burner, BURN_ADDRESS, burnAmount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
pragma solidity ^0.4.6; | ||
|
||
import "./BurnableToken.sol"; | ||
import "./UpgradeableToken.sol"; | ||
|
||
|
||
/** | ||
* Centrally issued Ethereum token. | ||
* | ||
* We mix in burnable and upgradeable traits. | ||
* | ||
* Token supply is created in the token contract creation and allocated to owner. | ||
* The owner can then transfer from its supply to crowdsale participants. | ||
* The owner, or anybody, can burn any excessive tokens they are holding. | ||
* | ||
*/ | ||
contract CentrallyIssuedToken is BurnableToken, UpgradeableToken { | ||
|
||
string public name; | ||
string public symbol; | ||
uint public decimals; | ||
|
||
function CentrallyIssuedToken(address _owner, string _name, string _symbol, uint _totalSupply, uint _decimals) UpgradeableToken(_owner) { | ||
name = _name; | ||
symbol = _symbol; | ||
totalSupply = _totalSupply; | ||
decimals = _decimals; | ||
|
||
// Allocate initial balance to the owner | ||
balances[_owner] = _totalSupply; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"""Burn functionality.""" | ||
|
||
import pytest | ||
from ethereum.tester import TransactionFailed | ||
from web3.contract import Contract | ||
|
||
|
||
@pytest.fixture | ||
def token(chain, team_multisig): | ||
args = [ | ||
team_multisig, | ||
"Token", | ||
"TKN", | ||
1000000, | ||
0 | ||
] | ||
contract, hash = chain.provider.deploy_contract('CentrallyIssuedToken', deploy_args=args) | ||
assert contract.call().balanceOf(team_multisig) == 1000000 | ||
return contract | ||
|
||
|
||
@pytest.fixture | ||
def token_with_customer_balance(chain, team_multisig, token, customer) -> Contract: | ||
"""Create a Crowdsale token where transfer restrictions have been lifted.""" | ||
|
||
# Make sure customer 1 has some token balance | ||
token.transact({"from": team_multisig}).transfer(customer, 10000) | ||
|
||
return token | ||
|
||
|
||
def test_burn(token_with_customer_balance: Contract, customer: str): | ||
"""Burn tokens.""" | ||
|
||
token = token_with_customer_balance | ||
initial_balance = token.call().balanceOf(customer) | ||
initial_supply = token.call().totalSupply() | ||
amount = 1000 | ||
|
||
token.transact({"from": customer}).burn(amount) | ||
|
||
assert token.call().balanceOf(customer) == initial_balance - amount | ||
assert token.call().totalSupply() == initial_supply - amount | ||
|
||
events = token.pastEvents("Transfer").get() | ||
assert len(events) == 1 + 1 # plus initial transfer | ||
e = events[-1] | ||
assert e["args"]["to"] == '0x0000000000000000000000000000000000000000' | ||
assert e["args"]["from"] == customer | ||
assert e["args"]["value"] == amount | ||
|
||
events = token.pastEvents("Burned").get() | ||
assert len(events) == 1 | ||
e = events[-1] | ||
assert e["args"]["burner"] == customer | ||
assert e["args"]["burnedAmount"] == amount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters