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: add routes test (semi-integration test) #28

Merged
merged 1 commit into from
Apr 10, 2024
Merged

Conversation

giladchase
Copy link
Collaborator

@giladchase giladchase commented Apr 4, 2024

  • tests that routes behave the way we expect, shouldn't have too much logic here, just test status codes and return values. Proper integration/flow tests will be in their own testing file.
  • add tower dependency that axum uses in order to simulate an HTTP request via the oneshot call: this simulates the HTTP request without having to spin up an actual server and perform IO.
  • Currently add_transaction test is identical to the one in gateway_test.rs, but they'll diverge once real logic kicks in. At that point the routes test will only test for success codes in basic scenarios.
  • is_alive is currently just a dummy test, since it isn't implemented yet.

This change is Reviewable

Copy link
Contributor

@MohammadNassar1 MohammadNassar1 left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 3 files at r1, all commit messages.
Reviewable status: 2 of 3 files reviewed, 3 unresolved discussions (waiting on @elintul and @giladchase)

a discussion (no related file):
Nice!

  1. Why these tests are not part of gateway_test?
  2. Are you planning to remove the identical test from gateway_test?


crates/gateway/tests/routing_test.rs line 17 at r1 (raw file):

    "DEPLOY_ACCOUNT"
)]
#[case("./src/json_files_for_testing/invoke_v3.json", "INVOKE")]

Why not "INVOKE_FUNCTION"?
This should be the expected type.

Code quote:

"INVOKE"

crates/gateway/tests/routing_test.rs line 22 at r1 (raw file):

    let tx_json = fs::read_to_string(json_file_path).unwrap();
    let request = Request::post("/add_transaction")
        .header("content-type", "application/json")

Could you explain why you added this header?

Code quote:

.header("content-type", "application/json")

Copy link
Collaborator Author

@giladchase giladchase left a comment

Choose a reason for hiding this comment

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

Reviewable status: 2 of 3 files reviewed, 3 unresolved discussions (waiting on @elintul and @MohammadNassar1)


crates/gateway/tests/routing_test.rs line 17 at r1 (raw file):

Previously, MohammadNassar1 (mohammad-starkware) wrote…

Why not "INVOKE_FUNCTION"?
This should be the expected type.

Just a dummy value for now, until we implement add_transaction properly, it will be deleted very soon.


crates/gateway/tests/routing_test.rs line 22 at r1 (raw file):

Previously, MohammadNassar1 (mohammad-starkware) wrote…

Could you explain why you added this header?

Looks like axum needs this explicitly in order to accept the JSON payload of the POST request.

Without this, the server hits 415, which means that it is refusing the request, probably being pedantic and not wanting to assume the string payload is a JSON without being told.

Copy link
Collaborator Author

@giladchase giladchase left a comment

Choose a reason for hiding this comment

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

Reviewable status: 2 of 3 files reviewed, 3 unresolved discussions (waiting on @elintul and @MohammadNassar1)

a discussion (no related file):

Previously, MohammadNassar1 (mohammad-starkware) wrote…

Nice!

  1. Why these tests are not part of gateway_test?
  2. Are you planning to remove the identical test from gateway_test?
  1. Cause it's an integration test of sorts. Tests in tests/ directory are compiled in separate crates, which simulates how our users will interact with our API.
  2. Nope, the add_transaction test in gateway_test will evolve into a real (probably multiple) tests that test add_transaction functionality; and the routing test here will evolve into a very basic e2e test, that just sends a tx and checks that it was processed via add_transaction. Maybe once we have a proper flow test it will be removed, but for now its a sanity check that our gateway actually works.

@giladchase giladchase force-pushed the gilad/refactor-gateway branch from 9aa64ae to c55bea7 Compare April 8, 2024 10:46
@codecov-commenter
Copy link

codecov-commenter commented Apr 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 48.48%. Comparing base (c7179ab) to head (0763a15).

Additional details and impacted files
@@             Coverage Diff             @@
##             main      #28       +/-   ##
===========================================
+ Coverage   34.84%   48.48%   +13.63%     
===========================================
  Files           5        5               
  Lines          66       66               
  Branches       66       66               
===========================================
+ Hits           23       32        +9     
+ Misses         43       34        -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@MohammadNassar1 MohammadNassar1 left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: 3 of 4 files reviewed, all discussions resolved (waiting on @elintul)

@giladchase giladchase force-pushed the gilad/refactor-gateway branch 2 times, most recently from 0c80811 to 0ddc1ae Compare April 9, 2024 14:07
Base automatically changed from gilad/refactor-gateway to main April 10, 2024 06:41
- tests that routes behave the way we expect, shouldn't have too much
  logic here, just test status codes and return values.
  Proper integration/flow tests will be in their own testing file.
- add `tower` dependency that `axum` uses in order to simulate an HTTP
  request via the `oneshot` call: this simulates the HTTP request
  without having to spin up an actual server and perform IO.
- Currently add_transaction test is identical to the one in
  gateway_test.rs, but they'll diverge once real logic kicks in. At that
  point the routes test will only test for success codes in basic
  scenarios.
- is_alive is currently just a dummy test, since it isn't implemented
  yet.
Copy link
Collaborator Author

@giladchase giladchase left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 3 files at r1, 3 of 3 files at r3, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @elintul)

@giladchase giladchase merged commit b595276 into main Apr 10, 2024
8 checks passed
@giladchase giladchase deleted the gilad/test-axum branch April 10, 2024 08:00
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.

3 participants