|
1 | 1 | from fee_allocator.fee_allocator import FeeAllocator |
2 | | - |
3 | | -from pathlib import Path |
4 | | -import pandas as pd |
5 | | -import pytest |
| 2 | +from fee_allocator.accounting.chains import CorePoolChain, CorePoolRunConfig |
| 3 | +from bal_tools.subgraph import DateRange |
| 4 | +from web3 import Web3 |
6 | 5 | from decimal import Decimal |
7 | | -import numpy as np |
8 | | -from dataclasses import dataclass |
9 | | -import json |
10 | | - |
11 | | - |
12 | | -def test_fee_allocator(fee_allocator): |
13 | | - fee_allocator.allocate() |
14 | | - incentives_path = fee_allocator.generate_incentives_csv(Path("tests/output")) |
15 | | - |
16 | | - generated_df = pd.read_csv(incentives_path) |
17 | | - expected_df = pd.read_csv(Path("tests/test_data/expected_incentives.csv")) |
18 | | - |
19 | | - assert set(generated_df['pool_id']) == set(expected_df['pool_id']), "Pool IDs don't match between generated and expected results" |
20 | | - |
21 | | - merged_df = pd.merge(generated_df, expected_df, on='pool_id', suffixes=('_gen', '_exp')) |
22 | | - |
23 | | - numeric_columns = ['earned_fees', 'fees_to_vebal', 'fees_to_dao', |
24 | | - 'total_incentives', 'aura_incentives', 'bal_incentives', 'redirected_incentives', 'reroute_incentives'] |
25 | | - |
26 | | - for col in numeric_columns: |
27 | | - gen_col = f'{col}_gen' |
28 | | - exp_col = f'{col}_exp' |
| 6 | +from pathlib import Path |
29 | 7 |
|
30 | | - diff_pct = abs((merged_df[gen_col] - merged_df[exp_col]) / merged_df[exp_col] * 100) |
31 | | - problems = merged_df[diff_pct > 1] |
32 | 8 |
|
33 | | - if not problems.empty: |
34 | | - error_msg = f"\nValues for {col} differ by more than 1% for the following pools:\n" |
35 | | - for _, row in problems.iterrows(): |
36 | | - error_msg += f"Pool {row['pool_id']}: Generated={row[gen_col]:.2f}, Expected={row[exp_col]:.2f}, Diff={diff_pct.loc[_]:.2f}%\n" |
37 | | - pytest.fail(error_msg) |
38 | 9 |
|
| 10 | +def test_core_pool_chain_initialization(chain: CorePoolChain): |
| 11 | + """Test that CorePoolChain can be initialized with valid parameters""" |
| 12 | + assert isinstance(chain.block_range, tuple) |
| 13 | + assert len(chain.block_range) == 2 |
| 14 | + |
| 15 | +def test_core_pool_chain_pool_fee_data(chain: CorePoolChain): |
| 16 | + """Test that CorePoolChain can fetch and process pool fee data and calculate fee distributions""" |
| 17 | + chain.set_pool_fee_data() |
| 18 | + |
| 19 | + # Verify pool fee data was processed |
| 20 | + assert hasattr(chain, 'pool_fee_data') |
| 21 | + if chain.pool_fee_data: |
| 22 | + assert isinstance(chain.pool_fee_data, list) |
| 23 | + for pool_data in chain.pool_fee_data: |
| 24 | + assert hasattr(pool_data, 'pool_id') |
| 25 | + assert hasattr(pool_data, 'total_earned_fees_usd_twap') |
| 26 | + assert type(pool_data.total_earned_fees_usd_twap) is Decimal |
| 27 | + |
| 28 | + # Verify fee calculations |
| 29 | + assert type(chain.total_earned_fees_usd_twap) is Decimal |
| 30 | + assert type(chain.noncore_fees_collected) is Decimal |
| 31 | + assert type(chain.noncore_to_dao_usd) is Decimal |
| 32 | + assert type(chain.noncore_to_vebal_usd) is Decimal |
| 33 | + assert type(chain.total_fees_earned) is Decimal |
| 34 | + |
| 35 | +def test_core_pool_chain_cache_handling(chain: CorePoolChain): |
| 36 | + cache_file = chain._cache_file_path() |
| 37 | + assert cache_file.parent == chain.chains.cache_dir |
| 38 | + assert str(chain.chains.date_range[0]) in cache_file.name |
| 39 | + assert str(chain.chains.date_range[1]) in cache_file.name |
| 40 | + |
| 41 | +def test_fee_allocator_initialization(allocator: FeeAllocator): |
| 42 | + assert isinstance(allocator.run_config, CorePoolRunConfig) |
| 43 | + assert isinstance(allocator.book, dict) |
| 44 | + |
| 45 | +def test_fee_allocator_allocation_process(allocator: FeeAllocator): |
| 46 | + allocator.allocate() |
| 47 | + |
| 48 | + # Verify core pool chains were initialized |
| 49 | + assert hasattr(allocator.run_config, '_chains') |
| 50 | + assert isinstance(allocator.run_config._chains, dict) |
39 | 51 |
|
40 | | - |
| 52 | + # Verify aura vebal share was set |
| 53 | + assert allocator.run_config.aura_vebal_share is not None |
| 54 | + assert isinstance(allocator.run_config.aura_vebal_share, Decimal) |
| 55 | + assert 0 <= allocator.run_config.aura_vebal_share <= 1 |
0 commit comments