Skip to content

Commit

Permalink
Try #3100:
Browse files Browse the repository at this point in the history
  • Loading branch information
iohk-bors[bot] authored Mar 1, 2022
2 parents cc0f201 + ae8a220 commit c823957
Show file tree
Hide file tree
Showing 10 changed files with 634 additions and 372 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module Test.Integration.Framework.TestData
, errMsg400WalletIdEncoding
, errMsg400StartTimeLaterThanEndTime
, errMsg403Fee
, errMsg403MinimizeFee
, errMsg403Collateral
, errMsg403NotAByronWallet
, errMsg403NotAnIcarusWallet
Expand Down Expand Up @@ -322,6 +323,11 @@ errMsg403Fee =
\available to pay for the fee and also pay for the minimum ada quantities \
\of all change outputs."

errMsg403MinimizeFee :: String
errMsg403MinimizeFee =
"I cannot minimize fees because I cannot construct a change \
\output. Try ensuring the wallet has at least a couple of ada."

errMsg403Collateral :: String
errMsg403Collateral =
"I'm unable to create this transaction because the balance of pure ada \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ import Test.Integration.Framework.TestData
, errMsg403ForeignTransaction
, errMsg403InvalidConstructTx
, errMsg403MinUTxOValue
, errMsg403MinimizeFee
, errMsg403MissingWitsInTransaction
, errMsg403MultiaccountTransaction
, errMsg403MultidelegationTransaction
Expand Down Expand Up @@ -1645,21 +1646,21 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do

it "TRANS_NEW_BALANCE_02b - Cannot balance when I cannot afford fee" $
\ctx -> runResourceT $ do
wa <- fixtureWalletWith @n ctx [2 * 1_000_000]
wa <- fixtureWalletWith @n ctx [2_500_000]
let balancePayload = Json PlutusScenario.pingPong_1
rTx <- request @ApiSerialisedTransaction ctx
(Link.balanceTransaction @'Shelley wa) Default balancePayload
verify rTx
[ expectResponseCode HTTP.status403
, expectErrorMessage errMsg403Fee
, expectErrorMessage errMsg403MinimizeFee
]

it "TRANS_NEW_BALANCE_02c - \
\Cannot balance when I cannot afford collateral" $
\ctx -> runResourceT $ do
liftIO $ pendingWith "unreachable with current params (need ≈2.2 ada for collateral, need ≈3.4 ada for balancing)"
wa <- fixtureWalletWith @n ctx
[ 2_000_000
, 2_000_000
[ 3_300_000
]
let toBalance = Json PlutusScenario.pingPong_1
rTx <- request @ApiSerialisedTransaction ctx
Expand Down Expand Up @@ -1689,11 +1690,11 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
, expectErrorMessage errMsg403Collateral
, expectErrorMessage $ unwords
[ "I need an ada amount of at least:"
, "2.779500"
, "2.627700"
]
, expectErrorMessage $ unwords
[ "The largest combination of pure ada UTxOs I could find is:"
, "[1.853000]"
, "[1.873000]"
]
]

Expand Down Expand Up @@ -1803,17 +1804,13 @@ 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" $
\I can balance correctly in case I have just enough" $
\ctx -> runResourceT $ do
liftIO $ pendingWith
"ADP-1286 - ValueNotConservedUTxO: Transaction seems balanced incorrectly \
\in case when less than minUtxOValue is left on the wallet"
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
let expectedFee = 1_000_000
let initialBalance = 3_180_000
wa <- fixtureWalletWith @n ctx [initialBalance]
-- PlutusScenario.pingPong_1 is sending out 2₳
let amt = 2_000_000
let balancePayload = Json PlutusScenario.pingPong_1
let hasExpectedFee = [expectField (#fee . #getQuantity) (`shouldBe` expectedFee)]

rTx <- request @ApiSerialisedTransaction ctx
(Link.balanceTransaction @'Shelley wa) Default balancePayload
Expand All @@ -1823,7 +1820,7 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do

rDecodedTx <- request @(ApiDecodedTransaction n) ctx
(Link.decodeTransaction @'Shelley wa) Default decodePayload
verify rDecodedTx hasExpectedFee
let expectedFee = getFromResponse (#fee . #getQuantity) rDecodedTx

signedTx <- signTx ctx wa apiTx [ expectResponseCode HTTP.status202 ]
submittedTx <- submitTxWithWid ctx wa signedTx
Expand All @@ -1839,9 +1836,25 @@ spec = describe "NEW_SHELLEY_TRANSACTIONS" $ do
[ expectSuccess
, expectField
(#balance . #available . #getQuantity)
(`shouldBe` 0)
(`shouldBe` (initialBalance - amt - expectedFee))
]

it "TRANS_NEW_BALANCE_05/ADP-1286 - \
\I cannot balance in case I have too little" $
\ctx -> runResourceT $ do
let initialBalance = 3_000_000
wa <- fixtureWalletWith @n ctx [initialBalance]
-- PlutusScenario.pingPong_1 is sending out 2₳
let balancePayload = Json PlutusScenario.pingPong_1

rTx <- request @ApiSerialisedTransaction ctx
(Link.balanceTransaction @'Shelley wa) Default balancePayload
verify rTx
[ expectResponseCode HTTP.status403
, expectErrorMessage "I cannot minimize fees because I cannot construct\
\ a change output. Try ensuring the wallet has at\
\ least a couple of ada." ]

it "TRANS_NEW_SIGN_01 - Sign single-output transaction" $ \ctx -> runResourceT $ do
w <- fixtureWallet ctx

Expand Down
10 changes: 8 additions & 2 deletions lib/core/src/Cardano/Api/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,14 @@ 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))
, (1, choose (-220_000, -150_000))
, (1, choose (150_000, 220_000))
, (1, choose (-1_000_000, 1_000_000))
]
pure $ max 0 $ boundary + offset


genTxFee :: CardanoEra era -> Gen (TxFee era)
Expand Down
Loading

0 comments on commit c823957

Please sign in to comment.