Skip to content

Commit

Permalink
Merge branch 'main' into revert-607-theodus/trusted-senders
Browse files Browse the repository at this point in the history
  • Loading branch information
gusinacio authored Feb 10, 2025
2 parents 1899f2f + 9c1eab2 commit b9de96f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 30 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/tap-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ name = "indexer-tap-agent"
path = "src/main.rs"

[features]
test = ["dep:test-assets"]
test = ["dep:test-assets", "dep:rand"]

[dependencies]
indexer-monitor = { path = "../monitor" }
Expand Down Expand Up @@ -51,6 +51,7 @@ tap_aggregator.workspace = true
futures = { version = "0.3.30", default-features = false }
bon = "3.3"
test-assets = { path = "../test-assets", optional = true }
rand = { version = "0.8", optional = true }

[dev-dependencies]
# Release-please breaks with cyclical dependencies if dev-dependencies
Expand Down
2 changes: 0 additions & 2 deletions crates/tap-agent/src/agent/sender_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,6 @@ pub mod tests {
#![allow(missing_docs)]
use std::{
collections::{HashMap, HashSet},
sync::atomic::AtomicU32,
time::{Duration, SystemTime, UNIX_EPOCH},
};

Expand Down Expand Up @@ -1344,7 +1343,6 @@ pub mod tests {
}

/// Prefix shared between tests so we don't have conflicts in the global registry
pub static PREFIX_ID: AtomicU32 = AtomicU32::new(0);
const ESCROW_VALUE: u128 = 1000;
const BUFFER_DURATION: Duration = Duration::from_millis(100);
const RETRY_DURATION: Duration = Duration::from_millis(1000);
Expand Down
24 changes: 8 additions & 16 deletions crates/tap-agent/src/agent/sender_accounts_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,14 +701,15 @@ mod tests {
use super::{new_receipts_watcher, SenderAccountsManagerMessage, State};
use crate::{
agent::{
sender_account::{tests::PREFIX_ID, SenderAccountMessage},
sender_account::SenderAccountMessage,
sender_accounts_manager::{handle_notification, AllocationId, NewReceiptNotification},
},
test::{
actors::{DummyActor, MockSenderAccount, MockSenderAllocation, TestableActor},
create_rav, create_received_receipt, create_sender_accounts_manager, get_grpc_url,
get_sender_account_config, store_rav, store_receipt, ALLOCATION_ID_0, ALLOCATION_ID_1,
INDEXER, SENDER_2, TAP_EIP712_DOMAIN_SEPARATOR,
create_rav, create_received_receipt, create_sender_accounts_manager,
generate_random_prefix, get_grpc_url, get_sender_account_config, store_rav,
store_receipt, ALLOCATION_ID_0, ALLOCATION_ID_1, INDEXER, SENDER_2,
TAP_EIP712_DOMAIN_SEPARATOR,
},
};
const DUMMY_URL: &str = "http://localhost:1234";
Expand Down Expand Up @@ -737,10 +738,7 @@ mod tests {
let senders_to_signers = vec![(SENDER.1, vec![SIGNER.1])].into_iter().collect();
let escrow_accounts = EscrowAccounts::new(HashMap::new(), senders_to_signers);

let prefix = format!(
"test-{}",
PREFIX_ID.fetch_add(1, std::sync::atomic::Ordering::SeqCst)
);
let prefix = generate_random_prefix();
(
prefix.clone(),
State {
Expand Down Expand Up @@ -866,10 +864,7 @@ mod tests {

#[sqlx::test(migrations = "../../migrations")]
async fn test_receive_notifications(pgpool: PgPool) {
let prefix = format!(
"test-{}",
PREFIX_ID.fetch_add(1, std::sync::atomic::Ordering::SeqCst)
);
let prefix = generate_random_prefix();
// create dummy allocation

let (mock_sender_allocation, mut receipts) = MockSenderAllocation::new_with_receipts();
Expand Down Expand Up @@ -968,10 +963,7 @@ mod tests {
let escrow_accounts = EscrowAccounts::new(HashMap::new(), senders_to_signers);
let escrow_accounts = watch::channel(escrow_accounts).1;

let prefix = format!(
"test-{}",
PREFIX_ID.fetch_add(1, std::sync::atomic::Ordering::SeqCst)
);
let prefix = generate_random_prefix();

let (last_message_emitted, mut rx) = mpsc::channel(64);

Expand Down
25 changes: 14 additions & 11 deletions crates/tap-agent/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::{
collections::{HashMap, HashSet},
net::SocketAddr,
sync::{atomic::AtomicU32, Arc},
sync::Arc,
time::Duration,
};

Expand All @@ -16,6 +16,7 @@ use indexer_monitor::{DeploymentDetails, EscrowAccounts, SubgraphClient};
use indexer_receipt::TapReceipt;
use lazy_static::lazy_static;
use ractor::{concurrency::JoinHandle, Actor, ActorRef};
use rand::{distributions::Alphanumeric, thread_rng, Rng};
use reqwest::Url;
use sqlx::{types::BigDecimal, PgPool};
use tap_aggregator::server::run_server;
Expand Down Expand Up @@ -60,8 +61,6 @@ lazy_static! {
tap_eip712_domain(1, Address::from([0x11u8; 20]),);
}

pub static PREFIX_ID: AtomicU32 = AtomicU32::new(0);

pub const TRIGGER_VALUE: u128 = 500;
pub const RECEIPT_LIMIT: u64 = 10000;
pub const DUMMY_URL: &str = "http://localhost:1234";
Expand All @@ -74,6 +73,16 @@ const TAP_SENDER_TIMEOUT: Duration = Duration::from_secs(30);
const RAV_REQUEST_BUFFER: Duration = Duration::from_secs(60);
const ESCROW_POLLING_INTERVAL: Duration = Duration::from_secs(30);

/// Generates a random prefix to be used for actor registry
pub fn generate_random_prefix() -> String {
const SIZE: usize = 16;
thread_rng()
.sample_iter(&Alphanumeric)
.take(SIZE)
.map(char::from)
.collect()
}

pub fn get_sender_account_config() -> &'static SenderAccountConfig {
Box::leak(Box::new(SenderAccountConfig {
rav_request_buffer: RAV_REQUEST_BUFFER,
Expand Down Expand Up @@ -141,10 +150,7 @@ pub async fn create_sender_account(
))
.expect("Failed to update escrow_accounts channel");

let prefix = format!(
"test-{}",
PREFIX_ID.fetch_add(1, std::sync::atomic::Ordering::SeqCst)
);
let prefix = generate_random_prefix();

let aggregator_url = match aggregator_endpoint {
Some(url) => url,
Expand Down Expand Up @@ -215,10 +221,7 @@ pub async fn create_sender_accounts_manager(
))
.expect("Failed to update escrow_accounts channel");

let prefix = format!(
"test-{}",
PREFIX_ID.fetch_add(1, std::sync::atomic::Ordering::SeqCst)
);
let prefix = generate_random_prefix();
let args = SenderAccountsManagerArgs {
config,
domain_separator: TAP_EIP712_DOMAIN_SEPARATOR.clone(),
Expand Down

0 comments on commit b9de96f

Please sign in to comment.