@@ -210,9 +210,8 @@ apiServerSpec = do
210
210
getPendingDeposits = pure []
211
211
putClientInput = const (pure () )
212
212
getHeadState = pure inIdleState
213
- responseChannelSimple <- runIO newTChanIO
214
- responseChannel <- runIO newTChanIO
215
213
describe " GET /protocol-parameters" $ do
214
+ responseChannel <- runIO newTChanIO
216
215
with
217
216
( return $
218
217
httpApp @ SimpleTx
@@ -244,6 +243,7 @@ apiServerSpec = do
244
243
}
245
244
246
245
describe " GET /head" $ do
246
+ responseChannel <- runIO newTChanIO
247
247
prop " responds correctly" $ \ headState -> do
248
248
withApplication
249
249
( httpApp @ SimpleTx
@@ -261,6 +261,7 @@ apiServerSpec = do
261
261
$ do
262
262
get " /head"
263
263
`shouldRespondWith` 200 {matchBody = matchJSON headState}
264
+ responseChannelSimpleTx <- runIO newTChanIO
264
265
prop " ok response matches schema" $ \ headState -> do
265
266
let isIdle = case headState of
266
267
Idle {} -> True
@@ -292,7 +293,7 @@ apiServerSpec = do
292
293
getPendingDeposits
293
294
putClientInput
294
295
300
295
- responseChannelSimple
296
+ responseChannelSimpleTx
296
297
)
297
298
$ do
298
299
get " /head"
@@ -303,6 +304,7 @@ apiServerSpec = do
303
304
(key " channels" . key " /head" . key " subscribe" . key " message" )
304
305
}
305
306
describe " GET /snapshot/last-seen" $ do
307
+ responseChannel <- runIO newTChanIO
306
308
prop " responds correctly" $ \ headState -> do
307
309
let seenSnapshot :: SeenSnapshot SimpleTx = getSeenSnapshot headState
308
310
withApplication
@@ -322,6 +324,7 @@ apiServerSpec = do
322
324
get " /snapshot/last-seen"
323
325
`shouldRespondWith` 200 {matchBody = matchJSON seenSnapshot}
324
326
describe " GET /snapshot" $ do
327
+ responseChannel <- runIO newTChanIO
325
328
prop " responds correctly" $ \ headState -> do
326
329
let confirmedSnapshot :: Maybe (ConfirmedSnapshot SimpleTx ) = getConfirmedSnapshot headState
327
330
withApplication
@@ -342,7 +345,8 @@ apiServerSpec = do
342
345
`shouldRespondWith` case confirmedSnapshot of
343
346
Nothing -> 404
344
347
Just confirmedSn -> 200 {matchBody = matchJSON confirmedSn}
345
- prop " ok response matches schema" $ \ (closedState :: ClosedState tx ) ->
348
+ responseChannelSimpleTx <- runIO newTChanIO
349
+ prop " ok response matches schema" $ \ (closedState :: ClosedState tx ) -> do
346
350
withMaxSuccess 4
347
351
. withJsonSpecifications
348
352
$ \ schemaDir -> do
@@ -357,7 +361,7 @@ apiServerSpec = do
357
361
getPendingDeposits
358
362
putClientInput
359
363
300
360
- responseChannelSimple
364
+ responseChannelSimpleTx
361
365
)
362
366
$ do
363
367
get " /snapshot"
@@ -369,6 +373,7 @@ apiServerSpec = do
369
373
}
370
374
371
375
describe " POST /snapshot" $ do
376
+ responseChannel <- runIO newTChanIO
372
377
prop " responds on valid requests" $ \ (request :: SideLoadSnapshotRequest Tx , headState ) -> do
373
378
withMaxSuccess 10
374
379
. withApplication
@@ -382,13 +387,14 @@ apiServerSpec = do
382
387
getPendingDeposits
383
388
putClientInput
384
389
300
385
- responseChannelSimple
390
+ responseChannel
386
391
)
387
392
$ do
388
393
post " /snapshot" (Aeson. encode request)
389
394
`shouldRespondWith` 200
390
395
391
396
describe " GET /snapshot/utxo" $ do
397
+ responseChannel <- runIO newTChanIO
392
398
prop " responds correctly" $ \ headState -> do
393
399
let utxo :: Maybe (UTxOType SimpleTx ) = getSnapshotUtxo headState
394
400
withApplication
@@ -409,6 +415,7 @@ apiServerSpec = do
409
415
`shouldRespondWith` case utxo of
410
416
Nothing -> 404
411
417
Just u -> 200 {matchBody = matchJSON u}
418
+ responseChannelSimpleTx <- runIO newTChanIO
412
419
prop " ok response matches schema" $ \ headState -> do
413
420
let mUTxO = getSnapshotUtxo headState
414
421
utxo :: UTxOType Tx = fromMaybe mempty mUTxO
@@ -428,7 +435,7 @@ apiServerSpec = do
428
435
getPendingDeposits
429
436
putClientInput
430
437
300
431
- responseChannelSimple
438
+ responseChannelSimpleTx
432
439
)
433
440
$ do
434
441
get " /snapshot/utxo"
@@ -466,7 +473,7 @@ apiServerSpec = do
466
473
getPendingDeposits
467
474
putClientInput
468
475
300
469
- responseChannelSimple
476
+ responseChannelSimpleTx
470
477
)
471
478
$ do
472
479
get " /snapshot/utxo"
@@ -487,6 +494,7 @@ apiServerSpec = do
487
494
}
488
495
let initialHeadState = Initial (generateWith arbitrary 42 )
489
496
let openHeadState = Open (generateWith arbitrary 42 )
497
+ responseChannel <- runIO newTChanIO
490
498
prop " responds on valid requests" $ \ (request :: DraftCommitTxRequest Tx ) ->
491
499
withApplication
492
500
( httpApp
@@ -499,7 +507,7 @@ apiServerSpec = do
499
507
getPendingDeposits
500
508
putClientInput
501
509
300
502
- responseChannelSimple
510
+ responseChannel
503
511
)
504
512
$ do
505
513
post " /commit" (Aeson. encode request)
@@ -542,7 +550,7 @@ apiServerSpec = do
542
550
getPendingDeposits
543
551
putClientInput
544
552
300
545
- responseChannelSimple
553
+ responseChannel
546
554
)
547
555
$ do
548
556
post " /commit" (Aeson. encode (request :: DraftCommitTxRequest Tx ))
@@ -560,6 +568,7 @@ apiServerSpec = do
560
568
now <- runIO getCurrentTime
561
569
562
570
prop " returns 202 Accepted on timeout" $ do
571
+ responseChannel <- newTChanIO
563
572
withApplication
564
573
( httpApp @ SimpleTx
565
574
nullTracer
@@ -577,6 +586,7 @@ apiServerSpec = do
577
586
post " /transaction" (mkReq testTx) `shouldRespondWith` 202
578
587
579
588
prop " returns 200 OK on confirmed snapshot" $ do
589
+ responseChannel <- newTChanIO
580
590
let snapshot =
581
591
Snapshot
582
592
{ headId = testHeadId
@@ -593,7 +603,6 @@ apiServerSpec = do
593
603
, seq = 0
594
604
, time = now
595
605
}
596
- _ <- atomically $ writeTChan responseChannel (Left event)
597
606
withApplication
598
607
( httpApp @ SimpleTx
599
608
nullTracer
@@ -603,14 +612,15 @@ apiServerSpec = do
603
612
(pure inIdleState)
604
613
(pure CannotCommit )
605
614
(pure [] )
606
- (const $ pure ( ) )
615
+ (const $ atomically $ writeTChan responseChannel ( Left event ))
607
616
10
608
617
responseChannel
609
618
)
610
619
$ do
611
620
post " /transaction" (mkReq testTx) `shouldRespondWith` 200
612
621
613
622
prop " returns 400 Bad Request on invalid tx" $ do
623
+ responseChannel <- newTChanIO
614
624
let validationError = ValidationError " some error"
615
625
event =
616
626
TimedServerOutput
@@ -624,7 +634,6 @@ apiServerSpec = do
624
634
, seq = 0
625
635
, time = now
626
636
}
627
- _ <- atomically $ writeTChan responseChannel (Left event)
628
637
withApplication
629
638
( httpApp @ SimpleTx
630
639
nullTracer
@@ -634,7 +643,7 @@ apiServerSpec = do
634
643
(pure inIdleState)
635
644
(pure CannotCommit )
636
645
(pure [] )
637
- (const $ pure ( ) )
646
+ (const $ atomically $ writeTChan responseChannel ( Left event ))
638
647
10
639
648
responseChannel
640
649
)
0 commit comments