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

Multi-asset API extensions #2447

Merged
merged 12 commits into from
Jan 25, 2021
14 changes: 7 additions & 7 deletions lib/core-integration/src/Test/Integration/Framework/DSL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,8 +1115,8 @@ rewardWallet ctx = do
eventually "MIR wallet: wallet is 100% synced " $ do
rg <- request @ApiWallet ctx (Link.getWallet @'Shelley w) Default Empty
verify rg
[ expectField (#balance . #getApiT . #available . #getQuantity) (.> 0)
, expectField (#balance . #getApiT . #reward . #getQuantity) (.> 0)
[ expectField (#balance . #available . #getQuantity) (.> 0)
, expectField (#balance . #reward . #getQuantity) (.> 0)
]
pure (getFromResponse id rg, mw)

Expand Down Expand Up @@ -1184,7 +1184,7 @@ fixtureWalletWithMnemonics ctx = snd <$> allocate create (free . fst)
checkBalance w = do
r <- request @ApiWallet ctx
(Link.getWallet @'Shelley w) Default Empty
if getFromResponse (#balance . #getApiT . #available) r > Quantity 0
if getFromResponse (#balance . #available) r > Quantity 0
then return (getFromResponse id r)
else threadDelay oneSecond *> checkBalance w

Expand Down Expand Up @@ -1387,7 +1387,7 @@ fixtureWalletWith ctx coins0 = do
-- ^ Coins to move
-> IO ()
moveCoins src dest coins = do
balance <- getFromResponse (#balance . #getApiT . #available . #getQuantity)
balance <- getFromResponse (#balance . #available . #getQuantity)
<$> request @ApiWallet ctx
(Link.getWallet @'Shelley dest) Default Empty
addrs <- fmap (view #id) . getFromResponse id
Expand All @@ -1411,14 +1411,14 @@ fixtureWalletWith ctx coins0 = do
rb <- request @ApiWallet ctx
(Link.getWallet @'Shelley dest) Default Empty
expectField
(#balance . #getApiT . #available)
(#balance . #available)
(`shouldBe` Quantity (sum (balance:coins))) rb
ra <- request @ApiWallet ctx
(Link.getWallet @'Shelley src) Default Empty

getFromResponse (#balance . #getApiT . #available) ra
getFromResponse (#balance . #available) ra
`shouldBe`
getFromResponse (#balance . #getApiT . #total) ra
getFromResponse (#balance . #total) ra

-- | Move coins from a wallet to another
moveByronCoins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ spec = describe "BYRON_COIN_SELECTION" $ do
rnW <- emptyRandomWallet ctx
shW <- emptyWallet ctx
(addr:_) <- fmap (view #id) <$> listAddresses @n ctx shW
let payments = NE.fromList [ AddressAmount addr (Quantity minUTxOValue) ]
let payments = NE.fromList [ AddressAmount addr (Quantity minUTxOValue) mempty ]
selectCoins @_ @'Byron ctx rnW payments >>= flip verify
[ expectResponseCode HTTP.status403
, expectErrorMessage errMsg403NotAnIcarusWallet
Expand All @@ -100,7 +100,7 @@ spec = describe "BYRON_COIN_SELECTION" $ do
target <- emptyWallet ctx
targetAddress : _ <- fmap (view #id) <$> listAddresses @n ctx target
let amt = Quantity minUTxOValue
let payment = AddressAmount targetAddress amt
let payment = AddressAmount targetAddress amt mempty
let output = ApiCoinSelectionOutput targetAddress amt
let isValidDerivationPath path =
( length path == 5 )
Expand Down Expand Up @@ -136,6 +136,7 @@ spec = describe "BYRON_COIN_SELECTION" $ do
let amounts = Quantity <$> [minUTxOValue ..]
let payments = NE.fromList
$ take paymentCount
$ map ($ mempty)
$ zipWith AddressAmount targetAddresses amounts
let outputs =
take paymentCount
Expand All @@ -153,7 +154,7 @@ spec = describe "BYRON_COIN_SELECTION" $ do
icW <- emptyIcarusWallet ctx
shW <- emptyWallet ctx
(addr:_) <- fmap (view #id) <$> listAddresses @n ctx shW
let payments = NE.fromList [ AddressAmount addr (Quantity minUTxOValue) ]
let payments = NE.fromList [ AddressAmount addr (Quantity minUTxOValue) mempty ]
_ <- request @ApiByronWallet ctx (Link.deleteWallet @'Byron icW) Default Empty
selectCoins @_ @'Byron ctx icW payments >>= flip verify
[ expectResponseCode HTTP.status404
Expand All @@ -168,7 +169,7 @@ spec = describe "BYRON_COIN_SELECTION" $ do

targetAddress:_ <- fmap (view #id) <$> listAddresses @n ctx target
let amt = Quantity minUTxOValue
let payment = AddressAmount targetAddress amt
let payment = AddressAmount targetAddress amt mempty
let output = ApiCoinSelectionOutput targetAddress amt
let isValidDerivationPath path =
( length path == 5 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ spec = describe "BYRON_HW_WALLETS" $ do
icarusAddresses @n mnemonics
let targetAmounts = take paymentCount $
Quantity <$> [minUTxOValue ..]
let payments = NE.fromList $
let payments = NE.fromList $ map ($ mempty) $
zipWith AddressAmount targetAddresses targetAmounts
let outputs =
zipWith ApiCoinSelectionOutput targetAddresses targetAmounts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,10 @@ spec = describe "BYRON_MIGRATIONS" $ do
Default
Empty >>= flip verify
[ expectField
(#balance . #getApiT . #available)
(#balance . #available)
(.> (Quantity expectedMinBalance))
, expectField
(#balance . #getApiT . #total)
(#balance . #total)
(.> (Quantity expectedMinBalance))
]

Expand Down Expand Up @@ -564,9 +564,9 @@ spec = describe "BYRON_MIGRATIONS" $ do
(Link.getWallet @'Shelley targetWallet) Default Empty
verify r2
[ expectField
(#balance . #getApiT . #available)
(#balance . #available)
(`shouldBe` Quantity expectedBalance)
, expectField
(#balance . #getApiT . #total)
(#balance . #total)
(`shouldBe` Quantity expectedBalance)
]
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ spec = describe "SHELLEY_ADDRESSES" $ do
rb <- request @ApiWallet ctx
(Link.getWallet @'Shelley wDest) Default Empty
expectField
(#balance . #getApiT . #available)
(#balance . #available)
(`shouldBe` Quantity (10 * 1_000_000))
rb

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ spec = describe "SHELLEY_COIN_SELECTION" $ do
target <- emptyWallet ctx
targetAddress : _ <- fmap (view #id) <$> listAddresses @n ctx target
let amount = Quantity minUTxOValue
let payment = AddressAmount targetAddress amount
let payment = AddressAmount targetAddress amount mempty
let output = ApiCoinSelectionOutput targetAddress amount
let isValidDerivationPath path =
( length path == 5 )
Expand Down Expand Up @@ -134,6 +134,7 @@ spec = describe "SHELLEY_COIN_SELECTION" $ do
let amounts = Quantity <$> [minUTxOValue ..]
let payments = NE.fromList
$ take paymentCount
$ map ($ mempty)
$ zipWith AddressAmount targetAddresses amounts
let outputs =
take paymentCount
Expand All @@ -150,7 +151,7 @@ spec = describe "SHELLEY_COIN_SELECTION" $ do
\Deleted wallet is not available for selection" $ \ctx -> runResourceT $ do
w <- emptyWallet ctx
(addr:_) <- fmap (view #id) <$> listAddresses @n ctx w
let payments = NE.fromList [ AddressAmount addr (Quantity minUTxOValue) ]
let payments = NE.fromList [ AddressAmount addr (Quantity minUTxOValue) mempty ]
_ <- request @ApiWallet ctx (Link.deleteWallet @'Shelley w) Default Empty
selectCoins @_ @'Shelley ctx w payments >>= flip verify
[ expectResponseCode HTTP.status404
Expand All @@ -161,7 +162,7 @@ spec = describe "SHELLEY_COIN_SELECTION" $ do
\Wrong selection method (not 'random')" $ \ctx -> runResourceT $ do
w <- fixtureWallet ctx
(addr:_) <- fmap (view #id) <$> listAddresses @n ctx w
let payments = NE.fromList [ AddressAmount addr (Quantity minUTxOValue) ]
let payments = NE.fromList [ AddressAmount addr (Quantity minUTxOValue) mempty ]
let payload = Json [json| { "payments": #{payments} } |]
let wid = toText $ getApiT $ w ^. #id
let endpoints = ("POST",) . mconcat <$>
Expand Down Expand Up @@ -209,7 +210,7 @@ spec = describe "SHELLEY_COIN_SELECTION" $ do
forM_ matrix $ \(title, headers, expectations) -> it title $ \ctx -> runResourceT $ do
w <- fixtureWallet ctx
(addr:_) <- fmap (view #id) <$> listAddresses @n ctx w
let payments = NE.fromList [ AddressAmount addr (Quantity minUTxOValue) ]
let payments = NE.fromList [ AddressAmount addr (Quantity minUTxOValue) mempty ]
let payload = Json [json| { "payments": #{payments} } |]
r <- request @(ApiCoinSelection n) ctx
(Link.selectCoins @'Shelley w) headers payload
Expand All @@ -224,17 +225,17 @@ spec = describe "SHELLEY_COIN_SELECTION" $ do
(Link.getWallet @'Shelley source) Default Empty
verify rGet
[ expectField
(#balance . #getApiT . #total)
(#balance . #total)
(`shouldBe` Quantity (2 * minUTxOValue))
, expectField
(#balance . #getApiT . #available)
(#balance . #available)
(`shouldBe` Quantity (2 * minUTxOValue))
]
target <- emptyWallet ctx

targetAddress:_ <- fmap (view #id) <$> listAddresses @n ctx target
let amount = Quantity minUTxOValue
let payment = AddressAmount targetAddress amount
let payment = AddressAmount targetAddress amount mempty
let output = ApiCoinSelectionOutput targetAddress amount
let isValidDerivationPath path =
( length path == 5 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ spec = describe "SHELLEY_HW_WALLETS" $ do
rInit <- postWallet ctx payldCrt
verify rInit
[ expectResponseCode HTTP.status201
, expectField (#balance . #getApiT . #available) (`shouldBe` Quantity 0)
, expectField (#balance . #getApiT . #total) (`shouldBe` Quantity 0)
, expectField (#balance . #available) (`shouldBe` Quantity 0)
, expectField (#balance . #total) (`shouldBe` Quantity 0)
]

--send funds
Expand All @@ -130,9 +130,9 @@ spec = describe "SHELLEY_HW_WALLETS" $ do
(Link.getWallet @'Shelley wDest) Default Empty
verify rGet
[ expectField
(#balance . #getApiT . #total) (`shouldBe` Quantity minUTxOValue)
(#balance . #total) (`shouldBe` Quantity minUTxOValue)
, expectField
(#balance . #getApiT . #available) (`shouldBe` Quantity minUTxOValue)
(#balance . #available) (`shouldBe` Quantity minUTxOValue)
]

-- delete wallet
Expand All @@ -149,9 +149,9 @@ spec = describe "SHELLEY_HW_WALLETS" $ do
(Link.getWallet @'Shelley wDest') Default Empty
verify rGet
[ expectField
(#balance . #getApiT . #total) (`shouldBe` Quantity minUTxOValue)
(#balance . #total) (`shouldBe` Quantity minUTxOValue)
, expectField
(#balance . #getApiT . #available) (`shouldBe` Quantity minUTxOValue)
(#balance . #available) (`shouldBe` Quantity minUTxOValue)
]

describe "HW_WALLETS_03 - Cannot do operations requiring private key" $ do
Expand Down Expand Up @@ -312,7 +312,7 @@ spec = describe "SHELLEY_HW_WALLETS" $ do
fmap (view #id) <$> listAddresses @n ctx target
let targetAmounts = take paymentCount $
Quantity <$> [minUTxOValue ..]
let payments = NE.fromList $
let payments = NE.fromList $ map ($ mempty) $
zipWith AddressAmount targetAddresses targetAmounts
let outputs =
zipWith ApiCoinSelectionOutput targetAddresses targetAmounts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ spec = describe "SHELLEY_MIGRATIONS" $ do
Default
Empty
verify r
[ expectField (#balance . #getApiT . #available) (.> Quantity 0)
[ expectField (#balance . #available) (.> Quantity 0)
]
return $ getFromResponse
(#balance . #getApiT . #available . #getQuantity) r
(#balance . #available . #getQuantity) r

-- Calculate the expected migration fee:
rFee <- request @ApiWalletMigrationInfo ctx
Expand Down Expand Up @@ -232,10 +232,10 @@ spec = describe "SHELLEY_MIGRATIONS" $ do
Default
Empty >>= flip verify
[ expectField
(#balance . #getApiT . #available)
(#balance . #available)
(.> (Quantity expectedMinBalance))
, expectField
(#balance . #getApiT . #total)
(#balance . #total)
(.> (Quantity expectedMinBalance))
]

Expand Down Expand Up @@ -290,9 +290,9 @@ spec = describe "SHELLEY_MIGRATIONS" $ do
Default
Empty
verify rg
[ expectField (#balance . #getApiT . #available) (.> Quantity 0)
[ expectField (#balance . #available) (.> Quantity 0)
]
pure $ getFromResponse (#balance . #getApiT. #available . #getQuantity)
pure $ getFromResponse (#balance. #available . #getQuantity)
rg

-- Calculate the expected migration fee:
Expand Down Expand Up @@ -325,10 +325,10 @@ spec = describe "SHELLEY_MIGRATIONS" $ do
Default
Empty >>= flip verify
[ expectField
(#balance . #getApiT . #available)
(#balance . #available)
( `shouldBe` Quantity expectedBalance)
, expectField
(#balance . #getApiT . #total)
(#balance . #total)
( `shouldBe` Quantity expectedBalance)
]

Expand Down Expand Up @@ -485,7 +485,7 @@ spec = describe "SHELLEY_MIGRATIONS" $ do
-- Restore a Shelley wallet with funds, to act as a source wallet:
sourceWallet <- fixtureWallet ctx
let originalBalance =
view (#balance . #getApiT. #available . #getQuantity)
view (#balance. #available . #getQuantity)
sourceWallet

-- Create an empty target wallet:
Expand Down Expand Up @@ -524,10 +524,10 @@ spec = describe "SHELLEY_MIGRATIONS" $ do
(Link.getWallet @'Shelley targetWallet) Default Empty
verify r2
[ expectField
(#balance . #getApiT . #available)
(#balance . #available)
(`shouldBe` Quantity expectedBalance)
, expectField
(#balance . #getApiT . #total)
(#balance . #total)
(`shouldBe` Quantity expectedBalance)
]

Expand All @@ -536,9 +536,9 @@ spec = describe "SHELLEY_MIGRATIONS" $ do
(Link.getWallet @'Shelley sourceWallet) Default Empty
verify r3
[ expectField
(#balance . #getApiT . #available)
(#balance . #available)
(`shouldBe` Quantity 0)
, expectField
(#balance . #getApiT . #total)
(#balance . #total)
(`shouldBe` Quantity 0)
]
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
Default Empty
verify r
[ expectField
(#balance . #getApiT . #reward)
(#balance . #reward)
(.> (Quantity 0))
]
let availableBalance =
getFromResponse (#balance . #getApiT . #available) r
getFromResponse (#balance . #available) r
let rewardBalance =
getFromResponse (#balance . #getApiT . #reward) r
getFromResponse (#balance . #reward) r
pure (availableBalance, rewardBalance)

-- Try to use rewards
Expand Down Expand Up @@ -299,7 +299,7 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
request @ApiWallet ctx (Link.getWallet @'Shelley src) Default Empty
>>= flip verify
[ expectField
(#balance . #getApiT . #reward) (`shouldBe` walletRewards)
(#balance . #reward) (`shouldBe` walletRewards)
]

-- there's currently no withdrawals in the wallet
Expand Down Expand Up @@ -338,10 +338,10 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
request @ApiWallet ctx (Link.getWallet @'Shelley src) Default Empty
>>= flip verify
[ expectField
(#balance . #getApiT . #reward)
(#balance . #reward)
(`shouldBe` (Quantity 0))
, expectField
(#balance . #getApiT . #available)
(#balance . #available)
(.> previousBalance)
]

Expand Down Expand Up @@ -600,7 +600,7 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
eventually "Wallet gets rewards" $ do
request @ApiWallet ctx (Link.getWallet @'Shelley w) Default Empty
>>= flip verify
[ expectField (#balance . #getApiT . #reward)
[ expectField (#balance . #reward)
(.> (Quantity 0))
]

Expand Down Expand Up @@ -902,10 +902,10 @@ spec = describe "SHELLEY_STAKE_POOLS" $ do
Default Empty >>= flip verify
[ expectField #delegation (`shouldBe` notDelegating [])
, expectField
(#balance . #getApiT . #total)
(#balance . #total)
(`shouldSatisfy` (== (Quantity (depositAmt ctx + change))))
, expectField
(#balance . #getApiT . #available)
(#balance . #available)
(`shouldSatisfy` (== (Quantity (depositAmt ctx + change))))
]

Expand Down
Loading