Skip to content

Commit

Permalink
refactor: use address and deployment_id initialization macros
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo Delgado <[email protected]>
  • Loading branch information
LNSD committed Dec 20, 2024
1 parent 9a85551 commit 85ad049
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 63 deletions.
10 changes: 5 additions & 5 deletions crates/attestation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn wallet_for_allocation(
mod tests {
use std::str::FromStr;

use alloy::primitives::U256;
use alloy::primitives::{address, U256};
use indexer_allocation::{Allocation, AllocationStatus, SubgraphDeployment};
use test_assets::DISPUTE_MANAGER_ADDRESS;
use test_log::test;
Expand All @@ -142,7 +142,7 @@ mod tests {
)
.unwrap()
.address(),
Address::from_str("0xfa44c72b753a66591f241c7dc04e8178c30e13af").unwrap()
address!("fa44c72b753a66591f241c7dc04e8178c30e13af")
);

assert_eq!(
Expand All @@ -157,7 +157,7 @@ mod tests {
)
.unwrap()
.address(),
Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap()
address!("a171cd12c3dde7eb8fe7717a0bcd06f3ffa65658")
);
}

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

let allocation = Allocation {
id: Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap(),
id: address!("a171cd12c3dde7eb8fe7717a0bcd06f3ffa65658"),
status: AllocationStatus::Null,
subgraph_deployment: SubgraphDeployment {
id: DeploymentId::from_str(
Expand Down Expand Up @@ -213,7 +213,7 @@ mod tests {

let allocation = Allocation {
// Purposefully wrong address
id: Address::from_str("0xdeadbeefcafebabedeadbeefcafebabedeadbeef").unwrap(),
id: address!("deadbeefcafebabedeadbeefcafebabedeadbeef"),
status: AllocationStatus::Null,
subgraph_deployment: SubgraphDeployment {
id: DeploymentId::from_str(
Expand Down
7 changes: 4 additions & 3 deletions crates/monitor/src/allocations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ pub async fn get_allocations(
mod test {
const NETWORK_SUBGRAPH_URL: &str =
"https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-arbitrum";
use std::str::FromStr;

use alloy::primitives::address;

use super::*;
use crate::client::{DeploymentDetails, SubgraphClient};
Expand All @@ -113,7 +114,7 @@ mod test {
async fn test_network_query() {
let result = get_allocations(
network_subgraph_client().await,
Address::from_str("0x326c584e0f0eab1f1f83c93cc6ae1acc0feba0bc").unwrap(),
address!("326c584e0f0eab1f1f83c93cc6ae1acc0feba0bc"),
Duration::from_secs(1712448507),
)
.await;
Expand All @@ -125,7 +126,7 @@ mod test {
async fn test_network_query_empty_response() {
let result = get_allocations(
network_subgraph_client().await,
Address::from_str("0xdeadbeefcafebabedeadbeefcafebabedeadbeef").unwrap(),
address!("deadbeefcafebabedeadbeefcafebabedeadbeef"),
Duration::from_secs(1712448507),
)
.await
Expand Down
14 changes: 5 additions & 9 deletions crates/monitor/src/client/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ pub async fn check_deployment_status(

#[cfg(test)]
mod tests {
use std::str::FromStr;

use serde_json::json;
use thegraph_core::deployment_id;
use wiremock::{
matchers::{method, path},
Mock, MockServer, ResponseTemplate,
Expand All @@ -81,8 +81,7 @@ mod tests {
.unwrap()
.join("/status")
.unwrap();
let deployment =
DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap();
let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

Mock::given(method("POST"))
.and(path("/status"))
Expand Down Expand Up @@ -121,8 +120,7 @@ mod tests {
.unwrap()
.join("/status")
.unwrap();
let deployment =
DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap();
let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

Mock::given(method("POST"))
.and(path("/status"))
Expand Down Expand Up @@ -161,8 +159,7 @@ mod tests {
.unwrap()
.join("/status")
.unwrap();
let deployment =
DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap();
let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

Mock::given(method("POST"))
.and(path("/status"))
Expand Down Expand Up @@ -201,8 +198,7 @@ mod tests {
.unwrap()
.join("/status")
.unwrap();
let deployment =
DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap();
let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

Mock::given(method("POST"))
.and(path("/status"))
Expand Down
11 changes: 4 additions & 7 deletions crates/monitor/src/client/subgraph_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ impl SubgraphClient {

#[cfg(test)]
mod test {
use std::str::FromStr;

use indexer_query::{current_epoch, user_query, CurrentEpoch, UserQuery};
use serde_json::json;
use thegraph_core::deployment_id;
use wiremock::{
matchers::{method, path},
Mock, MockServer, ResponseTemplate,
Expand Down Expand Up @@ -315,8 +315,7 @@ mod test {

#[tokio::test]
async fn test_uses_local_deployment_if_healthy_and_synced() {
let deployment =
DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap();
let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

let mock_server_status = MockServer::start().await;
mock_server_status
Expand Down Expand Up @@ -396,8 +395,7 @@ mod test {

#[tokio::test]
async fn test_uses_query_url_if_local_deployment_is_unhealthy() {
let deployment =
DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap();
let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

let mock_server_status = MockServer::start().await;
mock_server_status
Expand Down Expand Up @@ -477,8 +475,7 @@ mod test {

#[tokio::test]
async fn test_uses_query_url_if_local_deployment_is_not_synced() {
let deployment =
DeploymentId::from_str("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA").unwrap();
let deployment = deployment_id!("QmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

let mock_server_status = MockServer::start().await;
mock_server_status
Expand Down
9 changes: 4 additions & 5 deletions crates/service/src/database/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ pub(crate) mod test {
use std::str::FromStr;

use sqlx::PgPool;
use thegraph_core::deployment_id;

use super::*;

Expand Down Expand Up @@ -389,8 +390,7 @@ pub(crate) mod test {
}

// Third test: query for missing cost model
let missing_deployment =
DeploymentId::from_str("Qmaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").unwrap();
let missing_deployment = deployment_id!("Qmaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
let models = cost_models(&pool, &[missing_deployment])
.await
.expect("cost models query for missing deployment");
Expand All @@ -413,7 +413,7 @@ pub(crate) mod test {
)
.unwrap();
let deployment_id_from_hash =
DeploymentId::from_str("Qmb5Ysp5oCUXhLA8NmxmYKDAX2nCMnh7Vvb5uffb9n5vss").unwrap();
deployment_id!("Qmb5Ysp5oCUXhLA8NmxmYKDAX2nCMnh7Vvb5uffb9n5vss");

assert_eq!(deployment_id_from_bytes, deployment_id_from_hash);

Expand Down Expand Up @@ -454,8 +454,7 @@ pub(crate) mod test {
}

// Test that querying a non-existing deployment returns the default cost model
let missing_deployment =
DeploymentId::from_str("Qmnononononononononononononononononononononono").unwrap();
let missing_deployment = deployment_id!("Qmnononononononononononononononononononononono");
let model = cost_model(&pool, &missing_deployment)
.await
.expect("cost model query")
Expand Down
8 changes: 3 additions & 5 deletions crates/tap-agent/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
// SPDX-License-Identifier: Apache-2.0

use std::str::FromStr;

use alloy::{
primitives::{hex::ToHexExt, Address},
primitives::{address, hex::ToHexExt, Address},
signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner},
sol_types::Eip712Domain,
};
Expand All @@ -20,9 +18,9 @@ use tap_core::{

lazy_static! {
pub static ref ALLOCATION_ID_0: Address =
Address::from_str("0xabababababababababababababababababababab").unwrap();
address!("abababababababababababababababababababab");
pub static ref ALLOCATION_ID_1: Address =
Address::from_str("0xbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbc").unwrap();
address!("bcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbc");
// pub static ref SENDER: (PrivateKeySigner, Address) = wallet(0);
pub static ref SENDER_2: (PrivateKeySigner, Address) = wallet(1);
pub static ref SIGNER: (PrivateKeySigner, Address) = wallet(2);
Expand Down
58 changes: 29 additions & 29 deletions crates/test-assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use tap_core::{
signed_message::EIP712SignedMessage,
tap_eip712_domain,
};
use thegraph_core::DeploymentId;
use thegraph_core::{deployment_id, DeploymentId};
use tokio::sync::Notify;
use typed_builder::TypedBuilder;

Expand Down Expand Up @@ -110,31 +110,31 @@ pub const ESCROW_QUERY_RESPONSE: &str = r#"
"#;

lazy_static! {
pub static ref NETWORK_SUBGRAPH_DEPLOYMENT: DeploymentId = DeploymentId::from_str("QmU7zqJyHSyUP3yFii8sBtHT8FaJn2WmUnRvwjAUTjwMBP").unwrap();
pub static ref ESCROW_SUBGRAPH_DEPLOYMENT: DeploymentId = DeploymentId::from_str("Qmb5Ysp5oCUXhLA8NmxmYKDAX2nCMnh7Vvb5uffb9n5vss").unwrap();
pub static ref NETWORK_SUBGRAPH_DEPLOYMENT: DeploymentId = deployment_id!("QmU7zqJyHSyUP3yFii8sBtHT8FaJn2WmUnRvwjAUTjwMBP");
pub static ref ESCROW_SUBGRAPH_DEPLOYMENT: DeploymentId = deployment_id!("Qmb5Ysp5oCUXhLA8NmxmYKDAX2nCMnh7Vvb5uffb9n5vss");

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

pub static ref INDEXER_ADDRESS: Address =
Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap();
address!("d75c4dbcb215a6cf9097cfbcc70aab2596b96a9c");

pub static ref DISPUTE_MANAGER_ADDRESS: Address =
Address::from_str("0xdeadbeefcafebabedeadbeefcafebabedeadbeef").unwrap();
address!("deadbeefcafebabedeadbeefcafebabedeadbeef");


pub static ref ALLOCATION_ID_0: Address =
Address::from_str("0xfa44c72b753a66591f241c7dc04e8178c30e13af").unwrap();
address!("fa44c72b753a66591f241c7dc04e8178c30e13af");

pub static ref ALLOCATION_ID_1: Address =
Address::from_str("0xdd975e30aafebb143e54d215db8a3e8fd916a701").unwrap();
address!("dd975e30aafebb143e54d215db8a3e8fd916a701");

pub static ref ALLOCATION_ID_2: Address =
Address::from_str("0xa171cd12c3dde7eb8fe7717a0bcd06f3ffa65658").unwrap();
address!("a171cd12c3dde7eb8fe7717a0bcd06f3ffa65658");

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



Expand All @@ -145,7 +145,7 @@ lazy_static! {
*ALLOCATION_ID_0,
Allocation {
id: *ALLOCATION_ID_0,
indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(),
indexer: address!("d75c4dbcb215a6cf9097cfbcc70aab2596b96a9c"),
allocated_tokens: U256::from_str("5081382841000000014901161").unwrap(),
created_at_block_hash:
"0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf".to_string(),
Expand All @@ -169,7 +169,7 @@ lazy_static! {
*ALLOCATION_ID_1,
Allocation {
id: *ALLOCATION_ID_1,
indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(),
indexer: address!("d75c4dbcb215a6cf9097cfbcc70aab2596b96a9c"),
allocated_tokens: U256::from_str("601726452999999979510903").unwrap(),
created_at_block_hash:
"0x99d3fbdc0105f7ccc0cd5bb287b82657fe92db4ea8fb58242dafb90b1c6e2adf".to_string(),
Expand All @@ -193,7 +193,7 @@ lazy_static! {
*ALLOCATION_ID_2,
Allocation {
id: *ALLOCATION_ID_2,
indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(),
indexer: address!("d75c4dbcb215a6cf9097cfbcc70aab2596b96a9c"),
allocated_tokens: U256::from_str("5247998688000000081956387").unwrap(),
created_at_block_hash:
"0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887".to_string(),
Expand All @@ -217,7 +217,7 @@ lazy_static! {
*ALLOCATION_ID_3,
Allocation {
id: *ALLOCATION_ID_3,
indexer: Address::from_str("0xd75c4dbcb215a6cf9097cfbcc70aab2596b96a9c").unwrap(),
indexer: address!("d75c4dbcb215a6cf9097cfbcc70aab2596b96a9c"),
allocated_tokens: U256::from_str("2502334654999999795109034").unwrap(),
created_at_block_hash:
"0x6e7b7100c37f659236a029f87ce18914643995120f55ab5d01631f11f40fd887".to_string(),
Expand All @@ -240,43 +240,43 @@ lazy_static! {
]);

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


/// Maps signers back to their senders
pub static ref ESCROW_ACCOUNTS_SIGNERS_TO_SENDERS: HashMap<Address, Address> = HashMap::from([
(
Address::from_str("0x533661F0fb14d2E8B26223C86a610Dd7D2260892").unwrap(), // TAP_SIGNER
Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), // TAP_SENDER
address!("533661F0fb14d2E8B26223C86a610Dd7D2260892"), // TAP_SIGNER
address!("9858EfFD232B4033E47d90003D41EC34EcaEda94"), // TAP_SENDER
),
(
Address::from_str("0x2740f6fA9188cF53ffB6729DDD21575721dE92ce").unwrap(),
Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), // TAP_SENDER
address!("2740f6fA9188cF53ffB6729DDD21575721dE92ce"),
address!("9858EfFD232B4033E47d90003D41EC34EcaEda94"), // TAP_SENDER
),
(
Address::from_str("0x245059163ff6ee14279aa7b35ea8f0fdb967df6e").unwrap(),
Address::from_str("0x22d491bde2303f2f43325b2108d26f1eaba1e32b").unwrap(),
address!("245059163ff6ee14279aa7b35ea8f0fdb967df6e"),
address!("22d491bde2303f2f43325b2108d26f1eaba1e32b"),
),
]);


pub static ref ESCROW_ACCOUNTS_SENDERS_TO_SIGNERS: HashMap<Address, Vec<Address>> = HashMap::from([
(
Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), // TAP_SENDER
address!("9858EfFD232B4033E47d90003D41EC34EcaEda94"), // TAP_SENDER
vec![
Address::from_str("0x533661F0fb14d2E8B26223C86a610Dd7D2260892").unwrap(), // TAP_SIGNER
Address::from_str("0x2740f6fA9188cF53ffB6729DDD21575721dE92ce").unwrap(),
address!("533661F0fb14d2E8B26223C86a610Dd7D2260892"), // TAP_SIGNER
address!("2740f6fA9188cF53ffB6729DDD21575721dE92ce"),
],
),
(
Address::from_str("0x22d491bde2303f2f43325b2108d26f1eaba1e32b").unwrap(),
vec![Address::from_str("0x245059163ff6ee14279aa7b35ea8f0fdb967df6e").unwrap()],
address!("22d491bde2303f2f43325b2108d26f1eaba1e32b"),
vec![address!("245059163ff6ee14279aa7b35ea8f0fdb967df6e")],
),
(
Address::from_str("0x192c3B6e0184Fa0Cc5B9D2bDDEb6B79Fb216a002").unwrap(),
address!("192c3B6e0184Fa0Cc5B9D2bDDEb6B79Fb216a002"),
vec![],
),
]);
Expand Down Expand Up @@ -317,7 +317,7 @@ lazy_static! {

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

use alloy::primitives::Address;
use alloy::primitives::{address, Address};

#[derive(TypedBuilder)]
pub struct SignedReceiptRequest {
Expand Down

0 comments on commit 85ad049

Please sign in to comment.