Skip to content

Commit

Permalink
Add integration test TRANS_MIN_UTXO_BABBAGE_PRECISION
Browse files Browse the repository at this point in the history
Fails on master with:

  src/Test/Integration/Scenario/API/Shelley/Transactions.hs:276:11:
  1) API Specifications, SHELLEY_TRANSACTIONS, TRANS_MIN_UTXO_01b - I can spend exactly minUTxOValue
       From the following response: Left
           ( ClientError
               ( Object
                   ( fromList
                       [
                           ( "code"
                           , String "utxo_too_small"
                           )
                       ,
                           ( "message"
                           , String "One of the outputs you've specified has an ada quantity that is below the minimum required. Either increase the ada quantity to at least the minimum, or specify an ada quantity of zero, in which case the wallet will automatically assign the correct minimum ada quantity to the output. Destination address: 0179aff1...8e21f45f Required minimum ada quantity: 0.995610 Specified ada quantity: 0.978370  "
                           )
                       ]
                   )
               )
           )
       2. we should be able to send minUTxOValue
       expected: Status {
                   statusCode = 202,
                   statusMessage = "Accepted"
                 }
        but got: Status {
                   statusCode = 403,
                   statusMessage = "Forbidden"
                 }

  To rerun use: --match "/API Specifications/SHELLEY_TRANSACTIONS/TRANS_MIN_UTXO_01b - I can spend exactly minUTxOValue/"

but succeeds with #3423.
  • Loading branch information
Anviking authored and jonathanknowles committed Aug 9, 2022
1 parent 1f72c95 commit 0212cca
Showing 1 changed file with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ import Test.Integration.Framework.DSL
, Payload (..)
, between
, computeApiCoinSelectionFee
, counterexample
, emptyRandomWallet
, emptyWallet
, eventually
Expand Down Expand Up @@ -219,6 +220,74 @@ spec = describe "SHELLEY_TRANSACTIONS" $ do
expectResponseCode HTTP.status403 r
expectErrorMessage errMsg403MinUTxOValue r

it "TRANS_MIN_UTXO_BABBAGE_PRECISION - \
\I can spend exactly minUTxOValue" $ \ctx -> runResourceT $ do
-- Coin-selection will out of caution overestimate the size of the ada
-- quantity in its calculation when assigning a new minUTxOValue. In
-- practice, this would always be an overestimation of 0.017240 ada (see
-- calculation below). This tests checks that that the wallet also doesn't
-- validate user-provided values based on the overestimation: we want
-- all ada values allowed by the ledger to also be allowed by the wallet.
wSrc <- fixtureWallet ctx
wDest <- emptyWallet ctx

when (_mainEra ctx < ApiBabbage) $
liftIO $ pendingWith "only for the babbage era or later"

addrs <- listAddresses @n ctx wDest
let destination = (addrs !! 1) ^. #id

let ep = Link.createTransactionOld @'Shelley

minAda <-
counterexample "1. calculate the exact minUTxOValue (for address length)\
\ and manually compensate for the overestimation" $ do
r <- request @(ApiTransaction n) ctx (ep wSrc) Default $
Json [json|{
"payments": [{
"address": #{destination},
"amount": {
"quantity": 0,
"unit": "lovelace"
}
}],
"passphrase": #{fixturePassphrase}
}|]

expectResponseCode HTTP.status202 r
let Quantity totalAmt = getFromResponse #amount r
let Quantity fee = getFromResponse #fee r
let lovelacePerUTxOWord = 4310
let overestimatedCoinBytes = 9 - 5
let overestimation = lovelacePerUTxOWord * overestimatedCoinBytes
return $ totalAmt - fee - overestimation

counterexample "2. paying minUTxOValue should succeed" $ do
r2 <- request @(ApiTransaction n) ctx (ep wSrc) Default $ Json [json|{
"payments": [{
"address": #{destination},
"amount": {
"quantity": #{minAda},
"unit": "lovelace"
}
}],
"passphrase": #{fixturePassphrase}
}|]
expectResponseCode HTTP.status202 r2

counterexample "3. paying (minUTxOValue - 1) should fail" $ do
r3 <- request @(ApiTransaction n) ctx (ep wSrc) Default $ Json [json|{
"payments": [{
"address": #{destination},
"amount": {
"quantity": #{minAda - 1},
"unit": "lovelace"
}
}],
"passphrase": #{fixturePassphrase}
}|]
expectResponseCode HTTP.status403 r3

it "Regression ADP-626 - Filtering transactions between eras" $ do
\ctx -> runResourceT $ do
w <- fixtureWallet ctx
Expand Down

0 comments on commit 0212cca

Please sign in to comment.