Skip to content

Commit

Permalink
feat: implement exec_caller (#386)
Browse files Browse the repository at this point in the history
* feat: implement exec_caller

* chore: fmt

* Update crates/evm/src/tests/test_instructions/test_comparison_operations.cairo

Co-authored-by: Mathieu <[email protected]>

* Update crates/evm/src/tests/test_stack.cairo

Co-authored-by: Mathieu <[email protected]>

* Update crates/evm/src/tests/test_stack.cairo

Co-authored-by: Mathieu <[email protected]>

* fix: fix commnets

---------

Co-authored-by: Mathieu <[email protected]>
  • Loading branch information
Eikix and enitrat authored Oct 4, 2023
1 parent 31195a2 commit b3b3725
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl EnvironmentInformationImpl of EnvironmentInformationTrait {
/// Get caller address.
/// # Specification: https://www.evm.codes/#33?fork=shanghai
fn exec_caller(ref self: Machine) -> Result<(), EVMError> {
Result::Ok(())
self.stack.push(self.caller().into())
}

/// 0x34 - CALLVALUE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,7 @@ fn assert_sar(a: u256, b: u256, expected: u256) {

#[test]
#[available_gas(20000000)]
fn test__exec_or__should_pop_0_and_1_and_push_0xCD__when_0_is_0x89_and_1_is_0xC5() {
fn test_exec_or_should_pop_0_and_1_and_push_0xCD_when_0_is_0x89_and_1_is_0xC5() {
//Given
let mut machine = setup_machine();
machine.stack.push(0x89);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,32 @@ fn test_address_nested_call() { // A (EOA) -(calls)-> B (smart contract) -(calls
// ref: https://github.com/kkrt-labs/kakarot-ssj/issues/183
}


// *************************************************************************
// 0x33: CALLER
// *************************************************************************
#[test]
#[available_gas(5000000)]
fn test_caller() {
// Given
let mut machine = setup_machine();

// When
machine.exec_caller();

// Then
assert(machine.stack.len() == 1, 'stack should have one element');
assert(machine.stack.peek().unwrap() == evm_address().into(), 'should be evm_address');
}


// *************************************************************************
// 0x34: CALLVALUE
// *************************************************************************

#[test]
#[available_gas(1200000)]
fn test__exec_callvalue() {
fn test_exec_callvalue() {
// Given
let mut machine = setup_machine();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn test_exec_sdiv_pos() {

#[test]
#[available_gas(20000000)]
fn test__exec_sdiv_neg() {
fn test_exec_sdiv_neg() {
// Given
let mut machine = setup_machine();
machine.stack.push(BoundedInt::max()).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/src/tests/test_stack.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn test_stack_new_should_return_empty_stack() {

#[test]
#[available_gas(400000)]
fn test__empty__should_return_if_stack_is_empty() {
fn test_empty_should_return_if_stack_is_empty() {
// Given
let mut stack = StackTrait::new();

Expand All @@ -31,7 +31,7 @@ fn test__empty__should_return_if_stack_is_empty() {

#[test]
#[available_gas(350000)]
fn test__len__should_return_the_length_of_the_stack() {
fn test_len_should_return_the_length_of_the_stack() {
// Given
let mut stack = StackTrait::new();

Expand Down

0 comments on commit b3b3725

Please sign in to comment.