-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move {Encode,Decode}Address within backend-specific package #1677
Conversation
@@ -60,6 +94,109 @@ spec = do | |||
let toPoint' = toPoint gh epochLength | |||
toPoint' (fromTip' tip) === (getTipPoint tip) | |||
|
|||
describe "Hardware Ledger" $ do |
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.
Moved from Cardano.Wallet.Primitive.AddressDerivation.IcarusSpec
, "Ae2tdPwUPEZLU4TEkPMmkT2dfQ23YyKLFWXBwuxLi4rxF4kT6najwAi6APQ" | ||
, "Ae2tdPwUPEZBFKNnz2F1Bn5pLkhp2rm9byDAyW1JzN7ZUYSgRPqrH3Jgs88" | ||
] | ||
|
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.
Moved from Cardano.Wallet.Primitive.AddressDerivation.IcarusSpec
@@ -1425,77 +1412,6 @@ class EncodeAddress (n :: NetworkDiscriminant) where | |||
class DecodeAddress (n :: NetworkDiscriminant) where | |||
decodeAddress :: Text -> Either TextDecodingError Address | |||
|
|||
-- | Encode an 'Address' to a human-readable format. This produces two kinds of |
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.
Moved to Cardano.Wallet.Jormungandr.Compatibility
[ ( "NOT-AN-ADDRESS" | ||
, "Unable to decode Address: encoding is neither Bech32 nor Base58." | ||
) | ||
] |
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.
The generic malformed tests are no longer able to test errors related to the address encoding since it now depends on the underlying backend. So, negative tests are done in backend-specific tests suites on a per-case base .
@@ -383,8 +340,6 @@ spec = do | |||
httpApiDataRoundtrip $ Proxy @(ApiT AddressState) | |||
httpApiDataRoundtrip $ Proxy @Iso8601Time | |||
httpApiDataRoundtrip $ Proxy @(ApiT SortOrder) | |||
httpApiDataRoundtrip $ Proxy @(ApiT Address, Proxy 'Mainnet) | |||
httpApiDataRoundtrip $ Proxy @(ApiT Address, Proxy ('Testnet 0)) |
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.
Moved from Cardano.Wallet.Jormungandr.CompatibilitySpec
@@ -310,7 +268,6 @@ spec = do | |||
describe | |||
"can perform roundtrip JSON serialization & deserialization, \ | |||
\and match existing golden files" $ do | |||
jsonRoundtripAndGolden $ Proxy @(ApiAddress ('Testnet 0)) |
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.
Moved to Cardano.Wallet.Jormungandr.CompatibilitySpec
let msg = "Error in $: Unable to decode Address: \ | ||
\encoding is neither Bech32 nor Base58." | ||
Aeson.parseEither parseJSON [aesonQQ|"-----"|] | ||
`shouldBe` (Left @String @(ApiT Address, Proxy ('Testnet 0)) msg) |
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.
Moved to Cardano.Wallet.Jormungandr.CompatibilitySpec
@@ -569,130 +518,7 @@ spec = do | |||
parseUrlPiece "patate" | |||
`shouldBe` (Left @Text @(ApiT AddressState) msg) | |||
|
|||
describe "encodeAddress & decodeAddress (Mainnet)" $ do |
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.
Moved to Cardano.Wallet.Jormungandr.CompatibilitySpec
"addr1qn0e7zr89gafgauz9xu3m25cz5ugs0s4xhtxdhqsuca58r6ycclr\ | ||
\7sp2hlmqvhyywy266ghldvxn4p0adxn0esew6a423jkmxpdsc5d8n8hz07" | ||
|
||
describe "encodeAddress & decodeAddress (Testnet)" $ do |
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.
Moved to Cardano.Wallet.Jormungandr.CompatibilitySpec
-- new format. Faulty golden files should /not/ be commited. | ||
-- | ||
-- The directory `test/data/Cardano/Wallet/Api` is used. | ||
jsonRoundtripAndGolden |
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.
Extracted in test-utils
to be available from multiple packages.
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.
good move
-> [ByteString] | ||
-> Text | ||
-> SpecWith () | ||
goldenTestAddr _proxy pubkeys expected = it ("golden test: " <> T.unpack expected) $ do |
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.
extracted in test-utils to be available from multiple packages
] | ||
return (addr, Proxy) | ||
|
||
instance {-# OVERLAPS #-} Arbitrary (ApiT Address, Proxy ('Testnet 0)) 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.
instances moved to Cardano.Wallet.Jormungandr.CompatibilitySpec
genLegacyAddress | ||
:: Maybe ProtocolMagic | ||
-> Gen Address | ||
genLegacyAddress pm = do |
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.
Moved from Cardano.Wallet.Primitive.AddressDerivationSpec
for easier reuse
|
||
spec :: Spec | ||
spec = do | ||
describe "Golden Tests - Icarus' style addresses" $ do |
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.
Moved to Cardano.Wallet.Byron.CompatibilitySpec
@@ -119,154 +71,6 @@ spec = do | |||
it "paymentKeyFingerprint . liftPaymentAddress == pure" $ | |||
property prop_roundtripFingerprintLift | |||
|
|||
describe "Hardware Ledger" $ do |
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.
Moved to Cardano.Wallet.Byron.CompatibilitySpec
@@ -10,16 +10,12 @@ | |||
|
|||
module Cardano.Wallet.Primitive.AddressDerivationSpec | |||
( spec | |||
|
|||
-- * Generators | |||
, genAddress |
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.
Moved to Cardano.Wallet.Gen
|
||
-- * Generators | ||
, genAddress | ||
, genLegacyAddress |
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.
Moved to Cardano.Wallet.Jormungandr.CompatibilitySpec
import qualified Cardano.Wallet.Primitive.AddressDerivation.Jormungandr as Seq | ||
import qualified Cardano.Wallet.Primitive.AddressDerivation.Byron as Byron | ||
import qualified Cardano.Wallet.Primitive.AddressDerivation.Icarus as Icarus | ||
import qualified Cardano.Wallet.Primitive.AddressDerivation.Jormungandr as Jormungandr |
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.
|
||
{------------------------------------------------------------------------------- | ||
Address Encoding / Decoding | ||
-------------------------------------------------------------------------------} |
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.
👇 Moved from Cardano.Wallet.Api.Types
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.
good good
|
||
spec :: Spec | ||
spec = pure () | ||
spec = do |
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.
👇 Moved from Cardano.Wallet.Api.TypesSpec
So that each package can actually define how addresses should be parsed from the API, and provide different rules for decoding addresses for Byron, Jormungandr and Shelley.
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.
logical address-related code reshuffling (would be easier to decouple jormungandr as separate repo in the future thanks to that). Moves specific backend code from core to backends directories. My only question is : why all lib/core/test/data/Cardano/Wallet/Api/* was regenerated and included in this PR ?
So that the template haskell splice 'getTestDataDir' can be evaluated within the context of the package actually running the test, instead of the context of 'test-utils'.
5656699
to
f2a8ff0
Compare
bors r+ |
1677: Move {Encode,Decode}Address within backend-specific package r=KtorZ a=KtorZ # Issue Number <!-- Put here a reference to the issue this PR relates to and which requirements it tackles --> #1672 # Overview <!-- Detail in a few bullet points the work accomplished in this PR --> - 6845b48 📍 **move Aeson and HttpApiData roundtrip functions to test-utils** - bc83f45 📍 **relocate {Encode,Decode}Address instances to backend-specific packages** So that each package can actually define how addresses should be parsed from the API, and provide different rules for decoding addresses for Byron, Jormungandr and Shelley. - STILL TODO: encoding / decoding in Shelley (which should be similar to approach used in Jörmungandr, but with Shelley address decoders instead). # Comments <!-- Additional comments or screenshots to attach if any --> Big diff as I had to re-generate a lot of the golden test files for the API since the address encoding now depends on the chosen backend. This consequently fixes an "unreported issue" where Jörmungandr addresses would be accepted by cardano-wallet-byron despite being totally invalid. Also, I re-located many tests in backend-specific package if they were actually testing things related to the encoding. <!-- Don't forget to: ✓ Self-review your changes to make sure nothing unexpected slipped through ✓ Assign yourself to the PR ✓ Assign one or several reviewer(s) ✓ Once created, link this PR to its corresponding ticket ✓ Assign the PR to a corresponding milestone ✓ Acknowledge any changes required to the Wiki --> Co-authored-by: KtorZ <[email protected]> Co-authored-by: IOHK <[email protected]>
Build failed |
Byron addresses have no reason to mention bech32 actually
bors r+ |
Build succeeded |
Issue Number
#1672
Overview
6845b48
📍 move Aeson and HttpApiData roundtrip functions to test-utils
bc83f45
📍 relocate {Encode,Decode}Address instances to backend-specific packages
So that each package can actually define how addresses should be parsed from the API, and provide different rules for decoding addresses for Byron, Jormungandr and Shelley.
STILL TODO: encoding / decoding in Shelley (which should be similar to approach used in Jörmungandr, but with Shelley address decoders instead).
Comments
Big diff as I had to re-generate a lot of the golden test files for the API since the address encoding now depends on the chosen backend. This consequently fixes an "unreported issue" where Jörmungandr addresses would be accepted by cardano-wallet-byron despite being totally invalid.
Also, I re-located many tests in backend-specific package if they were actually testing things related to the encoding.