Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman committed Jan 31, 2020
1 parent 7654173 commit 84a935d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sol linguist-language=Solidity
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# token-mix

A bare-bones ERC20 template.

## Installation

```bash
brownie bake token
```
2 changes: 1 addition & 1 deletion scripts/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from brownie import *

def main():
accounts[0].deploy(Token, "Test Token", "TEST", 18, "1000 ether")
Token.deploy("Test Token", "TST", 18, 1e21, {'from': accounts[0]})
3 changes: 1 addition & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ def isolate(fn_isolation):

@pytest.fixture(scope="module")
def token(Token, accounts):
t = accounts[0].deploy(Token, "Test Token", "TST", 18, "1000 ether")
yield t
return accounts[0].deploy(Token, "Test Token", "TST", 18, 1e21)
26 changes: 14 additions & 12 deletions tests/test_approve_transferFrom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@

import pytest

import brownie


def test_balance(token, accounts):
assert token.balanceOf(accounts[0]) == "1000 ether"
assert token.balanceOf(accounts[0]) == 1e21


def test_approval(token, accounts):
'''Set approval'''
token.approve(accounts[1], "10 ether", {'from': accounts[0]})
assert token.allowance(accounts[0], accounts[1]) == "10 ether"
token.approve(accounts[1], 1e19, {'from': accounts[0]})
assert token.allowance(accounts[0], accounts[1]) == 1e19
assert token.allowance(accounts[0], accounts[2]) == 0

token.approve(accounts[1], "6 ether", {'from': accounts[0]})
assert token.allowance(accounts[0], accounts[1]) == "6 ether"
token.approve(accounts[1], 6e18, {'from': accounts[0]})
assert token.allowance(accounts[0], accounts[1]) == 6e18


def test_transferFrom(token, accounts):
'''Transfer tokens with transferFrom'''
token.approve(accounts[1], "6 ether", {'from': accounts[0]})
token.transferFrom(accounts[0], accounts[2], "5 ether", {'from': accounts[1]})
token.approve(accounts[1], 6e18, {'from': accounts[0]})
token.transferFrom(accounts[0], accounts[2], 5e18, {'from': accounts[1]})

assert token.balanceOf(accounts[2]) == "5 ether"
assert token.balanceOf(accounts[2]) == 5e18
assert token.balanceOf(accounts[1]) == 0
assert token.balanceOf(accounts[0]) == "995 ether"
assert token.allowance(accounts[0], accounts[1]) == "1 ether"
assert token.balanceOf(accounts[0]) == 9.95e20
assert token.allowance(accounts[0], accounts[1]) == 1e18


@pytest.mark.parametrize('idx', [0, 1, 2])
def test_transferFrom_reverts(token, accounts, idx):
'''transerFrom should revert'''
with pytest.reverts("Insufficient allowance"):
token.transferFrom(accounts[0], accounts[2], "1 ether", {'from': accounts[idx]})
with brownie.reverts("Insufficient allowance"):
token.transferFrom(accounts[0], accounts[2], 1e18, {'from': accounts[idx]})
8 changes: 4 additions & 4 deletions tests/test_transfer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python3

def test_transfer(token, accounts):
assert token.totalSupply() == "1000 ether"
token.transfer(accounts[1], "0.1 ether", {'from': accounts[0]})
assert token.balanceOf(accounts[1]) == "0.1 ether"
assert token.balanceOf(accounts[0]) == "999.9 ether"
assert token.totalSupply() == 1e21
token.transfer(accounts[1], 1e20, {'from': accounts[0]})
assert token.balanceOf(accounts[1]) == 1e20
assert token.balanceOf(accounts[0]) == 9e20

0 comments on commit 84a935d

Please sign in to comment.