@@ -92,13 +92,13 @@ tests =
9292 " underfunded transaction (outputs exceed inputs) always fails"
9393 prop_calcMinFeeRecursive_insufficient_funds
9494 , testProperty
95- " Case 1 : outputs with tokens not in UTxO returns NonAdaAssetsUnbalanced"
95+ " Precondition : outputs with tokens not in UTxO returns NonAdaAssetsUnbalanced"
9696 prop_calcMinFeeRecursive_non_ada_unbalanced
9797 , testProperty
98- " Case 2 : output with multi-assets below min UTxO returns MinUTxONotMet"
98+ " Case 1 : output with multi-assets below min UTxO returns MinUTxONotMet"
9999 prop_calcMinFeeRecursive_min_utxo_not_met
100100 , testProperty
101- " Case 3 : transaction with no outputs creates change output"
101+ " Case 2 : transaction with no outputs creates change output"
102102 prop_calcMinFeeRecursive_no_tx_outs
103103 , testProperty
104104 " Tiny surplus consumed by fee increase yields NotEnoughAda"
@@ -647,7 +647,7 @@ genUnderfundedTx era = do
647647 return (Exp. makeUnsignedTx era txBodyContent, utxo, changeAddr)
648648
649649-- | A well-funded transaction (UTxO >> output + fee) always produces a
650- -- successful positive fee calculation .
650+ -- successful, fully balanced result with a positive fee.
651651prop_calcMinFeeRecursive_well_funded_succeeds :: Property
652652prop_calcMinFeeRecursive_well_funded_succeeds = H. property $ do
653653 (unsignedTx, utxo, changeAddr) <- H. forAll $ genFundedSimpleTx Exp. ConwayEra
@@ -656,6 +656,16 @@ prop_calcMinFeeRecursive_well_funded_succeeds = H.property $ do
656656 Right (Exp. UnsignedTx resultLedgerTx) -> do
657657 let resultFee = resultLedgerTx ^. L. bodyTxL . L. feeTxBodyL
658658 H. assert $ resultFee > L. Coin 0
659+ -- The resulting transaction must be fully balanced (zero balance).
660+ let balance =
661+ UnexportedLedger. evalBalanceTxBody
662+ exampleProtocolParams
663+ (const Nothing )
664+ (const Nothing )
665+ (const False )
666+ utxo
667+ (resultLedgerTx ^. L. bodyTxL)
668+ balance H. === mempty
659669
660670-- | 'calcMinFeeRecursive' is idempotent: applying it to its own result
661671-- yields the same 'UnsignedTx'. This confirms the fee has reached a
@@ -685,7 +695,7 @@ prop_calcMinFeeRecursive_insufficient_funds = H.property $ do
685695
686696-- | Generates a transaction whose output demands a native token that does
687697-- not exist in the UTxO (which is ADA-only). This guarantees a negative
688- -- multi-asset balance, triggering Case 1 ('NonAdaAssetsUnbalanced').
698+ -- multi-asset balance, triggering the multi-asset precondition check ('NonAdaAssetsUnbalanced').
689699genNonAdaUnbalancedTx
690700 :: Exp. Era era
691701 -> Gen
@@ -727,8 +737,8 @@ genNonAdaUnbalancedTx era = do
727737-- | Generates a two-output transaction where the second output carries native
728738-- tokens with only 1000 lovelace — well below the minimum UTxO for a
729739-- token-bearing output. The surplus ADA is distributed to the first
730- -- output (Case 3 ), so the second output stays below minimum, triggering
731- -- Case 2 ('MinUTxONotMet').
740+ -- output (Case 2 ), so the second output stays below minimum, triggering
741+ -- Case 1 ('MinUTxONotMet').
732742genMinUTxOViolatingTx
733743 :: Exp. Era era
734744 -> Gen
@@ -771,7 +781,7 @@ genMinUTxOViolatingTx era = do
771781 return (Exp. makeUnsignedTx era txBodyContent, utxo, changeAddr)
772782
773783-- | Generates a transaction with inputs but no outputs. Once the fee
774- -- converges (Case 4 ), the positive surplus triggers Case 3 , and
784+ -- converges (Case 3 ), the positive surplus triggers Case 2 , and
775785-- 'balanceTxOuts' creates a change output with the surplus.
776786genNoOutputsTx
777787 :: Exp. Era era
@@ -851,7 +861,7 @@ prop_calcMinFeeRecursive_no_tx_outs = H.property $ do
851861-- Fee for 2-output tx (F2) ≈ 259 lovelace
852862-- Delta = F2 - F1 ≈ 23
853863-- A surplus of F1 + 1 to F1 + 15 ensures:
854- -- 1. After fee convergence at F1, a positive balance triggers Case 3 .
864+ -- 1. After fee convergence at F1, a positive balance triggers Case 2 .
855865-- 2. Adding the change output raises the fee to F2.
856866-- 3. The change is updated: (surplus - F1) + (F1 - F2) = surplus - F2 < 0.
857867-- 4. balanceTxOuts returns NotEnoughAda.
0 commit comments