1
- import std/ httpclient
2
1
import std/ times
3
2
import pkg/ ethers
4
- import pkg/ codex/ manifest
5
3
import pkg/ codex/ conf
6
4
import pkg/ codex/ contracts
7
- from pkg/ codex/ stores/ repostore/ types import DefaultQuotaBytes
8
5
import ../ asynctest
9
6
import ../ checktest
10
7
import ../ examples
11
8
import ../ codex/ examples
12
9
import ./ codexconfig
13
- import ./ codexprocess
10
+ import ./ codexclient
11
+ import ./ multinodes
14
12
15
- from ./ multinodes import Role , getTempDirName, jsonRpcProviderUrl, nextFreePort
13
+ multinodesuite " Rest API validation" :
14
+ let config = NodeConfigs (clients: CodexConfigs .init (nodes = 1 ).some)
15
+ var client: CodexClient
16
16
17
- # This suite allows to run fast the basic rest api validation.
18
- # It starts only one node for all the checks in order to speed up
19
- # the execution.
20
- asyncchecksuite " Rest API validation" :
21
- var node: CodexProcess
22
- var config = CodexConfigs .init (nodes = 1 ).configs[0 ]
23
- let starttime = now ().format (" yyyy-MM-dd'_'HH:mm:ss" )
24
- let nodexIdx = 0
25
- let datadir = getTempDirName (starttime, Role .Client , nodexIdx)
17
+ setup:
18
+ client = clients ()[0 ].client
26
19
27
- config.addCliOption (" --api-port" , $ (waitFor nextFreePort (8081 )))
28
- config.addCliOption (" --data-dir" , datadir)
29
- config.addCliOption (" --nat" , " none" )
30
- config.addCliOption (" --listen-addrs" , " /ip4/127.0.0.1/tcp/0" )
31
- config.addCliOption (" --disc-port" , $ (waitFor nextFreePort (8081 )))
32
- config.addCliOption (StartUpCmd .persistence, " --eth-provider" , jsonRpcProviderUrl)
33
- config.addCliOption (StartUpCmd .persistence, " --eth-account" , $ EthAddress .example)
34
-
35
- node =
36
- waitFor CodexProcess .startNode (config.cliArgs, config.debugEnabled, $ Role .Client )
37
-
38
- waitFor node.waitUntilStarted ()
39
-
40
- let client = node.client ()
41
-
42
- test " should return 422 when attempting delete of non-existing dataset" :
20
+ test " should return 422 when attempting delete of non-existing dataset" , config:
43
21
let data = await RandomChunker .example (blocks = 2 )
44
22
let cid = (await client.upload (data)).get
45
23
let duration = 100 .uint64
@@ -58,7 +36,7 @@ asyncchecksuite "Rest API validation":
58
36
check responseBefore.status == 422
59
37
check (await responseBefore.body) == " Tolerance needs to be bigger then zero"
60
38
61
- test " request storage fails for datasets that are too small" :
39
+ test " request storage fails for datasets that are too small" , config :
62
40
let cid = (await client.upload (" some file contents" )).get
63
41
let response = (
64
42
await client.requestStorageRaw (
@@ -77,7 +55,7 @@ asyncchecksuite "Rest API validation":
77
55
" Dataset too small for erasure parameters, need at least " &
78
56
$ (2 * DefaultBlockSize .int ) & " bytes"
79
57
80
- test " request storage fails if nodes and tolerance aren't correct" :
58
+ test " request storage fails if nodes and tolerance aren't correct" , config :
81
59
let data = await RandomChunker .example (blocks = 2 )
82
60
let cid = (await client.upload (data)).get
83
61
let duration = 100 .uint64
@@ -101,7 +79,7 @@ asyncchecksuite "Rest API validation":
101
79
check (await responseBefore.body) ==
102
80
" Invalid parameters: parameters must satify `1 < (nodes - tolerance) ≥ tolerance`"
103
81
104
- test " request storage fails if tolerance > nodes (underflow protection)" :
82
+ test " request storage fails if tolerance > nodes (underflow protection)" , config :
105
83
let data = await RandomChunker .example (blocks = 2 )
106
84
let cid = (await client.upload (data)).get
107
85
let duration = 100 .uint64
@@ -122,21 +100,21 @@ asyncchecksuite "Rest API validation":
122
100
check responseBefore.status == 422
123
101
check (await responseBefore.body) == " Tolerance needs to be bigger then zero"
124
102
125
- test " upload fails if content disposition contains bad filename" :
103
+ test " upload fails if content disposition contains bad filename" , config :
126
104
let headers = @ [(" Content-Disposition" , " attachment; filename=\" exam*ple.txt\" " )]
127
105
let response = await client.uploadRaw (" some file contents" , headers)
128
106
129
107
check response.status == 422
130
108
check (await response.body) == " The filename is not valid."
131
109
132
- test " upload fails if content type is invalid" :
110
+ test " upload fails if content type is invalid" , config :
133
111
let headers = @ [(" Content-Type" , " hello/world" )]
134
112
let response = await client.uploadRaw (" some file contents" , headers)
135
113
136
114
check response.status == 422
137
115
check (await response.body) == " The MIME type 'hello/world' is not valid."
138
116
139
- test " updating non-existing availability" :
117
+ test " updating non-existing availability" , config :
140
118
let nonExistingResponse = await client.patchAvailabilityRaw (
141
119
AvailabilityId .example,
142
120
duration = 100 .uint64 .some,
@@ -145,7 +123,7 @@ asyncchecksuite "Rest API validation":
145
123
)
146
124
check nonExistingResponse.status == 404
147
125
148
- test " updating availability - freeSize is not allowed to be changed" :
126
+ test " updating availability - freeSize is not allowed to be changed" , config :
149
127
let availability = (
150
128
await client.postAvailability (
151
129
totalSize = 140000 .uint64 ,
@@ -159,7 +137,7 @@ asyncchecksuite "Rest API validation":
159
137
check freeSizeResponse.status == 422
160
138
check " not allowed" in (await freeSizeResponse.body)
161
139
162
- test " creating availability above the node quota returns 422" :
140
+ test " creating availability above the node quota returns 422" , config :
163
141
let response = await client.postAvailabilityRaw (
164
142
totalSize = 24000000000 .uint64 ,
165
143
duration = 200 .uint64 ,
@@ -170,7 +148,7 @@ asyncchecksuite "Rest API validation":
170
148
check response.status == 422
171
149
check (await response.body) == " Not enough storage quota"
172
150
173
- test " updating availability above the node quota returns 422" :
151
+ test " updating availability above the node quota returns 422" , config :
174
152
let availability = (
175
153
await client.postAvailability (
176
154
totalSize = 140000 .uint64 ,
@@ -186,7 +164,7 @@ asyncchecksuite "Rest API validation":
186
164
check response.status == 422
187
165
check (await response.body) == " Not enough storage quota"
188
166
189
- test " creating availability when total size is zero returns 422" :
167
+ test " creating availability when total size is zero returns 422" , config :
190
168
let response = await client.postAvailabilityRaw (
191
169
totalSize = 0 .uint64 ,
192
170
duration = 200 .uint64 ,
@@ -197,7 +175,7 @@ asyncchecksuite "Rest API validation":
197
175
check response.status == 422
198
176
check (await response.body) == " Total size must be larger then zero"
199
177
200
- test " updating availability when total size is zero returns 422" :
178
+ test " updating availability when total size is zero returns 422" , config :
201
179
let availability = (
202
180
await client.postAvailability (
203
181
totalSize = 140000 .uint64 ,
@@ -212,7 +190,7 @@ asyncchecksuite "Rest API validation":
212
190
check response.status == 422
213
191
check (await response.body) == " Total size must be larger then zero"
214
192
215
- test " creating availability when total size is negative returns 422" :
193
+ test " creating availability when total size is negative returns 422" , config :
216
194
let json =
217
195
%* {
218
196
" totalSize" : " -1" ,
@@ -225,7 +203,7 @@ asyncchecksuite "Rest API validation":
225
203
check response.status == 400
226
204
check (await response.body) == " Parsed integer outside of valid range"
227
205
228
- test " updating availability when total size is negative returns 422" :
206
+ test " updating availability when total size is negative returns 422" , config :
229
207
let availability = (
230
208
await client.postAvailability (
231
209
totalSize = 140000 .uint64 ,
@@ -243,7 +221,7 @@ asyncchecksuite "Rest API validation":
243
221
check response.status == 400
244
222
check (await response.body) == " Parsed integer outside of valid range"
245
223
246
- test " request storage fails if tolerance is zero" :
224
+ test " request storage fails if tolerance is zero" , config :
247
225
let data = await RandomChunker .example (blocks = 2 )
248
226
let cid = (await client.upload (data)).get
249
227
let duration = 100 .uint64
@@ -264,7 +242,7 @@ asyncchecksuite "Rest API validation":
264
242
check responseBefore.status == 422
265
243
check (await responseBefore.body) == " Tolerance needs to be bigger then zero"
266
244
267
- test " request storage fails if duration exceeds limit" :
245
+ test " request storage fails if duration exceeds limit" , config :
268
246
let data = await RandomChunker .example (blocks = 2 )
269
247
let cid = (await client.upload (data)).get
270
248
let duration = (31 * 24 * 60 * 60 ).uint64
@@ -286,7 +264,7 @@ asyncchecksuite "Rest API validation":
286
264
check responseBefore.status == 422
287
265
check " Duration exceeds limit of" in (await responseBefore.body)
288
266
289
- test " request storage fails if expiry is zero" :
267
+ test " request storage fails if expiry is zero" , config :
290
268
let data = await RandomChunker .example (blocks = 2 )
291
269
let cid = (await client.upload (data)).get
292
270
let duration = 100 .uint64
@@ -306,7 +284,7 @@ asyncchecksuite "Rest API validation":
306
284
check (await responseBefore.body) ==
307
285
" Expiry must be greater than zero and less than the request's duration"
308
286
309
- test " request storage fails if proof probability is zero" :
287
+ test " request storage fails if proof probability is zero" , config :
310
288
let data = await RandomChunker .example (blocks = 2 )
311
289
let cid = (await client.upload (data)).get
312
290
let duration = 100 .uint64
@@ -325,7 +303,7 @@ asyncchecksuite "Rest API validation":
325
303
check responseBefore.status == 422
326
304
check (await responseBefore.body) == " Proof probability must be greater than zero"
327
305
328
- test " request storage fails if price per byte per second is zero" :
306
+ test " request storage fails if price per byte per second is zero" , config :
329
307
let data = await RandomChunker .example (blocks = 2 )
330
308
let cid = (await client.upload (data)).get
331
309
let duration = 100 .uint64
@@ -345,7 +323,7 @@ asyncchecksuite "Rest API validation":
345
323
check (await responseBefore.body) ==
346
324
" Price per byte per second must be greater than zero"
347
325
348
- test " request storage fails if collareral per byte is zero" :
326
+ test " request storage fails if collareral per byte is zero" , config :
349
327
let data = await RandomChunker .example (blocks = 2 )
350
328
let cid = (await client.upload (data)).get
351
329
let duration = 100 .uint64
@@ -364,7 +342,7 @@ asyncchecksuite "Rest API validation":
364
342
check responseBefore.status == 422
365
343
check (await responseBefore.body) == " Collateral per byte must be greater than zero"
366
344
367
- test " creating availability fails when until is negative" :
345
+ test " creating availability fails when until is negative" , config :
368
346
let totalSize = 12 .uint64
369
347
let minPricePerBytePerSecond = 1 .u256
370
348
let totalCollateral = totalSize.u256 * minPricePerBytePerSecond
@@ -379,6 +357,3 @@ asyncchecksuite "Rest API validation":
379
357
check:
380
358
response.status == 422
381
359
(await response.body) == " Cannot set until to a negative value"
382
-
383
- waitFor node.stop ()
384
- node.removeDataDir ()
0 commit comments