Skip to content
Permalink
Browse files

Tests for fee estimation and post tx when tx max size is reached for …

…single and multi output tx
  • Loading branch information...
piotr-iohk committed Jul 12, 2019
1 parent 0a0f191 commit 5c603997d0657d5bbd6b39b4577d9b657ef7ecae
@@ -616,42 +616,37 @@ emptyWalletWith ctx (name, passphrase, addrPoolGap) = do
expectResponseCode @IO HTTP.status202 r
return (getFromResponse id r)

-- | Prepare Wallet with utxo of size n (each output = amt ada) and payload for Tx
-- with n number of inputs (single input = 1 lovelace) to be sent from that wallet
-- | Prepare Wallet with utxo of size n (each utxo having = amt) and payload for Tx
-- with n number of inputs (single input = amtToSend) to be sent from that wallet
fixtureNInputs
:: forall t. (EncodeAddress t, DecodeAddress t)
=> Context t
-> (Int, Natural)
-> Natural
-> IO (ApiWallet, ApiWallet, Payload)
fixtureNInputs ctx (n, amt) = do
fixtureNInputs ctx (n, amt) amtToSend = do
wSrc <- fixtureWalletWith ctx (replicate n amt)
wDest1 <- emptyWalletWith ctx ("Wallet", "cardano-wallet", 100)
wDest2 <- emptyWalletWith ctx ("Wallet", "cardano-wallet", 100)
wDest3 <- emptyWalletWith ctx ("Wallet", "cardano-wallet", 100)
addrs1 <- listAddresses ctx wDest1
addrs2 <- listAddresses ctx wDest2
addrs3 <- listAddresses ctx wDest3

-- each amt is going to different address
let addrIds = view #id <$> take n (addrs1 ++ addrs2 ++ addrs3)
-- when sending to everything to one address - it worked
-- let addrIdRepl = replicate n addrIds !! 0
let amounts = take n [1, 1..] :: [Natural]
let payments = flip map (zip amounts addrIds) $ \(coin, addr) -> [aesonQQ|{
wDest <- emptyWallet ctx
addrs <- listAddresses ctx wDest

-- each amtToSend is going to the same address
let addrIds = view #id <$> take n addrs
let addrIdRepl = replicate n addrIds !! 1
let payments = flip map addrIdRepl $ \addr -> [aesonQQ|{
"address": #{addr},
"amount": {
"quantity": #{coin},
"quantity": #{amtToSend},
"unit": "lovelace"
}
}|]
let payload = Json [aesonQQ|{
"payments": #{payments :: [Value]},
"passphrase": "Secure Passphrase"
}|]
return (wSrc, wDest1, payload)
return (wSrc, wDest, payload)

-- | Prepare Wallet with utxo of size n (each output = amt ada) and payload for Tx
-- to be send with given amtToSend
-- | Prepare Wallet with utxo of size n (each output = amt) and payload for Tx
-- to be send with given amtToSend (single input)
fixtureMaxTxSize
:: forall t. (EncodeAddress t, DecodeAddress t)
=> Context t
@@ -739,11 +734,11 @@ fixtureWalletWith ctx coins = do
"payments": #{payments :: [Value]},
"passphrase": "cardano-wallet"
}|]
request @(ApiTransaction t) ctx (postTxEp widSrc) Default payload
>>= expectResponseCode HTTP.status202
rr <- request @(ApiTransaction t) ctx (postTxEp widSrc) Default payload
expectResponseCode HTTP.status202 rr
r <- request @ApiWallet ctx (getWalletEp widDest) Default Empty
expectEventually ctx balanceAvailable (sum $ currentAmt:amounts) r
if (firstTen == [] ) then
if ( null firstTen ) then
return ()
else do
-- perform tx with at most 10 inputs at a time because
@@ -50,6 +50,7 @@ module Test.Integration.Framework.TestData
, errMsg404NoRootKey
, errMsg404NoWallet
, errMsg403InputsDepleted
, errMsg403TxTooBig
, errMsg403ZeroAmtOutput
, errMsg405
, errMsg406
@@ -241,6 +242,12 @@ errMsg403InputsDepleted = "I had to select inputs to construct the requested\
\ transaction. Unfortunately, one output of the transaction depleted all\
\ available inputs. Try sending a smaller amount."

errMsg403TxTooBig :: Int -> String
errMsg403TxTooBig n = "I had to select " ++ show n ++ " inputs to construct the\
\ requested transaction. Unfortunately, this would create a transaction\
\ that is too big, and this would consequently be rejected by a core node.\
\ Try sending a smaller amount."

errMsg403ZeroAmtOutput :: String
errMsg403ZeroAmtOutput = "I can't validate coin selection because\
\ at least one output has value 0."
@@ -45,6 +45,8 @@ import Test.Integration.Framework.DSL
, faucetAmt
, faucetUtxoAmt
, feeEstimator
, fixtureMaxTxSize
, fixtureNInputs
, fixtureWallet
, fixtureWalletWith
, getWalletEp
@@ -64,6 +66,7 @@ import Test.Integration.Framework.TestData
, errMsg403Fee
, errMsg403InputsDepleted
, errMsg403NotEnoughMoney
, errMsg403TxTooBig
, errMsg403UTxO
, errMsg403WrongPass
, errMsg404NoEndpoint
@@ -1015,6 +1018,34 @@ spec = do
r <- request @ApiFee ctx (postTxFeeEp w) Default payload
expectResponseCode @IO HTTP.status404 r
expectErrorMessage (errMsg404NoWallet $ w ^. walletId) r

