This repository has been archived by the owner on Aug 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3210 from input-output-hk/KtorZ/CO-324/per-field-…
…endpoints [CO-324] Accounts per-field endpoints
- Loading branch information
Showing
12 changed files
with
232 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{-# LANGUAGE RankNTypes #-} | ||
{-# LANGUAGE TupleSections #-} | ||
|
||
module AccountSpecs (accountSpecs) where | ||
|
||
import Universum | ||
|
||
import Cardano.Wallet.API.Indices (accessIx) | ||
import Cardano.Wallet.Client.Http | ||
import Control.Lens | ||
import Pos.Core.Common (mkCoin) | ||
import Test.Hspec | ||
import Util | ||
|
||
import qualified Pos.Core as Core | ||
import qualified Prelude | ||
|
||
|
||
accountSpecs :: WalletRef -> WalletClient IO -> Spec | ||
accountSpecs _ wc = | ||
describe "Accounts" $ do | ||
it "can retrieve only an accounts balance" $ do | ||
let zero = V1 (mkCoin 0) | ||
(Wallet{..}, Account{..}) <- randomAccount wc | ||
eresp <- getAccountBalance wc walId accIndex | ||
|
||
partialAccount <- wrData <$> eresp `shouldPrism` _Right | ||
partialAccount `shouldBe` AccountBalance zero | ||
|
||
it "can retrieve only an account's addresses" $ do | ||
pair@(Wallet{..}, Account{..}) <- randomAccount wc | ||
addresses <- createAddresses wc 10 pair | ||
let addr = Prelude.head addresses | ||
let tests = | ||
[ PaginationTest (Just 1) (Just 5) NoFilters NoSorts | ||
(expectNAddresses 5) | ||
, PaginationTest (Just 1) (Just 5) (filterByAddress addr) NoSorts | ||
(expectExactlyAddresses [addr]) | ||
, PaginationTest (Just 2) (Just 5) (filterByAddress addr) NoSorts | ||
(expectExactlyAddresses []) | ||
] | ||
|
||
forM_ tests $ \PaginationTest{..} -> do | ||
eresp <- getAccountAddresses wc walId accIndex page perPage filters sorts | ||
expectations . acaAddresses . wrData =<< eresp `shouldPrism` _Right | ||
where | ||
filterByAddress :: WalletAddress -> FilterOperations WalletAddress | ||
filterByAddress addr = | ||
FilterOp (FilterByIndex $ accessIx @_ @(V1 Core.Address) addr) NoFilters | ||
|
||
expectNAddresses :: Int -> [WalletAddress] -> IO () | ||
expectNAddresses n addrs = | ||
length addrs `shouldBe` n | ||
|
||
expectExactlyAddresses :: [WalletAddress] -> [WalletAddress] -> IO () | ||
expectExactlyAddresses as bs = | ||
sort as `shouldBe` sort bs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.