Skip to content

Commit

Permalink
Implement HIP-113 - Cannot be deployed until 2024-05-10 (#787)
Browse files Browse the repository at this point in the history
* Implement HIP-113

* Update test to reflect new values
  • Loading branch information
bbalser authored May 9, 2024
1 parent 9dbcf00 commit e186ac7
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 79 deletions.
40 changes: 23 additions & 17 deletions mobile_verifier/src/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,11 @@ impl Ord for IndoorCoverageLevel {

impl IndoorCoverageLevel {
fn coverage_points(&self) -> Decimal {
match self.signal_level {
SignalLevel::High => dec!(400),
SignalLevel::Low => dec!(100),
match (&self.radio_key, self.signal_level) {
(OwnedKeyType::Wifi(_), SignalLevel::High) => dec!(400),
(OwnedKeyType::Wifi(_), SignalLevel::Low) => dec!(100),
(OwnedKeyType::Cbrs(_), SignalLevel::High) => dec!(100),
(OwnedKeyType::Cbrs(_), SignalLevel::Low) => dec!(25),
_ => dec!(0),
}
}
Expand Down Expand Up @@ -585,11 +587,15 @@ impl Ord for OutdoorCoverageLevel {

impl OutdoorCoverageLevel {
fn coverage_points(&self) -> Decimal {
match self.signal_level {
SignalLevel::High => dec!(16),
SignalLevel::Medium => dec!(8),
SignalLevel::Low => dec!(4),
SignalLevel::None => dec!(0),
match (&self.radio_key, self.signal_level) {
(OwnedKeyType::Wifi(_), SignalLevel::High) => dec!(16),
(OwnedKeyType::Wifi(_), SignalLevel::Medium) => dec!(8),
(OwnedKeyType::Wifi(_), SignalLevel::Low) => dec!(4),
(OwnedKeyType::Wifi(_), SignalLevel::None) => dec!(0),
(OwnedKeyType::Cbrs(_), SignalLevel::High) => dec!(4),
(OwnedKeyType::Cbrs(_), SignalLevel::Medium) => dec!(2),
(OwnedKeyType::Cbrs(_), SignalLevel::Low) => dec!(1),
(OwnedKeyType::Cbrs(_), SignalLevel::None) => dec!(0),
}
}
}
Expand Down Expand Up @@ -1131,7 +1137,7 @@ mod test {
radio_key: OwnedKeyType::Cbrs("3".to_string()),
hotspot: owner,
points: CoverageRewardPoints {
coverage_points: dec!(400),
coverage_points: dec!(100),
boost_multiplier: NonZeroU32::new(1).unwrap(),
hex_assignments: HexAssignments::test_best(),
rank: None
Expand Down Expand Up @@ -1247,7 +1253,7 @@ mod test {
radio_key: OwnedKeyType::Cbrs("10".to_string()),
hotspot: owner.clone(),
points: CoverageRewardPoints {
coverage_points: dec!(400),
coverage_points: dec!(100),
boost_multiplier: NonZeroU32::new(1).unwrap(),
hex_assignments: HexAssignments::test_best(),
rank: None
Expand Down Expand Up @@ -1290,7 +1296,7 @@ mod test {
radio_key: OwnedKeyType::Cbrs("5".to_string()),
hotspot: owner.clone(),
points: CoverageRewardPoints {
coverage_points: dec!(16),
coverage_points: dec!(4),
rank: Some(dec!(1.0)),
boost_multiplier: NonZeroU32::new(1).unwrap(),
hex_assignments: HexAssignments::test_best(),
Expand All @@ -1304,7 +1310,7 @@ mod test {
radio_key: OwnedKeyType::Cbrs("4".to_string()),
hotspot: owner.clone(),
points: CoverageRewardPoints {
coverage_points: dec!(16),
coverage_points: dec!(4),
rank: Some(dec!(0.50)),
boost_multiplier: NonZeroU32::new(1).unwrap(),
hex_assignments: HexAssignments::test_best(),
Expand All @@ -1318,7 +1324,7 @@ mod test {
radio_key: OwnedKeyType::Cbrs("3".to_string()),
hotspot: owner,
points: CoverageRewardPoints {
coverage_points: dec!(16),
coverage_points: dec!(4),
rank: Some(dec!(0.25)),
boost_multiplier: NonZeroU32::new(1).unwrap(),
hex_assignments: HexAssignments::test_best(),
Expand Down Expand Up @@ -1464,7 +1470,7 @@ mod test {

// assert outdoor cbrs radios
assert_eq!(
dec!(16),
dec!(4),
rewards
.iter()
.find(|r| r.radio_key == OwnedKeyType::Cbrs("oco1-3".to_string()))
Expand All @@ -1474,7 +1480,7 @@ mod test {
);

assert_eq!(
dec!(8),
dec!(2),
rewards
.iter()
.find(|r| r.radio_key == OwnedKeyType::Cbrs("oco1-4".to_string()))
Expand All @@ -1484,7 +1490,7 @@ mod test {
);

assert_eq!(
dec!(4),
dec!(1),
rewards
.iter()
.find(|r| r.radio_key == OwnedKeyType::Cbrs("oco1-1".to_string()))
Expand All @@ -1502,7 +1508,7 @@ mod test {

// assert indoor cbrs radios
assert_eq!(
dec!(400),
dec!(100),
rewards
.iter()
.find(|r| r.radio_key == OwnedKeyType::Cbrs("ico1-1".to_string()))
Expand Down
28 changes: 13 additions & 15 deletions mobile_verifier/src/reward_shares.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1415,31 +1415,31 @@ mod test {
*owner_rewards
.get(&owner1)
.expect("Could not fetch owner1 rewards"),
364_298_724_954
260_213_374_966
);
assert_eq!(
*owner_rewards
.get(&owner2)
.expect("Could not fetch owner2 rewards"),
1_366_120_218_577
975_800_156_122
);
assert_eq!(
*owner_rewards
.get(&owner3)
.expect("Could not fetch owner3 rewards"),
45_537_340_619
32_526_671_870
);
assert_eq!(owner_rewards.get(&owner4), None);

let owner5_reward = *owner_rewards
.get(&owner5)
.expect("Could not fetch owner5 rewards");
assert_eq!(owner5_reward, 182_149_362_477);
assert_eq!(owner5_reward, 520_426_749_934);

let owner6_reward = *owner_rewards
.get(&owner6)
.expect("Could not fetch owner6 rewards");
assert_eq!(owner6_reward, 45_537_340_619);
assert_eq!(owner6_reward, 130_106_687_483);

// confirm owner 6 reward is 0.25 of owner 5's reward
// this is due to owner 6's hotspot not having a validation location timestamp
Expand All @@ -1449,7 +1449,7 @@ mod test {
let owner7_reward = *owner_rewards
.get(&owner6)
.expect("Could not fetch owner7 rewards");
assert_eq!(owner7_reward, 45_537_340_619);
assert_eq!(owner7_reward, 130_106_687_483);

// confirm owner 7 reward is 0.25 of owner 5's reward
// owner 7's hotspot does have a validation location timestamp
Expand All @@ -1458,15 +1458,15 @@ mod test {
assert_eq!((owner5_reward as f64 * 0.25) as u64, owner7_reward);

// confirm total sum of allocated poc rewards
assert_eq!(allocated_poc_rewards, 2_049_180_327_865);
assert_eq!(allocated_poc_rewards, 2_049_180_327_858);

// confirm the unallocated poc reward amounts
let unallocated_sp_reward_amount = (total_poc_rewards
- Decimal::from(allocated_poc_rewards))
.round_dp_with_strategy(0, RoundingStrategy::ToZero)
.to_u64()
.unwrap_or(0);
assert_eq!(unallocated_sp_reward_amount, 3);
assert_eq!(unallocated_sp_reward_amount, 10);
}

#[tokio::test]
Expand Down Expand Up @@ -1583,19 +1583,17 @@ mod test {
}
println!("owner rewards {:?}", owner_rewards);

// These were different, now they are the same:

// wifi
let owner1_reward = *owner_rewards
.get(&owner1)
.expect("Could not fetch owner1 rewards");
assert_eq!(owner1_reward, 1_024_590_163_934);
assert_eq!(owner1_reward, 1_639_344_262_295);

// sercomm
let owner2_reward = *owner_rewards
.get(&owner2)
.expect("Could not fetch owner2 rewards");
assert_eq!(owner2_reward, 1_024_590_163_934);
assert_eq!(owner2_reward, 409_836_065_573);
}

#[tokio::test]
Expand Down Expand Up @@ -1728,7 +1726,7 @@ mod test {
// owner 1 is a wifi indoor with a distance_to_asserted > max
// and so gets the reduced reward scale of 0.1 ( radio reward scale of 0.4 * location scale of 0.25)
// owner 2 is a cbrs sercomm indoor which has a reward scale of 1.0
assert_eq!(owner1_reward, (owner2_reward as f64 * 0.25) as u64);
assert_eq!(owner1_reward, owner2_reward);
}

#[tokio::test]
Expand Down Expand Up @@ -1850,13 +1848,13 @@ mod test {
let owner1_reward = *owner_rewards
.get(&owner1)
.expect("Could not fetch owner1 rewards");
assert_eq!(owner1_reward, 1_024_590_163_934);
assert_eq!(owner1_reward, 1_639_344_262_295);

// sercomm
let owner2_reward = *owner_rewards
.get(&owner2)
.expect("Could not fetch owner2 rewards");
assert_eq!(owner2_reward, 1_024_590_163_934);
assert_eq!(owner2_reward, 409_836_065_573);
}

/// Test to ensure that rewards that are zeroed are not written out.
Expand Down
58 changes: 29 additions & 29 deletions mobile_verifier/tests/integrations/boosting_oracles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,43 +414,43 @@ async fn test_footfall_and_urbanization_and_landtype(pool: PgPool) -> anyhow::Re
// Hex | Assignment | Points Equation | Sum
// -----------------------------------------------
// == yellow - POI ≥ 1 Urbanized
// hex1 | A, A, A | 400 * 1 | 400
// hex2 | A, B, A | 400 * 1 | 400
// hex3 | A, C, A | 400 * 1 | 400
// hex1 | A, A, A | 100 * 1 | 100
// hex2 | A, B, A | 100 * 1 | 100
// hex3 | A, C, A | 100 * 1 | 100
// == orange - POI ≥ 1 Not Urbanized
// hex4 | A, A, B | 400 * 1 | 400
// hex5 | A, B, B | 400 * 1 | 400
// hex6 | A, C, B | 400 * 1 | 400
// hex4 | A, A, B | 100 * 1 | 100
// hex5 | A, B, B | 100 * 1 | 100
// hex6 | A, C, B | 100 * 1 | 100
// == light green - Point of Interest Urbanized
// hex7 | B, A, A | 400 * 0.70 | 280
// hex8 | B, B, A | 400 * 0.70 | 280
// hex9 | B, C, A | 400 * 0.70 | 280
// hex7 | B, A, A | 100 * 0.70 | 70
// hex8 | B, B, A | 100 * 0.70 | 70
// hex9 | B, C, A | 100 * 0.70 | 70
// == dark green - Point of Interest Not Urbanized
// hex10 | B, A, B | 400 * 0.50 | 200
// hex11 | B, B, B | 400 * 0.50 | 200
// hex12 | B, C, B | 400 * 0.50 | 200
// hex10 | B, A, B | 100 * 0.50 | 50
// hex11 | B, B, B | 100 * 0.50 | 50
// hex12 | B, C, B | 100 * 0.50 | 50
// == light blue - No POI Urbanized
// hex13 | C, A, A | 400 * 0.40 | 160
// hex14 | C, B, A | 400 * 0.30 | 120
// hex15 | C, C, A | 400 * 0.05 | 20
// hex13 | C, A, A | 100 * 0.40 | 40
// hex14 | C, B, A | 100 * 0.30 | 30
// hex15 | C, C, A | 100 * 0.05 | 5
// == dark blue - No POI Not Urbanized
// hex16 | C, A, B | 400 * 0.20 | 80
// hex17 | C, B, B | 400 * 0.15 | 60
// hex18 | C, C, B | 400 * 0.03 | 12
// hex16 | C, A, B | 100 * 0.20 | 20
// hex17 | C, B, B | 100 * 0.15 | 15
// hex18 | C, C, B | 100 * 0.03 | 3
// == gray - Outside of USA
// hex19 | A, A, C | 400 * 0.00 | 0
// hex20 | A, B, C | 400 * 0.00 | 0
// hex21 | A, C, C | 400 * 0.00 | 0
// hex22 | B, A, C | 400 * 0.00 | 0
// hex23 | B, B, C | 400 * 0.00 | 0
// hex24 | B, C, C | 400 * 0.00 | 0
// hex25 | C, A, C | 400 * 0.00 | 0
// hex26 | C, B, C | 400 * 0.00 | 0
// hex27 | C, C, C | 400 * 0.00 | 0
// hex19 | A, A, C | 100 * 0.00 | 0
// hex20 | A, B, C | 100 * 0.00 | 0
// hex21 | A, C, C | 100 * 0.00 | 0
// hex22 | B, A, C | 100 * 0.00 | 0
// hex23 | B, B, C | 100 * 0.00 | 0
// hex24 | B, C, C | 100 * 0.00 | 0
// hex25 | C, A, C | 100 * 0.00 | 0
// hex26 | C, B, C | 100 * 0.00 | 0
// hex27 | C, C, C | 100 * 0.00 | 0
// -----------------------------------------------
// = 4,292
// = 1,073

assert_eq!(coverage_points.hotspot_points(&owner), dec!(4292.0));
assert_eq!(coverage_points.hotspot_points(&owner), dec!(1073.0));

Ok(())
}
14 changes: 7 additions & 7 deletions mobile_verifier/tests/integrations/hex_boosting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,9 @@ async fn test_poc_with_cbrs_and_multi_coverage_boosted_hexes(pool: PgPool) -> an
);
if let Ok((poc_rewards, unallocated_reward)) = rewards {
// assert poc reward outputs
let exp_reward_1 = 23_990_403_838_464;
let exp_reward_2 = 23_990_403_838_464;
let exp_reward_3 = 1_199_520_191_923;
let exp_reward_1 = 24_437_429_996_945;
let exp_reward_2 = 24_437_429_996_945;
let exp_reward_3 = 305_467_874_961;

assert_eq!(exp_reward_1, poc_rewards[0].poc_reward);
assert_eq!(
Expand Down Expand Up @@ -963,11 +963,11 @@ async fn test_poc_with_cbrs_and_multi_coverage_boosted_hexes(pool: PgPool) -> an
poc_rewards[0].boosted_hexes[0].location
);

// hotspot1 should have 20x the reward of hotspot 3
assert_eq!(poc_rewards[0].poc_reward / poc_rewards[2].poc_reward, 20);
// hotspot1 should have 20x the reward of hotspot 3
// hotspot1 should have 80x the reward of hotspot 3
assert_eq!(poc_rewards[0].poc_reward / poc_rewards[2].poc_reward, 80);
// hotspot1 should have 80x the reward of hotspot 3
// due to the 2 boosted hexes each with a 10x multiplier
assert_eq!(poc_rewards[1].poc_reward / poc_rewards[2].poc_reward, 20);
assert_eq!(poc_rewards[1].poc_reward / poc_rewards[2].poc_reward, 80);

// confirm the total rewards allocated matches expectations
let poc_sum: u64 = poc_rewards.iter().map(|r| r.poc_reward).sum();
Expand Down
16 changes: 8 additions & 8 deletions mobile_verifier/tests/integrations/modeled_coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ async fn scenario_one(pool: PgPool) -> anyhow::Result<()> {
)
.await?;

assert_eq!(coverage_points.hotspot_points(&owner), dec!(1000));
assert_eq!(coverage_points.hotspot_points(&owner), dec!(250));

Ok(())
}
Expand Down Expand Up @@ -615,8 +615,8 @@ async fn scenario_two(pool: PgPool) -> anyhow::Result<()> {
)
.await?;

assert_eq!(coverage_points.hotspot_points(&owner_1), dec!(450));
assert_eq!(coverage_points.hotspot_points(&owner_2), dec!(1000));
assert_eq!(coverage_points.hotspot_points(&owner_1), dec!(112.5));
assert_eq!(coverage_points.hotspot_points(&owner_2), dec!(250));

Ok(())
}
Expand Down Expand Up @@ -901,7 +901,7 @@ async fn scenario_three(pool: PgPool) -> anyhow::Result<()> {
assert_eq!(coverage_points.hotspot_points(&owner_1), dec!(0));
assert_eq!(coverage_points.hotspot_points(&owner_2), dec!(0));
assert_eq!(coverage_points.hotspot_points(&owner_3), dec!(0));
assert_eq!(coverage_points.hotspot_points(&owner_4), dec!(1000));
assert_eq!(coverage_points.hotspot_points(&owner_4), dec!(250));
assert_eq!(coverage_points.hotspot_points(&owner_5), dec!(0));
assert_eq!(coverage_points.hotspot_points(&owner_6), dec!(0));

Expand Down Expand Up @@ -970,7 +970,7 @@ async fn scenario_four(pool: PgPool) -> anyhow::Result<()> {
)
.await?;

assert_eq!(coverage_points.hotspot_points(&owner), dec!(76));
assert_eq!(coverage_points.hotspot_points(&owner), dec!(19));

Ok(())
}
Expand Down Expand Up @@ -1071,9 +1071,9 @@ async fn scenario_five(pool: PgPool) -> anyhow::Result<()> {

assert_eq!(
coverage_points.hotspot_points(&owner_1),
dec!(76) * dec!(0.5)
dec!(19) * dec!(0.5)
);
assert_eq!(coverage_points.hotspot_points(&owner_2), dec!(32));
assert_eq!(coverage_points.hotspot_points(&owner_2), dec!(8));

Ok(())
}
Expand Down Expand Up @@ -1317,7 +1317,7 @@ async fn scenario_six(pool: PgPool) -> anyhow::Result<()> {
.await?;

assert_eq!(coverage_points.hotspot_points(&owner_1), dec!(0));
assert_eq!(coverage_points.hotspot_points(&owner_2), dec!(250));
assert_eq!(coverage_points.hotspot_points(&owner_2), dec!(62.5));
assert_eq!(coverage_points.hotspot_points(&owner_3), dec!(0));
assert_eq!(coverage_points.hotspot_points(&owner_4), dec!(0));
assert_eq!(coverage_points.hotspot_points(&owner_5), dec!(0));
Expand Down
Loading

0 comments on commit e186ac7

Please sign in to comment.