-
Notifications
You must be signed in to change notification settings - Fork 631
[CO-413] Removing wallet-new/src/Cardano/Wallet/Orphans* #3707
[CO-413] Removing wallet-new/src/Cardano/Wallet/Orphans* #3707
Conversation
…acy-and-v0 [CO-394] Remove Legacy* and V0* stuff
Also move MnemonicSpec.hs
- Remove references to V0 API - Use RecordWildCards instead of huge tuple
It had a laudable goal, was mangled and eventually bit-rotted. It's not used anymore and heavily rely on V0 and legacy data-layer code. R.I.P
…emonic [CO-373] Move `[email protected]` to `[email protected]`
…et-dep [CO-403] Remove `wallet` dependency from `Cardano/Wallet/Server/Plugins.hs`
[CO-404] Remove old wallet types from Example
…-api-types [CO-405] Remove old wallet code from API.V1.Types
[CO-406] Remove swagger import
We want to remove `wallet` as a dependency to `wallet-new`. This commit also moves `WAddressMeta` to `Cardano.Wallet.API.V1.Types`.
….hs from wallet-new [CO-380] Placate hlint
…tion-types' into CO-372/TheGreatCleanup
…-part-2 [CO-408] Tests and minor fixes related to Cardano.Wallet.Kernel.Decrypt
In the logs of integration tests (https://hydra.iohk.io/build/267893/log) I have:
Maybe it is because we do not have this included: #3704 ??? |
@@ -321,7 +322,8 @@ instance Buildable (SecureLog a) => Buildable (SecureLog (V1 a)) where | |||
instance (Buildable a, Buildable b) => Buildable (a, b) where | |||
build (a, b) = bprint ("("%build%", "%build%")") a b | |||
|
|||
|
|||
instance Buildable Version where | |||
build v = bprint shown v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 Where does that come from? Why using the underlying Show
instance here, that feels wrong.
Plus, it's another wild orphan as we are supposed to removed them 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Frankly speaking I got it from:
wallet/src/Pos/Wallet/Web/ClientTypes/Types.hs
675:instance Buildable Version where
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shown
is from Formatting(shown)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, this I understand ^.^ ... My question was more like: Why do we need this instance in a first place? Where is this Version
used?
If it's only in:
-- | The @static@ settings for this wallet node. In particular, we could group
-- here protocol-related settings like the slot duration, the transaction max size,
-- the current software version running on the node, etc.
data NodeSettings = NodeSettings {
setSlotDuration :: !SlotDuration
, setSoftwareInfo :: !(V1 Core.SoftwareVersion)
, setProjectVersion :: !Version
, setGitRevision :: !Text
} deriving (Show, Eq, Generic)
I'd rather stick a V1 Version
here and define a non-orphan instance for V1 Version
. This shouldn't break much thing and following the compiler steps will be easy.
parseUrlPiece p = do | ||
c <- Core.Coin <$> parseQueryParam p | ||
Core.checkCoin c | ||
pure c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We gotta need a roundtrip Aeson tests for that one 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
certainly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is already in wallet-new/test/MarshallingSpec.hs
line 95:
httpApiDataRoundtripProp @Core.Coin Proxy
but we are missing this one (although have aesonRoundtripProp @(V1 Core.Coin) Proxy
):
aesonRoundtripProp @Core.Coin Proxy
But if we test aeson roundtrips of V1 Something
do we need to check aeson roundtrips of Something
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant the httpAPIData
round trip of course :/ ...
I didn't realize at first this was also (again) an orphan instance. I think we want instances to be on V1 Core.Coin
here (like the others above). In such case (as for aeson instances, there's no point of doing a rountrip test on the non-wrapped type (Core.Coin
) itself, because we do want to test and use the wrapped instance. And chances are that there's not even an instance defined for the unwrapped type, which is good.
May you do this change 🙏 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will be addressed in https://iohk.myjetbrains.com/youtrack/issue/CO-422 for reasons specified therein
@@ -3271,3 +3282,6 @@ instance HasDiagnostic WalletError where | |||
"msg" | |||
RequestThrottled{} -> | |||
"microsecondsUntilRetry" | |||
|
|||
instance Arbitrary NoContent where | |||
arbitrary = pure NoContent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meh, still one orphan exchanged for another 😞 ...
Would it be too much work to go for a newtype here, or at leat pin-point the place where it's actually needed ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[7 of 9] SwaggerSpec
/home/pawel/IOHK/cardano-sl/wallet-new/test/SwaggerSpec.hs:57:13: error:
• No instance for (Arbitrary NoContent)
arising from a use of ‘validateEveryToJSON'’
• In the second argument of ‘($)’, namely
‘validateEveryToJSON' (Proxy @V1.API)’
In the second argument of ‘($)’, namely
‘describe "(V1) ToJSON matches ToSchema"
$ validateEveryToJSON' (Proxy @V1.API)’
In a stmt of a 'do' block:
parallel
$ describe "(V1) ToJSON matches ToSchema"
$ validateEveryToJSON' (Proxy @V1.API)
|
57 | validateEveryToJSON' (Proxy @ V1.API)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arbitrary instances should live with their type definitions IMO.
Otherwise, orphan arbitrary instances are one of the few justifiable ones, even to the Anti Orphan Squad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. It seems to be actually the "accepted pattern" here (in IOHK) to have orphan Arbitrary instances defined in test code only (even though, I tend to prefer having everything about a type defined next to the type itself).
In that specific case, since we need this Arbitrary only in the SwaggerSpec, let's make it an orphan instance there and not in V1.Types
.
ebde06f
to
bbb1543
Compare
304b920
to
8c4fc47
Compare
[CO-413] Relocating NoContent instance and adopt
Summary:
|
parseJSON (String v) = case readP_to_S parseVersion (T.unpack v) of | ||
(reverse -> ((ver,_):_)) -> pure (V1 ver) | ||
_ -> mempty | ||
parseJSON x = typeMismatch "Not a valid Version" x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's with the reverse
😕 ?
parseJSON (String v) = case readP_to_S parseVersion (T.unpack v) of
[(ver, _)] -> pure (V1 ver)
_ -> mempty
Isn't that enough ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prelude> import Data.Version
Prelude Data.Version> let v = makeVersion [1,2,3]
Prelude Data.Version> v
Version {versionBranch = [1,2,3], versionTags = []}
Prelude Data.Version> import Text.ParserCombinators.ReadP
Prelude Data.Version Text.ParserCombinators.ReadP> let out = readP_to_S parseVersion (showVersion v)
Prelude Data.Version Text.ParserCombinators.ReadP> out
[(Version {versionBranch = [1], versionTags = []},".2.3"),(Version {versionBranch = [1,2], versionTags = []},".3"),(Version {versionBranch = [1,2,3], versionTags = []},"")]
I need the last element. And I can have also [1,2] - hence the need to pattern match against the last element in the list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arf. Okay.
parseJSON x = typeMismatch "Not a valid Version" x | ||
|
||
instance Arbitrary (V1 Version) where | ||
arbitrary = fmap V1 arbitrary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does the Arbitrary Version
comes from ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ho :o !
That's a surprise. Great 🎉
Approving 👍 |
Description
Removing :
and adapting the rest code to work as before.
Linked issue
https://iohk.myjetbrains.com/youtrack/issue/CO-413
Type of change
Developer checklist
Testing checklist
QA Steps
Screenshots (if available)