Skip to content

Commit

Permalink
feat: add support for value transfer (#1)
Browse files Browse the repository at this point in the history
Adds an extra parameter for non-zero value transfer.
  • Loading branch information
smartcontracts authored May 24, 2022
1 parent 5982c8e commit 4fcdfd3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "/Users/james/devel/ExcessivelySafeCall/lib/ds-test"]
[submodule "lib/ds-test"]
path = lib/ds-test
url = https://github.com/dapphub/ds-test
2 changes: 1 addition & 1 deletion lib/ds-test
Submodule ds-test updated 2 files
+21 −22 demo/demo.sol
+42 −7 src/test.sol
4 changes: 3 additions & 1 deletion src/ExcessivelySafeCall.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ library ExcessivelySafeCall {
/// to memory.
/// @param _target The address to call
/// @param _gas The amount of gas to forward to the remote contract
/// @param _value The value in wei to send to the remote contract
/// @param _maxCopy The maximum number of bytes of returndata to copy
/// to memory.
/// @param _calldata The data to send to the remote contract
Expand All @@ -23,6 +24,7 @@ library ExcessivelySafeCall {
function excessivelySafeCall(
address _target,
uint256 _gas,
uint256 _value,
uint16 _maxCopy,
bytes memory _calldata
) internal returns (bool, bytes memory) {
Expand All @@ -38,7 +40,7 @@ library ExcessivelySafeCall {
_success := call(
_gas, // gas
_target, // recipient
0, // ether value
_value, // ether value
add(_calldata, 0x20), // inloc
mload(_calldata), // inlen
0, // outloc
Expand Down
21 changes: 21 additions & 0 deletions src/test/ExcessivelySafeCall.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ contract ContractTest is DSTest {
(_success, _ret) = target.excessivelySafeCall(
100_000,
0,
0,
abi.encodeWithSelector(CallTarget.one.selector)
);
assertTrue(_success);
Expand All @@ -37,6 +38,7 @@ contract ContractTest is DSTest {
(_success, _ret) = target.excessivelySafeCall(
100_000,
0,
0,
abi.encodeWithSelector(CallTarget.two.selector)
);
assertTrue(_success);
Expand All @@ -46,11 +48,22 @@ contract ContractTest is DSTest {
(_success, _ret) = target.excessivelySafeCall(
100_000,
0,
0,
abi.encodeWithSelector(CallTarget.any.selector, 5)
);
assertTrue(_success);
assertEq(_ret.length, 0);
assertEq(t.called(), 5);

(_success, _ret) = target.excessivelySafeCall(
100_000,
69,
0,
abi.encodeWithSelector(CallTarget.payme.selector)
);
assertTrue(_success);
assertEq(_ret.length, 0);
assertEq(t.called(), 69);
}

function testStaticCall() public {
Expand All @@ -74,6 +87,7 @@ contract ContractTest is DSTest {

(_success, _ret) = target.excessivelySafeCall(
100_000,
0,
_maxCopy,
abi.encodeWithSelector(CallTarget.retBytes.selector, uint256(_requested))
);
Expand All @@ -82,6 +96,7 @@ contract ContractTest is DSTest {

(_success, _ret) = target.excessivelySafeCall(
100_000,
0,
_maxCopy,
abi.encodeWithSelector(CallTarget.revBytes.selector, uint256(_requested))
);
Expand Down Expand Up @@ -119,6 +134,7 @@ contract ContractTest is DSTest {

(_success, _ret) = target.excessivelySafeCall(
3_000_000,
0,
32,
abi.encodeWithSelector(CallTarget.badRet.selector)
);
Expand All @@ -129,6 +145,7 @@ contract ContractTest is DSTest {

(_success, _ret) = target.excessivelySafeCall(
3_000_000,
0,
32,
abi.encodeWithSelector(CallTarget.badRev.selector)
);
Expand Down Expand Up @@ -179,6 +196,10 @@ contract CallTarget {
called = _num;
}

function payme() external payable {
called = msg.value;
}

function retBytes(uint256 _bytes) public view {
assembly {
return(0, _bytes)
Expand Down

0 comments on commit 4fcdfd3

Please sign in to comment.