Skip to content
This repository has been archived by the owner on Mar 1, 2019. It is now read-only.

EOSWALLETS tests #334

Merged
merged 10 commits into from
Feb 18, 2019
Merged

EOSWALLETS tests #334

merged 10 commits into from
Feb 18, 2019

Conversation

piotr-iohk
Copy link
Contributor

@piotr-iohk piotr-iohk commented Feb 12, 2019

#

Overview

Comments

verify (response :: Either ClientError EosWallet)
[ expectJSONError $ case poolGap of
-1 -> "Error in $.addressPoolGap: Word8 is either floating or will cause over or underflow: -1.0"
_ -> "Error in $.addressPoolGap: Address pool gap should be in range [10..100]"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this error message Address pool gap should be in range [10..100]. I was expecting it also when providing -1 as addressPoolGap. Instead we have Word8 is either floating or will cause over or underflow: -1.0. Maybe we'd like to change it for consistency?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error in $.addressPoolGap: Word8 is either floating or will cause over or underflow: -1.0

msg is interesting one - I didn't expect to see something like this. For example when I try to manually create address pool gap with a negative number:

> AddressPoolGap (-1)

I get

    Literal -1 is out of the Word8 range 0..255

which makes sense as Word8 is defined in specified range.

Edit:
Aha - msg comes from Aeson and decoding a "-1" string into a Word8:

> import Data.Aeson
> eitherDecode "-1" :: Either String Word8
Left "Error in $: Word8 is either floating or will cause over or underflow: -1.0"

so everything is as expected here. So you will try to push your json to the api. First thing that api will do is it will try to decode this json into expected Haskell data type. This will immediatelly fail in this json decoding part as Word8 won't be able to decode "-1" and Aeson library will rise the exception. If the exception wasn't rased by underlying aeson lib, we would catch it and rise "Address pool gap should be in range [10..100]".

If we would like to rise only single exception for AddressPoolGap one could define custom FromJSON instance that works only for [10..100] (ie, [minBound..maxBound]) and not to use custom/generic aeson instance https://github.com/input-output-hk/cardano-wallet/blob/15dd91b05112c16be506129e5c00e88114f8bd16/src/Cardano/Wallet/Kernel/AddressPoolGap.hs#L33 . This would do the trick in our case:

instance FromJSON AddressPoolGap where
    parseJSON = parseJSON >=> \gap -> case mkAddressPoolGap gap of
        Left err -> fail $ toString $ sformat build $ bprint
        ("Address pool gap should be in range ["%int%".."%int%"].")
        (minBound @AddressPoolGap)
        (maxBound @AddressPoolGap)
        Right x  -> pure x

or something along these lines. Anyway if you think this would be nice to have please open a new ticket and we will discuss it with rest of the team. For now I don't think this is necessary nor urgent to have

@piotr-iohk
Copy link
Contributor Author

@denisshevchenko - I'll ask here as it is related to creating EOS wallets. In the API doc -> https://input-output-hk.github.io/cardano-wallet/#tag/Externally-Owned-Wallets%2Fpaths%2F~1api~1v1~1wallets~1externally-owned%2Fpost it is said Creates a new or restores an existing Wallet. Is there an option to restore or the mention about the restore should be actually removed from the doc?

@piotr-iohk piotr-iohk force-pushed the eos_wallets_integration_tests branch from ebad913 to 4313adb Compare February 12, 2019 14:59
@denisshevchenko
Copy link
Contributor

Is there an option to restore

@piotr-iohk Not yet.

@piotr-iohk piotr-iohk changed the title EOSWALLETS_CREATE tests EOSWALLETS tests Feb 13, 2019
@piotr-iohk piotr-iohk force-pushed the eos_wallets_integration_tests branch from 0975d41 to d6906a9 Compare February 13, 2019 08:47
verify (response :: Either ClientError EosWallet)
[ expectJSONError $ case poolGap of
-1 -> "Error in $.addressPoolGap: Word8 is either floating or will cause over or underflow: -1.0"
_ -> "Error in $.addressPoolGap: Address pool gap should be in range [10..100]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error in $.addressPoolGap: Word8 is either floating or will cause over or underflow: -1.0

msg is interesting one - I didn't expect to see something like this. For example when I try to manually create address pool gap with a negative number:

> AddressPoolGap (-1)

I get

    Literal -1 is out of the Word8 range 0..255

which makes sense as Word8 is defined in specified range.

Edit:
Aha - msg comes from Aeson and decoding a "-1" string into a Word8:

> import Data.Aeson
> eitherDecode "-1" :: Either String Word8
Left "Error in $: Word8 is either floating or will cause over or underflow: -1.0"

so everything is as expected here. So you will try to push your json to the api. First thing that api will do is it will try to decode this json into expected Haskell data type. This will immediatelly fail in this json decoding part as Word8 won't be able to decode "-1" and Aeson library will rise the exception. If the exception wasn't rased by underlying aeson lib, we would catch it and rise "Address pool gap should be in range [10..100]".

If we would like to rise only single exception for AddressPoolGap one could define custom FromJSON instance that works only for [10..100] (ie, [minBound..maxBound]) and not to use custom/generic aeson instance https://github.com/input-output-hk/cardano-wallet/blob/15dd91b05112c16be506129e5c00e88114f8bd16/src/Cardano/Wallet/Kernel/AddressPoolGap.hs#L33 . This would do the trick in our case:

instance FromJSON AddressPoolGap where
    parseJSON = parseJSON >=> \gap -> case mkAddressPoolGap gap of
        Left err -> fail $ toString $ sformat build $ bprint
        ("Address pool gap should be in range ["%int%".."%int%"].")
        (minBound @AddressPoolGap)
        (maxBound @AddressPoolGap)
        Right x  -> pure x

or something along these lines. Anyway if you think this would be nice to have please open a new ticket and we will discuss it with rest of the team. For now I don't think this is necessary nor urgent to have

"name": "My EOS Wallet"
}|]
verify (response :: Either ClientError EosWallet)
[ expectJSONError "Error in $.accounts[0]: When parsing the record accountPublicKeyWithIx of type Cardano.Wallet.API.V1.Types.AccountPublicKeyWithIx the key publicKey was not present."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm - these types of error checks will gratelly depend on aeson version (msg might be modified in aeson) and on naming of the module where the function is located (if someone changes name of the module or name of the function itself msg will change)

I guess its ok as a temp solution. What do you think @denisshevchenko @uroboros ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, phrase in expectJSONError is too long and specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the error messages Address pool gap should be in range [10..100] and Word8 is either floating or will cause over or underflow I'd be for having one consistent message and obviously the first one is more user friendly and informative. I'll create a ticket. This is actually observed for addressPoolGap and index fields for certain values outside their ranges...

depend on ... naming of the module where the function is located (if someone changes name of the module or name of the function itself msg will change)

makes sense, I'll shorten the messages. 👍

"name": "My EosWallet2"
}|]
verify (updResp :: Either ClientError EosWallet)
[ expectWalletError (UnknownError "UpdateEosWalletError")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is right error - right @denisshevchenko @uroboros ?

I believe we are missing case such as <|> try' @UpdateEosWalletError updateEosWalletError at https://github.com/input-output-hk/cardano-wallet/blob/develop/src/Cardano/Wallet/API/V1/ReifyWalletError.hs#L47

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in my local branch - will push after we merge #337 (which fixes some failures) and test the patch

@piotr-iohk
Copy link
Contributor Author

@akegalj I have created a ticket #342 and marked test EOSWALLETS_LIST_01, EOSWALLETS_LIST_02 - cannot get FO wallets with EOS endpoint with pendingWith. From my side it is ready to be merged.

@piotr-iohk piotr-iohk force-pushed the eos_wallets_integration_tests branch from 5435572 to 311f6eb Compare February 15, 2019 18:03
@denisshevchenko denisshevchenko merged commit 6f958e9 into develop Feb 18, 2019
@denisshevchenko denisshevchenko deleted the eos_wallets_integration_tests branch February 18, 2019 11:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants