Skip to content

Commit

Permalink
some swagger fixes and reuse of Script Arbitrary instance from cardan…
Browse files Browse the repository at this point in the history
…o-addresses

hlint
  • Loading branch information
paweljakubas committed Oct 30, 2020
1 parent 1071e78 commit 6459319
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/core/src/Cardano/Wallet/Api/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ instance ToJSON AnyAddress where
(EnterpriseDelegating, 0) -> [Bech32.humanReadablePart|addr_test|]
(RewardAccount, 0) -> [Bech32.humanReadablePart|stake_test|]
_ -> error "Wrong network tag in AnyAddress"
object [ "address" .= (String $ T.decodeUtf8 $ encode (EBech32 hrp) p)]
object [ "address" .= String (T.decodeUtf8 $ encode (EBech32 hrp) p) ]

instance MkSomeMnemonic sizes => FromJSON (ApiMnemonicT sizes)
where
Expand Down
38 changes: 19 additions & 19 deletions lib/core/test/unit/Cardano/Wallet/Api/TypesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ import Test.QuickCheck
( Arbitrary (..)
, Gen
, InfiniteList (..)
, Positive (..)
, applyArbitrary2
, applyArbitrary4
, arbitraryBoundedEnum
Expand All @@ -286,6 +287,7 @@ import Test.QuickCheck
, property
, scale
, shrinkIntegral
, sized
, vector
, vectorOf
, (.&&.)
Expand Down Expand Up @@ -985,25 +987,23 @@ instance Arbitrary ApiScript where
arbitrary = ApiScript . ApiT <$> arbitrary

instance Arbitrary Script where
arbitrary = do
reqAllGen <- do
n <- choose (1,4)
pure $ RequireAllOf <$> vector n
reqAnyGen <- do
n <- choose (1,4)
pure $ RequireAnyOf <$> vector n
reqMofNGen <- do
m <- choose (2,5)
n <- choose ((fromInteger $ toInteger m),7)
pure $ RequireSomeOf m <$> vector n
let reqSig =
(RequireSignatureOf . KeyHash . BS.pack) <$> replicateM 28 arbitrary
oneof
(replicate 15 reqSig ++
[ reqAllGen
, reqAnyGen
, reqMofNGen
])
arbitrary = Test.QuickCheck.scale (`div` 3) $ sized scriptTree
where
scriptTree 0 = RequireSignatureOf <$> arbitrary
scriptTree n = do
Positive m <- arbitrary
let n' = n `div` (m + 1)
scripts <- vectorOf m (scriptTree n')
atLeast <- choose (0, fromIntegral (m + 1))
elements
[ RequireAllOf scripts
, RequireAnyOf scripts
, RequireSomeOf atLeast scripts
]
shrink = genericShrink

instance Arbitrary KeyHash where
arbitrary = KeyHash . BS.pack <$> vectorOf 28 arbitrary

instance Arbitrary ApiPubKey where
arbitrary =
Expand Down
9 changes: 4 additions & 5 deletions specifications/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -355,20 +355,19 @@ x-script: &script
- any condition for which any list element' expectation is to be met for the condition to be valid
- some condition for which a minimal number of list elements' expectation is to be met for the condition to be valid
example:
0: "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt36ms"
1: { "all": [ "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt36ms"
- "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt36ms"
- { "all": [ "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt36ms"
, "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt37ms"] }
2: { "all": [ "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt36ms"
- { "all": [ "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt36ms"
, { "any" : [ "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt37ms"
, "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt38ms"] }
] }
3: { "all": [ "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt36ms"
- { "all": [ "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt36ms"
, { "some" : { "from" : [ "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt37ms"
, "script_vkh18srsxr3khll7vl3w9mqfu55n6wzxxlxj7qzr2mhnyreluzt38ms"]
, "at_least" : 2
}
} ] }
nullable: false
additionalProperties:
$ref: "#/components/schemas/ScriptValue"
Expand Down

0 comments on commit 6459319

Please sign in to comment.