Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-write balanceTransaction using Node.evaluateTransactionBalance #3100

Merged
merged 24 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
db14617
Add shrinker for fee
Anviking Feb 22, 2022
7247796
Rewrite balanceTransaction using evalauteTransactionBalance
Anviking Feb 28, 2022
2b72c68
Re-add logging for balanceTransaction
Anviking Mar 3, 2022
3b38a71
Add guardTxSize to balanceTransaction
Anviking Mar 10, 2022
1c074ac
Add txMaxSize goldens for balanceTransaction
Anviking Mar 16, 2022
b4bdf3b
Implement SelectionStrategyMinimal fallback in balanceTransaction
Anviking Mar 14, 2022
4b0a57b
fixup duplicate error
Anviking Mar 17, 2022
7af4d69
Fixup: add Eq and Show
Anviking Mar 17, 2022
a003249
Fix a few formatting issues.
jonathanknowles Mar 21, 2022
3a29c09
Reduce noise by moving deconstruction to helpers
Anviking Mar 21, 2022
e69cbc4
Fixup: indentation
Anviking Mar 21, 2022
e43e32d
prop_balanceTransaction{Balanced -> Valid} + polish
Anviking Mar 21, 2022
43431d1
Add comment in genEncodingBoundaryLovelace
Anviking Mar 21, 2022
57adb81
Improve note about bad input-resolution: ADP-1544
Anviking Mar 21, 2022
d7851c6
Update lib/core/src/Cardano/Wallet.hs
Anviking Mar 21, 2022
583e92c
Add another note and link to ADP-1514
Anviking Mar 21, 2022
57864d1
Add prop_posAndNegFromCardanoValueRoundtrip test
Anviking Mar 22, 2022
4c5c4a5
fixup: revert accidental increase to withMaxSuccess
Anviking Mar 22, 2022
336513b
clarify cbor ada bounds in comment
Anviking Mar 22, 2022
76a1a4d
Minor fixes to indendation.
jonathanknowles Mar 23, 2022
ff80a02
Fix some spelling errors.
jonathanknowles Mar 23, 2022
df3c9ba
Wrap long comments in `balanceTransactionWithSelectionStrategy`.
jonathanknowles Mar 23, 2022
80f346c
Remove unnecessary UTxO map conversions when constructing log values.
jonathanknowles Mar 23, 2022
0b57295
Replace `fromIntegral` with `intCastMaybe` in `posAndNegFromCardanoVa…
jonathanknowles Mar 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1700,8 +1700,8 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
\Cannot balance when I cannot afford collateral" $
\ctx -> runResourceT $ do
wa <- fixtureWalletWith @n ctx
[ 2_000_000
, 2_000_000
[ 2_500_000
, 2_500_000
]
let toBalance = Json PlutusScenario.pingPong_1
rTx <- request @ApiSerialisedTransaction ctx
Expand Down Expand Up @@ -1731,11 +1731,11 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
, expectErrorMessage errMsg403Collateral
, expectErrorMessage $ unwords
[ "I need an ada amount of at least:"
, "2.779500"
, "4.278900"
]
, expectErrorMessage $ unwords
[ "The largest combination of pure ada UTxOs I could find is:"
, "[1.853000]"
, "[2.852600]"
]
]

Expand Down Expand Up @@ -1847,9 +1847,6 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
it "TRANS_NEW_BALANCE_05/ADP-1286 - \
\I can balance correctly in case I need to spend my remaining ADA for fee" $
\ctx -> runResourceT $ do
liftIO $ pendingWith
"ADP-1286 - ValueNotConservedUTxO: Transaction seems balanced incorrectly \
\in case when less than minUtxOValue is left on the wallet"
Anviking marked this conversation as resolved.
Show resolved Hide resolved
wa <- fixtureWalletWith @n ctx [3_000_000]
-- PlutusScenario.pingPong_1 is sending out 2₳ therefore tx fee
-- needs to be 1₳ to comply with minUTxOValue constraint
Expand Down
34 changes: 32 additions & 2 deletions lib/core/src/Cardano/Api/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module Cardano.Api.Gen
, genValueForMinting
, genSignedQuantity
, genTxMintValue
, genSignedValue
, genNetworkMagic
, genNetworkId
, genStakeCredential
Expand Down Expand Up @@ -256,8 +257,19 @@ genLovelace = Lovelace <$> frequency
, (8, pure 65536)
, (90, pure 4294967296)
]
x <- choose (-1_000_000, 1_000_000)
pure $ max 0 $ boundary + x

offset <- frequency
[ (1, choose (-10, 10))

-- Offset by values close to common fee values, in both the positive
-- and negative direction, with the hope that this helps find
-- corner-cases.
, (1, choose (-220_000, -150_000))
, (1, choose (150_000, 220_000))

, (1, choose (-1_000_000, 1_000_000))
Anviking marked this conversation as resolved.
Show resolved Hide resolved
]
pure $ max 0 $ boundary + offset


genTxFee :: CardanoEra era -> Gen (TxFee era)
Expand Down Expand Up @@ -451,6 +463,24 @@ genValueForTxOut = do
where
unLovelace (Lovelace l) = l

-- | Generate a 'Value' which could represent the balance of a partial
-- transaction, where both ada and other assets can be included, and quantities
-- can be both positive and negative.
genSignedValue :: Gen Value
genSignedValue = do
assetIds <- oneof
[ nub <$> scale (`div` 4) (listOf genAssetIdNoAda)
, pure []
]
assetQuantities <- infiniteListOf genSignedQuantity
ada <- fromInteger . unLovelace <$> oneof
[ genLovelace
, negate <$> genLovelace
]
return $ valueFromList $ (AdaAssetId, ada) : zip assetIds assetQuantities
where
unLovelace (Lovelace l) = l

-- | Generate a 'Value' suitable for minting, i.e. non-ADA asset ID and a
-- positive or negative quantity.
genValueForMinting :: Gen Value
Expand Down
Loading