Skip to content

Commit

Permalink
Refactoring call_data -> calldata
Browse files Browse the repository at this point in the history
  • Loading branch information
khaeljy committed Sep 4, 2023
1 parent 2c13db8 commit 7595f59
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions crates/evm/src/instructions/environmental_information.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ impl EnvironmentInformationImpl of EnvironmentInformationTrait {
let offset: u32 = Into::<u256, Result<u32, EVMError>>::into((*popped[1]))?;
let size: u32 = Into::<u256, Result<u32, EVMError>>::into((*popped[2]))?;

let call_data: Span<u8> = self.call_context().call_data();
let calldata: Span<u8> = self.call_context().call_data();

let slice_size = if (offset + size > call_data.len()) {
call_data.len() - offset
let slice_size = if (offset + size > calldata.len()) {
calldata.len() - offset
} else {
size
};

let data_to_copy: Span<u8> = call_data.slice(offset, slice_size);
let data_to_copy: Span<u8> = calldata.slice(offset, slice_size);
self.memory.store_n(data_to_copy, dest_offset);

// For out of bound bytes, 0s will be copied.
Expand Down
6 changes: 3 additions & 3 deletions crates/evm/src/tests/test_execution_context.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ fn no_op() {}
fn test_call_context_new() {
// When
let bytecode: Span<u8> = array![1, 2, 3].span();
let call_data: Span<u8> = array![4, 5, 6].span();
let calldata: Span<u8> = array![4, 5, 6].span();
let value: u256 = callvalue();

let call_ctx = CallContextTrait::new(bytecode, call_data, value);
let call_ctx = CallContextTrait::new(bytecode, calldata, value);
// TODO remove once no longer required (see https://github.com/starkware-libs/cairo/issues/3863)
no_op();

// Then
assert(call_ctx.bytecode() == bytecode, 'wrong bytecode');
assert(call_ctx.call_data() == call_data, 'wrong call_data');
assert(call_ctx.call_data() == calldata, 'wrong calldata');
assert(call_ctx.value() == callvalue(), 'wrong value');
}

Expand Down
8 changes: 4 additions & 4 deletions crates/evm/src/tests/test_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ fn callvalue() -> u256 {

fn setup_call_context() -> CallContext {
let bytecode: Span<u8> = array![1, 2, 3].span();
let call_data: Span<u8> = array![4, 5, 6].span();
let calldata: Span<u8> = array![4, 5, 6].span();
let value: u256 = callvalue();

CallContextTrait::new(bytecode, call_data, value)
CallContextTrait::new(bytecode, calldata, value)
}

fn setup_execution_context() -> ExecutionContext {
Expand All @@ -43,10 +43,10 @@ fn setup_execution_context() -> ExecutionContext {
}

fn setup_call_context_with_bytecode(bytecode: Span<u8>) -> CallContext {
let call_data: Span<u8> = array![4, 5, 6].span();
let calldata: Span<u8> = array![4, 5, 6].span();
let value: u256 = 100;

CallContextTrait::new(bytecode, call_data, value)
CallContextTrait::new(bytecode, calldata, value)
}

fn setup_execution_context_with_bytecode(bytecode: Span<u8>) -> ExecutionContext {
Expand Down

0 comments on commit 7595f59

Please sign in to comment.