Skip to content

Commit

Permalink
access accounts via fixtures, add error string
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdefinitelyahuman committed Sep 28, 2019
1 parent 7488736 commit f6592b6
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions tests/test_approve_transferFrom.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
#!/usr/bin/python3

import pytest
from brownie import accounts


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


def test_approval(token):
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"
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"


def test_transferFrom(token):
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]})

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


def test_transferFrom_reverts(token):
def test_transferFrom_reverts(token, accounts):
'''transerFrom should revert'''
with pytest.reverts():
token.transferFrom(accounts[0], accounts[3], "10 ether", {'from': accounts[1]})
with pytest.reverts():
with pytest.reverts("Insufficient allowance"):
token.transferFrom(accounts[0], accounts[2], "1 ether", {'from': accounts[1]})

with pytest.reverts("Insufficient allowance"):
token.transferFrom(accounts[0], accounts[2], "1 ether", {'from': accounts[0]})

0 comments on commit f6592b6

Please sign in to comment.