Skip to content

Commit

Permalink
tweaks and fixes after rebase with latest main
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Jan 5, 2024
1 parent eeb8679 commit 36188b4
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 26 deletions.
2 changes: 1 addition & 1 deletion mobile_config/src/client/carrier_service_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl CarrierServiceVerifier for CarrierServiceClient {
response.verify(&self.config_pubkey)?;
response.entity_key
}
Err(status) => Err(status)?,
Err(_status) => Err(ClientError::UnknownServiceProvider)?,
};
self.cache
.insert(pubkey.to_string(), response.clone(), self.cache_ttl)
Expand Down
2 changes: 1 addition & 1 deletion mobile_config/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub enum ClientError {
VerificationError(#[from] file_store::Error),
#[error("error parsing gateway location {0}")]
LocationParseError(#[from] std::num::ParseIntError),
#[error("unknown service provider")]
#[error("unknown service provider name")]
UnknownServiceProvider,
#[error("not found: {0}")]
NotFound(String),
Expand Down
2 changes: 1 addition & 1 deletion mobile_verifier/src/reward_shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ impl ServiceProviderShares {
fn entity_key_to_service_provider(key: &str) -> anyhow::Result<ServiceProvider> {
match key {
"Helium Mobile" => Ok(ServiceProvider::HeliumMobile),
_ => bail!("invalid service provider name"),
_ => bail!("unknown service provider name"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion mobile_verifier/src/rewarder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ pub async fn reward_oracles(

pub async fn reward_service_providers(
pool: &Pool<Postgres>,
carrier_client: &dyn CarrierServiceVerifier<Error = ClientError>,
carrier_client: &impl CarrierServiceVerifier<Error = ClientError>,
mobile_rewards: &FileSinkClient,
reward_period: &Range<DateTime<Utc>>,
mobile_bone_price: Decimal,
Expand Down
21 changes: 14 additions & 7 deletions mobile_verifier/tests/rewarder_mappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use helium_proto::{
};
use mobile_verifier::{reward_shares, rewarder, subscriber_location};
use rust_decimal::prelude::*;
use rust_decimal_macros::dec;
use sqlx::{PgPool, Postgres, Transaction};
use std::str::FromStr;
use std::string::ToString;
Expand Down Expand Up @@ -41,19 +42,19 @@ async fn test_mapper_rewards(pool: PgPool) -> anyhow::Result<()> {
SUBSCRIBER_1.to_string().encode_to_vec(),
subscriber_rewards[0].subscriber_id
);
assert_eq!(5464480874316, subscriber_rewards[0].discovery_location_amount);
assert_eq!(5_464_480_874_316, subscriber_rewards[0].discovery_location_amount);

assert_eq!(
SUBSCRIBER_2.to_string().encode_to_vec(),
subscriber_rewards[1].subscriber_id
);
assert_eq!(5464480874316, subscriber_rewards[2].discovery_location_amount);
assert_eq!(5_464_480_874_316, subscriber_rewards[2].discovery_location_amount);

assert_eq!(
SUBSCRIBER_3.to_string().encode_to_vec(),
subscriber_rewards[2].subscriber_id
);
assert_eq!(5464480874316, subscriber_rewards[2].discovery_location_amount);
assert_eq!(5_464_480_874_316, subscriber_rewards[2].discovery_location_amount);

// confirm our unallocated amount
assert_eq!(
Expand All @@ -66,13 +67,19 @@ async fn test_mapper_rewards(pool: PgPool) -> anyhow::Result<()> {
let expected_sum = reward_shares::get_scheduled_tokens_for_mappers(epoch.end - epoch.start)
.to_u64()
.unwrap();
assert_eq!(
expected_sum,
subscriber_rewards[0].discovery_location_amount
let subscriber_sum = subscriber_rewards[0].discovery_location_amount
+ subscriber_rewards[1].discovery_location_amount
+ subscriber_rewards[2].discovery_location_amount
+ unallocated_reward.amount
+ unallocated_reward.amount;
assert_eq!(
expected_sum,
subscriber_sum
);

// confirm the rewarded percentage amount matches expectations
let daily_total = reward_shares::get_total_scheduled_tokens(epoch.end - epoch.start);
let percent = (Decimal::from(subscriber_sum) / daily_total).round_dp_with_strategy(2, RoundingStrategy::MidpointNearestEven);
assert_eq!(percent, dec!(0.2));
}
);
Ok(())
Expand Down
8 changes: 7 additions & 1 deletion mobile_verifier/tests/rewarder_oracles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use chrono::{Duration as ChronoDuration, Utc};
use helium_proto::services::poc_mobile::{UnallocatedReward, UnallocatedRewardType};
use mobile_verifier::{reward_shares, rewarder};
use rust_decimal::prelude::*;
use rust_decimal_macros::dec;
use sqlx::PgPool;

#[sqlx::test]
Expand All @@ -21,13 +22,18 @@ async fn test_oracle_rewards(_pool: PgPool) -> anyhow::Result<()> {
unallocated_reward.reward_type
);
// confirm our unallocated amount
assert_eq!(65_573_770_491_803, unallocated_reward.amount);
assert_eq!(3_278_688_524_590, unallocated_reward.amount);

// confirm the total rewards allocated matches expectations
let expected_sum = reward_shares::get_scheduled_tokens_for_oracles(epoch.end - epoch.start)
.to_u64()
.unwrap();
assert_eq!(expected_sum, unallocated_reward.amount);

// confirm the rewarded percentage amount matches expectations
let daily_total = reward_shares::get_total_scheduled_tokens(epoch.end - epoch.start);
let percent = (Decimal::from(unallocated_reward.amount) / daily_total).round_dp_with_strategy(2, RoundingStrategy::MidpointNearestEven);
assert_eq!(percent, dec!(0.04));
}
);
Ok(())
Expand Down
26 changes: 16 additions & 10 deletions mobile_verifier/tests/rewarder_poc_dc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ async fn test_poc_and_dc_rewards(pool: PgPool) -> anyhow::Result<()> {
Ok((poc_rewards, dc_rewards, unallocated_poc_reward)) = receive_expected_rewards(&mut mobile_rewards) => {

// assert poc reward outputs
assert_eq!(24108003121986, poc_rewards[0].poc_reward);
assert_eq!(24_108_003_121_986, poc_rewards[0].poc_reward);
assert_eq!(
HOTSPOT_1.to_string(),
PublicKeyBinary::from(poc_rewards[0].hotspot_key.clone()).to_string()
);
assert_eq!(964320124879, poc_rewards[1].poc_reward);
assert_eq!(964_320_124_879, poc_rewards[1].poc_reward);
assert_eq!(
HOTSPOT_2.to_string(),
PublicKeyBinary::from(poc_rewards[1].hotspot_key.clone()).to_string()
);
assert_eq!(24108003121986, poc_rewards[2].poc_reward);
assert_eq!(24_108_003_121_986, poc_rewards[2].poc_reward);
assert_eq!(
HOTSPOT_3.to_string(),
PublicKeyBinary::from(poc_rewards[2].hotspot_key.clone()).to_string()
Expand All @@ -76,17 +76,17 @@ async fn test_poc_and_dc_rewards(pool: PgPool) -> anyhow::Result<()> {
assert_eq!(1, unallocated_poc_reward.amount);

// assert the dc reward outputs
assert_eq!(500000, dc_rewards[0].dc_transfer_reward);
assert_eq!(500_000, dc_rewards[0].dc_transfer_reward);
assert_eq!(
HOTSPOT_1.to_string(),
PublicKeyBinary::from(dc_rewards[0].hotspot_key.clone()).to_string()
);
assert_eq!(500000, dc_rewards[1].dc_transfer_reward);
assert_eq!(500_000, dc_rewards[1].dc_transfer_reward);
assert_eq!(
HOTSPOT_2.to_string(),
PublicKeyBinary::from(dc_rewards[1].hotspot_key.clone()).to_string()
);
assert_eq!(500000, dc_rewards[2].dc_transfer_reward);
assert_eq!(500_000, dc_rewards[2].dc_transfer_reward);
assert_eq!(
HOTSPOT_3.to_string(),
PublicKeyBinary::from(dc_rewards[2].hotspot_key.clone()).to_string()
Expand All @@ -96,11 +96,17 @@ async fn test_poc_and_dc_rewards(pool: PgPool) -> anyhow::Result<()> {
let poc_sum: u64 = poc_rewards.iter().map(|r| r.poc_reward).sum();
let dc_sum: u64 = dc_rewards.iter().map(|r| r.dc_transfer_reward).sum();
let unallocated_sum: u64 = unallocated_poc_reward.amount;
let total = poc_sum + dc_sum + unallocated_sum;

let expected_sum = reward_shares::get_scheduled_tokens_for_poc(epoch.end - epoch.start)
.to_u64()
.unwrap();
assert_eq!(expected_sum, poc_sum + dc_sum + unallocated_sum);
assert_eq!(expected_sum, total);

// confirm the rewarded percentage amount matches expectations
let daily_total = reward_shares::get_total_scheduled_tokens(epoch.end - epoch.start);
let percent = (Decimal::from(total) / daily_total).round_dp_with_strategy(2, RoundingStrategy::MidpointNearestEven);
assert_eq!(percent, dec!(0.6));
}
);
Ok(())
Expand Down Expand Up @@ -163,7 +169,7 @@ async fn seed_heartbeats(
},
cell_type: CellType::SercommIndoor,
distance_to_asserted: None,
coverage_object_insertion_time: None,
coverage_summary: None,
validity: HeartbeatValidity::Valid,
};

Expand All @@ -190,7 +196,7 @@ async fn seed_heartbeats(
},
cell_type: CellType::SercommOutdoor,
distance_to_asserted: None,
coverage_object_insertion_time: None,
coverage_summary: None,
validity: HeartbeatValidity::Valid,
};

Expand All @@ -216,7 +222,7 @@ async fn seed_heartbeats(
},
cell_type: CellType::NovaGenericWifiIndoor,
distance_to_asserted: Some(10),
coverage_object_insertion_time: None,
coverage_summary: None,
validity: HeartbeatValidity::Valid,
};

Expand Down
11 changes: 7 additions & 4 deletions mobile_verifier/tests/rewarder_sp_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl CarrierServiceVerifier for MockCarrierServiceClient {
async fn key_to_rewardable_entity<'a>(&self, pubkey: &'a str) -> Result<String, ClientError> {
match self.valid_sps.get(pubkey) {
Some(v) => Ok(v.clone()),
None => Err(ClientError::NotFound(pubkey.to_string())),
None => Err(ClientError::UnknownServiceProvider),
}
}
}
Expand Down Expand Up @@ -77,7 +77,6 @@ async fn test_service_provider_rewards(pool: PgPool) -> anyhow::Result<()> {
unallocated_reward.reward_type
);
assert_eq!(8_196_721_305_475, unallocated_reward.amount);
println!("point 1 {:?}", sp_reward);
// confirm the total rewards allocated matches expectations
let expected_sum =
reward_shares::get_scheduled_tokens_for_service_providers(epoch.end - epoch.start)
Expand All @@ -88,6 +87,11 @@ async fn test_service_provider_rewards(pool: PgPool) -> anyhow::Result<()> {
sp_reward.amount + unallocated_reward.amount
);

// confirm the rewarded percentage amount matches expectations
let daily_total = reward_shares::get_total_scheduled_tokens(epoch.end - epoch.start);
let percent = (Decimal::from(unallocated_reward.amount) / daily_total).round_dp_with_strategy(2, RoundingStrategy::MidpointNearestEven);
assert_eq!(percent, dec!(0.1));

}
}
Ok(())
Expand Down Expand Up @@ -119,12 +123,11 @@ async fn test_service_provider_rewards_invalid_sp(pool: PgPool) -> anyhow::Resul
.await;
assert_eq!(
resp.unwrap_err().to_string(),
"not found: 11sctWiP9r5wDJVuDe1Th4XSL2vaawaLLSQF8f8iokAoMAJHxqp".to_string()
"unknown service provider name".to_string()
);

// confirm we get no msgs as rewards halted
mobile_rewards.assert_no_messages();

Ok(())
}

Expand Down

0 comments on commit 36188b4

Please sign in to comment.