From 7f662ddcf193392cfc8ded6de60d30e9490084b0 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Mon, 8 Apr 2024 21:55:04 -0600 Subject: [PATCH] feat(wasm): Wasm Integration Tests working in CI (#197) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(wasm): Fix running wasm integration tests * fix(wasm): Make logging work inside the wasm integration tests * feat(wasm): working hashing integration test * ci(wasm): align rust builds with cat-ci latest version * feat(wasm): Add crypto wasm integration tests * fix(hermes): Re-enable hermes full build after getting wasm integration tests working * fix(wasm): silence the initial print inside wasm integration tests to prevent issues when running * fix(wasm): remove unused import after silencing the wasm integration tester * style(hermes): Fix code format * fix(spelling): spelling issue * fix(cbork): Align deny,toml with CI * fix(wasm): Align deny.toml with CI * Update hermes/bin/src/runtime_extensions/hermes/crypto/host.rs Co-authored-by: bkioshn <35752733+bkioshn@users.noreply.github.com> * Update hermes/bin/src/runtime_extensions/hermes/crypto/host.rs Co-authored-by: bkioshn <35752733+bkioshn@users.noreply.github.com> * feat: hermes-cron integration test cases (#199) * feat(wip): stub hermes-cron integration test cases * feat: add tests for cron api functions * fix: compare returned string with expected * feat(warm): Add Cardano Runtime Extension integration test skeleton (#198) * feat(wasm): Add Cardano Runtime Extension integration tests skeleton * feat(wasm): Use pallas to parse blocks in Cardano RTE integration test component --------- Co-authored-by: Steven Johnson * fix(wasm): remove commented obsolete code * Update wasm/integration-test/crypto/crypto.c Co-authored-by: bkioshn <35752733+bkioshn@users.noreply.github.com> * test: time module (#200) * feat: initial commit * feat: simple function * ci: add test * test: restructure and add test to localtime * fix: minor format * refactor: remove localtime name * fix: localtime issue * feat: clocks test * fix: test warms * fix: use existing tests * chore: earthfile tmp * fix: builder * fix: remove wall test * chore: fmtfix * fix(spelling): add to project words * fix(wasm): remove generated bindings, try and use autogenerated ones * chore(wasm): Fix Cardano RTE wasm integration test module (#204) * fix(hermes): Update rust builders to the latest --------- Co-authored-by: bkioshn <35752733+bkioshn@users.noreply.github.com> Co-authored-by: JoaquĆ­n Rosales Co-authored-by: Felipe Rosa Co-authored-by: Apisit Ritreungroj <38898766+apskhem@users.noreply.github.com> --- .config/dictionaries/project.dic | 1 + hermes/Earthfile | 33 +- .../hermes/crypto/bip32_ed25519.rs | 1 + .../runtime_extensions/hermes/crypto/host.rs | 11 +- .../runtime_extensions/hermes/crypto/mod.rs | 2 +- .../hermes/localtime/host.rs | 39 +- .../hermes/localtime/mod.rs | 1 + .../hermes/localtime/time.rs | 60 ++ hermes/bin/src/wasm/module.rs | 3 +- hermes/bin/tests/wasm-integration/main.rs | 197 +++--- hermes/crates/cbork/Earthfile | 2 +- hermes/crates/cbork/deny.toml | 7 +- wasm/c/integration-test.c | 123 ---- wasm/integration-test/cardano/.gitignore | 3 + wasm/integration-test/cardano/Cargo.lock | 583 ++++++++++++++++++ wasm/integration-test/cardano/Cargo.toml | 12 + wasm/integration-test/cardano/Earthfile | 23 + .../cardano/rust-toolchain.toml | 3 + wasm/integration-test/cardano/src/lib.rs | 100 +++ wasm/integration-test/clocks/Earthfile | 14 + wasm/integration-test/clocks/clocks.c | 78 +++ wasm/integration-test/cron/Earthfile | 14 + wasm/integration-test/cron/cron.c | 133 ++++ wasm/integration-test/crypto/Earthfile | 14 + wasm/integration-test/crypto/crypto.c | 114 ++++ wasm/integration-test/hashing/Earthfile | 14 + wasm/integration-test/hashing/hashing.c | 102 +++ wasm/integration-test/localtime/Earthfile | 14 + wasm/integration-test/localtime/localtime.c | 81 +++ wasm/integration-test/logger/Earthfile | 14 + wasm/integration-test/logger/logger.c | 92 +++ wasm/integration-test/smoke-test/Earthfile | 14 + wasm/integration-test/smoke-test/smoke-test.c | 89 +++ wasm/{c => stub-module}/Earthfile | 12 +- .../stub-module.c} | 0 wasm/wasi-hermes-component-adapter/Earthfile | 2 +- wasm/wasi-hermes-component-adapter/deny.toml | 3 +- wasm/wasi/.gitignore | 2 + wasm/wasi/Earthfile | 19 +- 39 files changed, 1758 insertions(+), 271 deletions(-) create mode 100644 hermes/bin/src/runtime_extensions/hermes/localtime/time.rs delete mode 100644 wasm/c/integration-test.c create mode 100644 wasm/integration-test/cardano/.gitignore create mode 100644 wasm/integration-test/cardano/Cargo.lock create mode 100644 wasm/integration-test/cardano/Cargo.toml create mode 100644 wasm/integration-test/cardano/Earthfile create mode 100644 wasm/integration-test/cardano/rust-toolchain.toml create mode 100644 wasm/integration-test/cardano/src/lib.rs create mode 100644 wasm/integration-test/clocks/Earthfile create mode 100644 wasm/integration-test/clocks/clocks.c create mode 100644 wasm/integration-test/cron/Earthfile create mode 100644 wasm/integration-test/cron/cron.c create mode 100644 wasm/integration-test/crypto/Earthfile create mode 100644 wasm/integration-test/crypto/crypto.c create mode 100644 wasm/integration-test/hashing/Earthfile create mode 100644 wasm/integration-test/hashing/hashing.c create mode 100644 wasm/integration-test/localtime/Earthfile create mode 100644 wasm/integration-test/localtime/localtime.c create mode 100644 wasm/integration-test/logger/Earthfile create mode 100644 wasm/integration-test/logger/logger.c create mode 100644 wasm/integration-test/smoke-test/Earthfile create mode 100644 wasm/integration-test/smoke-test/smoke-test.c rename wasm/{c => stub-module}/Earthfile (61%) rename wasm/{c/my-component.c => stub-module/stub-module.c} (100%) create mode 100644 wasm/wasi/.gitignore diff --git a/.config/dictionaries/project.dic b/.config/dictionaries/project.dic index 2439d67a4..24d571265 100644 --- a/.config/dictionaries/project.dic +++ b/.config/dictionaries/project.dic @@ -15,6 +15,7 @@ bmac BROTLI CHAINCODE cardano +cdylib chaincode cbor CBOR diff --git a/hermes/Earthfile b/hermes/Earthfile index ad7eb9395..e1c0bcc43 100644 --- a/hermes/Earthfile +++ b/hermes/Earthfile @@ -4,7 +4,7 @@ VERSION 0.7 # Set up our target toolchains, and copy our files. builder: - DO github.com/input-output-hk/catalyst-ci/earthly/rust:v2.10.3+SETUP + DO github.com/input-output-hk/catalyst-ci/earthly/rust:v2.11.2+SETUP COPY --dir .cargo .config crates bin . COPY Cargo.toml . COPY clippy.toml deny.toml rustfmt.toml . @@ -12,7 +12,7 @@ builder: RUN mkdir /wasm COPY --dir ../wasm+wasi-src/wasi /wasm/wasi # Compiled WASM component for benchmarks - COPY ../wasm/c+build/component.wasm /wasm/c/bench_component.wasm + COPY ../wasm/stub-module+build/stub.wasm /wasm/stub-module/stub.wasm # Expands `wasmtime::bindgen!` macro into the `bindings.rs` file bindings-expand: @@ -44,16 +44,37 @@ all-hosts-check: build: FROM +builder - # build wasm artifacts for testing - COPY (../wasm/c+build/component.wasm --c_files="integration-test.c") ../wasm/test-components/ + # Directory where WASM test components go when we run wasm module integration tests. + RUN mkdir ../wasm/test-components RUN /scripts/std_build.py --bench_flags="--features bench" \ --libs="cardano-chain-follower" \ - --bins="hermes/hermes" + --bins="hermes/hermes" \ + --verbose SAVE ARTIFACT target/$TARGETARCH/doc doc SAVE ARTIFACT target/$TARGETARCH/release/hermes hermes - SAVE ARTIFACT target/criterion + SAVE ARTIFACT target/criterion + +test-wasm-integration: + FROM +build + + # Copy all wasm module artifacts for testing + COPY ../wasm/integration-test/cron+build/cron.wasm ../wasm/test-components/ + COPY ../wasm/integration-test/clocks+build/clocks.wasm ../wasm/test-components/ + COPY ../wasm/integration-test/crypto+build/crypto.wasm ../wasm/test-components/ + COPY ../wasm/integration-test/cardano+build/cardano.wasm ../wasm/test-components/ + COPY ../wasm/integration-test/hashing+build/hashing.wasm ../wasm/test-components/ + COPY ../wasm/integration-test/localtime+build/localtime.wasm ../wasm/test-components/ + COPY ../wasm/integration-test/logger+build/logger.wasm ../wasm/test-components/ + COPY ../wasm/integration-test/smoke-test+build/smoke-test.wasm ../wasm/test-components/ + + # List all WASM integration tests/benches and also run them. + #RUN cargo test --release --test wasm-component-integration-tests -- --help + RUN cargo test --release --test wasm-component-integration-tests -- --list + RUN cargo test --release --test wasm-component-integration-tests -- --test + RUN cargo test --release --test wasm-component-integration-tests -- --bench + # Test which runs check with all supported host tooling. Needs qemu or rosetta to run. # Only used to validate tooling is working across host toolsets. diff --git a/hermes/bin/src/runtime_extensions/hermes/crypto/bip32_ed25519.rs b/hermes/bin/src/runtime_extensions/hermes/crypto/bip32_ed25519.rs index e679c33cc..4a9505087 100644 --- a/hermes/bin/src/runtime_extensions/hermes/crypto/bip32_ed25519.rs +++ b/hermes/bin/src/runtime_extensions/hermes/crypto/bip32_ed25519.rs @@ -198,6 +198,7 @@ mod tests_bip32_ed25519 { #[test] fn test_get_public_key() { let xprv = XPrv::from_extended_and_chaincode(&XPRV1, &CHAINCODE1); + // 3986768884739312704, 9782938079688165927, 7977656244723921923, 12587033252467133758 let pubk_tuple = get_public_key(&xprv); let pubk_hex = format!( "{:x}{:x}{:x}{:x}", diff --git a/hermes/bin/src/runtime_extensions/hermes/crypto/host.rs b/hermes/bin/src/runtime_extensions/hermes/crypto/host.rs index 43a181c10..ce7602746 100644 --- a/hermes/bin/src/runtime_extensions/hermes/crypto/host.rs +++ b/hermes/bin/src/runtime_extensions/hermes/crypto/host.rs @@ -36,13 +36,14 @@ impl HostBip32Ed25519 for HermesRuntimeContext { match xprv { Ok(xprv) => { if let Some(id) = add_resource(self.app_name(), xprv) { - return Ok(Resource::new_own(id)); + Ok(Resource::new_own(id)) + } else { + // TODO(bkioshn): https://github.com/input-output-hk/hermes/issues/183 + Err(wasmtime::Error::msg("Error creating new resource")) } }, - Err(e) => return Err(wasmtime::Error::msg(e.to_string())), - }; - // TODO(bkioshn): https://github.com/input-output-hk/hermes/issues/183 - Err(wasmtime::Error::msg("Error creating new resource")) + Err(e) => Err(wasmtime::Error::msg(e.to_string())), + } } /// Get the public key for this private key. diff --git a/hermes/bin/src/runtime_extensions/hermes/crypto/mod.rs b/hermes/bin/src/runtime_extensions/hermes/crypto/mod.rs index 6e31eb40a..904ccc3c5 100644 --- a/hermes/bin/src/runtime_extensions/hermes/crypto/mod.rs +++ b/hermes/bin/src/runtime_extensions/hermes/crypto/mod.rs @@ -11,7 +11,7 @@ mod state; pub(crate) fn new_context(ctx: &crate::runtime_context::HermesRuntimeContext) { // check whether it exist let state = get_state(); - if state.contains_key(ctx.app_name()) { + if !state.contains_key(ctx.app_name()) { set_state(ctx.app_name().clone()); } } diff --git a/hermes/bin/src/runtime_extensions/hermes/localtime/host.rs b/hermes/bin/src/runtime_extensions/hermes/localtime/host.rs index a7e1d1bc2..e04949941 100644 --- a/hermes/bin/src/runtime_extensions/hermes/localtime/host.rs +++ b/hermes/bin/src/runtime_extensions/hermes/localtime/host.rs @@ -1,16 +1,11 @@ //! Localtime host implementation for WASM runtime. -use chrono::{Local, TimeZone}; -use chrono_tz::Tz; - +use super::time::{alt_localtime, get_localtime}; use crate::{ runtime_context::HermesRuntimeContext, - runtime_extensions::{ - bindings::{ - hermes::localtime::api::{Errno, Host, Localtime, Timezone}, - wasi::clocks::wall_clock::Datetime, - }, - hermes::localtime::get_tz, + runtime_extensions::bindings::{ + hermes::localtime::api::{Errno, Host, Localtime, Timezone}, + wasi::clocks::wall_clock::Datetime, }, }; @@ -31,21 +26,7 @@ impl Host for HermesRuntimeContext { fn get_localtime( &mut self, when: Option, tz: Option, ) -> wasmtime::Result> { - let timezone = get_tz(tz)?; - let local_naive = match when { - Some(Datetime { - seconds, - nanoseconds, - }) => { - let seconds = seconds.try_into().map_err(|_| Errno::InvalidLocaltime)?; - let utc_dt = chrono::DateTime::from_timestamp(seconds, nanoseconds) - .ok_or(Errno::InvalidLocaltime)?; - utc_dt.naive_utc() - }, - None => Local::now().naive_utc(), - }; - let local_date_time = timezone.from_utc_datetime(&local_naive); - Ok(local_date_time.try_into()) + Ok(get_localtime(when, tz)) } /// Get a new localtime from a localtime, by recalculating time for a new timezone. @@ -63,15 +44,7 @@ impl Host for HermesRuntimeContext { fn alt_localtime( &mut self, time: Localtime, tz: Option, ) -> wasmtime::Result> { - let local_date_time: chrono::DateTime = time.try_into()?; - let alt_local_date_time = match tz { - Some(alt_tz) => { - let tz = get_tz(Some(alt_tz))?; - tz.from_utc_datetime(&local_date_time.naive_utc()) - }, - None => local_date_time, - }; - Ok(alt_local_date_time.try_into()) + Ok(alt_localtime(time, tz)) } /// Get a datetime from a localtime. diff --git a/hermes/bin/src/runtime_extensions/hermes/localtime/mod.rs b/hermes/bin/src/runtime_extensions/hermes/localtime/mod.rs index 145380bde..30d7aa915 100644 --- a/hermes/bin/src/runtime_extensions/hermes/localtime/mod.rs +++ b/hermes/bin/src/runtime_extensions/hermes/localtime/mod.rs @@ -9,6 +9,7 @@ use crate::runtime_extensions::bindings::{ }; mod host; +mod time; /// Advise Runtime Extensions of a new context pub(crate) fn new_context(_ctx: &crate::runtime_context::HermesRuntimeContext) {} diff --git a/hermes/bin/src/runtime_extensions/hermes/localtime/time.rs b/hermes/bin/src/runtime_extensions/hermes/localtime/time.rs new file mode 100644 index 000000000..d29a701ad --- /dev/null +++ b/hermes/bin/src/runtime_extensions/hermes/localtime/time.rs @@ -0,0 +1,60 @@ +//! Localtime host implementation for WASM runtime. + +use chrono::{Local, TimeZone}; +use chrono_tz::Tz; + +use crate::runtime_extensions::{ + bindings::{ + hermes::localtime::api::{Errno, Localtime, Timezone}, + wasi::clocks::wall_clock::Datetime, + }, + hermes::localtime::get_tz, +}; + +/// (Implementation) Get localtime from a datetime or now. +pub(super) fn get_localtime( + when: Option, tz: Option, +) -> Result { + let timezone = get_tz(tz)?; + let local_naive = match when { + Some(Datetime { + seconds, + nanoseconds, + }) => { + let seconds = seconds.try_into().map_err(|_| Errno::InvalidLocaltime)?; + let utc_dt = chrono::DateTime::from_timestamp(seconds, nanoseconds) + .ok_or(Errno::InvalidLocaltime)?; + utc_dt.naive_utc() + }, + None => Local::now().naive_utc(), + }; + let local_date_time = timezone.from_utc_datetime(&local_naive); + + local_date_time.try_into() +} + +/// (Implementation) Get a new localtime from a localtime, by recalculating time for a new +/// timezone. +pub(super) fn alt_localtime(time: Localtime, tz: Option) -> Result { + let local_date_time: chrono::DateTime = time.try_into()?; + let alt_local_date_time = match tz { + Some(alt_tz) => { + let tz = get_tz(Some(alt_tz))?; + tz.from_utc_datetime(&local_date_time.naive_utc()) + }, + None => local_date_time, + }; + + alt_local_date_time.try_into() +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_get_localtime_with_utc_offset() { + let result = get_localtime(None, Some(String::from("Europe/London"))); + assert!(result.is_ok()); // Check if the function call was successful + } +} diff --git a/hermes/bin/src/wasm/module.rs b/hermes/bin/src/wasm/module.rs index 4fca509a3..07a83bf75 100644 --- a/hermes/bin/src/wasm/module.rs +++ b/hermes/bin/src/wasm/module.rs @@ -162,8 +162,7 @@ pub mod bench { } } - let module = - Module::new(include_bytes!("../../../../wasm/c/bench_component.wasm")).unwrap(); + let module = Module::new(include_bytes!("../../../../wasm/stub-module/stub.wasm")).unwrap(); b.iter(|| { module diff --git a/hermes/bin/tests/wasm-integration/main.rs b/hermes/bin/tests/wasm-integration/main.rs index 5bd3e9c4c..dceb6cb54 100644 --- a/hermes/bin/tests/wasm-integration/main.rs +++ b/hermes/bin/tests/wasm-integration/main.rs @@ -23,101 +23,131 @@ use hermes::{ wasm::module::Module, }; use libtest_mimic::{Arguments, Failed, Measurement, Trial}; +use tracing::{level_filters::LevelFilter, subscriber::SetGlobalDefaultError}; +use tracing_subscriber::{fmt::time, FmtSubscriber}; + +/// Init the logger +fn init_logger() -> Result<(), SetGlobalDefaultError> { + let subscriber = FmtSubscriber::builder() + .json() + .with_level(true) + .with_thread_names(true) + .with_thread_ids(true) + .with_file(true) + .with_line_number(true) + .with_timer(time::UtcTime::rfc_3339()) + .with_max_level(LevelFilter::INFO) + .finish(); + + tracing::subscriber::set_global_default(subscriber) +} fn main() -> Result<(), Box> { + // This is necessary otherwise the logging functions inside hermes are silent during the + // test run. + init_logger()?; + // This causes issues with normal test runs, so comment out for now. + // info!("Starting Hermes WASM integration tests"); + let args = Arguments::from_args(); let tests = collect_tests()?; libtest_mimic::run(&args, tests).exit(); } -/// Creates as many tests as required for each `.wasm` file in the current directory or -/// sub-directories of the current directory. -fn collect_tests() -> Result, Box> { - #[allow(clippy::missing_docs_in_private_items)] - fn visit_dir(path: &Path, tests: &mut Vec) -> Result<(), Box> { - let args = Arguments::from_args(); - - let n_test: u32 = env::var(ENV_N_TEST) - .unwrap_or_else(|_| DEFAULT_ENV_N_TEST.to_owned()) - .parse()?; - let n_bench: u32 = env::var(ENV_N_BENCH) - .unwrap_or_else(|_| DEFAULT_ENV_N_BENCH.to_owned()) - .parse()?; - - let entries: Vec<_> = fs::read_dir(path)? - .collect::, _>>()? - .into_iter() - .map(|entry| entry.file_type().map(|file_type| (file_type, entry.path()))) - .collect::>()?; - let wasm_file_paths: Vec<_> = entries - .iter() - .filter_map(|(file_type, path)| { - (file_type.is_file() && path.extension() == Some(OsStr::new("wasm"))) - .then_some(path) - }) - .collect(); - let dir_paths: Vec<_> = entries - .iter() - .filter_map(|(file_type, path)| file_type.is_dir().then_some(path)) - .collect(); - - // process `.wasm` files - for file_path in wasm_file_paths { - let name = file_path.strip_prefix(path)?.display().to_string(); - - // Execute the wasm tests to get their name - // Load WASM module in the executor. - let wasm_buf = fs::read(file_path)?; - let mut module = Module::new(&wasm_buf)?; - - let mut collect = |event_type: EventType, n: u32| -> Result<(), Box> { - // Collect the cases in a loop until no more cases. - for i in 0..n { - match execute_event(&mut module, i, false, event_type)? { - Some(result) => { - let path_string = file_path.to_string_lossy().to_string(); - - let test = match event_type { - EventType::Test => { - Trial::test(result.name, move || { - execute_test(i, path_string, event_type) - }) - }, - EventType::Bench => { - Trial::bench(result.name, move |test_mode| { - execute_bench(test_mode, i, path_string, event_type) - }) - }, - } - .with_kind(name.clone()); - - tests.push(test); - }, - _ => { - break; - }, - } +/// Collect all the tests to run from a specified directory +fn visit_dir(path: &Path, tests: &mut Vec) -> Result<(), Box> { + let args = Arguments::from_args(); + + let n_test: u32 = env::var(ENV_N_TEST) + .unwrap_or_else(|_| DEFAULT_ENV_N_TEST.to_owned()) + .parse()?; + let n_bench: u32 = env::var(ENV_N_BENCH) + .unwrap_or_else(|_| DEFAULT_ENV_N_BENCH.to_owned()) + .parse()?; + + let raw_entries = match fs::read_dir(path) { + Ok(entries) => entries, + Err(_e) => return Ok(()), // If the directory of modules can not be found, just skip it. + }; + + let entries: Vec<_> = raw_entries + .collect::, _>>()? + .into_iter() + .map(|entry| entry.file_type().map(|file_type| (file_type, entry.path()))) + .collect::>()?; + + let wasm_file_paths: Vec<_> = entries + .iter() + .filter_map(|(file_type, path)| { + (file_type.is_file() && path.extension() == Some(OsStr::new("wasm"))).then_some(path) + }) + .collect(); + + let dir_paths: Vec<_> = entries + .iter() + .filter_map(|(file_type, path)| file_type.is_dir().then_some(path)) + .collect(); + + // process `.wasm` files + for file_path in wasm_file_paths { + let name = file_path.strip_prefix(path)?.display().to_string(); + + // Execute the wasm tests to get their name + // Load WASM module in the executor. + let wasm_buf = fs::read(file_path)?; + let mut module = Module::new(&wasm_buf)?; + + let mut collect = |event_type: EventType, n: u32| -> Result<(), Box> { + // Collect the cases in a loop until no more cases. + for i in 0..n { + match execute_event(&mut module, i, false, event_type)? { + Some(result) => { + let path_string = file_path.to_string_lossy().to_string(); + + let test = match event_type { + EventType::Test => { + Trial::test(result.name, move || { + execute_test(i, path_string, event_type) + }) + }, + EventType::Bench => { + Trial::bench(result.name, move |test_mode| { + execute_bench(test_mode, i, path_string, event_type) + }) + }, + } + .with_kind(name.clone()); + + tests.push(test); + }, + _ => { + break; + }, } + } - Ok(()) - }; + Ok(()) + }; - if args.bench { - collect(EventType::Bench, n_bench)?; - } - if args.test { - collect(EventType::Test, n_test)?; - } + if args.test || args.list { + collect(EventType::Test, n_test)?; } - - // process items inside directories - for path in dir_paths { - visit_dir(path, tests)?; + if args.bench || args.list { + collect(EventType::Bench, n_bench)?; } + } - Ok(()) + // process items inside directories + for path in dir_paths { + visit_dir(path, tests)?; } + Ok(()) +} + +/// Creates as many tests as required for each `.wasm` file in the current directory or +/// sub-directories of the current directory. +fn collect_tests() -> Result, Box> { // Read wasm components to be test in a directory. let mut tests = Vec::new(); let test_module_dir = @@ -137,8 +167,11 @@ fn execute(test_case: u32, path: String, event_type: EventType) -> Result<(), Fa match execute_event(&mut module, test_case, true, event_type)? { Some(result) => { - assert!(result.status); - Ok(()) + if result.status { + Ok(()) + } else { + Err(Failed::from("Failed")) + } }, _ => Err(Failed::from("result unexpected")), } diff --git a/hermes/crates/cbork/Earthfile b/hermes/crates/cbork/Earthfile index e8d3c070a..731cf181f 100644 --- a/hermes/crates/cbork/Earthfile +++ b/hermes/crates/cbork/Earthfile @@ -2,7 +2,7 @@ VERSION 0.7 # Set up our target toolchains, and copy our files. builder: - DO github.com/input-output-hk/catalyst-ci/earthly/rust:v2.10.0+SETUP + DO github.com/input-output-hk/catalyst-ci/earthly/rust:v2.11.2+SETUP COPY --dir .cargo .config cddl-parser abnf-parser . COPY Cargo.toml clippy.toml deny.toml rustfmt.toml . diff --git a/hermes/crates/cbork/deny.toml b/hermes/crates/cbork/deny.toml index 7fdf50db7..608eb845c 100644 --- a/hermes/crates/cbork/deny.toml +++ b/hermes/crates/cbork/deny.toml @@ -270,9 +270,8 @@ unknown-git = "deny" allow-registry = ["https://github.com/rust-lang/crates.io-index"] # List of URLs for allowed Git repositories allow-git = [ - # Remove this once upstream changes are merged. - # issue: https://github.com/input-output-hk/hermes/issues/63 - "https://github.com/input-output-hk/hermes.git" + "https://github.com/input-output-hk/hermes.git", + "https://github.com/input-output-hk/catalyst-pallas.git" ] [sources.allow-org] @@ -281,4 +280,4 @@ allow-git = [ # 1 or more gitlab.com organizations to allow git sources for #gitlab = [""] # 1 or more bitbucket.org organizations to allow git sources for -#bitbucket = [""] \ No newline at end of file +#bitbucket = [""] diff --git a/wasm/c/integration-test.c b/wasm/c/integration-test.c deleted file mode 100644 index 5ffdc1165..000000000 --- a/wasm/c/integration-test.c +++ /dev/null @@ -1,123 +0,0 @@ -#include "bindings_src/hermes.h" - -const uint32_t N_TEST = 5; -const exports_hermes_integration_test_event_test_result_t TESTS[N_TEST] = { - { - .name = { - .ptr = (uint8_t *)"Test Case 1", - .len = strlen("Test Case 1") - }, - .status = true - }, - { - .name = { - .ptr = (uint8_t *)"Test Case 2", - .len = strlen("Test Case 2") - }, - .status = true - }, - { - .name = { - .ptr = (uint8_t *)"Test Case 3", - .len = strlen("Test Case 3") - }, - .status = true - }, - { - .name = { - .ptr = (uint8_t *)"Test Case 4", - .len = strlen("Test Case 4") - }, - .status = true - }, - { - .name = { - .ptr = (uint8_t *)"Test Case 5", - .len = strlen("Test Case 5") - }, - .status = true - } -}; - -const uint32_t N_BENCH = 3; -const exports_hermes_integration_test_event_test_result_t BENCHES[N_BENCH] = { - { - .name = { - .ptr = (uint8_t *)"Bench 1", - .len = strlen("Bench 1") - }, - .status = true - }, - { - .name = { - .ptr = (uint8_t *)"Bench 2", - .len = strlen("Bench 2") - }, - .status = true - }, - { - .name = { - .ptr = (uint8_t *)"Bench 3", - .len = strlen("Bench 3") - }, - .status = true - } -}; - -// Exported Functions from `wasi:http/incoming-handler@0.2.0` -void exports_wasi_http_incoming_handler_handle(exports_wasi_http_incoming_handler_own_incoming_request_t request, exports_wasi_http_incoming_handler_own_response_outparam_t response_out) { - -} - -// Exported Functions from `hermes:cardano/event-on-block` -void exports_hermes_cardano_event_on_block_on_cardano_block(exports_hermes_cardano_event_on_block_cardano_blockchain_id_t blockchain, exports_hermes_cardano_event_on_block_cardano_block_t *block, exports_hermes_cardano_event_on_block_block_src_t source) { - -} - -// Exported Functions from `hermes:cardano/event-on-txn` -void exports_hermes_cardano_event_on_txn_on_cardano_txn(exports_hermes_cardano_event_on_txn_cardano_blockchain_id_t blockchain, uint64_t slot, uint32_t txn_index, exports_hermes_cardano_event_on_txn_cardano_txn_t *txn) { - -} - -// Exported Functions from `hermes:cardano/event-on-rollback` -void exports_hermes_cardano_event_on_rollback_on_cardano_rollback(exports_hermes_cardano_event_on_rollback_cardano_blockchain_id_t blockchain, uint64_t slot) { - -} - -// Exported Functions from `hermes:cron/event` -bool exports_hermes_cron_event_on_cron(exports_hermes_cron_event_cron_tagged_t *event, bool last) { - return false; -} - -// Exported Functions from `hermes:init/event` -bool exports_hermes_init_event_init(void) { - return false; -} - -// Exported Functions from `hermes:kv-store/event` -void exports_hermes_kv_store_event_kv_update(hermes_string_t *key, exports_hermes_kv_store_event_kv_values_t *value) { - -} - -// Exported Functions from `hermes:integration-test/event` -bool exports_hermes_integration_test_event_test(uint32_t test, bool run, exports_hermes_integration_test_event_test_result_t *ret) { - if (test < N_TEST) { - hermes_string_dup(&ret->name, TESTS[test].name.ptr); - ret->status = TESTS[test].status; - - return true; - } - - return false; -} - -bool exports_hermes_integration_test_event_bench(uint32_t test, bool run, exports_hermes_integration_test_event_test_result_t *ret) { - if (test < N_BENCH) { - hermes_string_dup(&ret->name, BENCHES[test].name.ptr); - ret->status = BENCHES[test].status; - - return true; - } - - return false; -} diff --git a/wasm/integration-test/cardano/.gitignore b/wasm/integration-test/cardano/.gitignore new file mode 100644 index 000000000..1bc620519 --- /dev/null +++ b/wasm/integration-test/cardano/.gitignore @@ -0,0 +1,3 @@ +target/ +src/hermes.rs +src/bindings.rs diff --git a/wasm/integration-test/cardano/Cargo.lock b/wasm/integration-test/cardano/Cargo.lock new file mode 100644 index 000000000..68db1ae9c --- /dev/null +++ b/wasm/integration-test/cardano/Cargo.lock @@ -0,0 +1,583 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" + +[[package]] +name = "base58" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6107fe1be6682a68940da878d9e9f5e90ca5745b3dec9fd1bb393c8777d4f581" + +[[package]] +name = "bech32" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "cardano-rte-test-component" +version = "0.1.0" +dependencies = [ + "hex", + "pallas-traverse", + "wit-bindgen", +] + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "crc" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86ec7a15cbe22e59248fc7eadb1907dab5ba09372595da4d73dd805ed4417dfe" +dependencies = [ + "crc-catalog", +] + +[[package]] +name = "crc-catalog" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "cryptoxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "382ce8820a5bb815055d3553a610e8cb542b2d767bbacea99038afda96cd760d" + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "half" +version = "1.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b43ede17f21864e81be2fa654110bf1e793774238d86ef8555c37e6519c0403" + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "id-arena" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25a2bc672d1148e28034f176e01fffebb08b35768468cc954630da77a1449005" + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown", + "serde", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "keccak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] + +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "minicbor" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d15f4203d71fdf90903c2696e55426ac97a363c67b218488a73b534ce7aca10" +dependencies = [ + "half", + "minicbor-derive", +] + +[[package]] +name = "minicbor-derive" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1154809406efdb7982841adb6311b3d095b46f78342dd646736122fe6b19e267" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "pallas-addresses" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9148574f9e1b25d67d11c9680bd267e927128d287d6d4de394695ed57388f28f" +dependencies = [ + "base58", + "bech32", + "crc", + "hex", + "pallas-codec", + "pallas-crypto", + "sha3", + "thiserror", +] + +[[package]] +name = "pallas-codec" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "357301a71c685b3c586defca1aaea59da46fb397c1b960c8487277adf0c346a1" +dependencies = [ + "hex", + "minicbor", + "serde", + "thiserror", +] + +[[package]] +name = "pallas-crypto" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1adbeb46418fd6b1ca00db9d81253f131c7555864f4e6712c7f562063c316" +dependencies = [ + "cryptoxide", + "hex", + "pallas-codec", + "rand_core", + "serde", + "thiserror", +] + +[[package]] +name = "pallas-primitives" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95666399b6ae09fdf93cf405e032d1c950909daf0fe8954b43c895653359a194" +dependencies = [ + "base58", + "bech32", + "hex", + "log", + "pallas-codec", + "pallas-crypto", + "serde", + "serde_json", +] + +[[package]] +name = "pallas-traverse" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfd9057640b61de89bf3176aeee20145192df644d09dd6672dcc85824901f11e" +dependencies = [ + "hex", + "pallas-addresses", + "pallas-codec", + "pallas-crypto", + "pallas-primitives", + "paste", + "serde", + "thiserror", +] + +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + +[[package]] +name = "proc-macro2" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "semver" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "serde_json" +version = "1.0.115" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest", + "keccak", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "spdx" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29ef1a0fa1e39ac22972c8db23ff89aea700ab96aa87114e1fb55937a631a0c9" +dependencies = [ + "smallvec", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasm-encoder" +version = "0.202.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfd106365a7f5f7aa3c1916a98cbb3ad477f5ff96ddb130285a91c6e7429e67a" +dependencies = [ + "leb128", +] + +[[package]] +name = "wasm-metadata" +version = "0.202.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "094aea3cb90e09f16ee25a4c0e324b3e8c934e7fd838bfa039aef5352f44a917" +dependencies = [ + "anyhow", + "indexmap", + "serde", + "serde_derive", + "serde_json", + "spdx", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.202.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6998515d3cf3f8b980ef7c11b29a9b1017d4cf86b99ae93b546992df9931413" +dependencies = [ + "bitflags", + "indexmap", + "semver", +] + +[[package]] +name = "wit-bindgen" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb4e7653763780be47e38f479e9aa83c768aa6a3b2ed086dc2826fdbbb7e7f5" +dependencies = [ + "wit-bindgen-rt", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b67e11c950041849a10828c7600ea62a4077c01e8af72e8593253575428f91b" +dependencies = [ + "anyhow", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rt" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0780cf7046630ed70f689a098cd8d56c5c3b22f2a7379bbdb088879963ff96" +dependencies = [ + "bitflags", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30acbe8fb708c3a830a33c4cb705df82659bf831b492ec6ca1a17a369cfeeafb" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b1b06eae85feaecdf9f2854f7cac124e00d5a6e5014bfb02eb1ecdeb5f265b9" +dependencies = [ + "anyhow", + "proc-macro2", + "quote", + "syn 2.0.58", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.202.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c836b1fd9932de0431c1758d8be08212071b6bba0151f7bac826dbc4312a2a9" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.202.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "744237b488352f4f27bca05a10acb79474415951c450e52ebd0da784c1df2bcc" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] diff --git a/wasm/integration-test/cardano/Cargo.toml b/wasm/integration-test/cardano/Cargo.toml new file mode 100644 index 000000000..cc79ae959 --- /dev/null +++ b/wasm/integration-test/cardano/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "cardano-rte-test-component" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib"] + +[dependencies] +hex = "0.4.3" +pallas-traverse = "0.25.0" +wit-bindgen = "0.24.0" diff --git a/wasm/integration-test/cardano/Earthfile b/wasm/integration-test/cardano/Earthfile new file mode 100644 index 000000000..a4335df5a --- /dev/null +++ b/wasm/integration-test/cardano/Earthfile @@ -0,0 +1,23 @@ +VERSION 0.7 + +build: + DO github.com/input-output-hk/catalyst-ci/earthly/rust:v2.11.2+SETUP + + COPY --dir src . + COPY Cargo.toml Cargo.lock . + COPY ../../wasi+build-rust-bindings/hermes.rs src/hermes.rs + + RUN cargo build --target wasm32-unknown-unknown --release + + COPY ../../wasi-hermes-component-adapter+build/wasi-hermes-component-adapter.wasm . + + RUN wasm-tools component new -o cardano.wasm target/wasm32-unknown-unknown/release/cardano_rte_test_component.wasm --adapt wasi-hermes-component-adapter.wasm + + SAVE ARTIFACT cardano.wasm + +get-local-bindings: + FROM scratch + + COPY ../../wasi+build-rust-bindings/hermes.rs hermes.rs + + SAVE ARTIFACT hermes.rs AS LOCAL src/hermes.rs diff --git a/wasm/integration-test/cardano/rust-toolchain.toml b/wasm/integration-test/cardano/rust-toolchain.toml new file mode 100644 index 000000000..bdbeb14b0 --- /dev/null +++ b/wasm/integration-test/cardano/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "1.75.0" +targets = ["wasm32-unknown-unknown"] diff --git a/wasm/integration-test/cardano/src/lib.rs b/wasm/integration-test/cardano/src/lib.rs new file mode 100644 index 000000000..2b6abe428 --- /dev/null +++ b/wasm/integration-test/cardano/src/lib.rs @@ -0,0 +1,100 @@ +// Allow everything since this is generated code. +#[allow(clippy::all, unused)] +mod hermes; + +use hermes::{ + exports::hermes::integration_test::event::TestResult, + hermes::{ + cardano::{ + self, + api::{BlockSrc, CardanoBlock, CardanoBlockchainId, CardanoTxn, Slot}, + }, + cron::api::CronTagged, + kv_store::api::KvValues, + }, + wasi::http::types::{IncomingRequest, ResponseOutparam}, +}; +use pallas_traverse::MultiEraBlock; + +struct TestComponent; + +fn test_fetch_block() -> bool { + let block_slot = 56581108; + let block_hash = + hex::decode("e095cca24865b85812109a8a0af01a8a80c6a74d1f56cfe1830631423a806b46") + .expect("valid block hash hex"); + + let slot = Slot::Point((block_slot, block_hash.clone())); + + let Ok(block_cbor) = cardano::api::fetch_block(CardanoBlockchainId::Preprod, &slot) else { + return false; + }; + + let Ok(block) = MultiEraBlock::decode(&block_cbor) else { + return false; + }; + + block_slot == block.slot() && block_hash == block.hash().to_vec() +} + +impl hermes::exports::hermes::integration_test::event::Guest for TestComponent { + fn test(test: u32, run: bool) -> Option { + match test { + 0 => { + let status = if run { test_fetch_block() } else { true }; + + Some(TestResult { + name: "Fetch block".to_string(), + status, + }) + } + + _ => None, + } + } + + fn bench(_test: u32, _run: bool) -> Option { + None + } +} + +impl hermes::exports::hermes::cardano::event_on_block::Guest for TestComponent { + fn on_cardano_block(_blockchain: CardanoBlockchainId, _block: CardanoBlock, _source: BlockSrc) { + } +} + +impl hermes::exports::hermes::cardano::event_on_rollback::Guest for TestComponent { + fn on_cardano_rollback(_blockchain: CardanoBlockchainId, _slot: u64) {} +} + +impl hermes::exports::hermes::cardano::event_on_txn::Guest for TestComponent { + fn on_cardano_txn( + _blockchain: CardanoBlockchainId, + _slot: u64, + _txn_index: u32, + _txn: CardanoTxn, + ) { + } +} + +impl hermes::exports::hermes::cron::event::Guest for TestComponent { + fn on_cron(_event: CronTagged, _last: bool) -> bool { + false + } +} + +impl hermes::exports::hermes::init::event::Guest for TestComponent { + fn init() -> bool { + true + } +} + +impl hermes::exports::hermes::kv_store::event::Guest for TestComponent { + fn kv_update(_key: String, _value: KvValues) {} +} + +impl hermes::exports::wasi::http::incoming_handler::Guest for TestComponent { + fn handle(_request: IncomingRequest, _response_out: ResponseOutparam) {} +} + +hermes::export!(TestComponent with_types_in hermes); diff --git a/wasm/integration-test/clocks/Earthfile b/wasm/integration-test/clocks/Earthfile new file mode 100644 index 000000000..2f179c1d3 --- /dev/null +++ b/wasm/integration-test/clocks/Earthfile @@ -0,0 +1,14 @@ +VERSION 0.7 + +# build - generate a wasm component from a C stub file +build: + FROM github.com/input-output-hk/catalyst-ci/earthly/wasm/c:v2.11.0+wasm-c-base + + ARG c_files="clocks.c" + + COPY ./$c_files . + COPY ../..+wasi-src/wasi . + + RUN /scripts/std_build.py --wit_path="wit" --c_files=$c_files --out="clocks.wasm" + + SAVE ARTIFACT clocks.wasm diff --git a/wasm/integration-test/clocks/clocks.c b/wasm/integration-test/clocks/clocks.c new file mode 100644 index 000000000..0c1d8eda6 --- /dev/null +++ b/wasm/integration-test/clocks/clocks.c @@ -0,0 +1,78 @@ +#include "bindings_src/hermes.h" +#include + +// Exported Functions from `wasi:http/incoming-handler@0.2.0` +void exports_wasi_http_incoming_handler_handle(exports_wasi_http_incoming_handler_own_incoming_request_t request, exports_wasi_http_incoming_handler_own_response_outparam_t response_out) +{ +} + +// Exported Functions from `hermes:cardano/event-on-block` +void exports_hermes_cardano_event_on_block_on_cardano_block(exports_hermes_cardano_event_on_block_cardano_blockchain_id_t blockchain, exports_hermes_cardano_event_on_block_cardano_block_t *block, exports_hermes_cardano_event_on_block_block_src_t source) +{ +} + +// Exported Functions from `hermes:cardano/event-on-txn` +void exports_hermes_cardano_event_on_txn_on_cardano_txn(exports_hermes_cardano_event_on_txn_cardano_blockchain_id_t blockchain, uint64_t slot, uint32_t txn_index, exports_hermes_cardano_event_on_txn_cardano_txn_t *txn) +{ +} + +// Exported Functions from `hermes:cardano/event-on-rollback` +void exports_hermes_cardano_event_on_rollback_on_cardano_rollback(exports_hermes_cardano_event_on_rollback_cardano_blockchain_id_t blockchain, uint64_t slot) +{ +} + +// Exported Functions from `hermes:cron/event` +bool exports_hermes_cron_event_on_cron(exports_hermes_cron_event_cron_tagged_t *event, bool last) +{ + return false; +} + +// Exported Functions from `hermes:init/event` +bool exports_hermes_init_event_init(void) +{ + return false; +} + +// Exported Functions from `hermes:kv-store/event` +void exports_hermes_kv_store_event_kv_update(hermes_string_t *key, exports_hermes_kv_store_event_kv_values_t *value) +{ +} + +#define HERMES_STRING(x) \ + (hermes_string_t) { (uint8_t *)x, strlen(x) } +#define HERMES_JSON_STRING(x) \ + (hermes_json_api_json_t) { (uint8_t *)x, strlen(x) } + + +// Monotonic clock test function +bool test_monotonic_now_function() +{ + wasi_clocks_monotonic_clock_instant_t one = wasi_clocks_monotonic_clock_now(); + wasi_clocks_monotonic_clock_instant_t two = wasi_clocks_monotonic_clock_now(); + + return one <= two; +} + +// Exported Functions from `hermes:integration-test/event` +bool exports_hermes_integration_test_event_test(uint32_t test, bool run, exports_hermes_integration_test_event_test_result_t *ret) +{ + ret->status = true; + switch (test) + { + case 0: + hermes_string_dup(&ret->name, "clocks_monotonic_now"); + if (run) + ret->status = test_monotonic_now_function(); + break; + + default: + return false; + } + + return true; +} + +bool exports_hermes_integration_test_event_bench(uint32_t test, bool run, exports_hermes_integration_test_event_test_result_t *ret) +{ + return false; +} diff --git a/wasm/integration-test/cron/Earthfile b/wasm/integration-test/cron/Earthfile new file mode 100644 index 000000000..b11926e31 --- /dev/null +++ b/wasm/integration-test/cron/Earthfile @@ -0,0 +1,14 @@ +VERSION 0.7 + +# build - generate a wasm component from a C stub file +build: + FROM github.com/input-output-hk/catalyst-ci/earthly/wasm/c:v2.11.0+wasm-c-base + + ARG c_files="cron.c" + + COPY ./$c_files . + COPY ../..+wasi-src/wasi . + + RUN /scripts/std_build.py --wit_path="wit" --c_files=$c_files --out="cron.wasm" + + SAVE ARTIFACT cron.wasm diff --git a/wasm/integration-test/cron/cron.c b/wasm/integration-test/cron/cron.c new file mode 100644 index 000000000..42b008021 --- /dev/null +++ b/wasm/integration-test/cron/cron.c @@ -0,0 +1,133 @@ +#include "bindings_src/hermes.h" +#include + +// Exported Functions from `wasi:http/incoming-handler@0.2.0` +void exports_wasi_http_incoming_handler_handle(exports_wasi_http_incoming_handler_own_incoming_request_t request, exports_wasi_http_incoming_handler_own_response_outparam_t response_out) +{ +} + +// Exported Functions from `hermes:cardano/event-on-block` +void exports_hermes_cardano_event_on_block_on_cardano_block(exports_hermes_cardano_event_on_block_cardano_blockchain_id_t blockchain, exports_hermes_cardano_event_on_block_cardano_block_t *block, exports_hermes_cardano_event_on_block_block_src_t source) +{ +} + +// Exported Functions from `hermes:cardano/event-on-txn` +void exports_hermes_cardano_event_on_txn_on_cardano_txn(exports_hermes_cardano_event_on_txn_cardano_blockchain_id_t blockchain, uint64_t slot, uint32_t txn_index, exports_hermes_cardano_event_on_txn_cardano_txn_t *txn) +{ +} + +// Exported Functions from `hermes:cardano/event-on-rollback` +void exports_hermes_cardano_event_on_rollback_on_cardano_rollback(exports_hermes_cardano_event_on_rollback_cardano_blockchain_id_t blockchain, uint64_t slot) +{ +} + +// Exported Functions from `hermes:cron/event` +bool exports_hermes_cron_event_on_cron(exports_hermes_cron_event_cron_tagged_t *event, bool last) +{ + return false; +} + +// Exported Functions from `hermes:init/event` +bool exports_hermes_init_event_init(void) +{ + return false; +} + +// Exported Functions from `hermes:kv-store/event` +void exports_hermes_kv_store_event_kv_update(hermes_string_t *key, exports_hermes_kv_store_event_kv_values_t *value) +{ +} + +const char *tag_str = "Example Tag"; +const char *schedule_str = "* * * * *"; + +hermes_cron_api_cron_tagged_t example_cron_tagged() +{ + hermes_cron_api_cron_sched_t when = {.ptr = (uint8_t *)schedule_str, .len = strlen(schedule_str)}; + hermes_cron_api_cron_event_tag_t tag = {.ptr = (uint8_t *)tag_str, .len = strlen(tag_str)}; + + return (hermes_cron_api_cron_tagged_t){ when, tag }; +} + +bool add_crontab() +{ + hermes_cron_api_cron_tagged_t entry = example_cron_tagged(); + bool retrigger = true; + + return hermes_cron_api_add(&entry, retrigger); +} + +bool delay_crontab() +{ + hermes_cron_api_cron_event_tag_t tag = {.ptr = (uint8_t *)tag_str, .len = strlen(tag_str)}; + hermes_cron_api_instant_t duration = 2000000000; + return hermes_cron_api_delay(duration, &tag); +} + +bool list_crontabs() +{ + hermes_cron_api_cron_event_tag_t maybe_tag = {.ptr = NULL, .len = 0}; + hermes_cron_api_list_tuple2_cron_tagged_bool_t ret; + hermes_cron_api_ls(&maybe_tag, &ret); + return ret.ptr != NULL && ret.len == 0; +} + +bool remove_crontab() +{ + hermes_cron_api_cron_tagged_t entry = example_cron_tagged(); + return !hermes_cron_api_rm(&entry); +} + +bool make_cron() +{ + hermes_cron_api_cron_component_t all = { .tag = HERMES_CRON_API_CRON_COMPONENT_ALL }; + hermes_cron_api_cron_time_t ctime = { .ptr = &all, .len = 1 }; + hermes_cron_api_cron_sched_t ret; + hermes_cron_api_mkcron(&ctime, &ctime, &ctime, &ctime, &ctime, &ret); + + size_t n = strlen(schedule_str); + return ret.ptr != NULL && ret.len == n && strncmp((const char *)ret.ptr, schedule_str, n) == 0; +} + +// Exported Functions from `hermes:integration-test/event` +bool exports_hermes_integration_test_event_test(uint32_t test, bool run, exports_hermes_integration_test_event_test_result_t *ret) +{ + ret->status = true; + switch (test) + { + case 0: + hermes_string_dup(&ret->name, "Add Crontab"); + if (run) + ret->status = add_crontab(); + break; + case 1: + hermes_string_dup(&ret->name, "Delay Crontab"); + if (run) + ret->status = delay_crontab(); + break; + case 2: + hermes_string_dup(&ret->name, "List Crontabs"); + if (run) + ret->status = list_crontabs(); + break; + case 3: + hermes_string_dup(&ret->name, "Remove Crontab"); + if (run) + ret->status = remove_crontab(); + break; + case 4: + hermes_string_dup(&ret->name, "Make Cron Entry"); + if (run) + ret->status = make_cron(); + break; + default: + return false; + } + + return true; +} + +bool exports_hermes_integration_test_event_bench(uint32_t test, bool run, exports_hermes_integration_test_event_test_result_t *ret) +{ + return false; +} diff --git a/wasm/integration-test/crypto/Earthfile b/wasm/integration-test/crypto/Earthfile new file mode 100644 index 000000000..8a2c8b0ca --- /dev/null +++ b/wasm/integration-test/crypto/Earthfile @@ -0,0 +1,14 @@ +VERSION 0.7 + +# build - generate a wasm component from a C stub file +build: + FROM github.com/input-output-hk/catalyst-ci/earthly/wasm/c:v2.11.0+wasm-c-base + + ARG c_files="crypto.c" + + COPY ./$c_files . + COPY ../..+wasi-src/wasi . + + RUN /scripts/std_build.py --wit_path="wit" --c_files=$c_files --out="crypto.wasm" + + SAVE ARTIFACT crypto.wasm diff --git a/wasm/integration-test/crypto/crypto.c b/wasm/integration-test/crypto/crypto.c new file mode 100644 index 000000000..51e19aca4 --- /dev/null +++ b/wasm/integration-test/crypto/crypto.c @@ -0,0 +1,114 @@ +#include "bindings_src/hermes.h" +#include + +// Exported Functions from `wasi:http/incoming-handler@0.2.0` +void exports_wasi_http_incoming_handler_handle(exports_wasi_http_incoming_handler_own_incoming_request_t request, exports_wasi_http_incoming_handler_own_response_outparam_t response_out) +{ +} + +// Exported Functions from `hermes:cardano/event-on-block` +void exports_hermes_cardano_event_on_block_on_cardano_block(exports_hermes_cardano_event_on_block_cardano_blockchain_id_t blockchain, exports_hermes_cardano_event_on_block_cardano_block_t *block, exports_hermes_cardano_event_on_block_block_src_t source) +{ +} + +// Exported Functions from `hermes:cardano/event-on-txn` +void exports_hermes_cardano_event_on_txn_on_cardano_txn(exports_hermes_cardano_event_on_txn_cardano_blockchain_id_t blockchain, uint64_t slot, uint32_t txn_index, exports_hermes_cardano_event_on_txn_cardano_txn_t *txn) +{ +} + +// Exported Functions from `hermes:cardano/event-on-rollback` +void exports_hermes_cardano_event_on_rollback_on_cardano_rollback(exports_hermes_cardano_event_on_rollback_cardano_blockchain_id_t blockchain, uint64_t slot) +{ +} + +// Exported Functions from `hermes:cron/event` +bool exports_hermes_cron_event_on_cron(exports_hermes_cron_event_cron_tagged_t *event, bool last) +{ + return false; +} + +// Exported Functions from `hermes:init/event` +bool exports_hermes_init_event_init(void) +{ + return false; +} + +// Exported Functions from `hermes:kv-store/event` +void exports_hermes_kv_store_event_kv_update(hermes_string_t *key, exports_hermes_kv_store_event_kv_values_t *value) +{ +} + +#define HERMES_STRING(x) \ + (hermes_string_t) { (uint8_t *)x, strlen(x) } + +hermes_crypto_api_borrow_bip32_ed25519_t get_or_add_resource() +{ + hermes_string_t mnemonic_string = HERMES_STRING("prevent company field green slot measure chief hero apple task eagle sunset endorse dress seed"); + hermes_crypto_api_mnemonic_phrase_t mnemonic = {.ptr = &mnemonic_string, .len = 1}; + + hermes_string_t passphrase_string = {.ptr = NULL, .len = 0}; + hermes_crypto_api_passphrase_t passphrase = {.ptr = &passphrase_string, .len = 0}; + + hermes_crypto_api_own_bip32_ed25519_t resource = hermes_crypto_api_constructor_bip32_ed25519(&mnemonic, NULL); + hermes_crypto_api_borrow_bip32_ed25519_t borrow_resource = hermes_crypto_api_borrow_bip32_ed25519(resource); + return borrow_resource; +} + +bool generate_mnemonic() +{ + hermes_string_t prefix_data = HERMES_STRING("project"); + + hermes_crypto_api_prefix_t prefix = {.ptr = &prefix_data, .len = 1}; + hermes_string_t language = HERMES_STRING("English"); + + hermes_crypto_api_mnemonic_phrase_t ret; + hermes_crypto_api_errno_t err; + + hermes_crypto_api_generate_mnemonic(24, &prefix, &language, &ret, &err); + + char *expected_prefix = "project"; + size_t n = strlen(expected_prefix); + + return ret.ptr != NULL && ret.ptr->ptr != NULL && ret.ptr->len >= n && + strncmp((const char *)ret.ptr->ptr, expected_prefix, n) == 0; +} + +bool get_pubkey() +{ + hermes_crypto_api_borrow_bip32_ed25519_t borrow_resource = get_or_add_resource(); + hermes_crypto_api_bip32_ed25519_public_key_t ret; + hermes_crypto_api_method_bip32_ed25519_public_key(borrow_resource, &ret); + + return (ret.f0 == 3986768884739312704ULL) && + (ret.f1 == 9782938079688165927ULL) && + (ret.f2 == 7977656244723921923ULL) && + (ret.f3 == 12587033252467133758ULL); +} + +// Exported Functions from `hermes:integration-test/event` +bool exports_hermes_integration_test_event_test(uint32_t test, bool run, exports_hermes_integration_test_event_test_result_t *ret) +{ + ret->status = true; + switch (test) + { + case 0: + hermes_string_dup(&ret->name, "Generate mnemonic"); + if (run) + ret->status = generate_mnemonic(); + break; + case 1: + hermes_string_dup(&ret->name, "BIP32-Ed25519"); + if (run) + ret->status = get_pubkey(); + break; + default: + return false; + } + + return true; +} + +bool exports_hermes_integration_test_event_bench(uint32_t test, bool run, exports_hermes_integration_test_event_test_result_t *ret) +{ + return false; +} diff --git a/wasm/integration-test/hashing/Earthfile b/wasm/integration-test/hashing/Earthfile new file mode 100644 index 000000000..c05497f6f --- /dev/null +++ b/wasm/integration-test/hashing/Earthfile @@ -0,0 +1,14 @@ +VERSION 0.7 + +# build - generate a wasm component from a C stub file +build: + FROM github.com/input-output-hk/catalyst-ci/earthly/wasm/c:v2.11.0+wasm-c-base + + ARG c_files="hashing.c" + + COPY ./$c_files . + COPY ../..+wasi-src/wasi . + + RUN /scripts/std_build.py --wit_path="wit" --c_files=$c_files --out="hashing.wasm" + + SAVE ARTIFACT hashing.wasm diff --git a/wasm/integration-test/hashing/hashing.c b/wasm/integration-test/hashing/hashing.c new file mode 100644 index 000000000..6f614d620 --- /dev/null +++ b/wasm/integration-test/hashing/hashing.c @@ -0,0 +1,102 @@ +#include "bindings_src/hermes.h" +#include + +// Exported Functions from `wasi:http/incoming-handler@0.2.0` +void exports_wasi_http_incoming_handler_handle(exports_wasi_http_incoming_handler_own_incoming_request_t request, exports_wasi_http_incoming_handler_own_response_outparam_t response_out) +{ +} + +// Exported Functions from `hermes:cardano/event-on-block` +void exports_hermes_cardano_event_on_block_on_cardano_block(exports_hermes_cardano_event_on_block_cardano_blockchain_id_t blockchain, exports_hermes_cardano_event_on_block_cardano_block_t *block, exports_hermes_cardano_event_on_block_block_src_t source) +{ +} + +// Exported Functions from `hermes:cardano/event-on-txn` +void exports_hermes_cardano_event_on_txn_on_cardano_txn(exports_hermes_cardano_event_on_txn_cardano_blockchain_id_t blockchain, uint64_t slot, uint32_t txn_index, exports_hermes_cardano_event_on_txn_cardano_txn_t *txn) +{ +} + +// Exported Functions from `hermes:cardano/event-on-rollback` +void exports_hermes_cardano_event_on_rollback_on_cardano_rollback(exports_hermes_cardano_event_on_rollback_cardano_blockchain_id_t blockchain, uint64_t slot) +{ +} + +// Exported Functions from `hermes:cron/event` +bool exports_hermes_cron_event_on_cron(exports_hermes_cron_event_cron_tagged_t *event, bool last) +{ + return false; +} + +// Exported Functions from `hermes:init/event` +bool exports_hermes_init_event_init(void) +{ + return false; +} + +// Exported Functions from `hermes:kv-store/event` +void exports_hermes_kv_store_event_kv_update(hermes_string_t *key, exports_hermes_kv_store_event_kv_values_t *value) +{ +} + +#define HERMES_BUFFER(x) \ + (hermes_hash_api_bstr_t) { (uint8_t *)x, strlen(x) } + +#define HERMES_STRING(x) \ + (hermes_string_t) { (uint8_t *)x, strlen(x) } +#define HERMES_JSON_STRING(x) \ + (hermes_json_api_json_t) { (uint8_t *)x, strlen(x) } + +// Logging test function +bool test_blake2b_512_function() +{ + + hermes_hash_api_bstr_t buf = HERMES_BUFFER("test test"); + uint8_t outlen = 64; + hermes_hash_api_bstr_t ret; + hermes_hash_api_errno_t err; + + if (hermes_hash_api_blake2b(&buf, &outlen, &ret, &err)) + { + // Check if the hash we got returned is the correct size. + if (ret.len == 64) + { + // Constant binary data to compare against + const unsigned char constantData[] = { + 0x8e, 0x27, 0xb2, 0x48, 0x1d, 0xd1, 0xfe, 0x73, + 0xd5, 0x98, 0x10, 0x4c, 0x03, 0xb1, 0xf6, 0x7d, + 0xa6, 0x07, 0x25, 0xab, 0xb7, 0x3c, 0xf6, 0x6e, + 0x40, 0x01, 0x77, 0xd7, 0x3a, 0xee, 0x01, 0xe7, + 0x4b, 0x93, 0xf5, 0x5a, 0xdd, 0xa2, 0x7b, 0x0a, + 0xd9, 0x2e, 0x22, 0xe2, 0x84, 0xb5, 0xe0, 0xcc, + 0x95, 0xad, 0x81, 0xb0, 0x4b, 0x49, 0x6b, 0xd5, + 0x8c, 0x4a, 0xe6, 0xbc, 0xa5, 0xf5, 0x61, 0x96}; + + return memcmp(ret.ptr, constantData, sizeof(constantData)) == 0; + } + } + return false; +} + +// Exported Functions from `hermes:integration-test/event` +bool exports_hermes_integration_test_event_test(uint32_t test, bool run, exports_hermes_integration_test_event_test_result_t *ret) +{ + ret->status = true; + switch (test) + { + case 0: + hermes_string_dup(&ret->name, "blake2b-512"); + if (run) + ret->status = test_blake2b_512_function(); + break; + + default: + return false; + } + + return true; +} + +bool exports_hermes_integration_test_event_bench(uint32_t test, bool run, exports_hermes_integration_test_event_test_result_t *ret) +{ + return false; +} diff --git a/wasm/integration-test/localtime/Earthfile b/wasm/integration-test/localtime/Earthfile new file mode 100644 index 000000000..a4465579b --- /dev/null +++ b/wasm/integration-test/localtime/Earthfile @@ -0,0 +1,14 @@ +VERSION 0.7 + +# build - generate a wasm component from a C stub file +build: + FROM github.com/input-output-hk/catalyst-ci/earthly/wasm/c:v2.11.0+wasm-c-base + + ARG c_files="localtime.c" + + COPY ./$c_files . + COPY ../..+wasi-src/wasi . + + RUN /scripts/std_build.py --wit_path="wit" --c_files=$c_files --out="localtime.wasm" + + SAVE ARTIFACT localtime.wasm diff --git a/wasm/integration-test/localtime/localtime.c b/wasm/integration-test/localtime/localtime.c new file mode 100644 index 000000000..1355851b6 --- /dev/null +++ b/wasm/integration-test/localtime/localtime.c @@ -0,0 +1,81 @@ +#include "bindings_src/hermes.h" +#include + +// Exported Functions from `wasi:http/incoming-handler@0.2.0` +void exports_wasi_http_incoming_handler_handle(exports_wasi_http_incoming_handler_own_incoming_request_t request, exports_wasi_http_incoming_handler_own_response_outparam_t response_out) +{ +} + +// Exported Functions from `hermes:cardano/event-on-block` +void exports_hermes_cardano_event_on_block_on_cardano_block(exports_hermes_cardano_event_on_block_cardano_blockchain_id_t blockchain, exports_hermes_cardano_event_on_block_cardano_block_t *block, exports_hermes_cardano_event_on_block_block_src_t source) +{ +} + +// Exported Functions from `hermes:cardano/event-on-txn` +void exports_hermes_cardano_event_on_txn_on_cardano_txn(exports_hermes_cardano_event_on_txn_cardano_blockchain_id_t blockchain, uint64_t slot, uint32_t txn_index, exports_hermes_cardano_event_on_txn_cardano_txn_t *txn) +{ +} + +// Exported Functions from `hermes:cardano/event-on-rollback` +void exports_hermes_cardano_event_on_rollback_on_cardano_rollback(exports_hermes_cardano_event_on_rollback_cardano_blockchain_id_t blockchain, uint64_t slot) +{ +} + +// Exported Functions from `hermes:cron/event` +bool exports_hermes_cron_event_on_cron(exports_hermes_cron_event_cron_tagged_t *event, bool last) +{ + return false; +} + +// Exported Functions from `hermes:init/event` +bool exports_hermes_init_event_init(void) +{ + return false; +} + +// Exported Functions from `hermes:kv-store/event` +void exports_hermes_kv_store_event_kv_update(hermes_string_t *key, exports_hermes_kv_store_event_kv_values_t *value) +{ +} + +#define HERMES_STRING(x) \ + (hermes_string_t) { (uint8_t *)x, strlen(x) } +#define HERMES_JSON_STRING(x) \ + (hermes_json_api_json_t) { (uint8_t *)x, strlen(x) } + +// Localtime test function +bool test_localtime_function() +{ + hermes_localtime_api_localtime_t ret; + hermes_localtime_api_errno_t err; + + if (hermes_localtime_api_get_localtime(NULL, &HERMES_STRING("Europe/London"), &ret, &err)) { + return true; + } + + return false; +} + +// Exported Functions from `hermes:integration-test/event` +bool exports_hermes_integration_test_event_test(uint32_t test, bool run, exports_hermes_integration_test_event_test_result_t *ret) +{ + ret->status = true; + switch (test) + { + case 0: + hermes_string_dup(&ret->name, "get_localtime"); + if (run) + ret->status = test_localtime_function(); + break; + + default: + return false; + } + + return true; +} + +bool exports_hermes_integration_test_event_bench(uint32_t test, bool run, exports_hermes_integration_test_event_test_result_t *ret) +{ + return false; +} diff --git a/wasm/integration-test/logger/Earthfile b/wasm/integration-test/logger/Earthfile new file mode 100644 index 000000000..cba16affe --- /dev/null +++ b/wasm/integration-test/logger/Earthfile @@ -0,0 +1,14 @@ +VERSION 0.7 + +# build - generate a wasm component from a C stub file +build: + FROM github.com/input-output-hk/catalyst-ci/earthly/wasm/c:v2.11.0+wasm-c-base + + ARG c_files="logger.c" + + COPY ./$c_files . + COPY ../..+wasi-src/wasi . + + RUN /scripts/std_build.py --wit_path="wit" --c_files=$c_files --out="logger.wasm" + + SAVE ARTIFACT logger.wasm diff --git a/wasm/integration-test/logger/logger.c b/wasm/integration-test/logger/logger.c new file mode 100644 index 000000000..257c8223b --- /dev/null +++ b/wasm/integration-test/logger/logger.c @@ -0,0 +1,92 @@ +#include "bindings_src/hermes.h" +#include + +// Exported Functions from `wasi:http/incoming-handler@0.2.0` +void exports_wasi_http_incoming_handler_handle(exports_wasi_http_incoming_handler_own_incoming_request_t request, exports_wasi_http_incoming_handler_own_response_outparam_t response_out) +{ +} + +// Exported Functions from `hermes:cardano/event-on-block` +void exports_hermes_cardano_event_on_block_on_cardano_block(exports_hermes_cardano_event_on_block_cardano_blockchain_id_t blockchain, exports_hermes_cardano_event_on_block_cardano_block_t *block, exports_hermes_cardano_event_on_block_block_src_t source) +{ +} + +// Exported Functions from `hermes:cardano/event-on-txn` +void exports_hermes_cardano_event_on_txn_on_cardano_txn(exports_hermes_cardano_event_on_txn_cardano_blockchain_id_t blockchain, uint64_t slot, uint32_t txn_index, exports_hermes_cardano_event_on_txn_cardano_txn_t *txn) +{ +} + +// Exported Functions from `hermes:cardano/event-on-rollback` +void exports_hermes_cardano_event_on_rollback_on_cardano_rollback(exports_hermes_cardano_event_on_rollback_cardano_blockchain_id_t blockchain, uint64_t slot) +{ +} + +// Exported Functions from `hermes:cron/event` +bool exports_hermes_cron_event_on_cron(exports_hermes_cron_event_cron_tagged_t *event, bool last) +{ + return false; +} + +// Exported Functions from `hermes:init/event` +bool exports_hermes_init_event_init(void) +{ + return false; +} + +// Exported Functions from `hermes:kv-store/event` +void exports_hermes_kv_store_event_kv_update(hermes_string_t *key, exports_hermes_kv_store_event_kv_values_t *value) +{ +} + +#define HERMES_STRING(x) \ + (hermes_string_t) { (uint8_t *)x, strlen(x) } +#define HERMES_JSON_STRING(x) \ + (hermes_json_api_json_t) { (uint8_t *)x, strlen(x) } + +// Logging test function +bool test_logging_function() +{ + hermes_string_t file; + hermes_string_t function; + uint32_t line; + uint32_t col; + hermes_string_t ctx; + hermes_string_t msg; + hermes_json_api_json_t data; + + file = HERMES_STRING("filename.c"); + function = HERMES_STRING("main"); + line = 11; + col = 6; + ctx = HERMES_STRING("Context"); + msg = HERMES_STRING("Log Message"); + data = HERMES_JSON_STRING("{\"key\":\"value\"}"); + + hermes_logging_api_log(2, &file, &function, &line, &col, &ctx, &msg, &data); + + return true; +} + +// Exported Functions from `hermes:integration-test/event` +bool exports_hermes_integration_test_event_test(uint32_t test, bool run, exports_hermes_integration_test_event_test_result_t *ret) +{ + ret->status = true; + switch (test) + { + case 0: + hermes_string_dup(&ret->name, "Call Logger"); + if (run) + ret->status = test_logging_function(); + break; + + default: + return false; + } + + return true; +} + +bool exports_hermes_integration_test_event_bench(uint32_t test, bool run, exports_hermes_integration_test_event_test_result_t *ret) +{ + return false; +} diff --git a/wasm/integration-test/smoke-test/Earthfile b/wasm/integration-test/smoke-test/Earthfile new file mode 100644 index 000000000..b85ddfcdd --- /dev/null +++ b/wasm/integration-test/smoke-test/Earthfile @@ -0,0 +1,14 @@ +VERSION 0.7 + +# build - generate a wasm component from a C stub file +build: + FROM github.com/input-output-hk/catalyst-ci/earthly/wasm/c:v2.11.0+wasm-c-base + + ARG c_files="smoke-test.c" + + COPY ./$c_files . + COPY ../..+wasi-src/wasi . + + RUN /scripts/std_build.py --wit_path="wit" --c_files=$c_files --out="smoke-test.wasm" + + SAVE ARTIFACT smoke-test.wasm diff --git a/wasm/integration-test/smoke-test/smoke-test.c b/wasm/integration-test/smoke-test/smoke-test.c new file mode 100644 index 000000000..2db8326e9 --- /dev/null +++ b/wasm/integration-test/smoke-test/smoke-test.c @@ -0,0 +1,89 @@ +#include "bindings_src/hermes.h" + +// Exported Functions from `wasi:http/incoming-handler@0.2.0` +void exports_wasi_http_incoming_handler_handle(exports_wasi_http_incoming_handler_own_incoming_request_t request, exports_wasi_http_incoming_handler_own_response_outparam_t response_out) +{ +} + +// Exported Functions from `hermes:cardano/event-on-block` +void exports_hermes_cardano_event_on_block_on_cardano_block(exports_hermes_cardano_event_on_block_cardano_blockchain_id_t blockchain, exports_hermes_cardano_event_on_block_cardano_block_t *block, exports_hermes_cardano_event_on_block_block_src_t source) +{ +} + +// Exported Functions from `hermes:cardano/event-on-txn` +void exports_hermes_cardano_event_on_txn_on_cardano_txn(exports_hermes_cardano_event_on_txn_cardano_blockchain_id_t blockchain, uint64_t slot, uint32_t txn_index, exports_hermes_cardano_event_on_txn_cardano_txn_t *txn) +{ +} + +// Exported Functions from `hermes:cardano/event-on-rollback` +void exports_hermes_cardano_event_on_rollback_on_cardano_rollback(exports_hermes_cardano_event_on_rollback_cardano_blockchain_id_t blockchain, uint64_t slot) +{ +} + +// Exported Functions from `hermes:cron/event` +bool exports_hermes_cron_event_on_cron(exports_hermes_cron_event_cron_tagged_t *event, bool last) +{ + return false; +} + +// Exported Functions from `hermes:init/event` +bool exports_hermes_init_event_init(void) +{ + return false; +} + +// Exported Functions from `hermes:kv-store/event` +void exports_hermes_kv_store_event_kv_update(hermes_string_t *key, exports_hermes_kv_store_event_kv_values_t *value) +{ +} + +// Exported Functions from `hermes:integration-test/event` +bool exports_hermes_integration_test_event_test(uint32_t test, bool run, exports_hermes_integration_test_event_test_result_t *ret) +{ + ret->status = true; + switch (test) + { + case 0: + hermes_string_dup(&ret->name, "Test Case 0"); + break; + case 1: + hermes_string_dup(&ret->name, "Test Case 1"); + break; + case 2: + hermes_string_dup(&ret->name, "Test Case 2"); + break; + case 3: + hermes_string_dup(&ret->name, "Test Case 3"); + break; + case 4: + hermes_string_dup(&ret->name, "Test Case 4"); + break; + + default: + return false; + } + + return true; +} + +bool exports_hermes_integration_test_event_bench(uint32_t test, bool run, exports_hermes_integration_test_event_test_result_t *ret) +{ + ret->status = true; + switch (test) + { + case 0: + hermes_string_dup(&ret->name, "Bench Case 0"); + break; + case 1: + hermes_string_dup(&ret->name, "Bench Case 1"); + break; + case 2: + hermes_string_dup(&ret->name, "Bench Case 2"); + break; + + default: + return false; + } + + return true; +} diff --git a/wasm/c/Earthfile b/wasm/stub-module/Earthfile similarity index 61% rename from wasm/c/Earthfile rename to wasm/stub-module/Earthfile index 3b79d84a2..198d964cf 100644 --- a/wasm/c/Earthfile +++ b/wasm/stub-module/Earthfile @@ -2,20 +2,20 @@ VERSION 0.7 # build - generate a wasm component from a C stub file build: - FROM github.com/input-output-hk/catalyst-ci/earthly/wasm/c:v2.9.0+wasm-c-base + FROM github.com/input-output-hk/catalyst-ci/earthly/wasm/c:v2.11.0+wasm-c-base - ARG c_files="my-component.c" + ARG c_files="stub-module.c" COPY ./$c_files . COPY ..+wasi-src/wasi . - RUN /scripts/std_build.py --wit_path="wit" --c_files=$c_files --out="component.wasm" + RUN /scripts/std_build.py --wit_path="wit" --c_files=$c_files --out="stub.wasm" - SAVE ARTIFACT component.wasm + SAVE ARTIFACT stub.wasm # Build and locally save an output artifact save-local: FROM scratch - COPY +build/component.wasm . - SAVE ARTIFACT component.wasm AS LOCAL bench_component.wasm + COPY +build/stub.wasm . + SAVE ARTIFACT stub.wasm AS LOCAL stub.wasm diff --git a/wasm/c/my-component.c b/wasm/stub-module/stub-module.c similarity index 100% rename from wasm/c/my-component.c rename to wasm/stub-module/stub-module.c diff --git a/wasm/wasi-hermes-component-adapter/Earthfile b/wasm/wasi-hermes-component-adapter/Earthfile index b1c4e89f6..3c4629d20 100644 --- a/wasm/wasi-hermes-component-adapter/Earthfile +++ b/wasm/wasi-hermes-component-adapter/Earthfile @@ -4,7 +4,7 @@ VERSION 0.7 # Set up our target toolchains, and copy source files. builder: - DO github.com/input-output-hk/catalyst-ci/earthly/rust:v2.10.0+SETUP + DO github.com/input-output-hk/catalyst-ci/earthly/rust:v2.11.2+SETUP COPY --dir .cargo .config src byte-array-literals . COPY ..+wasi-src/wasi ../wasi diff --git a/wasm/wasi-hermes-component-adapter/deny.toml b/wasm/wasi-hermes-component-adapter/deny.toml index 24ab10c6c..608eb845c 100644 --- a/wasm/wasi-hermes-component-adapter/deny.toml +++ b/wasm/wasi-hermes-component-adapter/deny.toml @@ -270,7 +270,8 @@ unknown-git = "deny" allow-registry = ["https://github.com/rust-lang/crates.io-index"] # List of URLs for allowed Git repositories allow-git = [ - "https://github.com/input-output-hk/hermes.git" + "https://github.com/input-output-hk/hermes.git", + "https://github.com/input-output-hk/catalyst-pallas.git" ] [sources.allow-org] diff --git a/wasm/wasi/.gitignore b/wasm/wasi/.gitignore new file mode 100644 index 000000000..b39f7a538 --- /dev/null +++ b/wasm/wasi/.gitignore @@ -0,0 +1,2 @@ +# Generated Bindings files +bindings diff --git a/wasm/wasi/Earthfile b/wasm/wasi/Earthfile index e0490f270..3a2d12c6a 100644 --- a/wasm/wasi/Earthfile +++ b/wasm/wasi/Earthfile @@ -71,16 +71,20 @@ build: SAVE ARTIFACT wasi-hermes-docs wasi-hermes-docs # test-rust-bindings - Test we can generate rust bindings without error from the hermes default world -test-rust-bindings: +build-rust-bindings: FROM ../wasi-hermes-component-adapter+builder - RUN wit-bindgen rust ../wasi/wit --stubs + RUN wit-bindgen rust ../wasi/wit + + SAVE ARTIFACT hermes.rs # test-c-bindings - Test we can generate C bindings without error from the hermes default world -test-c-bindings: +build-c-bindings: FROM ../wasi-hermes-component-adapter+builder - RUN wit-bindgen c --autodrop-borrows yes --no-object-file ../wasi/wit + RUN wit-bindgen c --autodrop-borrows yes --no-object-file ../wasi/wit --out-dir bindings/c + + SAVE ARTIFACT bindings # test-java-bindings - Test we can generate Java bindings without error from the hermes default world test-java-bindings: @@ -93,13 +97,16 @@ test-java-bindings: test-go-bindings: FROM ../wasi-hermes-component-adapter+builder - # java bindings are currently broken because `resource` is not yet implemented. RUN wit-bindgen tiny-go ../wasi/wit # test-csharp-bindings - Test we can generate CSharp bindings without error from the hermes default world test-csharp-bindings: FROM ../wasi-hermes-component-adapter+builder - # java bindings are currently broken because `lots of stuff is not yet implemented. + # csharp bindings are currently broken because `lots of stuff is not yet implemented. RUN wit-bindgen c-sharp -r mono --generate-stub ../wasi/wit | true +local-c-bindings: + FROM +build-c-bindings + + SAVE ARTIFACT bindings AS LOCAL bindings