diff --git a/Cargo.toml b/Cargo.toml index b2fc27a..eda20f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,8 @@ publish = false [dependencies] anyhow = "1" #ceramic-event = { git = "https://github.com/ceramicnetwork/rust-ceramic", branch = "main" } -#ceramic-event = { path = "/Users/dbrowning/code/3box/rust-ceramic/event", default-features = false } -ceramic-event = { git = "https://github.com/ceramicnetwork/rust-ceramic", branch = "feat/wasi" } +ceramic-event = { path = "/Users/dbrowning/code/3box/rust-ceramic/event", default-features = false } +#ceramic-event = { git = "https://github.com/ceramicnetwork/rust-ceramic", branch = "feat/wasi" } json-patch = { version = "1.2.0", features = ["diff"] } reqwest = { version = "0.11.14", features = ["json"], optional = true } schemars = "0.8.12" diff --git a/src/api.rs b/src/api.rs index a2db02b..cacd5b4 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1,8 +1,5 @@ use crate::query::FilterQuery; -use ceramic_event::{ - Base64String, Base64UrlString, Jws, MultiBase32String, MultiBase36String, StreamId, - StreamIdType, -}; +use ceramic_event::{Base64String, Base64UrlString, Jws, MultiBase32String, MultiBase36String, StreamId, StreamIdType}; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -25,7 +22,7 @@ pub struct BlockData { /// Header for block pub header: BlockHeader, /// Data for block - #[serde(skip_serializing_if = "Option::is_none")] + //#[serde(skip_serializing_if = "Option::is_none")] pub data: Option, /// Signature for block #[serde(skip_serializing_if = "Option::is_none")] diff --git a/src/lib.rs b/src/lib.rs index 20078c2..3c8f98a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,10 +8,7 @@ pub mod api; mod model_definition; mod query; -use ceramic_event::{ - Base64String, Cid, DagCborEncoded, EventArgs, Jws, MultiBase36String, Signer, StreamId, - StreamIdType, -}; +use ceramic_event::{Base64String, Cid, DeterministicInitEvent, EventArgs, Jws, MultiBase36String, Signer, StreamId, StreamIdType}; use serde::Serialize; use std::str::FromStr; @@ -147,12 +144,12 @@ impl CeramicHttpClient { pub async fn create_single_instance_request( &self, model_id: &StreamId, - ) -> anyhow::Result> { + ) -> anyhow::Result> { if !model_id.is_model() { anyhow::bail!("StreamId was not a model"); } let args = EventArgs::new_with_parent(&self.signer, model_id); - let commit = args.init()?; + let _commit = args.init()?; let controllers: Vec<_> = args.controllers().map(|c| c.id.clone()).collect(); let model = Base64String::from(model_id.to_vec()?); Ok(api::CreateRequest { @@ -165,7 +162,7 @@ impl CeramicHttpClient { }, linked_block: None, jws: None, - data: Some(commit.encoded), + data: None, cacao_block: None, }, }) @@ -630,6 +627,11 @@ pub mod tests { cli.create_model(&model).await.unwrap() } + pub async fn create_single_model(cli: &CeramicRemoteHttpClient) -> StreamId { + let model = ModelDefinition::new::("TestBall", ModelAccountRelation::Single).unwrap(); + cli.create_model(&model).await.unwrap() + } + #[tokio::test] async fn should_create_model() { let ceramic = CeramicRemoteHttpClient::new(signer().await, ceramic_url()); @@ -637,12 +639,38 @@ pub mod tests { ceramic.create_model(&model).await.unwrap(); } - // #[tokio::test] - // async fn should_create_single_instance() { - // let ceramic = CeramicRemoteHttpClient::new(did(), &did_private_key(), ceramic_url()); - // let model = create_model(&ceramic).await; - // ceramic.create_single_instance(&model).await.unwrap(); - // } + #[tokio::test] + async fn should_create_single_instance() { + let ceramic = CeramicRemoteHttpClient::new(signer().await, ceramic_url()); + let model = create_single_model(&ceramic).await; + ceramic.create_single_instance(&model).await.unwrap(); + } + + #[tokio::test] + async fn should_create_and_update_single_instance() { + let ceramic = CeramicRemoteHttpClient::new(signer().await, ceramic_url()); + let model = create_single_model(&ceramic).await; + let stream_id = ceramic.create_single_instance(&model).await.unwrap(); + + tokio::time::sleep(Duration::from_secs(1)).await; + + let patch = json_patch::Patch(vec![json_patch::PatchOperation::Replace( + ReplaceOperation { + path: "/".to_string(), + value: serde_json::json!({ + "creator": ceramic.client().signer().id().id.clone(), + "radius": 1, + "red": 2, + "green": 3, + "blue": 4, + }), + }, + )]); + let post_resp = ceramic.update(&model, &stream_id, patch).await.unwrap(); + assert_eq!(post_resp.stream_id, stream_id); + let post_resp: Ball = serde_json::from_value(post_resp.state.unwrap().content).unwrap(); + assert_eq!(post_resp.red, 5); + } #[tokio::test] async fn should_create_and_update_list() {