Skip to content

Commit defb43b

Browse files
committed
test: use builder for signed receipt request
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent afb6d29 commit defb43b

File tree

14 files changed

+100
-67
lines changed

14 files changed

+100
-67
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,4 @@ graphql_client = { version = "0.14.0", features = ["reqwest-rustls"] }
7777
bip39 = "2.0.0"
7878
rstest = "0.23.0"
7979
wiremock = "0.6.1"
80+
typed-builder = "0.20.0"

crates/service/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ graphql = { git = "https://github.com/edgeandnode/toolshed", tag = "graphql-v0.3
3939
tap_core.workspace = true
4040
uuid.workspace = true
4141
alloy.workspace = true
42+
typed-builder.workspace = true
4243
tower_governor = "0.4.3"
4344
governor = "0.6.0"
4445
tower-http = { version = "0.6.2", features = [
@@ -56,7 +57,6 @@ cost-model = { git = "https://github.com/graphprotocol/agora", rev = "3ed34ca" }
5657
bip39.workspace = true
5758
tower = "0.5.1"
5859
pin-project = "1.1.7"
59-
typed-builder = "0.20.0"
6060

6161
[dev-dependencies]
6262
hex-literal = "0.4.1"

crates/service/src/middleware/allocation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ mod tests {
7171
Router,
7272
};
7373
use reqwest::StatusCode;
74-
use test_assets::{create_signed_receipt, ESCROW_SUBGRAPH_DEPLOYMENT};
74+
use test_assets::{create_signed_receipt, SignedReceiptRequest, ESCROW_SUBGRAPH_DEPLOYMENT};
7575
use tokio::sync::watch;
7676
use tower::ServiceExt;
7777

@@ -96,7 +96,7 @@ mod tests {
9696

9797
let app = Router::new().route("/", get(handle)).layer(middleware);
9898

99-
let receipt = create_signed_receipt(Address::ZERO, 1, 1, 1).await;
99+
let receipt = create_signed_receipt(SignedReceiptRequest::builder().build()).await;
100100

101101
// with receipt
102102
let res = app

crates/service/src/middleware/auth.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ mod tests {
1414
use std::sync::Arc;
1515
use std::time::Duration;
1616

17-
use alloy::primitives::{address, Address};
1817
use axum::body::Body;
1918
use axum::http::{Request, Response};
2019
use reqwest::{header, StatusCode};
@@ -26,9 +25,8 @@ mod tests {
2625

2726
use crate::middleware::auth::{self, Bearer, OrExt};
2827
use crate::tap::IndexerTapContext;
29-
use test_assets::{create_signed_receipt, TAP_EIP712_DOMAIN};
28+
use test_assets::{create_signed_receipt, SignedReceiptRequest, TAP_EIP712_DOMAIN};
3029

31-
const ALLOCATION_ID: Address = address!("deadbeefcafebabedeadbeefcafebabedeadbeef");
3230
const BEARER_TOKEN: &str = "test";
3331

3432
async fn service(
@@ -98,7 +96,7 @@ mod tests {
9896
async fn test_composition_with_receipt(pgpool: PgPool) {
9997
let mut service = service(pgpool.clone()).await;
10098

101-
let receipt = create_signed_receipt(ALLOCATION_ID, 1, 1, 1).await;
99+
let receipt = create_signed_receipt(SignedReceiptRequest::builder().build()).await;
102100

103101
// check with receipt
104102
let mut req = Request::new(Default::default());

crates/service/src/middleware/auth/tap.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ mod tests {
8181
use tokio::time::sleep;
8282
use tower::{Service, ServiceBuilder, ServiceExt};
8383

84-
use alloy::primitives::{address, Address};
8584
use axum::{
8685
body::Body,
8786
http::{Request, Response},
@@ -97,7 +96,7 @@ mod tests {
9796
ReceiptWithState,
9897
},
9998
};
100-
use test_assets::{create_signed_receipt, TAP_EIP712_DOMAIN};
99+
use test_assets::{create_signed_receipt, SignedReceiptRequest, TAP_EIP712_DOMAIN};
101100
use tower_http::auth::AsyncRequireAuthorizationLayer;
102101

103102
use crate::{
@@ -108,8 +107,6 @@ mod tests {
108107
tap::IndexerTapContext,
109108
};
110109

111-
const ALLOCATION_ID: Address = address!("deadbeefcafebabedeadbeefcafebabedeadbeef");
112-
113110
#[fixture]
114111
fn metric() -> &'static prometheus::CounterVec {
115112
let registry = prometheus::Registry::new();
@@ -175,7 +172,7 @@ mod tests {
175172
) {
176173
let mut service = service(metric, pgpool.clone()).await;
177174

178-
let receipt = create_signed_receipt(ALLOCATION_ID, 1, 1, 1).await;
175+
let receipt = create_signed_receipt(SignedReceiptRequest::builder().build()).await;
179176

180177
// check with receipt
181178
let mut req = Request::new(Body::default());
@@ -226,7 +223,7 @@ mod tests {
226223
// default labels, all empty
227224
let labels: MetricLabels = Arc::new(TestLabel);
228225

229-
let mut receipt = create_signed_receipt(ALLOCATION_ID, 1, 1, 1).await;
226+
let mut receipt = create_signed_receipt(SignedReceiptRequest::builder().build()).await;
230227
// change the nonce to make the receipt invalid
231228
receipt.message.nonce = FAILED_NONCE;
232229
let mut req = Request::new(Body::default());

crates/service/src/middleware/sender.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ mod tests {
6161
use crate::middleware::sender::SenderState;
6262

6363
use super::{sender_middleware, Sender};
64-
use alloy::primitives::Address;
6564
use axum::{
6665
body::Body,
6766
http::{Extensions, Request},
@@ -72,7 +71,8 @@ mod tests {
7271
use indexer_monitor::EscrowAccounts;
7372
use reqwest::StatusCode;
7473
use test_assets::{
75-
create_signed_receipt, ESCROW_ACCOUNTS_BALANCES, ESCROW_ACCOUNTS_SENDERS_TO_SIGNERS,
74+
create_signed_receipt, SignedReceiptRequest, ESCROW_ACCOUNTS_BALANCES,
75+
ESCROW_ACCOUNTS_SENDERS_TO_SIGNERS,
7676
};
7777
use tokio::sync::watch;
7878
use tower::ServiceExt;
@@ -99,7 +99,7 @@ mod tests {
9999

100100
let app = Router::new().route("/", get(handle)).layer(middleware);
101101

102-
let receipt = create_signed_receipt(Address::ZERO, 1, 1, 1).await;
102+
let receipt = create_signed_receipt(SignedReceiptRequest::builder().build()).await;
103103

104104
let res = app
105105
.oneshot(

crates/service/src/middleware/tap_receipt.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub async fn receipt_middleware(mut request: Request, next: Next) -> Response {
2626
mod tests {
2727
use crate::{middleware::tap_receipt::receipt_middleware, service::TapReceipt};
2828

29-
use alloy::primitives::Address;
3029
use axum::{
3130
body::Body,
3231
http::{Extensions, Request},
@@ -37,14 +36,14 @@ mod tests {
3736
use axum_extra::headers::Header;
3837
use reqwest::StatusCode;
3938
use tap_core::receipt::SignedReceipt;
40-
use test_assets::create_signed_receipt;
39+
use test_assets::{create_signed_receipt, SignedReceiptRequest};
4140
use tower::ServiceExt;
4241

4342
#[tokio::test]
4443
async fn test_receipt_middleware() {
4544
let middleware = from_fn(receipt_middleware);
4645

47-
let receipt = create_signed_receipt(Address::ZERO, 1, 1, 1).await;
46+
let receipt = create_signed_receipt(SignedReceiptRequest::builder().build()).await;
4847
let receipt_json = serde_json::to_string(&receipt).unwrap();
4948

5049
let handle = move |extensions: Extensions| async move {

crates/service/src/service/tap_receipt_header.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,16 @@ impl Header for TapReceipt {
4747

4848
#[cfg(test)]
4949
mod test {
50-
use std::str::FromStr;
51-
52-
use alloy::primitives::Address;
5350
use axum::http::HeaderValue;
5451
use axum_extra::headers::Header;
5552

56-
use test_assets::create_signed_receipt;
53+
use test_assets::{create_signed_receipt, SignedReceiptRequest};
5754

5855
use super::TapReceipt;
5956

6057
#[tokio::test]
6158
async fn test_decode_valid_tap_receipt_header() {
62-
let allocation = Address::from_str("0xdeadbeefcafebabedeadbeefcafebabedeadbeef").unwrap();
63-
let original_receipt =
64-
create_signed_receipt(allocation, u64::MAX, u64::MAX, u128::MAX).await;
59+
let original_receipt = create_signed_receipt(SignedReceiptRequest::builder().build()).await;
6560
let serialized_receipt = serde_json::to_string(&original_receipt).unwrap();
6661
let header_value = HeaderValue::from_str(&serialized_receipt).unwrap();
6762
let header_values = vec![&header_value];

crates/service/src/tap/checks/deny_list_check.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,13 @@ impl Drop for DenyListCheck {
176176

177177
#[cfg(test)]
178178
mod tests {
179-
use std::str::FromStr;
180-
181179
use alloy::hex::ToHexExt;
182180
use tap_core::receipt::{Context, ReceiptWithState};
183181

184-
use test_assets::{self, create_signed_receipt, TAP_SENDER};
182+
use test_assets::{self, create_signed_receipt, SignedReceiptRequest, TAP_SENDER};
185183

186184
use super::*;
187185

188-
const ALLOCATION_ID: &str = "0xdeadbeefcafebabedeadbeefcafebabedeadbeef";
189-
190186
async fn new_deny_list_check(pgpool: PgPool) -> DenyListCheck {
191187
// Mock escrow accounts
192188
DenyListCheck::new(pgpool).await
@@ -206,9 +202,7 @@ mod tests {
206202
.await
207203
.unwrap();
208204

209-
let allocation_id = Address::from_str(ALLOCATION_ID).unwrap();
210-
let signed_receipt =
211-
create_signed_receipt(allocation_id, u64::MAX, u64::MAX, u128::MAX).await;
205+
let signed_receipt = create_signed_receipt(SignedReceiptRequest::builder().build()).await;
212206

213207
let deny_list_check = new_deny_list_check(pgpool.clone()).await;
214208

@@ -226,9 +220,7 @@ mod tests {
226220

227221
#[sqlx::test(migrations = "../../migrations")]
228222
async fn test_sender_denylist_updates(pgpool: PgPool) {
229-
let allocation_id = Address::from_str(ALLOCATION_ID).unwrap();
230-
let signed_receipt =
231-
create_signed_receipt(allocation_id, u64::MAX, u64::MAX, u128::MAX).await;
223+
let signed_receipt = create_signed_receipt(SignedReceiptRequest::builder().build()).await;
232224

233225
let deny_list_check = new_deny_list_check(pgpool.clone()).await;
234226

0 commit comments

Comments
 (0)