@@ -18,6 +18,10 @@ describe("GnosisSafe", async () => {
1818 function sendEth(address payable safe) public payable returns (bool success) {
1919 require(safe.send(msg.value));
2020 }
21+ function callEth(address payable safe) public payable returns (bool success) {
22+ (bool success,) = safe.call{ value: msg.value }("");
23+ require(success);
24+ }
2125 }`
2226 return {
2327 safe : await getSafeWithOwners ( [ user1 . address ] ) ,
@@ -30,23 +34,45 @@ describe("GnosisSafe", async () => {
3034 it ( 'should be able to receive ETH via transfer' , async ( ) => {
3135 const { safe, caller } = await setupTests ( )
3236 // Notes: It is not possible to load storage + a call + emit event with 2300 gas
33- // Test Validator
34- await caller . transferEth ( safe . address , { value : parseEther ( "1" ) } )
35- await expect ( await hre . ethers . provider . getBalance ( safe . address ) ) . to . be . deep . eq ( parseEther ( "1" ) )
37+ await expect (
38+ caller . transferEth ( safe . address , { value : parseEther ( "1" ) } )
39+ ) . to . be . reverted
3640 } )
3741
3842 it ( 'should be able to receive ETH via send' , async ( ) => {
3943 const { safe, caller } = await setupTests ( )
4044 // Notes: It is not possible to load storage + a call + emit event with 2300 gas
41- // Test Validator
42- await caller . sendEth ( safe . address , { value : parseEther ( "1" ) } )
45+ await expect (
46+ caller . sendEth ( safe . address , { value : parseEther ( "1" ) } )
47+ ) . to . be . reverted
48+ } )
49+
50+ it ( 'should be able to receive ETH via call' , async ( ) => {
51+ const { safe, caller } = await setupTests ( )
52+ await expect (
53+ caller . callEth ( safe . address , {
54+ value : parseEther ( "1" )
55+ } )
56+ ) . to . emit ( safe , "SafeReceived" ) . withArgs ( caller . address , parseEther ( "1" ) )
57+ await expect ( await hre . ethers . provider . getBalance ( safe . address ) ) . to . be . deep . eq ( parseEther ( "1" ) )
58+ } )
59+
60+
61+ it ( 'should be able to receive ETH via transaction' , async ( ) => {
62+ const { safe } = await setupTests ( )
63+ await expect (
64+ user1 . sendTransaction ( {
65+ to : safe . address ,
66+ value : parseEther ( "1" )
67+ } )
68+ ) . to . emit ( safe , "SafeReceived" ) . withArgs ( user1 . address , parseEther ( "1" ) )
4369 await expect ( await hre . ethers . provider . getBalance ( safe . address ) ) . to . be . deep . eq ( parseEther ( "1" ) )
4470 } )
4571
4672 it ( 'should throw for incoming eth with data' , async ( ) => {
4773 const { safe } = await setupTests ( )
4874 await expect (
49- user1 . sendTransaction ( { to : safe . address , value : 23 , data : "0xbaddad" } )
75+ user1 . sendTransaction ( { to : safe . address , value : 23 , data : "0xbaddad" } )
5076 ) . to . be . revertedWith ( "fallback function is not payable and was called with value 23" )
5177 } )
5278 } )
0 commit comments