Skip to content

Commit

Permalink
test: add missing test EIP-1706
Browse files Browse the repository at this point in the history
  • Loading branch information
obatirou authored and enitrat committed Aug 27, 2024
1 parent 4e29cc6 commit 79b71d5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
23 changes: 19 additions & 4 deletions crates/evm/src/instructions/memory_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -893,11 +893,9 @@ mod tests {


#[test]
fn test_exec_sstore_static_call() {
fn test_exec_sstore_should_fail_static_call() {
// Given
let (_, kakarot_core) = setup_contracts_for_testing();
let mut vm = VMBuilderTrait::new_with_presets().with_read_only().build();
deploy_contract_account(kakarot_core, vm.message().target.evm, [].span());
let key: u256 = 0x100000000000000000000000000000001;
let value: u256 = 0xABDE1E11A5;
vm.stack.push(value).expect('push failed');
Expand All @@ -908,7 +906,24 @@ mod tests {

// Then
assert(result.is_err(), 'should have errored');
assert(result.unwrap_err() == EVMError::WriteInStaticContext, 'wrong error variant');
assert(result.unwrap_err() == EVMError::WriteInStaticContext, 'wrong error returned');
}

#[test]
fn test_exec_sstore_should_fail_gas_left_inf_call_stipend_eip_1706() {
// Given
let mut vm = VMBuilderTrait::new_with_presets().with_gas_left(gas::CALL_STIPEND).build();
let key: u256 = 0x100000000000000000000000000000001;
let value: u256 = 0xABDE1E11A5;
vm.stack.push(value).expect('push failed');
vm.stack.push(key).expect('push failed');

// When
let result = vm.exec_sstore();

// Then
assert(result.is_err(), 'should have errored');
assert(result.unwrap_err() == EVMError::OutOfGas, 'wrong error returned');
}

#[test]
Expand Down
5 changes: 5 additions & 0 deletions crates/evm/src/test_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ impl VMBuilderImpl of VMBuilderTrait {
self.vm.valid_jumpdests = AccountTrait::get_jumpdests(self.vm.message.code);
return self.vm;
}

fn with_gas_left(mut self: VMBuilder, gas_left: u128) -> VMBuilder {
self.vm.gas_left = gas_left;
self
}
}

fn origin() -> EthAddress {
Expand Down

0 comments on commit 79b71d5

Please sign in to comment.