Skip to content

Commit

Permalink
chore: use a random model in recon tests
Browse files Browse the repository at this point in the history
don't hard code model to avoid syncing previous data when starting new test. this is a valid test, but different than what we've done so far.
  • Loading branch information
dav1do committed May 13, 2024
1 parent b514e4c commit bff2549
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
26 changes: 21 additions & 5 deletions runner/src/scenario/recon_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::str::FromStr;
use std::sync::atomic::AtomicU64;
use std::{sync::Arc, time::Duration};

use ceramic_http_client::ceramic_event::StreamId;
use ceramic_http_client::ceramic_event::{StreamId, StreamIdType};
use goose::prelude::*;
use tracing::{info, instrument};

Expand Down Expand Up @@ -69,10 +69,14 @@ async fn setup(user: &mut GooseUser, redis_cli: redis::Client) -> TransactionRes
let model_id = if first {
info!("creating model for event ID sync test");
// We only need a model ID we do not need it to be a real model.
// CID version mismatch between c1 versions so we just hard code one
let model_id =
StreamId::from_str("kjzl6kcym7w8y7nzgytqayf6aro12zt0mm01n6ydjomyvvklcspx9kr6gpbwd09")
.unwrap();
// CID version mismatch between http/c1 versions right now
let cid = random_cid().unwrap();
// could hard code an ID if we wanted the test to be different
let model_id = StreamId {
r#type: StreamIdType::Model,
cid,
};

set_key_to_stream_id(&mut conn, MODEL_ID_KEY, &model_id).await;

// TODO: set a real model
Expand Down Expand Up @@ -143,3 +147,15 @@ async fn create_new_event(user: &mut GooseUser) -> TransactionResult {
const SORT_KEY: &str = "model";
// hard code test controller in case we want to find/prune later
const TEST_CONTROLLER: &str = "did:key:z6MkoFUppcKEVYTS8oVidrja94UoJTatNhnhxJRKF7NYPScS";

// TODO: delete. mismatch between http and c1 versions currently. in flight updates.
fn random_cid() -> anyhow::Result<ceramic_http_client::ceramic_event::Cid> {
use multihash_codetable::MultihashDigest;

let mut data = [0u8; 8];
rand::Rng::fill(&mut rand::thread_rng(), &mut data);
let hash = multihash_codetable::Code::Sha2_256.digest(data.as_slice());
let hash = multibase::encode(multibase::Base::Base36Lower, hash.to_bytes());
let cid = ceramic_http_client::ceramic_event::Cid::from_str(&hash)?;
Ok(cid)
}
9 changes: 1 addition & 8 deletions runner/src/scenario/util.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::io::Write;

use base64::{engine::general_purpose, Engine};
use ceramic_core::{Cid, DagCborEncoded};
use goose::GooseError;
use ipld_core::ipld;
Expand Down Expand Up @@ -46,7 +45,7 @@ pub fn create_stream() -> anyhow::Result<(

let genesis_commit = ipld!({
"header": {
"unique": stream_unique_header(),
"unique": gen_rand_bytes::<12>().as_slice(),
"controllers": [controller]
}
});
Expand All @@ -59,12 +58,6 @@ pub fn create_stream() -> anyhow::Result<(
Ok((stream_id, cid, bytes))
}

fn stream_unique_header() -> String {
let mut data = [0u8; 8];
thread_rng().fill(&mut data);
general_purpose::STANDARD.encode(data)
}

const STREAMID_CODEC: u64 = 206;

pub fn write_stream_bytes(cid: &Cid) -> anyhow::Result<Vec<u8>> {
Expand Down

0 comments on commit bff2549

Please sign in to comment.