From 4fcdfd3593d21381f696c790fa6180b8ef559c1e Mon Sep 17 00:00:00 2001 From: smartcontracts Date: Tue, 24 May 2022 15:41:06 -0700 Subject: [PATCH] feat: add support for value transfer (#1) Adds an extra parameter for non-zero value transfer. --- .gitmodules | 2 +- lib/ds-test | 2 +- src/ExcessivelySafeCall.sol | 4 +++- src/test/ExcessivelySafeCall.t.sol | 21 +++++++++++++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index a9ba7c0..e124719 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/lib/ds-test b/lib/ds-test index 0a5da56..9310e87 160000 --- a/lib/ds-test +++ b/lib/ds-test @@ -1 +1 @@ -Subproject commit 0a5da56b0d65960e6a994d2ec8245e6edd38c248 +Subproject commit 9310e879db8ba3ea6d5c6489a579118fd264a3f5 diff --git a/src/ExcessivelySafeCall.sol b/src/ExcessivelySafeCall.sol index c7c313a..eebf39c 100644 --- a/src/ExcessivelySafeCall.sol +++ b/src/ExcessivelySafeCall.sol @@ -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 @@ -23,6 +24,7 @@ library ExcessivelySafeCall { function excessivelySafeCall( address _target, uint256 _gas, + uint256 _value, uint16 _maxCopy, bytes memory _calldata ) internal returns (bool, bytes memory) { @@ -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 diff --git a/src/test/ExcessivelySafeCall.t.sol b/src/test/ExcessivelySafeCall.t.sol index 0236e6c..f925678 100644 --- a/src/test/ExcessivelySafeCall.t.sol +++ b/src/test/ExcessivelySafeCall.t.sol @@ -28,6 +28,7 @@ contract ContractTest is DSTest { (_success, _ret) = target.excessivelySafeCall( 100_000, 0, + 0, abi.encodeWithSelector(CallTarget.one.selector) ); assertTrue(_success); @@ -37,6 +38,7 @@ contract ContractTest is DSTest { (_success, _ret) = target.excessivelySafeCall( 100_000, 0, + 0, abi.encodeWithSelector(CallTarget.two.selector) ); assertTrue(_success); @@ -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 { @@ -74,6 +87,7 @@ contract ContractTest is DSTest { (_success, _ret) = target.excessivelySafeCall( 100_000, + 0, _maxCopy, abi.encodeWithSelector(CallTarget.retBytes.selector, uint256(_requested)) ); @@ -82,6 +96,7 @@ contract ContractTest is DSTest { (_success, _ret) = target.excessivelySafeCall( 100_000, + 0, _maxCopy, abi.encodeWithSelector(CallTarget.revBytes.selector, uint256(_requested)) ); @@ -119,6 +134,7 @@ contract ContractTest is DSTest { (_success, _ret) = target.excessivelySafeCall( 3_000_000, + 0, 32, abi.encodeWithSelector(CallTarget.badRet.selector) ); @@ -129,6 +145,7 @@ contract ContractTest is DSTest { (_success, _ret) = target.excessivelySafeCall( 3_000_000, + 0, 32, abi.encodeWithSelector(CallTarget.badRev.selector) ); @@ -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)