Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions iot_verifier/src/reward_share.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,28 @@ mod test {
(value / (*DC_USD_PRICE)).round_dp_with_strategy(0, RoundingStrategy::ToNegativeInfinity)
}

fn default_rewards_info(total_emissions: u64, epoch_duration: Duration) -> EpochRewardInfo {
fn rewards_info_1_hour() -> EpochRewardInfo {
let now = Utc::now();
let epoch_duration = Duration::hours(1);
EpochRewardInfo {
epoch_day: 1,
epoch_address: EPOCH_ADDRESS.into(),
sub_dao_address: SUB_DAO_ADDRESS.into(),
epoch_period: (now - epoch_duration)..now,
epoch_emissions: Decimal::from(total_emissions),
epoch_emissions: dec!(100_000_000_000_000),
rewards_issued_at: now,
}
}

fn rewards_info_10_minutes() -> EpochRewardInfo {
let now = Utc::now();
let epoch_duration = Duration::minutes(10);
EpochRewardInfo {
epoch_day: 1,
epoch_address: EPOCH_ADDRESS.into(),
sub_dao_address: SUB_DAO_ADDRESS.into(),
epoch_period: (now - epoch_duration)..now,
epoch_emissions: Decimal::from(EMISSIONS_POOL_IN_BONES_10_MINUTES),
rewards_issued_at: now,
}
}
Expand All @@ -486,7 +500,7 @@ mod test {
#[test]
fn test_poc_scheduled_tokens() {
// set our rewards info
let rewards_info = default_rewards_info(100_000_000_000_000, Duration::hours(1));
let rewards_info = rewards_info_1_hour();
let (beacon_v, witness_v) = get_scheduled_poc_tokens(rewards_info.epoch_emissions, dec!(0));
assert_eq!(dec!(6_000_000_000_000), beacon_v);
assert_eq!(dec!(24_000_000_000_000), witness_v);
Expand All @@ -495,7 +509,7 @@ mod test {
#[test]
fn test_poc_scheduled_tokens_with_dc_remainder() {
// set our rewards info
let rewards_info = default_rewards_info(100_000_000_000_000, Duration::hours(1));
let rewards_info = rewards_info_1_hour();
let (beacon_v, witness_v) =
get_scheduled_poc_tokens(rewards_info.epoch_emissions, dec!(1_000_000_000_000));
assert_eq!(dec!(6_200_000_000_000), beacon_v);
Expand All @@ -505,15 +519,15 @@ mod test {
#[test]
fn test_op_fund_scheduled_tokens() {
// set our rewards info
let rewards_info = default_rewards_info(100_000_000_000_000, Duration::hours(1));
let rewards_info = rewards_info_1_hour();
let v = get_scheduled_ops_fund_tokens(rewards_info.epoch_emissions);
assert_eq!(dec!(7_000_000_000_000), v);
}

#[test]
fn test_oracles_scheduled_tokens() {
// set our rewards info
let rewards_info = default_rewards_info(100_000_000_000_000, Duration::hours(1));
let rewards_info = rewards_info_1_hour();
let v = get_scheduled_oracle_tokens(rewards_info.epoch_emissions);
assert_eq!(dec!(7_000_000_000_000), v);
}
Expand Down Expand Up @@ -559,8 +573,7 @@ mod test {
.parse()
.expect("failed gw6 parse");

let reward_info =
default_rewards_info(EMISSIONS_POOL_IN_BONES_10_MINUTES, Duration::minutes(10));
let reward_info = rewards_info_10_minutes();
let total_data_transfer_tokens_for_period =
get_scheduled_dc_tokens(reward_info.epoch_emissions);
println!("total data transfer scheduled tokens: {total_data_transfer_tokens_for_period}");
Expand Down Expand Up @@ -774,8 +787,7 @@ mod test {
.parse()
.expect("failed gw6 parse");

let reward_info =
default_rewards_info(EMISSIONS_POOL_IN_BONES_10_MINUTES, Duration::minutes(10));
let reward_info = rewards_info_10_minutes();
let total_data_transfer_tokens_for_period =
get_scheduled_dc_tokens(reward_info.epoch_emissions);
println!("total data transfer scheduled tokens: {total_data_transfer_tokens_for_period}");
Expand Down Expand Up @@ -974,8 +986,7 @@ mod test {
.parse()
.expect("failed gw6 parse");

let reward_info =
default_rewards_info(EMISSIONS_POOL_IN_BONES_10_MINUTES, Duration::minutes(10));
let reward_info = rewards_info_10_minutes();
let total_data_transfer_tokens_for_period =
get_scheduled_dc_tokens(reward_info.epoch_emissions);
println!("total_data_transfer_tokens_for_period: {total_data_transfer_tokens_for_period}");
Expand Down
5 changes: 3 additions & 2 deletions iot_verifier/tests/integrations/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ pub const EPOCH_ADDRESS: &str = "112E7TxoNHV46M6tiPA8N1MkeMeQxc9ztb4JQLXBVAAUfq1
pub const SUB_DAO_ADDRESS: &str = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6";
pub const EMISSIONS_POOL_IN_BONES_24_HOURS: u64 = 89_041_095_890_411;

pub fn default_rewards_info(total_emissions: u64, epoch_duration: Duration) -> EpochRewardInfo {
pub fn rewards_info_24_hours() -> EpochRewardInfo {
let now = Utc::now();
let epoch_duration = Duration::hours(24);
EpochRewardInfo {
epoch_day: 1,
epoch_address: EPOCH_ADDRESS.into(),
sub_dao_address: SUB_DAO_ADDRESS.into(),
epoch_period: (now - epoch_duration)..now,
epoch_emissions: Decimal::from(total_emissions),
epoch_emissions: Decimal::from(EMISSIONS_POOL_IN_BONES_24_HOURS),
rewards_issued_at: now,
}
}
Expand Down
7 changes: 2 additions & 5 deletions iot_verifier/tests/integrations/rewarder_operations.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::common::{
self, default_rewards_info, MockFileSinkReceiver, EMISSIONS_POOL_IN_BONES_24_HOURS,
};
use chrono::Duration;
use crate::common::{self, rewards_info_24_hours, MockFileSinkReceiver};
use helium_proto::services::poc_lora::{IotRewardShare, OperationalReward};
use iot_verifier::{reward_share, rewarder};
use rust_decimal::{prelude::ToPrimitive, Decimal, RoundingStrategy};
Expand All @@ -11,7 +8,7 @@ use rust_decimal_macros::dec;
async fn test_operations() -> anyhow::Result<()> {
let (iot_rewards_client, mut iot_rewards) = common::create_file_sink();

let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24));
let reward_info = rewards_info_24_hours();

let (_, rewards) = tokio::join!(
rewarder::reward_operational(&iot_rewards_client, &reward_info),
Expand Down
7 changes: 2 additions & 5 deletions iot_verifier/tests/integrations/rewarder_oracles.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::common::{
self, default_rewards_info, MockFileSinkReceiver, EMISSIONS_POOL_IN_BONES_24_HOURS,
};
use chrono::Duration;
use crate::common::{self, rewards_info_24_hours, MockFileSinkReceiver};
use helium_proto::services::poc_lora::{IotRewardShare, UnallocatedReward};
use iot_verifier::{reward_share, rewarder};
use rust_decimal::{prelude::ToPrimitive, Decimal, RoundingStrategy};
Expand All @@ -12,7 +9,7 @@ use sqlx::PgPool;
async fn test_oracles(_pool: PgPool) -> anyhow::Result<()> {
let (iot_rewards_client, mut iot_rewards) = common::create_file_sink();

let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24));
let reward_info = rewards_info_24_hours();

let (_, rewards) = tokio::join!(
rewarder::reward_oracles(&iot_rewards_client, &reward_info),
Expand Down
9 changes: 3 additions & 6 deletions iot_verifier/tests/integrations/rewarder_poc_dc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use crate::common::{
self, default_price_info, default_rewards_info, MockFileSinkReceiver,
EMISSIONS_POOL_IN_BONES_24_HOURS,
};
use chrono::{DateTime, Duration as ChronoDuration, Duration, Utc};
use crate::common::{self, default_price_info, rewards_info_24_hours, MockFileSinkReceiver};
use chrono::{DateTime, Duration as ChronoDuration, Utc};
use helium_crypto::PublicKeyBinary;
use helium_proto::services::poc_lora::{
GatewayReward, IotRewardShare, UnallocatedReward, UnallocatedRewardType,
Expand All @@ -27,7 +24,7 @@ const HOTSPOT_4: &str = "11eX55faMbqZB7jzN4p67m6w7ScPMH6ubnvCjCPLh72J49PaJEL";
async fn test_poc_and_dc_rewards(pool: PgPool) -> anyhow::Result<()> {
let (iot_rewards_client, mut iot_rewards) = common::create_file_sink();

let reward_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24));
let reward_info = rewards_info_24_hours();

let price_info = default_price_info();

Expand Down
66 changes: 36 additions & 30 deletions mobile_verifier/src/reward_shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,14 +795,28 @@ mod test {
(hnt_value / DC_USD_PRICE).round_dp_with_strategy(0, RoundingStrategy::ToNegativeInfinity)
}

fn default_rewards_info(total_emissions: u64, epoch_duration: Duration) -> EpochRewardInfo {
fn rewards_info_1_hour() -> EpochRewardInfo {
let now = Utc::now();
let epoch_duration = Duration::hours(1);
EpochRewardInfo {
epoch_day: 1,
epoch_address: EPOCH_ADDRESS.into(),
sub_dao_address: SUB_DAO_ADDRESS.into(),
epoch_period: (now - epoch_duration)..now,
epoch_emissions: Decimal::from(total_emissions),
epoch_emissions: Decimal::from(EMISSIONS_POOL_IN_BONES_1_HOUR),
rewards_issued_at: now,
}
}

fn rewards_info_24_hours() -> EpochRewardInfo {
let now = Utc::now();
let epoch_duration = Duration::hours(1);
EpochRewardInfo {
epoch_day: 1,
epoch_address: EPOCH_ADDRESS.into(),
sub_dao_address: SUB_DAO_ADDRESS.into(),
epoch_period: (now - epoch_duration)..now,
epoch_emissions: Decimal::from(EMISSIONS_POOL_IN_BONES_24_HOURS),
rewards_issued_at: now,
}
}
Expand All @@ -813,30 +827,26 @@ mod test {

#[test]
fn test_poc_scheduled_tokens() {
let rewards_info = default_rewards_info(100_000_000_000_000, Duration::hours(1));
let v = get_scheduled_tokens_for_poc(rewards_info.epoch_emissions);
assert_eq!(dec!(60_000_000_000_000), v);
let v = get_scheduled_tokens_for_poc(dec!(100));
assert_eq!(dec!(60), v, "poc gets 60%");
}

#[test]
fn test_mappers_scheduled_tokens() {
let rewards_info = default_rewards_info(100_000_000_000_000, Duration::hours(1));
let v = get_scheduled_tokens_for_mappers(rewards_info.epoch_emissions);
assert_eq!(dec!(20_000_000_000_000), v);
let v = get_scheduled_tokens_for_mappers(dec!(100));
assert_eq!(dec!(20), v, "mappers get 20%");
}

#[test]
fn test_service_provider_scheduled_tokens() {
let rewards_info = default_rewards_info(100_000_000_000_000, Duration::hours(1));
let v = get_scheduled_tokens_for_service_providers(rewards_info.epoch_emissions);
assert_eq!(dec!(10_000_000_000_000), v);
let v = get_scheduled_tokens_for_service_providers(dec!(100));
assert_eq!(dec!(10), v, "service providers get 10%");
}

#[test]
fn test_oracles_scheduled_tokens() {
let rewards_info = default_rewards_info(100_000_000_000_000, Duration::hours(1));
let v = get_scheduled_tokens_for_oracles(rewards_info.epoch_emissions);
assert_eq!(dec!(4_000_000_000_000), v);
let v = get_scheduled_tokens_for_oracles(dec!(100));
assert_eq!(dec!(4), v, "oracles get 4%");
}

#[test]
Expand Down Expand Up @@ -867,8 +877,7 @@ mod test {
}

// set our rewards info
let rewards_info =
default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24));
let rewards_info = rewards_info_24_hours();

// translate location shares into shares
let shares = MapperShares::new(mapping_activity_shares);
Expand Down Expand Up @@ -947,7 +956,7 @@ mod test {
},
);

let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1));
let rewards_info = rewards_info_1_hour();

let total_rewards = get_scheduled_tokens_for_poc(rewards_info.epoch_emissions);

Expand Down Expand Up @@ -1012,8 +1021,7 @@ mod test {
.unwrap();

// set our rewards info
let rewards_info =
default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24));
let rewards_info = rewards_info_24_hours();

let price_info = default_price_info();
assert_eq!(price_info.price_per_token, dec!(100000000));
Expand Down Expand Up @@ -1213,8 +1221,7 @@ mod test {

let speedtest_avgs = SpeedtestAverages { averages };

let rewards_info =
default_rewards_info(EMISSIONS_POOL_IN_BONES_24_HOURS, Duration::hours(24));
let rewards_info = rewards_info_24_hours();

let reward_shares = new_poc_only(rewards_info.epoch_emissions);

Expand Down Expand Up @@ -1388,7 +1395,7 @@ mod test {
// calculate the rewards for the sample group
let mut owner_rewards = HashMap::<PublicKeyBinary, u64>::new();

let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1));
let rewards_info = rewards_info_1_hour();

let reward_shares = new_poc_only(rewards_info.epoch_emissions);

Expand Down Expand Up @@ -1533,7 +1540,7 @@ mod test {
let mut owner_rewards = HashMap::<PublicKeyBinary, u64>::new();
let duration = Duration::hours(1);
let epoch = (now - duration)..now;
let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1));
let rewards_info = rewards_info_1_hour();

let reward_shares = new_poc_only(rewards_info.epoch_emissions);
let unique_connection_counts = HashMap::from([(gw1.clone(), 42)]);
Expand Down Expand Up @@ -1591,7 +1598,7 @@ mod test {
let now = Utc::now();
// We should never see any radio shares from owner2, since all of them are
// less than or equal to zero.
let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1));
let rewards_info = rewards_info_1_hour();

let uuid_1 = Uuid::new_v4();
let uuid_2 = Uuid::new_v4();
Expand Down Expand Up @@ -1703,7 +1710,7 @@ mod test {

#[tokio::test]
async fn skip_empty_radio_rewards() {
let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1));
let rewards_info = rewards_info_1_hour();
let coverage_shares = CoverageShares {
coverage_map: coverage_map::CoverageMapBuilder::default()
.build(&BoostedHexes::default(), rewards_info.epoch_period.start),
Expand All @@ -1722,7 +1729,7 @@ mod test {

let sp1 = ServiceProvider::HeliumMobile;

let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1));
let rewards_info = rewards_info_1_hour();

let total_sp_rewards = service_provider::get_scheduled_tokens(rewards_info.epoch_emissions);
let sp_reward_infos = ServiceProviderRewardInfos::new(
Expand Down Expand Up @@ -1762,7 +1769,7 @@ mod test {
let hnt_bone_price = dec!(1.0);
let sp1 = ServiceProvider::HeliumMobile;

let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1));
let rewards_info = rewards_info_1_hour();

let total_sp_rewards_in_bones = dec!(1_0000_0000);
let total_rewards_value_in_dc = hnt_bones_to_dc(total_sp_rewards_in_bones, hnt_bone_price);
Expand Down Expand Up @@ -1809,7 +1816,7 @@ mod test {
let hnt_bone_price = dec!(0.0001) / dec!(1_0000_0000);
let sp1 = ServiceProvider::HeliumMobile;

let rewards_info = default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(1));
let rewards_info = rewards_info_1_hour();

let total_sp_rewards_in_bones = dec!(500_000_000) * dec!(1_0000_0000);

Expand Down Expand Up @@ -1853,8 +1860,7 @@ mod test {
let hnt_bone_price = dec!(0.0001) / dec!(1_0000_0000);
let sp1 = ServiceProvider::HeliumMobile;

let rewards_info =
default_rewards_info(EMISSIONS_POOL_IN_BONES_1_HOUR, Duration::hours(24));
let rewards_info = rewards_info_1_hour();
let total_sp_rewards_in_bones = dec!(500_000_000) * dec!(1_0000_0000);

let sp_reward_infos = ServiceProviderRewardInfos::new(
Expand Down
Loading