Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 85edc58

Browse files
authored
Set up scaffolding for node API (#3788)
* Extract types and functions upstream for the Node's API * Sort the dependencies list * Reunite ApplicationName and SoftwareVersion Arbitrary orphans * Clean up dependencies * Remove dead code * Rename `Serokell` import qualification to `Aeson` * Use a hardcoded example for SyncPercentage as the unsafePerformIO broke golden tests when it moved beyond the module boundary. * add wallet db to gitignore
1 parent 89374a0 commit 85edc58

File tree

37 files changed

+1508
-1336
lines changed

37 files changed

+1508
-1336
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ wallet-new/bench/results/*.txt
9898
# wallet web API golden tests
9999
wallet-new/test/golden/*.txt.new
100100

101+
wallet/test/wallet-db-1.1.1/open.lock
102+
101103
# cardano-state-* for wallet data
102104
cardano-state-*
103105
state-*

chain/cardano-sl-chain.cabal

+6-4
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ library
154154
Pos.Chain.Update.Vote
155155

156156
build-depends: base
157-
, Cabal
158157
, aeson
159158
, aeson-options
160159
, array
161160
, bytestring
161+
, Cabal
162162
, canonical-json
163163
, cardano-sl-binary
164164
, cardano-sl-core
@@ -178,26 +178,28 @@ library
178178
, filepath
179179
, fmt >= 0.4
180180
, formatting
181+
, formatting
181182
, free
183+
, generic-arbitrary
182184
, hashable
183185
, lens
184186
, lrucache
185187
, memory
186-
, mtl
187188
, mmorph
188189
, mono-traversable
190+
, mtl
189191
, neat-interpolation
190192
, parsec
191193
, plutus-prototype
194+
, QuickCheck
195+
, reflection
192196
, safecopy
193197
, safe-exceptions
194198
, serokell-util
195-
, reflection
196199
, template-haskell
197200
, text
198201
, time
199202
, time-units
200-
, formatting
201203
, transformers
202204
, universum
203205
, unordered-containers

chain/src/Pos/Chain/Update/ApplicationName.hs

+11
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import Control.Monad.Except (MonadError (throwError))
1010
import Data.Aeson (FromJSON (..))
1111
import Data.Aeson.TH (defaultOptions, deriveToJSON)
1212
import Data.Char (isAscii)
13+
import Data.List ((!!))
1314
import Data.SafeCopy (base, deriveSafeCopySimple)
1415
import qualified Data.Text as T
16+
import Test.QuickCheck
1517

1618
import Pos.Binary.Class (Bi (..))
1719

@@ -40,6 +42,15 @@ checkApplicationName (ApplicationName appName)
4042
applicationNameMaxLength :: Integral i => i
4143
applicationNameMaxLength = 12
4244

45+
instance Arbitrary ApplicationName where
46+
arbitrary =
47+
ApplicationName .
48+
toText . map selectAlpha . take applicationNameMaxLength <$>
49+
arbitrary
50+
where
51+
selectAlpha n = alphabet !! (n `mod` length alphabet)
52+
alphabet = "-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
53+
4354
deriveToJSON defaultOptions ''ApplicationName
4455

4556
deriveSafeCopySimple 0 'base ''ApplicationName

chain/src/Pos/Chain/Update/SoftwareVersion.hs

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import Data.SafeCopy (base, deriveSafeCopySimple)
1515
import Formatting (bprint, int, stext, (%))
1616
import qualified Formatting.Buildable as Buildable
1717
import qualified Prelude
18+
import Test.QuickCheck
19+
import Test.QuickCheck.Arbitrary.Generic (genericArbitrary,
20+
genericShrink)
1821

1922
import Pos.Util.Some (Some, liftLensSome)
2023

@@ -41,6 +44,10 @@ instance Hashable SoftwareVersion
4144

4245
instance NFData SoftwareVersion
4346

47+
instance Arbitrary SoftwareVersion where
48+
arbitrary = genericArbitrary
49+
shrink = genericShrink
50+
4451
deriveSafeCopySimple 0 'base ''SoftwareVersion
4552

4653
-- | A software version is valid iff its application name is valid.

chain/test/Test/Pos/Chain/Update/Arbitrary.hs

+3-19
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,16 @@ module Test.Pos.Chain.Update.Arbitrary
99
import Universum
1010

1111
import qualified Data.HashMap.Strict as HM
12-
import Data.List ((!!))
1312
import Test.QuickCheck (Arbitrary (..), Gen, elements, frequency,
1413
listOf, listOf1)
1514
import Test.QuickCheck.Arbitrary.Generic (genericArbitrary,
1615
genericShrink)
1716

18-
import Pos.Chain.Update (ApplicationName (..), BlockVersion (..),
19-
BlockVersionData (..), BlockVersionModifier,
20-
SoftforkRule (..), SoftwareVersion (..), SystemTag (..),
17+
import Pos.Chain.Update (BlockVersion (..), BlockVersionData (..),
18+
BlockVersionModifier, SoftforkRule (..), SystemTag (..),
2119
UpdateData (..), UpdatePayload (..), UpdateProposal,
2220
UpdateProposalToSign (..), UpdateVote (..),
23-
VoteState (..), applicationNameMaxLength,
24-
mkUpdateProposalWSign, mkUpdateVote)
21+
VoteState (..), mkUpdateProposalWSign, mkUpdateVote)
2522
import Pos.Core.Attributes (mkAttributes)
2623
import Pos.Crypto (ProtocolMagic, fakeSigner)
2724

@@ -39,23 +36,10 @@ instance Arbitrary BlockVersionData where
3936
arbitrary = genericArbitrary
4037
shrink = genericShrink
4138

42-
instance Arbitrary ApplicationName where
43-
arbitrary =
44-
ApplicationName .
45-
toText . map selectAlpha . take applicationNameMaxLength <$>
46-
arbitrary
47-
where
48-
selectAlpha n = alphabet !! (n `mod` length alphabet)
49-
alphabet = "-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
50-
5139
instance Arbitrary BlockVersion where
5240
arbitrary = genericArbitrary
5341
shrink = genericShrink
5442

55-
instance Arbitrary SoftwareVersion where
56-
arbitrary = genericArbitrary
57-
shrink = genericShrink
58-
5943
instance Arbitrary BlockVersionModifier where
6044
arbitrary = genericArbitrary
6145
shrink = genericShrink

core/cardano-sl-core.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ library
137137
, fmt
138138
, formatting
139139
, hashable
140+
, http-api-data
140141
, lens
141142
, parsec
142143
, memory

core/src/Pos/Core/Common/Coin.hs

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import Formatting (Format, bprint, build, int, (%))
3434
import qualified Formatting.Buildable
3535
import qualified Text.JSON.Canonical as Canonical (FromJSON (..),
3636
ReportSchemaErrors, ToJSON (..))
37+
import Web.HttpApiData (FromHttpApiData (..), ToHttpApiData (..))
3738

3839
import Pos.Binary.Class (Bi (..))
3940
import Pos.Util.Json.Canonical ()
@@ -68,6 +69,15 @@ instance Aeson.FromJSON Coin where
6869
instance Aeson.ToJSON Coin where
6970
toJSON = Aeson.toJSON . unsafeGetCoin
7071

72+
instance FromHttpApiData Coin where
73+
parseUrlPiece p = do
74+
c <- Coin <$> parseQueryParam p
75+
checkCoin c
76+
pure c
77+
78+
instance ToHttpApiData Coin where
79+
toQueryParam = pretty . coinToInteger
80+
7181
-- | Maximal possible value of 'Coin'.
7282
maxCoinVal :: Word64
7383
maxCoinVal = 45000000000000000

lib/cardano-sl.cabal

+16-4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ library
6464
Pos.Network.Block.Types
6565
Pos.Network.Block.WorkMode
6666

67+
-- Node management API
68+
Pos.Node.API
69+
6770
-- cardano-sl-client & cardano-sl-generator
6871
Pos.Communication.Limits
6972
Pos.Communication.Types
@@ -113,6 +116,11 @@ library
113116
Test.Pos.Configuration
114117

115118
Pos.Util.Servant
119+
Pos.Util.Jsend
120+
Pos.Util.UnitsOfMeasure
121+
Pos.Util.Pagination
122+
Pos.Util.Example
123+
Pos.Util.KnownSymbols
116124

117125

118126
other-modules:
@@ -133,13 +141,12 @@ library
133141
Pos.Communication.Server
134142

135143
build-depends: base
136-
, QuickCheck
137-
, async
138144
, aeson >= 0.11.2.1
139145
, aeson-options
140-
, async
141146
, ansi-terminal
142147
, ansi-wl-pprint
148+
, async
149+
, base64-bytestring
143150
, bytestring
144151
, canonical-json
145152
, cardano-sl-binary
@@ -165,8 +172,11 @@ library
165172
, filelock >= 0.1.0.1
166173
, filepath
167174
, formatting
175+
, formatting
168176
, generic-arbitrary
177+
, generics-sop
169178
, hspec
179+
, http-api-data
170180
, http-client
171181
, http-client-tls
172182
, http-conduit
@@ -183,6 +193,8 @@ library
183193
, optparse-applicative
184194
, parsec
185195
, pvss
196+
, QuickCheck
197+
, quickcheck-instances
186198
, random
187199
, reflection
188200
, safe-exceptions
@@ -194,10 +206,10 @@ library
194206
, servant-swagger
195207
, stm
196208
, streaming-commons
209+
, swagger2
197210
, tagged
198211
, template-haskell
199212
, text
200-
, formatting
201213
, time
202214
, time-units
203215
, tls

0 commit comments

Comments
 (0)