Skip to content

Commit

Permalink
Merge #1987
Browse files Browse the repository at this point in the history
1987: additional tests for redeem rewards r=paweljakubas a=piotr-iohk

# Issue Number

<!-- Put here a reference to the issue this PR relates to and which requirements it tackles -->


# Overview

- 34f17f2
  additional tests for redeem rewards
  
- ef15832
  Add more reward wallets
  
- 85a07e7
  Additional cases to cover not enough fee and not enough money on withdrawals



# Comments

in progress...

<!-- 
Don't forget to:

 ✓ Self-review your changes to make sure nothing unexpected slipped through
 ✓ Assign yourself to the PR
 ✓ Assign one or several reviewer(s)
 ✓ Once created, link this PR to its corresponding ticket
 ✓ Assign the PR to a corresponding milestone
 ✓ Acknowledge any changes required to the Wiki
-->


Co-authored-by: Piotr Stachyra <piotr.stachyra@iohk.io>
Co-authored-by: Pawel Jakubas <pawel.jakubas@iohk.io>
  • Loading branch information
3 people committed Aug 6, 2020
2 parents c93a28d + 457c5fb commit 4a4d0a6
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 0 deletions.
60 changes: 60 additions & 0 deletions lib/core-integration/src/Test/Integration/Faucet.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,66 @@ mirMnemonics = unsafeMkMnemonic <$>
,"crumble","staff","ten","potato","laptop","off"
,"action","chuckle","medal","bread","blind","peanut","horse"
]
, ["version", "reason", "distance", "cargo", "fancy", "anxiety"
, "renew", "grace", "jealous", "brother", "live", "wheel", "lava"
, "exercise", "tragic", "foster", "office", "govern", "title", "inquiry"
, "fit", "twist", "powder", "subway"
]
, ["dentist", "diagram", "eternal", "tuition", "leave", "library"
, "coffee", "power", "brief", "syrup", "six", "donkey", "inner"
, "valley", "carpet", "drop", "labor", "observe", "decade", "okay"
, "play", "stable", "wagon", "blind"
]
, ["gallery", "approve", "trophy", "side", "lawn", "soldier", "gentle"
, "wire", "enact", "illegal", "chef", "sentence", "nation", "beach"
, "glimpse", "term", "unlock", "chalk", "monitor", "panel", "famous"
, "alert", "matter", "female"
]
, ["reason", "grow", "memory", "spray", "gossip", "middle", "grocery"
, "lesson", "poem", "cannon", "dilemma", "elegant", "point", "east"
, "evil", "sauce", "exile", "typical", "cram", "ride", "remove"
, "phrase", "lecture", "degree"
]
, ["else", "normal", "rotate", "flash", "nose", "east", "weasel", "hammer"
, "priority", "pig", "seven", "mention", "model", "profit", "oxygen"
, "tomato", "foot", "age", "glad", "jazz", "retire", "okay"
, "village", "crater"
]
, ["negative", "purpose", "outdoor", "slush", "beach", "radar"
, "canoe", "course", "donkey", "earn", "bone", "bar", "frost"
, "manual", "inhale", "humor", "this", "reflect", "learn", "special"
, "horse", "course", "start", "debris"
]
, ["wealth", "float", "steak", "oil", "rare", "gift", "put", "stool"
, "vault", "give", "gorilla", "indicate", "inside", "comfort"
, "lawn", "assault", "urban", "ancient", "identify", "depth", "injury"
, "solution", "warrior", "exercise"
]
, ["syrup", "shield", "chef", "child", "dwarf", "frog", "hire"
, "script", "suit", "jelly", "point", "degree", "brisk", "oak"
, "minute", "absurd", "refuse", "iron", "forum", "effort"
, "regret", "kidney", "drama", "still"
]
, ["moral", "stem", "myth", "awesome", "crime", "slush", "try"
, "wood", "coconut", "erase", "patient", "trigger", "crew", "solve"
, "element", "million", "nasty", "raven", "innocent", "happy"
, "behind", "ankle", "trick", "museum"
]
, ["wish", "peasant", "void", "nature", "position", "dial", "grant"
, "recycle", "raw", "melody", "equal", "stool", "parent", "category"
, "limb", "apart", "indoor", "six", "float", "happy", "insane"
, "guide", "burst", "other"
]
, ["fury", "possible", "relax", "eyebrow", "supply", "embrace"
, "decide", "wolf", "boring", "blossom", "credit", "drill", "theme"
, "skate", "focus", "trick", "field", "wrist", "update", "hawk"
, "renew", "motor", "learn", "cook"
]
, ["gas", "woman", "grief", "story", "evidence", "actor", "filter"
, "lion", "pilot", "illness", "abuse", "palm", "hurry", "mail", "equal"
, "pen", "element", "nut", "lobster", "enemy", "base", "steel"
, "aisle", "lamp"
]
]

-- | Generate faucets addresses and mnemonics to a file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ module Test.Integration.Framework.TestData
, errMsg400MinWithdrawalWrong
, errMsg403WithdrawalNotWorth
, errMsg403NotAShelleyWallet
, errMsg403InputsDepleted
) where

import Prelude
Expand Down Expand Up @@ -251,6 +252,11 @@ versionLine = "Running as v" <> pack (showFullVersion version gitRevision)
--- Error messages
---

errMsg403InputsDepleted :: String
errMsg403InputsDepleted = "I cannot select enough UTxO from your wallet to construct\
\ an adequate transaction. Try sending a smaller amount or increasing the number\
\ of available UTxO."

