@@ -168,8 +168,8 @@ pub mod tests {
168
168
use bcr_ebill_core:: {
169
169
ValidationError ,
170
170
bill:: {
171
- BillAcceptanceStatus , BillPaymentStatus , BillRecourseStatus , BillSellStatus ,
172
- PastPaymentStatus , RecourseReason ,
171
+ BillAcceptanceStatus , BillCurrentWaitingState , BillPaymentStatus , BillRecourseStatus ,
172
+ BillSellStatus , BillWaitingForPaymentState , PastPaymentStatus , RecourseReason ,
173
173
} ,
174
174
blockchain:: {
175
175
Blockchain ,
@@ -4233,6 +4233,14 @@ pub mod tests {
4233
4233
. check_requests_for_expiration( & bill_payment, 1731593928 )
4234
4234
. unwrap( )
4235
4235
) ;
4236
+ bill_payment. status . payment . request_to_pay_timed_out = true ;
4237
+ // if it already timed out, we don't need to check anymore
4238
+ assert ! (
4239
+ !service
4240
+ . check_requests_for_expiration( & bill_payment, 1731593928 )
4241
+ . unwrap( )
4242
+ ) ;
4243
+ bill_payment. status . payment . request_to_pay_timed_out = false ;
4236
4244
assert ! (
4237
4245
!service
4238
4246
. check_requests_for_expiration( & bill_payment, 1431593928 )
@@ -4244,10 +4252,37 @@ pub mod tests {
4244
4252
. check_requests_for_expiration( & bill_payment, 1531593929 )
4245
4253
. unwrap( )
4246
4254
) ;
4247
- // 2 days after req to pay, but not yet 2 days after end of day maturity date, req expired
4255
+ bill_payment. current_waiting_state = Some ( BillCurrentWaitingState :: Payment (
4256
+ BillWaitingForPaymentState {
4257
+ time_of_request : 1531593928 ,
4258
+ payer : empty_identity_public_data ( ) ,
4259
+ payee : empty_identity_public_data ( ) ,
4260
+ currency : "sat" . into ( ) ,
4261
+ sum : "10" . into ( ) ,
4262
+ link_to_pay : String :: default ( ) ,
4263
+ address_to_pay : String :: default ( ) ,
4264
+ mempool_link_for_address_to_pay : String :: default ( ) ,
4265
+ } ,
4266
+ ) ) ;
4267
+ // req to pay expired, but not yet 2 days after end of day maturity date
4268
+ // current waiting state set, so wasnt recalculated yet
4248
4269
assert ! (
4249
4270
service
4250
- . check_requests_for_expiration( & bill_payment, 1531780429 )
4271
+ . check_requests_for_expiration(
4272
+ & bill_payment,
4273
+ 1531593929 + PAYMENT_DEADLINE_SECONDS + 1
4274
+ )
4275
+ . unwrap( )
4276
+ ) ;
4277
+ bill_payment. current_waiting_state = None ;
4278
+ // req to pay expired, but not yet 2 days after end of day maturity date
4279
+ // but no current waiting state, so was already checked
4280
+ assert ! (
4281
+ !service
4282
+ . check_requests_for_expiration(
4283
+ & bill_payment,
4284
+ 1531593929 + PAYMENT_DEADLINE_SECONDS + 1
4285
+ )
4251
4286
. unwrap( )
4252
4287
) ;
4253
4288
// after req to pay, and after end of day maturity date, payment expired
@@ -4262,6 +4297,22 @@ pub mod tests {
4262
4297
. check_requests_for_expiration( & bill_payment, 1531593929 )
4263
4298
. unwrap( )
4264
4299
) ;
4300
+ bill_payment. status . payment . rejected_to_pay = true ;
4301
+ // already rejected, no need to check anymore
4302
+ assert ! (
4303
+ !service
4304
+ . check_requests_for_expiration( & bill_payment, 1831593928 )
4305
+ . unwrap( )
4306
+ ) ;
4307
+ bill_payment. status . payment . rejected_to_pay = false ;
4308
+ bill_payment. status . payment . paid = true ;
4309
+ // already paid, no need to check anymore
4310
+ assert ! (
4311
+ !service
4312
+ . check_requests_for_expiration( & bill_payment, 1831593928 )
4313
+ . unwrap( )
4314
+ ) ;
4315
+ bill_payment. status . payment . paid = false ;
4265
4316
4266
4317
let mut bill_acceptance = get_baseline_cached_bill ( TEST_BILL_ID . to_string ( ) ) ;
4267
4318
bill_acceptance. status . acceptance = BillAcceptanceStatus {
@@ -4277,6 +4328,36 @@ pub mod tests {
4277
4328
. check_requests_for_expiration( & bill_acceptance, 1731593928 )
4278
4329
. unwrap( )
4279
4330
) ;
4331
+ bill_acceptance
4332
+ . status
4333
+ . acceptance
4334
+ . request_to_accept_timed_out = true ;
4335
+ // already expired, no need to check anymore
4336
+ assert ! (
4337
+ !service
4338
+ . check_requests_for_expiration( & bill_acceptance, 1731593928 )
4339
+ . unwrap( )
4340
+ ) ;
4341
+ bill_acceptance
4342
+ . status
4343
+ . acceptance
4344
+ . request_to_accept_timed_out = false ;
4345
+ bill_acceptance. status . acceptance . rejected_to_accept = true ;
4346
+ // already rejected, no need to check anymore
4347
+ assert ! (
4348
+ !service
4349
+ . check_requests_for_expiration( & bill_acceptance, 1731593928 )
4350
+ . unwrap( )
4351
+ ) ;
4352
+ bill_acceptance. status . acceptance . rejected_to_accept = false ;
4353
+ bill_acceptance. status . acceptance . accepted = true ;
4354
+ // already accepted, no need to check anymore
4355
+ assert ! (
4356
+ !service
4357
+ . check_requests_for_expiration( & bill_acceptance, 1731593928 )
4358
+ . unwrap( )
4359
+ ) ;
4360
+ bill_acceptance. status . acceptance . accepted = false ;
4280
4361
4281
4362
let mut bill_sell = get_baseline_cached_bill ( TEST_BILL_ID . to_string ( ) ) ;
4282
4363
bill_sell. status . sell = BillSellStatus {
@@ -4293,6 +4374,31 @@ pub mod tests {
4293
4374
. unwrap( )
4294
4375
) ;
4295
4376
4377
+ bill_sell. status . sell . offer_to_sell_timed_out = true ;
4378
+ // already expired, no need to check anymore
4379
+ assert ! (
4380
+ !service
4381
+ . check_requests_for_expiration( & bill_sell, 1731593928 )
4382
+ . unwrap( )
4383
+ ) ;
4384
+ bill_sell. status . sell . offer_to_sell_timed_out = false ;
4385
+ bill_sell. status . sell . rejected_offer_to_sell = true ;
4386
+ // already rejected, no need to check anymore
4387
+ assert ! (
4388
+ !service
4389
+ . check_requests_for_expiration( & bill_sell, 1731593928 )
4390
+ . unwrap( )
4391
+ ) ;
4392
+ bill_sell. status . sell . rejected_offer_to_sell = false ;
4393
+ bill_sell. status . sell . sold = true ;
4394
+ // already sold, no need to check anymore
4395
+ assert ! (
4396
+ !service
4397
+ . check_requests_for_expiration( & bill_sell, 1731593928 )
4398
+ . unwrap( )
4399
+ ) ;
4400
+ bill_sell. status . sell . sold = false ;
4401
+
4296
4402
let mut bill_recourse = get_baseline_cached_bill ( TEST_BILL_ID . to_string ( ) ) ;
4297
4403
bill_recourse. status . recourse = BillRecourseStatus {
4298
4404
time_of_last_request_to_recourse : Some ( 1531593928 ) ,
@@ -4307,5 +4413,28 @@ pub mod tests {
4307
4413
. check_requests_for_expiration( & bill_recourse, 1731593928 )
4308
4414
. unwrap( )
4309
4415
) ;
4416
+ bill_recourse. status . recourse . request_to_recourse_timed_out = true ;
4417
+ // already expired, no need to check anymore
4418
+ assert ! (
4419
+ !service
4420
+ . check_requests_for_expiration( & bill_recourse, 1731593928 )
4421
+ . unwrap( )
4422
+ ) ;
4423
+ bill_recourse. status . recourse . rejected_request_to_recourse = true ;
4424
+ // already rejected, no need to check anymore
4425
+ assert ! (
4426
+ !service
4427
+ . check_requests_for_expiration( & bill_recourse, 1731593928 )
4428
+ . unwrap( )
4429
+ ) ;
4430
+ bill_recourse. status . recourse . rejected_request_to_recourse = false ;
4431
+ bill_recourse. status . recourse . recoursed = true ;
4432
+ // already recoursed, no need to check anymore
4433
+ assert ! (
4434
+ !service
4435
+ . check_requests_for_expiration( & bill_recourse, 1731593928 )
4436
+ . unwrap( )
4437
+ ) ;
4438
+ bill_recourse. status . recourse . recoursed = false ;
4310
4439
}
4311
4440
}
0 commit comments