Skip to content

Commit

Permalink
Make CoverageObjectReqV1 valid
Browse files Browse the repository at this point in the history
  • Loading branch information
macpie committed Jun 6, 2024
1 parent 5b95628 commit 4939f76
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,19 @@ VALUES
'verifier'
) ON CONFLICT (pubkey, key_role) DO
UPDATE
SET
updated_at = CURRENT_TIMESTAMP;

INSERT INTO
registered_keys (pubkey, key_role, created_at, updated_at, name)
VALUES
(
'13te9quF3s24VNrQmBRHnoNSwWPg48Jh2hfJdqFQoiFYiDcDAsp',
'pcs',
CURRENT_TIMESTAMP,
CURRENT_TIMESTAMP,
'Authorized Coverage Object Key'
) ON CONFLICT (pubkey, key_role) DO
UPDATE
SET
updated_at = CURRENT_TIMESTAMP;
4 changes: 3 additions & 1 deletion test_mobile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@
**NOTE:** The test will `docker compose up` on start and `docker compose stop` at the end. It is up to **you** to `docker compose down` if you want to clean up.

[^files]: Maps of hexes used
![Hexes](docs/hexes.jpg "Hexes")
![Hexes](docs/hexes.jpg "Hexes")

key pair for coverage object `13te9quF3s24VNrQmBRHnoNSwWPg48Jh2hfJdqFQoiFYiDcDAsp`
24 changes: 14 additions & 10 deletions test_mobile/tests/common/hotspot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ use anyhow::Result;
use backon::{ExponentialBuilder, Retryable};
use chrono::Utc;
use h3o::CellIndex;
use helium_crypto::{KeyTag, Keypair, PublicKeyBinary, Sign};
use helium_crypto::{Keypair, PublicKeyBinary, Sign};
use helium_proto::services::poc_mobile::{
coverage_object_req_v1::KeyType, Client as PocMobileClient, CoverageObjectReqV1,
RadioHexSignalLevel, SpeedtestReqV1, WifiHeartbeatReqV1,
};
use prost::Message;
use rand::rngs::OsRng;
use sqlx::postgres::PgPoolOptions;
use std::str::FromStr;
use std::{str::FromStr, sync::Arc};
use tonic::{metadata::MetadataValue, transport::Channel, Request};
use tracing::instrument;
use uuid::Uuid;

use crate::common::{hours_ago, now, TimestampToDateTime};
use crate::common::{generate_keypair, hours_ago, now, TimestampToDateTime};

#[derive(Debug)]
pub struct Hotspot {
Expand All @@ -36,8 +35,8 @@ impl Hotspot {
.await
.expect("client connect");

let keypair = Keypair::generate(KeyTag::default(), &mut OsRng);
let wallet = Keypair::generate(KeyTag::default(), &mut OsRng);
let keypair = generate_keypair();
let wallet = generate_keypair();
let b58 = keypair.public_key().to_string();

tracing::info!(hotspot = b58, "hotspot connected to ingester");
Expand Down Expand Up @@ -98,12 +97,16 @@ impl Hotspot {
}

#[instrument(skip(self), fields(hotspot = %self.b58))]
pub async fn submit_coverage_object(&mut self, uuid: Uuid) -> Result<()> {
pub async fn submit_coverage_object(
&mut self,
uuid: Uuid,
pcs_keypair: Arc<Keypair>,
) -> Result<()> {
let coverage_claim_time = now() - hours_ago(24);
let pub_key = self.keypair.public_key().to_vec();

let mut coverage_object_req = CoverageObjectReqV1 {
pub_key: pub_key.clone(),
pub_key: pcs_keypair.public_key().to_vec(),
uuid: uuid.as_bytes().to_vec(),
coverage_claim_time,
coverage: vec![RadioHexSignalLevel {
Expand All @@ -117,8 +120,7 @@ impl Hotspot {
key_type: Some(KeyType::HotspotKey(pub_key)),
};

coverage_object_req.signature = self
.keypair
coverage_object_req.signature = pcs_keypair
.sign(&coverage_object_req.encode_to_vec())
.expect("sign");

Expand Down Expand Up @@ -266,5 +268,7 @@ async fn populate_mobile_metadata(
.execute(&pool)
.await?;

pool.close().await;

Ok(())
}
20 changes: 18 additions & 2 deletions test_mobile/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use std::time::{SystemTime, UNIX_EPOCH};

use anyhow::Result;
use chrono::{DateTime, NaiveDateTime, TimeZone, Utc};
use helium_crypto::{KeyTag, Keypair};
use rand::rngs::OsRng;
use std::{
sync::Arc,
time::{SystemTime, UNIX_EPOCH},
};
use tracing::instrument;

pub mod docker;
pub mod hotspot;
Expand Down Expand Up @@ -28,3 +34,13 @@ pub fn now() -> u64 {
pub fn hours_ago(hours: i64) -> u64 {
chrono::Duration::hours(hours).num_milliseconds() as u64
}

pub fn generate_keypair() -> Keypair {
Keypair::generate(KeyTag::default(), &mut OsRng)
}

pub async fn load_pcs_keypair() -> Result<Arc<Keypair>> {
let data = std::fs::read("tests/pc_keypair.bin").map_err(helium_crypto::Error::from)?;
let pcs_keypair = Arc::new(helium_crypto::Keypair::try_from(&data[..])?);
Ok(pcs_keypair)
}
8 changes: 6 additions & 2 deletions test_mobile/tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::Result;
use common::{docker::Docker, hotspot::Hotspot, hours_ago};
use common::{docker::Docker, hotspot::Hotspot, hours_ago, load_pcs_keypair};
use test_mobile::cli::assignment::CENTER_CELL;
use uuid::Uuid;

Expand All @@ -24,12 +24,16 @@ async fn main() -> Result<()> {
}
}

let pcs_keypair = load_pcs_keypair().await?;

let api_token = "api-token".to_string();

let mut hotspot1 = Hotspot::new(api_token, CENTER_CELL).await?;
let co_uuid = Uuid::new_v4();

hotspot1.submit_coverage_object(co_uuid).await?;
hotspot1
.submit_coverage_object(co_uuid, pcs_keypair.clone())
.await?;

hotspot1
.submit_speedtest(500_000_000, 500_000_000, 25)
Expand Down
Binary file added test_mobile/tests/pc_keypair.bin
Binary file not shown.

0 comments on commit 4939f76

Please sign in to comment.