Skip to content

Commit

Permalink
add integration tests for getAccountKey
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed May 24, 2021
1 parent 2ed0a9d commit 9f93930
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
18 changes: 18 additions & 0 deletions lib/core-integration/src/Test/Integration/Framework/DSL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ module Test.Integration.Framework.DSL
, patchSharedWallet
, getSharedWalletKey
, postAccountKeyShared
, getAccountKeyShared

-- * Wallet helpers
, listFilteredWallets
Expand Down Expand Up @@ -1478,6 +1479,23 @@ postAccountKeyShared ctx wal ix headers payload =
r :: forall w. HasType (ApiT WalletId) w => w -> m (HTTP.Status, Either RequestException ApiAccountKeyShared)
r w = request @ApiAccountKeyShared ctx (Link.postAccountKey @'Shared w ix) headers payload

getAccountKeyShared
:: forall m.
( MonadIO m
, MonadUnliftIO m
)
=> Context
-> ApiSharedWallet
-> Maybe Bool
-> m (HTTP.Status, Either RequestException ApiAccountKeyShared)
getAccountKeyShared ctx wal hashed =
case wal of
ApiSharedWallet (Left wal') -> r wal'
ApiSharedWallet (Right wal') -> r wal'
where
r :: forall w. HasType (ApiT WalletId) w => w -> m (HTTP.Status, Either RequestException ApiAccountKeyShared)
r w = request @ApiAccountKeyShared ctx (Link.getAccountKey @'Shared w hashed) Default Empty

patchEndpointEnding :: CredentialType -> Text
patchEndpointEnding = \case
Payment -> "payment-script-template"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import Test.Integration.Framework.DSL
, fixturePassphrase
, genMnemonics
, genXPubs
, getAccountKeyShared
, getFromResponse
, getSharedWallet
, getSharedWalletKey
Expand Down Expand Up @@ -174,6 +175,16 @@ spec = describe "SHARED_WALLETS" $ do
let (ApiAccountKeyShared bytes _) = getFromResponse id rKey
T.decodeUtf8 (hex bytes) `Expectations.shouldBe` accXPubDerived

aKey <-
getAccountKeyShared ctx wal (Just True)

verify aKey
[ expectResponseCode HTTP.status200
, expectField #format (`shouldBe` Extended)
]
let (ApiAccountKeyShared bytes' _) = getFromResponse id aKey
T.decodeUtf8 (hex bytes') `Expectations.shouldBe` accXPubDerived

it "SHARED_WALLETS_CREATE_02 - Create a pending shared wallet from root xprv" $ \ctx -> runResourceT $ do
m15txt <- liftIO $ genMnemonics M15
m12txt <- liftIO $ genMnemonics M12
Expand Down Expand Up @@ -244,8 +255,8 @@ spec = describe "SHARED_WALLETS" $ do
}
}
} |]
r <- postSharedWallet ctx Default payload
verify (second (\(Right (ApiSharedWallet (Right res))) -> Right res) r)
rPost <- postSharedWallet ctx Default payload
verify (second (\(Right (ApiSharedWallet (Right res))) -> Right res) rPost)
[ expectResponseCode HTTP.status201
, expectField
(#name . #getApiT . #getWalletName) (`shouldBe` "Shared Wallet")
Expand All @@ -262,6 +273,17 @@ spec = describe "SHARED_WALLETS" $ do
, expectField (#accountIndex . #getApiT) (`shouldBe` DerivationIndex 2147483658)
]

let wal = getFromResponse id rPost
aKey <-
getAccountKeyShared ctx wal (Just True)

verify aKey
[ expectResponseCode HTTP.status200
, expectField #format (`shouldBe` Extended)
]
let (ApiAccountKeyShared bytes' _) = getFromResponse id aKey
T.decodeUtf8 (hex bytes') `Expectations.shouldBe` accXPubTxt

it "SHARED_WALLETS_CREATE_04 - Create a pending shared wallet from account xpub" $ \ctx -> runResourceT $ do
(_, accXPubTxt):_ <- liftIO $ genXPubs 1
let payload = Json [json| {
Expand Down

0 comments on commit 9f93930

Please sign in to comment.