Skip to content

Commit

Permalink
fix: couting correct royalty transfer notif
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed Nov 3, 2023
1 parent c1e4dc0 commit 8e74013
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions sn_node/tests/nodes_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,14 @@ async fn nodes_rewards_for_chunks_notifs_over_gossipsub() -> Result<()> {
)?;

println!("Paying for {} random addresses...", chunks.len());

let royalties_pk = NETWORK_ROYALTIES_PK.public_key();
let handle =
spawn_royalties_payment_listener("https://127.0.0.1:12001".to_string(), royalties_pk, true);
let handle = spawn_royalties_payment_listener(
"https://127.0.0.1:12001".to_string(),

Check notice

Code scanning / devskim

Accessing localhost could indicate debug code, or could hinder scaling. Note

Do not leave debug code in production
royalties_pk,
true,
chunks.len(),
);

let _cost = files_api
.pay_and_upload_bytes_test(*content_addr.xorname(), chunks)
Expand Down Expand Up @@ -157,9 +162,14 @@ async fn nodes_rewards_for_register_notifs_over_gossipsub() -> Result<()> {
let register_addr = XorName::random(&mut rng);

println!("Paying for random Register address {register_addr:?} ...");

let royalties_pk = NETWORK_ROYALTIES_PK.public_key();
let handle =
spawn_royalties_payment_listener("https://127.0.0.1:12001".to_string(), royalties_pk, true);
let handle = spawn_royalties_payment_listener(
"https://127.0.0.1:12001".to_string(),

Check notice

Code scanning / devskim

Accessing localhost could indicate debug code, or could hinder scaling. Note

Do not leave debug code in production
royalties_pk,
true,
1,
);

let _register = client
.create_and_pay_for_register(register_addr, &mut wallet_client, true)
Expand Down Expand Up @@ -192,17 +202,26 @@ async fn nodes_rewards_transfer_notifs_filter() -> Result<()> {

// this node shall receive the notifications since we set the correct royalties pk as filter
let royalties_pk = NETWORK_ROYALTIES_PK.public_key();
let handle_1 =
spawn_royalties_payment_listener("https://127.0.0.1:12001".to_string(), royalties_pk, true);
let handle_1 = spawn_royalties_payment_listener(
"https://127.0.0.1:12001".to_string(),

Check notice

Code scanning / devskim

Accessing localhost could indicate debug code, or could hinder scaling. Note

Do not leave debug code in production
royalties_pk,
true,
chunks.len(),
);
// this other node shall *not* receive any notification since we set the wrong pk as filter
let random_pk = SecretKey::random().public_key();
let handle_2 =
spawn_royalties_payment_listener("https://127.0.0.1:12002".to_string(), random_pk, true);
let handle_2 = spawn_royalties_payment_listener(
"https://127.0.0.1:12002".to_string(),

Check notice

Code scanning / devskim

Accessing localhost could indicate debug code, or could hinder scaling. Note

Do not leave debug code in production
random_pk,
true,
chunks.len(),
);
// this other node shall *not* receive any notification either since we don't set any pk as filter
let handle_3 = spawn_royalties_payment_listener(
"https://127.0.0.1:12003".to_string(),
royalties_pk,
false,
chunks.len(),
);

let _cost = files_api
Expand Down Expand Up @@ -275,6 +294,7 @@ fn spawn_royalties_payment_listener(
endpoint: String,
royalties_pk: PublicKey,
set_fiter: bool,
expected_cout: usize,
) -> JoinHandle<Result<usize, eyre::Report>> {
tokio::spawn(async move {
let mut rpc_client = SafeNodeClient::connect(endpoint).await?;
Expand All @@ -287,7 +307,7 @@ fn spawn_royalties_payment_listener(
.await?;
}

let royalty_topic: &str = "ROYALTY_TRANSFER";
let royalty_topic: &str = "TRANSFER_NOTIFICATION";
let _ = rpc_client
.subscribe_to_topic(Request::new(GossipsubSubscribeRequest {
topic: royalty_topic.to_string(),
Expand All @@ -310,7 +330,8 @@ fn spawn_royalties_payment_listener(
println!("Transfer notif received for key {key:?}");
if key == royalties_pk {
count += 1;
if count == CLOSE_GROUP_SIZE {
println!("Received {count}/{expected_cout} royalty notifs so far");
if count == expected_cout {
break;
}
}
Expand Down

0 comments on commit 8e74013

Please sign in to comment.