errMsg409WalletExists :: String -> String
errMsg409WalletExists walId = "This operation would yield a wallet with the following\
\ id: " ++ walId ++ " However, I already know of a wallet with this id."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ import Test.Integration.Framework.TestData
( errMsg400MinWithdrawalWrong
, errMsg400StartTimeLaterThanEndTime
, errMsg403Fee
, errMsg403InputsDepleted
, errMsg403NoPendingAnymore
, errMsg403NotAShelleyWallet
, errMsg403NotEnoughMoney
, errMsg403NotEnoughMoney_
, errMsg403WithdrawalNotWorth
, errMsg403WrongPass
, errMsg404CannotFindTx
Expand Down Expand Up @@ -1416,6 +1418,113 @@ spec = do
[ expectResponseCode HTTP.status403
, expectErrorMessage errMsg403NotAShelleyWallet
]

it "SHELLEY_TX_REDEEM_06a - Can't redeem rewards if utxo = 0 from other" $ \ctx -> do
(_, mw) <- rewardWallet ctx
wSelf <- emptyWallet ctx
addr:_ <- fmap (view #id) <$> listAddresses @n ctx wSelf

let payload = Json [json|{
"withdrawal": #{mnemonicToText mw},
"payments": [{
"address": #{addr},
"amount": { "quantity": 1000000, "unit": "lovelace" }
}],
"passphrase": #{fixturePassphrase}
}|]

-- Try withdrawing when no UTxO on a wallet
rTx <- request @(ApiTransaction n) ctx
(Link.createTransaction @'Shelley wSelf) Default payload
verify rTx
[ expectResponseCode HTTP.status403
, expectErrorMessage errMsg403InputsDepleted
]

it "SHELLEY_TX_REDEEM_06b - Can't redeem rewards if utxo = 0 from self" $ \ctx -> do
(wRewards, mw) <- rewardWallet ctx
wOther <- emptyWallet ctx

-- migrate all utxo from rewards wallet
addr:_ <- fmap (view #id) <$> listAddresses @n ctx wOther
let payloadMigr = Json [json|{
"passphrase": #{fixturePassphrase},
"addresses": [#{addr}]
}|]

let ep = Link.migrateWallet @'Shelley wRewards
rM <- request @[ApiTransaction n] ctx ep Default payloadMigr
expectResponseCode HTTP.status202 rM

eventually "No UTxO is on rewards wallet" $ do
rWOther <- request @ApiWallet ctx
(Link.getWallet @'Shelley wRewards) Default Empty
verify rWOther
[ expectField (#balance . #getApiT . #available)
(`shouldBe` Quantity 0)
]

-- Try withdrawing when no UTxO on a wallet
let payload = Json [json|{
"withdrawal": #{mnemonicToText mw},
"payments": [{
"address": #{addr},
"amount": { "quantity": #{oneAda}, "unit": "lovelace" }
}],
"passphrase": #{fixturePassphrase}
}|]
rTx <- request @(ApiTransaction n) ctx
(Link.createTransaction @'Shelley wRewards) Default payload
verify rTx
[ expectResponseCode HTTP.status403
, expectErrorMessage errMsg403InputsDepleted
]

it "SHELLEY_TX_REDEEM_07a - Can't redeem rewards if cannot cover fee" $ \ctx -> do
(_, mw) <- rewardWallet ctx
wSelf <- fixtureWalletWith @n ctx [oneThousandAda]
addr:_ <- fmap (view #id) <$> listAddresses @n ctx wSelf
let amt = oneThousandAda + oneMillionAda

let payload = Json [json|{
"withdrawal": #{mnemonicToText mw},
"payments": [{
"address": #{addr},
"amount": { "quantity": #{amt}, "unit": "lovelace" }
}],
"passphrase": #{fixturePassphrase}
}|]

-- Try withdrawing when cannot cover fee
rTx <- request @(ApiTransaction n) ctx
(Link.createTransaction @'Shelley wSelf) Default payload
verify rTx
[ expectResponseCode HTTP.status403
, expectErrorMessage errMsg403Fee
]

it "SHELLEY_TX_REDEEM_07b - Can't redeem rewards if not enough money" $ \ctx -> do
(_, mw) <- rewardWallet ctx
wSelf <- fixtureWalletWith @n ctx [oneThousandAda]
addr:_ <- fmap (view #id) <$> listAddresses @n ctx wSelf
let amt = oneThousandAda + oneMillionAda + oneAda

let payload = Json [json|{
"withdrawal": #{mnemonicToText mw},
"payments": [{
"address": #{addr},
"amount": { "quantity": #{amt}, "unit": "lovelace" }
}],
"passphrase": #{fixturePassphrase}
}|]

-- Try withdrawing when no not enough money
rTx <- request @(ApiTransaction n) ctx
(Link.createTransaction @'Shelley wSelf) Default payload
verify rTx
[ expectResponseCode HTTP.status403
, expectErrorMessage errMsg403NotEnoughMoney_
]
where
txDeleteNotExistsingTxIdTest eWallet resource =
it resource $ \ctx -> do
Expand Down Expand Up @@ -1506,3 +1615,12 @@ spec = do
plusDelta, minusDelta :: UTCTime -> UTCTime
plusDelta = addUTCTime (toEnum 1000000000)
minusDelta = addUTCTime (toEnum (-1000000000))

oneAda :: Natural
oneAda = 1_000_000

oneThousandAda :: Natural
oneThousandAda = 1_000 * oneAda

oneMillionAda :: Natural
oneMillionAda = 1_000 * oneThousandAda

0 comments on commit 4a4d0a6

Please sign in to comment.