Skip to content

Commit

Permalink
Merge pull request #416 from input-output-hk/KtorZ/remove-unnecessary…
Browse files Browse the repository at this point in the history
…-fixtureWallet-usage

reduce usage of 'fixtureWallet' in the integration tests
  • Loading branch information
KtorZ authored Jun 14, 2019
2 parents 840fa20 + 8d11050 commit d89bed5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import Prelude

import Cardano.Wallet.Api.Types
( ApiAddress, ApiTransaction, ApiWallet )
import Cardano.Wallet.Primitive.AddressDiscovery
( defaultAddressPoolGap, getAddressPoolGap )
import Cardano.Wallet.Primitive.Types
( AddressState (..), DecodeAddress (..), EncodeAddress (..) )
import Control.Monad
Expand Down Expand Up @@ -58,29 +60,22 @@ import qualified Network.HTTP.Types.Status as HTTP
spec :: forall t. (DecodeAddress t, EncodeAddress t) => SpecWith (Context t)
spec = do
it "ADDRESS_LIST_01 - Can list known addresses on a default wallet" $ \ctx -> do
w <- fixtureWallet ctx
let g = fromIntegral $ getAddressPoolGap defaultAddressPoolGap
w <- emptyWallet ctx
r <- request @[ApiAddress t] ctx (getAddressesEp w "") Default Empty
expectResponseCode @IO HTTP.status200 r
expectListSizeEqual 21 r
expectListItemFieldEqual 0 state Used r
forM_ [1..20] $ \addrNum -> do
expectListSizeEqual g r
forM_ [0..(g-1)] $ \addrNum -> do
expectListItemFieldEqual addrNum state Unused r

it "ADDRESS_LIST_01 - Can list addresses with non-default pool gap"
$ \ctx -> do
w <- emptyWalletWith ctx ("Wallet", "cardano-wallet", 15)
r <- request @[ApiAddress t] ctx (getAddressesEp w "") Default Empty
expectResponseCode @IO HTTP.status200 r
expectListSizeEqual 15 r
forM_ [0..14] $ \addrNum -> do
expectListItemFieldEqual addrNum state Unused r

it "ADDRESS_LIST_01 - Can list addresses with default pool gap" $ \ctx -> do
w <- emptyWallet ctx
let g = 15
w <- emptyWalletWith ctx ("Wallet", "cardano-wallet", g)
r <- request @[ApiAddress t] ctx (getAddressesEp w "") Default Empty
expectResponseCode @IO HTTP.status200 r
expectListSizeEqual 20 r
forM_ [0..19] $ \addrNum -> do
expectListSizeEqual g r
forM_ [0..(g-1)] $ \addrNum -> do
expectListItemFieldEqual addrNum state Unused r

it "ADDRESS_LIST_02 - Can filter used and unused addresses" $ \ctx -> do
Expand All @@ -92,7 +87,6 @@ spec = do
expectResponseCode @IO HTTP.status200 rUsed
expectListSizeEqual 1 rUsed
expectListItemFieldEqual 0 state Used rUsed

expectResponseCode @IO HTTP.status200 rUnused
expectListSizeEqual 20 rUnused
forM_ [0..19] $ \addrNum -> do
Expand All @@ -107,17 +101,23 @@ spec = do
Default Empty
expectResponseCode @IO HTTP.status200 rUsed
expectListSizeEqual 0 rUsed

expectResponseCode @IO HTTP.status200 rUnused
expectListSizeEqual 20 rUnused
forM_ [0..19] $ \addrNum -> do
expectListItemFieldEqual addrNum state Unused rUnused

describe "ADDRESS_LIST_02 - Invalid filters are bad requests" $ do
let filters = [ "?state=usedd", "?state=uused", "?state=unusedd"
, "?state=uunused", "?state=USED", "?state=UNUSED"
, "?state=-1000", "?state=44444444", "?state=*" ]

