From 7058cc9f8fed5c93d1e35139e3a99d265bb8ace9 Mon Sep 17 00:00:00 2001 From: David Meister Date: Mon, 3 Aug 2020 20:53:41 +0400 Subject: [PATCH 1/6] wip on validate links callback --- crates/holochain/src/core/ribosome.rs | 13 + crates/holochain/src/core/ribosome/error.rs | 6 +- .../src/core/ribosome/guest_callback.rs | 1 + .../guest_callback/validate_link_add.rs | 440 ++++++++++++ .../src/core/ribosome/host_fn/remove_link.rs | 4 +- .../src/core/ribosome/wasm_ribosome.rs | 12 + .../src/core/state/source_chain/error.rs | 6 +- .../src/core/workflow/call_zome_workflow.rs | 59 +- crates/holochain/src/fixt.rs | 6 + .../wasm/validate_link_add_invalid/Cargo.lock | 635 ++++++++++++++++++ .../wasm/validate_link_add_invalid/Cargo.toml | 26 + .../wasm/validate_link_add_invalid/src/lib.rs | 19 + crates/zome_types/src/lib.rs | 2 + crates/zome_types/src/validate_link_add.rs | 27 + 14 files changed, 1249 insertions(+), 7 deletions(-) create mode 100644 crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs create mode 100644 crates/test_utils/wasm/validate_link_add_invalid/Cargo.lock create mode 100644 crates/test_utils/wasm/validate_link_add_invalid/Cargo.toml create mode 100644 crates/test_utils/wasm/validate_link_add_invalid/src/lib.rs create mode 100644 crates/zome_types/src/validate_link_add.rs diff --git a/crates/holochain/src/core/ribosome.rs b/crates/holochain/src/core/ribosome.rs index 7005b44c68..ff2a3035b0 100644 --- a/crates/holochain/src/core/ribosome.rs +++ b/crates/holochain/src/core/ribosome.rs @@ -23,6 +23,9 @@ use crate::core::ribosome::guest_callback::post_commit::PostCommitInvocation; use crate::core::ribosome::guest_callback::post_commit::PostCommitResult; use crate::core::ribosome::guest_callback::validate::ValidateInvocation; use crate::core::ribosome::guest_callback::validate::ValidateResult; +use crate::core::ribosome::guest_callback::validate_link_add::ValidateLinkAddHostAccess; +use crate::core::ribosome::guest_callback::validate_link_add::ValidateLinkAddInvocation; +use crate::core::ribosome::guest_callback::validate_link_add::ValidateLinkAddResult; use crate::core::ribosome::guest_callback::validation_package::ValidationPackageInvocation; use crate::core::ribosome::guest_callback::validation_package::ValidationPackageResult; use crate::core::ribosome::guest_callback::CallIterator; @@ -80,6 +83,7 @@ impl CallContext { pub enum HostAccess { ZomeCall(ZomeCallHostAccess), Validate(ValidateHostAccess), + ValidateLinkAdd(ValidateLinkAddHostAccess), Init(InitHostAccess), EntryDefs(EntryDefsHostAccess), MigrateAgent(MigrateAgentHostAccess), @@ -92,6 +96,9 @@ impl From<&HostAccess> for HostFnAccess { match host_access { HostAccess::ZomeCall(zome_call_host_access) => zome_call_host_access.into(), HostAccess::Validate(validate_host_access) => validate_host_access.into(), + HostAccess::ValidateLinkAdd(validate_link_add_host_access) => { + validate_link_add_host_access.into() + } HostAccess::Init(init_host_access) => init_host_access.into(), HostAccess::EntryDefs(entry_defs_host_access) => entry_defs_host_access.into(), HostAccess::MigrateAgent(migrate_agent_host_access) => migrate_agent_host_access.into(), @@ -405,6 +412,12 @@ pub trait RibosomeT: Sized { invocation: ValidateInvocation, ) -> RibosomeResult; + fn run_validate_link_add( + &self, + access: ValidateLinkAddHostAccess, + invocation: ValidateLinkAddInvocation, + ) -> RibosomeResult; + fn call_iterator( &self, access: HostAccess, diff --git a/crates/holochain/src/core/ribosome/error.rs b/crates/holochain/src/core/ribosome/error.rs index 36151e1730..04b369cdab 100755 --- a/crates/holochain/src/core/ribosome/error.rs +++ b/crates/holochain/src/core/ribosome/error.rs @@ -3,7 +3,7 @@ use crate::core::state::{cascade::error::CascadeError, source_chain::SourceChainError}; use crate::core::workflow::call_zome_workflow::unsafe_call_zome_workspace::error::UnsafeCallZomeWorkspaceError; -use holo_hash::HeaderHash; +use holo_hash::AnyDhtHash; use holochain_crypto::CryptoError; use holochain_serialized_bytes::prelude::SerializedBytesError; use holochain_types::dna::error::DnaError; @@ -44,8 +44,8 @@ pub enum RibosomeError { /// for example a remove link ribosome call needs to find the add link in order to infer the /// correct base and this dependent relationship exists before even subconscious validation /// kicks in - #[error("A mandatory element is missing, header hash: {0}")] - ElementDeps(HeaderHash), + #[error("A mandatory element is missing, dht hash: {0}")] + ElementDeps(AnyDhtHash), /// ident #[error(transparent)] diff --git a/crates/holochain/src/core/ribosome/guest_callback.rs b/crates/holochain/src/core/ribosome/guest_callback.rs index a71153e21c..31aa672290 100644 --- a/crates/holochain/src/core/ribosome/guest_callback.rs +++ b/crates/holochain/src/core/ribosome/guest_callback.rs @@ -3,6 +3,7 @@ pub mod init; pub mod migrate_agent; pub mod post_commit; pub mod validate; +pub mod validate_link_add; pub mod validation_package; use super::HostAccess; use crate::core::ribosome::error::RibosomeError; diff --git a/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs b/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs new file mode 100644 index 0000000000..1d9a2242b3 --- /dev/null +++ b/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs @@ -0,0 +1,440 @@ +use crate::core::ribosome::FnComponents; +use crate::core::ribosome::HostAccess; +use crate::core::ribosome::Invocation; +use crate::core::ribosome::ZomesToInvoke; +use derive_more::Constructor; +use holochain_serialized_bytes::prelude::*; +use holochain_types::dna::zome::HostFnAccess; +use holochain_zome_types::entry::Entry; +use holochain_zome_types::header::LinkAdd; +use holochain_zome_types::validate_link_add::ValidateLinkAddCallbackResult; +use holochain_zome_types::zome::ZomeName; +use holochain_zome_types::HostInput; +use std::sync::Arc; + +#[derive(Clone)] +pub struct ValidateLinkAddInvocation { + pub zome_name: ZomeName, + // Arc here as LinkAdd contains arbitrary bytes in the tag + pub link_add: Arc, + pub base: Arc, + pub target: Arc, +} + +impl ValidateLinkAddInvocation { + pub fn new(zome_name: ZomeName, link_add: LinkAdd, base: Entry, target: Entry) -> Self { + Self { + zome_name, + link_add: Arc::new(link_add), + base: Arc::new(base), + target: Arc::new(target), + } + } +} + +#[derive(Clone, Constructor)] +pub struct ValidateLinkAddHostAccess; + +impl From for HostAccess { + fn from(validate_link_add_host_access: ValidateLinkAddHostAccess) -> Self { + Self::ValidateLinkAdd(validate_link_add_host_access) + } +} + +impl From<&ValidateLinkAddHostAccess> for HostFnAccess { + fn from(_: &ValidateLinkAddHostAccess) -> Self { + Self::none() + } +} + +impl Invocation for ValidateLinkAddInvocation { + fn zomes(&self) -> ZomesToInvoke { + // links are specific to zomes so only validate in the zome the link is defined in + // note that here it is possible there is a zome/link mismatch + // we rely on the invocation to be built correctly + ZomesToInvoke::One(self.zome_name.clone()) + } + fn fn_components(&self) -> FnComponents { + vec![ + "validate_link".into(), + // "add" is optional, validate_link is fine too + "add".into(), + ] + .into() + } + fn host_input(self) -> Result { + Ok(HostInput::new((&*self.link_add).try_into()?)) + } +} + +impl TryFrom for HostInput { + type Error = SerializedBytesError; + fn try_from( + validate_link_add_invocation: ValidateLinkAddInvocation, + ) -> Result { + Ok(Self::new( + (&*validate_link_add_invocation.link_add).try_into()?, + )) + } +} + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SerializedBytes)] +pub enum ValidateLinkAddResult { + Valid, + Invalid(String), +} + +impl From> for ValidateLinkAddResult { + fn from(a: Vec<(ZomeName, ValidateLinkAddCallbackResult)>) -> Self { + a.into_iter().map(|(_, v)| v).collect::>().into() + } +} + +impl From> for ValidateLinkAddResult { + fn from(callback_results: Vec) -> Self { + callback_results.into_iter().fold(Self::Valid, |acc, x| { + match x { + // validation is invalid if any x is invalid + ValidateLinkAddCallbackResult::Invalid(i) => Self::Invalid(i), + // valid x allows validation to continue + ValidateLinkAddCallbackResult::Valid => acc, + } + }) + } +} + +#[cfg(test)] +mod test { + + use super::ValidateLinkAddResult; + use crate::core::ribosome::Invocation; + use crate::core::ribosome::ZomesToInvoke; + use crate::fixt::ValidateHostAccessFixturator; + use crate::fixt::ValidateInvocationFixturator; + use crate::fixt::ZomeCallCapGrantFixturator; + use ::fixt::prelude::*; + use holo_hash::fixt::AgentPubKeyFixturator; + use holochain_serialized_bytes::prelude::*; + use holochain_types::{dna::zome::HostFnAccess, fixt::CapClaimFixturator}; + use holochain_zome_types::entry::Entry; + use holochain_zome_types::validate_link_add::ValidateLinkAddCallbackResult; + use holochain_zome_types::HostInput; + use rand::seq::SliceRandom; + use std::sync::Arc; + + #[tokio::test(threaded_scheduler)] + async fn validate_callback_result_fold() { + let mut rng = thread_rng(); + + let result_valid = || ValidateLinkAddResult::Valid; + // let result_ud = || ValidateLinkAddResult::UnresolvedDependencies(vec![]); + let result_invalid = || ValidateLinkAddResult::Invalid("".into()); + + let cb_valid = || ValidateLinkAddCallbackResult::Valid; + // let cb_ud = || ValidateCallbackResult::UnresolvedDependencies(vec![]); + let cb_invalid = || ValidateLinkAddCallbackResult::Invalid("".into()); + + for (mut results, expected) in vec![ + (vec![], result_valid()), + (vec![cb_valid()], result_valid()), + (vec![cb_invalid()], result_invalid()), + // (vec![cb_ud()], result_ud()), + (vec![cb_invalid(), cb_valid()], result_invalid()), + // (vec![cb_invalid(), cb_ud()], result_invalid()), + // (vec![cb_valid(), cb_ud()], result_ud()), + // (vec![cb_valid(), cb_ud(), cb_invalid()], result_invalid()), + ] { + // order of the results should not change the final result + results.shuffle(&mut rng); + + // number of times a callback result appears should not change the final result + let number_of_extras = rng.gen_range(0, 5); + for _ in 0..number_of_extras { + let maybe_extra = results.choose(&mut rng).cloned(); + match maybe_extra { + Some(extra) => results.push(extra), + _ => {} + }; + } + + assert_eq!(expected, results.into(),); + } + } + + #[tokio::test(threaded_scheduler)] + async fn validate_invocation_allow_side_effects() { + let validate_host_access = ValidateHostAccessFixturator::new(fixt::Unpredictable) + .next() + .unwrap(); + assert_eq!( + HostFnAccess::from(&validate_host_access), + HostFnAccess::none(), + ); + } + + #[tokio::test(threaded_scheduler)] + async fn validate_invocation_zomes() { + let validate_invocation = ValidateInvocationFixturator::new(fixt::Unpredictable) + .next() + .unwrap(); + let zome_name = validate_invocation.zome_name.clone(); + assert_eq!(ZomesToInvoke::One(zome_name), validate_invocation.zomes(),); + } + + #[tokio::test(threaded_scheduler)] + async fn validate_invocation_fn_components() { + let mut validate_invocation = ValidateInvocationFixturator::new(fixt::Unpredictable) + .next() + .unwrap(); + + let agent_entry = Entry::Agent( + AgentPubKeyFixturator::new(fixt::Unpredictable) + .next() + .unwrap() + .into(), + ); + validate_invocation.entry = Arc::new(agent_entry); + let mut expected = vec!["validate", "validate_agent"]; + for fn_component in validate_invocation.fn_components() { + assert_eq!(fn_component, expected.pop().unwrap(),); + } + + let agent_entry = Entry::App( + SerializedBytesFixturator::new(fixt::Unpredictable) + .next() + .unwrap() + .into(), + ); + validate_invocation.entry = Arc::new(agent_entry); + let mut expected = vec!["validate", "validate_entry"]; + for fn_component in validate_invocation.fn_components() { + assert_eq!(fn_component, expected.pop().unwrap(),); + } + + let agent_entry = Entry::CapClaim( + CapClaimFixturator::new(fixt::Unpredictable) + .next() + .unwrap() + .into(), + ); + validate_invocation.entry = Arc::new(agent_entry); + let mut expected = vec!["validate", "validate_cap_claim"]; + for fn_component in validate_invocation.fn_components() { + assert_eq!(fn_component, expected.pop().unwrap(),); + } + + let agent_entry = Entry::CapGrant( + ZomeCallCapGrantFixturator::new(fixt::Unpredictable) + .next() + .unwrap() + .into(), + ); + validate_invocation.entry = Arc::new(agent_entry); + let mut expected = vec!["validate", "validate_cap_grant"]; + for fn_component in validate_invocation.fn_components() { + assert_eq!(fn_component, expected.pop().unwrap(),); + } + } + + #[tokio::test(threaded_scheduler)] + async fn validate_invocation_host_input() { + let validate_invocation = ValidateInvocationFixturator::new(fixt::Unpredictable) + .next() + .unwrap(); + + let host_input = validate_invocation.clone().host_input().unwrap(); + + assert_eq!( + host_input, + HostInput::new(SerializedBytes::try_from(&*validate_invocation.entry).unwrap()), + ); + } +} + +#[cfg(test)] +#[cfg(feature = "slow_tests")] +mod slow_tests { + + use super::ValidateLinkAddHostAccess; + use super::ValidateLinkAddResult; + use crate::core::ribosome::RibosomeT; + // use crate::core::state::source_chain::SourceChainResult; + // use crate::core::workflow::call_zome_workflow::CallZomeWorkspace; + use crate::fixt::curve::Zomes; + use crate::fixt::ValidateLinkAddInvocationFixturator; + use crate::fixt::WasmRibosomeFixturator; + // use crate::fixt::ZomeCallHostAccessFixturator; + // use fixt::prelude::*; + // use futures::future::BoxFuture; + // use futures::future::FutureExt; + // use holo_hash::fixt::AgentPubKeyFixturator; + // use holo_hash::HeaderHash; + use holochain_wasm_test_utils::TestWasm; + // use holochain_zome_types::CommitEntryOutput; + // use holochain_zome_types::Entry; + // use std::sync::Arc; + + #[tokio::test(threaded_scheduler)] + async fn test_validate_link_add_unimplemented() { + let ribosome = WasmRibosomeFixturator::new(Zomes(vec![TestWasm::Foo])) + .next() + .unwrap(); + let mut validate_invocation = ValidateLinkAddInvocationFixturator::new(fixt::Empty) + .next() + .unwrap(); + validate_invocation.zome_name = TestWasm::Foo.into(); + + let result = ribosome + .run_validate_link_add(ValidateLinkAddHostAccess, validate_invocation) + .unwrap(); + assert_eq!(result, ValidateLinkAddResult::Valid,); + } + + // #[tokio::test(threaded_scheduler)] + // async fn test_validate_implemented_valid() { + // let ribosome = WasmRibosomeFixturator::new(Zomes(vec![TestWasm::ValidateValid])) + // .next() + // .unwrap(); + // let mut validate_invocation = ValidateLinkAddInvocationFixturator::new(fixt::Empty) + // .next() + // .unwrap(); + // validate_invocation.zome_name = TestWasm::ValidateValid.into(); + // + // let result = ribosome + // .run_validate_link_add(ValidateLinkAddHostAccess, validate_invocation) + // .unwrap(); + // assert_eq!(result, ValidateLinkAddResult::Valid,); + // } + // + #[tokio::test(threaded_scheduler)] + async fn test_validate_link_add_implemented_invalid() { + let ribosome = WasmRibosomeFixturator::new(Zomes(vec![TestWasm::ValidateInvalid])) + .next() + .unwrap(); + let mut validate_invocation = ValidateLinkAddInvocationFixturator::new(fixt::Empty) + .next() + .unwrap(); + validate_invocation.zome_name = TestWasm::ValidateInvalid.into(); + + let result = ribosome + .run_validate_link_add(ValidateLinkAddHostAccess, validate_invocation) + .unwrap(); + assert_eq!( + result, + ValidateLinkAddResult::Invalid("esoteric edge case".into()), + ); + } + // + // #[tokio::test(threaded_scheduler)] + // async fn test_validate_implemented_multi() { + // let ribosome = WasmRibosomeFixturator::new(Zomes(vec![TestWasm::ValidateInvalid])) + // .next() + // .unwrap(); + // let mut validate_invocation = ValidateLinkAddInvocationFixturator::new(fixt::Empty) + // .next() + // .unwrap(); + // let entry = Entry::Agent( + // AgentPubKeyFixturator::new(fixt::Unpredictable) + // .next() + // .unwrap() + // .into(), + // ); + // + // validate_invocation.zome_name = TestWasm::ValidateInvalid.into(); + // validate_invocation.link_add = Arc::new(link_add); + // + // let result = ribosome + // .run_validate_link_add(ValidateLinkAddHostAccess, validate_invocation) + // .unwrap(); + // assert_eq!(result, ValidateLinkAddResult::Invalid("esoteric edge case".into())); + // } + // + // #[tokio::test(threaded_scheduler)] + // async fn pass_validate_test<'a>() { + // // test workspace boilerplate + // let env = holochain_state::test_utils::test_cell_env(); + // let dbs = env.dbs().await; + // let env_ref = env.guard().await; + // let reader = holochain_state::env::ReadManager::reader(&env_ref).unwrap(); + // let mut workspace = ::new(&reader, &dbs).unwrap(); + // + // // commits fail validation if we don't do genesis + // crate::core::workflow::fake_genesis(&mut workspace.source_chain) + // .await + // .unwrap(); + // + // let (_g, raw_workspace) = + // crate::core::workflow::unsafe_call_zome_workspace::UnsafeCallZomeWorkspace::from_mut( + // &mut workspace, + // ); + // let mut host_access = fixt!(ZomeCallHostAccess); + // host_access.workspace = raw_workspace.clone(); + // + // let output: CommitEntryOutput = + // crate::call_test_ribosome!(host_access, TestWasm::Validate, "always_validates", ()); + // + // // the chain head should be the committed entry header + // let call = + // |workspace: &'a mut CallZomeWorkspace| -> BoxFuture<'a, SourceChainResult> { + // async move { + // let source_chain = &mut workspace.source_chain; + // Ok(source_chain.chain_head()?.to_owned()) + // } + // .boxed() + // }; + // let chain_head = + // tokio_safe_block_on::tokio_safe_block_forever_on(tokio::task::spawn(async move { + // unsafe { raw_workspace.apply_mut(call).await } + // })) + // .unwrap() + // .unwrap() + // .unwrap(); + // + // assert_eq!(chain_head, output.into_inner(),); + // } + // + // #[tokio::test(threaded_scheduler)] + // async fn fail_validate_test<'a>() { + // // test workspace boilerplate + // let env = holochain_state::test_utils::test_cell_env(); + // let dbs = env.dbs().await; + // let env_ref = env.guard().await; + // let reader = holochain_state::env::ReadManager::reader(&env_ref).unwrap(); + // let mut workspace = ::new(&reader, &dbs).unwrap(); + // + // // commits fail validation if we don't do genesis + // crate::core::workflow::fake_genesis(&mut workspace.source_chain) + // .await + // .unwrap(); + // + // let (_g, raw_workspace) = + // crate::core::workflow::unsafe_call_zome_workspace::UnsafeCallZomeWorkspace::from_mut( + // &mut workspace, + // ); + // + // let mut host_access = fixt!(ZomeCallHostAccess); + // host_access.workspace = raw_workspace.clone(); + // + // let output: CommitEntryOutput = + // crate::call_test_ribosome!(host_access, TestWasm::Validate, "never_validates", ()); + // + // // the chain head should be the committed entry header + // let call = + // |workspace: &'a mut CallZomeWorkspace| -> BoxFuture<'a, SourceChainResult> { + // async move { + // let source_chain = &mut workspace.source_chain; + // Ok(source_chain.chain_head()?.to_owned()) + // } + // .boxed() + // }; + // let chain_head = + // tokio_safe_block_on::tokio_safe_block_forever_on(tokio::task::spawn(async move { + // unsafe { raw_workspace.apply_mut(call).await } + // })) + // .unwrap() + // .unwrap() + // .unwrap(); + // + // assert_eq!(chain_head, output.into_inner(),); + // } +} diff --git a/crates/holochain/src/core/ribosome/host_fn/remove_link.rs b/crates/holochain/src/core/ribosome/host_fn/remove_link.rs index 478dc9456d..fbebd85567 100644 --- a/crates/holochain/src/core/ribosome/host_fn/remove_link.rs +++ b/crates/holochain/src/core/ribosome/host_fn/remove_link.rs @@ -58,7 +58,7 @@ pub fn remove_link<'a>( Header::LinkAdd(link_add_header) => Ok(link_add_header.base_address.clone()), // the add link header hash provided was found but didn't point to an AddLink // header (it is something else) so we cannot proceed - _ => Err(RibosomeError::ElementDeps(link_add_address.clone())), + _ => Err(RibosomeError::ElementDeps(link_add_address.clone().into())), } } // the add link header hash could not be found @@ -66,7 +66,7 @@ pub fn remove_link<'a>( // that isn't also discoverable in either the cache or DHT, but it _is_ possible so we have // to fail in that case (e.g. the local cache could have GC'd at the same moment the // network connection dropped out) - None => Err(RibosomeError::ElementDeps(link_add_address.clone())), + None => Err(RibosomeError::ElementDeps(link_add_address.clone().into())), }?; // add a LinkRemove to the source chain diff --git a/crates/holochain/src/core/ribosome/wasm_ribosome.rs b/crates/holochain/src/core/ribosome/wasm_ribosome.rs index 683868916d..680950a32f 100644 --- a/crates/holochain/src/core/ribosome/wasm_ribosome.rs +++ b/crates/holochain/src/core/ribosome/wasm_ribosome.rs @@ -18,6 +18,9 @@ use crate::core::ribosome::guest_callback::post_commit::PostCommitInvocation; use crate::core::ribosome::guest_callback::post_commit::PostCommitResult; use crate::core::ribosome::guest_callback::validate::ValidateInvocation; use crate::core::ribosome::guest_callback::validate::ValidateResult; +use crate::core::ribosome::guest_callback::validate_link_add::ValidateLinkAddHostAccess; +use crate::core::ribosome::guest_callback::validate_link_add::ValidateLinkAddInvocation; +use crate::core::ribosome::guest_callback::validate_link_add::ValidateLinkAddResult; use crate::core::ribosome::guest_callback::validation_package::ValidationPackageInvocation; use crate::core::ribosome::guest_callback::validation_package::ValidationPackageResult; use crate::core::ribosome::guest_callback::CallIterator; @@ -66,6 +69,7 @@ use holochain_zome_types::migrate_agent::MigrateAgentCallbackResult; use holochain_zome_types::post_commit::PostCommitCallbackResult; use holochain_zome_types::validate::ValidateCallbackResult; use holochain_zome_types::validate::ValidationPackageCallbackResult; +use holochain_zome_types::validate_link_add::ValidateLinkAddCallbackResult; use holochain_zome_types::zome::ZomeName; use holochain_zome_types::CallbackResult; use holochain_zome_types::GuestOutput; @@ -402,6 +406,14 @@ impl RibosomeT for WasmRibosome { do_callback!(self, access, invocation, ValidateCallbackResult) } + fn run_validate_link_add( + &self, + access: ValidateLinkAddHostAccess, + invocation: ValidateLinkAddInvocation, + ) -> RibosomeResult { + do_callback!(self, access, invocation, ValidateLinkAddCallbackResult) + } + fn run_init( &self, access: InitHostAccess, diff --git a/crates/holochain/src/core/state/source_chain/error.rs b/crates/holochain/src/core/state/source_chain/error.rs index 8413955baf..9a57f832d7 100644 --- a/crates/holochain/src/core/state/source_chain/error.rs +++ b/crates/holochain/src/core/state/source_chain/error.rs @@ -1,5 +1,6 @@ use crate::core::workflow::produce_dht_ops_workflow::dht_op_light::error::DhtOpConvertError; -use holo_hash::{EntryHash, HeaderHash}; +use holo_hash::EntryHash; +use holo_hash::HeaderHash; use holochain_serialized_bytes::prelude::*; use holochain_state::error::DatabaseError; use holochain_types::dht_op::error::DhtOpError; @@ -44,6 +45,9 @@ pub enum SourceChainError { #[error("InvalidCommit error: {0}")] InvalidCommit(String), + #[error("InvalidLinkAdd error: {0}")] + InvalidLinkAdd(String), + #[error("KeystoreError: {0}")] KeystoreError(#[from] holochain_keystore::KeystoreError), diff --git a/crates/holochain/src/core/workflow/call_zome_workflow.rs b/crates/holochain/src/core/workflow/call_zome_workflow.rs index 5304fd594e..9e5024817c 100644 --- a/crates/holochain/src/core/workflow/call_zome_workflow.rs +++ b/crates/holochain/src/core/workflow/call_zome_workflow.rs @@ -1,6 +1,10 @@ use super::error::{WorkflowError, WorkflowResult}; +use crate::core::ribosome::error::RibosomeError; use crate::core::ribosome::guest_callback::validate::ValidateInvocation; use crate::core::ribosome::guest_callback::validate::{ValidateHostAccess, ValidateResult}; +use crate::core::ribosome::guest_callback::validate_link_add::ValidateLinkAddHostAccess; +use crate::core::ribosome::guest_callback::validate_link_add::ValidateLinkAddInvocation; +use crate::core::ribosome::guest_callback::validate_link_add::ValidateLinkAddResult; use crate::core::ribosome::ZomeCallInvocation; use crate::core::ribosome::ZomeCallInvocationResponse; use crate::core::ribosome::{error::RibosomeResult, RibosomeT, ZomeCallHostAccess}; @@ -19,6 +23,8 @@ use holochain_keystore::KeystoreSender; use holochain_p2p::HolochainP2pCell; use holochain_state::prelude::*; use holochain_types::element::Element; +use holochain_zome_types::entry::GetOptions; +use holochain_zome_types::header::Header; use std::sync::Arc; use unsafe_call_zome_workspace::UnsafeCallZomeWorkspace; @@ -78,7 +84,7 @@ async fn call_zome_workflow_inner<'env, Ribosome: RibosomeT>( // Create the unsafe sourcechain for use with wasm closure let result = { let (_g, raw_workspace) = UnsafeCallZomeWorkspace::from_mut(workspace); - let host_access = ZomeCallHostAccess::new(raw_workspace, keystore, network); + let host_access = ZomeCallHostAccess::new(raw_workspace, keystore, network.clone()); ribosome.call_zome_function(host_access, invocation) }; tracing::trace!(line = line!()); @@ -126,7 +132,58 @@ async fn call_zome_workflow_inner<'env, Ribosome: RibosomeT>( } } + let mut cascade = workspace.cascade(network); for chain_element in to_app_validate { + match chain_element.header() { + // @todo have app validate in its own workflow + Header::LinkAdd(link_add) => { + let validate: ValidateLinkAddResult = ribosome.run_validate_link_add( + ValidateLinkAddHostAccess, + ValidateLinkAddInvocation { + zome_name: zome_name.clone(), + base: Arc::new( + cascade + .dht_get(link_add.base_address.clone().into(), GetOptions.into()) + .await + .map_err(|e| RibosomeError::from(e))? + .ok_or(RibosomeError::ElementDeps( + link_add.base_address.clone().into(), + ))? + .entry() + .as_option() + .ok_or(RibosomeError::ElementDeps( + link_add.base_address.clone().into(), + ))? + .to_owned(), + ), + target: Arc::new( + cascade + .dht_get(link_add.target_address.clone().into(), GetOptions.into()) + .await + .map_err(|e| RibosomeError::from(e))? + .ok_or(RibosomeError::ElementDeps( + link_add.target_address.clone().into(), + ))? + .entry() + .as_option() + .ok_or(RibosomeError::ElementDeps( + link_add.target_address.clone().into(), + ))? + .to_owned(), + ), + link_add: Arc::new(link_add.to_owned()), + }, + )?; + match validate { + ValidateLinkAddResult::Valid => {} + ValidateLinkAddResult::Invalid(reason) => { + Err(SourceChainError::InvalidLinkAdd(reason))? + } + } + } + _ => {} + } + match chain_element.entry() { holochain_types::element::ElementEntry::Present(entry) => { let validate: ValidateResult = ribosome.run_validate( diff --git a/crates/holochain/src/fixt.rs b/crates/holochain/src/fixt.rs index 3b96a281e9..e9fa4df9ba 100644 --- a/crates/holochain/src/fixt.rs +++ b/crates/holochain/src/fixt.rs @@ -11,6 +11,7 @@ use crate::core::ribosome::guest_callback::post_commit::PostCommitHostAccess; use crate::core::ribosome::guest_callback::post_commit::PostCommitInvocation; use crate::core::ribosome::guest_callback::validate::ValidateHostAccess; use crate::core::ribosome::guest_callback::validate::ValidateInvocation; +use crate::core::ribosome::guest_callback::validate_link_add::ValidateLinkAddInvocation; use crate::core::ribosome::guest_callback::validation_package::ValidationPackageHostAccess; use crate::core::ribosome::guest_callback::validation_package::ValidationPackageInvocation; use crate::core::ribosome::wasm_ribosome::WasmRibosome; @@ -324,6 +325,11 @@ fixturator!( constructor fn new(ZomeName, Entry); ); +fixturator!( + ValidateLinkAddInvocation; + constructor fn new(ZomeName, LinkAdd, Entry, Entry); +); + fixturator!( ValidateHostAccess; constructor fn new(); diff --git a/crates/test_utils/wasm/validate_link_add_invalid/Cargo.lock b/crates/test_utils/wasm/validate_link_add_invalid/Cargo.lock new file mode 100644 index 0000000000..ac403eb9e0 --- /dev/null +++ b/crates/test_utils/wasm/validate_link_add_invalid/Cargo.lock @@ -0,0 +1,635 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + +[[package]] +name = "autocfg" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" + +[[package]] +name = "autocfg" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "block-buffer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a076c298b9ecdb530ed9d967e74a6027d6a7478924520acddcddc24c1c8ab3ab" +dependencies = [ + "arrayref", + "byte-tools", +] + +[[package]] +name = "byte-tools" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40" + +[[package]] +name = "byteorder" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" + +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "digest" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90" +dependencies = [ + "generic-array", +] + +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + +[[package]] +name = "generic-array" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d" +dependencies = [ + "typenum", +] + +[[package]] +name = "holo_hash" +version = "0.0.1" +dependencies = [ + "holochain_serialized_bytes", + "rmp-serde", + "serde", + "serde_bytes", +] + +[[package]] +name = "holochain_serialized_bytes" +version = "0.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03c9314720fa798e94b99ac219fd232c719688971adcf8c368c4e1aa91229183" +dependencies = [ + "holochain_serialized_bytes_derive", + "rmp-serde", + "serde", + "serde-transcode", + "serde_bytes", + "serde_json", + "thiserror", +] + +[[package]] +name = "holochain_serialized_bytes_derive" +version = "0.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90321247a91d3d01cf658465b5933dc40196321017f3c1a278725e004fc879a1" +dependencies = [ + "quote 0.6.13", + "syn 0.15.44", +] + +[[package]] +name = "holochain_wasmer_common" +version = "0.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "158532e5478884b8030477e6d8378de5f312f3401e8500dd551f8f5f0a819596" +dependencies = [ + "holochain_serialized_bytes", + "serde", + "thiserror", +] + +[[package]] +name = "holochain_wasmer_guest" +version = "0.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d38745de8587f886aec602bea3d051d9cbedbdfad467e7cc37c6348cbe8682" +dependencies = [ + "holochain_serialized_bytes", + "holochain_wasmer_common", + "serde", +] + +[[package]] +name = "holochain_zome_types" +version = "0.0.1" +dependencies = [ + "holo_hash", + "holochain_serialized_bytes", + "multihash", + "nanoid", + "rust-base58", + "serde", + "serde_bytes", +] + +[[package]] +name = "indexmap" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c398b2b113b55809ceb9ee3e753fcbac793f1956663f3c36549c1346015c2afe" +dependencies = [ + "autocfg 1.0.0", +] + +[[package]] +name = "itoa" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" + +[[package]] +name = "libc" +version = "0.2.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701" + +[[package]] +name = "multihash" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62469025f45dee2464ef9fc845f4683c543993792c1993e7d903c17a4546b74" +dependencies = [ + "sha1", + "sha2", + "tiny-keccak", +] + +[[package]] +name = "nanoid" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6226bc4e142124cb44e309a37a04cd9bb10e740d8642855441d3b14808f635e" +dependencies = [ + "rand", +] + +[[package]] +name = "num" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab3e176191bc4faad357e3122c4747aa098ac880e88b168f106386128736cf4a" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f3fc75e3697059fb1bc465e3d8cca6cf92f56854f201158b3f9c77d5a3cfa0" +dependencies = [ + "autocfg 1.0.0", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05ad05bd8977050b171b3f6b48175fea6e0565b7981059b486075e1026a9fb5" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" +dependencies = [ + "autocfg 1.0.0", + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6e6b7c748f995c4c29c5f5ae0248536e04a5739927c74ec0fa564805094b9f" +dependencies = [ + "autocfg 1.0.0", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5b4d7360f362cfb50dde8143501e6940b22f644be75a4cc90b2d81968908138" +dependencies = [ + "autocfg 1.0.0", + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" +dependencies = [ + "autocfg 1.0.0", +] + +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid 0.1.0", +] + +[[package]] +name = "proc-macro2" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" +dependencies = [ + "unicode-xid 0.2.1", +] + +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2 1.0.18", +] + +[[package]] +name = "rand" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +dependencies = [ + "autocfg 0.1.7", + "libc", + "rand_chacha", + "rand_core 0.4.2", + "rand_hc", + "rand_isaac", + "rand_jitter", + "rand_os", + "rand_pcg", + "rand_xorshift", + "winapi", +] + +[[package]] +name = "rand_chacha" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +dependencies = [ + "autocfg 0.1.7", + "rand_core 0.3.1", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_jitter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" +dependencies = [ + "libc", + "rand_core 0.4.2", + "winapi", +] + +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +dependencies = [ + "cloudabi", + "fuchsia-cprng", + "libc", + "rand_core 0.4.2", + "rdrand", + "winapi", +] + +[[package]] +name = "rand_pcg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +dependencies = [ + "autocfg 0.1.7", + "rand_core 0.4.2", +] + +[[package]] +name = "rand_xorshift" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rmp" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f10b46df14cf1ee1ac7baa4d2fbc2c52c0622a4b82fa8740e37bc452ac0184f" +dependencies = [ + "byteorder", + "num-traits", +] + +[[package]] +name = "rmp-serde" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c1ee98f14fe8b8e9c5ea13d25da7b2a1796169202c57a09d7288de90d56222b" +dependencies = [ + "byteorder", + "rmp", + "serde", +] + +[[package]] +name = "rust-base58" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b313b91fcdc6719ad41fa2dad2b7e810b03833fae4bf911950e15529a5f04439" +dependencies = [ + "num", +] + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "serde" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-transcode" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97528f0dfcf8ce2d51d995cb513a103b9cd301dc3f387a9cae5ef974381d4e1c" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_bytes" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.34", +] + +[[package]] +name = "serde_json" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "171698ce4ec7cbb93babeb3190021b4d72e96ccb98e33d277ae4ea959d6f2d9e" + +[[package]] +name = "sha2" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9eb6be24e4c23a84d7184280d2722f7f2731fcdd4a9d886efbfe4413e4847ea0" +dependencies = [ + "block-buffer", + "byte-tools", + "digest", + "fake-simd", +] + +[[package]] +name = "syn" +version = "0.15.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "unicode-xid 0.1.0", +] + +[[package]] +name = "syn" +version = "1.0.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936cae2873c940d92e697597c5eee105fb570cd5689c695806f672883653349b" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "unicode-xid 0.2.1", +] + +[[package]] +name = "test_wasm_validate_invalid" +version = "0.0.1" +dependencies = [ + "holochain_serialized_bytes", + "holochain_wasmer_guest", + "holochain_zome_types", + "serde", +] + +[[package]] +name = "thiserror" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.34", +] + +[[package]] +name = "tiny-keccak" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d8a021c69bb74a44ccedb824a046447e2c84a01df9e5c20779750acb38e11b2" +dependencies = [ + "crunchy", +] + +[[package]] +name = "typenum" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/crates/test_utils/wasm/validate_link_add_invalid/Cargo.toml b/crates/test_utils/wasm/validate_link_add_invalid/Cargo.toml new file mode 100644 index 0000000000..a70c5464dd --- /dev/null +++ b/crates/test_utils/wasm/validate_link_add_invalid/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "test_wasm_validate_invalid" +version = "0.0.1" +authors = [ "thedavidmeister", "thedavidmeister@gmail.com" ] +edition = "2018" + +[profile.dev] +opt-level = "z" + +[profile.release] +opt-level = "z" + +# Ensure that this is not inside of any other workspace. +# This crate should be an implementation detail of test_utils_wasm and +# therefore shouldn't be mentioned in the top-level Cargo.toml +[workspace] + +[lib] +name = "test_wasm_validate_invalid" +crate-type = [ "cdylib", "rlib" ] + +[dependencies] +holochain_serialized_bytes = "=0.0.40" +holochain_wasmer_guest = "=0.0.37" +holochain_zome_types = { version = "=0.0.1", path = "../../../zome_types" } +serde = "=1.0.104" diff --git a/crates/test_utils/wasm/validate_link_add_invalid/src/lib.rs b/crates/test_utils/wasm/validate_link_add_invalid/src/lib.rs new file mode 100644 index 0000000000..fa3b379dd3 --- /dev/null +++ b/crates/test_utils/wasm/validate_link_add_invalid/src/lib.rs @@ -0,0 +1,19 @@ +use holochain_wasmer_guest::*; +use holochain_zome_types::*; +use holochain_zome_types::validate::ValidateCallbackResult; + +holochain_wasmer_guest::holochain_externs!(); + +#[no_mangle] +/// this only runs for agent entries +/// this passes but should not override the base validate call that has an Invalid result +pub extern "C" fn validate_agent(_: GuestPtr) -> GuestPtr { + ret!(GuestOutput::new(try_result!(ValidateCallbackResult::Valid.try_into(), "failed to serialize valid agent callback"))) +} + +#[no_mangle] +/// this runs for all entries +/// this never passes and so should always invalide the result for any input entry +pub extern "C" fn validate(_: GuestPtr) -> GuestPtr { + ret!(GuestOutput::new(try_result!(ValidateCallbackResult::Invalid("esoteric edge case".into()).try_into(), "failed to serialize validate return value"))); +} diff --git a/crates/zome_types/src/lib.rs b/crates/zome_types/src/lib.rs index 53a210e413..7bb52a1c05 100644 --- a/crates/zome_types/src/lib.rs +++ b/crates/zome_types/src/lib.rs @@ -37,6 +37,8 @@ pub mod timestamp; #[allow(missing_docs)] pub mod validate; #[allow(missing_docs)] +pub mod validate_link_add; +#[allow(missing_docs)] pub mod zome; #[allow(missing_docs)] pub mod zome_info; diff --git a/crates/zome_types/src/validate_link_add.rs b/crates/zome_types/src/validate_link_add.rs new file mode 100644 index 0000000000..65361ae705 --- /dev/null +++ b/crates/zome_types/src/validate_link_add.rs @@ -0,0 +1,27 @@ +use crate::zome_io::GuestOutput; +use crate::CallbackResult; +use holochain_serialized_bytes::prelude::*; + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, SerializedBytes)] +pub enum ValidateLinkAddCallbackResult { + Valid, + Invalid(String), +} + +impl CallbackResult for ValidateLinkAddCallbackResult { + fn is_definitive(&self) -> bool { + match self { + ValidateLinkAddCallbackResult::Invalid(_) => true, + _ => false, + } + } +} + +impl From for ValidateLinkAddCallbackResult { + fn from(guest_output: GuestOutput) -> Self { + match guest_output.into_inner().try_into() { + Ok(v) => v, + Err(e) => Self::Invalid(format!("{:?}", e)), + } + } +} From 89356cf10d5b975ecc4f94f5f7c328bac60c6930 Mon Sep 17 00:00:00 2001 From: David Meister Date: Tue, 4 Aug 2020 15:30:30 +0400 Subject: [PATCH 2/6] test_validate_link_add_implemented_invalid --- crates/hdk/src/prelude.rs | 2 ++ .../guest_callback/validate_link_add.rs | 27 ++++++++++++++----- crates/test_utils/wasm/build.rs | 3 ++- crates/test_utils/wasm/src/lib.rs | 7 +++++ .../wasm/validate_link_add_invalid/Cargo.lock | 14 +++++++++- .../wasm/validate_link_add_invalid/Cargo.toml | 5 ++-- .../wasm/validate_link_add_invalid/src/lib.rs | 16 +++-------- crates/zome_types/src/validate_link_add.rs | 9 +++++++ 8 files changed, 61 insertions(+), 22 deletions(-) diff --git a/crates/hdk/src/prelude.rs b/crates/hdk/src/prelude.rs index b932dcdde8..49aba4f2d1 100644 --- a/crates/hdk/src/prelude.rs +++ b/crates/hdk/src/prelude.rs @@ -40,5 +40,7 @@ pub use holochain_zome_types::entry_def::EntryDefsCallbackResult; pub use holochain_zome_types::entry_def::EntryVisibility; pub use holochain_zome_types::entry_def::RequiredValidations; pub use holochain_zome_types::zome_info::ZomeInfo; +pub use holochain_zome_types::validate_link_add::ValidateLinkAddCallbackResult; +pub use holochain_zome_types::validate_link_add::ValidateLinkAddData; pub use holochain_zome_types::*; pub use std::convert::TryFrom; diff --git a/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs b/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs index 1d9a2242b3..dd3a97a050 100644 --- a/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs +++ b/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs @@ -8,6 +8,7 @@ use holochain_types::dna::zome::HostFnAccess; use holochain_zome_types::entry::Entry; use holochain_zome_types::header::LinkAdd; use holochain_zome_types::validate_link_add::ValidateLinkAddCallbackResult; +use holochain_zome_types::validate_link_add::ValidateLinkAddData; use holochain_zome_types::zome::ZomeName; use holochain_zome_types::HostInput; use std::sync::Arc; @@ -32,6 +33,16 @@ impl ValidateLinkAddInvocation { } } +impl From for ValidateLinkAddData { + fn from(validate_link_add_invocation: ValidateLinkAddInvocation) -> Self { + Self { + link_add: (*validate_link_add_invocation.link_add).clone(), + base: (*validate_link_add_invocation.base).clone(), + target: (*validate_link_add_invocation.target).clone(), + } + } +} + #[derive(Clone, Constructor)] pub struct ValidateLinkAddHostAccess; @@ -63,7 +74,11 @@ impl Invocation for ValidateLinkAddInvocation { .into() } fn host_input(self) -> Result { - Ok(HostInput::new((&*self.link_add).try_into()?)) + Ok( + HostInput::new( + ValidateLinkAddData::from(self).try_into()? + ) + ) } } @@ -308,20 +323,20 @@ mod slow_tests { // #[tokio::test(threaded_scheduler)] async fn test_validate_link_add_implemented_invalid() { - let ribosome = WasmRibosomeFixturator::new(Zomes(vec![TestWasm::ValidateInvalid])) + let ribosome = WasmRibosomeFixturator::new(Zomes(vec![TestWasm::ValidateLinkAddInvalid])) .next() .unwrap(); - let mut validate_invocation = ValidateLinkAddInvocationFixturator::new(fixt::Empty) + let mut validate_link_add_invocation = ValidateLinkAddInvocationFixturator::new(fixt::Empty) .next() .unwrap(); - validate_invocation.zome_name = TestWasm::ValidateInvalid.into(); + validate_link_add_invocation.zome_name = TestWasm::ValidateLinkAddInvalid.into(); let result = ribosome - .run_validate_link_add(ValidateLinkAddHostAccess, validate_invocation) + .run_validate_link_add(ValidateLinkAddHostAccess, validate_link_add_invocation) .unwrap(); assert_eq!( result, - ValidateLinkAddResult::Invalid("esoteric edge case".into()), + ValidateLinkAddResult::Invalid("esoteric edge case (link version)".into()), ); } // diff --git a/crates/test_utils/wasm/build.rs b/crates/test_utils/wasm/build.rs index c60923e085..e721d5c37d 100644 --- a/crates/test_utils/wasm/build.rs +++ b/crates/test_utils/wasm/build.rs @@ -4,7 +4,7 @@ fn main() { let out_dir = std::env::var_os("OUT_DIR").unwrap(); println!("cargo:rerun-if-changed=Cargo.toml"); - // println!("cargo:rerun-if-changed=*"); + println!("cargo:rerun-if-changed=*"); println!("cargo:rerun-if-changed=../../../Cargo.lock"); // We want to rebuild if anything upstream of the wasms has changed. // Since we use local paths, changes to those crates will not affect the @@ -37,6 +37,7 @@ fn main() { "post_commit_success", "validate", "validate_invalid", + "validate_link_add_invalid", "validate_valid", "validation_package_fail", "validation_package_success", diff --git a/crates/test_utils/wasm/src/lib.rs b/crates/test_utils/wasm/src/lib.rs index d318c3555c..31cb6616a5 100644 --- a/crates/test_utils/wasm/src/lib.rs +++ b/crates/test_utils/wasm/src/lib.rs @@ -24,6 +24,7 @@ pub enum TestWasm { PostCommitSuccess, Validate, ValidateInvalid, + ValidateLinkAddInvalid, ValidateValid, ValidationPackageFail, ValidationPackageSuccess, @@ -50,6 +51,7 @@ impl From for ZomeName { TestWasm::PostCommitSuccess => "post_commit_success", TestWasm::Validate => "validate", TestWasm::ValidateInvalid => "validate_invalid", + TestWasm::ValidateLinkAddInvalid => "validate_link_add_invalid", TestWasm::ValidateValid => "validate_valid", TestWasm::ValidationPackageFail => "validation_package_fail", TestWasm::ValidationPackageSuccess => "validation_package_success", @@ -146,6 +148,11 @@ impl From for DnaWasm { "/wasm32-unknown-unknown/release/test_wasm_validate_invalid.wasm" )) .to_vec(), + TestWasm::ValidateLinkAddInvalid => include_bytes!(concat!( + env!("OUT_DIR"), + "/wasm32-unknown-unknown/release/test_wasm_validate_link_add_invalid.wasm" + )) + .to_vec(), TestWasm::ValidateValid => include_bytes!(concat!( env!("OUT_DIR"), "/wasm32-unknown-unknown/release/test_wasm_validate_valid.wasm" diff --git a/crates/test_utils/wasm/validate_link_add_invalid/Cargo.lock b/crates/test_utils/wasm/validate_link_add_invalid/Cargo.lock index ac403eb9e0..56da6102e8 100644 --- a/crates/test_utils/wasm/validate_link_add_invalid/Cargo.lock +++ b/crates/test_utils/wasm/validate_link_add_invalid/Cargo.lock @@ -91,6 +91,17 @@ dependencies = [ "typenum", ] +[[package]] +name = "hdk3" +version = "0.0.1" +dependencies = [ + "holo_hash", + "holochain_wasmer_guest", + "holochain_zome_types", + "serde", + "serde_bytes", +] + [[package]] name = "holo_hash" version = "0.0.1" @@ -556,9 +567,10 @@ dependencies = [ ] [[package]] -name = "test_wasm_validate_invalid" +name = "test_wasm_validate_link_add_invalid" version = "0.0.1" dependencies = [ + "hdk3", "holochain_serialized_bytes", "holochain_wasmer_guest", "holochain_zome_types", diff --git a/crates/test_utils/wasm/validate_link_add_invalid/Cargo.toml b/crates/test_utils/wasm/validate_link_add_invalid/Cargo.toml index a70c5464dd..6f87e260cb 100644 --- a/crates/test_utils/wasm/validate_link_add_invalid/Cargo.toml +++ b/crates/test_utils/wasm/validate_link_add_invalid/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "test_wasm_validate_invalid" +name = "test_wasm_validate_link_add_invalid" version = "0.0.1" authors = [ "thedavidmeister", "thedavidmeister@gmail.com" ] edition = "2018" @@ -16,7 +16,7 @@ opt-level = "z" [workspace] [lib] -name = "test_wasm_validate_invalid" +name = "test_wasm_validate_link_add_invalid" crate-type = [ "cdylib", "rlib" ] [dependencies] @@ -24,3 +24,4 @@ holochain_serialized_bytes = "=0.0.40" holochain_wasmer_guest = "=0.0.37" holochain_zome_types = { version = "=0.0.1", path = "../../../zome_types" } serde = "=1.0.104" +hdk3 = { path = "../../../hdk" } diff --git a/crates/test_utils/wasm/validate_link_add_invalid/src/lib.rs b/crates/test_utils/wasm/validate_link_add_invalid/src/lib.rs index fa3b379dd3..992982878e 100644 --- a/crates/test_utils/wasm/validate_link_add_invalid/src/lib.rs +++ b/crates/test_utils/wasm/validate_link_add_invalid/src/lib.rs @@ -1,19 +1,11 @@ use holochain_wasmer_guest::*; use holochain_zome_types::*; -use holochain_zome_types::validate::ValidateCallbackResult; +use hdk3::prelude::*; holochain_wasmer_guest::holochain_externs!(); -#[no_mangle] -/// this only runs for agent entries -/// this passes but should not override the base validate call that has an Invalid result -pub extern "C" fn validate_agent(_: GuestPtr) -> GuestPtr { - ret!(GuestOutput::new(try_result!(ValidateCallbackResult::Valid.try_into(), "failed to serialize valid agent callback"))) -} +map_extern!(validate_link, _validate_link); -#[no_mangle] -/// this runs for all entries -/// this never passes and so should always invalide the result for any input entry -pub extern "C" fn validate(_: GuestPtr) -> GuestPtr { - ret!(GuestOutput::new(try_result!(ValidateCallbackResult::Invalid("esoteric edge case".into()).try_into(), "failed to serialize validate return value"))); +pub fn _validate_link(_: ValidateLinkAddData) -> Result { + Ok(ValidateLinkAddCallbackResult::Invalid("esoteric edge case (link version)".into())) } diff --git a/crates/zome_types/src/validate_link_add.rs b/crates/zome_types/src/validate_link_add.rs index 65361ae705..ced38b6a1e 100644 --- a/crates/zome_types/src/validate_link_add.rs +++ b/crates/zome_types/src/validate_link_add.rs @@ -1,7 +1,16 @@ use crate::zome_io::GuestOutput; use crate::CallbackResult; +use crate::header::LinkAdd; +use crate::entry::Entry; use holochain_serialized_bytes::prelude::*; +#[derive(Serialize, Deserialize, SerializedBytes)] +pub struct ValidateLinkAddData { + pub link_add: LinkAdd, + pub base: Entry, + pub target: Entry, +} + #[derive(Clone, Debug, PartialEq, Serialize, Deserialize, SerializedBytes)] pub enum ValidateLinkAddCallbackResult { Valid, From 7ba521f75eb76cfd3b09490d5f299d3b776387ac Mon Sep 17 00:00:00 2001 From: David Meister Date: Tue, 4 Aug 2020 16:08:18 +0400 Subject: [PATCH 3/6] test_validate_implemented_valid --- crates/hdk/src/prelude.rs | 2 +- .../guest_callback/validate_link_add.rs | 45 +- .../src/core/workflow/call_zome_workflow.rs | 37 +- crates/test_utils/wasm/build.rs | 1 + crates/test_utils/wasm/src/lib.rs | 7 + .../wasm/validate_link_add_valid/Cargo.lock | 647 ++++++++++++++++++ .../wasm/validate_link_add_valid/Cargo.toml | 27 + .../wasm/validate_link_add_valid/src/lib.rs | 11 + crates/zome_types/src/validate_link_add.rs | 4 +- 9 files changed, 734 insertions(+), 47 deletions(-) create mode 100644 crates/test_utils/wasm/validate_link_add_valid/Cargo.lock create mode 100644 crates/test_utils/wasm/validate_link_add_valid/Cargo.toml create mode 100644 crates/test_utils/wasm/validate_link_add_valid/src/lib.rs diff --git a/crates/hdk/src/prelude.rs b/crates/hdk/src/prelude.rs index 49aba4f2d1..97200141d7 100644 --- a/crates/hdk/src/prelude.rs +++ b/crates/hdk/src/prelude.rs @@ -39,8 +39,8 @@ pub use holochain_zome_types::entry_def::EntryDefs; pub use holochain_zome_types::entry_def::EntryDefsCallbackResult; pub use holochain_zome_types::entry_def::EntryVisibility; pub use holochain_zome_types::entry_def::RequiredValidations; -pub use holochain_zome_types::zome_info::ZomeInfo; pub use holochain_zome_types::validate_link_add::ValidateLinkAddCallbackResult; pub use holochain_zome_types::validate_link_add::ValidateLinkAddData; +pub use holochain_zome_types::zome_info::ZomeInfo; pub use holochain_zome_types::*; pub use std::convert::TryFrom; diff --git a/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs b/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs index dd3a97a050..89353fd256 100644 --- a/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs +++ b/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs @@ -74,11 +74,7 @@ impl Invocation for ValidateLinkAddInvocation { .into() } fn host_input(self) -> Result { - Ok( - HostInput::new( - ValidateLinkAddData::from(self).try_into()? - ) - ) + Ok(HostInput::new(ValidateLinkAddData::from(self).try_into()?)) } } @@ -305,30 +301,31 @@ mod slow_tests { assert_eq!(result, ValidateLinkAddResult::Valid,); } - // #[tokio::test(threaded_scheduler)] - // async fn test_validate_implemented_valid() { - // let ribosome = WasmRibosomeFixturator::new(Zomes(vec![TestWasm::ValidateValid])) - // .next() - // .unwrap(); - // let mut validate_invocation = ValidateLinkAddInvocationFixturator::new(fixt::Empty) - // .next() - // .unwrap(); - // validate_invocation.zome_name = TestWasm::ValidateValid.into(); - // - // let result = ribosome - // .run_validate_link_add(ValidateLinkAddHostAccess, validate_invocation) - // .unwrap(); - // assert_eq!(result, ValidateLinkAddResult::Valid,); - // } - // #[tokio::test(threaded_scheduler)] - async fn test_validate_link_add_implemented_invalid() { - let ribosome = WasmRibosomeFixturator::new(Zomes(vec![TestWasm::ValidateLinkAddInvalid])) + async fn test_validate_implemented_valid() { + let ribosome = WasmRibosomeFixturator::new(Zomes(vec![TestWasm::ValidateLinkAddValid])) .next() .unwrap(); - let mut validate_link_add_invocation = ValidateLinkAddInvocationFixturator::new(fixt::Empty) + let mut validate_invocation = ValidateLinkAddInvocationFixturator::new(fixt::Empty) + .next() + .unwrap(); + validate_invocation.zome_name = TestWasm::ValidateLinkAddValid.into(); + + let result = ribosome + .run_validate_link_add(ValidateLinkAddHostAccess, validate_invocation) + .unwrap(); + assert_eq!(result, ValidateLinkAddResult::Valid,); + } + + #[tokio::test(threaded_scheduler)] + async fn test_validate_link_add_implemented_invalid() { + let ribosome = WasmRibosomeFixturator::new(Zomes(vec![TestWasm::ValidateLinkAddInvalid])) .next() .unwrap(); + let mut validate_link_add_invocation = + ValidateLinkAddInvocationFixturator::new(fixt::Empty) + .next() + .unwrap(); validate_link_add_invocation.zome_name = TestWasm::ValidateLinkAddInvalid.into(); let result = ribosome diff --git a/crates/holochain/src/core/workflow/call_zome_workflow.rs b/crates/holochain/src/core/workflow/call_zome_workflow.rs index 9e5024817c..99e3d02349 100644 --- a/crates/holochain/src/core/workflow/call_zome_workflow.rs +++ b/crates/holochain/src/core/workflow/call_zome_workflow.rs @@ -19,6 +19,7 @@ use crate::core::{ sys_validate_element, }; use fallible_iterator::FallibleIterator; +use holo_hash::AnyDhtHash; use holochain_keystore::KeystoreSender; use holochain_p2p::HolochainP2pCell; use holochain_state::prelude::*; @@ -141,36 +142,32 @@ async fn call_zome_workflow_inner<'env, Ribosome: RibosomeT>( ValidateLinkAddHostAccess, ValidateLinkAddInvocation { zome_name: zome_name.clone(), - base: Arc::new( + base: Arc::new({ + let base_address: AnyDhtHash = link_add.base_address.clone().into(); + #[allow(clippy::eval_order_dependence)] cascade - .dht_get(link_add.base_address.clone().into(), GetOptions.into()) + .dht_get(base_address.clone(), GetOptions.into()) .await .map_err(|e| RibosomeError::from(e))? - .ok_or(RibosomeError::ElementDeps( - link_add.base_address.clone().into(), - ))? + .ok_or_else(|| RibosomeError::ElementDeps(base_address.clone()))? .entry() .as_option() - .ok_or(RibosomeError::ElementDeps( - link_add.base_address.clone().into(), - ))? - .to_owned(), - ), - target: Arc::new( + .ok_or_else(|| RibosomeError::ElementDeps(base_address.clone()))? + .to_owned() + }), + target: Arc::new({ + let target_address: AnyDhtHash = link_add.target_address.clone().into(); + #[allow(clippy::eval_order_dependence)] cascade - .dht_get(link_add.target_address.clone().into(), GetOptions.into()) + .dht_get(target_address.clone(), GetOptions.into()) .await .map_err(|e| RibosomeError::from(e))? - .ok_or(RibosomeError::ElementDeps( - link_add.target_address.clone().into(), - ))? + .ok_or_else(|| RibosomeError::ElementDeps(target_address.clone()))? .entry() .as_option() - .ok_or(RibosomeError::ElementDeps( - link_add.target_address.clone().into(), - ))? - .to_owned(), - ), + .ok_or_else(|| RibosomeError::ElementDeps(target_address.clone()))? + .to_owned() + }), link_add: Arc::new(link_add.to_owned()), }, )?; diff --git a/crates/test_utils/wasm/build.rs b/crates/test_utils/wasm/build.rs index e721d5c37d..2d839ead28 100644 --- a/crates/test_utils/wasm/build.rs +++ b/crates/test_utils/wasm/build.rs @@ -39,6 +39,7 @@ fn main() { "validate_invalid", "validate_link_add_invalid", "validate_valid", + "validate_link_add_valid", "validation_package_fail", "validation_package_success", "whoami", diff --git a/crates/test_utils/wasm/src/lib.rs b/crates/test_utils/wasm/src/lib.rs index 31cb6616a5..c7012aa594 100644 --- a/crates/test_utils/wasm/src/lib.rs +++ b/crates/test_utils/wasm/src/lib.rs @@ -26,6 +26,7 @@ pub enum TestWasm { ValidateInvalid, ValidateLinkAddInvalid, ValidateValid, + ValidateLinkAddValid, ValidationPackageFail, ValidationPackageSuccess, WhoAmI, @@ -53,6 +54,7 @@ impl From for ZomeName { TestWasm::ValidateInvalid => "validate_invalid", TestWasm::ValidateLinkAddInvalid => "validate_link_add_invalid", TestWasm::ValidateValid => "validate_valid", + TestWasm::ValidateLinkAddValid => "validate_link_add_valid", TestWasm::ValidationPackageFail => "validation_package_fail", TestWasm::ValidationPackageSuccess => "validation_package_success", TestWasm::WhoAmI => "whoami", @@ -158,6 +160,11 @@ impl From for DnaWasm { "/wasm32-unknown-unknown/release/test_wasm_validate_valid.wasm" )) .to_vec(), + TestWasm::ValidateLinkAddValid => include_bytes!(concat!( + env!("OUT_DIR"), + "/wasm32-unknown-unknown/release/test_wasm_validate_link_add_valid.wasm" + )) + .to_vec(), TestWasm::ValidationPackageFail => include_bytes!(concat!( env!("OUT_DIR"), "/wasm32-unknown-unknown/release/test_wasm_validation_package_fail.wasm" diff --git a/crates/test_utils/wasm/validate_link_add_valid/Cargo.lock b/crates/test_utils/wasm/validate_link_add_valid/Cargo.lock new file mode 100644 index 0000000000..6f5d382073 --- /dev/null +++ b/crates/test_utils/wasm/validate_link_add_valid/Cargo.lock @@ -0,0 +1,647 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + +[[package]] +name = "autocfg" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" + +[[package]] +name = "autocfg" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "block-buffer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a076c298b9ecdb530ed9d967e74a6027d6a7478924520acddcddc24c1c8ab3ab" +dependencies = [ + "arrayref", + "byte-tools", +] + +[[package]] +name = "byte-tools" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40" + +[[package]] +name = "byteorder" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" + +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "digest" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90" +dependencies = [ + "generic-array", +] + +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + +[[package]] +name = "generic-array" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d" +dependencies = [ + "typenum", +] + +[[package]] +name = "hdk3" +version = "0.0.1" +dependencies = [ + "holo_hash", + "holochain_wasmer_guest", + "holochain_zome_types", + "serde", + "serde_bytes", +] + +[[package]] +name = "holo_hash" +version = "0.0.1" +dependencies = [ + "holochain_serialized_bytes", + "rmp-serde", + "serde", + "serde_bytes", +] + +[[package]] +name = "holochain_serialized_bytes" +version = "0.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03c9314720fa798e94b99ac219fd232c719688971adcf8c368c4e1aa91229183" +dependencies = [ + "holochain_serialized_bytes_derive", + "rmp-serde", + "serde", + "serde-transcode", + "serde_bytes", + "serde_json", + "thiserror", +] + +[[package]] +name = "holochain_serialized_bytes_derive" +version = "0.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90321247a91d3d01cf658465b5933dc40196321017f3c1a278725e004fc879a1" +dependencies = [ + "quote 0.6.13", + "syn 0.15.44", +] + +[[package]] +name = "holochain_wasmer_common" +version = "0.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "158532e5478884b8030477e6d8378de5f312f3401e8500dd551f8f5f0a819596" +dependencies = [ + "holochain_serialized_bytes", + "serde", + "thiserror", +] + +[[package]] +name = "holochain_wasmer_guest" +version = "0.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d38745de8587f886aec602bea3d051d9cbedbdfad467e7cc37c6348cbe8682" +dependencies = [ + "holochain_serialized_bytes", + "holochain_wasmer_common", + "serde", +] + +[[package]] +name = "holochain_zome_types" +version = "0.0.1" +dependencies = [ + "holo_hash", + "holochain_serialized_bytes", + "multihash", + "nanoid", + "rust-base58", + "serde", + "serde_bytes", +] + +[[package]] +name = "indexmap" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c398b2b113b55809ceb9ee3e753fcbac793f1956663f3c36549c1346015c2afe" +dependencies = [ + "autocfg 1.0.0", +] + +[[package]] +name = "itoa" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" + +[[package]] +name = "libc" +version = "0.2.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701" + +[[package]] +name = "multihash" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62469025f45dee2464ef9fc845f4683c543993792c1993e7d903c17a4546b74" +dependencies = [ + "sha1", + "sha2", + "tiny-keccak", +] + +[[package]] +name = "nanoid" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6226bc4e142124cb44e309a37a04cd9bb10e740d8642855441d3b14808f635e" +dependencies = [ + "rand", +] + +[[package]] +name = "num" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab3e176191bc4faad357e3122c4747aa098ac880e88b168f106386128736cf4a" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f3fc75e3697059fb1bc465e3d8cca6cf92f56854f201158b3f9c77d5a3cfa0" +dependencies = [ + "autocfg 1.0.0", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05ad05bd8977050b171b3f6b48175fea6e0565b7981059b486075e1026a9fb5" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" +dependencies = [ + "autocfg 1.0.0", + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6e6b7c748f995c4c29c5f5ae0248536e04a5739927c74ec0fa564805094b9f" +dependencies = [ + "autocfg 1.0.0", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5b4d7360f362cfb50dde8143501e6940b22f644be75a4cc90b2d81968908138" +dependencies = [ + "autocfg 1.0.0", + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" +dependencies = [ + "autocfg 1.0.0", +] + +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid 0.1.0", +] + +[[package]] +name = "proc-macro2" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" +dependencies = [ + "unicode-xid 0.2.1", +] + +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2 1.0.18", +] + +[[package]] +name = "rand" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +dependencies = [ + "autocfg 0.1.7", + "libc", + "rand_chacha", + "rand_core 0.4.2", + "rand_hc", + "rand_isaac", + "rand_jitter", + "rand_os", + "rand_pcg", + "rand_xorshift", + "winapi", +] + +[[package]] +name = "rand_chacha" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +dependencies = [ + "autocfg 0.1.7", + "rand_core 0.3.1", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_jitter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" +dependencies = [ + "libc", + "rand_core 0.4.2", + "winapi", +] + +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +dependencies = [ + "cloudabi", + "fuchsia-cprng", + "libc", + "rand_core 0.4.2", + "rdrand", + "winapi", +] + +[[package]] +name = "rand_pcg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +dependencies = [ + "autocfg 0.1.7", + "rand_core 0.4.2", +] + +[[package]] +name = "rand_xorshift" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rmp" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f10b46df14cf1ee1ac7baa4d2fbc2c52c0622a4b82fa8740e37bc452ac0184f" +dependencies = [ + "byteorder", + "num-traits", +] + +[[package]] +name = "rmp-serde" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c1ee98f14fe8b8e9c5ea13d25da7b2a1796169202c57a09d7288de90d56222b" +dependencies = [ + "byteorder", + "rmp", + "serde", +] + +[[package]] +name = "rust-base58" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b313b91fcdc6719ad41fa2dad2b7e810b03833fae4bf911950e15529a5f04439" +dependencies = [ + "num", +] + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "serde" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-transcode" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97528f0dfcf8ce2d51d995cb513a103b9cd301dc3f387a9cae5ef974381d4e1c" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_bytes" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.34", +] + +[[package]] +name = "serde_json" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "171698ce4ec7cbb93babeb3190021b4d72e96ccb98e33d277ae4ea959d6f2d9e" + +[[package]] +name = "sha2" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9eb6be24e4c23a84d7184280d2722f7f2731fcdd4a9d886efbfe4413e4847ea0" +dependencies = [ + "block-buffer", + "byte-tools", + "digest", + "fake-simd", +] + +[[package]] +name = "syn" +version = "0.15.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "unicode-xid 0.1.0", +] + +[[package]] +name = "syn" +version = "1.0.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936cae2873c940d92e697597c5eee105fb570cd5689c695806f672883653349b" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "unicode-xid 0.2.1", +] + +[[package]] +name = "test_wasm_validate_link_add_valid" +version = "0.0.1" +dependencies = [ + "hdk3", + "holochain_serialized_bytes", + "holochain_wasmer_guest", + "holochain_zome_types", + "serde", +] + +[[package]] +name = "thiserror" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.34", +] + +[[package]] +name = "tiny-keccak" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d8a021c69bb74a44ccedb824a046447e2c84a01df9e5c20779750acb38e11b2" +dependencies = [ + "crunchy", +] + +[[package]] +name = "typenum" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/crates/test_utils/wasm/validate_link_add_valid/Cargo.toml b/crates/test_utils/wasm/validate_link_add_valid/Cargo.toml new file mode 100644 index 0000000000..0175e1c487 --- /dev/null +++ b/crates/test_utils/wasm/validate_link_add_valid/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "test_wasm_validate_link_add_valid" +version = "0.0.1" +authors = [ "thedavidmeister", "thedavidmeister@gmail.com" ] +edition = "2018" + +[profile.dev] +opt-level = "z" + +[profile.release] +opt-level = "z" + +# Ensure that this is not inside of any other workspace. +# This crate should be an implementation detail of test_utils_wasm and +# therefore shouldn't be mentioned in the top-level Cargo.toml +[workspace] + +[lib] +name = "test_wasm_validate_link_add_valid" +crate-type = [ "cdylib", "rlib" ] + +[dependencies] +holochain_serialized_bytes = "=0.0.40" +holochain_wasmer_guest = "=0.0.37" +holochain_zome_types = { version = "=0.0.1", path = "../../../zome_types" } +serde = "=1.0.104" +hdk3 = { path = "../../../hdk" } diff --git a/crates/test_utils/wasm/validate_link_add_valid/src/lib.rs b/crates/test_utils/wasm/validate_link_add_valid/src/lib.rs new file mode 100644 index 0000000000..549ee064c9 --- /dev/null +++ b/crates/test_utils/wasm/validate_link_add_valid/src/lib.rs @@ -0,0 +1,11 @@ +use holochain_wasmer_guest::*; +use holochain_zome_types::*; +use hdk3::prelude::*; + +holochain_wasmer_guest::holochain_externs!(); + +map_extern!(validate_link, _validate_link); + +pub fn _validate_link(_: ValidateLinkAddData) -> Result { + Ok(ValidateLinkAddCallbackResult::Valid) +} diff --git a/crates/zome_types/src/validate_link_add.rs b/crates/zome_types/src/validate_link_add.rs index ced38b6a1e..cbd44c3aaa 100644 --- a/crates/zome_types/src/validate_link_add.rs +++ b/crates/zome_types/src/validate_link_add.rs @@ -1,7 +1,7 @@ +use crate::entry::Entry; +use crate::header::LinkAdd; use crate::zome_io::GuestOutput; use crate::CallbackResult; -use crate::header::LinkAdd; -use crate::entry::Entry; use holochain_serialized_bytes::prelude::*; #[derive(Serialize, Deserialize, SerializedBytes)] From 83efb73f7ce99e13cc06ef597f8ceccc84d22430 Mon Sep 17 00:00:00 2001 From: David Meister Date: Tue, 4 Aug 2020 16:28:40 +0400 Subject: [PATCH 4/6] wip on validate test --- .../guest_callback/validate_link_add.rs | 112 ++- .../test_utils/wasm/validate_link/Cargo.lock | 635 ++++++++++++++++++ .../test_utils/wasm/validate_link/Cargo.toml | 26 + .../test_utils/wasm/validate_link/src/lib.rs | 107 +++ 4 files changed, 812 insertions(+), 68 deletions(-) create mode 100644 crates/test_utils/wasm/validate_link/Cargo.lock create mode 100644 crates/test_utils/wasm/validate_link/Cargo.toml create mode 100644 crates/test_utils/wasm/validate_link/src/lib.rs diff --git a/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs b/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs index 89353fd256..8990c76270 100644 --- a/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs +++ b/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs @@ -336,74 +336,50 @@ mod slow_tests { ValidateLinkAddResult::Invalid("esoteric edge case (link version)".into()), ); } - // - // #[tokio::test(threaded_scheduler)] - // async fn test_validate_implemented_multi() { - // let ribosome = WasmRibosomeFixturator::new(Zomes(vec![TestWasm::ValidateInvalid])) - // .next() - // .unwrap(); - // let mut validate_invocation = ValidateLinkAddInvocationFixturator::new(fixt::Empty) - // .next() - // .unwrap(); - // let entry = Entry::Agent( - // AgentPubKeyFixturator::new(fixt::Unpredictable) - // .next() - // .unwrap() - // .into(), - // ); - // - // validate_invocation.zome_name = TestWasm::ValidateInvalid.into(); - // validate_invocation.link_add = Arc::new(link_add); - // - // let result = ribosome - // .run_validate_link_add(ValidateLinkAddHostAccess, validate_invocation) - // .unwrap(); - // assert_eq!(result, ValidateLinkAddResult::Invalid("esoteric edge case".into())); - // } - // - // #[tokio::test(threaded_scheduler)] - // async fn pass_validate_test<'a>() { - // // test workspace boilerplate - // let env = holochain_state::test_utils::test_cell_env(); - // let dbs = env.dbs().await; - // let env_ref = env.guard().await; - // let reader = holochain_state::env::ReadManager::reader(&env_ref).unwrap(); - // let mut workspace = ::new(&reader, &dbs).unwrap(); - // - // // commits fail validation if we don't do genesis - // crate::core::workflow::fake_genesis(&mut workspace.source_chain) - // .await - // .unwrap(); - // - // let (_g, raw_workspace) = - // crate::core::workflow::unsafe_call_zome_workspace::UnsafeCallZomeWorkspace::from_mut( - // &mut workspace, - // ); - // let mut host_access = fixt!(ZomeCallHostAccess); - // host_access.workspace = raw_workspace.clone(); - // - // let output: CommitEntryOutput = - // crate::call_test_ribosome!(host_access, TestWasm::Validate, "always_validates", ()); - // - // // the chain head should be the committed entry header - // let call = - // |workspace: &'a mut CallZomeWorkspace| -> BoxFuture<'a, SourceChainResult> { - // async move { - // let source_chain = &mut workspace.source_chain; - // Ok(source_chain.chain_head()?.to_owned()) - // } - // .boxed() - // }; - // let chain_head = - // tokio_safe_block_on::tokio_safe_block_forever_on(tokio::task::spawn(async move { - // unsafe { raw_workspace.apply_mut(call).await } - // })) - // .unwrap() - // .unwrap() - // .unwrap(); - // - // assert_eq!(chain_head, output.into_inner(),); - // } + + #[tokio::test(threaded_scheduler)] + async fn pass_validate_test<'a>() { + // test workspace boilerplate + let env = holochain_state::test_utils::test_cell_env(); + let dbs = env.dbs().await; + let env_ref = env.guard().await; + let reader = holochain_state::env::ReadManager::reader(&env_ref).unwrap(); + let mut workspace = ::new(&reader, &dbs).unwrap(); + + // commits fail validation if we don't do genesis + crate::core::workflow::fake_genesis(&mut workspace.source_chain) + .await + .unwrap(); + + let (_g, raw_workspace) = + crate::core::workflow::unsafe_call_zome_workspace::UnsafeCallZomeWorkspace::from_mut( + &mut workspace, + ); + let mut host_access = fixt!(ZomeCallHostAccess); + host_access.workspace = raw_workspace.clone(); + + let output: CommitEntryOutput = + crate::call_test_ribosome!(host_access, TestWasm::Validate, "always_validates", ()); + + // the chain head should be the committed entry header + let call = + |workspace: &'a mut CallZomeWorkspace| -> BoxFuture<'a, SourceChainResult> { + async move { + let source_chain = &mut workspace.source_chain; + Ok(source_chain.chain_head()?.to_owned()) + } + .boxed() + }; + let chain_head = + tokio_safe_block_on::tokio_safe_block_forever_on(tokio::task::spawn(async move { + unsafe { raw_workspace.apply_mut(call).await } + })) + .unwrap() + .unwrap() + .unwrap(); + + assert_eq!(chain_head, output.into_inner(),); + } // // #[tokio::test(threaded_scheduler)] // async fn fail_validate_test<'a>() { diff --git a/crates/test_utils/wasm/validate_link/Cargo.lock b/crates/test_utils/wasm/validate_link/Cargo.lock new file mode 100644 index 0000000000..7fde115d38 --- /dev/null +++ b/crates/test_utils/wasm/validate_link/Cargo.lock @@ -0,0 +1,635 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + +[[package]] +name = "autocfg" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" + +[[package]] +name = "autocfg" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "block-buffer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a076c298b9ecdb530ed9d967e74a6027d6a7478924520acddcddc24c1c8ab3ab" +dependencies = [ + "arrayref", + "byte-tools", +] + +[[package]] +name = "byte-tools" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40" + +[[package]] +name = "byteorder" +version = "1.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" + +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "digest" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90" +dependencies = [ + "generic-array", +] + +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" + +[[package]] +name = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" + +[[package]] +name = "generic-array" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d" +dependencies = [ + "typenum", +] + +[[package]] +name = "holo_hash" +version = "0.0.1" +dependencies = [ + "holochain_serialized_bytes", + "rmp-serde", + "serde", + "serde_bytes", +] + +[[package]] +name = "holochain_serialized_bytes" +version = "0.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03c9314720fa798e94b99ac219fd232c719688971adcf8c368c4e1aa91229183" +dependencies = [ + "holochain_serialized_bytes_derive", + "rmp-serde", + "serde", + "serde-transcode", + "serde_bytes", + "serde_json", + "thiserror", +] + +[[package]] +name = "holochain_serialized_bytes_derive" +version = "0.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90321247a91d3d01cf658465b5933dc40196321017f3c1a278725e004fc879a1" +dependencies = [ + "quote 0.6.13", + "syn 0.15.44", +] + +[[package]] +name = "holochain_wasmer_common" +version = "0.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "158532e5478884b8030477e6d8378de5f312f3401e8500dd551f8f5f0a819596" +dependencies = [ + "holochain_serialized_bytes", + "serde", + "thiserror", +] + +[[package]] +name = "holochain_wasmer_guest" +version = "0.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d38745de8587f886aec602bea3d051d9cbedbdfad467e7cc37c6348cbe8682" +dependencies = [ + "holochain_serialized_bytes", + "holochain_wasmer_common", + "serde", +] + +[[package]] +name = "holochain_zome_types" +version = "0.0.1" +dependencies = [ + "holo_hash", + "holochain_serialized_bytes", + "multihash", + "nanoid", + "rust-base58", + "serde", + "serde_bytes", +] + +[[package]] +name = "indexmap" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c398b2b113b55809ceb9ee3e753fcbac793f1956663f3c36549c1346015c2afe" +dependencies = [ + "autocfg 1.0.0", +] + +[[package]] +name = "itoa" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" + +[[package]] +name = "libc" +version = "0.2.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9f8082297d534141b30c8d39e9b1773713ab50fdbe4ff30f750d063b3bfd701" + +[[package]] +name = "multihash" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c62469025f45dee2464ef9fc845f4683c543993792c1993e7d903c17a4546b74" +dependencies = [ + "sha1", + "sha2", + "tiny-keccak", +] + +[[package]] +name = "nanoid" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6226bc4e142124cb44e309a37a04cd9bb10e740d8642855441d3b14808f635e" +dependencies = [ + "rand", +] + +[[package]] +name = "num" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab3e176191bc4faad357e3122c4747aa098ac880e88b168f106386128736cf4a" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f3fc75e3697059fb1bc465e3d8cca6cf92f56854f201158b3f9c77d5a3cfa0" +dependencies = [ + "autocfg 1.0.0", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05ad05bd8977050b171b3f6b48175fea6e0565b7981059b486075e1026a9fb5" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d59457e662d541ba17869cf51cf177c0b5f0cbf476c66bdc90bf1edac4f875b" +dependencies = [ + "autocfg 1.0.0", + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6e6b7c748f995c4c29c5f5ae0248536e04a5739927c74ec0fa564805094b9f" +dependencies = [ + "autocfg 1.0.0", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5b4d7360f362cfb50dde8143501e6940b22f644be75a4cc90b2d81968908138" +dependencies = [ + "autocfg 1.0.0", + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac267bcc07f48ee5f8935ab0d24f316fb722d7a1292e2913f0cc196b29ffd611" +dependencies = [ + "autocfg 1.0.0", +] + +[[package]] +name = "proc-macro2" +version = "0.4.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +dependencies = [ + "unicode-xid 0.1.0", +] + +[[package]] +name = "proc-macro2" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" +dependencies = [ + "unicode-xid 0.2.1", +] + +[[package]] +name = "quote" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" +dependencies = [ + "proc-macro2 0.4.30", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2 1.0.18", +] + +[[package]] +name = "rand" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +dependencies = [ + "autocfg 0.1.7", + "libc", + "rand_chacha", + "rand_core 0.4.2", + "rand_hc", + "rand_isaac", + "rand_jitter", + "rand_os", + "rand_pcg", + "rand_xorshift", + "winapi", +] + +[[package]] +name = "rand_chacha" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +dependencies = [ + "autocfg 0.1.7", + "rand_core 0.3.1", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +dependencies = [ + "rand_core 0.4.2", +] + +[[package]] +name = "rand_core" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" + +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rand_jitter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" +dependencies = [ + "libc", + "rand_core 0.4.2", + "winapi", +] + +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +dependencies = [ + "cloudabi", + "fuchsia-cprng", + "libc", + "rand_core 0.4.2", + "rdrand", + "winapi", +] + +[[package]] +name = "rand_pcg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +dependencies = [ + "autocfg 0.1.7", + "rand_core 0.4.2", +] + +[[package]] +name = "rand_xorshift" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +dependencies = [ + "rand_core 0.3.1", +] + +[[package]] +name = "rmp" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f10b46df14cf1ee1ac7baa4d2fbc2c52c0622a4b82fa8740e37bc452ac0184f" +dependencies = [ + "byteorder", + "num-traits", +] + +[[package]] +name = "rmp-serde" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c1ee98f14fe8b8e9c5ea13d25da7b2a1796169202c57a09d7288de90d56222b" +dependencies = [ + "byteorder", + "rmp", + "serde", +] + +[[package]] +name = "rust-base58" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b313b91fcdc6719ad41fa2dad2b7e810b03833fae4bf911950e15529a5f04439" +dependencies = [ + "num", +] + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "serde" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-transcode" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97528f0dfcf8ce2d51d995cb513a103b9cd301dc3f387a9cae5ef974381d4e1c" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_bytes" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.34", +] + +[[package]] +name = "serde_json" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "171698ce4ec7cbb93babeb3190021b4d72e96ccb98e33d277ae4ea959d6f2d9e" + +[[package]] +name = "sha2" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9eb6be24e4c23a84d7184280d2722f7f2731fcdd4a9d886efbfe4413e4847ea0" +dependencies = [ + "block-buffer", + "byte-tools", + "digest", + "fake-simd", +] + +[[package]] +name = "syn" +version = "0.15.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" +dependencies = [ + "proc-macro2 0.4.30", + "quote 0.6.13", + "unicode-xid 0.1.0", +] + +[[package]] +name = "syn" +version = "1.0.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "936cae2873c940d92e697597c5eee105fb570cd5689c695806f672883653349b" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "unicode-xid 0.2.1", +] + +[[package]] +name = "test_wasm_validate" +version = "0.0.1" +dependencies = [ + "holochain_serialized_bytes", + "holochain_wasmer_guest", + "holochain_zome_types", + "serde", +] + +[[package]] +name = "thiserror" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793" +dependencies = [ + "proc-macro2 1.0.18", + "quote 1.0.7", + "syn 1.0.34", +] + +[[package]] +name = "tiny-keccak" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d8a021c69bb74a44ccedb824a046447e2c84a01df9e5c20779750acb38e11b2" +dependencies = [ + "crunchy", +] + +[[package]] +name = "typenum" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" + +[[package]] +name = "unicode-xid" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/crates/test_utils/wasm/validate_link/Cargo.toml b/crates/test_utils/wasm/validate_link/Cargo.toml new file mode 100644 index 0000000000..07b6f664f6 --- /dev/null +++ b/crates/test_utils/wasm/validate_link/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "test_wasm_validate" +version = "0.0.1" +authors = [ "thedavidmeister", "thedavidmeister@gmail.com" ] +edition = "2018" + +[profile.dev] +opt-level = "z" + +[profile.release] +opt-level = "z" + +# Ensure that this is not inside of any other workspace. +# This crate should be an implementation detail of test_utils_wasm and +# therefore shouldn't be mentioned in the top-level Cargo.toml +[workspace] + +[lib] +name = "test_wasm_validate" +crate-type = [ "cdylib", "rlib" ] + +[dependencies] +holochain_serialized_bytes = "=0.0.40" +holochain_wasmer_guest = "=0.0.37" +holochain_zome_types = { version = "=0.0.1", path = "../../../zome_types" } +serde = "=1.0.104" diff --git a/crates/test_utils/wasm/validate_link/src/lib.rs b/crates/test_utils/wasm/validate_link/src/lib.rs new file mode 100644 index 0000000000..ca6fc96248 --- /dev/null +++ b/crates/test_utils/wasm/validate_link/src/lib.rs @@ -0,0 +1,107 @@ +use holochain_wasmer_guest::*; +use holochain_zome_types::*; +use holochain_zome_types::validate::ValidateCallbackResult; +use holochain_zome_types::entry_def::EntryDefId; +use holochain_zome_types::entry_def::EntryDefsCallbackResult; +use holochain_zome_types::entry_def::EntryDefs; +use holochain_zome_types::entry_def::EntryDef; +use holochain_zome_types::crdt::CrdtType; +use holochain_zome_types::entry_def::RequiredValidations; +use holochain_zome_types::entry_def::EntryVisibility; + +holochain_wasmer_guest::holochain_externs!(); + +/// an example inner value that can be serialized into the contents of Entry::App() +#[derive(Deserialize, Serialize, SerializedBytes)] +enum ThisWasmEntry { + AlwaysValidates, + NeverValidates, +} + +impl From<&ThisWasmEntry> for EntryDefId { + fn from(entry: &ThisWasmEntry) -> Self { + match entry { + ThisWasmEntry::AlwaysValidates => "always_validates", + ThisWasmEntry::NeverValidates => "never_validates", + }.into() + } +} + +impl From<&ThisWasmEntry> for CrdtType { + fn from(_: &ThisWasmEntry) -> Self { + Self + } +} + +impl From<&ThisWasmEntry> for RequiredValidations { + fn from(_: &ThisWasmEntry) -> Self { + 5.into() + } +} + +impl From<&ThisWasmEntry> for EntryVisibility { + fn from(_: &ThisWasmEntry) -> Self { + Self::Public + } +} + +impl From<&ThisWasmEntry> for EntryDef { + fn from(entry: &ThisWasmEntry) -> Self { + Self { + id: entry.into(), + crdt_type: entry.into(), + required_validations: entry.into(), + visibility: entry.into(), + } + } +} + +#[no_mangle] +pub extern "C" fn entry_defs(_: GuestPtr) -> GuestPtr { + let defs: EntryDefs = vec![ + (&ThisWasmEntry::AlwaysValidates).into(), + (&ThisWasmEntry::NeverValidates).into(), + ].into(); + + ret!(GuestOutput::new(try_result!(EntryDefsCallbackResult::Defs( + defs, + ).try_into(), "failed to serialize entry defs return value"))); +} + +#[no_mangle] +pub extern "C" fn validate(host_allocation_ptr: GuestPtr) -> GuestPtr { + // load host args + let input: HostInput = host_args!(host_allocation_ptr); + + // extract the entry to validate + let result: ValidateCallbackResult = match Entry::try_from(input.into_inner()) { + // we do want to validate our app entries + Ok(Entry::App(serialized_bytes)) => match ThisWasmEntry::try_from(serialized_bytes) { + // the AlwaysValidates variant passes + Ok(ThisWasmEntry::AlwaysValidates) => ValidateCallbackResult::Valid, + // the NeverValidates variants fails + Ok(ThisWasmEntry::NeverValidates) => ValidateCallbackResult::Invalid("NeverValidates never validates".to_string()), + _ => ValidateCallbackResult::Invalid("Couldn't get ThisWasmEntry from the app entry".to_string()), + }, + // other entry types we don't care about + Ok(_) => ValidateCallbackResult::Valid, + _ => ValidateCallbackResult::Invalid("Couldn't get App serialized bytes from host input".to_string()), + }; + + ret!(GuestOutput::new(try_result!(result.try_into(), "failed to serialize return value".to_string()))); +} + +/// we can write normal rust code with Results outside our externs +fn _commit_validate(to_commit: ThisWasmEntry) -> Result { + let commit_output: CommitEntryOutput = host_call!(__commit_entry, CommitEntryInput::new(((&to_commit).into(), Entry::App(to_commit.try_into()?))))?; + Ok(GuestOutput::new(commit_output.try_into()?)) +} + +#[no_mangle] +pub extern "C" fn always_validates(_: GuestPtr) -> GuestPtr { + ret!(try_result!(_commit_validate(ThisWasmEntry::AlwaysValidates), "error processing commit")) +} +#[no_mangle] +pub extern "C" fn never_validates(_: GuestPtr) -> GuestPtr { + ret!(try_result!(_commit_validate(ThisWasmEntry::NeverValidates), "error processing commit")) +} From dce15bd9ffe8121f3cf4fe686a0da913cf79850d Mon Sep 17 00:00:00 2001 From: David Meister Date: Wed, 5 Aug 2020 14:15:41 +0400 Subject: [PATCH 5/6] working tests for validate link add --- crates/hdk/src/api.rs | 20 ++ crates/hdk/src/hash_path/anchor.rs | 2 +- crates/hdk/src/hash_path/path.rs | 4 +- .../guest_callback/validate_link_add.rs | 232 +++++++----------- crates/holochain/src/fixt.rs | 6 + crates/test_utils/wasm/build.rs | 1 + .../test_utils/wasm/commit_entry/src/lib.rs | 2 +- crates/test_utils/wasm/entry_defs/src/lib.rs | 2 + crates/test_utils/wasm/src/lib.rs | 7 + .../test_utils/wasm/validate_link/Cargo.lock | 14 +- .../test_utils/wasm/validate_link/Cargo.toml | 5 +- .../test_utils/wasm/validate_link/src/lib.rs | 122 +++------ 12 files changed, 181 insertions(+), 236 deletions(-) diff --git a/crates/hdk/src/api.rs b/crates/hdk/src/api.rs index da0701f50e..3a4579e15b 100644 --- a/crates/hdk/src/api.rs +++ b/crates/hdk/src/api.rs @@ -43,6 +43,26 @@ macro_rules! entry_def { } } + impl TryFrom<&$crate::prelude::Entry> for $t { + type Error = $crate::prelude::SerializedBytesError; + fn try_from(entry: &$crate::prelude::Entry) -> Result { + match entry { + Entry::App(sb) => Ok(Self::try_from(sb.to_owned())?), + _ => Err($crate::prelude::SerializedBytesError::FromBytes(format!( + "{:?} is not an Entry::App so has no serialized bytes", + entry + ))), + } + } + } + + impl TryFrom<$crate::prelude::Entry> for $t { + type Error = $crate::prelude::SerializedBytesError; + fn try_from(entry: $crate::prelude::Entry) -> Result { + Self::try_from(&entry) + } + } + impl From<$t> for $crate::prelude::EntryDef { fn from(_: $t) -> Self { $t::entry_def() diff --git a/crates/hdk/src/hash_path/anchor.rs b/crates/hdk/src/hash_path/anchor.rs index f69007b08f..46a404f8f8 100644 --- a/crates/hdk/src/hash_path/anchor.rs +++ b/crates/hdk/src/hash_path/anchor.rs @@ -6,7 +6,7 @@ use holochain_wasmer_guest::*; /// "anchor" pub const ROOT: &str = "hdk3anchor"; -#[derive(PartialEq, serde::Serialize, serde::Deserialize, Debug, SerializedBytes, Clone)] +#[derive(PartialEq, SerializedBytes, serde::Serialize, serde::Deserialize, Debug, Clone)] pub struct Anchor { pub anchor_type: String, pub anchor_text: Option, diff --git a/crates/hdk/src/hash_path/path.rs b/crates/hdk/src/hash_path/path.rs index 99ee68db39..222246f86e 100644 --- a/crates/hdk/src/hash_path/path.rs +++ b/crates/hdk/src/hash_path/path.rs @@ -22,9 +22,7 @@ pub const NAME: [u8; 8] = [0x68, 0x64, 0x6b, 0x2e, 0x70, 0x61, 0x74, 0x68]; /// each path component is arbitrary bytes to be hashed together in a predictable way when the path /// is hashed to create something that can be linked and discovered by all DHT participants -#[derive( - Clone, PartialEq, Debug, Default, serde::Deserialize, serde::Serialize, SerializedBytes, -)] +#[derive(Clone, PartialEq, Debug, Default, serde::Deserialize, serde::Serialize)] #[repr(transparent)] pub struct Component(#[serde(with = "serde_bytes")] Vec); diff --git a/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs b/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs index 8990c76270..2427f6934b 100644 --- a/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs +++ b/crates/holochain/src/core/ribosome/guest_callback/validate_link_add.rs @@ -120,40 +120,31 @@ mod test { use super::ValidateLinkAddResult; use crate::core::ribosome::Invocation; use crate::core::ribosome::ZomesToInvoke; - use crate::fixt::ValidateHostAccessFixturator; - use crate::fixt::ValidateInvocationFixturator; - use crate::fixt::ZomeCallCapGrantFixturator; + use crate::fixt::ValidateLinkAddHostAccessFixturator; + use crate::fixt::ValidateLinkAddInvocationFixturator; use ::fixt::prelude::*; - use holo_hash::fixt::AgentPubKeyFixturator; use holochain_serialized_bytes::prelude::*; - use holochain_types::{dna::zome::HostFnAccess, fixt::CapClaimFixturator}; - use holochain_zome_types::entry::Entry; + use holochain_types::dna::zome::HostFnAccess; use holochain_zome_types::validate_link_add::ValidateLinkAddCallbackResult; + use holochain_zome_types::validate_link_add::ValidateLinkAddData; use holochain_zome_types::HostInput; use rand::seq::SliceRandom; - use std::sync::Arc; #[tokio::test(threaded_scheduler)] - async fn validate_callback_result_fold() { + async fn validate_link_add_callback_result_fold() { let mut rng = thread_rng(); let result_valid = || ValidateLinkAddResult::Valid; - // let result_ud = || ValidateLinkAddResult::UnresolvedDependencies(vec![]); let result_invalid = || ValidateLinkAddResult::Invalid("".into()); let cb_valid = || ValidateLinkAddCallbackResult::Valid; - // let cb_ud = || ValidateCallbackResult::UnresolvedDependencies(vec![]); let cb_invalid = || ValidateLinkAddCallbackResult::Invalid("".into()); for (mut results, expected) in vec![ (vec![], result_valid()), (vec![cb_valid()], result_valid()), (vec![cb_invalid()], result_invalid()), - // (vec![cb_ud()], result_ud()), (vec![cb_invalid(), cb_valid()], result_invalid()), - // (vec![cb_invalid(), cb_ud()], result_invalid()), - // (vec![cb_valid(), cb_ud()], result_ud()), - // (vec![cb_valid(), cb_ud(), cb_invalid()], result_invalid()), ] { // order of the results should not change the final result results.shuffle(&mut rng); @@ -173,91 +164,58 @@ mod test { } #[tokio::test(threaded_scheduler)] - async fn validate_invocation_allow_side_effects() { - let validate_host_access = ValidateHostAccessFixturator::new(fixt::Unpredictable) - .next() - .unwrap(); + async fn validate_link_add_invocation_allow_side_effects() { + let validate_link_add_host_access = + ValidateLinkAddHostAccessFixturator::new(fixt::Unpredictable) + .next() + .unwrap(); assert_eq!( - HostFnAccess::from(&validate_host_access), + HostFnAccess::from(&validate_link_add_host_access), HostFnAccess::none(), ); } #[tokio::test(threaded_scheduler)] - async fn validate_invocation_zomes() { - let validate_invocation = ValidateInvocationFixturator::new(fixt::Unpredictable) - .next() - .unwrap(); - let zome_name = validate_invocation.zome_name.clone(); - assert_eq!(ZomesToInvoke::One(zome_name), validate_invocation.zomes(),); - } - - #[tokio::test(threaded_scheduler)] - async fn validate_invocation_fn_components() { - let mut validate_invocation = ValidateInvocationFixturator::new(fixt::Unpredictable) - .next() - .unwrap(); - - let agent_entry = Entry::Agent( - AgentPubKeyFixturator::new(fixt::Unpredictable) + async fn validate_link_add_invocation_zomes() { + let validate_link_add_invocation = + ValidateLinkAddInvocationFixturator::new(fixt::Unpredictable) .next() - .unwrap() - .into(), - ); - validate_invocation.entry = Arc::new(agent_entry); - let mut expected = vec!["validate", "validate_agent"]; - for fn_component in validate_invocation.fn_components() { - assert_eq!(fn_component, expected.pop().unwrap(),); - } - - let agent_entry = Entry::App( - SerializedBytesFixturator::new(fixt::Unpredictable) - .next() - .unwrap() - .into(), + .unwrap(); + let zome_name = validate_link_add_invocation.zome_name.clone(); + assert_eq!( + ZomesToInvoke::One(zome_name), + validate_link_add_invocation.zomes(), ); - validate_invocation.entry = Arc::new(agent_entry); - let mut expected = vec!["validate", "validate_entry"]; - for fn_component in validate_invocation.fn_components() { - assert_eq!(fn_component, expected.pop().unwrap(),); - } + } - let agent_entry = Entry::CapClaim( - CapClaimFixturator::new(fixt::Unpredictable) + #[tokio::test(threaded_scheduler)] + async fn validate_link_add_invocation_fn_components() { + let validate_link_add_invocation = + ValidateLinkAddInvocationFixturator::new(fixt::Unpredictable) .next() - .unwrap() - .into(), - ); - validate_invocation.entry = Arc::new(agent_entry); - let mut expected = vec!["validate", "validate_cap_claim"]; - for fn_component in validate_invocation.fn_components() { - assert_eq!(fn_component, expected.pop().unwrap(),); - } + .unwrap(); - let agent_entry = Entry::CapGrant( - ZomeCallCapGrantFixturator::new(fixt::Unpredictable) - .next() - .unwrap() - .into(), - ); - validate_invocation.entry = Arc::new(agent_entry); - let mut expected = vec!["validate", "validate_cap_grant"]; - for fn_component in validate_invocation.fn_components() { + let mut expected = vec!["validate_link", "validate_link_add"]; + for fn_component in validate_link_add_invocation.fn_components() { assert_eq!(fn_component, expected.pop().unwrap(),); } } #[tokio::test(threaded_scheduler)] - async fn validate_invocation_host_input() { - let validate_invocation = ValidateInvocationFixturator::new(fixt::Unpredictable) - .next() - .unwrap(); + async fn validate_link_add_invocation_host_input() { + let validate_link_add_invocation = + ValidateLinkAddInvocationFixturator::new(fixt::Unpredictable) + .next() + .unwrap(); - let host_input = validate_invocation.clone().host_input().unwrap(); + let host_input = validate_link_add_invocation.clone().host_input().unwrap(); assert_eq!( host_input, - HostInput::new(SerializedBytes::try_from(&*validate_invocation.entry).unwrap()), + HostInput::new( + SerializedBytes::try_from(&ValidateLinkAddData::from(validate_link_add_invocation)) + .unwrap() + ), ); } } @@ -269,21 +227,17 @@ mod slow_tests { use super::ValidateLinkAddHostAccess; use super::ValidateLinkAddResult; use crate::core::ribosome::RibosomeT; - // use crate::core::state::source_chain::SourceChainResult; - // use crate::core::workflow::call_zome_workflow::CallZomeWorkspace; + use crate::core::state::source_chain::SourceChainResult; + use crate::core::workflow::call_zome_workflow::CallZomeWorkspace; use crate::fixt::curve::Zomes; use crate::fixt::ValidateLinkAddInvocationFixturator; use crate::fixt::WasmRibosomeFixturator; - // use crate::fixt::ZomeCallHostAccessFixturator; - // use fixt::prelude::*; - // use futures::future::BoxFuture; - // use futures::future::FutureExt; - // use holo_hash::fixt::AgentPubKeyFixturator; - // use holo_hash::HeaderHash; + use crate::fixt::ZomeCallHostAccessFixturator; + use fixt::prelude::*; + use futures::future::BoxFuture; + use futures::future::FutureExt; + use holo_hash::HeaderHash; use holochain_wasm_test_utils::TestWasm; - // use holochain_zome_types::CommitEntryOutput; - // use holochain_zome_types::Entry; - // use std::sync::Arc; #[tokio::test(threaded_scheduler)] async fn test_validate_link_add_unimplemented() { @@ -338,7 +292,7 @@ mod slow_tests { } #[tokio::test(threaded_scheduler)] - async fn pass_validate_test<'a>() { + async fn pass_validate_link_add_test<'a>() { // test workspace boilerplate let env = holochain_state::test_utils::test_cell_env(); let dbs = env.dbs().await; @@ -358,8 +312,53 @@ mod slow_tests { let mut host_access = fixt!(ZomeCallHostAccess); host_access.workspace = raw_workspace.clone(); - let output: CommitEntryOutput = - crate::call_test_ribosome!(host_access, TestWasm::Validate, "always_validates", ()); + let output: HeaderHash = + crate::call_test_ribosome!(host_access, TestWasm::ValidateLink, "add_valid_link", ()); + + // the chain head should be the committed entry header + let call = + |workspace: &'a mut CallZomeWorkspace| -> BoxFuture<'a, SourceChainResult> { + async move { + let source_chain = &mut workspace.source_chain; + Ok(source_chain.chain_head()?.to_owned()) + } + .boxed() + }; + let chain_head = + tokio_safe_block_on::tokio_safe_block_forever_on(tokio::task::spawn(async move { + unsafe { raw_workspace.apply_mut(call).await } + })) + .unwrap() + .unwrap() + .unwrap(); + + assert_eq!(chain_head, output,); + } + + #[tokio::test(threaded_scheduler)] + async fn fail_validate_link_add_test<'a>() { + // test workspace boilerplate + let env = holochain_state::test_utils::test_cell_env(); + let dbs = env.dbs().await; + let env_ref = env.guard().await; + let reader = holochain_state::env::ReadManager::reader(&env_ref).unwrap(); + let mut workspace = ::new(&reader, &dbs).unwrap(); + + // commits fail validation if we don't do genesis + crate::core::workflow::fake_genesis(&mut workspace.source_chain) + .await + .unwrap(); + + let (_g, raw_workspace) = + crate::core::workflow::unsafe_call_zome_workspace::UnsafeCallZomeWorkspace::from_mut( + &mut workspace, + ); + + let mut host_access = fixt!(ZomeCallHostAccess); + host_access.workspace = raw_workspace.clone(); + + let output: HeaderHash = + crate::call_test_ribosome!(host_access, TestWasm::ValidateLink, "add_invalid_link", ()); // the chain head should be the committed entry header let call = @@ -378,51 +377,6 @@ mod slow_tests { .unwrap() .unwrap(); - assert_eq!(chain_head, output.into_inner(),); + assert_eq!(chain_head, output,); } - // - // #[tokio::test(threaded_scheduler)] - // async fn fail_validate_test<'a>() { - // // test workspace boilerplate - // let env = holochain_state::test_utils::test_cell_env(); - // let dbs = env.dbs().await; - // let env_ref = env.guard().await; - // let reader = holochain_state::env::ReadManager::reader(&env_ref).unwrap(); - // let mut workspace = ::new(&reader, &dbs).unwrap(); - // - // // commits fail validation if we don't do genesis - // crate::core::workflow::fake_genesis(&mut workspace.source_chain) - // .await - // .unwrap(); - // - // let (_g, raw_workspace) = - // crate::core::workflow::unsafe_call_zome_workspace::UnsafeCallZomeWorkspace::from_mut( - // &mut workspace, - // ); - // - // let mut host_access = fixt!(ZomeCallHostAccess); - // host_access.workspace = raw_workspace.clone(); - // - // let output: CommitEntryOutput = - // crate::call_test_ribosome!(host_access, TestWasm::Validate, "never_validates", ()); - // - // // the chain head should be the committed entry header - // let call = - // |workspace: &'a mut CallZomeWorkspace| -> BoxFuture<'a, SourceChainResult> { - // async move { - // let source_chain = &mut workspace.source_chain; - // Ok(source_chain.chain_head()?.to_owned()) - // } - // .boxed() - // }; - // let chain_head = - // tokio_safe_block_on::tokio_safe_block_forever_on(tokio::task::spawn(async move { - // unsafe { raw_workspace.apply_mut(call).await } - // })) - // .unwrap() - // .unwrap() - // .unwrap(); - // - // assert_eq!(chain_head, output.into_inner(),); - // } } diff --git a/crates/holochain/src/fixt.rs b/crates/holochain/src/fixt.rs index e9fa4df9ba..7d9bdd82bc 100644 --- a/crates/holochain/src/fixt.rs +++ b/crates/holochain/src/fixt.rs @@ -11,6 +11,7 @@ use crate::core::ribosome::guest_callback::post_commit::PostCommitHostAccess; use crate::core::ribosome::guest_callback::post_commit::PostCommitInvocation; use crate::core::ribosome::guest_callback::validate::ValidateHostAccess; use crate::core::ribosome::guest_callback::validate::ValidateInvocation; +use crate::core::ribosome::guest_callback::validate_link_add::ValidateLinkAddHostAccess; use crate::core::ribosome::guest_callback::validate_link_add::ValidateLinkAddInvocation; use crate::core::ribosome::guest_callback::validation_package::ValidationPackageHostAccess; use crate::core::ribosome::guest_callback::validation_package::ValidationPackageInvocation; @@ -330,6 +331,11 @@ fixturator!( constructor fn new(ZomeName, LinkAdd, Entry, Entry); ); +fixturator!( + ValidateLinkAddHostAccess; + constructor fn new(); +); + fixturator!( ValidateHostAccess; constructor fn new(); diff --git a/crates/test_utils/wasm/build.rs b/crates/test_utils/wasm/build.rs index 2d839ead28..f5a0c38997 100644 --- a/crates/test_utils/wasm/build.rs +++ b/crates/test_utils/wasm/build.rs @@ -36,6 +36,7 @@ fn main() { "post_commit_fail", "post_commit_success", "validate", + "validate_link", "validate_invalid", "validate_link_add_invalid", "validate_valid", diff --git a/crates/test_utils/wasm/commit_entry/src/lib.rs b/crates/test_utils/wasm/commit_entry/src/lib.rs index 3728ff62ee..2bf2b2dc73 100644 --- a/crates/test_utils/wasm/commit_entry/src/lib.rs +++ b/crates/test_utils/wasm/commit_entry/src/lib.rs @@ -3,7 +3,7 @@ use hdk3::prelude::*; holochain_wasmer_guest::holochain_externs!(); const POST_ID: &str = "post"; -#[derive(Default, SerializedBytes, Serialize, Deserialize)] +#[derive(Default, SerializedBytes, serde::Serialize, serde::Deserialize)] #[repr(transparent)] #[serde(transparent)] struct Post(String); diff --git a/crates/test_utils/wasm/entry_defs/src/lib.rs b/crates/test_utils/wasm/entry_defs/src/lib.rs index 1075e42c32..07e2167434 100644 --- a/crates/test_utils/wasm/entry_defs/src/lib.rs +++ b/crates/test_utils/wasm/entry_defs/src/lib.rs @@ -3,9 +3,11 @@ use hdk3::prelude::*; holochain_wasmer_guest::holochain_externs!(); const POST_ID: &str = "post"; +#[derive(serde::Serialize, serde::Deserialize, SerializedBytes)] struct Post; const COMMENT_ID: &str = "comment"; +#[derive(serde::Serialize, serde::Deserialize, SerializedBytes)] struct Comment; entry_def!(Post EntryDef { diff --git a/crates/test_utils/wasm/src/lib.rs b/crates/test_utils/wasm/src/lib.rs index c7012aa594..874a25af50 100644 --- a/crates/test_utils/wasm/src/lib.rs +++ b/crates/test_utils/wasm/src/lib.rs @@ -23,6 +23,7 @@ pub enum TestWasm { PostCommitFail, PostCommitSuccess, Validate, + ValidateLink, ValidateInvalid, ValidateLinkAddInvalid, ValidateValid, @@ -51,6 +52,7 @@ impl From for ZomeName { TestWasm::PostCommitFail => "post_commit_fail", TestWasm::PostCommitSuccess => "post_commit_success", TestWasm::Validate => "validate", + TestWasm::ValidateLink => "validate_link", TestWasm::ValidateInvalid => "validate_invalid", TestWasm::ValidateLinkAddInvalid => "validate_link_add_invalid", TestWasm::ValidateValid => "validate_valid", @@ -145,6 +147,11 @@ impl From for DnaWasm { "/wasm32-unknown-unknown/release/test_wasm_validate.wasm" )) .to_vec(), + TestWasm::ValidateLink => include_bytes!(concat!( + env!("OUT_DIR"), + "/wasm32-unknown-unknown/release/test_wasm_validate_link.wasm" + )) + .to_vec(), TestWasm::ValidateInvalid => include_bytes!(concat!( env!("OUT_DIR"), "/wasm32-unknown-unknown/release/test_wasm_validate_invalid.wasm" diff --git a/crates/test_utils/wasm/validate_link/Cargo.lock b/crates/test_utils/wasm/validate_link/Cargo.lock index 7fde115d38..dd8255888e 100644 --- a/crates/test_utils/wasm/validate_link/Cargo.lock +++ b/crates/test_utils/wasm/validate_link/Cargo.lock @@ -91,6 +91,17 @@ dependencies = [ "typenum", ] +[[package]] +name = "hdk3" +version = "0.0.1" +dependencies = [ + "holo_hash", + "holochain_wasmer_guest", + "holochain_zome_types", + "serde", + "serde_bytes", +] + [[package]] name = "holo_hash" version = "0.0.1" @@ -556,9 +567,10 @@ dependencies = [ ] [[package]] -name = "test_wasm_validate" +name = "test_wasm_validate_link" version = "0.0.1" dependencies = [ + "hdk3", "holochain_serialized_bytes", "holochain_wasmer_guest", "holochain_zome_types", diff --git a/crates/test_utils/wasm/validate_link/Cargo.toml b/crates/test_utils/wasm/validate_link/Cargo.toml index 07b6f664f6..bd3d53263f 100644 --- a/crates/test_utils/wasm/validate_link/Cargo.toml +++ b/crates/test_utils/wasm/validate_link/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "test_wasm_validate" +name = "test_wasm_validate_link" version = "0.0.1" authors = [ "thedavidmeister", "thedavidmeister@gmail.com" ] edition = "2018" @@ -16,7 +16,7 @@ opt-level = "z" [workspace] [lib] -name = "test_wasm_validate" +name = "test_wasm_validate_link" crate-type = [ "cdylib", "rlib" ] [dependencies] @@ -24,3 +24,4 @@ holochain_serialized_bytes = "=0.0.40" holochain_wasmer_guest = "=0.0.37" holochain_zome_types = { version = "=0.0.1", path = "../../../zome_types" } serde = "=1.0.104" +hdk3 = { path = "../../../hdk" } diff --git a/crates/test_utils/wasm/validate_link/src/lib.rs b/crates/test_utils/wasm/validate_link/src/lib.rs index ca6fc96248..70854332b2 100644 --- a/crates/test_utils/wasm/validate_link/src/lib.rs +++ b/crates/test_utils/wasm/validate_link/src/lib.rs @@ -1,107 +1,51 @@ -use holochain_wasmer_guest::*; -use holochain_zome_types::*; -use holochain_zome_types::validate::ValidateCallbackResult; -use holochain_zome_types::entry_def::EntryDefId; -use holochain_zome_types::entry_def::EntryDefsCallbackResult; -use holochain_zome_types::entry_def::EntryDefs; -use holochain_zome_types::entry_def::EntryDef; -use holochain_zome_types::crdt::CrdtType; -use holochain_zome_types::entry_def::RequiredValidations; -use holochain_zome_types::entry_def::EntryVisibility; +use hdk3::prelude::*; holochain_wasmer_guest::holochain_externs!(); -/// an example inner value that can be serialized into the contents of Entry::App() -#[derive(Deserialize, Serialize, SerializedBytes)] -enum ThisWasmEntry { - AlwaysValidates, - NeverValidates, +const MAYBE_LINKABLE_ID: &str = "maybe_linkable"; +#[derive(serde::Serialize, serde::Deserialize, SerializedBytes, Clone, Copy)] +enum MaybeLinkable { + AlwaysLinkable, + NeverLinkable, } -impl From<&ThisWasmEntry> for EntryDefId { - fn from(entry: &ThisWasmEntry) -> Self { - match entry { - ThisWasmEntry::AlwaysValidates => "always_validates", - ThisWasmEntry::NeverValidates => "never_validates", - }.into() - } -} +entry_def!(MaybeLinkable EntryDef { + id: MAYBE_LINKABLE_ID.into(), + ..Default::default() +}); -impl From<&ThisWasmEntry> for CrdtType { - fn from(_: &ThisWasmEntry) -> Self { - Self - } -} +entry_defs!(vec![MaybeLinkable::entry_def()]); -impl From<&ThisWasmEntry> for RequiredValidations { - fn from(_: &ThisWasmEntry) -> Self { - 5.into() - } -} +map_extern!(validate_link, _validate_link); +map_extern!(add_valid_link, _add_valid_link); +map_extern!(add_invalid_link, _add_invalid_link); -impl From<&ThisWasmEntry> for EntryVisibility { - fn from(_: &ThisWasmEntry) -> Self { - Self::Public - } -} +fn _validate_link(validate_link_add_data: ValidateLinkAddData) -> Result { + let base: MaybeLinkable = validate_link_add_data.base.try_into()?; + let target: MaybeLinkable = validate_link_add_data.target.try_into()?; -impl From<&ThisWasmEntry> for EntryDef { - fn from(entry: &ThisWasmEntry) -> Self { - Self { - id: entry.into(), - crdt_type: entry.into(), - required_validations: entry.into(), - visibility: entry.into(), + Ok(match base { + MaybeLinkable::AlwaysLinkable => match target { + MaybeLinkable::AlwaysLinkable => ValidateLinkAddCallbackResult::Valid, + _ => ValidateLinkAddCallbackResult::Invalid("target never validates".to_string()), } - } + _ => ValidateLinkAddCallbackResult::Invalid("base never validates".to_string()), + }) } -#[no_mangle] -pub extern "C" fn entry_defs(_: GuestPtr) -> GuestPtr { - let defs: EntryDefs = vec![ - (&ThisWasmEntry::AlwaysValidates).into(), - (&ThisWasmEntry::NeverValidates).into(), - ].into(); +fn _add_valid_link(_: ()) -> Result { + let always_linkable_entry_hash = entry_hash!(MaybeLinkable::AlwaysLinkable)?; + commit_entry!(MaybeLinkable::AlwaysLinkable)?; - ret!(GuestOutput::new(try_result!(EntryDefsCallbackResult::Defs( - defs, - ).try_into(), "failed to serialize entry defs return value"))); + Ok(link_entries!(always_linkable_entry_hash.clone(), always_linkable_entry_hash)?) } -#[no_mangle] -pub extern "C" fn validate(host_allocation_ptr: GuestPtr) -> GuestPtr { - // load host args - let input: HostInput = host_args!(host_allocation_ptr); +fn _add_invalid_link(_: ()) -> Result { + let always_linkable_entry_hash = entry_hash!(MaybeLinkable::AlwaysLinkable)?; + let never_linkable_entry_hash = entry_hash!(MaybeLinkable::NeverLinkable)?; - // extract the entry to validate - let result: ValidateCallbackResult = match Entry::try_from(input.into_inner()) { - // we do want to validate our app entries - Ok(Entry::App(serialized_bytes)) => match ThisWasmEntry::try_from(serialized_bytes) { - // the AlwaysValidates variant passes - Ok(ThisWasmEntry::AlwaysValidates) => ValidateCallbackResult::Valid, - // the NeverValidates variants fails - Ok(ThisWasmEntry::NeverValidates) => ValidateCallbackResult::Invalid("NeverValidates never validates".to_string()), - _ => ValidateCallbackResult::Invalid("Couldn't get ThisWasmEntry from the app entry".to_string()), - }, - // other entry types we don't care about - Ok(_) => ValidateCallbackResult::Valid, - _ => ValidateCallbackResult::Invalid("Couldn't get App serialized bytes from host input".to_string()), - }; + commit_entry!(MaybeLinkable::AlwaysLinkable)?; + commit_entry!(MaybeLinkable::NeverLinkable)?; - ret!(GuestOutput::new(try_result!(result.try_into(), "failed to serialize return value".to_string()))); -} - -/// we can write normal rust code with Results outside our externs -fn _commit_validate(to_commit: ThisWasmEntry) -> Result { - let commit_output: CommitEntryOutput = host_call!(__commit_entry, CommitEntryInput::new(((&to_commit).into(), Entry::App(to_commit.try_into()?))))?; - Ok(GuestOutput::new(commit_output.try_into()?)) -} - -#[no_mangle] -pub extern "C" fn always_validates(_: GuestPtr) -> GuestPtr { - ret!(try_result!(_commit_validate(ThisWasmEntry::AlwaysValidates), "error processing commit")) -} -#[no_mangle] -pub extern "C" fn never_validates(_: GuestPtr) -> GuestPtr { - ret!(try_result!(_commit_validate(ThisWasmEntry::NeverValidates), "error processing commit")) + Ok(link_entries!(always_linkable_entry_hash, never_linkable_entry_hash)?) } From 8e9ffa121b4883e49215efe59702ac0aded4797e Mon Sep 17 00:00:00 2001 From: David Meister Date: Thu, 6 Aug 2020 16:56:22 +0400 Subject: [PATCH 6/6] lint --- crates/hdk/src/api.rs | 2 +- .../test_utils/wasm/validate_link/Cargo.lock | 16 ++--- .../test_utils/wasm/validate_link/Cargo.toml | 4 +- .../test_utils/wasm/validate_link/src/lib.rs | 2 +- .../wasm/validate_link_add_invalid/Cargo.lock | 65 ++++++++++++++++--- 5 files changed, 68 insertions(+), 21 deletions(-) diff --git a/crates/hdk/src/api.rs b/crates/hdk/src/api.rs index 3a4579e15b..50793ebfd5 100644 --- a/crates/hdk/src/api.rs +++ b/crates/hdk/src/api.rs @@ -3,7 +3,7 @@ macro_rules! map_extern { ( $name:tt, $f:ident ) => { #[no_mangle] pub extern "C" fn $name(ptr: GuestPtr) -> GuestPtr { - let input: HostInput = host_args!(ptr); + let input: HostInput = crate::host_args!(ptr); let result = $f(try_result!( input.into_inner().try_into(), "failed to deserialize args" diff --git a/crates/test_utils/wasm/validate_link/Cargo.lock b/crates/test_utils/wasm/validate_link/Cargo.lock index dd8255888e..22cc7367fa 100644 --- a/crates/test_utils/wasm/validate_link/Cargo.lock +++ b/crates/test_utils/wasm/validate_link/Cargo.lock @@ -114,9 +114,9 @@ dependencies = [ [[package]] name = "holochain_serialized_bytes" -version = "0.0.40" +version = "0.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03c9314720fa798e94b99ac219fd232c719688971adcf8c368c4e1aa91229183" +checksum = "a2a34e186e9cf3231875a3e2f744a26a7136380b4e12d7acdb9704380e8a0f4f" dependencies = [ "holochain_serialized_bytes_derive", "rmp-serde", @@ -129,9 +129,9 @@ dependencies = [ [[package]] name = "holochain_serialized_bytes_derive" -version = "0.0.40" +version = "0.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90321247a91d3d01cf658465b5933dc40196321017f3c1a278725e004fc879a1" +checksum = "96ab5c62ddc952b5fdec4ac187f366480cef3615ec53637f20c088791fbbcf39" dependencies = [ "quote 0.6.13", "syn 0.15.44", @@ -139,9 +139,9 @@ dependencies = [ [[package]] name = "holochain_wasmer_common" -version = "0.0.37" +version = "0.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "158532e5478884b8030477e6d8378de5f312f3401e8500dd551f8f5f0a819596" +checksum = "36f29c1a0f4acc4a27ba92925464f1a03e322e00eb7c8bb9e372e4325c204349" dependencies = [ "holochain_serialized_bytes", "serde", @@ -150,9 +150,9 @@ dependencies = [ [[package]] name = "holochain_wasmer_guest" -version = "0.0.37" +version = "0.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d38745de8587f886aec602bea3d051d9cbedbdfad467e7cc37c6348cbe8682" +checksum = "6e9e8a55b2a04b79a52b157c5abc78a6f4b858d08e1ecaba22f28e4c67d0050f" dependencies = [ "holochain_serialized_bytes", "holochain_wasmer_common", diff --git a/crates/test_utils/wasm/validate_link/Cargo.toml b/crates/test_utils/wasm/validate_link/Cargo.toml index bd3d53263f..788008a15d 100644 --- a/crates/test_utils/wasm/validate_link/Cargo.toml +++ b/crates/test_utils/wasm/validate_link/Cargo.toml @@ -20,8 +20,8 @@ name = "test_wasm_validate_link" crate-type = [ "cdylib", "rlib" ] [dependencies] -holochain_serialized_bytes = "=0.0.40" -holochain_wasmer_guest = "=0.0.37" +holochain_serialized_bytes = "=0.0.41" +holochain_wasmer_guest = "=0.0.40" holochain_zome_types = { version = "=0.0.1", path = "../../../zome_types" } serde = "=1.0.104" hdk3 = { path = "../../../hdk" } diff --git a/crates/test_utils/wasm/validate_link/src/lib.rs b/crates/test_utils/wasm/validate_link/src/lib.rs index 70854332b2..dc0ccc9c6f 100644 --- a/crates/test_utils/wasm/validate_link/src/lib.rs +++ b/crates/test_utils/wasm/validate_link/src/lib.rs @@ -1,6 +1,6 @@ use hdk3::prelude::*; -holochain_wasmer_guest::holochain_externs!(); +holochain_externs!(); const MAYBE_LINKABLE_ID: &str = "maybe_linkable"; #[derive(serde::Serialize, serde::Deserialize, SerializedBytes, Clone, Copy)] diff --git a/crates/test_utils/wasm/validate_link_add_invalid/Cargo.lock b/crates/test_utils/wasm/validate_link_add_invalid/Cargo.lock index 56da6102e8..0c1c2769cb 100644 --- a/crates/test_utils/wasm/validate_link_add_invalid/Cargo.lock +++ b/crates/test_utils/wasm/validate_link_add_invalid/Cargo.lock @@ -96,7 +96,7 @@ name = "hdk3" version = "0.0.1" dependencies = [ "holo_hash", - "holochain_wasmer_guest", + "holochain_wasmer_guest 0.0.40", "holochain_zome_types", "serde", "serde_bytes", @@ -106,7 +106,7 @@ dependencies = [ name = "holo_hash" version = "0.0.1" dependencies = [ - "holochain_serialized_bytes", + "holochain_serialized_bytes 0.0.41", "rmp-serde", "serde", "serde_bytes", @@ -118,7 +118,22 @@ version = "0.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03c9314720fa798e94b99ac219fd232c719688971adcf8c368c4e1aa91229183" dependencies = [ - "holochain_serialized_bytes_derive", + "holochain_serialized_bytes_derive 0.0.40", + "rmp-serde", + "serde", + "serde-transcode", + "serde_bytes", + "serde_json", + "thiserror", +] + +[[package]] +name = "holochain_serialized_bytes" +version = "0.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2a34e186e9cf3231875a3e2f744a26a7136380b4e12d7acdb9704380e8a0f4f" +dependencies = [ + "holochain_serialized_bytes_derive 0.0.41", "rmp-serde", "serde", "serde-transcode", @@ -137,13 +152,34 @@ dependencies = [ "syn 0.15.44", ] +[[package]] +name = "holochain_serialized_bytes_derive" +version = "0.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96ab5c62ddc952b5fdec4ac187f366480cef3615ec53637f20c088791fbbcf39" +dependencies = [ + "quote 0.6.13", + "syn 0.15.44", +] + [[package]] name = "holochain_wasmer_common" version = "0.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "158532e5478884b8030477e6d8378de5f312f3401e8500dd551f8f5f0a819596" dependencies = [ - "holochain_serialized_bytes", + "holochain_serialized_bytes 0.0.40", + "serde", + "thiserror", +] + +[[package]] +name = "holochain_wasmer_common" +version = "0.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36f29c1a0f4acc4a27ba92925464f1a03e322e00eb7c8bb9e372e4325c204349" +dependencies = [ + "holochain_serialized_bytes 0.0.41", "serde", "thiserror", ] @@ -154,8 +190,19 @@ version = "0.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1d38745de8587f886aec602bea3d051d9cbedbdfad467e7cc37c6348cbe8682" dependencies = [ - "holochain_serialized_bytes", - "holochain_wasmer_common", + "holochain_serialized_bytes 0.0.40", + "holochain_wasmer_common 0.0.37", + "serde", +] + +[[package]] +name = "holochain_wasmer_guest" +version = "0.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e9e8a55b2a04b79a52b157c5abc78a6f4b858d08e1ecaba22f28e4c67d0050f" +dependencies = [ + "holochain_serialized_bytes 0.0.41", + "holochain_wasmer_common 0.0.40", "serde", ] @@ -164,7 +211,7 @@ name = "holochain_zome_types" version = "0.0.1" dependencies = [ "holo_hash", - "holochain_serialized_bytes", + "holochain_serialized_bytes 0.0.41", "multihash", "nanoid", "rust-base58", @@ -571,8 +618,8 @@ name = "test_wasm_validate_link_add_invalid" version = "0.0.1" dependencies = [ "hdk3", - "holochain_serialized_bytes", - "holochain_wasmer_guest", + "holochain_serialized_bytes 0.0.40", + "holochain_wasmer_guest 0.0.37", "holochain_zome_types", "serde", ]