mirror of
https://github.com/kristoferssolo/captra.git
synced 2026-02-25 04:58:15 +00:00
refactor(tests): fix clippy warnings
This commit is contained in:
14
tests/common/host.rs
Normal file
14
tests/common/host.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use crate::common::manifest::load_example_manifest;
|
||||
use captra::HostState;
|
||||
use ed25519_dalek::SigningKey;
|
||||
use rand::rngs::OsRng;
|
||||
|
||||
/// Build a [`HostState`] with a fixed seed and a fresh [`SigningKey`] (`OsRng`).
|
||||
/// # Panics
|
||||
#[must_use]
|
||||
pub fn make_host_with_seed(seed: u64) -> HostState {
|
||||
let manifest = load_example_manifest();
|
||||
let mut csprng = OsRng;
|
||||
let keypair = SigningKey::generate(&mut csprng);
|
||||
HostState::new(manifest, seed, keypair)
|
||||
}
|
||||
9
tests/common/manifest.rs
Normal file
9
tests/common/manifest.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
use captra::{CapabilityManifest, load_manifest};
|
||||
|
||||
/// Load the example manifest bundled with the repo.
|
||||
/// # Panics
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn load_example_manifest() -> CapabilityManifest {
|
||||
load_manifest("examples/manifest.json").expect("examples/manifest.json must exists")
|
||||
}
|
||||
6
tests/common/mod.rs
Normal file
6
tests/common/mod.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
#[allow(dead_code)]
|
||||
pub mod host;
|
||||
#[allow(dead_code)]
|
||||
pub mod manifest;
|
||||
#[allow(dead_code)]
|
||||
pub mod wasm;
|
||||
14
tests/common/wasm.rs
Normal file
14
tests/common/wasm.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use captra::{HostState, add_wasm_linker_funcs};
|
||||
use wasmtime::{Engine, Linker, Store};
|
||||
|
||||
/// Create a wasmtime engine + linker with your host functions registered,
|
||||
/// and a [`Store`] that owns the given [`HostState`].
|
||||
/// # Panics
|
||||
#[must_use]
|
||||
pub fn wasm_store_with_hosts(host: HostState) -> (Engine, Linker<HostState>, Store<HostState>) {
|
||||
let engine = Engine::default();
|
||||
let mut linker = Linker::new(&engine);
|
||||
add_wasm_linker_funcs(&mut linker).expect("linker registration");
|
||||
let store = Store::new(&engine, host);
|
||||
(engine, linker, store)
|
||||
}
|
||||
Reference in New Issue
Block a user