Skip to content

Commit

Permalink
Move MockHexBoostingClient to common
Browse files Browse the repository at this point in the history
  • Loading branch information
macpie committed May 3, 2024
1 parent 15ce03d commit 0f38c4c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 68 deletions.
36 changes: 36 additions & 0 deletions mobile_verifier/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,50 @@
use chrono::{DateTime, Utc};
use file_store::file_sink::{FileSinkClient, Message as SinkMessage};
use futures::{stream, StreamExt};
use helium_proto::{
services::poc_mobile::{
mobile_reward_share::Reward as MobileReward, GatewayReward, MobileRewardShare, RadioReward,
ServiceProviderReward, SpeedtestAvg, SubscriberReward, UnallocatedReward,
},
Message,
};
use mobile_config::{
boosted_hex_info::{BoostedHexInfo, BoostedHexInfoStream},
client::{hex_boosting_client::HexBoostingInfoResolver, ClientError},
};
use mobile_verifier::boosting_oracles::{Assignment, BoostedHexAssignments, HexAssignments};
use std::collections::HashMap;
use tokio::{sync::mpsc::error::TryRecvError, time::timeout};
use tonic::async_trait;

#[derive(Debug, Clone)]
pub struct MockHexBoostingClient {
boosted_hexes: Vec<BoostedHexInfo>,
}

// this fn is actually used but clippy is unhappy bc it's only used in tests...
#[allow(dead_code)]
impl MockHexBoostingClient {
pub fn new(boosted_hexes: Vec<BoostedHexInfo>) -> Self {
Self { boosted_hexes }
}
}

#[async_trait]
impl HexBoostingInfoResolver for MockHexBoostingClient {
type Error = ClientError;

async fn stream_boosted_hexes_info(&mut self) -> Result<BoostedHexInfoStream, ClientError> {
Ok(stream::iter(self.boosted_hexes.clone()).boxed())
}

async fn stream_modified_boosted_hexes_info(
&mut self,
_timestamp: DateTime<Utc>,
) -> Result<BoostedHexInfoStream, ClientError> {
Ok(stream::iter(self.boosted_hexes.clone()).boxed())
}
}

