-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from iamdefinitelyahuman/v0.1.0
v0.1.0
- Loading branch information
Showing
8 changed files
with
177 additions
and
56 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 |
---|---|---|
|
@@ -24,31 +24,36 @@ jobs: | |
- name: Run Tox | ||
run: tox -e lint | ||
|
||
# TODO uncomment once test suite is ready | ||
# core: | ||
# runs-on: ${{ matrix.os }} | ||
# strategy: | ||
# fail-fast: false | ||
# matrix: | ||
# os: [macos-latest, ubuntu-latest, windows-latest] | ||
# python-minor: [6, 7, 8] | ||
|
||
# steps: | ||
# - uses: actions/checkout@v2 | ||
|
||
# - name: Setup Python 3.${{ matrix.python-minor }} | ||
# uses: actions/setup-python@v2 | ||
# with: | ||
# python-version: 3.${{ matrix.python-minor }} | ||
|
||
# - name: Install Tox | ||
# run: pip install tox wheel | ||
|
||
# - name: Run Tox | ||
# run: tox -e py3${{ matrix.python-minor }} | ||
|
||
# - name: Upload coverage to Codecov | ||
# uses: codecov/codecov-action@v1 | ||
# with: | ||
# file: ./coverage.xml | ||
# fail_ci_if_error: true | ||
core: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [macos-latest, ubuntu-latest, windows-latest] | ||
python-minor: [6, 7, 8] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v1 | ||
|
||
- name: Install Ganache | ||
run: npm install -g [email protected] | ||
|
||
- name: Setup Python 3.${{ matrix.python-minor }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.${{ matrix.python-minor }} | ||
|
||
- name: Install Tox | ||
run: pip install tox wheel | ||
|
||
- name: Run Tox | ||
run: tox -e py3${{ matrix.python-minor }} | ||
|
||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
file: ./coverage.xml | ||
fail_ci_if_error: true |
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
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,23 @@ | ||
import brownie | ||
import pytest | ||
|
||
|
||
def pytest_configure(): | ||
brownie.network.connect("development") | ||
|
||
|
||
@pytest.fixture(scope="function", autouse=True) | ||
def isolation(): | ||
brownie.chain.snapshot() | ||
yield | ||
brownie.chain.revert() | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def alice(): | ||
yield brownie.accounts[0] | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def bob(): | ||
yield brownie.accounts[1] |
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,83 @@ | ||
import itertools | ||
import pytest | ||
from brownie.exceptions import VirtualMachineError | ||
|
||
from brownie_tokens import ERC20 | ||
from brownie_tokens.template import FAIL_STATEMENT, RETURN_STATEMENT | ||
|
||
|
||
@pytest.fixture(scope="module", params=itertools.product(RETURN_STATEMENT, FAIL_STATEMENT)) | ||
def token(request, alice): | ||
success, fail = request.param | ||
if None in (fail, success) and fail is not success: | ||
pytest.skip() | ||
contract = ERC20(success=success, fail=fail) | ||
contract._mint_for_testing(alice, 10 ** 18, {"from": alice}) | ||
yield (contract, success, fail) | ||
|
||
|
||
def test_transfer_success(alice, bob, token): | ||
token, success, fail = token | ||
tx = token.transfer(bob, 0, {"from": alice}) | ||
if success is None: | ||
assert len(tx.return_value) == 0 | ||
else: | ||
assert tx.return_value is success | ||
|
||
|
||
def test_transfer_fail(alice, bob, token): | ||
token, success, fail = token | ||
if fail == "revert": | ||
with pytest.raises(VirtualMachineError): | ||
token.transfer(bob, 10 ** 19, {"from": alice}) | ||
else: | ||
tx = token.transfer(bob, 10 ** 19, {"from": alice}) | ||
if fail is None: | ||
assert len(tx.return_value) == 0 | ||
else: | ||
assert tx.return_value is fail | ||
|
||
|
||
def test_approve(alice, bob, token): | ||
token, success, fail = token | ||
tx = token.approve(alice, 10 ** 21, {"from": bob}) | ||
if success is None: | ||
assert len(tx.return_value) == 0 | ||
else: | ||
assert tx.return_value is success | ||
|
||
|
||
def test_transferFrom_success(alice, bob, token): | ||
token, success, fail = token | ||
tx = token.transferFrom(alice, bob, 0, {"from": alice}) | ||
if success is None: | ||
assert len(tx.return_value) == 0 | ||
else: | ||
assert tx.return_value is success | ||
|
||
|
||
def test_transferFrom_fail_allowance(alice, bob, token): | ||
token, success, fail = token | ||
if fail == "revert": | ||
with pytest.raises(VirtualMachineError): | ||
token.transferFrom(alice, bob, 10 ** 18, {"from": bob}) | ||
else: | ||
tx = token.transferFrom(alice, bob, 10 ** 18, {"from": bob}) | ||
if fail is None: | ||
assert len(tx.return_value) == 0 | ||
else: | ||
assert tx.return_value is fail | ||
|
||
|
||
def test_transferFrom_fail_balance(alice, bob, token): | ||
token, success, fail = token | ||
token.approve(bob, 10 ** 21, {"from": alice}) | ||
if fail == "revert": | ||
with pytest.raises(VirtualMachineError): | ||
token.transferFrom(alice, bob, 10 ** 21, {"from": bob}) | ||
else: | ||
tx = token.transferFrom(alice, bob, 10 ** 21, {"from": bob}) | ||
if fail is None: | ||
assert len(tx.return_value) == 0 | ||
else: | ||
assert tx.return_value is fail |