Skip to content

Commit

Permalink
Make eventually work with MonadicIO
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Oct 1, 2020
1 parent 72de8fb commit 0c9a952
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 110 deletions.
17 changes: 9 additions & 8 deletions lib/core-integration/src/Test/Integration/Framework/DSL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ waitAllTxsInLedger
=> Context t
-> ApiWallet
-> m ()
waitAllTxsInLedger ctx w = liftIO $ eventually "waitAllTxsInLedger: all txs in ledger" $ do
waitAllTxsInLedger ctx w = eventually "waitAllTxsInLedger: all txs in ledger" $ do
let ep = Link.listTransactions @'Shelley w
(_, txs) <- unsafeRequest @[ApiTransaction n] ctx ep Empty
view (#status . #getApiT) <$> txs `shouldSatisfy` all (== InLedger)
Expand All @@ -593,7 +593,7 @@ waitForNextEpoch
waitForNextEpoch ctx = do
epoch <- getFromResponse (#nodeTip . #epochNumber) <$>
request @ApiNetworkInformation ctx Link.getNetworkInfo Default Empty
liftIO $ eventually "waitForNextEpoch: goes to next epoch" $ do
eventually "waitForNextEpoch: goes to next epoch" $ do
epoch' <- getFromResponse (#nodeTip . #epochNumber) <$>
request @ApiNetworkInformation ctx Link.getNetworkInfo Default Empty
unless (getApiT epoch' > getApiT epoch) $ fail "not yet"
Expand Down Expand Up @@ -664,7 +664,7 @@ a .<= b
--
-- It is like 'eventuallyUsingDelay', but with the default delay of 500 ms
-- between retries.
eventually :: String -> IO a -> IO a
eventually :: MonadIO m => String -> IO a -> m a
eventually = eventuallyUsingDelay (500 * ms)
where
ms = 1000
Expand All @@ -674,11 +674,12 @@ eventually = eventuallyUsingDelay (500 * ms)
--
-- It sleeps for a specified delay between retries.
eventuallyUsingDelay
:: Int -- ^ Delay in microseconds
:: MonadIO m
=> Int -- ^ Delay in microseconds
-> String -- ^ Brief description of the IO action
-> IO a
-> IO a
eventuallyUsingDelay delay desc io = do
-> m a
eventuallyUsingDelay delay desc io = liftIO $ do
lastErrorRef <- newIORef Nothing
-- NOTE
-- This __90s__ is mostly justified by the parameters in the shelley
Expand Down Expand Up @@ -737,7 +738,7 @@ restoreWalletFromPubKey ctx pubKey name = snd <$> allocate create destroy
r <- request @w ctx (Link.postWallet @style) Default payloadRestore
expectResponseCode HTTP.status201 r
let wid = getFromResponse id r
liftIO $ eventually "restoreWalletFromPubKey: wallet is 100% synced " $ do
eventually "restoreWalletFromPubKey: wallet is 100% synced " $ do
rg <- request @w ctx (Link.getWallet @style wid) Default Empty
expectField (typed @(ApiT SyncProgress) . #getApiT) (`shouldBe` Ready) rg
return wid
Expand Down Expand Up @@ -929,7 +930,7 @@ rewardWallet ctx = do
expectResponseCode HTTP.status201 r
let w = getFromResponse id r
waitForNextEpoch ctx
liftIO $ eventually "MIR wallet: wallet is 100% synced " $ do
eventually "MIR wallet: wallet is 100% synced " $ do
rg <- request @ApiWallet ctx (Link.getWallet @'Shelley w) Default Empty
verify rg
[ expectField (#balance . #getApiT . #available . #getQuantity) (.> 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ import Cardano.Wallet.Primitive.Types
( AddressState (..) )
import Control.Monad
( forM_ )
import Control.Monad.IO.Class
( liftIO )
import Control.Monad.Trans.Resource
( ResourceT, runResourceT )
import Data.Generics.Internal.VL.Lens
Expand Down Expand Up @@ -428,7 +426,7 @@ scenario_ADDRESS_IMPORT_05 addrNum fixture = it title $ \ctx -> runResourceT $ d
[ expectResponseCode HTTP.status204
]

liftIO $ eventually "Addresses are imported" $ do
eventually "Addresses are imported" $ do
r1 <- request @[ApiAddress n] ctx (Link.listAddresses @'Byron w) Default Empty
verify r1
[ expectListSize addrNum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ spec = describe "BYRON_HW_WALLETS" $ do
(Link.createTransaction @'Byron wSrc) Default payload
expectResponseCode HTTP.status202 rTrans

liftIO $ eventually "Wallet balance is as expected" $ do
eventually "Wallet balance is as expected" $ do
rGet <- request @ApiByronWallet ctx
(Link.getWallet @'Byron wDest) Default Empty
verify rGet
Expand All @@ -161,7 +161,7 @@ spec = describe "BYRON_HW_WALLETS" $ do
let accXPub = pubKeyFromMnemonics mnemonics
wDest' <- restoreWalletFromPubKey @ApiByronWallet @'Byron ctx accXPub restoredWalletName

liftIO $ eventually "Balance of restored wallet is as expected" $ do
eventually "Balance of restored wallet is as expected" $ do
rGet <- request @ApiByronWallet ctx
(Link.getWallet @'Byron wDest') Default Empty
verify rGet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ spec = describe "BYRON_MIGRATIONS" $ do
"style": "random"
} |]
wOld <- unsafeResponse <$> postByronWallet ctx payloadRestore
originalBalance <- liftIO $ eventually "wallet balance greater than 0" $ do
originalBalance <- eventually "wallet balance greater than 0" $ do
r <- request @ApiByronWallet ctx
(Link.getWallet @'Byron wOld)
Default
Expand Down Expand Up @@ -285,7 +285,7 @@ spec = describe "BYRON_MIGRATIONS" $ do

-- Check that funds become available in the target wallet:
let expectedBalance = originalBalance - expectedFee - leftovers
liftIO $ eventually "wallet balance = expectedBalance" $ do
eventually "wallet balance = expectedBalance" $ do
request @ApiWallet ctx
(Link.getWallet @'Shelley wNew)
Default
Expand Down Expand Up @@ -377,7 +377,7 @@ spec = describe "BYRON_MIGRATIONS" $ do
"style": "random"
} |]
sourceWallet <- unsafeResponse <$> postByronWallet ctx payloadRestore
liftIO $ eventually "wallet balance greater than 0" $ do
eventually "wallet balance greater than 0" $ do
request @ApiByronWallet ctx
(Link.getWallet @'Byron sourceWallet)
Default
Expand Down Expand Up @@ -517,7 +517,7 @@ spec = describe "BYRON_MIGRATIONS" $ do

-- Check that funds become available in the target wallet:
let expectedBalance = originalBalance - expectedFee - leftovers
liftIO $ eventually "Wallet has expectedBalance" $ do
eventually "Wallet has expectedBalance" $ do
r2 <- request @ApiWallet ctx
(Link.getWallet @'Shelley targetWallet) Default Empty
verify r2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ spec = describe "BYRON_WALLETS" $ do
liftIO $ verify r expectations
let w = getFromResponse id r

liftIO $ eventually "wallet is available and ready" $ do
eventually "wallet is available and ready" $ do
-- get
rg <- request @ApiByronWallet ctx
(Link.getWallet @'Byron w) Default Empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ spec = describe "COMMON_NETWORK" $ do
let getNetworkInfo = request @ApiNetworkInformation ctx
Link.getNetworkInfo Default Empty
w <- emptyRandomWallet ctx
liftIO $ eventually "Wallet has the same tip as network/information" $ do
eventually "Wallet has the same tip as network/information" $ do
sync <- getNetworkInfo
expectField (#syncProgress . #getApiT) (`shouldBe` Ready) sync

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import Cardano.Wallet.Primitive.Types
( AddressState (..) )
import Control.Monad
( forM_ )
import Control.Monad.IO.Class
( liftIO )
import Control.Monad.Trans.Resource
( runResourceT )
import Data.Generics.Internal.VL.Lens
Expand Down Expand Up @@ -199,7 +197,7 @@ spec = describe "SHELLEY_ADDRESSES" $ do
expectResponseCode HTTP.status202 rTrans

-- make sure all transactions are in ledger
liftIO $ eventually "Wallet balance = initPoolGap * minUTxOValue" $ do
eventually "Wallet balance = initPoolGap * minUTxOValue" $ do
rb <- request @ApiWallet ctx
(Link.getWallet @'Shelley wDest) Default Empty
expectField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ spec = describe "SHELLEY_HW_WALLETS" $ do
(Link.createTransaction @'Shelley wSrc) Default payload
expectResponseCode HTTP.status202 rTrans

liftIO $ eventually "Wallet balance is as expected" $ do
eventually "Wallet balance is as expected" $ do
rGet <- request @ApiWallet ctx
(Link.getWallet @'Shelley wDest) Default Empty
verify rGet
Expand All @@ -140,7 +140,7 @@ spec = describe "SHELLEY_HW_WALLETS" $ do
let accXPub = pubKeyFromMnemonics mnemonics
wDest' <- restoreWalletFromPubKey @ApiWallet @'Shelley ctx accXPub restoredWalletName

liftIO $ eventually "Balance of restored wallet is as expected" $ do
eventually "Balance of restored wallet is as expected" $ do
rGet <- request @ApiWallet ctx
(Link.getWallet @'Shelley wDest') Default Empty
verify rGet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ spec = describe "SHELLEY_MIGRATIONS" $ do
"passphrase": #{fixturePassphrase}
} |]
wOld <- unsafeResponse <$> postWallet ctx payloadRestore
originalBalance <- liftIO $ eventually "wallet balance greater than 0" $ do
originalBalance <- eventually "wallet balance greater than 0" $ do
r <- request @ApiWallet ctx
(Link.getWallet @'Shelley wOld)
Default
Expand Down Expand Up @@ -212,7 +212,7 @@ spec = describe "SHELLEY_MIGRATIONS" $ do

-- Check that funds become available in the target wallet:
let expectedBalance = originalBalance - expectedFee - leftovers
liftIO $ eventually "wallet balance = expectedBalance" $ do
eventually "wallet balance = expectedBalance" $ do
request @ApiWallet ctx
(Link.getWallet @'Shelley wNew)
Default
Expand Down Expand Up @@ -270,7 +270,7 @@ spec = describe "SHELLEY_MIGRATIONS" $ do
"passphrase": #{fixturePassphrase}
} |]
sourceWallet <- unsafeResponse <$> postWallet ctx payloadRestore
originalBalance <- liftIO $ eventually "wallet balance greater than 0" $ do
originalBalance <- eventually "wallet balance greater than 0" $ do
rg <- request @ApiWallet ctx
(Link.getWallet @'Shelley sourceWallet)
Default
Expand Down Expand Up @@ -305,7 +305,7 @@ spec = describe "SHELLEY_MIGRATIONS" $ do

-- Check that funds become available in the target wallet:
let expectedBalance = originalBalance - expectedFee
liftIO $ eventually "targetWallet balance = expectedBalance" $ do
eventually "targetWallet balance = expectedBalance" $ do
request @ApiWallet ctx
(Link.getWallet @'Shelley targetWallet)
Default
Expand Down Expand Up @@ -466,7 +466,7 @@ spec = describe "SHELLEY_MIGRATIONS" $ do

-- Check that funds become available in the target wallet:
let expectedBalance = originalBalance - expectedFee
liftIO $ eventually "Wallet has expectedBalance" $ do
eventually "Wallet has expectedBalance" $ do
r2 <- request @ApiWallet ctx
(Link.getWallet @'Shelley targetWallet) Default Empty
verify r2
Expand Down
Loading

0 comments on commit 0c9a952

Please sign in to comment.