Skip to content

Commit

Permalink
create separate SharedWallet integration test spec
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Apr 15, 2021
1 parent 289af78 commit 60fd608
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/core-integration/cardano-wallet-core-integration.cabal
Expand Up @@ -100,6 +100,7 @@ library
Test.Integration.Scenario.API.Shelley.Transactions
Test.Integration.Scenario.API.Shelley.Migrations
Test.Integration.Scenario.API.Shelley.Wallets
Test.Integration.Scenario.API.Shelley.SharedWallets
Test.Integration.Scenario.API.Network
Test.Integration.Scenario.CLI.Byron.Wallets
Test.Integration.Scenario.CLI.Byron.Addresses
Expand Down
25 changes: 22 additions & 3 deletions lib/core-integration/src/Test/Integration/Framework/DSL.hs
Expand Up @@ -74,6 +74,7 @@ module Test.Integration.Framework.DSL
, emptyWalletWith
, emptyByronWalletFromXPrvWith
, rewardWallet
, postSharedWallet

-- * Wallet helpers
, listFilteredWallets
Expand Down Expand Up @@ -214,6 +215,7 @@ import Cardano.Wallet.Api.Types
, ApiMaintenanceAction (..)
, ApiNetworkInformation
, ApiNetworkParameters (..)
, ApiSharedWallet (..)
, ApiStakePool
, ApiT (..)
, ApiTransaction
Expand Down Expand Up @@ -1298,7 +1300,6 @@ fixtureMultiAssetRandomWallet ctx = do
]
return (getFromResponse id rb)


fixtureMultiAssetIcarusWallet
:: forall n m.
( DecodeAddress n
Expand Down Expand Up @@ -1339,6 +1340,24 @@ fixtureMultiAssetIcarusWallet ctx = do
]
return (getFromResponse id rb)


postSharedWallet
:: (MonadIO m, MonadUnliftIO m)
=> Context
-> Headers
-> Payload
-> ResourceT m (HTTP.Status, Either RequestException ApiSharedWallet)
postSharedWallet ctx headers payload = snd <$> allocate create (free . snd)
where
create =
request @ApiSharedWallet ctx Link.postSharedWallet headers payload

free (Right (ApiSharedWallet (Left w))) = void $ request @Aeson.Value ctx
(Link.deleteSharedWallet w) Default Empty
free (Right (ApiSharedWallet (Right w))) = void $ request @Aeson.Value ctx
(Link.deleteSharedWallet w) Default Empty
free (Left _) = return ()

fixtureRawTx
:: Context
-> (Address, Natural)
Expand Down Expand Up @@ -1987,13 +2006,13 @@ listTransactions
-> Maybe UTCTime
-> Maybe SortOrder
-> m [ApiTransaction n]
listTransactions ctx wallet mStart mEnd mOrder = do
listTransactions ctx w mStart mEnd mOrder = do
r <- request @[ApiTransaction n] ctx path Default Empty
expectResponseCode HTTP.status200 r
let txs = getFromResponse id r
return txs
where
path = Link.listTransactions' @'Shelley wallet
path = Link.listTransactions' @'Shelley w
Nothing
(Iso8601Time <$> mStart)
(Iso8601Time <$> mEnd)
Expand Down
@@ -0,0 +1,68 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}

module Test.Integration.Scenario.API.Shelley.SharedWallets
( spec
) where

import Prelude

import Cardano.Wallet.Api.Types
( DecodeAddress, DecodeStakeAddress, EncodeAddress (..) )
import Cardano.Wallet.Primitive.AddressDerivation
( PaymentAddress )
import Cardano.Wallet.Primitive.AddressDerivation.Shelley
( ShelleyKey )
import Control.Monad.IO.Class
( liftIO )
import Control.Monad.Trans.Resource
( runResourceT )
import Test.Hspec
( SpecWith, describe )
import Test.Hspec.Extra
( it )
import Test.Integration.Framework.DSL
( Context (..)
, Headers (..)
, MnemonicLength (..)
, Payload (..)
, expectResponseCode
, fixturePassphrase
, genMnemonics
, json
, postSharedWallet
, verify
)

import qualified Network.HTTP.Types as HTTP

spec :: forall n.
( DecodeAddress n
, DecodeStakeAddress n
, EncodeAddress n
, PaymentAddress n ShelleyKey
) => SpecWith Context
spec = describe "SHARED_WALLETS" $ do
it "SHARED_WALLETS_CREATE_01 - Create a shared wallet" $ \ctx -> runResourceT $ do
m15 <- liftIO $ genMnemonics M15
m12 <- liftIO $ genMnemonics M12
let payload = Json [json| {
"name": "Shared Wallet",
"mnemonic_sentence": #{m15},
"mnemonic_second_factor": #{m12},
"passphrase": #{fixturePassphrase},
"address_pool_gap": 30
} |]
r <- postSharedWallet ctx Default payload
verify r
[ expectResponseCode HTTP.status201
]
1 change: 1 addition & 0 deletions lib/core/src/Cardano/Wallet/Api.hs
Expand Up @@ -120,6 +120,7 @@ module Cardano.Wallet.Api
, GetSharedWallet
, PatchSharedWalletInPayment
, PatchSharedWalletInDelegation
, DeleteSharedWallet

, Proxy_
, PostExternalTransaction
Expand Down
23 changes: 23 additions & 0 deletions lib/core/src/Cardano/Wallet/Api/Link.hs
Expand Up @@ -104,6 +104,10 @@ module Cardano.Wallet.Api.Link

, getCurrentSMASHHealth

-- * Shared Wallets
, postSharedWallet
, deleteSharedWallet

, PostWallet
, Discriminate
) where
Expand Down Expand Up @@ -675,6 +679,25 @@ getCurrentSMASHHealth'
getCurrentSMASHHealth' smash =
endpoint @Api.GetCurrentSMASHHealth (\mk -> mk (ApiT <$> smash))

--
-- Shared Wallets
--
postSharedWallet
:: (Method, Text)
postSharedWallet =
endpoint @Api.PostSharedWallet id

deleteSharedWallet
:: forall w.
( HasType (ApiT WalletId) w
)
=> w
-> (Method, Text)
deleteSharedWallet w =
endpoint @Api.DeleteSharedWallet (wid &)
where
wid = w ^. typed @(ApiT WalletId)

--
-- Internals
--
Expand Down
2 changes: 2 additions & 0 deletions lib/shelley/test/integration/Main.hs
Expand Up @@ -154,6 +154,7 @@ import qualified Test.Integration.Scenario.API.Shelley.HWWallets as HWWallets
import qualified Test.Integration.Scenario.API.Shelley.Migrations as Migrations
import qualified Test.Integration.Scenario.API.Shelley.Network as Network_
import qualified Test.Integration.Scenario.API.Shelley.Settings as Settings
import qualified Test.Integration.Scenario.API.Shelley.SharedWallets as SharedWallets
import qualified Test.Integration.Scenario.API.Shelley.StakePools as StakePools
import qualified Test.Integration.Scenario.API.Shelley.Transactions as Transactions
import qualified Test.Integration.Scenario.API.Shelley.Wallets as Wallets
Expand All @@ -180,6 +181,7 @@ main = withTestsSetup $ \testDir tracers -> do
ByronAddresses.spec @n
ByronCoinSelections.spec @n
Wallets.spec @n
SharedWallets.spec @n
ByronWallets.spec @n
HWWallets.spec @n
Migrations.spec @n
Expand Down

0 comments on commit 60fd608

Please sign in to comment.