Skip to content

Commit 4d5b113

Browse files
committed
Exercise partial amounts in TxTraceSpec
Signed-off-by: Sasha Bogicevic <[email protected]>
1 parent c4091aa commit 4d5b113

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

hydra-node/test/Hydra/Chain/Direct/TxTraceSpec.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ module Hydra.Chain.Direct.TxTraceSpec where
2121
import Hydra.Prelude hiding (Any, State, label, show)
2222
import Test.Hydra.Prelude
2323

24-
import Cardano.Api.UTxO (UTxO)
24+
import Cardano.Api.UTxO (UTxO, totalLovelace)
2525
import Cardano.Api.UTxO qualified as UTxO
2626
import Data.List (nub, (\\))
2727
import Data.Map.Strict qualified as Map
2828
import Data.Time.Clock.POSIX (posixSecondsToUTCTime)
2929
import Hydra.Cardano.Api (
30+
Coin (..),
3031
CtxUTxO,
3132
PaymentKey,
3233
SlotNo (..),
@@ -72,7 +73,7 @@ import Test.Hydra.Tx.Gen (
7273
genUTxO1,
7374
genVerificationKey,
7475
)
75-
import Test.Hydra.Tx.Mutation (addParticipationTokens)
76+
import Test.Hydra.Tx.Mutation (addParticipationTokens, randomBetween)
7677
import Test.QuickCheck (Confidence (..), Property, Smart (..), Testable, checkCoverage, checkCoverageWith, cover, elements, frequency, ioProperty)
7778
import Test.QuickCheck.Monadic (monadic)
7879
import Test.QuickCheck.StateModel (
@@ -817,6 +818,7 @@ newDepositTx _ utxoToDeposit = do
817818
let validBefore = SlotNo 0
818819
deadline <- liftIO getCurrentTime
819820
let depositUTxO = realWorldModelUTxO utxoToDeposit
821+
amount <- liftIO $ randomBetween 1_000_000 (unCoin $ totalLovelace depositUTxO)
820822
let blueprint = CommitBlueprintTx{blueprintTx = txSpendingUTxO depositUTxO, lookupUTxO = depositUTxO}
821823
pure $
822824
Right $
@@ -826,7 +828,7 @@ newDepositTx _ utxoToDeposit = do
826828
blueprint
827829
validBefore
828830
deadline
829-
Nothing
831+
(Just $ Coin amount)
830832

831833
-- | Creates a increment transaction using given utxo and given snapshot.
832834
newIncrementTx :: Actor -> ConfirmedSnapshot Tx -> AppM (Either IncrementTxError Tx)

hydra-tx/hydra-tx.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ library testlib
144144
, QuickCheck
145145
, quickcheck-arbitrary-adt
146146
, quickcheck-instances
147+
, random
147148

148149
ghc-options: -haddock
149150

hydra-tx/testlib/Test/Hydra/Tx/Mutation.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ import Hydra.Tx.Utils (findFirst, onChainIdToAssetName, verificationKeyToOnChain
157157
import PlutusLedgerApi.V3 (CurrencySymbol, POSIXTime, toData)
158158
import PlutusLedgerApi.V3 qualified as Plutus
159159
import System.Directory.Internal.Prelude qualified as Prelude
160+
import System.Random (newStdGen, randomR)
160161
import Test.Hydra.Prelude
161162
import Test.Hydra.Tx.Fixture (testPolicyId)
162163
import Test.Hydra.Tx.Fixture qualified as Fixture
@@ -945,3 +946,7 @@ removePTFromMintedValue output tx =
945946
(AssetId pid asset, _) ->
946947
pid == headId && asset == assetName
947948
_ -> False
949+
950+
randomBetween :: Integer -> Integer -> IO Integer
951+
randomBetween min' max' =
952+
fst . randomR (min', max') <$> newStdGen

0 commit comments

Comments
 (0)