Skip to content

Commit 6ee1950

Browse files
author
Piotr Stachyra
committed
Better error message when trying to generate address on icarus wallet.
1 parent cd1e1e7 commit 6ee1950

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

lib/byron/test/integration/Test/Integration/Byron/Scenario/API/Addresses.hs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,14 @@ scenario_ADDRESS_CREATE_02 = it title $ \ctx -> do
172172
w <- emptyIcarusWallet ctx
173173
let payload = Json [json| { "passphrase": "Secure Passphrase" }|]
174174
r <- request @(ApiAddress n) ctx (Link.postRandomAddress w) Default payload
175-
verify r [ expectResponseCode @IO HTTP.status403 ]
175+
verify r
176+
[ expectResponseCode @IO HTTP.status403
177+
, expectErrorMessage
178+
"I cannot derive new address for this wallet type.\
179+
\ Make sure to use Byron random wallet id."
180+
]
176181
where
177-
title = "ADDRESS_CREATE_02 - Creation if forbidden on Icarus wallets"
182+
title = "ADDRESS_CREATE_02 - Creation is forbidden on Icarus wallets"
178183

179184
scenario_ADDRESS_CREATE_03
180185
:: forall (n :: NetworkDiscriminant) t.
@@ -250,6 +255,9 @@ scenario_ADDRESS_CREATE_06 = it title $ \ctx -> do
250255
r0 <- request @(ApiAddress n) ctx (Link.postRandomAddress w) Default payload
251256
verify r0 [ expectResponseCode @IO HTTP.status201 ]
252257
r1 <- request @(ApiAddress n) ctx (Link.postRandomAddress w) Default payload
253-
verify r1 [ expectResponseCode @IO HTTP.status409 ]
258+
verify r1
259+
[ expectResponseCode @IO HTTP.status409
260+
, expectErrorMessage "I already know of such address."
261+
]
254262
where
255263
title = "ADDRESS_CREATE_06 - Cannot create an address that already exists"

lib/core/src/Cardano/Wallet.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,7 @@ data ErrCreateRandomAddress
17641764
= ErrIndexAlreadyExists (Index 'Hardened 'AddressK)
17651765
| ErrCreateAddrNoSuchWallet ErrNoSuchWallet
17661766
| ErrCreateAddrWithRootKey ErrWithRootKey
1767+
| ErrCreateAddressNotAByronWallet
17671768
deriving (Generic, Eq, Show)
17681769

17691770
{-------------------------------------------------------------------------------

lib/core/src/Cardano/Wallet/Api/Server.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ byronServer byron icarus ntp =
702702
byronAddresses =
703703
(\wid s -> withLegacyLayer wid
704704
(byron, postRandomAddress byron wid s)
705-
(icarus, throwError err403)
705+
(icarus, liftHandler $ throwE ErrCreateAddressNotAByronWallet)
706706
)
707707
:<|> (\wid s -> withLegacyLayer wid
708708
(byron , listAddresses byron (const pure) wid s)
@@ -2381,6 +2381,11 @@ instance LiftHandler ErrCreateRandomAddress where
23812381
[ "I cannot derive a new unused address #", pretty (fromEnum ix)
23822382
, " because I already know of such address."
23832383
]
2384+
ErrCreateAddressNotAByronWallet ->
2385+
apiError err403 InvalidWalletType $ mconcat
2386+
[ "I cannot derive new address for this wallet type."
2387+
, " Make sure to use Byron random wallet id."
2388+
]
23842389

23852390
instance LiftHandler (Request, ServerError) where
23862391
handler (req, err@(ServerError code _ body headers))

lib/core/src/Cardano/Wallet/Api/Types.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ data ApiErrorCode
629629
| NotImplemented
630630
| WalletNotResponding
631631
| AddressAlreadyExists
632+
| InvalidWalletType
632633
deriving (Eq, Generic, Show)
633634

634635
-- | Defines a point in time that can be formatted as and parsed from an

0 commit comments

Comments
 (0)