Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: in given out for /custom-direct-quote #423

Merged
merged 14 commits into from
Aug 17, 2024
Merged

Feat: in given out for /custom-direct-quote #423

merged 14 commits into from
Aug 17, 2024

Conversation

p0mvn
Copy link
Member

@p0mvn p0mvn commented Aug 1, 2024

This is a separate pull request from actual implemetation of in given out for /custom-direct-quote introducing e2e tests for exact amount out/in custom quotes.

Test results for TestExactAmountOutDirectCustomQuote:

[nix-shell:~/go/src/github.com/deividaspetraitis/sqs]$ SQS_ENVIRONMENTS=local pytest -s -n 4 tests/test_router_direct_custom_quote_in_giv
en_out.py 
========================================================== test session starts ==========================================================
platform linux -- Python 3.11.9, pytest-8.2.1, pluggy-1.5.0
rootdir: /home/deividas/go/src/github.com/deividaspetraitis/sqs
plugins: xdist-3.6.1
4 workers [360 items]   
.........................................................................................................................................
.........................................................................................................................................
......................................................................................
========================================================== 360 passed in 1.04s ==========================================================
(venv) 

Test results for TestExactAmountInDirectCustomQuote:

[nix-shell:~/go/src/github.com/deividaspetraitis/sqs]$ SQS_ENVIRONMENTS=local pytest -s -n 4 tests/test_router_direct_custom_quote_out_gi
ven_in.py 
========================================================== test session starts ==========================================================
platform linux -- Python 3.11.9, pytest-8.2.1, pluggy-1.5.0
rootdir: /home/deividas/go/src/github.com/deividaspetraitis/sqs
plugins: xdist-3.6.1
4 workers [360 items]   
.........................................................................................................................................
.........................................................................................................................................
......................................................................................
========================================================== 360 passed in 1.11s ==========================================================
(venv) 

PR includes work for refactoring of quotes testing logic in order to reuse existing code to avoid duplication. Failures are not related directly with refactoring and this task and should be dealt seperately.

Test results for TestExactAmountInQuote:

