Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement the test suite for MLOAD opcode #265

Closed
wants to merge 19 commits into from
Closed
2 changes: 1 addition & 1 deletion crates/evm/src/instructions/memory_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl MemoryOperation of MemoryOperationTrait {
/// MLOAD operation.
/// Load word from memory and push to stack.
fn exec_mload(ref self: ExecutionContext) -> Result<(), EVMError> {
Result::Ok(())
panic_with_felt252('MLOAD not implement yet')
khaeljy marked this conversation as resolved.
Show resolved Hide resolved
}

/// 0x52 - MSTORE operation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,44 @@ fn test_pc_gets_updated_properly_1() {
assert(ctx.stack.pop().unwrap() == 9000, 'updating PC failed');
}

// 0x51 - MLOAD

#[test]
#[available_gas(20000000000)]
#[should_panic(expected: ('MLOAD not implement yet',))]
fn test_exec_mload_should_load_a_value_from_memory() {
assert_mload(0x1, 0, 0x1, 32);
}

#[test]
#[available_gas(20000000000)]
#[should_panic(expected: ('MLOAD not implement yet',))]
fn test_exec_mload_should_load_a_value_from_memory_with_memory_expansion() {
assert_mload(0x1, 16, 0x100000000000000000000000000000000, 64);
}

#[test]
#[available_gas(20000000000)]
#[should_panic(expected: ('MLOAD not implement yet',))]
fn test_exec_mload_should_load_a_value_from_memory_with_offset_larger_than_msize() {
assert_mload(0x1, 684, 0x0, 736);
}

fn assert_mload(value: u256, offset: u256, expected_value: u256, expected_memory_size: u32) {
// Given
let mut ctx = setup_execution_context();
ctx.memory.store(value, 0);

ctx.stack.push(offset);

// When
ctx.exec_mload();

// Then
assert(ctx.stack.len() == 1, 'stack should have one element');
assert(ctx.stack.pop().unwrap() == expected_value, 'mload failed');
assert(ctx.memory.bytes_len == expected_memory_size, 'memory size error');
}

#[test]
#[available_gas(20000000)]
Expand Down
Loading