pub struct MockFileSinkReceiver {
pub receiver: tokio::sync::mpsc::Receiver<SinkMessage>,
Expand Down
35 changes: 2 additions & 33 deletions mobile_verifier/tests/hex_boosting.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
mod common;
use crate::common::MockFileSinkReceiver;
use async_trait::async_trait;
use chrono::{DateTime, Duration as ChronoDuration, Duration, Utc};
use common::MockHexBoostingClient;
use file_store::{
coverage::{CoverageObject as FSCoverageObject, KeyType, RadioHexSignalLevel},
mobile_radio_threshold::{RadioThresholdIngestReport, RadioThresholdReportReq},
speedtest::CellSpeedtest,
};
use futures_util::{stream, StreamExt as FuturesStreamExt};
use helium_crypto::PublicKeyBinary;
use helium_proto::services::poc_mobile::{
CoverageObjectValidity, HeartbeatValidity, RadioReward, SeniorityUpdateReason, SignalLevel,
UnallocatedReward,
};
use hextree::Cell;
use mobile_config::{
boosted_hex_info::{BoostedHexInfo, BoostedHexInfoStream},
client::{hex_boosting_client::HexBoostingInfoResolver, ClientError},
};
use mobile_config::boosted_hex_info::BoostedHexInfo;
use mobile_verifier::{
cell_type::CellType,
coverage::{set_oracle_boosting_assignments, CoverageObject, UnassignedHex},
Expand All @@ -39,33 +35,6 @@ const CARRIER_HOTSPOT_KEY: &str = "11hd7HoicRgBPjBGcqcT2Y9hRQovdZeff5eKFMbCSuDYQ
const BOOST_HEX_PUBKEY: &str = "J9JiLTpjaShxL8eMvUs8txVw6TZ36E38SiJ89NxnMbLU";
const BOOST_CONFIG_PUBKEY: &str = "BZM1QTud72B2cpTW7PhEnFmRX7ZWzvY7DpPpNJJuDrWG";

#[derive(Debug, Clone)]
pub struct MockHexBoostingClient {
pub boosted_hexes: Vec<BoostedHexInfo>,
}

impl MockHexBoostingClient {
fn new(boosted_hexes: Vec<BoostedHexInfo>) -> Self {
Self { boosted_hexes }
}
}

#[async_trait]
impl HexBoostingInfoResolver for MockHexBoostingClient {
type Error = ClientError;

async fn stream_boosted_hexes_info(&mut self) -> Result<BoostedHexInfoStream, ClientError> {
Ok(stream::iter(self.boosted_hexes.clone()).boxed())
}

async fn stream_modified_boosted_hexes_info(
&mut self,
_timestamp: DateTime<Utc>,
) -> Result<BoostedHexInfoStream, ClientError> {
Ok(stream::iter(self.boosted_hexes.clone()).boxed())
}
}

async fn update_assignments(pool: &PgPool) -> anyhow::Result<()> {
let unassigned_hexes = UnassignedHex::fetch(pool);
let _ = set_oracle_boosting_assignments(
Expand Down
36 changes: 1 addition & 35 deletions mobile_verifier/tests/rewarder_poc_dc.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
mod common;
use crate::common::MockFileSinkReceiver;
use async_trait::async_trait;
use crate::common::{MockFileSinkReceiver, MockHexBoostingClient};
use chrono::{DateTime, Duration as ChronoDuration, Utc};
use file_store::{
coverage::{CoverageObject as FSCoverageObject, KeyType, RadioHexSignalLevel},
speedtest::CellSpeedtest,
};
use futures_util::{stream, StreamExt as FuturesStreamExt};
use helium_crypto::PublicKeyBinary;
use helium_proto::services::poc_mobile::{
CoverageObjectValidity, GatewayReward, HeartbeatValidity, RadioReward, SeniorityUpdateReason,
SignalLevel, UnallocatedReward, UnallocatedRewardType,
};
use mobile_config::{
boosted_hex_info::{BoostedHexInfo, BoostedHexInfoStream},
client::{hex_boosting_client::HexBoostingInfoResolver, ClientError},
};
use mobile_verifier::{
cell_type::CellType,
coverage::{set_oracle_boosting_assignments, CoverageObject, UnassignedHex},
Expand All @@ -32,34 +26,6 @@ const HOTSPOT_1: &str = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6";
const HOTSPOT_2: &str = "11uJHS2YaEWJqgqC7yza9uvSmpv5FWoMQXiP8WbxBGgNUmifUJf";
const HOTSPOT_3: &str = "112E7TxoNHV46M6tiPA8N1MkeMeQxc9ztb4JQLXBVAAUfq1kJLoF";
const PAYER_1: &str = "11eX55faMbqZB7jzN4p67m6w7ScPMH6ubnvCjCPLh72J49PaJEL";

#[derive(Debug, Clone)]
pub struct MockHexBoostingClient {
pub boosted_hexes: Vec<BoostedHexInfo>,
}

impl MockHexBoostingClient {
fn new(boosted_hexes: Vec<BoostedHexInfo>) -> Self {
Self { boosted_hexes }
}
}

#[async_trait]
impl HexBoostingInfoResolver for MockHexBoostingClient {
type Error = ClientError;

async fn stream_boosted_hexes_info(&mut self) -> Result<BoostedHexInfoStream, ClientError> {
Ok(stream::iter(self.boosted_hexes.clone()).boxed())
}

async fn stream_modified_boosted_hexes_info(
&mut self,
_timestamp: DateTime<Utc>,
) -> Result<BoostedHexInfoStream, ClientError> {
Ok(stream::iter(self.boosted_hexes.clone()).boxed())
}
}

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

0 comments on commit 0f38c4c

Please sign in to comment.