Skip to content

Commit

Permalink
Include ERC20 ABI with changed "from" method
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Dec 5, 2023
1 parent 1c7fce4 commit 947bea8
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 90 deletions.
222 changes: 222 additions & 0 deletions contracts/interfaces/ERC20.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
[
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_spender",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "approve",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalSupply",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_from",
"type": "address"
},
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transferFrom",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [
{
"name": "",
"type": "uint8"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_owner",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"name": "balance",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "symbol",
"outputs": [
{
"name": "",
"type": "string"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"name": "_owner",
"type": "address"
},
{
"name": "_spender",
"type": "address"
}
],
"name": "allowance",
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"payable": true,
"stateMutability": "payable",
"type": "fallback"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "owner",
"type": "address"
},
{
"indexed": true,
"name": "spender",
"type": "address"
},
{
"indexed": false,
"name": "value",
"type": "uint256"
}
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"name": "_from",
"type": "address"
},
{
"indexed": true,
"name": "to",
"type": "address"
},
{
"indexed": false,
"name": "value",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
}
]
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def pytest_sessionstart():
logging.info("Connecting to Ethereum fork")
# connect to the network. TODO: use Drpc-Key header instead of GET param
boa.env.fork(url=environ["RPC_ETHEREUM"])
# TODO: boa.env.enable_fast_mode()

# store registries globally, so we don't have to recreate multiple times when generating tests.
# TODO: Can we move these to fixtures?
Expand Down
22 changes: 10 additions & 12 deletions tests/mainnet/metaregistry/api/test_get_admin_balances.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from tests.utils import (
assert_negative_coin_balance,
check_decode_error,
get_deployed_token_contract,
get_deployed_contract,
)


Expand All @@ -31,7 +31,7 @@ def pre_test_checks(metaregistry, pool):

