Skip to content

Commit

Permalink
fix bad test file merge after merging unrebased branch (#845)
Browse files Browse the repository at this point in the history
mobile-rewards-v2 integration branch was based off the hip-119 branch.
The hip-119 branch was merged, then the v2 inteagration branch was
merged directly after without rebasing it onto master.

Somehow, this resulted in a duplicate test.
  • Loading branch information
michaeldjeffrey authored Jul 17, 2024
1 parent d24c9f6 commit 632b995
Showing 1 changed file with 0 additions and 179 deletions.
179 changes: 0 additions & 179 deletions mobile_verifier/tests/integrations/hex_boosting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,185 +1074,6 @@ async fn test_distance_from_asserted_removes_boosting_but_not_location_trust(
Ok(())
}

#[sqlx::test]
async fn test_distance_from_asserted_removes_boosting_but_not_location_trust(
pool: PgPool,
) -> anyhow::Result<()> {
let (mobile_rewards_client, mut mobile_rewards) = common::create_file_sink();
let (speedtest_avg_client, _speedtest_avg_server) = common::create_file_sink();
let now = Utc::now();
let epoch = (now - ChronoDuration::hours(24))..now;
let epoch_duration = epoch.end - epoch.start;
let boost_period_length = Duration::days(30);

// seed all the things
let mut txn = pool.clone().begin().await?;
seed_heartbeats_with_location_trust(
epoch.start,
&mut txn,
// hotspot 1 can receive boosting
HotspotLocationTrust {
meters: 10,
multiplier: dec!(1.0),
},
// hotspot 2 can receive boosting but has no boosted hexes
HotspotLocationTrust {
meters: 10,
multiplier: dec!(1.0),
},
// hotspot 3 is too far for boosting
HotspotLocationTrust {
meters: 100,
multiplier: dec!(1.0),
},
)
.await?;
seed_speedtests(epoch.end, &mut txn).await?;
seed_radio_thresholds(epoch.start, &mut txn).await?;
txn.commit().await?;
update_assignments(&pool).await?;

// setup boosted hex where reward start time is in the second period length
let multipliers1 = vec![NonZeroU32::new(2).unwrap()];
let start_ts_1 = epoch.start;
let end_ts_1 = start_ts_1 + (boost_period_length * multipliers1.len() as i32);

// setup boosted hex where no start or end time is set
let multipliers2 = vec![NonZeroU32::new(2).unwrap()];

let boosted_hexes = vec![
BoostedHexInfo {
// hotspot 1's location
location: Cell::from_raw(0x8a1fb466d2dffff_u64)?,
start_ts: Some(start_ts_1),
end_ts: Some(end_ts_1),
period_length: boost_period_length,
multipliers: multipliers1,
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
},
BoostedHexInfo {
// hotspot 3's location
location: Cell::from_raw(0x8c2681a306607ff_u64)?,
start_ts: None,
end_ts: None,
period_length: boost_period_length,
multipliers: multipliers2,
boosted_hex_pubkey: Pubkey::from_str(BOOST_HEX_PUBKEY).unwrap(),
boost_config_pubkey: Pubkey::from_str(BOOST_CONFIG_PUBKEY).unwrap(),
version: 0,
},
];

let hex_boosting_client = MockHexBoostingClient::new(boosted_hexes);
let total_poc_emissions = reward_shares::get_scheduled_tokens_for_poc(epoch_duration)
.to_u64()
.unwrap();

let (_, rewards) = tokio::join!(
// run rewards for poc and dc
rewarder::reward_poc_and_dc(
&pool,
&hex_boosting_client,
&mobile_rewards_client,
&speedtest_avg_client,
&epoch,
dec!(0.0001)
),
receive_expected_rewards_maybe_unallocated(
&mut mobile_rewards,
ExpectUnallocated::NoWhenValue(total_poc_emissions)
)
);

let Ok((poc_rewards, unallocated_reward)) = rewards else {
panic!("no rewards received");
};

let mut poc_rewards = poc_rewards.iter();
let hotspot_2 = poc_rewards.next().unwrap(); // full location trust NO boosts
let hotspot_1 = poc_rewards.next().unwrap(); // full location trust 1 boost
let hotspot_3 = poc_rewards.next().unwrap(); // reduced location trust 1 boost
assert_eq!(
None,
poc_rewards.next(),
"Received more hotspots than expected in rewards"
);
assert_eq!(
HOTSPOT_1.to_string(),
PublicKeyBinary::from(hotspot_1.hotspot_key.clone()).to_string()
);
assert_eq!(
HOTSPOT_2.to_string(),
PublicKeyBinary::from(hotspot_2.hotspot_key.clone()).to_string()
);
assert_eq!(
HOTSPOT_3.to_string(),
PublicKeyBinary::from(hotspot_3.hotspot_key.clone()).to_string()
);

// Calculating expected rewards
let (regular_poc, boosted_poc) = get_poc_allocation_buckets(epoch_duration);

// Here's how we get the regular shares per coverage points
// | base coverage point | speedtest | location | total |
// |---------------------|-----------|----------|-------|
// | 400 | 0.75 | 1.00 | 300 |
// | 400 | 0.75 | 1.00 | 300 |
// | 400 | 0.75 | 1.00 | 300 |
// |---------------------|-----------|----------|-------|
// | 900 |
let regular_share = regular_poc / dec!(900);

// Boosted hexes are 2x, only one radio qualifies based on the location trust
// 300 * 1 == 300
// To get points _only_ from boosting.
let boosted_share = boosted_poc / dec!(300);

let exp_reward_1 =
rounded(regular_share * dec!(300)) + rounded(boosted_share * dec!(300) * dec!(1));
let exp_reward_2 =
rounded(regular_share * dec!(300)) + rounded(boosted_share * dec!(300) * dec!(0));
let exp_reward_3 =
rounded(regular_share * dec!(300)) + rounded(boosted_share * dec!(300) * dec!(0));

assert_eq!(exp_reward_1, hotspot_1.poc_reward);
assert_eq!(exp_reward_2, hotspot_2.poc_reward);
assert_eq!(exp_reward_3, hotspot_3.poc_reward);

// assert the number of boosted hexes for each radio
//hotspot 1 has one boosted hex
assert_eq!(1, hotspot_1.boosted_hexes.len());
//hotspot 2 has no boosted hexes
assert_eq!(0, hotspot_2.boosted_hexes.len());
// hotspot 3 has a boosted location but as its location trust score
// is reduced the boost does not get applied
assert_eq!(0, hotspot_3.boosted_hexes.len());

// assert the hex boost multiplier values
// assert_eq!(2, hotspot_1.boosted_hexes[0].multiplier);
assert_eq!(2, hotspot_1.boosted_hexes[0].multiplier);
assert_eq!(0x8a1fb466d2dffff_u64, hotspot_1.boosted_hexes[0].location);

// confirm the total rewards allocated matches expectations
let poc_sum = hotspot_1.poc_reward + hotspot_2.poc_reward + hotspot_3.poc_reward;
let total = poc_sum + unallocated_reward.amount;

let expected_sum = reward_shares::get_scheduled_tokens_for_poc(epoch.end - epoch.start)
.to_u64()
.unwrap();
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(())
}

#[sqlx::test]
async fn test_poc_with_cbrs_and_multi_coverage_boosted_hexes(pool: PgPool) -> anyhow::Result<()> {
let (mobile_rewards_client, mut mobile_rewards) = common::create_file_sink();
Expand Down

0 comments on commit 632b995

Please sign in to comment.