@@ -67,6 +67,7 @@ describe('TokenPaymaster', function () {
6767 let factory : SimpleAccountFactory
6868 let paymasterAddress : string
6969 let paymaster : TokenPaymaster
70+ let paymasterOwner : string
7071 let callData : string
7172 let token : TestERC20
7273 let weth : TestWrappedNativeToken
@@ -88,7 +89,7 @@ describe('TokenPaymaster', function () {
8889 tokenOracle = await new TestOracle2__factory ( ethersSigner ) . deploy ( initialPriceToken , 8 )
8990 await weth . deposit ( { value : parseEther ( '1' ) } )
9091 await weth . transfer ( testUniswap . address , parseEther ( '1' ) )
91- const owner = await ethersSigner . getAddress ( )
92+ paymasterOwner = await ethersSigner . getAddress ( )
9293 const tokenPaymasterConfig : TokenPaymaster . TokenPaymasterConfigStruct = {
9394 priceMaxAge : 86400 ,
9495 refundPostopCost : 40000 ,
@@ -120,7 +121,7 @@ describe('TokenPaymaster', function () {
120121 tokenPaymasterConfig ,
121122 oracleHelperConfig ,
122123 uniswapHelperConfig ,
123- owner
124+ paymasterOwner
124125 )
125126 paymasterAddress = paymaster . address
126127
@@ -132,6 +133,25 @@ describe('TokenPaymaster', function () {
132133 callData = await account . populateTransaction . execute ( accountOwner . address , 0 , '0x' ) . then ( tx => tx . data ! )
133134 } )
134135
136+ it ( 'Only owner should withdraw eth from paymaster to destination' , async function ( ) {
137+ const recipient = accountOwner . address
138+ const amount = 2e18 . toString ( )
139+ const balanceBefore = await ethers . provider . getBalance ( paymasterAddress )
140+ await fund ( paymasterAddress , '2' )
141+ const balanceAfter = await ethers . provider . getBalance ( paymasterAddress )
142+ assert . equal ( balanceBefore . add ( BigNumber . from ( amount ) ) . toString ( ) , balanceAfter . toString ( ) )
143+
144+ const impersonatedSigner = await ethers . getImpersonatedSigner ( '0x1234567890123456789012345678901234567890' )
145+ const paymasterDifferentSigner = TokenPaymaster__factory . connect ( paymasterAddress , impersonatedSigner )
146+
147+ await expect ( paymasterDifferentSigner . withdrawEth ( paymasterOwner , amount ) ) . to . be . revertedWith ( 'OwnableUnauthorizedAccount' )
148+
149+ const recipientBalanceBefore = await ethers . provider . getBalance ( recipient )
150+ await paymaster . withdrawEth ( recipient , balanceAfter )
151+ const recipientBalanceAfter = await ethers . provider . getBalance ( recipient )
152+ assert . equal ( recipientBalanceBefore . add ( BigNumber . from ( amount ) ) . toString ( ) , recipientBalanceAfter . toString ( ) )
153+ } )
154+
135155 it ( 'paymaster should reject if account does not have enough tokens or allowance' , async ( ) => {
136156 const snapshot = await ethers . provider . send ( 'evm_snapshot' , [ ] )
137157 let op = await fillUserOp ( {
0 commit comments