Skip to content

Commit

Permalink
Merge pull request #803 from helium/macpie/clippy_fix
Browse files Browse the repository at this point in the history
Fix clippy
  • Loading branch information
macpie authored May 3, 2024
2 parents 6d198bf + 0f38c4c commit 5816910
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 85 deletions.
6 changes: 0 additions & 6 deletions boost_manager/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ use file_store::file_sink::{FileSinkClient, Message as SinkMessage};
use helium_proto::BoostedHexInfoV1 as BoostedHexInfoProto;
use helium_proto::BoostedHexUpdateV1 as BoostedHexUpdateProto;
use helium_proto::Message;
use mobile_config::boosted_hex_info::BoostedHexInfo;
use tokio::{sync::mpsc::error::TryRecvError, time::timeout};

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

pub struct MockFileSinkReceiver {
pub receiver: tokio::sync::mpsc::Receiver<SinkMessage>,
}
Expand Down
7 changes: 6 additions & 1 deletion boost_manager/tests/watcher_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod common;
use crate::common::{MockFileSinkReceiver, MockHexBoostingClient};
use crate::common::MockFileSinkReceiver;
use async_trait::async_trait;
use boost_manager::watcher::{self, Watcher};
use chrono::{DateTime, Duration as ChronoDuration, Duration, Utc};
Expand All @@ -16,6 +16,11 @@ use std::{num::NonZeroU32, str::FromStr};
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 }
Expand Down
39 changes: 31 additions & 8 deletions mobile_verifier/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,49 @@
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;
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};

pub type ValidSpMap = HashMap<String, String>;
use tonic::async_trait;

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

#[derive(Debug, Clone)]
pub struct MockHexBoostingClient {
pub 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 {
Expand Down
32 changes: 3 additions & 29 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, MockHexBoostingClient};
use async_trait::async_trait;
use crate::common::MockFileSinkReceiver;
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,28 +35,6 @@ const CARRIER_HOTSPOT_KEY: &str = "11hd7HoicRgBPjBGcqcT2Y9hRQovdZeff5eKFMbCSuDYQ
const BOOST_HEX_PUBKEY: &str = "J9JiLTpjaShxL8eMvUs8txVw6TZ36E38SiJ89NxnMbLU";
const BOOST_CONFIG_PUBKEY: &str = "BZM1QTud72B2cpTW7PhEnFmRX7ZWzvY7DpPpNJJuDrWG";

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
39 changes: 0 additions & 39 deletions mobile_verifier/tests/rewarder_poc_dc.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
mod common;
use crate::common::{MockFileSinkReceiver, MockHexBoostingClient};
use async_trait::async_trait;
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},
data_session,
geofence::GeofenceValidator,
heartbeats::{HbType, Heartbeat, ValidatedHeartbeat},
reward_shares, rewarder, speedtests,
};
Expand All @@ -33,38 +26,6 @@ const HOTSPOT_1: &str = "112NqN2WWMwtK29PMzRby62fDydBJfsCLkCAf392stdok48ovNT6";
const HOTSPOT_2: &str = "11uJHS2YaEWJqgqC7yza9uvSmpv5FWoMQXiP8WbxBGgNUmifUJf";
const HOTSPOT_3: &str = "112E7TxoNHV46M6tiPA8N1MkeMeQxc9ztb4JQLXBVAAUfq1kJLoF";
const PAYER_1: &str = "11eX55faMbqZB7jzN4p67m6w7ScPMH6ubnvCjCPLh72J49PaJEL";

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())
}
}

#[derive(Clone)]
struct MockGeofence;

impl GeofenceValidator<hextree::Cell> for MockGeofence {
fn in_valid_region(&self, _cell: &hextree::Cell) -> bool {
true
}
}

#[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
9 changes: 7 additions & 2 deletions mobile_verifier/tests/rewarder_sp_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use rust_decimal::prelude::*;
use rust_decimal_macros::dec;
use sqlx::{PgPool, Postgres, Transaction};

use common::MockCarrierServiceClient;
use common::ValidSpMap;
use mobile_config::client::{carrier_service_client::CarrierServiceVerifier, ClientError};
use mobile_verifier::{data_session, reward_shares, rewarder};

Expand All @@ -26,6 +24,13 @@ const PAYER_1: &str = "11uJHS2YaEWJqgqC7yza9uvSmpv5FWoMQXiP8WbxBGgNUmifUJf";
const PAYER_2: &str = "11sctWiP9r5wDJVuDe1Th4XSL2vaawaLLSQF8f8iokAoMAJHxqp";
const SP_1: &str = "Helium Mobile";

pub type ValidSpMap = HashMap<String, String>;

#[derive(Debug, Clone)]
pub struct MockCarrierServiceClient {
pub valid_sps: ValidSpMap,
}

impl MockCarrierServiceClient {
fn new(valid_sps: ValidSpMap) -> Self {
Self { valid_sps }
Expand Down

0 comments on commit 5816910

Please sign in to comment.