let filters =
[ "?state=usedd"
, "?state=uused"
, "?state=unusedd"
, "?state=uunused"
, "?state=USED"
, "?state=UNUSED"
, "?state=-1000"
, "?state=44444444"
, "?state=*"
]
forM_ filters $ \fil -> it fil $ \ctx -> do
let stateFilter = T.pack fil
w <- emptyWallet ctx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ spec = do
, ( "polish", T.unpack polishWalletName, base58Err )
]
forM_ matrix $ \(title, addr, errMsg) -> it title $ \ctx -> do
wSrc <- fixtureWallet ctx
wSrc <- emptyWallet ctx
let payload = Json [json|{
"payments": [{
"address": #{addr},
Expand All @@ -400,7 +400,7 @@ spec = do
]

it "TRANS_CREATE_05 - [] as address" $ \ctx -> do
wSrc <- fixtureWallet ctx
wSrc <- emptyWallet ctx
let payload = Json [json|{
"payments": [{
"address": [],
Expand All @@ -418,7 +418,7 @@ spec = do
]

it "TRANS_CREATE_05 - Num as address" $ \ctx -> do
wSrc <- fixtureWallet ctx
wSrc <- emptyWallet ctx
let payload = Json [json|{
"payments": [{
"address": 123123,
Expand All @@ -436,7 +436,7 @@ spec = do
]

it "TRANS_CREATE_05 - address param missing" $ \ctx -> do
wSrc <- fixtureWallet ctx
wSrc <- emptyWallet ctx
let payload = Json [json|{
"payments": [{
"amount": {
Expand Down Expand Up @@ -529,7 +529,7 @@ spec = do
)
]
forM_ matrix $ \(title, amt, expectations) -> it title $ \ctx -> do
wSrc <- fixtureWallet ctx
wSrc <- emptyWallet ctx
wDest <- emptyWallet ctx
addr:_ <- listAddresses ctx wDest

Expand Down Expand Up @@ -569,7 +569,7 @@ spec = do
expectErrorMessage errMsg404NoEndpoint r

it "TRANS_CREATE_07 - 'almost' valid walletId" $ \ctx -> do
w <- fixtureWallet ctx
w <- emptyWallet ctx
wDest <- emptyWallet ctx
addr:_ <- listAddresses ctx wDest
let destination = addr ^. #id
Expand All @@ -592,7 +592,7 @@ spec = do
expectErrorMessage errMsg404NoEndpoint r

it "TRANS_CREATE_07 - Deleted wallet" $ \ctx -> do
w <- fixtureWallet ctx
w <- emptyWallet ctx
_ <- request @ApiWallet ctx (deleteWalletEp w) Default Empty
wDest <- emptyWallet ctx
addr:_ <- listAddresses ctx wDest
Expand All @@ -614,7 +614,7 @@ spec = do
describe "TRANS_CREATE_08 - v2/wallets/{id}/transactions - Methods Not Allowed" $ do
let matrix = ["PUT", "DELETE", "CONNECT", "TRACE", "OPTIONS", "GET"]
forM_ matrix $ \method -> it (show method) $ \ctx -> do
w <- fixtureWallet ctx
w <- emptyWallet ctx
wDest <- emptyWallet ctx
addr:_ <- listAddresses ctx wDest
let destination = addr ^. #id
Expand Down Expand Up @@ -663,7 +663,7 @@ spec = do
)
]
forM_ matrix $ \(title, headers, expectations) -> it title $ \ctx -> do
w <- fixtureWallet ctx
w <- emptyWallet ctx
wDest <- emptyWallet ctx
addr:_ <- listAddresses ctx wDest
let destination = addr ^. #id
Expand Down Expand Up @@ -697,7 +697,7 @@ spec = do
]

forM_ matrix $ \(name, nonJson) -> it name $ \ctx -> do
w <- fixtureWallet ctx
w <- emptyWallet ctx
let payload = nonJson
r <- request @(ApiTransaction t) ctx (postTxEp w)
Default payload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ spec = do
, ( "address is space", " ", base58Err )
]
forM_ matrix $ \(title, addr, errMsg) -> it title $ \ctx -> do
wSrc <- fixtureWallet ctx
wSrc <- emptyWallet ctx
let args = T.unpack <$>
[ wSrc ^. walletId
, "--payment", "12@" <> (T.pack addr)
Expand All @@ -374,7 +374,7 @@ spec = do
, ("no amount", "", errNum)
]
forM_ matrix $ \(title, amt, errMsg) -> it title $ \ctx -> do
wSrc <- fixtureWallet ctx
wSrc <- emptyWallet ctx
wDest <- emptyWallet ctx
addrs:_ <- listAddresses ctx wDest
let addr =
Expand Down Expand Up @@ -411,7 +411,7 @@ spec = do
\hex-encoded string of 40 characters"

it "TRANSCLI_CREATE_07 - 'almost' valid walletId" $ \ctx -> do
wSrc <- fixtureWallet ctx
wSrc <- emptyWallet ctx
wDest <- emptyWallet ctx
addrs:_ <- listAddresses ctx wDest
let port = T.pack $ show $ ctx ^. typed @Port
Expand All @@ -428,7 +428,7 @@ spec = do
c `shouldBe` ExitFailure 1

it "TRANS_CREATE_07 - Deleted wallet" $ \ctx -> do
wSrc <- fixtureWallet ctx
wSrc <- emptyWallet ctx
Exit ex <- deleteWalletViaCLI ctx (T.unpack ( wSrc ^. walletId ))
ex `shouldBe` ExitSuccess

Expand Down

0 comments on commit d89bed5

Please sign in to comment.