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 exec_caller #386

Merged
merged 6 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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