From 0f38c4cd1d52e217332243d7af5c2db3613aab98 Mon Sep 17 00:00:00 2001 From: Macpie Date: Fri, 3 May 2024 13:40:19 -0700 Subject: [PATCH] Move MockHexBoostingClient to common --- mobile_verifier/tests/common/mod.rs | 36 ++++++++++++++++++++++++ mobile_verifier/tests/hex_boosting.rs | 35 ++--------------------- mobile_verifier/tests/rewarder_poc_dc.rs | 36 +----------------------- 3 files changed, 39 insertions(+), 68 deletions(-) diff --git a/mobile_verifier/tests/common/mod.rs b/mobile_verifier/tests/common/mod.rs index 35c1c6aad..026c0b594 100644 --- a/mobile_verifier/tests/common/mod.rs +++ b/mobile_verifier/tests/common/mod.rs @@ -1,4 +1,6 @@ +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, @@ -6,9 +8,43 @@ use helium_proto::{ }, 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, +} + +// 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) -> Self { + Self { boosted_hexes } + } +} + +#[async_trait] +impl HexBoostingInfoResolver for MockHexBoostingClient { + type Error = ClientError; + + async fn stream_boosted_hexes_info(&mut self) -> Result { + Ok(stream::iter(self.boosted_hexes.clone()).boxed()) + } + + async fn stream_modified_boosted_hexes_info( + &mut self, + _timestamp: DateTime, + ) -> Result { + Ok(stream::iter(self.boosted_hexes.clone()).boxed()) + } +} pub struct MockFileSinkReceiver { pub receiver: tokio::sync::mpsc::Receiver, diff --git a/mobile_verifier/tests/hex_boosting.rs b/mobile_verifier/tests/hex_boosting.rs index bea18ba03..c85ad0dd1 100644 --- a/mobile_verifier/tests/hex_boosting.rs +++ b/mobile_verifier/tests/hex_boosting.rs @@ -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}, @@ -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, -} - -impl MockHexBoostingClient { - fn new(boosted_hexes: Vec) -> Self { - Self { boosted_hexes } - } -} - -#[async_trait] -impl HexBoostingInfoResolver for MockHexBoostingClient { - type Error = ClientError; - - async fn stream_boosted_hexes_info(&mut self) -> Result { - Ok(stream::iter(self.boosted_hexes.clone()).boxed()) - } - - async fn stream_modified_boosted_hexes_info( - &mut self, - _timestamp: DateTime, - ) -> Result { - 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( diff --git a/mobile_verifier/tests/rewarder_poc_dc.rs b/mobile_verifier/tests/rewarder_poc_dc.rs index 1b92b212b..842c4979b 100644 --- a/mobile_verifier/tests/rewarder_poc_dc.rs +++ b/mobile_verifier/tests/rewarder_poc_dc.rs @@ -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}, @@ -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, -} - -impl MockHexBoostingClient { - fn new(boosted_hexes: Vec) -> Self { - Self { boosted_hexes } - } -} - -#[async_trait] -impl HexBoostingInfoResolver for MockHexBoostingClient { - type Error = ClientError; - - async fn stream_boosted_hexes_info(&mut self) -> Result { - Ok(stream::iter(self.boosted_hexes.clone()).boxed()) - } - - async fn stream_modified_boosted_hexes_info( - &mut self, - _timestamp: DateTime, - ) -> Result { - 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();