Skip to content

Commit

Permalink
tests: updated tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
stas committed Dec 20, 2024
1 parent 6bb6e74 commit 275ecd3
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 242 deletions.
8 changes: 4 additions & 4 deletions tests/test_factory_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

from web3.constants import ADDRESS_ZERO

CHAIN_ID = os.getenv('CHAIN_ID', 34443)
CHAIN_ID = os.getenv("CHAIN_ID", 34443)


@pytest.fixture
@pytest.mark.skipif(int(CHAIN_ID) in [10, 8453], reason="Only leaf chains")
def factory_registry(FactoryRegistry):
def factory_registry(project):
# Deploy the contract using the first test account as the owner
yield FactoryRegistry.at(os.getenv(f'REGISTRY_{CHAIN_ID}'))
yield project.FactoryRegistry.at(os.getenv(f"REGISTRY_{CHAIN_ID}"))


@pytest.mark.skipif(int(CHAIN_ID) in [10, 8453], reason="Only leaf chains")
Expand All @@ -34,4 +34,4 @@ def test_initHashToPoolFactory(factory_registry):
factories = factory_registry.poolFactories()
result = factory_registry.initHashToPoolFactory(factories[0])

assert str(result) in os.getenv(f'INIT_HASHES_{CHAIN_ID}')
assert str(result) in os.getenv(f"INIT_HASHES_{CHAIN_ID}")
141 changes: 39 additions & 102 deletions tests/test_lp_sugar.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,32 @@
# SPDX-License-Identifier: BUSL-1.1
import os
import pytest
from collections import namedtuple

from web3.constants import ADDRESS_ZERO

CHAIN_ID = os.getenv('CHAIN_ID', 10)
CHAIN_ID = os.getenv("CHAIN_ID", 10)


@pytest.fixture
def sugar_contract(LpSugar, accounts):
def sugar_contract(project):
# Since we depend on the rest of the protocol,
# we just point to an existing deployment
yield LpSugar.at(os.getenv(f'LP_SUGAR_ADDRESS_{CHAIN_ID}'))
yield project.LpSugar.at(os.getenv(f"LP_SUGAR_ADDRESS_{CHAIN_ID}"))


@pytest.fixture
def TokenStruct(sugar_contract):
method_output = sugar_contract.tokens.abi['outputs'][0]
members = list(map(lambda _e: _e['name'], method_output['components']))

yield namedtuple('TokenStruct', members)


@pytest.fixture
def LpStruct(sugar_contract):
method_output = sugar_contract.byIndex.abi['outputs'][0]
members = list(map(lambda _e: _e['name'], method_output['components']))

yield namedtuple('LpStruct', members)


@pytest.fixture
def SwapLpStruct(sugar_contract):
method_output = sugar_contract.forSwaps.abi['outputs'][0]
members = list(map(lambda _e: _e['name'], method_output['components']))

yield namedtuple('SwapLpStruct', members)


@pytest.fixture
def PositionStruct(sugar_contract):
method_output = sugar_contract.positionsByFactory.abi['outputs'][0]
members = list(map(lambda _e: _e['name'], method_output['components']))

yield namedtuple('PositionStruct', members)


def test_byIndex(sugar_contract, LpStruct):
lp = LpStruct(*sugar_contract.byIndex(0))
def test_byIndex(sugar_contract):
lp = sugar_contract.byIndex(0)

assert lp is not None
assert len(lp) == 28
assert lp.lp is not None
assert lp.gauge != ADDRESS_ZERO


def test_forSwaps(sugar_contract, SwapLpStruct, LpStruct):
first_lp = LpStruct(*sugar_contract.byIndex(0))
second_lp = LpStruct(*sugar_contract.byIndex(1))
swap_lps = list(map(
lambda _p: SwapLpStruct(*_p),
sugar_contract.forSwaps(10, 0)
))
def test_forSwaps(sugar_contract):
first_lp = sugar_contract.byIndex(0)
second_lp = sugar_contract.byIndex(1)
swap_lps = sugar_contract.forSwaps(10, 0)

assert swap_lps is not None
assert len(swap_lps) > 1
Expand All @@ -73,17 +37,14 @@ def test_forSwaps(sugar_contract, SwapLpStruct, LpStruct):
assert second_lp.lp in lps


