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 @@ -190,4 +190,25 @@ contract L2 is SignatureChecker {
190
190
191
191
batches[honestStartNonce].status = BatchStatus.Refunded;
192
192
}
193
+
194
+ function refund (uint256 index ) public {
195
+ require (
196
+ block .timestamp > tickets[index].timestamp + maxAuthDelay,
197
+ "maxAuthDelay must have passed since deposit "
198
+ );
199
+
200
+ require (
201
+ nextNonceToAuthorize <= index,
202
+ "The nonce must not be a part of a batch "
203
+ );
204
+ (Batch memory batch , ) = createBatch (nextNonceToAuthorize, index);
205
+ batches[nextNonceToAuthorize] = batch;
206
+ batch.status = BatchStatus.Refunded;
207
+ nextNonceToAuthorize = index + 1 ;
208
+
209
+ (bool sent , ) = tickets[index].l1Recipient.call {
210
+ value: tickets[index].value
211
+ }("" );
212
+ require (sent, "Failed to send Ether " );
213
+ }
193
214
}
Original file line number Diff line number Diff line change @@ -192,3 +192,21 @@ it("Able to prove fraud", async () => {
192
192
) ,
193
193
) ;
194
194
} ) ;
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