Skip to content

Commit

Permalink
Add property to check that wallet removes consumed inputs from its UT…
Browse files Browse the repository at this point in the history
…XO after balancing.
  • Loading branch information
KtorZ committed Dec 2, 2021
1 parent 51c10af commit 2d09e90
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions hydra-node/test/Hydra/Chain/Direct/WalletSpec.hs
Expand Up @@ -56,6 +56,7 @@ import Test.QuickCheck (
scale,
suchThat,
vectorOf,
(===),
)

spec :: Spec
Expand All @@ -69,6 +70,7 @@ spec = parallel $ do

describe "coverFee" $ do
prop "balances transaction with fees" prop_balanceTransaction
prop "transaction's inputs are removed from wallet" prop_removeUsedInputs

describe "withTinyWallet" $ do
(vk, sk) <- runIO generateKeyPair
Expand Down Expand Up @@ -169,6 +171,25 @@ prop_balanceTransaction =
& counterexample ("Outputs after: " <> show (coin out'))
& counterexample ("Outputs before: " <> show (coin out))

prop_removeUsedInputs ::
Property
prop_removeUsedInputs =
forAllBlind (reasonablySized genValidatedTx) $ \tx ->
forAllBlind (reasonablySized $ genOutputsForInputs tx) $ \txUtxo ->
forAllBlind (reasonablySized genUtxo) $ \extraUtxo ->
prop' txUtxo (txUtxo <> extraUtxo) tx
where
prop' txUtxo walletUtxo tx =
case coverFee_ pparams mempty walletUtxo tx of
Left e ->
property False
& label "Left"
& counterexample (show e)
Right (utxo', _) ->
utxo' === (walletUtxo `Map.withoutKeys` (Map.keysSet txUtxo))
& label "Right"
& counterexample ("Remaining UTXO: " <> show utxo')

--
-- Generators
--
Expand Down

0 comments on commit 2d09e90

Please sign in to comment.