Skip to content

Commit

Permalink
test: added oncecell
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosvdr committed Jan 17, 2025
1 parent 9c9b85d commit 014bf64
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions crates/tap-agent/src/agent/sender_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ pub mod tests {
};
use tokio::sync::{
watch::{self, Sender},
Notify,
Notify, OnceCell,
};
use wiremock::{
matchers::{body_string_contains, method},
Expand Down Expand Up @@ -1133,35 +1133,36 @@ pub mod tests {
const RETRY_DURATION: Duration = Duration::from_millis(1000);

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);
static ref MOCK_ESCROW_SUBGRAPH: OnceCell<Arc<(MockServer, MockGuard)>> = OnceCell::new();
}

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
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"
}],
}
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
"data": {
"transactions": [{
"id": "0x00224ee6ad4ae77b817b4e509dc29d644da9004ad0c44005a7f34481d421256409000000"
}]
}
}))),
)
.await;
let server = Arc::new((mock_ecrow_subgraph_server, mock_ecrow_subgraph));
*guard = Some(server.clone());
server
}
}

Ok::<_, anyhow::Error>(Arc::new((mock_server, mock_guard)))
})
.await
.unwrap()
.clone()
}


async fn mock_escrow_subgraph_empty_response() -> (MockServer, MockGuard) {
let mock_ecrow_subgraph_server: MockServer = MockServer::start().await;
Expand Down

0 comments on commit 014bf64

Please sign in to comment.