Skip to content

Commit 9d762e5

Browse files
committed
refactor: use address and deployment_id initialization macros
Signed-off-by: Lorenzo Delgado <[email protected]>
1 parent cbf0b21 commit 9d762e5

File tree

9 files changed

+60
-75
lines changed

9 files changed

+60
-75
lines changed

crates/attestation/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn wallet_for_allocation(
119119
mod tests {
120120
use std::str::FromStr;
121121

122-
use alloy::primitives::U256;
122+
use alloy::primitives::{address, U256};
123123
use indexer_allocation::{Allocation, AllocationStatus, SubgraphDeployment};
124124
use test_assets::DISPUTE_MANAGER_ADDRESS;
125125
use test_log::test;
@@ -142,7 +142,7 @@ mod tests {
142142
)
143143
.unwrap()
144144
.address(),
145-
Address::from_str("0xfa44c72b753a66591f241c7dc04e8178c30e13af").unwrap()
145+
address!("fa44c72b753a66591f241c7dc04e8178c30e13af")
146146
);
147147

148148
assert_eq!(
@@ -157,7 +157,7 @@ mod tests {
157157
)
158158
.unwrap()
159159
.address(),
160-
Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap()
160+
address!("a171cd12c3dde7eb8fe7717a0bcd06f3ffa65658")
161161
);
162162
}
163163