lp_token = metaregistry.get_lp_token(pool)
try:
contract = get_deployed_token_contract(lp_token)
contract = get_deployed_contract("ERC20", lp_token)
if contract.totalSupply() == 0:
return pytest.skip("LP token supply is zero")
except ABIDecodeError as e:
Expand Down Expand Up @@ -67,7 +67,7 @@ def test_stable_factory_pools(
except BoaError:
first_coin = pool.coins(0)
with boa.reverts():
get_deployed_token_contract(first_coin).balanceOf(
get_deployed_contract("ERC20", first_coin).balanceOf(
stable_factory_pool
)
return pytest.skip(
Expand All @@ -84,9 +84,8 @@ def test_stable_factory_pools(
def _get_crypto_pool_admin_fees(
populated_metaregistry, pool, fee_receiver, alice_address
):
lp_token = get_deployed_token_contract(
populated_metaregistry.get_lp_token(pool)
)
lp_address = populated_metaregistry.get_lp_token(pool)
lp_token = get_deployed_contract("ERC20", lp_address)
fee_receiver_token_balance_before = lp_token.balanceOf(fee_receiver)

with boa.env.anchor():
Expand Down Expand Up @@ -124,19 +123,18 @@ def test_crypto_registry_pools(
alice_address,
)
except BoaError:
balance_of_pool = get_deployed_token_contract(pool.coins(1)).balanceOf(
pool.address
)
balance_of_pool = get_deployed_contract(
"ERC20", pool.coins(1)
).balanceOf(pool.address)
balance = pool.balances(1)
assert balance / balance_of_pool > 10**11
assert balance / balance_of_pool > 10**8
return pytest.skip(
f"Pool {pool} cannot claim admin fees. "
f"Pool has {balance_of_pool} but thinks it has {balance}."
)

metaregistry_output = populated_metaregistry.get_admin_balances(pool)
for i, output in enumerate(admin_balances):
assert output == pytest.approx(metaregistry_output[i])
assert admin_balances == pytest.approx(metaregistry_output)


def test_crypto_factory_pools(
Expand Down
24 changes: 8 additions & 16 deletions tests/mainnet/metaregistry/api/test_get_pool_name.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import pytest

from tests.utils import ZERO_ADDRESS, get_deployed_token_contract
from tests.utils import ZERO_ADDRESS, get_deployed_contract


def test_stable_registry_pools(
Expand All @@ -21,25 +19,20 @@ def test_stable_factory_pools(populated_metaregistry, stable_factory_pool):
)
)
num_registry_handlers = len(
list(filter((ZERO_ADDRESS).__ne__, pool_registry_handlers))
handler != ZERO_ADDRESS for handler in pool_registry_handlers
)

name = populated_metaregistry.get_pool_name(stable_factory_pool)
token_contract = get_deployed_contract("ERC20", stable_factory_pool)
if num_registry_handlers == 1:
assert name == get_deployed_token_contract(stable_factory_pool).name()
assert name == token_contract.name()
else:
with pytest.raises(AssertionError):
assert (
name == get_deployed_token_contract(stable_factory_pool).name()
)
assert name != token_contract.name()

pool_name2 = populated_metaregistry.get_pool_name(
stable_factory_pool, 1
)
assert (
pool_name2
== get_deployed_token_contract(stable_factory_pool).name()
)
assert pool_name2 == token_contract.name()

assert num_registry_handlers in (1, 2)

Expand All @@ -55,7 +48,6 @@ def test_crypto_factory_pools(
populated_metaregistry, crypto_factory_pool, crypto_factory
):
pool_name = populated_metaregistry.get_pool_name(crypto_factory_pool)
contract = get_deployed_token_contract(
crypto_factory.get_token(crypto_factory_pool)
)
lp_token = crypto_factory.get_token(crypto_factory_pool)
contract = get_deployed_contract("ERC20", lp_token)
assert pool_name == contract.name()
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tests.utils import (
ZERO_ADDRESS,
assert_negative_coin_balance,
get_deployed_token_contract,
get_deployed_contract,
)

EXCEPTION_POOLS = ["0x79a8C46DeA5aDa233ABaFFD40F3A0A2B1e5A4F27"]
Expand Down Expand Up @@ -38,7 +38,7 @@ def _get_underlying_balances(

if base_pool != ZERO_ADDRESS:
basepool_lp_token_balance = balances[idx]
coin_contract = get_deployed_token_contract(coin)
coin_contract = get_deployed_contract("ERC20", coin)
try:
lp_token_supply = coin_contract.totalSupply()
except (BoaError, AttributeError):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from boa import BoaError

from tests.utils import ZERO_ADDRESS, get_deployed_token_contract
from tests.utils import ZERO_ADDRESS, get_deployed_contract

EXCEPTIONS = {
# eth: ankreth pool returns [18, 0] when it should return:
Expand Down Expand Up @@ -32,8 +32,8 @@ def _test_underlying_decimals_getter(metaregistry, registry, pool):
continue

try:
token_contract = get_deployed_token_contract(
underlying_coins[i]
token_contract = get_deployed_contract(
"ERC20", underlying_coins[i]
)
actual_output.append(token_contract.decimals())
except BoaError:
Expand Down
4 changes: 2 additions & 2 deletions tests/mainnet/metaregistry/api/test_get_virtual_price.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ZERO_ADDRESS,
assert_negative_coin_balance,
check_decode_error,
get_deployed_token_contract,
get_deployed_contract,
)

# ---- sanity checks since vprice getters can revert for specific pools states ----
Expand Down Expand Up @@ -43,7 +43,7 @@ def _check_skem_tokens_with_weird_decimals(
pool_balances_float.append(pool_balances[i] / 10 ** coin_decimals[i])

first_coin = metaregistry.get_coins(pool)[0]
coin_contract = get_deployed_token_contract(first_coin)
coin_contract = get_deployed_contract("ERC20", first_coin)
if coin_decimals[i] == 0 and coin_contract.decimals() == 0:
try:
virtual_price = metaregistry.get_virtual_price_from_lp_token(
Expand Down
Loading

0 comments on commit 947bea8

Please sign in to comment.