it "TRANS_CREATE_10, TRANS_ESTIMATE_10 - \
\Cannot post/estimate tx when max tx size reached (single output)" $ \ctx -> do
(wSrc, _, payload) <- fixtureMaxTxSize ctx (11, 1_000_000) 10_000_001
fee <- request @ApiFee ctx (postTxFeeEp wSrc) Default payload
tx <- request @(ApiTransaction t) ctx (postTxEp wSrc) Default payload
verify fee
[ expectResponseCode HTTP.status403
, expectErrorMessage (errMsg403TxTooBig 10)
]
verify tx
[ expectResponseCode HTTP.status403
, expectErrorMessage (errMsg403TxTooBig 10)
]

it "TRANS_CREATE_10, TRANS_ESTIMATE_10 - \
\Cannot post/estimate tx when max tx size reached (multi output)" $ \ctx -> do
(wSrc, _, payload) <- fixtureNInputs ctx (11, 1_000_000) 1
fee <- request @ApiFee ctx (postTxFeeEp wSrc) Default payload
tx <- request @(ApiTransaction t) ctx (postTxEp wSrc) Default payload
verify fee
[ expectResponseCode HTTP.status403
, expectErrorMessage (errMsg403TxTooBig 10)
]
verify tx
[ expectResponseCode HTTP.status403
, expectErrorMessage (errMsg403TxTooBig 10)
]
where
longAddr = replicate 10000 '1'
encodeErr = "Unable to decode Address:"
@@ -57,15 +57,17 @@ spec = do
, expectErrorMessage errMsg403ZeroAmtOutput
]

it "TRANS_ESTIMATE_09 - 0 tx fee estimation is allowed? on single output tx" $ \ctx -> do
it "TRANS_ESTIMATE_09 - \
\a fee cannot be estimated for a tx with an output of amount 0 (single)" $ \ctx -> do
(wSrc, payload) <- fixtureZeroAmtSingle ctx
r <- request @ApiFee ctx (postTxFeeEp wSrc) Default payload
verify r
[ expectResponseCode HTTP.status403
, expectErrorMessage errMsg403ZeroAmtOutput
]

it "TRANS_ESTIMATE_09 - 0 amount tx fee estimation is allowed? on multi-output tx" $ \ctx -> do
it "TRANS_ESTIMATE_09 - \
\a fee cannot be estimated for a tx with an output of amount 0 (multi)" $ \ctx -> do
(wSrc, payload) <- fixtureZeroAmtMulti ctx
r <- request @ApiFee ctx (postTxFeeEp wSrc) Default payload
verify r
@@ -24,16 +24,13 @@ import Test.Integration.Framework.DSL
, Headers (..)
, Payload (..)
, emptyWallet
, expectErrorMessage
, expectResponseCode
, fixtureNInputs
, fixtureWallet
, json
, listAddresses
, postTxEp
, postTxFeeEp
, request
, verify
)

import qualified Network.HTTP.Types.Status as HTTP
@@ -50,30 +47,18 @@ spec = do
r <- request @(ApiTransaction t) ctx (postTxEp wSrc) Default payload
expectResponseCode HTTP.status202 r

it "TRANS_ESTIMATE_09 - 0 tx fee estimation is accepted on single output tx" $ \ctx -> do
it "TRANS_ESTIMATE_09 - \
\a fee can be estimated for a tx with an output of amount 0 (single)" $ \ctx -> do
(wSrc, payload) <- fixtureZeroAmtSingle ctx
r <- request @ApiFee ctx (postTxFeeEp wSrc) Default payload
expectResponseCode HTTP.status202 r

it "TRANS_ESTIMATE_09 - 0 amount tx fee estimation is accepted on multi-output tx" $ \ctx -> do
it "TRANS_ESTIMATE_09 - \
\a fee can be estimated for a tx with an output of amount 0 (multi)" $ \ctx -> do
(wSrc, payload) <- fixtureZeroAmtMulti ctx
r <- request @ApiFee ctx (postTxFeeEp wSrc) Default payload
expectResponseCode HTTP.status202 r

it "TRANS_CREATE_10, TRANS_ESTIMATE_10 - 256 input/output tx/fee" $ \ctx -> do
(wSrc, _, payload) <- fixtureNInputs ctx (256, 1_000_000)
fee <- request @ApiFee ctx (postTxFeeEp wSrc) Default payload
tx <- request @(ApiTransaction t) ctx (postTxEp wSrc) Default payload
verify fee
[ expectResponseCode HTTP.status403
, expectErrorMessage "I can't estimate transaction fee because\
\ transaction has either more than 255 inputs or more than\
\ 255 outputs."
]
verify tx
[ expectResponseCode HTTP.status500
, expectErrorMessage "Something went wrong"
]
where
fixtureZeroAmtSingle ctx = do
wSrc <- fixtureWallet ctx

0 comments on commit 5c60399

Please sign in to comment.
You can’t perform that action at this time.