From 1f0d0c2c3aab0a48ba9f79e1efa58266b2d06698 Mon Sep 17 00:00:00 2001 From: sword_smith Date: Tue, 10 Sep 2024 13:01:02 +0200 Subject: [PATCH] feat: Add `From` for InitVmState implementation Allows us to call `.into()` on a FunctionInitialState for use with e.g. `negative_test` test-helper function. --- tasm-lib/src/traits/function.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tasm-lib/src/traits/function.rs b/tasm-lib/src/traits/function.rs index 3bf5248a..ad7a79b6 100644 --- a/tasm-lib/src/traits/function.rs +++ b/tasm-lib/src/traits/function.rs @@ -11,6 +11,7 @@ use crate::snippet_bencher::write_benchmarks; use crate::snippet_bencher::BenchmarkCase; use crate::snippet_bencher::NamedBenchmarkResult; use crate::test_helpers::test_rust_equivalence_given_complete_state; +use crate::InitVmState; use crate::VmHasher; use super::basic_snippet::BasicSnippet; @@ -55,6 +56,17 @@ pub struct FunctionInitialState { pub memory: HashMap, } +impl From for InitVmState { + fn from(value: FunctionInitialState) -> Self { + let nd = NonDeterminism::default().with_ram(value.memory); + Self { + stack: value.stack, + nondeterminism: nd, + ..Default::default() + } + } +} + pub struct ShadowedFunction { pub function: Rc>, }