Skip to content

Commit

Permalink
clean up tests for MCOPY
Browse files Browse the repository at this point in the history
  • Loading branch information
snissn committed Aug 14, 2024
1 parent 09bfaec commit 8ff4c5f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions actors/evm/src/interpreter/instructions/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ pub fn mcopy(
let memory_slice = state.memory[region.offset..region.offset + region.size.get()].to_vec();

// expand memory to match dest_index + size
let _destination_region = get_memory_region(&mut state.memory, dest_index, size)?.expect("empty region");
let _destination_region =
get_memory_region(&mut state.memory, dest_index, size)?.expect("empty region");

//copy
copy_to_memory(&mut state.memory, dest_index, size, U256::zero(), &memory_slice, true)
Expand Down Expand Up @@ -397,7 +398,8 @@ mod tests {
assert_eq!(m.state.memory.len(), 96);

// Check the memory contents
let mut expected = vec![0u8; 68];
let mut expected = vec![0u8; 96];
expected[..4].copy_from_slice(&[0x01, 0x02, 0x03, 0x04]);
expected[64..68].copy_from_slice(&[0x01, 0x02, 0x03, 0x04]);
assert_eq!(&*m.state.memory, &expected[..]);
};
Expand All @@ -415,17 +417,20 @@ mod tests {
m.state.memory[..28].copy_from_slice(&[0x01; 28]);

// Set up stack: Source partially out of range
m.state.stack.push(U256::from(8)).unwrap(); // length
m.state.stack.push(U256::from(10)).unwrap(); // length
m.state.stack.push(U256::from(24)).unwrap(); // source offset (partially out of range)
m.state.stack.push(U256::from(0)).unwrap(); // destination offset

// Execute and expect memory expansion
assert!(m.step().is_ok(), "execution step failed");
assert_eq!(m.state.stack.len(), 0);

// Check the length of the memory after the operation
assert_eq!(m.state.memory.len(), 32+EVM_WORD_SIZE); // Memory should remain at 32 bytes after the operation

// Check that memory was expanded correctly
let mut expected = vec![0u8; 32];
expected[..8].copy_from_slice(&[0x01; 8]);
let mut expected = vec![0x01; 4]; // First 4 bytes copied
expected.extend_from_slice(&[0x00; 4]); // Remaining 4 bytes unchanged
assert_eq!(&m.state.memory[..8], &expected[..8]);
};
}
Expand Down Expand Up @@ -453,6 +458,7 @@ mod tests {

// Check the memory contents
let mut expected = vec![0u8; 132];
expected[..4].copy_from_slice(&[0x01, 0x02, 0x03, 0x04]);
expected[128..132].copy_from_slice(&[0x01, 0x02, 0x03, 0x04]);
assert_eq!(&m.state.memory[0..132], &expected[0..132]);

Expand Down

0 comments on commit 8ff4c5f

Please sign in to comment.