def test_tokens(sugar_contract, TokenStruct, LpStruct):
first_lp = LpStruct(*sugar_contract.byIndex(0))
tokens = list(map(
lambda _p: TokenStruct(*_p),
sugar_contract.tokens(10, 0, ADDRESS_ZERO, [])
))
def test_tokens(sugar_contract):
first_lp = sugar_contract.byIndex(0)
tokens = sugar_contract.tokens(10, 0, ADDRESS_ZERO, [])

assert tokens is not None
assert len(tokens) > 1

token0, token1 = tokens[0: 2]
token0, token1 = tokens[0:2]

assert token0.token_address == first_lp.token0
assert token0.symbol is not None
Expand All @@ -93,60 +54,48 @@ def test_tokens(sugar_contract, TokenStruct, LpStruct):


@pytest.mark.skipif(int(CHAIN_ID) not in [10], reason="Only OP")
def test_tokens_long_symbol(sugar_contract, TokenStruct):
tokens = list(map(
lambda _p: TokenStruct(*_p),
sugar_contract.tokens(1, 995, ADDRESS_ZERO, [])
))
def test_tokens_long_symbol(sugar_contract):
tokens = sugar_contract.tokens(1, 995, ADDRESS_ZERO, [])

assert tokens is not None
assert len(tokens) > 1

token = tokens[0]

assert token.symbol is not None
assert token.symbol == '-???-'
assert token.symbol == "-???-"


@pytest.mark.skipif(int(CHAIN_ID) not in [8453], reason="Only BASE")
def test_tokens_max_long_symbol(sugar_contract, TokenStruct):
tokens = list(map(
lambda _p: TokenStruct(*_p),
sugar_contract.tokens(1, 2508, ADDRESS_ZERO, [])
))
def test_tokens_max_long_symbol(sugar_contract):
tokens = sugar_contract.tokens(1, 2508, ADDRESS_ZERO, [])

assert tokens is not None
assert len(tokens) > 1

token = tokens[0]

assert token.symbol is not None
assert token.symbol != '-???-'
assert token.symbol != "-???-"


@pytest.mark.skipif(int(CHAIN_ID) not in [10], reason="Only OP")
def test_all_long_symbol(sugar_contract, LpStruct):
pools = list(map(
lambda _p: LpStruct(*_p),
sugar_contract.all(1, 995)
))
def test_all_long_symbol(sugar_contract):
pools = sugar_contract.all(1, 995)

assert pools is not None
assert len(pools) == 1

pool = pools[0]

assert pool.symbol is not None
assert pool.symbol == '-???-'
assert pool.symbol == "-???-"


def test_all(sugar_contract, LpStruct):
first_lp = LpStruct(*sugar_contract.byIndex(0))
second_lp = LpStruct(*sugar_contract.byIndex(1))
lps = list(map(
lambda _p: LpStruct(*_p),
sugar_contract.all(10, 0)
))
def test_all(sugar_contract):
first_lp = sugar_contract.byIndex(0)
second_lp = sugar_contract.byIndex(1)
lps = sugar_contract.all(10, 0)

assert lps is not None
assert len(lps) > 1
Expand All @@ -161,7 +110,7 @@ def test_all(sugar_contract, LpStruct):


@pytest.mark.skipif(int(CHAIN_ID) not in [10, 8453], reason="Only root chains")
def test_all_pagination(sugar_contract, LpStruct):
def test_all_pagination(sugar_contract):
max_lps = sugar_contract.MAX_LPS()

for i in range(0, max_lps, max_lps):
Expand All @@ -171,12 +120,9 @@ def test_all_pagination(sugar_contract, LpStruct):
assert len(lps) > max_lps - 1


def test_all_limit_offset(sugar_contract, LpStruct):
second_lp = LpStruct(*sugar_contract.byIndex(1))
lps = list(map(
lambda _p: LpStruct(*_p),
sugar_contract.all(1, 1)
))
def test_all_limit_offset(sugar_contract):
second_lp = sugar_contract.byIndex(1)
lps = sugar_contract.all(1, 1)

assert lps is not None
assert len(lps) == 1
Expand All @@ -187,15 +133,12 @@ def test_all_limit_offset(sugar_contract, LpStruct):
assert lp1.lp == second_lp.lp


def test_positions(sugar_contract, PositionStruct):
def test_positions(sugar_contract):
limit = 100
offset = 0
account = os.getenv(f'TEST_ADDRESS_{CHAIN_ID}')
account = os.getenv(f"TEST_ADDRESS_{CHAIN_ID}")

