From a0e10761f5d0b8894a1a359cdde9096176a282da Mon Sep 17 00:00:00 2001 From: Bobbin Threadbare Date: Wed, 2 Oct 2024 22:49:14 -0700 Subject: [PATCH] refactor: rename felt_array_to_ints into() felt_slice_to_ints() --- stdlib/tests/collections/mmr.rs | 12 ++++++------ stdlib/tests/mem/mod.rs | 12 ++++++------ test-utils/src/lib.rs | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/stdlib/tests/collections/mmr.rs b/stdlib/tests/collections/mmr.rs index 4c3f7b3ba..4f514eee3 100644 --- a/stdlib/tests/collections/mmr.rs +++ b/stdlib/tests/collections/mmr.rs @@ -3,7 +3,7 @@ use test_utils::{ init_merkle_leaf, init_merkle_leaves, MerkleError, MerkleStore, MerkleTree, Mmr, NodeIndex, RpoDigest, }, - felt_array_to_ints, hash_elements, Felt, StarkField, Word, EMPTY_WORD, ONE, ZERO, + felt_slice_to_ints, hash_elements, Felt, StarkField, Word, EMPTY_WORD, ONE, ZERO, }; // TESTS @@ -259,7 +259,7 @@ fn test_mmr_unpack() { let hash = hash_elements(&hash_data.concat()); // Set up the VM stack with the MMR hash, and its target address - let mut stack = felt_array_to_ints(&*hash); + let mut stack = felt_slice_to_ints(&*hash); let mmr_ptr = 1000_u32; stack.insert(0, mmr_ptr as u64); @@ -321,7 +321,7 @@ fn test_mmr_unpack_invalid_hash() { let hash = hash_elements(&hash_data.concat()); // Set up the VM stack with the MMR hash, and its target address - let mut stack = felt_array_to_ints(&*hash); + let mut stack = felt_slice_to_ints(&*hash); let mmr_ptr = 1000; stack.insert(0, mmr_ptr); @@ -383,7 +383,7 @@ fn test_mmr_unpack_large_mmr() { let hash = hash_elements(&hash_data.concat()); // Set up the VM stack with the MMR hash, and its target address - let mut stack = felt_array_to_ints(&*hash); + let mut stack = felt_slice_to_ints(&*hash); let mmr_ptr = 1000_u32; stack.insert(0, mmr_ptr as u64); @@ -443,7 +443,7 @@ fn test_mmr_pack_roundtrip() { let hash = accumulator.hash_peaks(); // Set up the VM stack with the MMR hash, and its target address - let mut stack = felt_array_to_ints(&*hash); + let mut stack = felt_slice_to_ints(&*hash); let mmr_ptr = 1000; stack.insert(0, mmr_ptr); // first value is used by unpack, to load data to memory stack.insert(0, mmr_ptr); // second is used by pack, to load data from memory @@ -648,7 +648,7 @@ fn test_mmr_large_add_roundtrip() { let hash = old_accumulator.hash_peaks(); // Set up the VM stack with the MMR hash, and its target address - let mut stack = felt_array_to_ints(&*hash); + let mut stack = felt_slice_to_ints(&*hash); stack.insert(0, mmr_ptr as u64); // both the advice stack and merkle store start empty (data is available in diff --git a/stdlib/tests/mem/mod.rs b/stdlib/tests/mem/mod.rs index 97d5cee65..0d32c1a8c 100644 --- a/stdlib/tests/mem/mod.rs +++ b/stdlib/tests/mem/mod.rs @@ -1,6 +1,6 @@ use processor::{ContextId, DefaultHost, ProcessState, Program}; use test_utils::{ - build_expected_hash, build_expected_perm, felt_array_to_ints, ExecutionOptions, Process, + build_expected_hash, build_expected_perm, felt_slice_to_ints, ExecutionOptions, Process, StackInputs, ONE, ZERO, }; @@ -117,7 +117,7 @@ fn test_pipe_double_words_to_memory() { let operand_stack = &[]; let data = &[1, 2, 3, 4, 5, 6, 7, 8]; let mut expected_stack = - felt_array_to_ints(&build_expected_perm(&[0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8])); + felt_slice_to_ints(&build_expected_perm(&[0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8])); expected_stack.push(1002); build_test!(source, operand_stack, &data).expect_stack_and_memory( &expected_stack, @@ -144,7 +144,7 @@ fn test_pipe_words_to_memory() { let operand_stack = &[]; let data = &[1, 2, 3, 4]; - let mut expected_stack = felt_array_to_ints(&build_expected_hash(data)); + let mut expected_stack = felt_slice_to_ints(&build_expected_hash(data)); expected_stack.push(1001); build_test!(one_word, operand_stack, &data).expect_stack_and_memory( &expected_stack, @@ -167,7 +167,7 @@ fn test_pipe_words_to_memory() { let operand_stack = &[]; let data = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]; - let mut expected_stack = felt_array_to_ints(&build_expected_hash(data)); + let mut expected_stack = felt_slice_to_ints(&build_expected_hash(data)); expected_stack.push(1003); build_test!(three_words, operand_stack, &data).expect_stack_and_memory( &expected_stack, @@ -195,7 +195,7 @@ fn test_pipe_preimage_to_memory() { let operand_stack = &[]; let data = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]; - let mut advice_stack = felt_array_to_ints(&build_expected_hash(data)); + let mut advice_stack = felt_slice_to_ints(&build_expected_hash(data)); advice_stack.reverse(); advice_stack.extend(data); build_test!(three_words, operand_stack, &advice_stack).expect_stack_and_memory( @@ -221,7 +221,7 @@ fn test_pipe_preimage_to_memory_invalid_preimage() { let operand_stack = &[]; let data = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]; - let mut advice_stack = felt_array_to_ints(&build_expected_hash(data)); + let mut advice_stack = felt_slice_to_ints(&build_expected_hash(data)); advice_stack.reverse(); advice_stack[0] += 1; // corrupt the expected hash advice_stack.extend(data); diff --git a/test-utils/src/lib.rs b/test-utils/src/lib.rs index 1751f4f2e..e6b5aa397 100644 --- a/test-utils/src/lib.rs +++ b/test-utils/src/lib.rs @@ -262,7 +262,7 @@ impl Test { let mem_state = process.get_mem_value(ContextId::root(), mem_start_addr).unwrap_or(EMPTY_WORD); - let mem_state = felt_array_to_ints(&mem_state); + let mem_state = felt_slice_to_ints(&mem_state); assert_eq!( data, mem_state, "Expected memory [{}] => {:?}, found {:?}", @@ -423,8 +423,8 @@ impl Test { // HELPER FUNCTIONS // ================================================================================================ -/// Converts an array of Felts into u64 -pub fn felt_array_to_ints(values: &[Felt]) -> Vec { +/// Converts a slice of Felts into a vector of u64 values. +pub fn felt_slice_to_ints(values: &[Felt]) -> Vec { values.iter().map(|e| (*e).as_int()).collect() }