Skip to content

Commit

Permalink
try adding e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Nov 4, 2024
1 parent 7c42583 commit 3d9e378
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions tests/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def calculate_expected_base_out_quote_spot_price(denom_out, coin):

return expected_in_base_out_quote_price, expected_token_in, token_in_amount_usdc_value

def run_quote_test(environment_url, token_in, token_out, human_denoms, single_route, expected_latency_upper_bound_ms, expected_status_code=200) -> QuoteExactAmountInResponse:
def run_quote_test(environment_url, token_in, token_out, human_denoms, single_route, expected_latency_upper_bound_ms, expected_status_code=200, simulator_address="", simulation_slippage_tolerance="") -> QuoteExactAmountInResponse:
"""
Runs a test for the /router/quote endpoint with the given input parameters.
Expand All @@ -130,7 +130,7 @@ def run_quote_test(environment_url, token_in, token_out, human_denoms, single_ro
- Latency is under the given bound
"""

service_call = lambda: conftest.SERVICE_MAP[environment_url].get_exact_amount_in_quote(token_in, token_out, human_denoms, single_route)
service_call = lambda: conftest.SERVICE_MAP[environment_url].get_exact_amount_in_quote(token_in, token_out, human_denoms, single_route, simulator_address, simulation_slippage_tolerance)

response = Quote.run_quote_test(service_call, expected_latency_upper_bound_ms, expected_status_code)

Expand Down
5 changes: 4 additions & 1 deletion tests/quote_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ def __init__(self, pools, out_amount, in_amount, **kwargs):
# QuoteExactAmountInResponse represents the response format
# of the /router/quote endpoint for Exact Amount In Quote.
class QuoteExactAmountInResponse:
def __init__(self, amount_in, amount_out, route, effective_fee, price_impact, in_base_out_quote_spot_price):
def __init__(self, amount_in, amount_out, route, effective_fee, price_impact, in_base_out_quote_spot_price, price_info):
self.amount_in = Coin(**amount_in)
self.amount_out = int(amount_out)
self.route = [Route(**r) for r in route]
self.effective_fee = Decimal(effective_fee)
self.price_impact = Decimal(price_impact)
self.in_base_out_quote_spot_price = Decimal(in_base_out_quote_spot_price)

if price_info:
self.price_info = price_info

def get_pool_ids(self):
pool_ids = []
for route in self.route:
Expand Down
4 changes: 3 additions & 1 deletion tests/sqs_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_candidate_routes(self, denom_in, denom_out, human_denoms="false"):
# Send the GET request
return requests.get(self.url + ROUTER_ROUTES_URL, params=params, headers=self.headers)

def get_exact_amount_in_quote(self, denom_in, denom_out, human_denoms="false", singleRoute="false"):
def get_exact_amount_in_quote(self, denom_in, denom_out, human_denoms="false", singleRoute="false", simulator_address="", simulation_slippage_tolerance=""):
"""
Fetches exact amount in quote from the specified endpoint and returns it.
Expand All @@ -108,6 +108,8 @@ def get_exact_amount_in_quote(self, denom_in, denom_out, human_denoms="false", s
"tokenOutDenom": denom_out,
"humanDenoms": human_denoms,
"singleRoute": singleRoute,
"simulatorAddress": simulator_address,
"simulationSlippageTolerance": simulation_slippage_tolerance,
}

# Send the GET request
Expand Down
21 changes: 20 additions & 1 deletion tests/test_router_quote_out_given_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def test_usdc_in_high_liq_out(self, environment_url, coin_obj):

# Set the token in coin
token_in_coin = amount_str + USDC

# Run the quote test
quote = ExactAmountInQuote.run_quote_test(environment_url, token_in_coin, denom_out, False, False, EXPECTED_LATENCY_UPPER_BOUND_MS)

Expand Down Expand Up @@ -287,3 +286,23 @@ def test_orderbook(self, environment_url, amount, token_pair):
amount_out_diff = relative_error(expected_amount_out, amount_out)
assert amount_out_diff < error_tolerance, \
f"Error: difference between calculated and actual amount out is {amount_out_diff} which is greater than {error_tolerance}"


def test_simulation_slippage_tolerance(self, environment_url):
"""
This test validates that the simulation slippage tolerance is working as expected.
"""
token_in_coin = "1000000uosmo"
denom_out = "uion"

# Fillbot address and slippage tolerance
# We choose fillbot address because we expect it to have at least one OSMO.
fillbot_address = "osmo10s3vlv40h64qs2p98yal9w0tpm4r30uyg6ceux"
simulation_slippage_tolerance = 1.2

# Run the quote test
quote = ExactAmountInQuote.run_quote_test(environment_url, token_in_coin, denom_out, False, False, EXPECTED_LATENCY_UPPER_BOUND_MS, fillbot_address, simulation_slippage_tolerance)

# Validate that the price info is set to something
assert quote is not None
assert quote.price_info is not None

0 comments on commit 3d9e378

Please sign in to comment.