positions = list(map(
lambda _p: PositionStruct(*_p),
sugar_contract.positions(limit, offset, account)
))
positions = sugar_contract.positions(limit, offset, account)

assert positions is not None
assert len(positions) > 0
Expand All @@ -207,15 +150,12 @@ def test_positions(sugar_contract, PositionStruct):


@pytest.mark.skipif(int(CHAIN_ID) not in [10, 8453], reason="Only root chains")
def test_positionsUnstakedConcentrated(sugar_contract, PositionStruct):
def test_positionsUnstakedConcentrated(sugar_contract):
limit = 100
offset = 0
account = os.getenv(f'TEST_ADDRESS_{CHAIN_ID}')
account = os.getenv(f"TEST_ADDRESS_{CHAIN_ID}")

positions = list(map(
lambda _p: PositionStruct(*_p),
sugar_contract.positionsUnstakedConcentrated(limit, offset, account)
))
positions = sugar_contract.positionsUnstakedConcentrated(limit, offset, account)

assert positions is not None
assert len(positions) > 0
Expand All @@ -227,13 +167,10 @@ def test_positionsUnstakedConcentrated(sugar_contract, PositionStruct):


@pytest.mark.skipif(int(CHAIN_ID) not in [10, 8453], reason="Only root chains")
def test_positions_ALM(sugar_contract, PositionStruct):
account = os.getenv(f'TEST_ALM_ADDRESS_{CHAIN_ID}')
def test_positions_ALM(sugar_contract):
account = os.getenv(f"TEST_ALM_ADDRESS_{CHAIN_ID}")

positions = list(map(
lambda _p: PositionStruct(*_p),
sugar_contract.positions(1000, 0, account)
))
positions = sugar_contract.positions(1000, 0, account)

assert positions is not None
assert len(positions) > 0
Expand Down
31 changes: 10 additions & 21 deletions tests/test_relay_sugar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,32 @@
import os
import pytest

from collections import namedtuple
from web3.constants import ADDRESS_ZERO

CHAIN_ID = os.getenv('CHAIN_ID', 10)
CHAIN_ID = os.getenv("CHAIN_ID", 10)


@pytest.fixture
@pytest.mark.skipif(int(CHAIN_ID) not in [10, 8453], reason="Only root chains")
def sugar_contract(RelaySugar, accounts):
def sugar_contract(project, accounts):
# Since we depend on the rest of the protocol,
# we just point to an existing deployment
yield RelaySugar.at(os.getenv(f'RELAY_SUGAR_ADDRESS_{CHAIN_ID}'))


@pytest.fixture
@pytest.mark.skipif(int(CHAIN_ID) not in [10, 8453], reason="Only root chains")
def RelayStruct(sugar_contract):
method_output = sugar_contract.all.abi['outputs'][0]
members = list(map(lambda _e: _e['name'], method_output['components']))

yield namedtuple('RelayStruct', members)
yield project.RelaySugar.at(os.getenv(f"RELAY_SUGAR_ADDRESS_{CHAIN_ID}"))


@pytest.mark.skipif(int(CHAIN_ID) not in [10, 8453], reason="Only root chains")
def test_initial_state(sugar_contract):
assert sugar_contract.voter() == os.getenv(f'VOTER_{CHAIN_ID}')
assert sugar_contract.registries(0) == \
os.getenv(f'RELAY_REGISTRY_ADDRESSES_{CHAIN_ID}').split(',')[0]
assert sugar_contract.voter() == os.getenv(f"VOTER_{CHAIN_ID}")
assert (
sugar_contract.registries(0)
== os.getenv(f"RELAY_REGISTRY_ADDRESSES_{CHAIN_ID}").split(",")[0]
)
assert sugar_contract.ve() is not None
assert sugar_contract.token() is not None


@pytest.mark.skipif(int(CHAIN_ID) not in [10, 8453], reason="Only root chains")
def test_all(sugar_contract, RelayStruct):
relays = list(map(
lambda _r: RelayStruct(*_r),
sugar_contract.all(ADDRESS_ZERO)
))
def test_all(sugar_contract):
relays = sugar_contract.all(ADDRESS_ZERO)

assert len(relays) > 5
Loading

0 comments on commit 275ecd3

Please sign in to comment.