From 7f448a7316f9c1fd35bb2e0e93d68e5817db611e Mon Sep 17 00:00:00 2001 From: Michael Jeffrey Date: Thu, 5 Sep 2024 17:18:53 -0700 Subject: [PATCH] update hex boosting tests for radio_reward_v2 It becomes more difficult to compare ratios with radio_reward_v2 because boosted rewards are scaled. In many of the test we were hoping to have nice ratios (1:10) of poc_rewards. However, this was mostly because a radio would have received 0 boosted_rewards. Checking that ratio is impossible. We can however check the coverage_points (now that they mean points, and not rewards) for the expected ratio, and rely on other tests to ensure we're calculating poc_reward amount correctly. --- .../tests/coverage_point_calculator.rs | 1 + .../tests/integrations/hex_boosting.rs | 55 ++++++++++--------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/coverage_point_calculator/tests/coverage_point_calculator.rs b/coverage_point_calculator/tests/coverage_point_calculator.rs index b7027ac92..646e9f97c 100644 --- a/coverage_point_calculator/tests/coverage_point_calculator.rs +++ b/coverage_point_calculator/tests/coverage_point_calculator.rs @@ -402,6 +402,7 @@ impl BoostedHexMap for NoBoostedHexes { fn get_current_multiplier( &self, _cell: hextree::Cell, + _device_type: coverage_map::DeviceType, _ts: chrono::DateTime, ) -> Option { None diff --git a/mobile_verifier/tests/integrations/hex_boosting.rs b/mobile_verifier/tests/integrations/hex_boosting.rs index 76b62361a..a72fb18db 100644 --- a/mobile_verifier/tests/integrations/hex_boosting.rs +++ b/mobile_verifier/tests/integrations/hex_boosting.rs @@ -965,6 +965,7 @@ async fn test_distance_from_asserted_removes_boosting_but_not_location_trust( boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(), boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(), version: 0, + device_type: BoostedHexDeviceType::All, }, BoostedHexInfo { // hotspot 3's location @@ -976,6 +977,7 @@ async fn test_distance_from_asserted_removes_boosting_but_not_location_trust( boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(), boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(), version: 0, + device_type: BoostedHexDeviceType::All, }, ]; @@ -1367,17 +1369,18 @@ async fn test_poc_boosted_hex_stack_multiplier(pool: PgPool) -> anyhow::Result<( ); let [radio_one, radio_two] = &poc_rewards; + assert_eq!( - radio_one.coverage_points, radio_two.coverage_points, - "radios perform equally unboosted" - ); - assert_eq!( - radio_one.poc_reward, radio_two.poc_reward, + radio_one.total_poc_reward(), + radio_two.total_poc_reward(), "radios earn equally unboosted" ); // Make sure there were no unallocated rewards - let total = poc_rewards.iter().map(|r| r.poc_reward).sum::(); + let total = poc_rewards + .iter() + .map(|r| r.total_poc_reward()) + .sum::(); assert_eq!( reward_shares::get_scheduled_tokens_for_poc(epoch.end - epoch.start) .to_u64() @@ -1435,32 +1438,28 @@ async fn test_poc_boosted_hex_stack_multiplier(pool: PgPool) -> anyhow::Result<( ); // sort by rewards ascending - poc_rewards.sort_by_key(|r| r.poc_reward); + poc_rewards.sort_by_key(|r| r.total_poc_reward()); let [unboosted, boosted] = &poc_rewards; - let boosted_hex = boosted.boosted_hexes.first().expect("boosted hex"); - assert_eq!(10, boosted_hex.multiplier); + let boosted_hexes = boosted.boosted_hexes(); + let boosted_hex = boosted_hexes.first().expect("boosted hex"); + assert_eq!(10, boosted_hex.boosted_multiplier); assert_eq!( 10, - boosted.coverage_points / unboosted.coverage_points, + boosted.total_coverage_points() / unboosted.total_coverage_points(), "boosted radio should have 10x coverage_points" ); - assert_eq!( - 10, - boosted.poc_reward / unboosted.poc_reward, - "boosted radio should have 10x poc_rewards" - ); - // Make sure there were no unallocated rewards - let total = poc_rewards.iter().map(|r| r.poc_reward).sum::(); - assert_eq!( - reward_shares::get_scheduled_tokens_for_poc(epoch.end - epoch.start) - .to_u64() - .unwrap(), - total, - "allocated equals scheduled output" - ); + // We expect a single unallocated + let total = poc_rewards + .iter() + .map(|r| r.total_poc_reward()) + .sum::(); + let allocated = reward_shares::get_scheduled_tokens_for_poc(epoch.end - epoch.start) + .to_u64() + .unwrap(); + assert_eq!(allocated - 1, total, "allocated equals scheduled output"); } Ok(()) @@ -1553,8 +1552,11 @@ async fn test_poc_boosted_hex_only_applies_to_device_type(pool: PgPool) -> anyho let wifi1 = poc_rewards_map.get(wifi_pubkey1.as_ref()).unwrap(); let wifi2 = poc_rewards_map.get(wifi_pubkey2.as_ref()).unwrap(); - assert_eq!(5, boosted_cbrs.poc_reward / unboosted_cbrs.poc_reward,); - assert_eq!(wifi1.poc_reward, wifi2.poc_reward); + assert_eq!( + 5, + boosted_cbrs.total_coverage_points() / unboosted_cbrs.total_coverage_points(), + ); + assert_eq!(wifi1.total_coverage_points(), wifi2.total_coverage_points()); Ok(()) } @@ -2249,6 +2251,7 @@ impl HexBoostableRadio { coverage_object: Some(cov_obj.coverage_object.uuid), location_validation_timestamp: Some(time_behind), timestamp: time_ahead, + location_source: LocationSource::Skyhook, }, cell_type: CellType::NovaGenericWifiIndoor, distance_to_asserted: Some(10),