-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
access accounts via fixtures, add error string
- Loading branch information
1 parent
7488736
commit f6592b6
Showing
1 changed file
with
10 additions
and
8 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 |
---|---|---|
@@ -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]}) |