Skip to content

Commit 662266a

Browse files
committed
fix: tests that fixtures werent available
1 parent 6aa7024 commit 662266a

File tree

5 files changed

+151
-81
lines changed

5 files changed

+151
-81
lines changed

crates/monitor/src/client/monitor.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ pub async fn check_deployment_status(
6262

6363
#[cfg(test)]
6464
mod tests {
65-
use axum::error_handling::future;
6665
use reqwest::Url;
6766
use serde_json::json;
6867
use thegraph_core::deployment_id;

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

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,20 +1701,22 @@ pub mod tests {
17011701
.as_nanos() as u64
17021702
}
17031703

1704-
#[sqlx::test(migrations = "../../migrations")]
1705-
async fn test_update_receipt_fees_no_rav(pgpool: PgPool) {
1706-
let (sender_account, _, prefix, _) = create_sender_account().pgpool(pgpool).call().await;
1707-
1704+
#[rstest::rstest]
1705+
#[tokio::test]
1706+
async fn test_update_receipt_fees_no_rav(
1707+
#[future(awt)] basic_sender_account: TestSenderAccount,
1708+
) {
17081709
// create a fake sender allocation
17091710
let (triggered_rav_request, _, _) = create_mock_sender_allocation(
1710-
prefix,
1711+
basic_sender_account.prefix,
17111712
SENDER.1,
17121713
ALLOCATION_ID_0,
1713-
sender_account.clone(),
1714+
basic_sender_account.sender_account.clone(),
17141715
)
17151716
.await;
17161717

1717-
sender_account
1718+
basic_sender_account
1719+
.sender_account
17181720
.cast(SenderAccountMessage::UpdateReceiptFees(
17191721
ALLOCATION_ID_0,
17201722
ReceiptFees::NewReceipt(TRIGGER_VALUE - 1, get_current_timestamp_u64_ns()),
@@ -1727,40 +1729,42 @@ pub mod tests {
17271729
assert_not_triggered!(&triggered_rav_request);
17281730
}
17291731

1730-
#[sqlx::test(migrations = "../../migrations")]
1731-
async fn test_update_receipt_fees_trigger_rav(pgpool: PgPool) {
1732-
let (sender_account, notify, prefix, _) =
1733-
create_sender_account().pgpool(pgpool).call().await;
1734-
1732+
#[rstest::rstest]
1733+
#[tokio::test]
1734+
async fn test_update_receipt_fees_trigger_rav(
1735+
#[future(awt)] basic_sender_account: TestSenderAccount,
1736+
) {
17351737
// create a fake sender allocation
17361738
let (triggered_rav_request, _, _) = create_mock_sender_allocation(
1737-
prefix,
1739+
basic_sender_account.prefix,
17381740
SENDER.1,
17391741
ALLOCATION_ID_0,
1740-
sender_account.clone(),
1742+
basic_sender_account.sender_account.clone(),
17411743
)
17421744
.await;
17431745

1744-
sender_account
1746+
basic_sender_account
1747+
.sender_account
17451748
.cast(SenderAccountMessage::UpdateReceiptFees(
17461749
ALLOCATION_ID_0,
17471750
ReceiptFees::NewReceipt(TRIGGER_VALUE, get_current_timestamp_u64_ns()),
17481751
))
17491752
.unwrap();
17501753

1751-
flush_messages(&notify).await;
1754+
flush_messages(&basic_sender_account.notify).await;
17521755
assert_not_triggered!(&triggered_rav_request);
17531756

17541757
// wait for it to be outside buffer
17551758
tokio::time::sleep(BUFFER_DURATION).await;
17561759

1757-
sender_account
1760+
basic_sender_account
1761+
.sender_account
17581762
.cast(SenderAccountMessage::UpdateReceiptFees(
17591763
ALLOCATION_ID_0,
17601764
ReceiptFees::Retry,
17611765
))
17621766
.unwrap();
1763-
flush_messages(&notify).await;
1767+
flush_messages(&basic_sender_account.notify).await;
17641768

17651769
assert_triggered!(&triggered_rav_request);
17661770
}
@@ -1851,6 +1855,7 @@ pub mod tests {
18511855

18521856
/// Test that the deny status is correctly loaded from the DB at the start of the actor
18531857
#[rstest::rstest]
1858+
#[tokio::test]
18541859
async fn test_init_deny(#[future(awt)] pgpool: PgPool) {
18551860
sqlx::query!(
18561861
r#"

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

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,16 +1042,21 @@ mod tests {
10421042
}
10431043

10441044
#[rstest::rstest]
1045-
async fn test_pending_sender_allocations(
1046-
#[future(awt)] state: TestState,
1047-
#[future(awt)] pgpool: PgPool,
1048-
#[future(awt)] _receipts: (),
1049-
) {
1045+
#[tokio::test]
1046+
async fn test_pending_sender_allocations(#[future(awt)] pgpool: PgPool) {
1047+
let (_, state) = create_state(pgpool.clone()).await;
1048+
// add receipts to the database
1049+
for i in 1..=10 {
1050+
let receipt = create_received_receipt(&ALLOCATION_ID_0, &SIGNER.0, i, i, i.into());
1051+
store_receipt(&pgpool, receipt.signed_receipt())
1052+
.await
1053+
.unwrap();
1054+
}
10501055
// add non-final ravs
10511056
let signed_rav = create_rav(ALLOCATION_ID_1, SIGNER.0.clone(), 4, 10);
10521057
store_rav(&pgpool, signed_rav, SENDER.1).await.unwrap();
10531058

1054-
let pending_allocation_id = state.state.get_pending_sender_allocation_id_v1().await;
1059+
let pending_allocation_id = state.get_pending_sender_allocation_id_v1().await;
10551060

10561061
// check if pending allocations are correct
10571062
assert_eq!(pending_allocation_id.len(), 1);
@@ -1108,6 +1113,7 @@ mod tests {
11081113
}
11091114

11101115
#[rstest::rstest]
1116+
#[tokio::test]
11111117
async fn test_create_sender_account(
11121118
#[future(awt)] state: TestState,
11131119
#[future(awt)] supervisor: ActorRef<()>,
@@ -1132,13 +1138,13 @@ mod tests {
11321138
}
11331139

11341140
#[rstest::rstest]
1141+
#[tokio::test]
11351142
async fn test_deny_sender_account_on_failure(
11361143
#[future(awt)] pgpool: PgPool,
1137-
#[future(awt)] state: TestState,
11381144
#[future(awt)] supervisor: ActorRef<()>,
11391145
) {
1146+
let (_prefix, state) = create_state(pgpool.clone()).await;
11401147
state
1141-
.state
11421148
.create_or_deny_sender(
11431149
supervisor.get_cell(),
11441150
INDEXER.1,
@@ -1167,10 +1173,8 @@ mod tests {
11671173
}
11681174

11691175
#[rstest::rstest]
1170-
async fn test_receive_notifications(
1171-
#[future(awt)] pglistener: PgListener,
1172-
#[future(awt)] _receipts: (),
1173-
) {
1176+
#[tokio::test]
1177+
async fn test_receive_notifications(#[future(awt)] pgpool: PgPool) {
11741178
let prefix = generate_random_prefix();
11751179
// create dummy allocation
11761180

@@ -1190,6 +1194,17 @@ mod tests {
11901194
.await
11911195
.unwrap();
11921196

1197+
// create tokio task to listen for notifications
1198+
1199+
let mut pglistener = PgListener::connect_with(&pgpool.clone()).await.unwrap();
1200+
pglistener
1201+
.listen("scalar_tap_receipt_notification")
1202+
.await
1203+
.expect(
1204+
"should be able to subscribe to Postgres Notify events on the channel \
1205+
'scalar_tap_receipt_notification'",
1206+
);
1207+
11931208
let escrow_accounts_rx = watch::channel(EscrowAccounts::new(
11941209
HashMap::from([(SENDER.1, U256::from(1000))]),
11951210
HashMap::from([(SENDER.1, vec![SIGNER.1])]),
@@ -1208,7 +1223,13 @@ mod tests {
12081223

12091224
let receipts_count = 10;
12101225

1211-
// receipts added through fixture
1226+
// add receipts to the database
1227+
for i in 1..=receipts_count {
1228+
let receipt = create_received_receipt(&ALLOCATION_ID_0, &SIGNER.0, i, i, i.into());
1229+
store_receipt(&pgpool, receipt.signed_receipt())
1230+
.await
1231+
.unwrap();
1232+
}
12121233

12131234
flush_messages(&notify).await;
12141235

@@ -1224,10 +1245,17 @@ mod tests {
12241245
}
12251246

12261247
#[rstest::rstest]
1227-
async fn test_manager_killed_in_database_connection(
1228-
#[future(awt)] pgpool: PgPool,
1229-
#[future(awt)] pglistener: PgListener,
1230-
) {
1248+
#[tokio::test]
1249+
async fn test_manager_killed_in_database_connection(#[future(awt)] pgpool: PgPool) {
1250+
let mut pglistener = PgListener::connect_with(&pgpool).await.unwrap();
1251+
pglistener
1252+
.listen("scalar_tap_receipt_notification")
1253+
.await
1254+
.expect(
1255+
"should be able to subscribe to Postgres Notify events on the channel \
1256+
'scalar_tap_receipt_notification'",
1257+
);
1258+
12311259
let escrow_accounts_rx = watch::channel(EscrowAccounts::default()).1;
12321260
let dummy_actor = DummyActor::spawn().await;
12331261

0 commit comments

Comments
 (0)