@@ -237,7 +237,7 @@ describe('GovernanceOApp Test', function () {
237237 expect ( BigInt ( await gatewayConfigMockBis . value ( ) ) ) . to . equal ( 2n )
238238 } )
239239
240- it ( 'owner can wihdraw ETH from prefunded governanceOAppSender ' , async function ( ) {
240+ it ( 'owner can wihdraw ETH from prefunded GovernanceOAppSender ' , async function ( ) {
241241 await owner . sendTransaction ( {
242242 to : governanceOAppSender . address ,
243243 value : ethers . utils . parseEther ( '1' ) ,
@@ -259,7 +259,7 @@ describe('GovernanceOApp Test', function () {
259259 expect ( diff <= tolerance ) . to . equal ( true )
260260 } )
261261
262- it ( 'should not send recovered funds to null address' , async function ( ) {
262+ it ( 'should not send recovered funds from GovernanceOAppSender to null address' , async function ( ) {
263263 await owner . sendTransaction ( {
264264 to : governanceOAppSender . address ,
265265 value : ethers . utils . parseEther ( '1' ) ,
@@ -278,6 +278,49 @@ describe('GovernanceOApp Test', function () {
278278 }
279279 } )
280280
281+ it ( 'owner can wihdraw ETH from prefunded GovernanceOAppReceiver' , async function ( ) {
282+ await ethers . provider . send ( 'hardhat_setBalance' , [
283+ // on a real network, funds could be sent to GovernanceOAppReceiver contract via the payable lzReceive method
284+ governanceOAppReceiver . address ,
285+ '0xde0b6b3a7640000' , // 1 ETH in hex
286+ ] )
287+
288+ const balanceOwnerBefore = await ethers . provider . getBalance ( owner . address )
289+ const balanceGovReceiverBefore = await ethers . provider . getBalance ( governanceOAppReceiver . address )
290+ expect ( balanceGovReceiverBefore . toBigInt ( ) ) . to . equal ( ethers . utils . parseEther ( '1' ) . toBigInt ( ) )
291+
292+ await governanceOAppReceiver . withdrawETH ( ethers . utils . parseEther ( '1' ) , owner . address )
293+
294+ const balanceOwnerAfter = await ethers . provider . getBalance ( owner . address )
295+ const balanceGovReceiverAfter = await ethers . provider . getBalance ( governanceOAppReceiver . address )
296+ expect ( balanceGovReceiverAfter . toBigInt ( ) ) . to . equal ( 0n )
297+ const received = balanceOwnerAfter . sub ( balanceOwnerBefore ) . toBigInt ( )
298+ const expected = ethers . utils . parseEther ( '1' ) . toBigInt ( )
299+ const tolerance = ethers . utils . parseEther ( '0.0001' ) . toBigInt ( ) // account gas used for the tx
300+ const diff = received > expected ? received - expected : expected - received
301+ expect ( diff <= tolerance ) . to . equal ( true )
302+ } )
303+
304+ it ( 'should not send recovered funds from GovernanceOAppReceiver to null address' , async function ( ) {
305+ await ethers . provider . send ( 'hardhat_setBalance' , [
306+ // on a real network, funds could be sent to GovernanceOAppReceiver contract via the payable lzReceive method
307+ governanceOAppReceiver . address ,
308+ '0xde0b6b3a7640000' , // 1 ETH in hex
309+ ] )
310+ const tx = governanceOAppReceiver
311+ . connect ( owner )
312+ . withdrawETH ( ethers . utils . parseEther ( '1' ) , ethers . constants . AddressZero )
313+ try {
314+ await tx
315+ expect . fail ( 'withdrawETH should have reverted with InvalidNullRecipient' )
316+ } catch ( err : any ) {
317+ const data = err . data
318+ const selector = data . slice ( 0 , 10 )
319+ const expected = governanceOAppReceiver . interface . getSighash ( 'InvalidNullRecipient()' )
320+ expect ( selector ) . to . equal ( expected )
321+ }
322+ } )
323+
281324 it ( 'should send a payable remote proposal' , async function ( ) {
282325 expect ( BigInt ( await gatewayConfigMock . value ( ) ) ) . to . equal ( 0n )
283326 await owner . sendTransaction ( {
0 commit comments