From dda248932844f4209b961f4380f050d1d0b1b8fa Mon Sep 17 00:00:00 2001 From: Paul Schoenfelder <955793+bitwalker@users.noreply.github.com> Date: Fri, 8 Mar 2024 20:03:59 -0500 Subject: [PATCH] fix: improve dynexec/procref test The previous version of this test started to fail because it assumed that it could blindly call u64::wrapping_add on a word representing the hash of a procedure. This is not actually safe, as there is no guarantee the hash will consist of 4 valid 32-bit limbs - and in fact that is what caused it to start to fail here - the procedure hash changed, was no longer valid for use as an operand to that function, and caused execution to trap deep in the VM. This commit changes the test to use actual checked operands, and adds a separate module into the mix to facilitate testing that procref/dynexec works across modules. --- miden/tests/integration/flow_control/mod.rs | 28 +++++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/miden/tests/integration/flow_control/mod.rs b/miden/tests/integration/flow_control/mod.rs index 8381cd79a4..55cb2ebbc8 100644 --- a/miden/tests/integration/flow_control/mod.rs +++ b/miden/tests/integration/flow_control/mod.rs @@ -281,9 +281,10 @@ fn simple_dyn_exec() { #[test] fn dynexec_with_procref() { let program_source = " - use.std::math::u64 + use.external::module proc.foo + dropw push.1.2 u32wrapping_add end @@ -292,22 +293,27 @@ fn dynexec_with_procref() { procref.foo dynexec - procref.u64::wrapping_add + procref.module::func dynexec + + dup + push.4 + assert_eq.err=101 end"; let mut test = build_test!(program_source, &[]); test.libraries = vec![StdLibrary::default().into()]; + test.add_module( + "external::module".parse().unwrap(), + "\ + export.func + dropw + u32wrapping_add.1 + end + ", + ); - test.expect_stack(&[ - 1719755471, - 1057995821, - 3, - 12973202366681443424, - 7933716460165146367, - 14382661273226268231, - 15818904913409383971, - ]); + test.expect_stack(&[4]); } #[test]