[nix-shell:~/go/src/github.com/deividaspetraitis/sqs]$ SQS_ENVIRONMENTS=local pytest -s -n 4 tests/test_router_quote_out_given_in.py
======================================================== short test summary info ========================================================
FAILED tests/test_router_quote_out_given_in.py::TestExactAmountInQuote::test_usdc_in_high_liq_out[http://localhost:9092-647339ibc/603140E
681973C7A3A33B06B1D377AAD0F6AC376119735CECC04C9184A1AB080] - AssertionError: Error: {"message":"no candidate routes found"}
FAILED tests/test_router_quote_out_given_in.py::TestExactAmountInQuote::test_usdc_in_high_liq_out[http://localhost:9092-7948585ibc/603140
E681973C7A3A33B06B1D377AAD0F6AC376119735CECC04C9184A1AB080] - AssertionError: Error: {"message":"no candidate routes found"}
FAILED tests/test_router_quote_out_given_in.py::TestExactAmountInQuote::test_usdc_in_high_liq_out[http://localhost:9092-50724812ibc/60314
0E681973C7A3A33B06B1D377AAD0F6AC376119735CECC04C9184A1AB080] - AssertionError: Error: {"message":"no candidate routes found"}
FAILED tests/test_router_quote_out_given_in.py::TestExactAmountInQuote::test_usdc_in_high_liq_out[http://localhost:9092-492585221ibc/6031
40E681973C7A3A33B06B1D377AAD0F6AC376119735CECC04C9184A1AB080] - AssertionError: Error: {"message":"no candidate routes found"}
FAILED tests/test_router_quote_out_given_in.py::TestExactAmountInQuote::test_usdc_in_high_liq_out[http://localhost:9092-2243931546ibc/603
140E681973C7A3A33B06B1D377AAD0F6AC376119735CECC04C9184A1AB080] - AssertionError: Error: {"message":"no candidate routes found"}
FAILED tests/test_router_quote_out_given_in.py::TestExactAmountInQuote::test_usdc_in_high_liq_out[http://localhost:9092-86039045326ibc/60
3140E681973C7A3A33B06B1D377AAD0F6AC376119735CECC04C9184A1AB080] - AssertionError: Error: {"message":"no candidate routes found"}
FAILED tests/test_router_quote_out_given_in.py::TestExactAmountInQuote::test_orderbook[http://localhost:9092-token_pair0-1000] - Assertio
nError: Error: difference between numia spot price and sqs spot price is 0.1453799180620686107498066332 which is greater tha...
===================================================== 7 failed, 477 passed in 1.40s =====================================================
(venv) 

Test results for TestExactAmountOutQuote:

[nix-shell:~/go/src/github.com/deividaspetraitis/sqs]$ SQS_ENVIRONMENTS=local pytest -s -n 4 tests/test_router_quote_in_given_out.py 
======================================================== short test summary info ========================================================
FAILED tests/test_router_quote_in_given_out.py::TestExactAmountOutQuote::test_usdc_in_high_liq_in[http://localhost:9092-647339ibc/603140E
681973C7A3A33B06B1D377AAD0F6AC376119735CECC04C9184A1AB080] - AssertionError: Error: {"message":"no candidate routes found"}
FAILED tests/test_router_quote_in_given_out.py::TestExactAmountOutQuote::test_usdc_in_high_liq_in[http://localhost:9092-7948585ibc/603140
E681973C7A3A33B06B1D377AAD0F6AC376119735CECC04C9184A1AB080] - AssertionError: Error: {"message":"no candidate routes found"}
FAILED tests/test_router_quote_in_given_out.py::TestExactAmountOutQuote::test_usdc_in_high_liq_in[http://localhost:9092-50724812ibc/60314
0E681973C7A3A33B06B1D377AAD0F6AC376119735CECC04C9184A1AB080] - AssertionError: Error: {"message":"no candidate routes found"}
FAILED tests/test_router_quote_in_given_out.py::TestExactAmountOutQuote::test_usdc_in_high_liq_in[http://localhost:9092-492585221ibc/6031
40E681973C7A3A33B06B1D377AAD0F6AC376119735CECC04C9184A1AB080] - AssertionError: Error: {"message":"no candidate routes found"}
FAILED tests/test_router_quote_in_given_out.py::TestExactAmountOutQuote::test_usdc_in_high_liq_in[http://localhost:9092-2243931546ibc/603
140E681973C7A3A33B06B1D377AAD0F6AC376119735CECC04C9184A1AB080] - AssertionError: Error: {"message":"no candidate routes found"}
FAILED tests/test_router_quote_in_given_out.py::TestExactAmountOutQuote::test_usdc_in_high_liq_in[http://localhost:9092-86039045326ibc/60
3140E681973C7A3A33B06B1D377AAD0F6AC376119735CECC04C9184A1AB080] - AssertionError: Error: {"message":"no candidate routes found"}
===================================================== 6 failed, 475 passed in 1.24s =====================================================
(venv) 

e2e tests for exact amount out init
Copy link
Contributor

coderabbitai bot commented Aug 1, 2024

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@deividaspetraitis deividaspetraitis self-assigned this Aug 15, 2024
e2e tests for /custom-direct-quote
@deividaspetraitis deividaspetraitis marked this pull request as ready for review August 15, 2024 12:29
Copy link
Member Author

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Had some nits around reducing code duplication, adding deterministic tests and wiring them into synthetic geo suite.

Once addressed, we can merge this!

Comment on lines 74 to 83
start_time = time.time()
response = sqs_service.get_exact_amount_out_custom_direct_quote(token_out, denom_in, pool_id)
elapsed_time_ms = (time.time() - start_time) * 1000

assert response.status_code == expected_status_code, f"Error: {response.text}"
assert expected_latency_upper_bound_ms > elapsed_time_ms, f"Error: latency {elapsed_time_ms} exceeded {expected_latency_upper_bound_ms} ms, denom in {denom_in} and token out {token_out}"

response_json = response.json()

print(response.text)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I keep seeing this and similar boilerplate repeatedly. Is there a chance we could abstract it with a helper?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! It was abstracted in the following method.

Comment on lines 39 to 46
# Compute expected base out quote spot price
# First, get the USD price of each denom, and then divide to get the expected spot price
in_base_usd_quote_price = conftest.get_usd_price_scaled(denom_in)
out_base_usd_quote_price = conftest.get_usd_price_scaled(coin.denom)
expected_in_base_out_quote_price = out_base_usd_quote_price / in_base_usd_quote_price

# Compute expected token out
expected_token_in = int(coin.amount) * expected_in_base_out_quote_price
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to create a helper to abstract this to reduce code duplication?

I think we could reuse that helper here

Similar abstraction could be added for "out given in"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved such logic to calculate_expected_base_out_quote_spot_price methods for given out and given in respectively. 🚀

pool_id = ','.join(map(str, optimal_quote.get_pool_ids()))
denoms_in = ','.join(map(str, optimal_quote.get_token_in_denoms()))

quote = self.run_quote_test(environment_url, token_out, denoms_in, pool_id, EXPECTED_LATENCY_UPPER_BOUND_MS)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see that these tests are dynamic.

However, could we add the hardcoded tests similar to "out given in" still?
https://vscode.dev/github/osmosis-labs/sqs/blob/SQS-303-e2e/tests/test_router_quote_out_given_in.py#L101-L146

Let's then wire all hardcoded test cases into our synthetic monitoring suite here 🙏 :
https://vscode.dev/github/osmosis-labs/sqs/blob/SQS-303-e2e/tests/test_synthetic_geo.py#L18

The synthetic monitoring suite runs every 20 minutes on schedule against every environment. As a result, we need more determinism via hardcoding so that those are not flaky.

Copy link
Collaborator

@deividaspetraitis deividaspetraitis Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Synth tests from now on includes test cases for given in/out quotes as well as for in/out custom direct quotes. 👍 I am not sure I get idea of "all" right, if not, would creating a separate task would make more sense? Given that we quite improved tests state in overall with this PR and by including all the rest tests to synh would be out of the scope of original task and would not provide enough visibility.

Break run_quote_test into smaller individual parts for reusability
Introduce calculate_expected_base_out_quote_spot_price
Add synthetic tests for /quote and /custom-direct-quote
Copy link
Member Author

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks for adding synthetic monitoring tests!

tests/route.py Outdated Show resolved Hide resolved
@p0mvn p0mvn merged commit 4c25823 into SQS-303 Aug 17, 2024
7 checks passed
@p0mvn p0mvn deleted the SQS-303-e2e branch August 17, 2024 06:47
p0mvn added a commit that referenced this pull request Aug 17, 2024
* Feat: in given out for /custom-direct-quote

* Feat: in given out for /custom-direct-quote

Add humanDenoms support

* Feat: in given out for /custom-direct-quote

Update swagger

* Feat: in given out for /custom-direct-quote

Update docs

* Feat: in given out for /custom-direct-quote

Add docs for supported route types

* Feat: in given out for /custom-direct-quote (#423)

* Feat: in given out for /custom-direct-quote

e2e tests for exact amount out init

* fix merge error

* WIP

* WIP

* Feat: in given out for /custom-direct-quote

e2e tests for /custom-direct-quote

* Feat: in given out for /custom-direct-quote

Break run_quote_test into smaller individual parts for reusability

* Feat: in given out for /custom-direct-quote

Introduce calculate_expected_base_out_quote_spot_price

* Feat: in given out for /custom-direct-quote

Add synthetic tests for /quote and /custom-direct-quote

* Update tests/route.py

---------

Co-authored-by: Deividas Petraitis <[email protected]>

* code rabbit

---------

Co-authored-by: Roman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants