Skip to content

Commit

Permalink
fix(node): move reward test calc before storecost check for better co…
Browse files Browse the repository at this point in the history
…nsistency
  • Loading branch information
joshuef authored and bochaco committed Oct 11, 2023
1 parent dafcaea commit 9e356b3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sn_node/tests/nodes_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ async fn nodes_rewards_for_storing_chunks() -> Result<()> {

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

let prev_rewards_balance = current_rewards_balance()?;
let cost = wallet_client
.pay_for_storage(
chunks
Expand All @@ -59,7 +60,6 @@ async fn nodes_rewards_for_storing_chunks() -> Result<()> {
)
.await?;

let prev_rewards_balance = current_rewards_balance()?;
let expected_rewards_balance = prev_rewards_balance
.checked_add(cost)
.ok_or_else(|| eyre!("Failed to sum up rewards balance"))?;
Expand Down Expand Up @@ -87,6 +87,10 @@ async fn nodes_rewards_for_storing_registers() -> Result<()> {
let owner_pk = client.signer_pk();
let register_addr = XorName::random(&mut rng);

// check the rewards balance before paying for the storage
// this avoids issues if the balance changed before the storage was paid
let prev_rewards_balance = current_rewards_balance()?;

let cost = wallet_client
.pay_for_storage(
std::iter::once(NetworkAddress::RegisterAddress(RegisterAddress::new(
Expand All @@ -97,7 +101,6 @@ async fn nodes_rewards_for_storing_registers() -> Result<()> {
)
.await?;

let prev_rewards_balance = current_rewards_balance()?;
let expected_rewards_balance = prev_rewards_balance
.checked_add(cost)
.ok_or_else(|| eyre!("Failed to sum up rewards balance"))?;
Expand Down

0 comments on commit 9e356b3

Please sign in to comment.