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

Gatewayd integration test suite proposal #1702

Merged
merged 5 commits into from
Mar 22, 2023

Conversation

okjodom
Copy link
Contributor

@okjodom okjodom commented Feb 17, 2023

Proposes an integration test suite for gatewayd.

To start with, tests are only run with mocks of dependencies like ILnRpcClient and IFederationApi.

In it's full extent, this proposal would involve sharing the following from fedimint-testing crate:

  • fixtures for setting up fake bitcoin tests
  • fixtures for setting up real bitcoin tests
  • fixtures for setting up fake lightning tests
  • fixtures for setting up real lightning tests
  • fixtures for setting up fake fedimintd with modules
  • fixtures for setting up real fedimintd with modules

Gateway would then own it's own integration tests where it uses real or fake fixtures in validating it's functionality in serving one or more federations

towards #742

@okjodom okjodom changed the title Propose: Gatewayd functional test suite Gatewayd functional test suite proposal Feb 17, 2023
@okjodom okjodom marked this pull request as ready for review February 17, 2023 08:04
@codecov-commenter
Copy link

codecov-commenter commented Feb 17, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.12 ⚠️

Comparison is base (0b89f34) 62.95% compared to head (08fc244) 62.84%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1702      +/-   ##
==========================================
- Coverage   62.95%   62.84%   -0.12%     
==========================================
  Files         137      137              
  Lines       26517    26518       +1     
==========================================
- Hits        16694    16664      -30     
- Misses       9823     9854      +31     
Impacted Files Coverage Δ
fedimint-core/src/config.rs 67.30% <100.00%> (+0.10%) ⬆️

... and 10 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@jkitman
Copy link
Contributor

jkitman commented Feb 17, 2023

Why would the real tests and mock tests be separated if we can hide the implementation behind an interface?

I think similar to how we do in integrationtests it can be useful to run both with and without mocks depending on the level of testing required, using an env flag.

@okjodom
Copy link
Contributor Author

okjodom commented Feb 17, 2023

Why would the real tests and mock tests be separated if we can hide the implementation behind an interface?

Spinning up a real federation with bitcoind and other integration artifacts might too heavy for the gateway test suite. However, we may want to:

  • have functional test spec that uses a mock of the federation and mocks of lightning
  • have an independent test suite for any real lightning extensions we build

integrationtest would have simpler tests for the gateway, but might ochestrate its real gateway with various implementations of lightning

@okjodom okjodom marked this pull request as draft February 18, 2023 04:02
@okjodom
Copy link
Contributor Author

okjodom commented Feb 19, 2023

Why would the real tests and mock tests be separated if we can hide the implementation behind an interface?

Spinning up a real federation with bitcoind and other integration artifacts might too heavy for the gateway test suite.

Not true! After #1717 , I see how we can move all gateway integration tests to this framework. We'd just need to share he fixture for spinning up real bitcoind, lightning, and federations

@okjodom okjodom changed the title Gatewayd functional test suite proposal Gatewayd integration test suite proposal Feb 20, 2023
@okjodom okjodom force-pushed the gatewayd-tests branch 2 times, most recently from e98cd4a to 914e09e Compare February 27, 2023 22:41
Copy link
Contributor

@mxz42 mxz42 left a comment

Choose a reason for hiding this comment

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

just some comments; I know it's WIP, but just wanted to know what's going on.
I probably need to have a closer look at the gateway API myself to get some context.

gateway/ln-gateway/tests/authentication_tests.rs Outdated Show resolved Hide resolved
)
.await?
.status(),
401
Copy link
Contributor

Choose a reason for hiding this comment

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

is that a copy paste error? the returned status should not be 401, right?
edit: I see, it's a asser_ne. maybe change this to an assert_eq and expect the status code 200 that is returned when the call was successful (I assume).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

assert_eq(200) tests for success on authentication, AND success in whatever authenticated api we are currently checking. Since we cannot be sure that our API succeeds after successful auth, we did not assert a 200.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same discussion, months apart :) #1023 (comment)

gateway/ln-gateway/tests/integration_tests.rs Show resolved Hide resolved
integrationtests/tests/tests.rs Outdated Show resolved Hide resolved
integrationtests/tests/tests.rs Outdated Show resolved Hide resolved
Comment on lines 303 to 322
// assert cannot withdraw amount greater than the available balance
let outcome = parse_response::<TransactionId>(
rpc_ref
.withdraw(
gw_password.clone(),
WithdrawPayload {
federation_id: fid.clone(),
amount: bitcoin::Amount::from_sat(amount_sats.clone() + 1),
address: bitcoin.get_new_address().await,
},
)
.await
.map_err(|e| anyhow::anyhow!(e))
.unwrap(),
)
.await
.unwrap();

assert_eq!(outcome.0, 200);
assert!(outcome.1.is_some());
Copy link
Contributor

Choose a reason for hiding this comment

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

hm, I would expect that we get some error or similar that the amount we want to withdrawal is too big?
Basically, these assert make sure that the call to withdraw was successful and then we ensure below by calling get_balance that nothing was withdrawn, right?

I'm not sure if we can design the API slightly different, so that the call to withdraw already lets us know that it's not possible to withdraw that amount (I'm missing a bit of context here. didn't dig into it).

edit: ok, I think I fundamentally do not understand something. We do a withdraw that is too large here and we get back a Some(TransactionId) in outcome.1. In line 367 we withdraw a permitted amount (everything that the gateway has) and we assert that outcome.1.is_none(), so no TransactionId?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Revisiting these proposals.
In order to give the best attention to each test case, I will first propose the test suite and then fill in the test cases one-by-one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, so I deferred the test implementation themselves. Following up with those. With consideration for the review above

@justinmoon
Copy link
Contributor

What is our strategy for merging this?

Perhaps it would be best to just move the existing tests to the new crate, and then add new tests in follow-up commits?

@okjodom
Copy link
Contributor Author

okjodom commented Mar 16, 2023

Perhaps it would be best to just move the existing tests to the new crate, and then add new tests in follow-up commits?

How about the reverse strategy: add new non-overlapping tests so we have more coverage, and then move the existing tests over? IMO this is preferable because the existing tests don't exercise the public API surface of gatewayd. Moving them over will include a considerable rewrite.

@justinmoon
Copy link
Contributor

How about the reverse strategy: add new non-overlapping tests so we have more coverage, and then move the existing tests over? IMO this is preferable because the existing tests don't exercise the public API surface of gatewayd. Moving them over will include a considerable rewrite.

Works for me!

@okjodom okjodom marked this pull request as ready for review March 17, 2023 20:16
Copy link
Contributor

@jkitman jkitman left a comment

Choose a reason for hiding this comment

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

Looks good as a first step. I'd aim for an optional mock / real mode like with our existing tests.

Often you find bugs in real mode you wouldn't with mocks, but you don't want to run it while developing.

@justinmoon justinmoon merged commit 1901a9d into fedimint:master Mar 22, 2023
@okjodom okjodom deleted the gatewayd-tests branch June 9, 2023 20:34
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.

None yet

5 participants