Struct holochain::sweettest::SweetDnaFile
source · pub struct SweetDnaFile(_);
Expand description
Helpful constructors for DnaFiles used in tests
Implementations§
source§impl SweetDnaFile
impl SweetDnaFile
sourcepub async fn from_bundle(path: &Path) -> DnaResult<DnaFile>
pub async fn from_bundle(path: &Path) -> DnaResult<DnaFile>
Create a DnaFile from a path to a *.dna bundle
sourcepub async fn from_bundle_with_overrides<P, E>(
path: &Path,
modifiers: DnaModifiersOpt<P>
) -> DnaResult<DnaFile>where
P: TryInto<SerializedBytes, Error = E>,
SerializedBytesError: From<E>,
pub async fn from_bundle_with_overrides<P, E>(
path: &Path,
modifiers: DnaModifiersOpt<P>
) -> DnaResult<DnaFile>where
P: TryInto<SerializedBytes, Error = E>,
SerializedBytesError: From<E>,
Create a DnaFile from a path to a *.dna bundle, applying the specified modifier overrides
sourcepub async fn from_zomes<I, C, D>(
network_seed: String,
integrity_zomes: Vec<I>,
coordinator_zomes: Vec<C>,
wasms: Vec<D>,
properties: SerializedBytes
) -> (DnaFile, Vec<IntegrityZome>, Vec<CoordinatorZome>)where
I: Into<IntegrityZome>,
C: Into<CoordinatorZome>,
D: Into<DnaWasm>,
pub async fn from_zomes<I, C, D>(
network_seed: String,
integrity_zomes: Vec<I>,
coordinator_zomes: Vec<C>,
wasms: Vec<D>,
properties: SerializedBytes
) -> (DnaFile, Vec<IntegrityZome>, Vec<CoordinatorZome>)where
I: Into<IntegrityZome>,
C: Into<CoordinatorZome>,
D: Into<DnaWasm>,
Create a DnaFile from a collection of Zomes
Examples found in repository?
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
pub async fn unique_from_zomes<I, C, D>(
integrity_zomes: Vec<I>,
coordinator_zomes: Vec<C>,
wasms: Vec<D>,
) -> (DnaFile, Vec<IntegrityZome>, Vec<CoordinatorZome>)
where
I: Into<IntegrityZome>,
C: Into<CoordinatorZome>,
D: Into<wasm::DnaWasm>,
{
Self::from_zomes(
random_network_seed(),
integrity_zomes,
coordinator_zomes,
wasms,
SerializedBytes::default(),
)
.await
}
/// Create a DnaFile from a collection of TestWasm
pub async fn from_test_wasms<W>(
network_seed: String,
wasms: Vec<W>,
properties: SerializedBytes,
) -> (DnaFile, Vec<IntegrityZome>, Vec<CoordinatorZome>)
where
W: Into<TestWasmPair<IntegrityZome, CoordinatorZome>>
+ Into<TestWasmPair<wasm::DnaWasm>>
+ Clone,
{
let (integrity_zomes, coordinator_zomes) = wasms
.clone()
.into_iter()
.map(|w| {
let TestWasmPair::<IntegrityZome, CoordinatorZome> {
integrity,
coordinator,
} = w.into();
(integrity.into_inner(), coordinator.into_inner())
})
.unzip();
let wasms = wasms
.into_iter()
.flat_map(|w| {
let TestWasmPair::<DnaWasm> {
integrity,
coordinator,
} = w.into();
[integrity, coordinator]
})
.collect();
Self::from_zomes(
network_seed,
integrity_zomes,
coordinator_zomes,
wasms,
properties,
)
.await
}
/// Create a DnaFile from a collection of TestWasm
/// with a random network seed
pub async fn unique_from_test_wasms<W>(
test_wasms: Vec<W>,
) -> (DnaFile, Vec<IntegrityZome>, Vec<CoordinatorZome>)
where
W: Into<TestWasmPair<IntegrityZome, CoordinatorZome>>
+ Into<TestWasmPair<wasm::DnaWasm>>
+ Clone,
{
let (dna, integrity_zomes, coordinator_zomes) = Self::from_test_wasms(
random_network_seed(),
test_wasms,
SerializedBytes::default(),
)
.await;
(dna, integrity_zomes, coordinator_zomes)
}
/// Create a DnaFile from a collection of InlineZomes (no Wasm)
pub async fn from_inline_zomes(
network_seed: String,
zomes: impl Into<InlineZomeSet>,
) -> (DnaFile, Vec<IntegrityZome>, Vec<CoordinatorZome>) {
let mut zomes = zomes.into();
let coordinator_zomes: Vec<CoordinatorZome> = zomes
.coordinator_zomes
.into_iter()
.map(|(n, z)| (n.into(), z.into()))
.map(|t| {
let dep = zomes.dependencies.remove(&t.0);
let mut z: CoordinatorZome = t.into();
if let Some(dep) = dep {
z.set_dependency(dep);
}
z
})
.collect();
Self::from_zomes(
network_seed,
zomes
.integrity_order
.into_iter()
.map(|n| zomes.integrity_zomes.remove_entry(n).unwrap())
.map(|(n, z)| (n.into(), z.into()))
.collect(),
coordinator_zomes,
Vec::<wasm::DnaWasm>::with_capacity(0),
SerializedBytes::default(),
)
.await
}
sourcepub async fn unique_from_zomes<I, C, D>(
integrity_zomes: Vec<I>,
coordinator_zomes: Vec<C>,
wasms: Vec<D>
) -> (DnaFile, Vec<IntegrityZome>, Vec<CoordinatorZome>)where
I: Into<IntegrityZome>,
C: Into<CoordinatorZome>,
D: Into<DnaWasm>,
pub async fn unique_from_zomes<I, C, D>(
integrity_zomes: Vec<I>,
coordinator_zomes: Vec<C>,
wasms: Vec<D>
) -> (DnaFile, Vec<IntegrityZome>, Vec<CoordinatorZome>)where
I: Into<IntegrityZome>,
C: Into<CoordinatorZome>,
D: Into<DnaWasm>,
Create a DnaFile from a collection of Zomes, with a random network seed
sourcepub async fn from_test_wasms<W>(
network_seed: String,
wasms: Vec<W>,
properties: SerializedBytes
) -> (DnaFile, Vec<IntegrityZome>, Vec<CoordinatorZome>)where
W: Into<TestWasmPair<IntegrityZome, CoordinatorZome>> + Into<TestWasmPair<DnaWasm>> + Clone,
pub async fn from_test_wasms<W>(
network_seed: String,
wasms: Vec<W>,
properties: SerializedBytes
) -> (DnaFile, Vec<IntegrityZome>, Vec<CoordinatorZome>)where
W: Into<TestWasmPair<IntegrityZome, CoordinatorZome>> + Into<TestWasmPair<DnaWasm>> + Clone,
Create a DnaFile from a collection of TestWasm
Examples found in repository?
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
pub async fn unique_from_test_wasms<W>(
test_wasms: Vec<W>,
) -> (DnaFile, Vec<IntegrityZome>, Vec<CoordinatorZome>)
where
W: Into<TestWasmPair<IntegrityZome, CoordinatorZome>>
+ Into<TestWasmPair<wasm::DnaWasm>>
+ Clone,
{
let (dna, integrity_zomes, coordinator_zomes) = Self::from_test_wasms(
random_network_seed(),
test_wasms,
SerializedBytes::default(),
)
.await;
(dna, integrity_zomes, coordinator_zomes)
}
More examples
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
fn next(&mut self) -> Option<Self::Item> {
let input = self.0.curve.0.clone();
let uuid = StringFixturator::new(Unpredictable).next().unwrap();
let (dna_file, _, _) = tokio_helper::block_forever_on(async move {
SweetDnaFile::from_test_wasms(uuid, input, Default::default()).await
});
let ribosome = RealRibosome::new(dna_file).unwrap();
// warm the module cache for each wasm in the ribosome
for zome in self.0.curve.0.clone() {
let mut call_context = CallContextFixturator::new(Empty).next().unwrap();
call_context.zome = CoordinatorZome::from(zome).erase_type();
ribosome.module(call_context.zome.zome_name()).unwrap();
}
self.0.index += 1;
Some(ribosome)
}
sourcepub async fn unique_from_test_wasms<W>(
test_wasms: Vec<W>
) -> (DnaFile, Vec<IntegrityZome>, Vec<CoordinatorZome>)where
W: Into<TestWasmPair<IntegrityZome, CoordinatorZome>> + Into<TestWasmPair<DnaWasm>> + Clone,
pub async fn unique_from_test_wasms<W>(
test_wasms: Vec<W>
) -> (DnaFile, Vec<IntegrityZome>, Vec<CoordinatorZome>)where
W: Into<TestWasmPair<IntegrityZome, CoordinatorZome>> + Into<TestWasmPair<DnaWasm>> + Clone,
Create a DnaFile from a collection of TestWasm with a random network seed
sourcepub async fn from_inline_zomes(
network_seed: String,
zomes: impl Into<InlineZomeSet>
) -> (DnaFile, Vec<IntegrityZome>, Vec<CoordinatorZome>)
pub async fn from_inline_zomes(
network_seed: String,
zomes: impl Into<InlineZomeSet>
) -> (DnaFile, Vec<IntegrityZome>, Vec<CoordinatorZome>)
Create a DnaFile from a collection of InlineZomes (no Wasm)
Examples found in repository?
More examples
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
pub async fn data_zome(integrity_uuid: String, coordinator_uuid: String) -> DnaFile {
let integrity_zome_name = "integrity_zome1";
let coordinator_zome_name = "zome1";
let zomes = InlineZomeSet::new(
[(
integrity_zome_name,
integrity_uuid.clone(),
InlineEntryTypes::entry_defs(),
0,
)],
[(coordinator_zome_name, coordinator_uuid)],
)
.function(
coordinator_zome_name,
"create_many",
move |api, entries: Vec<Entry>| {
for entry in entries {
api.create(CreateInput::new(
InlineZomeSet::get_entry_location(&api, InlineEntryTypes::A),
EntryVisibility::Public,
entry,
ChainTopOrdering::default(),
))?;
}
Ok(())
},
)
.function(coordinator_zome_name, "read", |api, hash: ActionHash| {
api.get(vec![GetInput::new(hash.into(), GetOptions::default())])
.map(|e| e.into_iter().next().unwrap())
.map_err(Into::into)
});
let (dna_file, _, _) = SweetDnaFile::from_inline_zomes(integrity_uuid, zomes).await;
dna_file
}
sourcepub async fn unique_from_inline_zomes(
zomes: impl Into<InlineZomeSet>
) -> (DnaFile, Vec<IntegrityZome>, Vec<CoordinatorZome>)
pub async fn unique_from_inline_zomes(
zomes: impl Into<InlineZomeSet>
) -> (DnaFile, Vec<IntegrityZome>, Vec<CoordinatorZome>)
Create a DnaFile from a collection of InlineZomes (no Wasm), with a random network seed
Methods from Deref<Target = DnaFile>§
sourcepub fn dna(&self) -> &HoloHashed<DnaDef>
pub fn dna(&self) -> &HoloHashed<DnaDef>
The DnaDef along with its hash
sourcepub fn verify_hash(&self) -> Result<(), DnaError>
pub fn verify_hash(&self) -> Result<(), DnaError>
Verify that the DNA hash in the file matches the DnaDef
sourcepub fn code(&self) -> &BTreeMap<HoloHash<Wasm>, DnaWasm, Global>
pub fn code(&self) -> &BTreeMap<HoloHash<Wasm>, DnaWasm, Global>
The bytes of the WASM zomes referenced in the Dna portion.
sourcepub fn get_wasm_for_zome(
&self,
zome_name: &ZomeName
) -> Result<&DnaWasm, DnaError>
pub fn get_wasm_for_zome(
&self,
zome_name: &ZomeName
) -> Result<&DnaWasm, DnaError>
Fetch the Webassembly byte code for a zome.
sourcepub async fn to_file_content(
&self
) -> impl Future<Output = Result<Vec<u8, Global>, DnaError>>
👎Deprecated: remove after app bundles become standard; use DnaBundle instead
pub async fn to_file_content(
&self
) -> impl Future<Output = Result<Vec<u8, Global>, DnaError>>
Render this dna_file as bytecode to send over the wire, or store in a file.
sourcepub fn update_modifiers(
&self,
dna_modifiers: DnaModifiersOpt<SerializedBytes>
) -> DnaFile
pub fn update_modifiers(
&self,
dna_modifiers: DnaModifiersOpt<SerializedBytes>
) -> DnaFile
Change the DNA modifiers – the network seed, origin time and properties – while leaving the actual DNA code intact.
Trait Implementations§
source§impl AsRef<DnaFile> for SweetDnaFile
impl AsRef<DnaFile> for SweetDnaFile
source§impl Borrow<DnaFile> for SweetDnaFile
impl Borrow<DnaFile> for SweetDnaFile
source§impl Clone for SweetDnaFile
impl Clone for SweetDnaFile
source§fn clone(&self) -> SweetDnaFile
fn clone(&self) -> SweetDnaFile
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for SweetDnaFile
impl Debug for SweetDnaFile
source§impl Deref for SweetDnaFile
impl Deref for SweetDnaFile
source§impl From<DnaFile> for SweetDnaFile
impl From<DnaFile> for SweetDnaFile
source§fn from(original: DnaFile) -> SweetDnaFile
fn from(original: DnaFile) -> SweetDnaFile
source§impl From<SweetDnaFile> for DnaFile
impl From<SweetDnaFile> for DnaFile
source§fn from(original: SweetDnaFile) -> Self
fn from(original: SweetDnaFile) -> Self
Auto Trait Implementations§
impl !RefUnwindSafe for SweetDnaFile
impl Send for SweetDnaFile
impl Sync for SweetDnaFile
impl Unpin for SweetDnaFile
impl !UnwindSafe for SweetDnaFile
Blanket Implementations§
§impl<T> Any for Twhere
T: Any + ?Sized,
impl<T> Any for Twhere
T: Any + ?Sized,
§fn type_id_compat(&self) -> TypeId
fn type_id_compat(&self) -> TypeId
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
§impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
§fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.