diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db66c16..f5cf088 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,8 +13,8 @@ jobs: run: docker build ./ -t velodrome/sugar - name: Runs code QA and tests for optimism - run: docker run --rm --env-file=env.example -v $(pwd):/app -w /app -t velodrome/sugar sh -c 'flake8 && brownie test tests/optimism/**.py --network=optimism-main' + run: docker run --rm --env-file=env.example -e CHAIN_ID=10 -v $(pwd):/app -w /app -t velodrome/sugar sh -c 'flake8 && brownie test --network=optimism-main' - name: Runs code QA and tests for base - run: docker run --rm --env-file=env.example -v $(pwd):/app -w /app -t velodrome/sugar sh -c 'flake8 && brownie test tests/base/**.py --network=base-main' + run: docker run --rm --env-file=env.example -e CHAIN_ID=8453 -v $(pwd):/app -w /app -t velodrome/sugar sh -c 'flake8 && brownie test --network=base-main' - name: Runs code QA and sugar factory registry tests - run: docker run --rm --env-file=env.example -v $(pwd):/app -w /app -t velodrome/sugar sh -c 'flake8 && brownie test tests/test_factory_registry.py --network=mode-main' + run: docker run --rm --env-file=env.example -e CHAIN_ID=34443 -v $(pwd):/app -w /app -t velodrome/sugar sh -c 'flake8 && brownie test --network=mode-main' diff --git a/brownie-config.yaml b/brownie-config.yaml index dd0b871..1a6bebb 100644 --- a/brownie-config.yaml +++ b/brownie-config.yaml @@ -8,5 +8,6 @@ networks: fork: https://optimism-mainnet.wallet.coinbase.com evm_version: shanghai compiler: + evm_version: cancun vyper: version: 0.4.0 diff --git a/env.example b/env.example index 92ea5e9..2550f72 100644 --- a/env.example +++ b/env.example @@ -12,11 +12,11 @@ RELAY_REGISTRY_ADDRESSES_10=0xe9F00f2e61CB0c6fb00A2e457546aCbF0fC303C2,0x6b1253B GOVERNOR_10=0x1F82e10D58aEf03DeA2e478029fB0387A1cbE989 TEST_FACTORY_ADDRESS_10=0xCc0bDDB707055e04e497aB22a59c2aF4391cd12F -TEST_ADDRESS_10=0xEeE7FB850D28f5cabd5f1EDF540646b5bEA17CE5 -TEST_ALM_ADDRESS_10=0x892Ff98a46e5bd141E2D12618f4B2Fe6284debac +TEST_ADDRESS_10=0x892ff98a46e5bd141e2d12618f4b2fe6284debac +TEST_ALM_ADDRESS_10=0x892ff98a46e5bd141e2d12618f4b2fe6284debac -LP_SUGAR_ADDRESS_10=0x35F233BE126d7D08aB2D65E647E8c379b1FACF39 -REWARDS_SUGAR_ADDRESS_10= +LP_SUGAR_ADDRESS_10=0xd0bF8A2e7ECAC81106b3A1A341299E9314219598 +REWARDS_SUGAR_ADDRESS_10=0xc4e64A0B93713a9be19B1ccdA408F76923202B73 VE_SUGAR_ADDRESS_10=0x94f913362b232e31daB49a1aFB775cfd25DaA6a1 RELAY_SUGAR_ADDRESS_10=0xb8307e5842B9aeE75C704183F0355076aa74b4e2 @@ -31,11 +31,11 @@ RELAY_REGISTRY_ADDRESSES_8453=0x05e41604B9463e2224227053980dfF3f57fb6dB5,0xD308a GOVERNOR_8453=0x94C012A23A8A65A6f40608dA30534a46a433F410 TEST_FACTORY_ADDRESS_8453=0x5e7BB104d84c7CB9B682AaC2F3d509f5F406809A -TEST_ADDRESS_8453=0xEeE7FB850D28f5cabd5f1EDF540646b5bEA17CE5 +TEST_ADDRESS_8453=0x892Ff98a46e5bd141E2D12618f4B2Fe6284debac TEST_ALM_ADDRESS_8453=0x892Ff98a46e5bd141E2D12618f4B2Fe6284debac -LP_SUGAR_ADDRESS_8453=0x63a73829C74e936C1D2EEbE64164694f16700138 -REWARDS_SUGAR_ADDRESS_8453= +LP_SUGAR_ADDRESS_8453=0xC9611f3191073EE063a6AFDc6b58b660e8C90afE +REWARDS_SUGAR_ADDRESS_8453=0xEbfD2d983340e0bA6109a387928ADAe9FEE47D4b VE_SUGAR_ADDRESS_8453=0x4c5d3925fe65DFeB5A079485136e4De09cb664A5 RELAY_SUGAR_ADDRESS_8453=0x8932B5FE23C07Df06533F8f09E43e7cca6a24143 diff --git a/requirements.txt b/requirements.txt index 46254c2..057e2cd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ eth-brownie @ git+https://github.com/velodrome-finance/brownie@vyper-v0.4 vyper==0.4.0 flake8 -titanoboa diff --git a/scripts/deploy.py b/scripts/deploy.py index 8a8aa0a..ae0b7a7 100644 --- a/scripts/deploy.py +++ b/scripts/deploy.py @@ -1,7 +1,9 @@ # SPDX-License-Identifier: BUSL-1.1 import os -from brownie import accounts, VeSugar, LpSugar, RelaySugar, FactoryRegistry, RewardsSugar +from brownie import ( + accounts, VeSugar, LpSugar, RelaySugar, FactoryRegistry, RewardsSugar +) def main(): diff --git a/tests/base/test_ve_sugar.py b/tests/base/test_ve_sugar.py deleted file mode 100644 index 81ef098..0000000 --- a/tests/base/test_ve_sugar.py +++ /dev/null @@ -1,84 +0,0 @@ -# SPDX-License-Identifier: BUSL-1.1 -import os -import pytest - -from collections import namedtuple - - -@pytest.fixture -def sugar_contract(VeSugar, accounts): - # Since we depend on the rest of the protocol, - # we just point to an existing deployment - yield VeSugar.at(os.getenv('VE_SUGAR_ADDRESS_8453')) - - -@pytest.fixture -def VeNFTStruct(sugar_contract): - method_output = sugar_contract.byId.abi['outputs'][0] - members = list(map(lambda _e: _e['name'], method_output['components'])) - - yield namedtuple('VeNFTStruct', members) - - -def test_initial_state(sugar_contract): - assert sugar_contract.voter() == os.getenv('VOTER_8453') - assert sugar_contract.dist() == \ - os.getenv('DIST_8453') - assert sugar_contract.ve() is not None - - -def test_byId(sugar_contract, VeNFTStruct): - venft = VeNFTStruct(*sugar_contract.byId(1)) - - assert venft is not None - assert len(venft) == 14 - assert venft.id is not None - assert venft.voted_at > 0 - - -def test_byAccount(sugar_contract, VeNFTStruct): - venft = VeNFTStruct(*sugar_contract.byId(1)) - acc_venft = list(map( - lambda _v: VeNFTStruct(*_v), - sugar_contract.byAccount(venft.account) - )) - - assert venft is not None - assert len(venft) == 14 - assert venft.account == acc_venft[0].account - - -def test_all(sugar_contract, VeNFTStruct): - first_venft = VeNFTStruct(*sugar_contract.byId(1)) - second_venft = VeNFTStruct(*sugar_contract.byId(2)) - venfts = list(map( - lambda _v: VeNFTStruct(*_v), - sugar_contract.all(30, 0) - )) - - assert venfts is not None - assert len(venfts) > 2 - - venft1, venft2 = venfts[0:2] - - assert venft1.id == first_venft.id - assert venft1.account == first_venft.account - - assert venft2.id == second_venft.id - assert venft2.account == second_venft.account - - -def test_all_limit_offset(sugar_contract, VeNFTStruct): - second_venft = VeNFTStruct(*sugar_contract.byId(1)) - venfts = list(map( - lambda _v: VeNFTStruct(*_v), - sugar_contract.all(1, 1) - )) - - assert venfts is not None - assert len(venfts) == 1 - - venft1 = venfts[0] - - assert venft1.id == second_venft.id - assert venft1.account == second_venft.account diff --git a/tests/optimism/test_lp_sugar.py b/tests/optimism/test_lp_sugar.py deleted file mode 100644 index e849bdb..0000000 --- a/tests/optimism/test_lp_sugar.py +++ /dev/null @@ -1,260 +0,0 @@ -# SPDX-License-Identifier: BUSL-1.1 -import os -import pytest -from collections import namedtuple - -from web3.constants import ADDRESS_ZERO - - -@pytest.fixture -def sugar_contract(LpSugar, accounts): - # Since we depend on the rest of the protocol, - # we just point to an existing deployment - yield LpSugar.at(os.getenv('LP_SUGAR_ADDRESS_10')) - - -@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) - - -@pytest.fixture -def LpEpochStruct(sugar_contract): - method_output = sugar_contract.epochsByAddress.abi['outputs'][0] - members = list(map(lambda _e: _e['name'], method_output['components'])) - - yield namedtuple('LpEpochStruct', members) - - -@pytest.fixture -def LpEpochBribeStruct(sugar_contract): - lp_epoch_comp = sugar_contract.epochsByAddress.abi['outputs'][0] - pe_bribe_comp = lp_epoch_comp['components'][4] - members = list(map(lambda _e: _e['name'], pe_bribe_comp['components'])) - - yield namedtuple('LpEpochBribeStruct', members) - - -def test_initial_state(sugar_contract): - assert sugar_contract.voter() == os.getenv('VOTER_10') - assert sugar_contract.registry() == os.getenv('REGISTRY_10') - - -def test_byIndex(sugar_contract, LpStruct): - lp = LpStruct(*sugar_contract.byIndex(0)) - - assert lp is not None - assert len(lp) == 27 - 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, 1) - )) - - assert swap_lps is not None - assert len(swap_lps) > 1 - - lp1, lp2 = swap_lps[0:2] - - assert lp1.lp == first_lp.lp - - assert lp2.lp == second_lp.lp - - -def test_tokens(sugar_contract, TokenStruct, LpStruct): - first_lp = LpStruct(*sugar_contract.byIndex(0)) - second_lp = LpStruct(*sugar_contract.byIndex(1)) - tokens = list(map( - lambda _p: TokenStruct(*_p), - sugar_contract.tokens(10, 0, ADDRESS_ZERO, []) - )) - - assert tokens is not None - assert len(tokens) > 1 - - token0, token1, token2 = tokens[0: 3] - - assert token0.token_address == first_lp.token0 - assert token0.symbol is not None - assert token0.decimals > 0 - - assert token1.token_address == first_lp.token1 - assert token2.token_address == second_lp.token0 - - -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) - )) - - assert lps is not None - assert len(lps) > 1 - - lp1, lp2 = lps[0:2] - - assert lp1.lp == first_lp.lp - assert lp1.gauge == first_lp.gauge - - assert lp2.lp == second_lp.lp - assert lp2.gauge == second_lp.gauge - - -def test_all_pagination(sugar_contract, LpStruct): - max_lps = sugar_contract.MAX_LPS() - - for i in range(0, max_lps, max_lps): - lps = sugar_contract.all(max_lps, 0) - - assert lps is not None - 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) - )) - - assert lps is not None - assert len(lps) == 1 - - lp1 = lps[0] - - assert lp1.lp == second_lp.lp - assert lp1.lp == second_lp.lp - - -def test_positionsByFactory(sugar_contract, PositionStruct): - limit = 100 - offset = 0 - account = os.getenv('TEST_ADDRESS_10') - factory = os.getenv('TEST_FACTORY_ADDRESS_10') - - positions = list(map( - lambda _p: PositionStruct(*_p), - sugar_contract.positionsByFactory(limit, offset, account, factory) - )) - - assert positions is not None - assert len(positions) > 0 - - pos = positions[0] - - assert pos.id is not None - assert pos.lp is not None - - -def test_positions_ALM(sugar_contract, PositionStruct): - account = os.getenv('TEST_ALM_ADDRESS_10') - - positions = list(map( - lambda _p: PositionStruct(*_p), - sugar_contract.positions(1000, 0, account) - )) - - assert positions is not None - assert len(positions) > 0 - - pos = positions[0] - - assert pos.id is not None - assert pos.lp is not None - assert pos.alm is not None - - -def test_epochsByAddress_limit_offset( - sugar_contract, - LpStruct, - LpEpochStruct, - LpEpochBribeStruct - ): - first_lp = LpStruct(*sugar_contract.byIndex(1)) - lp_epochs = list(map( - lambda _p: LpEpochStruct(*_p), - sugar_contract.epochsByAddress(20, 3, first_lp.lp) - )) - - assert lp_epochs is not None - assert len(lp_epochs) > 10 - - epoch = lp_epochs[1] - epoch_bribes = list(map( - lambda _b: LpEpochBribeStruct(*_b), - epoch.bribes - )) - epoch_fees = list(map( - lambda _f: LpEpochBribeStruct(*_f), - epoch.fees - )) - - assert epoch.lp == first_lp.lp - assert epoch.votes > 0 - assert epoch.emissions > 0 - - if len(epoch_bribes) > 0: - assert epoch_bribes[0].amount > 0 - - if len(epoch_fees) > 0: - assert epoch_fees[0].amount > 0 - - -def test_epochsLatest_limit_offset( - sugar_contract, - LpStruct, - LpEpochStruct - ): - second_lp = LpStruct(*sugar_contract.byIndex(1)) - lp_epoch = list(map( - lambda _p: LpEpochStruct(*_p), - sugar_contract.epochsByAddress(1, 0, second_lp.lp) - )) - latest_epoch = list(map( - lambda _p: LpEpochStruct(*_p), - sugar_contract.epochsLatest(1, 1) - )) - - assert lp_epoch is not None - assert len(latest_epoch) == 1 - - pepoch = LpEpochStruct(*lp_epoch[0]) - lepoch = LpEpochStruct(*latest_epoch[0]) - - assert lepoch.lp == pepoch.lp - assert lepoch.ts == pepoch.ts diff --git a/tests/optimism/test_relay_sugar.py b/tests/optimism/test_relay_sugar.py deleted file mode 100644 index ed5ff41..0000000 --- a/tests/optimism/test_relay_sugar.py +++ /dev/null @@ -1,38 +0,0 @@ -# SPDX-License-Identifier: BUSL-1.1 -import os -import pytest - -from collections import namedtuple -from web3.constants import ADDRESS_ZERO - - -@pytest.fixture -def sugar_contract(RelaySugar, accounts): - # Since we depend on the rest of the protocol, - # we just point to an existing deployment - yield RelaySugar.at(os.getenv('RELAY_SUGAR_ADDRESS_10')) - - -@pytest.fixture -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) - - -def test_initial_state(sugar_contract): - assert sugar_contract.voter() == os.getenv('VOTER_10') - assert sugar_contract.registries(0) == \ - os.getenv('RELAY_REGISTRY_ADDRESSES_10').split(',')[0] - assert sugar_contract.ve() is not None - assert sugar_contract.token() is not None - - -def test_all(sugar_contract, RelayStruct): - relays = list(map( - lambda _r: RelayStruct(*_r), - sugar_contract.all(ADDRESS_ZERO) - )) - - assert len(relays) > 5 diff --git a/tests/test_factory_registry.py b/tests/test_factory_registry.py index 751c0d9..2bfbd86 100644 --- a/tests/test_factory_registry.py +++ b/tests/test_factory_registry.py @@ -3,18 +3,22 @@ from web3.constants import ADDRESS_ZERO +CHAIN_ID = os.getenv('CHAIN_ID', 10) + @pytest.fixture def factory_registry(FactoryRegistry): # Deploy the contract using the first test account as the owner - yield FactoryRegistry.at(os.getenv('REGISTRY_34443')) + yield FactoryRegistry.at(os.getenv(f'REGISTRY_{CHAIN_ID}')) +@pytest.mark.skipif(int(CHAIN_ID) in [10, 8453], reason="Only leaf chains") def test_initial_state(factory_registry): assert factory_registry.owner() ==\ "0xd42C7914cF8dc24a1075E29C283C581bd1b0d3D3" +@pytest.mark.skipif(int(CHAIN_ID) in [10, 8453], reason="Only leaf chains") def test_factories_to_pool_factory(factory_registry): pool_factory = "0x1111111111111111111111111111111111111111" result = factory_registry.factoriesToPoolFactory(pool_factory) diff --git a/tests/base/test_lp_sugar.py b/tests/test_lp_sugar.py similarity index 61% rename from tests/base/test_lp_sugar.py rename to tests/test_lp_sugar.py index 08290fa..bc34544 100644 --- a/tests/base/test_lp_sugar.py +++ b/tests/test_lp_sugar.py @@ -5,12 +5,14 @@ from web3.constants import ADDRESS_ZERO +CHAIN_ID = os.getenv('CHAIN_ID', 10) + @pytest.fixture def sugar_contract(LpSugar, accounts): # Since we depend on the rest of the protocol, # we just point to an existing deployment - yield LpSugar.at(os.getenv('LP_SUGAR_ADDRESS_8453')) + yield LpSugar.at(os.getenv(f'LP_SUGAR_ADDRESS_{CHAIN_ID}')) @pytest.fixture @@ -45,28 +47,6 @@ def PositionStruct(sugar_contract): yield namedtuple('PositionStruct', members) -@pytest.fixture -def LpEpochStruct(sugar_contract): - method_output = sugar_contract.epochsByAddress.abi['outputs'][0] - members = list(map(lambda _e: _e['name'], method_output['components'])) - - yield namedtuple('LpEpochStruct', members) - - -@pytest.fixture -def LpEpochBribeStruct(sugar_contract): - lp_epoch_comp = sugar_contract.epochsByAddress.abi['outputs'][0] - pe_bribe_comp = lp_epoch_comp['components'][4] - members = list(map(lambda _e: _e['name'], pe_bribe_comp['components'])) - - yield namedtuple('LpEpochBribeStruct', members) - - -def test_initial_state(sugar_contract): - assert sugar_contract.voter() == os.getenv('VOTER_8453') - assert sugar_contract.registry() == os.getenv('REGISTRY_8453') - - def test_byIndex(sugar_contract, LpStruct): lp = LpStruct(*sugar_contract.byIndex(0)) @@ -87,11 +67,10 @@ def test_forSwaps(sugar_contract, SwapLpStruct, LpStruct): assert swap_lps is not None assert len(swap_lps) > 1 - lp1, lp2 = swap_lps[0:2] - - assert lp1.lp == first_lp.lp + lps = list(map(lambda lp: lp.lp, swap_lps)) - assert lp2.lp == second_lp.lp + assert first_lp.lp in lps + assert second_lp.lp in lps def test_tokens(sugar_contract, TokenStruct, LpStruct): @@ -159,15 +138,14 @@ def test_all_limit_offset(sugar_contract, LpStruct): assert lp1.lp == second_lp.lp -def test_positionsByFactory(sugar_contract, PositionStruct): +def test_positions(sugar_contract, PositionStruct): limit = 100 offset = 0 - account = os.getenv('TEST_ADDRESS_8453') - factory = os.getenv('TEST_FACTORY_ADDRESS_8453') + account = os.getenv(f'TEST_ADDRESS_{CHAIN_ID}') positions = list(map( lambda _p: PositionStruct(*_p), - sugar_contract.positionsByFactory(limit, offset, account, factory) + sugar_contract.positions(limit, offset, account) )) assert positions is not None @@ -182,7 +160,7 @@ def test_positionsByFactory(sugar_contract, PositionStruct): def test_positionsUnstakedConcentrated(sugar_contract, PositionStruct): limit = 100 offset = 0 - account = os.getenv('TEST_ADDRESS_8453') + account = os.getenv(f'TEST_ADDRESS_{CHAIN_ID}') positions = list(map( lambda _p: PositionStruct(*_p), @@ -199,7 +177,7 @@ def test_positionsUnstakedConcentrated(sugar_contract, PositionStruct): def test_positions_ALM(sugar_contract, PositionStruct): - account = os.getenv('TEST_ALM_ADDRESS_8453') + account = os.getenv(f'TEST_ALM_ADDRESS_{CHAIN_ID}') positions = list(map( lambda _p: PositionStruct(*_p), @@ -214,64 +192,3 @@ def test_positions_ALM(sugar_contract, PositionStruct): assert pos.id is not None assert pos.lp is not None assert pos.alm is not None - - -def test_epochsByAddress_limit_offset( - sugar_contract, - LpStruct, - LpEpochStruct, - LpEpochBribeStruct - ): - first_lp = LpStruct(*sugar_contract.byIndex(0)) - lp_epochs = list(map( - lambda _p: LpEpochStruct(*_p), - sugar_contract.epochsByAddress(20, 3, first_lp.lp) - )) - - assert lp_epochs is not None - assert len(lp_epochs) > 10 - - epoch = lp_epochs[1] - epoch_bribes = list(map( - lambda _b: LpEpochBribeStruct(*_b), - epoch.bribes - )) - epoch_fees = list(map( - lambda _f: LpEpochBribeStruct(*_f), - epoch.fees - )) - - assert epoch.lp == first_lp.lp - assert epoch.votes > 0 - assert epoch.emissions > 0 - - if len(epoch_bribes) > 0: - assert epoch_bribes[0].amount > 0 - - if len(epoch_fees) > 0: - assert epoch_fees[0].amount > 0 - - -def test_epochsLatest_limit_offset( - sugar_contract, - LpStruct, - LpEpochStruct - ): - second_lp = LpStruct(*sugar_contract.byIndex(1)) - lp_epoch = list(map( - lambda _p: LpEpochStruct(*_p), - sugar_contract.epochsByAddress(1, 0, second_lp.lp) - )) - latest_epoch = list(map( - lambda _p: LpEpochStruct(*_p), - sugar_contract.epochsLatest(1, 1) - )) - - assert lp_epoch is not None - assert len(latest_epoch) == 1 - - pepoch = LpEpochStruct(*lp_epoch[0]) - lepoch = LpEpochStruct(*latest_epoch[0]) - - assert lepoch.lp == pepoch.lp - assert lepoch.ts == pepoch.ts diff --git a/tests/base/test_relay_sugar.py b/tests/test_relay_sugar.py similarity index 78% rename from tests/base/test_relay_sugar.py rename to tests/test_relay_sugar.py index 7a58f36..eab5631 100644 --- a/tests/base/test_relay_sugar.py +++ b/tests/test_relay_sugar.py @@ -5,12 +5,14 @@ from collections import namedtuple from web3.constants import ADDRESS_ZERO +CHAIN_ID = os.getenv('CHAIN_ID', 10) + @pytest.fixture def sugar_contract(RelaySugar, accounts): # Since we depend on the rest of the protocol, # we just point to an existing deployment - yield RelaySugar.at(os.getenv('RELAY_SUGAR_ADDRESS_8453')) + yield RelaySugar.at(os.getenv(f'RELAY_SUGAR_ADDRESS_{CHAIN_ID}')) @pytest.fixture @@ -22,9 +24,9 @@ def RelayStruct(sugar_contract): def test_initial_state(sugar_contract): - assert sugar_contract.voter() == os.getenv('VOTER_8453') + assert sugar_contract.voter() == os.getenv(f'VOTER_{CHAIN_ID}') assert sugar_contract.registries(0) == \ - os.getenv('RELAY_REGISTRY_ADDRESSES_8453').split(',')[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 diff --git a/tests/base/test_rewards_sugar.py b/tests/test_rewards_sugar.py similarity index 74% rename from tests/base/test_rewards_sugar.py rename to tests/test_rewards_sugar.py index 9c7864f..f9d3053 100644 --- a/tests/base/test_rewards_sugar.py +++ b/tests/test_rewards_sugar.py @@ -3,14 +3,29 @@ import pytest from collections import namedtuple -from web3.constants import ADDRESS_ZERO +CHAIN_ID = os.getenv('CHAIN_ID', 10) @pytest.fixture def sugar_contract(RewardsSugar, accounts): # Since we depend on the rest of the protocol, # we just point to an existing deployment - yield LpSugar.at(os.getenv('REWARDS_SUGAR_ADDRESS_8453')) + yield RewardsSugar.at(os.getenv(f'REWARDS_SUGAR_ADDRESS_{CHAIN_ID}')) + + +@pytest.fixture +def lp_sugar_contract(LpSugar, accounts): + # 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}')) + + +@pytest.fixture +def LpStruct(lp_sugar_contract): + method_output = lp_sugar_contract.byIndex.abi['outputs'][0] + members = list(map(lambda _e: _e['name'], method_output['components'])) + + yield namedtuple('LpStruct', members) @pytest.fixture @@ -30,18 +45,14 @@ def LpEpochBribeStruct(sugar_contract): yield namedtuple('LpEpochBribeStruct', members) -def test_initial_state(sugar_contract): - assert sugar_contract.voter() == os.getenv('VOTER_8453') - assert sugar_contract.registry() == os.getenv('REGISTRY_8453') - - def test_epochsByAddress_limit_offset( sugar_contract, + lp_sugar_contract, LpStruct, LpEpochStruct, LpEpochBribeStruct ): - first_lp = LpStruct(*sugar_contract.byIndex(0)) + first_lp = LpStruct(*lp_sugar_contract.byIndex(1)) lp_epochs = list(map( lambda _p: LpEpochStruct(*_p), sugar_contract.epochsByAddress(20, 3, first_lp.lp) @@ -73,10 +84,11 @@ def test_epochsByAddress_limit_offset( def test_epochsLatest_limit_offset( sugar_contract, + lp_sugar_contract, LpStruct, LpEpochStruct ): - second_lp = LpStruct(*sugar_contract.byIndex(1)) + second_lp = LpStruct(*lp_sugar_contract.byIndex(1)) lp_epoch = list(map( lambda _p: LpEpochStruct(*_p), sugar_contract.epochsByAddress(1, 0, second_lp.lp) diff --git a/tests/optimism/test_ve_sugar.py b/tests/test_ve_sugar.py similarity index 90% rename from tests/optimism/test_ve_sugar.py rename to tests/test_ve_sugar.py index 28b9cfc..584e6e6 100644 --- a/tests/optimism/test_ve_sugar.py +++ b/tests/test_ve_sugar.py @@ -4,12 +4,14 @@ from collections import namedtuple +CHAIN_ID = os.getenv('CHAIN_ID', 10) + @pytest.fixture def sugar_contract(VeSugar, accounts): # Since we depend on the rest of the protocol, # we just point to an existing deployment - yield VeSugar.at(os.getenv('VE_SUGAR_ADDRESS_10')) + yield VeSugar.at(os.getenv(f'VE_SUGAR_ADDRESS_{CHAIN_ID}')) @pytest.fixture @@ -21,9 +23,9 @@ def VeNFTStruct(sugar_contract): def test_initial_state(sugar_contract): - assert sugar_contract.voter() == os.getenv('VOTER_10') + assert sugar_contract.voter() == os.getenv(f'VOTER_{CHAIN_ID}') assert sugar_contract.dist() == \ - os.getenv('DIST_10') + os.getenv(f'DIST_{CHAIN_ID}') assert sugar_contract.ve() is not None @@ -33,7 +35,6 @@ def test_byId(sugar_contract, VeNFTStruct): assert venft is not None assert len(venft) == 14 assert venft.id is not None - assert len(venft.votes) > 0 assert venft.voted_at > 0