Skip to content

Commit

Permalink
Merge branch 'paweljakubas/ADP-660/add-shared-wallet-endpoints' of ht…
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Stachyra committed Apr 14, 2021
2 parents 9e65a6c + 6af3f37 commit 86545a9
Show file tree
Hide file tree
Showing 35 changed files with 13,926 additions and 497 deletions.
1 change: 1 addition & 0 deletions lib/core-integration/cardano-wallet-core-integration.cabal
Original file line number Diff line number Diff line change
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
81 changes: 78 additions & 3 deletions lib/core-integration/src/Test/Integration/Framework/DSL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ module Test.Integration.Framework.DSL
, emptyWalletWith
, emptyByronWalletFromXPrvWith
, rewardWallet
, postSharedWallet
, deleteSharedWallet
, getSharedWallet
, patchSharedWallet

-- * Wallet helpers
, listFilteredWallets
Expand Down Expand Up @@ -214,6 +218,7 @@ import Cardano.Wallet.Api.Types
, ApiMaintenanceAction (..)
, ApiNetworkInformation
, ApiNetworkParameters (..)
, ApiSharedWallet (..)
, ApiStakePool
, ApiT (..)
, ApiTransaction
Expand Down Expand Up @@ -254,6 +259,8 @@ import Cardano.Wallet.Primitive.AddressDerivation.Icarus
( IcarusKey )
import Cardano.Wallet.Primitive.AddressDerivation.Shelley
( ShelleyKey )
import Cardano.Wallet.Primitive.AddressDiscovery.Script
( CredentialType (..) )
import Cardano.Wallet.Primitive.AddressDiscovery.Sequential
( coinTypeAda )
import Cardano.Wallet.Primitive.SyncProgress
Expand Down Expand Up @@ -1298,7 +1305,6 @@ fixtureMultiAssetRandomWallet ctx = do
]
return (getFromResponse id rb)


fixtureMultiAssetIcarusWallet
:: forall n m.
( DecodeAddress n
Expand Down Expand Up @@ -1339,6 +1345,75 @@ 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 ()

deleteSharedWallet
:: forall m.
( MonadIO m
, MonadUnliftIO m
)
=> Context
-> ApiSharedWallet
-> m (HTTP.Status, Either RequestException Value)
deleteSharedWallet ctx (ApiSharedWallet (Left w)) =
request @Aeson.Value ctx
(Link.deleteSharedWallet w) Default Empty
deleteSharedWallet ctx (ApiSharedWallet (Right w)) =
request @Aeson.Value ctx
(Link.deleteSharedWallet w) Default Empty

getSharedWallet
:: forall m.
( MonadIO m
, MonadUnliftIO m
)
=> Context
-> ApiSharedWallet
-> m (HTTP.Status, Either RequestException ApiSharedWallet)
getSharedWallet ctx (ApiSharedWallet (Left w)) = do
let link = Link.getSharedWallet w
request @ApiSharedWallet ctx link Default Empty
getSharedWallet ctx (ApiSharedWallet (Right w)) = do
let link = Link.getSharedWallet w
request @ApiSharedWallet ctx link Default Empty

patchEndpointEnding :: CredentialType -> Text
patchEndpointEnding = \case
Payment -> "payment-script-template"
Delegation -> "delegation-script-template"

patchSharedWallet
:: forall m.
( MonadIO m
, MonadUnliftIO m
)
=> Context
-> ApiSharedWallet
-> CredentialType
-> Payload
-> m (HTTP.Status, Either RequestException ApiSharedWallet)
patchSharedWallet ctx (ApiSharedWallet (Left w)) cred payload = do
let endpoint = "v2/shared-wallets" </> w ^. walletId </> patchEndpointEnding cred
request @ApiSharedWallet ctx ("PATCH", endpoint) Default payload
patchSharedWallet ctx (ApiSharedWallet (Right w)) cred payload = do
let endpoint = "v2/shared-wallets" </> w ^. walletId </> patchEndpointEnding cred
request @ApiSharedWallet ctx ("PATCH", endpoint) Default payload

fixtureRawTx
:: Context
-> (Address, Natural)
Expand Down Expand Up @@ -1987,13 +2062,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
32 changes: 32 additions & 0 deletions lib/core-integration/src/Test/Integration/Framework/TestData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ module Test.Integration.Framework.TestData
, errMsg403WrongIndex
, errMsg403OutputTokenBundleSizeExceedsLimit
, errMsg403OutputTokenQuantityExceedsLimit
, errMsg403WalletAlreadyActive
, errMsg403NoDelegationTemplate
, errMsg403KeyAlreadyPresent
, errMsg403NoSuchCosigner
) where

import Prelude
Expand Down Expand Up @@ -495,3 +499,31 @@ errMsg403OutputTokenQuantityExceedsLimit
, pretty quantityMaxBound
, "."
]

errMsg403WalletAlreadyActive :: String
errMsg403WalletAlreadyActive = mconcat
[ "It looks like you've tried to add a cosigner key for a "
, "shared wallet that is active. This can be done only for "
, "pending shared wallet."
]

errMsg403NoDelegationTemplate :: String
errMsg403NoDelegationTemplate = mconcat
[ "It looks like you've tried to add a cosigner key to "
, "a shared wallet's delegation template. This cannot be done for "
, "the wallet that does not define any delegation template."
]

errMsg403KeyAlreadyPresent :: Text -> String
errMsg403KeyAlreadyPresent cred = mconcat
[ "It looks like you've tried to add a cosigner key to a shared wallet's "
, unpack cred," template that is already ascribed to another cosigner. "
, "Please make sure to assign a different key to each cosigner."
]

errMsg403NoSuchCosigner :: Text -> Int -> String
errMsg403NoSuchCosigner cred cosigner = mconcat
[ "It looks like you've tried to add a cosigner key to a shared wallet's "
, unpack cred, " template to a non-existing cosigner index: "
, show cosigner, "."
]
Loading

0 comments on commit 86545a9

Please sign in to comment.