@@ -1516,8 +1516,8 @@ canRecoverDeposit tracer workDir backend hydraScriptsTxId =
1516
1516
hydraTracer = contramap FromHydraNode tracer
1517
1517
1518
1518
-- | Open a single participant head, deposit, Close and then recover it.
1519
- canRecoverDepositWhenClosed :: ChainBackend backend => Tracer IO EndToEndLog -> FilePath -> backend -> [TxId ] -> IO ()
1520
- canRecoverDepositWhenClosed tracer workDir backend hydraScriptsTxId =
1519
+ canRecoverDepositInAnyState :: ChainBackend backend => Tracer IO EndToEndLog -> FilePath -> backend -> [TxId ] -> IO ()
1520
+ canRecoverDepositInAnyState tracer workDir backend hydraScriptsTxId =
1521
1521
(`finally` returnFundsToFaucet tracer backend Alice ) $ do
1522
1522
refuelIfNeeded tracer backend Alice 30_000_000
1523
1523
-- NOTE: Directly expire deposits
@@ -1541,60 +1541,150 @@ canRecoverDepositWhenClosed tracer workDir backend hydraScriptsTxId =
1541
1541
-- Get some L1 funds
1542
1542
(walletVk, walletSk) <- generate genKeyPair
1543
1543
let commitAmount = 5_000_000
1544
- commitUTxO <- seedFromFaucet backend walletVk commitAmount (contramap FromFaucet tracer)
1544
+ commitUTxO1 <- seedFromFaucet backend walletVk commitAmount (contramap FromFaucet tracer)
1545
+ commitUTxO2 <- seedFromFaucet backend walletVk commitAmount (contramap FromFaucet tracer)
1546
+ commitUTxO3 <- seedFromFaucet backend walletVk commitAmount (contramap FromFaucet tracer)
1545
1547
1546
1548
(balance <$> Backend. queryUTxOFor backend QueryTip walletVk)
1547
- `shouldReturn` lovelaceToValue commitAmount
1549
+ `shouldReturn` lovelaceToValue ( commitAmount * 3 )
1548
1550
1549
- depositTransaction <-
1551
+ -- Increment commit #1
1552
+ depositTransaction1 <-
1550
1553
parseUrlThrow (" POST " <> hydraNodeBaseUrl n1 <> " /commit" )
1551
- <&> setRequestBodyJSON commitUTxO
1554
+ <&> setRequestBodyJSON commitUTxO1
1552
1555
>>= httpJSON
1553
1556
<&> getResponseBody
1554
1557
1555
- let tx = signTx walletSk depositTransaction
1556
- Backend. submitTransaction backend tx
1558
+ let tx1 = signTx walletSk depositTransaction1
1559
+ Backend. submitTransaction backend tx1
1560
+
1561
+ deadline1 <- waitMatch 10 n1 $ \ v -> do
1562
+ guard $ v ^? key " tag" == Just " CommitRecorded"
1563
+ v ^? key " deadline" >>= parseMaybe parseJSON
1564
+
1565
+ (selectLovelace . balance <$> Backend. queryUTxOFor backend QueryTip walletVk)
1566
+ `shouldReturn` (commitAmount * 2 )
1567
+
1568
+ -- Increment commit #2
1569
+ depositTransaction2 <-
1570
+ parseUrlThrow (" POST " <> hydraNodeBaseUrl n1 <> " /commit" )
1571
+ <&> setRequestBodyJSON commitUTxO2
1572
+ >>= httpJSON
1573
+ <&> getResponseBody
1574
+
1575
+ let tx2 = signTx walletSk depositTransaction2
1576
+ Backend. submitTransaction backend tx2
1557
1577
1558
- deadline <- waitMatch 10 n1 $ \ v -> do
1578
+ deadline2 <- waitMatch 10 n1 $ \ v -> do
1579
+ guard $ v ^? key " tag" == Just " CommitRecorded"
1580
+ v ^? key " deadline" >>= parseMaybe parseJSON
1581
+
1582
+ (selectLovelace . balance <$> Backend. queryUTxOFor backend QueryTip walletVk)
1583
+ `shouldReturn` commitAmount
1584
+
1585
+ -- Increment commit #3
1586
+ depositTransaction3 <-
1587
+ parseUrlThrow (" POST " <> hydraNodeBaseUrl n1 <> " /commit" )
1588
+ <&> setRequestBodyJSON commitUTxO3
1589
+ >>= httpJSON
1590
+ <&> getResponseBody
1591
+
1592
+ let tx3 = signTx walletSk depositTransaction3
1593
+ Backend. submitTransaction backend tx3
1594
+
1595
+ deadline3 <- waitMatch 10 n1 $ \ v -> do
1559
1596
guard $ v ^? key " tag" == Just " CommitRecorded"
1560
1597
v ^? key " deadline" >>= parseMaybe parseJSON
1561
1598
1562
1599
(selectLovelace . balance <$> Backend. queryUTxOFor backend QueryTip walletVk)
1563
1600
`shouldReturn` 0
1564
1601
1602
+ -- Close the head
1565
1603
send n1 $ input " Close" []
1566
1604
1567
- deadline ' <- waitMatch (10 * blockTime) n1 $ \ v -> do
1605
+ deadline1 ' <- waitMatch (10 * blockTime) n1 $ \ v -> do
1568
1606
guard $ v ^? key " tag" == Just " HeadIsClosed"
1569
1607
v ^? key " contestationDeadline" . _JSON
1570
1608
1571
- let path = BSC. unpack $ urlEncode False $ encodeUtf8 $ T. pack $ show (getTxId $ getTxBody tx)
1609
+ -- Recover deposit #1
1610
+ let path1 = BSC. unpack $ urlEncode False $ encodeUtf8 $ T. pack $ show (getTxId $ getTxBody tx1)
1572
1611
-- NOTE: we need to wait for the deadline to pass before we can recover the deposit
1573
- diff <- realToFrac . diffUTCTime deadline <$> getCurrentTime
1574
- threadDelay $ diff + 1
1612
+ diff1 <- realToFrac . diffUTCTime deadline1 <$> getCurrentTime
1613
+ threadDelay $ diff1 + 1
1575
1614
1576
1615
(`shouldReturn` " OK" ) $
1577
- parseUrlThrow (" DELETE " <> hydraNodeBaseUrl n1 <> " /commits/" <> path )
1616
+ parseUrlThrow (" DELETE " <> hydraNodeBaseUrl n1 <> " /commits/" <> path1 )
1578
1617
>>= httpJSON
1579
1618
<&> getResponseBody @ String
1580
1619
1581
1620
waitMatch 20 n1 $ \ v -> do
1582
1621
guard $ v ^? key " tag" == Just " CommitRecovered"
1583
- guard $ v ^? key " recoveredUTxO" == Just (toJSON commitUTxO )
1622
+ guard $ v ^? key " recoveredUTxO" == Just (toJSON commitUTxO1 )
1584
1623
1585
1624
(balance <$> Backend. queryUTxOFor backend QueryTip walletVk)
1586
1625
`shouldReturn` lovelaceToValue commitAmount
1587
1626
1588
- remainingTime <- diffUTCTime deadline' <$> getCurrentTime
1627
+ -- Fanout the head
1628
+ remainingTime <- diffUTCTime deadline1' <$> getCurrentTime
1589
1629
waitFor hydraTracer (remainingTime + 3 * blockTime) [n1] $
1590
1630
output " ReadyToFanout" [" headId" .= headId]
1591
1631
send n1 $ input " Fanout" []
1592
1632
waitMatch (20 * blockTime) n1 $ \ v ->
1593
1633
guard $ v ^? key " tag" == Just " HeadIsFinalized"
1594
1634
1635
+ -- Recover deposit #2
1636
+ let path2 = BSC. unpack $ urlEncode False $ encodeUtf8 $ T. pack $ show (getTxId $ getTxBody tx2)
1637
+ -- NOTE: we need to wait for the deadline to pass before we can recover the deposit
1638
+ diff2 <- realToFrac . diffUTCTime deadline2 <$> getCurrentTime
1639
+ threadDelay $ diff2 + 1
1640
+
1641
+ (`shouldReturn` " OK" ) $
1642
+ parseUrlThrow (" DELETE " <> hydraNodeBaseUrl n1 <> " /commits/" <> path2)
1643
+ >>= httpJSON
1644
+ <&> getResponseBody @ String
1645
+
1646
+ waitMatch 20 n1 $ \ v -> do
1647
+ guard $ v ^? key " tag" == Just " CommitRecovered"
1648
+ guard $ v ^? key " recoveredUTxO" == Just (toJSON commitUTxO2)
1649
+
1650
+ (balance <$> Backend. queryUTxOFor backend QueryTip walletVk)
1651
+ `shouldReturn` lovelaceToValue (commitAmount * 2 )
1652
+
1653
+ -- Assert final wallet balance
1654
+ (balance <$> Backend. queryUTxOFor backend QueryTip walletVk)
1655
+ `shouldReturn` balance (commitUTxO1 <> commitUTxO2)
1656
+
1657
+ -- Open a new head
1658
+ send n1 $ input " Init" []
1659
+ headId2 <- waitMatch 10 n1 $ headIsInitializingWith (Set. fromList [alice])
1660
+
1661
+ -- Commit nothing
1662
+ requestCommitTx n1 mempty >>= Backend. submitTransaction backend
1663
+
1664
+ waitFor hydraTracer (20 * blockTime) [n1] $
1665
+ output " HeadIsOpen" [" utxo" .= object mempty , " headId" .= headId2]
1666
+
1667
+ -- Recover deposit #3
1668
+ let path3 = BSC. unpack $ urlEncode False $ encodeUtf8 $ T. pack $ show (getTxId $ getTxBody tx3)
1669
+ -- NOTE: we need to wait for the deadline to pass before we can recover the deposit
1670
+ diff3 <- realToFrac . diffUTCTime deadline3 <$> getCurrentTime
1671
+ threadDelay $ diff3 + 1
1672
+
1673
+ (`shouldReturn` " OK" ) $
1674
+ parseUrlThrow (" DELETE " <> hydraNodeBaseUrl n1 <> " /commits/" <> path3)
1675
+ >>= httpJSON
1676
+ <&> getResponseBody @ String
1677
+
1678
+ waitMatch 20 n1 $ \ v -> do
1679
+ guard $ v ^? key " tag" == Just " CommitRecovered"
1680
+ guard $ v ^? key " recoveredUTxO" == Just (toJSON commitUTxO3)
1681
+
1682
+ (balance <$> Backend. queryUTxOFor backend QueryTip walletVk)
1683
+ `shouldReturn` lovelaceToValue (commitAmount * 3 )
1684
+
1595
1685
-- Assert final wallet balance
1596
1686
(balance <$> Backend. queryUTxOFor backend QueryTip walletVk)
1597
- `shouldReturn` balance commitUTxO
1687
+ `shouldReturn` balance (commitUTxO1 <> commitUTxO2 <> commitUTxO3)
1598
1688
where
1599
1689
hydraTracer = contramap FromHydraNode tracer
1600
1690
0 commit comments