Skip to content

Commit

Permalink
Work on tests, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hwood-fg committed Apr 9, 2023
1 parent 21112c7 commit e963957
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 75 deletions.
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions dnas/clutter/coordinator_zomes/mews/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ pub fn mews_feed(_options: FeedOptions) -> ExternResult<Vec<FeedMew>> {

#[hdk_extern]
pub fn recommended(_: ()) -> ExternResult<Vec<FeedMew>> {
let mut feed = Vec::new();
let me = agent_info()?.agent_latest_pubkey;
// let feed = Vec::new();
// let me = agent_info()?.agent_latest_pubkey;
let atoms: Vec<TrustAtom> = call_local_zome(
"trust_atom",
"query_mine",
Expand Down Expand Up @@ -304,7 +304,7 @@ pub fn recommended(_: ()) -> ExternResult<Vec<FeedMew>> {
None => Some(atom), // trust atoms with no value typically mean "yup" without a specific "percent/weight"
});

let mut feed_mews = recomended_tags_by_author
let mut feed_mews: Vec<FeedMew> = recomended_tags_by_author
.map(|atom| {
let followed_author = atom.target_hash;
match atom.content {
Expand All @@ -322,7 +322,7 @@ pub fn recommended(_: ()) -> ExternResult<Vec<FeedMew>> {
}
})
.flatten()
.collect::<Vec<FeedMew>>();
.collect();

// match get_links(followed_author, LinkTypes::Mew, None) {
// Ok(links) => Some(links),
Expand All @@ -343,7 +343,7 @@ pub fn recommended(_: ()) -> ExternResult<Vec<FeedMew>> {
// *buttttt* maybe just chron is good! if only showing last time chunk, or (later) mews since last visit
// it really depends if that last chunk is 100 mews (chron fine) or 10,000 mews (then weight of tags is awesome)

Ok(feed)
Ok(feed_mews)
}

// *** Liking ***
Expand Down
193 changes: 133 additions & 60 deletions dnas/clutter/coordinator_zomes/mews/tests/mews_tests.rs
Original file line number Diff line number Diff line change
@@ -1,85 +1,158 @@
#![warn(warnings)]

use futures::future;

use hdk::prelude::*;
use holochain::sweettest::{
SweetAgents, SweetAppBatch, SweetCell, SweetConductor, SweetConductorBatch, SweetDnaFile,
};
// use hdk::prelude::holo_hash::*;
use holochain::conductor::config::ConductorConfig;
use holochain::sweettest::{SweetConductorBatch, SweetDnaFile};
use holochain::test_utils::consistency_10s;

use mews_integrity::*;

const DNA_FILEPATH: &str = "../../workdir/clutter.dna";

// TESTS:
const ZOME_NAME: &str = "clutter";

#[tokio::test(flavor = "multi_thread")]
pub async fn mew_can_be_200_chars() {
let (conductor, _alice, cell1): (SweetConductor, AgentPubKey, SweetCell) =
setup_1_conductor().await;

let long_mew = std::iter::repeat('a').take(200).collect::<String>();
let create_mew_input = CreateMewInput {
text: Some(long_mew),
mew_type: MewType::Original,
links: None,
};

let mew_hash: ActionHash = conductor
.call(&cell1.zome("mews"), "create_mew", create_mew_input)
async fn trustd_feed_is_based_on_follow_topics() {
// Use prebuilt DNA file
let dna_path = std::env::current_dir().unwrap().join(DNA_FILEPATH);
let dna = SweetDnaFile::from_bundle(&dna_path).await.unwrap();

// Set up conductors
let mut conductors = SweetConductorBatch::from_config(3, ConductorConfig::default()).await;
let apps = conductors.setup_app("clutter", &[dna]).await.unwrap();
conductors.exchange_peer_info().await;

let ((ann,), (bob,), (cat,)) = apps.into_tuples();

let ann_zome = ann.zome(ZOME_NAME);
let bob_zome = bob.zome(ZOME_NAME);
let cat_zome = cat.zome(ZOME_NAME);

// let ann_conductor = conductors[0].clone();
// let bob_conductor = conductors[1].clone();
// let cat_conductor = conductors[2].clone();

let _entry_hash: EntryHash = conductors[0]
.call(
&ann_zome,
"follow",
FollowInput {
agent: bob.agent_pubkey().clone(),
follow_topics: vec![FollowTopicInput {
topic: String::from("kittens"),
weight: String::from("1.0"),
}],
},
)
.await;

let bytes = mew_hash.get_raw_39();
let leading_bytes = bytes.get(..3).unwrap();
assert_eq!(leading_bytes, &[132, 41, 36]);
consistency_10s([&ann, &bob, &cat]).await;

// let applet = AppletInstance {
// custom_name: String::from("custom name"),
// description: String::from("description"),
// logo_src: None,
// devhub_happ_release_hash: fixt!(EntryHash),
// devhub_gui_release_hash: fixt!(EntryHash),

// network_seed: None,
// properties: BTreeMap::new(), // Segmented by RoleId
// dna_hashes: BTreeMap::new(), // Segmented by RoleId
// };

// let _entry_hash: EntryHash = conductors[0]
// .call(&ann_zome, "register_applet_instance", applet)
// .await;

// let all_applets: Vec<Record> = conductors[1]
// .call(&bob_zome, "get_applets_instances", ())
// .await;

// assert_eq!(all_applets.len(), 1);
}

// SETUP:
// #![warn(warnings)]

async fn setup_1_conductor() -> (SweetConductor, AgentPubKey, SweetCell) {
let dna = SweetDnaFile::from_bundle(std::path::Path::new(DNA_FILEPATH))
.await
.unwrap();
// use futures::future;

let mut conductor = SweetConductor::from_standard_config().await;
// use hdk::prelude::*;
// use holochain::sweettest::{
// SweetAgents, SweetAppBatch, SweetCell, SweetConductor, SweetConductorBatch, SweetDnaFile,
// };

let holo_core_agent = SweetAgents::one(conductor.keystore()).await;
let app1 = conductor
.setup_app_for_agent("app", holo_core_agent.clone(), &[dna.clone()])
.await
.unwrap();
// use mews_integrity::*;

let cell1 = app1.into_cells()[0].clone();
// const DNA_FILEPATH: &str = "../../workdir/clutter.dna";

let agent_hash = holo_core_agent.into_inner();
let agent = AgentPubKey::from_raw_39(agent_hash).unwrap();
// // TESTS:

(conductor, agent, cell1)
}
// #[tokio::test(flavor = "multi_thread")]
// pub async fn trustd_feed_is_based_on_follow_() {
// let (conductor, _ann, cell1): (SweetConductor, AgentPubKey, SweetCell) =
// setup_1_conductor().await;

pub async fn setup_conductors(n: usize) -> (SweetConductorBatch, Vec<AgentPubKey>, SweetAppBatch) {
let dna = SweetDnaFile::from_bundle(std::path::Path::new(DNA_FILEPATH))
.await
.unwrap();
// let long_mew = std::iter::repeat('a').take(200).collect::<String>();
// let create_mew_input = CreateMewInput {
// text: Some(long_mew),
// mew_type: MewType::Original,
// links: None,
// };

let mut conductors = SweetConductorBatch::from_standard_config(n).await;
// let mew_hash: ActionHash = conductor
// .call(&cell1.zome("mews"), "create_mew", create_mew_input)
// .await;

let all_agents1: Vec<holochain::core::AgentPubKey> =
future::join_all(conductors.iter().map(|c| SweetAgents::one(c.keystore()))).await;
// let bytes = mew_hash.get_raw_39();
// let leading_bytes = bytes.get(..3).unwrap();
// assert_eq!(leading_bytes, &[132, 41, 36]);
// }

let all_agents2: Vec<AgentPubKey> = all_agents1
.iter()
.map(|holo_core_agent| {
let agent_hash = holo_core_agent.clone().into_inner();
AgentPubKey::from_raw_39(agent_hash).unwrap()
})
.collect();
// // SETUP:

let apps = conductors
.setup_app_for_zipped_agents("app", &all_agents1, &[dna])
.await
.unwrap();
// async fn setup_1_conductor() -> (SweetConductor, AgentPubKey, SweetCell) {
// let dna = SweetDnaFile::from_bundle(std::path::Path::new(DNA_FILEPATH))
// .await
// .unwrap();

conductors.exchange_peer_info().await;
(conductors, all_agents2, apps)
}
// let mut conductor = SweetConductor::from_standard_config().await;

// let holo_core_agent = SweetAgents::one(conductor.keystore()).await;
// let app1 = conductor
// .setup_app_for_agent("app", holo_core_agent.clone(), &[dna.clone()])
// .await
// .unwrap();

// let cell1 = app1.into_cells()[0].clone();

// let agent_hash = holo_core_agent.into_inner();
// let agent = AgentPubKey::from_raw_39(agent_hash).unwrap();

// (conductor, agent, cell1)
// }

// pub async fn setup_conductors(n: usize) -> (SweetConductorBatch, Vec<AgentPubKey>, SweetAppBatch) {
// let dna = SweetDnaFile::from_bundle(std::path::Path::new(DNA_FILEPATH))
// .await
// .unwrap();

// let mut conductors = SweetConductorBatch::from_standard_config(n).await;

// let all_agents1: Vec<holochain::core::AgentPubKey> =
// future::join_all(conductors.iter().map(|c| SweetAgents::one(c.keystore()))).await;

// let all_agents2: Vec<AgentPubKey> = all_agents1
// .iter()
// .map(|holo_core_agent| {
// let agent_hash = holo_core_agent.clone().into_inner();
// AgentPubKey::from_raw_39(agent_hash).unwrap()
// })
// .collect();

// let apps = conductors
// .setup_app_for_zipped_agents("app", &all_agents1, &[dna])
// .await
// .unwrap();

// conductors.exchange_peer_info().await;
// (conductors, all_agents2, apps)
// }
3 changes: 0 additions & 3 deletions dnas/trust_atom_integrity_zome/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ version = "0.0.1"
crate-type = ["cdylib", "rlib"]
name = "trust_atom_integrity_zome"

[net]
git-fetch-with-cli = false # default is false

[dependencies]
trust_atom_integrity = {git = "https://github.com/trustgraph/trustgraph-holochain.git", package = "trust_atom_integrity"}
# trust_atom_integrity = { path= "/Users/knight/code/trustgraph/trustgraph-holochain/zomes/trust_atom_integrity"}
Expand Down
3 changes: 0 additions & 3 deletions dnas/trust_atom_zome/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ version = "0.0.1"
crate-type = ["cdylib", "rlib"]
name = "trust_atom_zome"

[net]
git-fetch-with-cli = false # default is false

[dependencies]
trust_atom = {git = "https://github.com/trustgraph/trustgraph-holochain.git", package = "trust_atom"}
# trust_atom = { path= "/Users/knight/code/trustgraph/trustgraph-holochain/zomes/trust_atom"}
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e963957

Please sign in to comment.