-
Notifications
You must be signed in to change notification settings - Fork 20
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
Enhance Test Coverage for Receipt Insertion, Batch Processing, and Sender Accounts #572
base: main
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 12835420725Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@carlosvdr can you squash/fix the commit history, please 🙏
e3ef764
to
025024c
Compare
@carlosvdr , approving just to remove the block 👍 |
async fn mock_escrow_subgraph_empty_response() -> (MockServer, MockGuard) { | ||
let mock_ecrow_subgraph_server: MockServer = MockServer::start().await; | ||
let _mock_ecrow_subgraph = mock_ecrow_subgraph_server | ||
.register_as_scoped( | ||
Mock::given(method("POST")) | ||
.and(body_string_contains("TapTransactions")) | ||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({ "data": { | ||
"transactions": [], | ||
} | ||
}))), | ||
) | ||
.await; | ||
(mock_ecrow_subgraph_server, _mock_ecrow_subgraph) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you consider implementing this in a "lazy" way since it could be called by multiple tests in parallel and is deterministic? (https://stackoverflow.com/a/59614532/24786256)
async fn mock_escrow_subgraph_empty_response() -> (MockServer, MockGuard) { | ||
let mock_ecrow_subgraph_server: MockServer = MockServer::start().await; | ||
let _mock_ecrow_subgraph = mock_ecrow_subgraph_server | ||
.register_as_scoped( | ||
Mock::given(method("POST")) | ||
//.and(body_string_contains("TapTransactions")) | ||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({ "data": { | ||
"transactions": [], | ||
} | ||
}))), | ||
) | ||
.await; | ||
(mock_ecrow_subgraph_server, _mock_ecrow_subgraph) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same thought about "lazy static" here as well: https://stackoverflow.com/a/59614532/24786256
lazy_static! { | ||
static ref MOCK_ESCROW_SUBGRAPH: Mutex<Option<Arc<(MockServer, MockGuard)>>> = | ||
Mutex::new(None); | ||
static ref MOCK_EMPTY_ESCROW_SUBGRAPH: Mutex<Option<Arc<(MockServer, MockGuard)>>> = | ||
Mutex::new(None); | ||
} | ||
|
||
async fn mock_escrow_subgraph() -> Arc<(MockServer, MockGuard)> { | ||
let mut guard = MOCK_ESCROW_SUBGRAPH.lock().unwrap(); | ||
if let Some(server) = guard.as_ref() { | ||
server.clone() | ||
} else { | ||
let mock_ecrow_subgraph_server = MockServer::start().await; | ||
let mock_ecrow_subgraph = mock_ecrow_subgraph_server | ||
.register_as_scoped( | ||
Mock::given(method("POST")) | ||
.and(body_string_contains("TapTransactions")) | ||
.respond_with(ResponseTemplate::new(200).set_body_json(json!({ "data": { | ||
"transactions": [{ | ||
"id": "0x00224ee6ad4ae77b817b4e509dc29d644da9004ad0c44005a7f34481d421256409000000" | ||
}], | ||
} | ||
"transactions": [{ | ||
"id": "0x00224ee6ad4ae77b817b4e509dc29d644da9004ad0c44005a7f34481d421256409000000" | ||
}], | ||
} | ||
}))), | ||
) | ||
.await; | ||
(mock_ecrow_subgraph_server, _mock_ecrow_subgraph) | ||
let server = Arc::new((mock_ecrow_subgraph_server, mock_ecrow_subgraph)); | ||
*guard = Some(server.clone()); | ||
server | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@carlosvdr this is on the right track but I suggest looking at how others use OnceCell
instead of the Mutex
. I don't have time to try this myself right now, but I would expect things to look more like:
use lazy_static::lazy_static;
use tokio::sync::{OnceCell, Mutex};
use std::sync::Arc;
use wiremock::{Mock, MockServer, MockGuard, ResponseTemplate};
use wiremock::matchers::{method, body_string_contains};
use serde_json::json;
lazy_static! {
static ref MOCK_ESCROW_SUBGRAPH: OnceCell<Arc<(MockServer, MockGuard)>> = OnceCell::new();
}
async fn mock_escrow_subgraph() -> Arc<(MockServer, MockGuard)> {
MOCK_ESCROW_SUBGRAPH
.get_or_try_init(async {
let mock_server = MockServer::start().await;
let mock_guard = mock_server
.register_as_scoped(
Mock::given(method("POST"))
.and(body_string_contains("TapTransactions"))
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
"data": {
"transactions": [{
"id": "0x00224ee6ad4ae77b817b4e509dc29d644da9004ad0c44005a7f34481d421256409000000"
}]
}
}))),
)
.await;
Ok::<_, wiremock::Error>(Arc::new((mock_server, mock_guard)))
})
.await
.unwrap()
.clone()
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks let me take a look into this
8140179
to
7930988
Compare
This new tests cover are here to enhance the testing experience and help ensure tap V2 wont affect the processes in a "bigger picture"
As well as added more test types around receiving receipts. For this a new method was added regarding batch inserts for receipts into the DB, trying to be have a more accurate representation of how TAP works on a day to day basis.
Regarding the tests on the "bigger picture" , tests for several layers were added.
Such as a full process from sender account all the way from starting it, creating a sender allocation up to the point of marking allocation as last for redeeming.
Another test added from the sender account manager layer which tries to do the same process as the previous layer but starting from the manager.
And finally a test for the full Tap Agent and simulate as closely as possible the full process of it