Skip to content

Commit 3be8d30

Browse files
committed
test: fix tests and cleanup
1 parent d33ce55 commit 3be8d30

File tree

6 files changed

+46
-147
lines changed

6 files changed

+46
-147
lines changed

crates/tap-agent/src/agent/sender_accounts_manager.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,9 @@ mod tests {
620620
},
621621
test::{
622622
actors::{DummyActor, MockSenderAccount, MockSenderAllocation, TestableActor},
623-
create_rav, create_received_receipt, create_sender_accounts_manager, get_config,
624-
get_grpc_url, store_rav, store_receipt, ALLOCATION_ID_0, ALLOCATION_ID_1, INDEXER,
625-
SENDER_2, TAP_EIP712_DOMAIN_SEPARATOR,
623+
create_rav, create_received_receipt, create_sender_accounts_manager, get_grpc_url,
624+
get_sender_account_config, store_rav, store_receipt, ALLOCATION_ID_0, ALLOCATION_ID_1,
625+
INDEXER, SENDER_2, TAP_EIP712_DOMAIN_SEPARATOR,
626626
},
627627
};
628628

@@ -646,7 +646,7 @@ mod tests {
646646
}
647647

648648
async fn create_state(pgpool: PgPool) -> (String, State) {
649-
let config = get_config();
649+
let config = get_sender_account_config();
650650
let senders_to_signers = vec![(SENDER.1, vec![SIGNER.1])].into_iter().collect();
651651
let escrow_accounts = EscrowAccounts::new(HashMap::new(), senders_to_signers);
652652

crates/tap-agent/src/agent/sender_allocation.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,11 +410,6 @@ impl SenderAllocationState {
410410
self.tap_manager.remove_obsolete_receipts().await?;
411411

412412
let signers = signers_trimmed(self.escrow_accounts.clone(), self.sender).await?;
413-
println!(
414-
"Allocation that will look for {:#?} and signer {:#?}",
415-
self.allocation_id.encode_hex(),
416-
signers
417-
);
418413
let res = sqlx::query!(
419414
r#"
420415
SELECT

crates/tap-agent/src/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const TAP_SENDER_TIMEOUT: Duration = Duration::from_secs(30);
7070
const RAV_REQUEST_BUFFER: Duration = Duration::from_secs(60);
7171
const ESCROW_POLLING_INTERVAL: Duration = Duration::from_secs(30);
7272

73-
pub fn get_config() -> &'static SenderAccountConfig {
73+
pub fn get_sender_account_config() -> &'static SenderAccountConfig {
7474
Box::leak(Box::new(SenderAccountConfig {
7575
rav_request_buffer: RAV_REQUEST_BUFFER,
7676
max_amount_willing_to_lose_grt: TRIGGER_VALUE + 100,
@@ -186,7 +186,7 @@ pub async fn create_sender_accounts_manager(
186186
Arc<Notify>,
187187
(ActorRef<SenderAccountsManagerMessage>, JoinHandle<()>),
188188
) {
189-
let config = get_config();
189+
let config = get_sender_account_config();
190190
let (_allocations_tx, allocations_rx) = watch::channel(HashMap::new());
191191
let escrow_subgraph = Box::leak(Box::new(
192192
SubgraphClient::new(

crates/tap-agent/tests/sender_account_manager_test.rs

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ use indexer_tap_agent::{
88
sender_account::SenderAccountMessage, sender_accounts_manager::SenderAccountsManagerMessage,
99
},
1010
test::{
11-
create_received_receipt, create_sender_accounts_manager, store_receipt, ALLOCATION_ID_0,
12-
TAP_EIP712_DOMAIN_SEPARATOR,
11+
create_received_receipt, create_sender_accounts_manager, get_grpc_url, store_receipt,
12+
ALLOCATION_ID_0,
1313
},
1414
};
1515
use ractor::ActorRef;
1616
use reqwest::Url;
1717
use serde_json::json;
1818
use sqlx::PgPool;
19-
use tap_aggregator::server::run_server;
2019
use test_assets::{flush_messages, TAP_SENDER as SENDER, TAP_SIGNER as SIGNER};
2120
use wiremock::{
2221
matchers::{body_string_contains, method},
@@ -25,27 +24,11 @@ use wiremock::{
2524

2625
const TRIGGER_VALUE: u128 = 100;
2726

27+
// This test should ensure the full flow starting from
28+
// sender account manager layer to work, up to closing an allocation
2829
#[sqlx::test(migrations = "../../migrations")]
29-
async fn test_account_manger_to_sender_allocation_closing(pgpool: PgPool) {
30-
let (handle, aggregator_endpoint) = run_server(
31-
0,
32-
SIGNER.0.clone(),
33-
vec![SIGNER.1].into_iter().collect(),
34-
TAP_EIP712_DOMAIN_SEPARATOR.clone(),
35-
100 * 1024,
36-
100 * 1024,
37-
1,
38-
)
39-
.await
40-
.unwrap();
41-
42-
let aggregator_endpoint = Some(
43-
Url::from_str(&("http://".to_owned() + &aggregator_endpoint.to_string()))
44-
.expect("This shouldn't fail"),
45-
);
46-
30+
async fn sender_account_manager_layer_test(pgpool: PgPool) {
4731
let mock_network_subgraph_server: MockServer = MockServer::start().await;
48-
4932
mock_network_subgraph_server
5033
.register(
5134
Mock::given(method("POST"))
@@ -68,19 +51,17 @@ async fn test_account_manger_to_sender_allocation_closing(pgpool: PgPool) {
6851

6952
let mock_escrow_subgraph_server: MockServer = MockServer::start().await;
7053
mock_escrow_subgraph_server
71-
.register(
72-
Mock::given(method("POST"))
73-
//.and(body_string_contains("TapTransactions"))
74-
.respond_with(ResponseTemplate::new(200).set_body_json(json!({ "data": {
75-
"transactions": [],
76-
}
77-
}))),
78-
)
54+
.register(Mock::given(method("POST")).respond_with(
55+
ResponseTemplate::new(200).set_body_json(json!({ "data": {
56+
"transactions": [],
57+
}
58+
})),
59+
))
7960
.await;
8061

8162
let (prefix, notify, (actor, join_handle)) = create_sender_accounts_manager()
8263
.pgpool(pgpool.clone())
83-
.aggregator_endpoint(aggregator_endpoint.expect("should be valid"))
64+
.aggregator_endpoint(Url::from_str(&get_grpc_url().await).unwrap())
8465
.network_subgraph(&mock_network_subgraph_server.uri())
8566
.escrow_subgraph(&mock_escrow_subgraph_server.uri())
8667
.call()
@@ -93,7 +74,7 @@ async fn test_account_manger_to_sender_allocation_closing(pgpool: PgPool) {
9374
.unwrap();
9475
flush_messages(&notify).await;
9576

96-
// // verify if create sender account
77+
// verify if create sender account
9778
let actor_ref =
9879
ActorRef::<SenderAccountMessage>::where_is(format!("{}:{}", prefix.clone(), SENDER.1));
9980
assert!(actor_ref.is_some());
@@ -103,9 +84,7 @@ async fn test_account_manger_to_sender_allocation_closing(pgpool: PgPool) {
10384
.await
10485
.unwrap();
10586

106-
// Create a sender allocation inside sender account
107-
108-
// // we expect it to create a sender allocation
87+
// we expect it to create a sender allocation
10988
actor_ref
11089
.clone()
11190
.unwrap()
@@ -151,9 +130,4 @@ async fn test_account_manger_to_sender_allocation_closing(pgpool: PgPool) {
151130
// safely stop the manager
152131
actor.stop_and_wait(None, None).await.unwrap();
153132
join_handle.await.unwrap();
154-
155-
// Stop the TAP aggregator server.
156-
handle.abort();
157-
// handle.stop().unwrap();
158-
// handle.stopped().await;
159133
}

crates/tap-agent/tests/sender_account_test.rs

Lines changed: 11 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ use std::{collections::HashSet, str::FromStr, sync::atomic::AtomicU32};
55

66
use indexer_tap_agent::{
77
agent::sender_account::SenderAccountMessage,
8-
test::{
9-
create_received_receipt, create_sender_account, store_receipt, TAP_EIP712_DOMAIN_SEPARATOR,
10-
},
8+
test::{create_received_receipt, create_sender_account, get_grpc_url, store_receipt},
119
};
1210
use ractor::concurrency::Duration;
1311
use reqwest::Url;
1412
use serde_json::json;
1513
use sqlx::PgPool;
16-
use tap_aggregator::server::run_server;
1714
use test_assets::{ALLOCATION_ID_0, TAP_SIGNER as SIGNER};
1815
use wiremock::{
1916
matchers::{body_string_contains, method},
@@ -24,51 +21,19 @@ pub static PREFIX_ID: AtomicU32 = AtomicU32::new(0);
2421
const TRIGGER_VALUE: u128 = 500;
2522
const RECEIPT_LIMIT: u64 = 10000;
2623

24+
// This test should ensure the full flow starting from
25+
// sender account layer to work, up to closing an allocation
2726
#[sqlx::test(migrations = "../../migrations")]
28-
async fn test_rav_marked_as_last_closing_sender_allocation(pgpool: PgPool) {
29-
// Start a TAP aggregator server.
30-
let (handle, aggregator_endpoint) = run_server(
31-
0,
32-
SIGNER.0.clone(),
33-
vec![SIGNER.1].into_iter().collect(),
34-
TAP_EIP712_DOMAIN_SEPARATOR.clone(),
35-
100 * 1024,
36-
100 * 1024,
37-
1,
38-
)
39-
.await
40-
.unwrap();
41-
27+
async fn sender_account_layer_test(pgpool: PgPool) {
4228
let mock_server = MockServer::start().await;
43-
44-
let no_allocations_closed_guard = mock_server
45-
.register_as_scoped(
46-
Mock::given(method("POST"))
47-
.and(body_string_contains("ClosedAllocations"))
48-
.respond_with(ResponseTemplate::new(200).set_body_json(json!({ "data": {
49-
"meta": {
50-
"block": {
51-
"number": 1,
52-
"hash": "hash",
53-
"timestamp": 1
54-
}
55-
},
56-
"allocations": []
57-
}
58-
}))),
59-
)
60-
.await;
61-
6229
let mock_escrow_subgraph_server: MockServer = MockServer::start().await;
6330
mock_escrow_subgraph_server
64-
.register(
65-
Mock::given(method("POST"))
66-
// .and(body_string_contains("TapTransactions"))
67-
.respond_with(ResponseTemplate::new(200).set_body_json(json!({ "data": {
68-
"transactions": [],
69-
}
70-
}))),
71-
)
31+
.register(Mock::given(method("POST")).respond_with(
32+
ResponseTemplate::new(200).set_body_json(json!({ "data": {
33+
"transactions": [],
34+
}
35+
})),
36+
))
7237
.await;
7338

7439
let receipt = create_received_receipt(&ALLOCATION_ID_0, &SIGNER.0, 1, 1, TRIGGER_VALUE - 100);
@@ -84,10 +49,7 @@ async fn test_rav_marked_as_last_closing_sender_allocation(pgpool: PgPool) {
8449
.escrow_subgraph_endpoint(&mock_escrow_subgraph_server.uri())
8550
.network_subgraph_endpoint(&mock_server.uri())
8651
.rav_request_receipt_limit(RECEIPT_LIMIT)
87-
.aggregator_endpoint(
88-
Url::from_str(&("http://".to_owned() + &aggregator_endpoint.to_string()))
89-
.expect("This shouldnt fail"),
90-
)
52+
.aggregator_endpoint(Url::from_str(&get_grpc_url().await).unwrap())
9153
.call()
9254
.await;
9355

@@ -99,7 +61,6 @@ async fn test_rav_marked_as_last_closing_sender_allocation(pgpool: PgPool) {
9961
.unwrap();
10062
notify.notified().await;
10163

102-
drop(no_allocations_closed_guard);
10364
mock_server
10465
.register(
10566
Mock::given(method("POST"))
@@ -138,8 +99,4 @@ async fn test_rav_marked_as_last_closing_sender_allocation(pgpool: PgPool) {
13899
.await
139100
.expect("Should not fail to fetch from scalar_tap_ravs");
140101
assert!(!rav_marked_as_last.is_empty());
141-
// Stop the TAP aggregator server.
142-
handle.abort();
143-
// handle.stop().unwrap();
144-
// handle.stopped().await;
145102
}

crates/tap-agent/tests/tap_agent_test.rs

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ use indexer_tap_agent::{
1717
},
1818
sender_allocation::SenderAllocationMessage,
1919
},
20-
test::{actors::TestableActor, create_received_receipt, store_batch_receipts},
20+
test::{actors::TestableActor, create_received_receipt, get_grpc_url, store_batch_receipts},
2121
};
2222
use ractor::{call, concurrency::JoinHandle, Actor, ActorRef};
2323
use reqwest::Url;
2424
use serde_json::json;
2525
use sqlx::PgPool;
26-
use tap_aggregator::server::run_server;
2726
use tap_core::receipt::{state::Checking, ReceiptWithState};
2827
use test_assets::{
2928
assert_while_retry, flush_messages, ALLOCATION_ID_0, ALLOCATION_ID_1, ALLOCATION_ID_2,
@@ -34,41 +33,24 @@ use thegraph_core::alloy::primitives::Address;
3433
use tokio::sync::{watch, Notify};
3534
use wiremock::{matchers::method, Mock, MockServer, ResponseTemplate};
3635

37-
async fn mock_escrow_subgraph_empty_response() -> MockServer {
38-
let mock_ecrow_subgraph_server: MockServer = MockServer::start().await;
39-
let _mock_ecrow_subgraph = mock_ecrow_subgraph_server
40-
.register(Mock::given(method("POST")).respond_with(
41-
ResponseTemplate::new(200).set_body_json(json!({ "data": {
42-
"transactions": [],
43-
}
44-
})),
45-
))
46-
.await;
47-
mock_ecrow_subgraph_server
48-
}
4936
pub async fn start_agent(
5037
pgpool: PgPool,
5138
) -> (
5239
String,
5340
Arc<Notify>,
5441
(ActorRef<SenderAccountsManagerMessage>, JoinHandle<()>),
55-
JoinHandle<()>,
5642
) {
57-
let escrow_subgraph_mock_server = mock_escrow_subgraph_empty_response().await;
43+
let escrow_subgraph_mock_server: MockServer = MockServer::start().await;
44+
escrow_subgraph_mock_server
45+
.register(Mock::given(method("POST")).respond_with(
46+
ResponseTemplate::new(200).set_body_json(json!({ "data": {
47+
"transactions": [],
48+
}
49+
})),
50+
))
51+
.await;
5852

5953
let network_subgraph_mock_server = MockServer::start().await;
60-
// Start a TAP aggregator server.
61-
let (handle_aggregator, aggregator_endpoint) = run_server(
62-
0,
63-
TAP_SIGNER.0.clone(),
64-
vec![TAP_SIGNER.1].into_iter().collect(),
65-
TAP_EIP712_DOMAIN.clone(),
66-
100 * 1024,
67-
100 * 1024,
68-
1,
69-
)
70-
.await
71-
.unwrap();
7254

7355
let (_escrow_tx, escrow_accounts) = watch::channel(EscrowAccounts::new(
7456
ESCROW_ACCOUNTS_BALANCES.clone(),
@@ -78,12 +60,10 @@ pub async fn start_agent(
7860

7961
let (_allocations_tx, indexer_allocations1) = watch::channel(INDEXER_ALLOCATIONS.clone());
8062

81-
let sender_aggregator_endpoints: HashMap<_, _> = vec![(
82-
TAP_SENDER.1,
83-
Url::from_str(&format!("http://{}", aggregator_endpoint)).unwrap(),
84-
)]
85-
.into_iter()
86-
.collect();
63+
let sender_aggregator_endpoints: HashMap<_, _> =
64+
vec![(TAP_SENDER.1, Url::from_str(&get_grpc_url().await).unwrap())]
65+
.into_iter()
66+
.collect();
8767

8868
let http_client = reqwest::Client::new();
8969

@@ -132,25 +112,18 @@ pub async fn start_agent(
132112
prefix: Some(prefix.clone()),
133113
};
134114

135-
// let actorr = SenderAccountsManager::spawn(None, SenderAccountsManager, args)
136-
// .await
137-
// .expect("Failed to start sender accounts manager actor.");
138-
// actorr
139-
140115
let actor = TestableActor::new(SenderAccountsManager);
141116
let notify = actor.notify.clone();
142117
(
143118
prefix,
144119
notify,
145120
Actor::spawn(None, actor, args).await.unwrap(),
146-
handle_aggregator,
147121
)
148122
}
149123

150124
#[sqlx::test(migrations = "../../migrations")]
151125
async fn test_start_tap_agent(pgpool: PgPool) {
152-
let (prefix, notify, (_actor_ref, _handle), _aggregator_handle) =
153-
start_agent(pgpool.clone()).await;
126+
let (prefix, notify, (_actor_ref, _handle)) = start_agent(pgpool.clone()).await;
154127
flush_messages(&notify).await;
155128

156129
// verify if create sender account

0 commit comments

Comments
 (0)