Skip to content

Commit

Permalink
add integration testing
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Jan 28, 2021
1 parent c7d7346 commit 223b801
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Expand Up @@ -76,6 +76,7 @@ module Test.Integration.Framework.TestData
, errMsg403TxTooLarge
, errMsg403CouldntIdentifyAddrAsMine
, errMsg503PastHorizon
, errMsg403WrongIndex
) where

import Prelude
Expand Down Expand Up @@ -443,3 +444,8 @@ errMsg403CouldntIdentifyAddrAsMine = "I \

errMsg503PastHorizon :: String
errMsg503PastHorizon = "Tried to convert something that is past the horizon"

errMsg403WrongIndex :: String
errMsg403WrongIndex = "It looks like you've provided a derivation index that is out of bound.\
\ The index is well-formed, but I require indexes valid for hardened derivation only. That\
\ is, indexes between 2147483648 and 4294967295 with a suffix 'H'."
Expand Up @@ -16,6 +16,7 @@ import Prelude

import Cardano.Wallet.Api.Types
( AnyAddress
, ApiAccountKey
, ApiAddress
, ApiT (..)
, ApiTransaction
Expand Down Expand Up @@ -77,7 +78,7 @@ import Test.Integration.Framework.DSL
, walletId
)
import Test.Integration.Framework.TestData
( errMsg404NoWallet )
( errMsg403WrongIndex, errMsg404NoWallet )

import qualified Cardano.Wallet.Api.Link as Link
import qualified Data.Aeson as Aeson
Expand Down Expand Up @@ -650,6 +651,35 @@ spec = describe "SHELLEY_ADDRESSES" $ do
r <- request @AnyAddress ctx Link.postAnyAddress Default payload
expectResponseCode HTTP.status400 r
expectErrorMessage "must have at least one credential" r

it "POST_ACCOUNT_01 - Can retrieve account public keys" $ \ctx -> runResourceT $ do
let initPoolGap = 10
w <- emptyWalletWith ctx ("Wallet", fixturePassphrase, initPoolGap)

let endpoint = Link.postAccountKey w (DerivationIndex 0)
let payload = Json [json|{
"passphrase": #{fixturePassphrase},
"extended": true
}|]
resp <- request @ApiAccountKey ctx endpoint Default payload
expectErrorMessage errMsg403WrongIndex resp

-- Request first 10 extended account public keys
let indices = [0..9]
accountPublicKeys <- forM indices $ \index -> do
let accountPath = Link.postAccountKey w (DerivationIndex $ 2147483648 + index)
let payload1 = Json [json|{
"passphrase": #{fixturePassphrase},
"extended": true
}|]
let payload2 = Json [json|{
"passphrase": #{fixturePassphrase},
"extended": false
}|]
(_, accXPub) <- unsafeRequest @ApiAccountKey ctx accountPath payload1
(_, accPub) <- unsafeRequest @ApiAccountKey ctx accountPath payload2
pure [accXPub, accPub]
length (concat accountPublicKeys) `Expectations.shouldBe` 20
where
validateAddr resp expected = do
let addr = getFromResponse id resp
Expand Down
13 changes: 13 additions & 0 deletions lib/core/src/Cardano/Wallet/Api/Link.hs
Expand Up @@ -51,6 +51,7 @@ module Cardano.Wallet.Api.Link
-- * WalletKeys
, getWalletKey
, signMetadata
, postAccountKey

-- * Addresses
, postRandomAddress
Expand Down Expand Up @@ -302,6 +303,18 @@ signMetadata w role_ index =
where
wid = w ^. typed @(ApiT WalletId)

postAccountKey
:: forall w.
( HasType (ApiT WalletId) w
)
=> w
-> DerivationIndex
-> (Method, Text)
postAccountKey w index =
endpoint @Api.PostAccountKey (\mk -> mk wid (ApiT index))
where
wid = w ^. typed @(ApiT WalletId)

--
-- Addresses
--
Expand Down

0 comments on commit 223b801

Please sign in to comment.