Skip to content

Commit 2ba1960

Browse files
committed
test: update create_manager() to receive list of initial accounts
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 342fad5 commit 2ba1960

File tree

3 files changed

+53
-17
lines changed

3 files changed

+53
-17
lines changed

crates/tap-agent/src/test.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use crate::{
4444
},
4545
sender_accounts_manager::{
4646
AllocationId, SenderAccountsManager, SenderAccountsManagerArgs,
47-
SenderAccountsManagerMessage,
47+
SenderAccountsManagerMessage, SenderType,
4848
},
4949
},
5050
tap::{
@@ -178,6 +178,7 @@ pub async fn create_sender_account(
178178
allocation_ids: HashSet::new(),
179179
prefix: Some(prefix.clone()),
180180
retry_interval: RETRY_DURATION,
181+
sender_type: SenderType::Legacy,
181182
};
182183

183184
let actor = TestableActor::new(SenderAccount);
@@ -198,6 +199,8 @@ pub async fn create_sender_accounts_manager(
198199
pgpool: PgPool,
199200
network_subgraph: Option<&str>,
200201
escrow_subgraph: Option<&str>,
202+
initial_escrow_accounts_v1: Option<EscrowAccounts>,
203+
initial_escrow_accounts_v2: Option<EscrowAccounts>,
201204
) -> (
202205
String,
203206
Arc<Notify>,
@@ -222,21 +225,27 @@ pub async fn create_sender_accounts_manager(
222225
.await,
223226
));
224227
let (escrow_accounts_tx, escrow_accounts_rx) = watch::channel(EscrowAccounts::default());
225-
escrow_accounts_tx
226-
.send(EscrowAccounts::new(
227-
HashMap::from([(SENDER.1, U256::from(ESCROW_VALUE))]),
228-
HashMap::from([(SENDER.1, vec![SIGNER.1])]),
229-
))
230-
.expect("Failed to update escrow_accounts channel");
228+
if let Some(escrow_acccounts) = initial_escrow_accounts_v1 {
229+
escrow_accounts_tx
230+
.send(escrow_acccounts)
231+
.expect("Failed to update escrow_accounts channel");
232+
}
233+
234+
let (escrow_accounts_tx_v2, escrow_accounts_rx_v2) = watch::channel(EscrowAccounts::default());
235+
if let Some(escrow_acccounts) = initial_escrow_accounts_v2 {
236+
escrow_accounts_tx_v2
237+
.send(escrow_acccounts)
238+
.expect("Failed to update escrow_accounts channel");
239+
}
231240

232241
let prefix = generate_random_prefix();
233242
let args = SenderAccountsManagerArgs {
234243
config,
235244
domain_separator: TAP_EIP712_DOMAIN_SEPARATOR.clone(),
236245
pgpool,
237246
indexer_allocations: allocations_rx,
238-
escrow_accounts_v1: escrow_accounts_rx.clone(),
239-
escrow_accounts_v2: escrow_accounts_rx,
247+
escrow_accounts_v1: escrow_accounts_rx,
248+
escrow_accounts_v2: escrow_accounts_rx_v2,
240249
escrow_subgraph,
241250
network_subgraph,
242251
sender_aggregator_endpoints: HashMap::from([

crates/tap-agent/tests/sender_account_manager_test.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use std::collections::HashSet;
4+
use std::collections::{HashMap, HashSet};
55

6+
use indexer_monitor::EscrowAccounts;
67
use indexer_tap_agent::{
78
agent::{
89
sender_account::SenderAccountMessage,
@@ -11,12 +12,14 @@ use indexer_tap_agent::{
1112
},
1213
test::{
1314
create_received_receipt, create_sender_accounts_manager, store_receipt, ALLOCATION_ID_0,
15+
ESCROW_VALUE,
1416
},
1517
};
1618
use ractor::{ActorRef, ActorStatus};
1719
use serde_json::json;
1820
use sqlx::PgPool;
1921
use test_assets::{assert_while_retry, flush_messages, TAP_SENDER as SENDER, TAP_SIGNER as SIGNER};
22+
use thegraph_core::alloy::primitives::U256;
2023
use wiremock::{
2124
matchers::{body_string_contains, method},
2225
Mock, MockServer, ResponseTemplate,
@@ -26,7 +29,7 @@ const TRIGGER_VALUE: u128 = 100;
2629

2730
// This test should ensure the full flow starting from
2831
// sender account manager layer to work, up to closing an allocation
29-
#[sqlx::test(migrations = "../../migrations")]
32+
#[test_log::test(sqlx::test(migrations = "../../migrations"))]
3033
async fn sender_account_manager_layer_test(pgpool: PgPool) {
3134
let mock_network_subgraph_server: MockServer = MockServer::start().await;
3235
mock_network_subgraph_server
@@ -63,6 +66,10 @@ async fn sender_account_manager_layer_test(pgpool: PgPool) {
6366
.pgpool(pgpool.clone())
6467
.network_subgraph(&mock_network_subgraph_server.uri())
6568
.escrow_subgraph(&mock_escrow_subgraph_server.uri())
69+
.initial_escrow_accounts_v1(EscrowAccounts::new(
70+
HashMap::from([(SENDER.1, U256::from(ESCROW_VALUE))]),
71+
HashMap::from([(SENDER.1, vec![SIGNER.1])]),
72+
))
6673
.call()
6774
.await;
6875

@@ -72,6 +79,14 @@ async fn sender_account_manager_layer_test(pgpool: PgPool) {
7279
))
7380
.unwrap();
7481
flush_messages(&notify).await;
82+
assert_while_retry!({
83+
ActorRef::<SenderAccountMessage>::where_is(format!(
84+
"{}:legacy:{}",
85+
prefix.clone(),
86+
SENDER.1
87+
))
88+
.is_none()
89+
});
7590

7691
// verify if create sender account
7792
let sender_account_ref = ActorRef::<SenderAccountMessage>::where_is(format!(
@@ -134,12 +149,13 @@ async fn sender_account_manager_layer_test(pgpool: PgPool) {
134149

135150
sender_account_ref.unwrap().wait(None).await.unwrap();
136151
// verify if it gets removed
137-
let actor_ref = ActorRef::<SenderAccountMessage>::where_is(format!("{}:{}", prefix, SENDER.1));
152+
let actor_ref =
153+
ActorRef::<SenderAccountMessage>::where_is(format!("{}:legacy:{}", prefix, SENDER.1));
138154
assert!(actor_ref.is_none());
139155

140156
let rav_marked_as_last = sqlx::query!(
141157
r#"
142-
SELECT * FROM scalar_tap_ravs WHERE last;
158+
SELECT * FROM scalar_tap_ravs;
143159
"#,
144160
)
145161
.fetch_all(&pgpool)

crates/tap-agent/tests/tap_agent_test.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub async fn start_agent(
101101
pgpool,
102102
indexer_allocations: indexer_allocations1,
103103
escrow_accounts_v1: escrow_accounts.clone(),
104-
escrow_accounts_v2: escrow_accounts,
104+
escrow_accounts_v2: watch::channel(EscrowAccounts::default()).1,
105105
escrow_subgraph,
106106
network_subgraph,
107107
sender_aggregator_endpoints: sender_aggregator_endpoints.clone(),
@@ -119,9 +119,11 @@ async fn test_start_tap_agent(pgpool: PgPool) {
119119
flush_messages(&notify).await;
120120

121121
// verify if create sender account
122-
let actor_ref = ActorRef::<SenderAccountMessage>::where_is(format!("legacy:{}", TAP_SENDER.1));
123-
124-
assert!(actor_ref.is_some());
122+
assert_while_retry!(ActorRef::<SenderAccountMessage>::where_is(format!(
123+
"legacy:{}",
124+
TAP_SENDER.1
125+
))
126+
.is_none());
125127

126128
// Add batch receits to the database.
127129
const AMOUNT_OF_RECEIPTS: u64 = 3000;
@@ -141,6 +143,15 @@ async fn test_start_tap_agent(pgpool: PgPool) {
141143
}
142144
let res = store_batch_receipts(&pgpool, receipts).await;
143145
assert!(res.is_ok());
146+
147+
assert_while_retry!({
148+
ActorRef::<SenderAllocationMessage>::where_is(format!(
149+
"{}:{}",
150+
TAP_SENDER.1, ALLOCATION_ID_0,
151+
))
152+
.is_none()
153+
});
154+
144155
let sender_allocation_ref = ActorRef::<SenderAllocationMessage>::where_is(format!(
145156
"{}:{}",
146157
TAP_SENDER.1, ALLOCATION_ID_0,

0 commit comments

Comments
 (0)