Skip to content

Commit 3c46881

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

File tree

7 files changed

+54
-63
lines changed

7 files changed

+54
-63
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/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/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);

crates/test-assets/src/lib.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use tap_core::{
1616
signed_message::EIP712SignedMessage,
1717
tap_eip712_domain,
1818
};
19-
use thegraph_core::DeploymentId;
19+
use thegraph_core::{deployment_id, DeploymentId};
2020
use tokio::sync::Notify;
2121
use typed_builder::TypedBuilder;
2222

@@ -110,31 +110,31 @@ pub const ESCROW_QUERY_RESPONSE: &str = r#"
110110
"#;
111111

112112
lazy_static! {
113-
pub static ref NETWORK_SUBGRAPH_DEPLOYMENT: DeploymentId = DeploymentId::from_str("QmU7zqJyHSyUP3yFii8sBtHT8FaJn2WmUnRvwjAUTjwMBP").unwrap();
114-
pub static ref ESCROW_SUBGRAPH_DEPLOYMENT: DeploymentId = DeploymentId::from_str("Qmb5Ysp5oCUXhLA8NmxmYKDAX2nCMnh7Vvb5uffb9n5vss").unwrap();
113+
pub static ref NETWORK_SUBGRAPH_DEPLOYMENT: DeploymentId = deployment_id!("QmU7zqJyHSyUP3yFii8sBtHT8FaJn2WmUnRvwjAUTjwMBP");
114+
pub static ref ESCROW_SUBGRAPH_DEPLOYMENT: DeploymentId = deployment_id!("Qmb5Ysp5oCUXhLA8NmxmYKDAX2nCMnh7Vvb5uffb9n5vss");
115115

116116
pub static ref INDEXER_MNEMONIC: Mnemonic = Mnemonic::from_str(
117117
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about",
118118
).unwrap();
119119

120120
pub static ref INDEXER_ADDRESS: Address =
121-
Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap();
121+
address!("d75c4dbcb215a6cf9097cfbcc70aab2596b96a9c");
122122

123123
pub static ref DISPUTE_MANAGER_ADDRESS: Address =
124-
Address::from_str("0xdeadbeefcafebabedeadbeefcafebabedeadbeef").unwrap();
124+
address!("deadbeefcafebabedeadbeefcafebabedeadbeef");
125125

126126

127127
pub static ref ALLOCATION_ID_0: Address =
128-
Address::from_str("0xfa44c72b753a66591f241c7dc04e8178c30e13af").unwrap();
128+
address!("fa44c72b753a66591f241c7dc04e8178c30e13af");
129129

130130
pub static ref ALLOCATION_ID_1: Address =
131-
Address::from_str("0xdd975e30aafebb143e54d215db8a3e8fd916a701").unwrap();
131+
address!("dd975e30aafebb143e54d215db8a3e8fd916a701");
132132

133133
pub static ref ALLOCATION_ID_2: Address =
134-
Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap();
134+
address!("a171cd12c3dde7eb8fe7717a0bcd06f3ffa65658");
135135

136136
pub static ref ALLOCATION_ID_3: Address =
137-
Address::from_str("0x69f961358846fdb64b04e1fd7b2701237c13cd9a").unwrap();
137+
address!("69f961358846fdb64b04e1fd7b2701237c13cd9a");
138138

139139

140140

@@ -145,7 +145,7 @@ lazy_static! {
145145
*ALLOCATION_ID_0,
146146
Allocation {
147147
id: *ALLOCATION_ID_0,
148-
indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(),
148+
indexer: address!("d75c4dbcb215a6cf9097cfbcc70aab2596b96a9c"),
149149
allocated_tokens: U256::from_str("5081382841000000014901161").unwrap(),
150150
created_at_block_hash:
151151
"0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf".to_string(),
@@ -169,7 +169,7 @@ lazy_static! {
169169
*ALLOCATION_ID_1,
170170
Allocation {
171171
id: *ALLOCATION_ID_1,
172-
indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(),
172+
indexer: address!("d75c4dbcb215a6cf9097cfbcc70aab2596b96a9c"),
173173
allocated_tokens: U256::from_str("601726452999999979510903").unwrap(),
174174
created_at_block_hash:
175175
"0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf".to_string(),
@@ -193,7 +193,7 @@ lazy_static! {
193193
*ALLOCATION_ID_2,
194194
Allocation {
195195
id: *ALLOCATION_ID_2,
196-
indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(),
196+
indexer: address!("d75c4dbcb215a6cf9097cfbcc70aab2596b96a9c"),
197197
allocated_tokens: U256::from_str("5247998688000000081956387").unwrap(),
198198
created_at_block_hash:
199199
"0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887".to_string(),
@@ -217,7 +217,7 @@ lazy_static! {
217217
*ALLOCATION_ID_3,
218218
Allocation {
219219
id: *ALLOCATION_ID_3,
220-
indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(),
220+
indexer: address!("d75c4dbcb215a6cf9097cfbcc70aab2596b96a9c"),
221221
allocated_tokens: U256::from_str("2502334654999999795109034").unwrap(),
222222
created_at_block_hash:
223223
"0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887".to_string(),
@@ -240,43 +240,43 @@ lazy_static! {
240240
]);
241241

242242
pub static ref ESCROW_ACCOUNTS_BALANCES: HashMap<Address, U256> = HashMap::from([
243-
(Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), U256::from(24)), // TAP_SENDER
244-
(Address::from_str("0x22d491bde2303f2f43325b2108d26f1eaba1e32b").unwrap(), U256::from(42)),
245-
(Address::from_str("0x192c3B6e0184Fa0Cc5B9D2bDDEb6B79Fb216a002").unwrap(), U256::from(2975)),
243+
(address!("9858EfFD232B4033E47d90003D41EC34EcaEda94"), U256::from(24)), // TAP_SENDER
244+
(address!("22d491bde2303f2f43325b2108d26f1eaba1e32b"), U256::from(42)),
245+
(address!("192c3B6e0184Fa0Cc5B9D2bDDEb6B79Fb216a002"), U256::from(2975)),
246246
]);
247247

248248

249249
/// Maps signers back to their senders
250250
pub static ref ESCROW_ACCOUNTS_SIGNERS_TO_SENDERS: HashMap<Address, Address> = HashMap::from([
251251
(
252-
Address::from_str("0x533661F0fb14d2E8B26223C86a610Dd7D2260892").unwrap(), // TAP_SIGNER
253-
Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), // TAP_SENDER
252+
address!("533661F0fb14d2E8B26223C86a610Dd7D2260892"), // TAP_SIGNER
253+
address!("9858EfFD232B4033E47d90003D41EC34EcaEda94"), // TAP_SENDER
254254
),
255255
(
256-
Address::from_str("0x2740f6fA9188cF53ffB6729DDD21575721dE92ce").unwrap(),
257-
Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), // TAP_SENDER
256+
address!("2740f6fA9188cF53ffB6729DDD21575721dE92ce"),
257+
address!("9858EfFD232B4033E47d90003D41EC34EcaEda94"), // TAP_SENDER
258258
),
259259
(
260-
Address::from_str("0x245059163ff6ee14279aa7b35ea8f0fdb967df6e").unwrap(),
261-
Address::from_str("0x22d491bde2303f2f43325b2108d26f1eaba1e32b").unwrap(),
260+
address!("245059163ff6ee14279aa7b35ea8f0fdb967df6e"),
261+
address!("22d491bde2303f2f43325b2108d26f1eaba1e32b"),
262262
),
263263
]);
264264

265265

266266
pub static ref ESCROW_ACCOUNTS_SENDERS_TO_SIGNERS: HashMap<Address, Vec<Address>> = HashMap::from([
267267
(
268-
Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), // TAP_SENDER
268+
address!("9858EfFD232B4033E47d90003D41EC34EcaEda94"), // TAP_SENDER
269269
vec![
270-
Address::from_str("0x533661F0fb14d2E8B26223C86a610Dd7D2260892").unwrap(), // TAP_SIGNER
271-
Address::from_str("0x2740f6fA9188cF53ffB6729DDD21575721dE92ce").unwrap(),
270+
address!("533661F0fb14d2E8B26223C86a610Dd7D2260892"), // TAP_SIGNER
271+
address!("2740f6fA9188cF53ffB6729DDD21575721dE92ce"),
272272
],
273273
),
274274
(
275-
Address::from_str("0x22d491bde2303f2f43325b2108d26f1eaba1e32b").unwrap(),
276-
vec![Address::from_str("0x245059163ff6ee14279aa7b35ea8f0fdb967df6e").unwrap()],
275+
address!("22d491bde2303f2f43325b2108d26f1eaba1e32b"),
276+
vec![address!("245059163ff6ee14279aa7b35ea8f0fdb967df6e")],
277277
),
278278
(
279-
Address::from_str("0x192c3B6e0184Fa0Cc5B9D2bDDEb6B79Fb216a002").unwrap(),
279+
address!("192c3B6e0184Fa0Cc5B9D2bDDEb6B79Fb216a002"),
280280
vec![],
281281
),
282282
]);
@@ -317,7 +317,7 @@ lazy_static! {
317317

318318
use std::time::{SystemTime, UNIX_EPOCH};
319319

320-
use alloy::primitives::Address;
320+
use alloy::primitives::{address, Address};
321321

322322
#[derive(TypedBuilder)]
323323
pub struct SignedReceiptRequest {

0 commit comments

Comments
 (0)