From 84a935d2d2cfabb096c17b08f06af3bb4c7960f9 Mon Sep 17 00:00:00 2001 From: iamdefinitelyahuman Date: Fri, 31 Jan 2020 20:07:34 +0400 Subject: [PATCH] minor updates --- .gitattributes | 1 + README.md | 7 +++++++ scripts/token.py | 2 +- tests/conftest.py | 3 +-- tests/test_approve_transferFrom.py | 26 ++++++++++++++------------ tests/test_transfer.py | 8 ++++---- 6 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..52031de --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.sol linguist-language=Solidity diff --git a/README.md b/README.md index 681854a..dd92c6a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,9 @@ # token-mix + A bare-bones ERC20 template. + +## Installation + +```bash +brownie bake token +``` diff --git a/scripts/token.py b/scripts/token.py index 69a2ef2..09606c2 100644 --- a/scripts/token.py +++ b/scripts/token.py @@ -3,4 +3,4 @@ from brownie import * def main(): - accounts[0].deploy(Token, "Test Token", "TEST", 18, "1000 ether") \ No newline at end of file + Token.deploy("Test Token", "TST", 18, 1e21, {'from': accounts[0]}) diff --git a/tests/conftest.py b/tests/conftest.py index 375be47..7cd08d5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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) diff --git a/tests/test_approve_transferFrom.py b/tests/test_approve_transferFrom.py index 9b4c738..09e57fe 100644 --- a/tests/test_approve_transferFrom.py +++ b/tests/test_approve_transferFrom.py @@ -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]}) diff --git a/tests/test_transfer.py b/tests/test_transfer.py index 33fa2a5..36b1386 100644 --- a/tests/test_transfer.py +++ b/tests/test_transfer.py @@ -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