@@ -166,7 +166,7 @@ mod tests {
166166
// Note that we use `derive_key_pair` to derive the private key
167167

168168
let allocation = Allocation {
169-
id: Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap(),
169+
id: address!("a171cd12c3dde7eb8fe7717a0bcd06f3ffa65658"),
170170
status: AllocationStatus::Null,
171171
subgraph_deployment: SubgraphDeployment {
172172
id: DeploymentId::from_str(
@@ -213,7 +213,7 @@ mod tests {
213213

214214
let allocation = Allocation {
215215
// Purposefully wrong address
216-
id: Address::from_str("0xdeadbeefcafebabedeadbeefcafebabedeadbeef").unwrap(),
216+
id: address!("deadbeefcafebabedeadbeefcafebabedeadbeef"),
217217
status: AllocationStatus::Null,
218218
subgraph_deployment: SubgraphDeployment {
219219
id: DeploymentId::from_str(

crates/config/src/config.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,9 @@ pub struct RavRequestConfig {
421421

422422
#[cfg(test)]
423423
mod tests {
424-
use std::{env, fs, path::PathBuf, str::FromStr};
424+
use std::{env, fs, path::PathBuf};
425425

426-
use alloy::primitives::{Address, FixedBytes};
426+
use alloy::primitives::address;
427427
use figment::value::Uncased;
428428
use sealed_test::prelude::*;
429429
use tracing_test::traced_test;
@@ -449,9 +449,7 @@ mod tests {
449449
)
450450
.unwrap();
451451
max_config.dips = Some(crate::DipsConfig {
452-
allowed_payers: vec![Address(
453-
FixedBytes::<20>::from_str("0x3333333333333333333333333333333333333333").unwrap(),
454-
)],
452+
allowed_payers: vec![address!("3333333333333333333333333333333333333333")],
455453
cancellation_time_tolerance: None,
456454
});
457455

crates/monitor/src/allocations.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ pub async fn get_allocations(
9292
mod test {
9393
const NETWORK_SUBGRAPH_URL: &str =
9494
"https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-arbitrum";
95-
use std::str::FromStr;
95+
96+
use alloy::primitives::address;
9697

9798
use super::*;
9899
use crate::client::{DeploymentDetails, SubgraphClient};
@@ -113,7 +114,7 @@ mod test {
113114
async fn test_network_query() {
114115
let result = get_allocations(
115116
network_subgraph_client().await,
116-
Address::from_str("0x326c584e0f0eab1f1f83c93cc6ae1acc0feba0bc").unwrap(),
117+
address!("326c584e0f0eab1f1f83c93cc6ae1acc0feba0bc"),
117118
Duration::from_secs(1712448507),
118119
)
119120
.await;
@@ -125,7 +126,7 @@ mod test {
125126
async fn test_network_query_empty_response() {
126127
let result = get_allocations(
127128
network_subgraph_client().await,
128-
Address::from_str("0xdeadbeefcafebabedeadbeefcafebabedeadbeef").unwrap(),
129+
address!("deadbeefcafebabedeadbeefcafebabedeadbeef"),
129130
Duration::from_secs(1712448507),
130131
)
131132
.await

crates/monitor/src/client/monitor.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ pub async fn check_deployment_status(
6262

6363
#[cfg(test)]
6464
mod tests {
65-
use std::str::FromStr;
6665

6766
use serde_json::json;
67+
use thegraph_core::deployment_id;
6868
use wiremock::{
6969
matchers::{method, path},
7070
Mock, MockServer, ResponseTemplate,
@@ -81,8 +81,7 @@ mod tests {
8181
.unwrap()
8282
.join("/status")
8383
.unwrap();
84-
let deployment =
85-
DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap();
84+
let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
8685

8786
Mock::given(method("POST"))
8887
.and(path("/status"))
@@ -121,8 +120,7 @@ mod tests {
121120
.unwrap()
122121
.join("/status")
123122
.unwrap();
124-
let deployment =
125-
DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap();
123+
let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
126124

127125
Mock::given(method("POST"))
128126
.and(path("/status"))
@@ -161,8 +159,7 @@ mod tests {
161159
.unwrap()
162160
.join("/status")
163161
.unwrap();
164-
let deployment =
165-
DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap();
162+
let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
166163

167164
Mock::given(method("POST"))
168165
.and(path("/status"))
@@ -201,8 +198,7 @@ mod tests {
201198
.unwrap()
202199
.join("/status")
203200
.unwrap();
204-
let deployment =
205-
DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap();
201+
let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
206202

207203
Mock::given(method("POST"))
208204
.and(path("/status"))

crates/monitor/src/client/subgraph_client.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,10 @@ impl SubgraphClient {
251251

252252
#[cfg(test)]
253253
mod test {
254-
use std::str::FromStr;
255254

256255
use indexer_query::{current_epoch, user_query, CurrentEpoch, UserQuery};
257256
use serde_json::json;
257+
use thegraph_core::deployment_id;
258258
use wiremock::{
259259
matchers::{method, path},
260260
Mock, MockServer, ResponseTemplate,
@@ -315,8 +315,7 @@ mod test {
315315

316316
#[tokio::test]
317317
async fn test_uses_local_deployment_if_healthy_and_synced() {
318-
let deployment =
319-
DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap();
318+
let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
320319

321320
let mock_server_status = MockServer::start().await;
322321
mock_server_status
@@ -396,8 +395,7 @@ mod test {
396395

397396
#[tokio::test]
398397
async fn test_uses_query_url_if_local_deployment_is_unhealthy() {
399-
let deployment =
400-
DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap();
398+
let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
401399

402400
let mock_server_status = MockServer::start().await;
403401
mock_server_status
@@ -477,8 +475,7 @@ mod test {
477475

478476
#[tokio::test]
479477
async fn test_uses_query_url_if_local_deployment_is_not_synced() {
480-
let deployment =
481-
DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap();
478+
let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
482479

483480
let mock_server_status = MockServer::start().await;
484481
mock_server_status

crates/service/src/database/cost_model.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ pub(crate) mod test {
194194
use std::str::FromStr;
195195

196196
use sqlx::PgPool;
197+
use thegraph_core::deployment_id;
197198

198199
use super::*;
199200

@@ -389,8 +390,7 @@ pub(crate) mod test {
389390
}
390391

391392
// Third test: query for missing cost model
392-
let missing_deployment =
393-
DeploymentId::from_str("Qmaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").unwrap();
393+
let missing_deployment = deployment_id!("Qmaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
394394
let models = cost_models(&pool, &[missing_deployment])
395395
.await
396396
.expect("cost models query for missing deployment");
@@ -413,7 +413,7 @@ pub(crate) mod test {
413413
)
414414
.unwrap();
415415
let deployment_id_from_hash =
416-
DeploymentId::from_str("Qmb5Ysp5oCUXhLA8NmxmYKDAX2nCMnh7Vvb5uffb9n5vss").unwrap();
416+
deployment_id!("Qmb5Ysp5oCUXhLA8NmxmYKDAX2nCMnh7Vvb5uffb9n5vss");
417417

418418
assert_eq!(deployment_id_from_bytes, deployment_id_from_hash);
419419

@@ -454,8 +454,7 @@ pub(crate) mod test {
454454
}
455455

456456
// Test that querying a non-existing deployment returns the default cost model
457-
let missing_deployment =
458-
DeploymentId::from_str("Qmnononononononononononononononononononononono").unwrap();
457+
let missing_deployment = deployment_id!("Qmnononononononononononononononononononononono");
459458
let model = cost_model(&pool, &missing_deployment)
460459
.await
461460
.expect("cost model query")

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,10 @@ impl Check for ReceiptMaxValueCheck {
3939
}
4040
#[cfg(test)]
4141
mod tests {
42-
use std::{
43-
str::FromStr,
44-
time::{Duration, SystemTime},
45-
};
42+
use std::time::{Duration, SystemTime};
4643

4744
use alloy::{
48-
primitives::Address,
45+
primitives::{address, Address},
4946
signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner},
5047
};
5148
use tap_core::{
@@ -81,8 +78,7 @@ mod tests {
8178
let receipt = EIP712SignedMessage::new(
8279
&eip712_domain_separator,
8380
Receipt {
84-
allocation_id: Address::from_str("0xabababababababababababababababababababab")
85-
.unwrap(),
81+
allocation_id: address!("abababababababababababababababababababab"),
8682
nonce,
8783
timestamp_ns,
8884
value,

crates/tap-agent/src/test.rs

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

4-
use std::str::FromStr;
5-
64
use alloy::{
7-
primitives::{hex::ToHexExt, Address},
5+
primitives::{address, hex::ToHexExt, Address},
86
signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner},
97
sol_types::Eip712Domain,
108
};
@@ -20,9 +18,9 @@ use tap_core::{
2018

2119
lazy_static! {
2220
pub static ref ALLOCATION_ID_0: Address =
23-
Address::from_str("0xabababababababababababababababababababab").unwrap();
21+
address!("abababababababababababababababababababab");
2422
pub static ref ALLOCATION_ID_1: Address =
25-
Address::from_str("0xbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbc").unwrap();
23+
address!("bcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbc");
2624
// pub static ref SENDER: (PrivateKeySigner, Address) = wallet(0);
2725
pub static ref SENDER_2: (PrivateKeySigner, Address) = wallet(1);
2826
pub static ref SIGNER: (PrivateKeySigner, Address) = wallet(2);

0 commit comments

Comments
 (0)