Skip to content

Commit

Permalink
Added test to compare basic usage when quantity is unspecified
Browse files Browse the repository at this point in the history
  • Loading branch information
poliwop committed Sep 6, 2024
1 parent d224f4a commit 76bc198
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions hydradx/tests/test_omnipool_amm.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,32 @@ def test_remove_liquidity_specified_quantity_unspecified_nft(price_mult: float):
if not new_state.fail:
raise AssertionError(f'Removing liquidity with quantity greater than holdings should fail.')

@given(st.floats(min_value=0.1, max_value=10))
def test_remove_liquidity_unspecified_quantity_specified_nft(price_mult: float):
liquidity = {'HDX': mpf(10000000), 'USD': mpf(1000000), 'DOT': mpf(100000)}
lrna = {'HDX': mpf(1000000), 'USD': mpf(1000000), 'DOT': mpf(1000000)}
initial_state = oamm.OmnipoolState(
tokens={
tkn: {'liquidity': liquidity[tkn], 'LRNA': lrna[tkn]} for tkn in lrna
}
)
tkn = 'DOT'

p = price_mult * initial_state.price(initial_state, tkn, 'LRNA')
s = initial_state.shares[tkn] / 10
position = OmnipoolLiquidityPosition(tkn, p, s, 0, initial_state.unique_id)
init_agent = Agent(nfts={'position': position})

new_state, new_agent = oamm.simulate_remove_liquidity(initial_state, init_agent, tkn_remove=tkn, nft_id='position')
comp_state, comp_agent = oamm.simulate_remove_liquidity(initial_state, init_agent, s, tkn, 'position')
if new_state.liquidity[tkn] != pytest.approx(comp_state.liquidity[tkn], rel=1e-20):
raise AssertionError(f'Remaining liquidity doesn\'t match.')
if new_state.shares[tkn] != pytest.approx(comp_state.shares[tkn], rel=1e-20):
raise AssertionError(f'Remaining shares doesn\'t match.')
if new_state.lrna[tkn] != pytest.approx(comp_state.lrna[tkn], rel=1e-20):
raise AssertionError(f'Remaining LRNA doesn\'t match.')
if new_state.protocol_shares[tkn] != pytest.approx(comp_state.protocol_shares[tkn], rel=1e-20):
raise AssertionError(f'Remaining protocol shares doesn\'t match.')


@given(omnipool_config(token_count=3, withdrawal_fee=False))
Expand Down

0 comments on commit 76bc198

Please sign in to comment.