Python contract wrappers (#1721)
This commit is contained in:
committed by
F. Eugene Aumson
parent
e043735362
commit
a256494ec8
80
python-packages/contract_wrappers/test/test_erc20_wrapper.py
Normal file
80
python-packages/contract_wrappers/test/test_erc20_wrapper.py
Normal file
@@ -0,0 +1,80 @@
|
||||
"""Tests for ERC20Token wrapper."""
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
|
||||
from zero_ex.contract_wrappers import ERC20Token, TxParams
|
||||
|
||||
|
||||
MAX_ALLOWANCE = int("{:.0f}".format(Decimal(2) ** 256 - 1))
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def erc20_wrapper(ganache_provider):
|
||||
"""Get an instance of ERC20Token wrapper class for testing."""
|
||||
return ERC20Token(ganache_provider)
|
||||
|
||||
|
||||
def test_erc20_wrapper__balance_of(
|
||||
accounts,
|
||||
erc20_wrapper, # pylint: disable=redefined-outer-name
|
||||
weth_address,
|
||||
weth_instance, # pylint: disable=redefined-outer-name
|
||||
):
|
||||
"""Test getting baance of an account for an ERC20 token."""
|
||||
acc1_original_weth_balance = erc20_wrapper.balance_of(
|
||||
weth_address, accounts[0]
|
||||
)
|
||||
acc2_original_weth_balance = erc20_wrapper.balance_of(
|
||||
weth_address, accounts[1]
|
||||
)
|
||||
|
||||
expected_difference = 1 * 10 ** 18
|
||||
|
||||
weth_instance.functions.deposit().transact(
|
||||
{"from": accounts[0], "value": expected_difference}
|
||||
)
|
||||
weth_instance.functions.deposit().transact(
|
||||
{"from": accounts[1], "value": expected_difference}
|
||||
)
|
||||
acc1_weth_balance = erc20_wrapper.balance_of(weth_address, accounts[0])
|
||||
acc2_weth_balance = erc20_wrapper.balance_of(weth_address, accounts[1])
|
||||
|
||||
assert (
|
||||
acc1_weth_balance - acc1_original_weth_balance == expected_difference
|
||||
)
|
||||
assert (
|
||||
acc2_weth_balance - acc2_original_weth_balance == expected_difference
|
||||
)
|
||||
|
||||
|
||||
def test_erc20_wrapper__approve(
|
||||
accounts,
|
||||
erc20_proxy_address,
|
||||
erc20_wrapper, # pylint: disable=redefined-outer-name
|
||||
weth_address, # pylint: disable=redefined-outer-name
|
||||
):
|
||||
"""Test approving one account to spend balance from another account."""
|
||||
erc20_wrapper.approve(
|
||||
weth_address,
|
||||
erc20_proxy_address,
|
||||
MAX_ALLOWANCE,
|
||||
tx_params=TxParams(from_=accounts[0]),
|
||||
)
|
||||
erc20_wrapper.approve(
|
||||
weth_address,
|
||||
erc20_proxy_address,
|
||||
MAX_ALLOWANCE,
|
||||
tx_params=TxParams(from_=accounts[1]),
|
||||
)
|
||||
|
||||
acc_1_weth_allowance = erc20_wrapper.allowance(
|
||||
weth_address, accounts[0], erc20_proxy_address
|
||||
)
|
||||
acc_2_weth_allowance = erc20_wrapper.allowance(
|
||||
weth_address, accounts[1], erc20_proxy_address
|
||||
)
|
||||
|
||||
assert acc_1_weth_allowance == MAX_ALLOWANCE
|
||||
assert acc_2_weth_allowance == MAX_ALLOWANCE
|
Reference in New Issue
Block a user