Skip to content

Commit

Permalink
Contract calls (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
xermicus authored Jun 1, 2024
1 parent 532721f commit 1ba806b
Show file tree
Hide file tree
Showing 27 changed files with 541 additions and 930 deletions.
50 changes: 25 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions crates/integration/contracts/Call.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8;

contract Call {
function value_transfer(address payable destination) public payable {
destination.transfer(msg.value);
}

function echo(bytes memory payload) public pure returns (bytes memory) {
return payload;
}

function call(
address callee,
bytes memory payload
) public pure returns (bytes memory) {
return Call(callee).echo(payload);
}
}
49 changes: 49 additions & 0 deletions crates/integration/src/cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,19 @@ sol!(
}
);

sol!(
contract Call {
function value_transfer(address payable destination) public payable;

function echo(bytes memory payload) public payable returns (bytes memory);

function call(
address callee,
bytes memory payload
) public payable returns (bytes memory);
}
);

impl Contract {
/// Execute the contract.
///
Expand Down Expand Up @@ -441,6 +454,42 @@ impl Contract {
calldata: MCopy::memcpyCall::new((payload,)).abi_encode(),
}
}

pub fn call_value_transfer(destination: Address) -> Self {
let code = include_str!("../contracts/Call.sol");
let name = "Call";

Self {
name,
evm_runtime: crate::compile_evm_bin_runtime(name, code),
pvm_runtime: crate::compile_blob(name, code),
calldata: Call::value_transferCall::new((destination,)).abi_encode(),
}
}

pub fn call_call(callee: Address, payload: Vec<u8>) -> Self {
let code = include_str!("../contracts/Call.sol");
let name = "Call";

Self {
name,
evm_runtime: crate::compile_evm_bin_runtime(name, code),
pvm_runtime: crate::compile_blob(name, code),
calldata: Call::callCall::new((callee, payload)).abi_encode(),
}
}

pub fn call_constructor() -> Self {
let code = include_str!("../contracts/Call.sol");
let name = "Call";

Self {
name,
evm_runtime: crate::compile_evm_bin_runtime(name, code),
pvm_runtime: crate::compile_blob(name, code),
calldata: Default::default(),
}
}
}

#[cfg(test)]
Expand Down
Loading

0 comments on commit 1ba806b

Please sign in to comment.