File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -189,4 +189,25 @@ contract L2 is SignatureChecker {
189189
190190 batches[honestStartNonce].status = BatchStatus.Refunded;
191191 }
192+
193+ function refund (uint256 index ) public {
194+ require (
195+ block .timestamp > tickets[index].timestamp + maxAuthDelay,
196+ "maxAuthDelay must have passed since deposit "
197+ );
198+
199+ require (
200+ nextNonceToAuthorize <= index,
201+ "The nonce must not be a part of a batch "
202+ );
203+ (Batch memory batch , ) = createBatch (nextNonceToAuthorize, index);
204+ batches[nextNonceToAuthorize] = batch;
205+ batch.status = BatchStatus.Refunded;
206+ nextNonceToAuthorize = index + 1 ;
207+
208+ (bool sent , ) = tickets[index].l1Recipient.call {
209+ value: tickets[index].value
210+ }("" );
211+ require (sent, "Failed to send Ether " );
212+ }
192213}
Original file line number Diff line number Diff line change @@ -192,3 +192,21 @@ it("Handles a fraud proofs", async () => {
192192 ) ,
193193 ) ;
194194} ) ;
195+
196+ it ( "Able to get a ticket refunded" , async ( ) => {
197+ await deposit ( 0 , 10 ) ;
198+ await expect ( customerL2 . refund ( 0 , { gasLimit } ) ) . to . be . rejectedWith (
199+ "maxAuthDelay must have passed since deposit" ,
200+ ) ;
201+ await ethers . provider . send ( "evm_increaseTime" , [ 61 ] ) ;
202+ await waitForTx ( customerL2 . refund ( 0 , { gasLimit } ) ) ;
203+ await waitForTx ( customerL2 . refund ( 1 , { gasLimit } ) ) ;
204+ await expect ( customerL2 . refund ( 1 , { gasLimit } ) ) . to . be . rejectedWith (
205+ "The nonce must not be a part of a batch" ,
206+ ) ;
207+
208+ await deposit ( 2 , 8 ) ;
209+ await ethers . provider . send ( "evm_increaseTime" , [ 61 ] ) ;
210+ // Refund 3rd and 4th deposit
211+ await waitForTx ( customerL2 . refund ( 2 , { gasLimit } ) ) ;
212+ } ) ;
You can’t perform that action at this time.
0 commit comments