mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-02-17 07:16:47 +00:00
* Improve integration testing client (CodexClient) and json serialization The current client used for integration testing against the REST endpoints for Codex accepts and passes primitive types. This caused a hard to diagnose bug where a `uint` was not being deserialized correctly. In addition, the json de/serializing done between the CodexClient and REST client was not easy to read and was not tested. These changes bring non-primitive types to most of the CodexClient functions, allowing us to lean on the compiler to ensure we're providing correct typings. More importantly, a json de/serialization util was created as a drop-in replacement for the std/json lib, with the main two differences being that field serialization is opt-in (instead of opt-out as in the case of json_serialization) and serialization errors are captured and logged, making debugging serialization issues much easier. * Update integration test to use nodes=2 and tolerance=1 * clean up
38 lines
980 B
Nim
38 lines
980 B
Nim
import pkg/questionable
|
|
import pkg/questionable/results
|
|
import pkg/stew/byteutils
|
|
import ../sales
|
|
import ../purchasing
|
|
import ../utils/json
|
|
|
|
export json
|
|
|
|
type
|
|
StorageRequestParams* = object
|
|
duration* {.serialize.}: UInt256
|
|
proofProbability* {.serialize.}: UInt256
|
|
reward* {.serialize.}: UInt256
|
|
collateral* {.serialize.}: UInt256
|
|
expiry* {.serialize.}: ?UInt256
|
|
nodes* {.serialize.}: ?uint
|
|
tolerance* {.serialize.}: ?uint
|
|
|
|
RestPurchase* = object
|
|
requestId* {.serialize.}: RequestId
|
|
request* {.serialize.}: ?StorageRequest
|
|
state* {.serialize.}: string
|
|
error* {.serialize.}: ?string
|
|
|
|
RestAvailability* = object
|
|
size* {.serialize.}: UInt256
|
|
duration* {.serialize.}: UInt256
|
|
minPrice* {.serialize.}: UInt256
|
|
maxCollateral* {.serialize.}: UInt256
|
|
|
|
func `%`*(obj: StorageRequest | Slot): JsonNode =
|
|
let jsonObj = newJObject()
|
|
for k, v in obj.fieldPairs: jsonObj[k] = %v
|
|
jsonObj["id"] = %(obj.id)
|
|
|
|
return jsonObj
|