diff --git a/mobile_config/src/client/carrier_service_client.rs b/mobile_config/src/client/carrier_service_client.rs index 653968ca4..55267c237 100644 --- a/mobile_config/src/client/carrier_service_client.rs +++ b/mobile_config/src/client/carrier_service_client.rs @@ -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) diff --git a/mobile_config/src/client/mod.rs b/mobile_config/src/client/mod.rs index 6aa7a3d9d..9b24eb38a 100644 --- a/mobile_config/src/client/mod.rs +++ b/mobile_config/src/client/mod.rs @@ -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), diff --git a/mobile_verifier/src/reward_shares.rs b/mobile_verifier/src/reward_shares.rs index 193b9b38a..5b078a988 100644 --- a/mobile_verifier/src/reward_shares.rs +++ b/mobile_verifier/src/reward_shares.rs @@ -336,7 +336,7 @@ impl ServiceProviderShares { fn entity_key_to_service_provider(key: &str) -> anyhow::Result { match key { "Helium Mobile" => Ok(ServiceProvider::HeliumMobile), - _ => bail!("invalid service provider name"), + _ => bail!("unknown service provider name"), } } } diff --git a/mobile_verifier/src/rewarder.rs b/mobile_verifier/src/rewarder.rs index dc77a737c..795ee2af7 100644 --- a/mobile_verifier/src/rewarder.rs +++ b/mobile_verifier/src/rewarder.rs @@ -410,7 +410,7 @@ pub async fn reward_oracles( pub async fn reward_service_providers( pool: &Pool, - carrier_client: &dyn CarrierServiceVerifier, + carrier_client: &impl CarrierServiceVerifier, mobile_rewards: &FileSinkClient, reward_period: &Range>, mobile_bone_price: Decimal, diff --git a/mobile_verifier/tests/rewarder_mappers.rs b/mobile_verifier/tests/rewarder_mappers.rs index 6f6c77d53..b7d95f30a 100644 --- a/mobile_verifier/tests/rewarder_mappers.rs +++ b/mobile_verifier/tests/rewarder_mappers.rs @@ -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; @@ -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!( @@ -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(()) diff --git a/mobile_verifier/tests/rewarder_oracles.rs b/mobile_verifier/tests/rewarder_oracles.rs index a0d331d7c..90c493b6b 100644 --- a/mobile_verifier/tests/rewarder_oracles.rs +++ b/mobile_verifier/tests/rewarder_oracles.rs @@ -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] @@ -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(()) diff --git a/mobile_verifier/tests/rewarder_poc_dc.rs b/mobile_verifier/tests/rewarder_poc_dc.rs index 45874b707..36b508cba 100644 --- a/mobile_verifier/tests/rewarder_poc_dc.rs +++ b/mobile_verifier/tests/rewarder_poc_dc.rs @@ -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() @@ -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() @@ -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(()) @@ -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, }; @@ -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, }; @@ -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, }; diff --git a/mobile_verifier/tests/rewarder_sp_rewards.rs b/mobile_verifier/tests/rewarder_sp_rewards.rs index 0ef911e3e..d3657d632 100644 --- a/mobile_verifier/tests/rewarder_sp_rewards.rs +++ b/mobile_verifier/tests/rewarder_sp_rewards.rs @@ -38,7 +38,7 @@ impl CarrierServiceVerifier for MockCarrierServiceClient { async fn key_to_rewardable_entity<'a>(&self, pubkey: &'a str) -> Result { match self.valid_sps.get(pubkey) { Some(v) => Ok(v.clone()), - None => Err(ClientError::NotFound(pubkey.to_string())), + None => Err(ClientError::UnknownServiceProvider), } } } @@ -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) @@ -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(()) @@ -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(()) }