diff options
author | F. Eugene Aumson <feuGeneA@users.noreply.github.com> | 2019-01-09 22:58:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-09 22:58:29 +0800 |
commit | aa5af04447dfae24731557c6beead55bd8ff99a9 (patch) | |
tree | 1ffcc631ab078c88f85e2ab2b708f5d91b731cea /python-packages/json_schemas | |
parent | 5b7eff217e9c8d09d64ff8721d7a16e1df8a7c58 (diff) | |
download | dexon-0x-contracts-aa5af04447dfae24731557c6beead55bd8ff99a9.tar dexon-0x-contracts-aa5af04447dfae24731557c6beead55bd8ff99a9.tar.gz dexon-0x-contracts-aa5af04447dfae24731557c6beead55bd8ff99a9.tar.bz2 dexon-0x-contracts-aa5af04447dfae24731557c6beead55bd8ff99a9.tar.lz dexon-0x-contracts-aa5af04447dfae24731557c6beead55bd8ff99a9.tar.xz dexon-0x-contracts-aa5af04447dfae24731557c6beead55bd8ff99a9.tar.zst dexon-0x-contracts-aa5af04447dfae24731557c6beead55bd8ff99a9.zip |
Python contract demo, with lots of refactoring (#1485)
* Refine Order for Web3 compat. & add conversions
Changed some of the fields in the Order class so that it can be passed
to our contracts via Web3.
Added conversion utilities so that an Order can be easily converted to
and from a JSON-compatible dict (specifically by encoding/decoding the
`bytes` fields), to facilitate validation against the JSON schema.
Also modified JSON order schema to accept integers in addition to
stringified integers.
* Fixes for json_schemas
Has-types indicator file, py.typed, was not being included in package.
Schemas were not being properly gathered into package installation.
* Add test/demo of Exchange.getOrderInfo()
* web3 bug workaround
* Fix problem packaging contract artifacts
* Move contract addresses to their own package
* Move contract artifacts to their own package
* Add scripts to install, test & lint all components
* prettierignore files in local python dev env
* Correct missing coverage analysis for sra_client
* CI cache lint: don't save, re-use from test-python
* tag hacks as hacks
* correct merge mistake
* remove local strip_0x() in favor of eth_utils
* remove json schemas from old order_utils location
* correct merge mistake
* doctest json schemas via command-line, not code
Diffstat (limited to 'python-packages/json_schemas')
50 files changed, 616 insertions, 29 deletions
diff --git a/python-packages/json_schemas/setup.py b/python-packages/json_schemas/setup.py index 7813f101f..389d14591 100755 --- a/python-packages/json_schemas/setup.py +++ b/python-packages/json_schemas/setup.py @@ -20,7 +20,7 @@ class TestCommandExtension(TestCommand): """Invoke pytest.""" import pytest - exit(pytest.main()) + exit(pytest.main(["--doctest-modules"])) class LintCommand(distutils.command.build_py.build_py): @@ -41,6 +41,15 @@ class LintCommand(distutils.command.build_py.build_py): "mypy src test setup.py".split(), # security issue checker: "bandit -r src ./setup.py".split(), + # HACK: ensure json schemas don't differ from the authoritative + # copies: this is a hack. ideally we would symlink to the + # authoritative copies, but a problem with setuptools is preventing + # it from following symlinks when gathering package_data. see + # https://github.com/pypa/setuptools/issues/415. + ( + "diff src/zero_ex/json_schemas/schemas" + + " ../../packages/json-schemas/schemas" + ).split(), # general linter: "pylint src test setup.py".split(), # pylint takes relatively long to run, so it runs last, to enable diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas deleted file mode 120000 index b8257372c..000000000 --- a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas +++ /dev/null @@ -1 +0,0 @@ -../../../../../packages/json-schemas/schemas/
\ No newline at end of file diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/address_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/address_schema.json new file mode 100644 index 000000000..0dc02d331 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/address_schema.json @@ -0,0 +1,5 @@ +{ + "id": "/addressSchema", + "type": "string", + "pattern": "^0x[0-9a-f]{40}$" +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/asset_pairs_request_opts_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/asset_pairs_request_opts_schema.json new file mode 100644 index 000000000..fad0bd371 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/asset_pairs_request_opts_schema.json @@ -0,0 +1,8 @@ +{ + "id": "/AssetPairsRequestOptsSchema", + "type": "object", + "properties": { + "assetDataA": { "$ref": "/hexSchema" }, + "assetDataB": { "$ref": "/hexSchema" } + } +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/block_param_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/block_param_schema.json new file mode 100644 index 000000000..ed4dd1e87 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/block_param_schema.json @@ -0,0 +1,11 @@ +{ + "id": "/blockParamSchema", + "oneOf": [ + { + "type": "number" + }, + { + "enum": ["latest", "earliest", "pending"] + } + ] +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/block_range_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/block_range_schema.json new file mode 100644 index 000000000..b14294649 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/block_range_schema.json @@ -0,0 +1,8 @@ +{ + "id": "/blockRangeSchema", + "properties": { + "fromBlock": { "$ref": "/blockParamSchema" }, + "toBlock": { "$ref": "/blockParamSchema" } + }, + "type": "object" +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/call_data_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/call_data_schema.json new file mode 100644 index 000000000..e5e6e3282 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/call_data_schema.json @@ -0,0 +1,27 @@ +{ + "id": "/callDataSchema", + "properties": { + "from": { "$ref": "/addressSchema" }, + "to": { "$ref": "/addressSchema" }, + "value": { + "oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/jsNumberSchema" }] + }, + "gas": { + "oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/jsNumberSchema" }] + }, + "gasPrice": { + "oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/jsNumberSchema" }] + }, + "data": { + "type": "string", + "pattern": "^0x[0-9a-f]*$" + }, + "nonce": { + "type": "number", + "minimum": 0 + } + }, + "required": [], + "type": "object", + "additionalProperties": false +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/ec_signature_parameter_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/ec_signature_parameter_schema.json new file mode 100644 index 000000000..0c08ec240 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/ec_signature_parameter_schema.json @@ -0,0 +1,5 @@ +{ + "id": "/ecSignatureParameterSchema", + "type": "string", + "pattern": "^0[xX][0-9A-Fa-f]{64}$" +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/ec_signature_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/ec_signature_schema.json new file mode 100644 index 000000000..52ccfe7bb --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/ec_signature_schema.json @@ -0,0 +1,14 @@ +{ + "id": "/ecSignatureSchema", + "properties": { + "v": { + "type": "number", + "minimum": 27, + "maximum": 28 + }, + "r": { "$ref": "/ecSignatureParameterSchema" }, + "s": { "$ref": "/ecSignatureParameterSchema" } + }, + "required": ["v", "r", "s"], + "type": "object" +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/eip712_typed_data_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/eip712_typed_data_schema.json new file mode 100644 index 000000000..8efd6de44 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/eip712_typed_data_schema.json @@ -0,0 +1,28 @@ +{ + "id": "/eip712TypedDataSchema", + "type": "object", + "properties": { + "types": { + "type": "object", + "properties": { + "EIP712Domain": { "type": "array" } + }, + "additionalProperties": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { "type": "string" }, + "type": { "type": "string" } + }, + "required": ["name", "type"] + } + }, + "required": ["EIP712Domain"] + }, + "primaryType": { "type": "string" }, + "domain": { "type": "object" }, + "message": { "type": "object" } + }, + "required": ["types", "primaryType", "domain", "message"] +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/hex_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/hex_schema.json new file mode 100644 index 000000000..f37815d5b --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/hex_schema.json @@ -0,0 +1,5 @@ +{ + "id": "/hexSchema", + "type": "string", + "pattern": "^0x(([0-9a-f][0-9a-f])+)?$" +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/index_filter_values_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/index_filter_values_schema.json new file mode 100644 index 000000000..bec00d79e --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/index_filter_values_schema.json @@ -0,0 +1,7 @@ +{ + "id": "/indexFilterValuesSchema", + "additionalProperties": { + "oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/addressSchema" }, { "$ref": "/orderHashSchema" }] + }, + "type": "object" +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/js_number_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/js_number_schema.json new file mode 100644 index 000000000..7df1c4747 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/js_number_schema.json @@ -0,0 +1,5 @@ +{ + "id": "/jsNumberSchema", + "type": "number", + "minimum": 0 +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/number_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/number_schema.json new file mode 100644 index 000000000..a48f3e8cf --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/number_schema.json @@ -0,0 +1,5 @@ +{ + "id": "/numberSchema", + "type": "string", + "pattern": "^\\d+(\\.\\d+)?$" +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_cancel_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_cancel_schema.json new file mode 100644 index 000000000..8d0999941 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_cancel_schema.json @@ -0,0 +1,12 @@ +{ + "id": "/orderCancellationRequestsSchema", + "type": "array", + "items": { + "properties": { + "order": { "$ref": "/orderSchema" }, + "takerTokenCancelAmount": { "$ref": "/wholeNumberSchema" } + }, + "required": ["order", "takerTokenCancelAmount"], + "type": "object" + } +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_config_request_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_config_request_schema.json new file mode 100644 index 000000000..19b043e7f --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_config_request_schema.json @@ -0,0 +1,24 @@ +{ + "id": "/OrderConfigRequestSchema", + "type": "object", + "properties": { + "makerAddress": { "$ref": "/addressSchema" }, + "takerAddress": { "$ref": "/addressSchema" }, + "makerAssetAmount": { "$ref": "/wholeNumberSchema" }, + "takerAssetAmount": { "$ref": "/wholeNumberSchema" }, + "makerAssetData": { "$ref": "/hexSchema" }, + "takerAssetData": { "$ref": "/hexSchema" }, + "exchangeAddress": { "$ref": "/addressSchema" }, + "expirationTimeSeconds": { "$ref": "/wholeNumberSchema" } + }, + "required": [ + "makerAddress", + "takerAddress", + "makerAssetAmount", + "takerAssetAmount", + "makerAssetData", + "takerAssetData", + "exchangeAddress", + "expirationTimeSeconds" + ] +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_fill_or_kill_requests_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_fill_or_kill_requests_schema.json new file mode 100644 index 000000000..73bbf20bb --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_fill_or_kill_requests_schema.json @@ -0,0 +1,12 @@ +{ + "id": "/orderFillOrKillRequestsSchema", + "type": "array", + "items": { + "properties": { + "signedOrder": { "$ref": "/signedOrderSchema" }, + "fillTakerAmount": { "$ref": "/wholeNumberSchema" } + }, + "required": ["signedOrder", "fillTakerAmount"], + "type": "object" + } +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_fill_requests_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_fill_requests_schema.json new file mode 100644 index 000000000..d06fb19a2 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_fill_requests_schema.json @@ -0,0 +1,12 @@ +{ + "id": "/orderFillRequestsSchema", + "type": "array", + "items": { + "properties": { + "signedOrder": { "$ref": "/signedOrderSchema" }, + "takerTokenFillAmount": { "$ref": "/wholeNumberSchema" } + }, + "required": ["signedOrder", "takerTokenFillAmount"], + "type": "object" + } +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_hash_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_hash_schema.json new file mode 100644 index 000000000..4a770579f --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_hash_schema.json @@ -0,0 +1,5 @@ +{ + "id": "/orderHashSchema", + "type": "string", + "pattern": "^0x[0-9a-fA-F]{64}$" +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_schema.json new file mode 100644 index 000000000..c70b9e2dd --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_schema.json @@ -0,0 +1,34 @@ +{ + "id": "/orderSchema", + "properties": { + "makerAddress": { "$ref": "/addressSchema" }, + "takerAddress": { "$ref": "/addressSchema" }, + "makerFee": { "$ref": "/wholeNumberSchema" }, + "takerFee": { "$ref": "/wholeNumberSchema" }, + "senderAddress": { "$ref": "/addressSchema" }, + "makerAssetAmount": { "$ref": "/wholeNumberSchema" }, + "takerAssetAmount": { "$ref": "/wholeNumberSchema" }, + "makerAssetData": { "$ref": "/hexSchema" }, + "takerAssetData": { "$ref": "/hexSchema" }, + "salt": { "$ref": "/wholeNumberSchema" }, + "exchangeAddress": { "$ref": "/addressSchema" }, + "feeRecipientAddress": { "$ref": "/addressSchema" }, + "expirationTimeSeconds": { "$ref": "/wholeNumberSchema" } + }, + "required": [ + "makerAddress", + "takerAddress", + "makerFee", + "takerFee", + "senderAddress", + "makerAssetAmount", + "takerAssetAmount", + "makerAssetData", + "takerAssetData", + "salt", + "exchangeAddress", + "feeRecipientAddress", + "expirationTimeSeconds" + ], + "type": "object" +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_watcher_web_socket_request_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_watcher_web_socket_request_schema.json new file mode 100644 index 000000000..b0c419f94 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_watcher_web_socket_request_schema.json @@ -0,0 +1,52 @@ +{ + "id": "/orderWatcherWebSocketRequestSchema", + "type": "object", + "definitions": { + "signedOrderParam": { + "type": "object", + "properties": { + "signedOrder": { "$ref": "/signedOrderSchema" } + }, + "required": ["signedOrder"] + }, + "orderHashParam": { + "type": "object", + "properties": { + "orderHash": { "$ref": "/hexSchema" } + }, + "required": ["orderHash"] + } + }, + "oneOf": [ + { + "type": "object", + "properties": { + "id": { "type": "number" }, + "jsonrpc": { "type": "string" }, + "method": { "enum": ["ADD_ORDER"] }, + "params": { "$ref": "#/definitions/signedOrderParam" } + }, + "required": ["id", "jsonrpc", "method", "params"] + }, + { + "type": "object", + "properties": { + "id": { "type": "number" }, + "jsonrpc": { "type": "string" }, + "method": { "enum": ["REMOVE_ORDER"] }, + "params": { "$ref": "#/definitions/orderHashParam" } + }, + "required": ["id", "jsonrpc", "method", "params"] + }, + { + "type": "object", + "properties": { + "id": { "type": "number" }, + "jsonrpc": { "type": "string" }, + "method": { "enum": ["GET_STATS"] }, + "params": {} + }, + "required": ["id", "jsonrpc", "method"] + } + ] +}
\ No newline at end of file diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_watcher_web_socket_utf8_message_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_watcher_web_socket_utf8_message_schema.json new file mode 100644 index 000000000..154d6d754 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/order_watcher_web_socket_utf8_message_schema.json @@ -0,0 +1,10 @@ +{ + "id": "/orderWatcherWebSocketUtf8MessageSchema", + "properties": { + "utf8Data": { "type": "string" } + }, + "required": [ + "utf8Data" + ], + "type": "object" +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/orderbook_request_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/orderbook_request_schema.json new file mode 100644 index 000000000..5ce6e8ab0 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/orderbook_request_schema.json @@ -0,0 +1,9 @@ +{ + "id": "/OrderbookRequestSchema", + "type": "object", + "properties": { + "baseAssetData": { "$ref": "/hexSchema" }, + "quoteAssetData": { "$ref": "/hexSchema" } + }, + "required": ["baseAssetData", "quoteAssetData"] +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/orders_request_opts_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/orders_request_opts_schema.json new file mode 100644 index 000000000..4c1b9b4e9 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/orders_request_opts_schema.json @@ -0,0 +1,19 @@ +{ + "id": "/OrdersRequestOptsSchema", + "type": "object", + "properties": { + "makerAssetProxyId": { "$ref": "/hexSchema" }, + "takerAssetProxyId": { "$ref": "/hexSchema" }, + "makerAssetAddress": { "$ref": "/addressSchema" }, + "takerAssetAddress": { "$ref": "/addressSchema" }, + "exchangeAddress": { "$ref": "/addressSchema" }, + "senderAddress": { "$ref": "/addressSchema" }, + "makerAssetData": { "$ref": "/hexSchema" }, + "takerAssetData": { "$ref": "/hexSchema" }, + "traderAssetData": { "$ref": "/hexSchema" }, + "makerAddress": { "$ref": "/addressSchema" }, + "takerAddress": { "$ref": "/addressSchema" }, + "traderAddress": { "$ref": "/addressSchema" }, + "feeRecipientAddress": { "$ref": "/addressSchema" } + } +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/orders_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/orders_schema.json new file mode 100644 index 000000000..1e1c6a875 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/orders_schema.json @@ -0,0 +1,5 @@ +{ + "id": "/ordersSchema", + "type": "array", + "items": { "$ref": "/orderSchema" } +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/paged_request_opts_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/paged_request_opts_schema.json new file mode 100644 index 000000000..f143c28b0 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/paged_request_opts_schema.json @@ -0,0 +1,8 @@ +{ + "id": "/PagedRequestOptsSchema", + "type": "object", + "properties": { + "page": { "type": "number" }, + "perPage": { "type": "number" } + } +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/paginated_collection_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/paginated_collection_schema.json new file mode 100644 index 000000000..9dcedf5b4 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/paginated_collection_schema.json @@ -0,0 +1,10 @@ +{ + "id": "/paginatedCollectionSchema", + "type": "object", + "properties": { + "total": { "type": "number" }, + "perPage": { "type": "number" }, + "page": { "type": "number" } + }, + "required": ["total", "perPage", "page"] +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_asset_data_pairs_response_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_asset_data_pairs_response_schema.json new file mode 100644 index 000000000..d1150d3db --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_asset_data_pairs_response_schema.json @@ -0,0 +1,13 @@ +{ + "id": "/relayerApiAssetDataPairsResponseSchema", + "type": "object", + "allOf": [ + { "$ref": "/paginatedCollectionSchema" }, + { + "properties": { + "records": { "$ref": "/relayerApiAssetDataPairsSchema" } + }, + "required": ["records"] + } + ] +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_asset_data_pairs_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_asset_data_pairs_schema.json new file mode 100644 index 000000000..62d4745b8 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_asset_data_pairs_schema.json @@ -0,0 +1,12 @@ +{ + "id": "/relayerApiAssetDataPairsSchema", + "type": "array", + "items": { + "properties": { + "assetDataA": { "$ref": "/relayerApiAssetDataTradeInfoSchema" }, + "assetDataB": { "$ref": "/relayerApiAssetDataTradeInfoSchema" } + }, + "required": ["assetDataA", "assetDataB"], + "type": "object" + } +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_asset_data_trade_info_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_asset_data_trade_info_schema.json new file mode 100644 index 000000000..e0f274c5d --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_asset_data_trade_info_schema.json @@ -0,0 +1,11 @@ +{ + "id": "/relayerApiAssetDataTradeInfoSchema", + "type": "object", + "properties": { + "assetData": { "$ref": "/hexSchema" }, + "minAmount": { "$ref": "/wholeNumberSchema" }, + "maxAmount": { "$ref": "/wholeNumberSchema" }, + "precision": { "type": "number" } + }, + "required": ["assetData"] +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_error_response_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_error_response_schema.json new file mode 100644 index 000000000..be4659b0b --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_error_response_schema.json @@ -0,0 +1,21 @@ +{ + "id": "/relayerApiErrorResponseSchema", + "type": "object", + "properties": { + "code": { "type": "integer", "minimum": 100, "maximum": 103 }, + "reason": { "type": "string" }, + "validationErrors": { + "type": "array", + "items": { + "type": "object", + "properties": { + "field": { "type": "string" }, + "code": { "type": "integer", "minimum": 1000, "maximum": 1006 }, + "reason": { "type": "string" } + }, + "required": ["field", "code", "reason"] + } + } + }, + "required": ["code", "reason"] +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_fee_recipients_response_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_fee_recipients_response_schema.json new file mode 100644 index 000000000..c73506dbb --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_fee_recipients_response_schema.json @@ -0,0 +1,16 @@ +{ + "id": "/relayerApiFeeRecipientsResponseSchema", + "type": "object", + "allOf": [ + { "$ref": "/paginatedCollectionSchema" }, + { + "properties": { + "records": { + "type": "array", + "items": { "$ref": "/addressSchema" } + } + }, + "required": ["records"] + } + ] +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_order_config_payload_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_order_config_payload_schema.json new file mode 100644 index 000000000..f4583fc62 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_order_config_payload_schema.json @@ -0,0 +1,24 @@ +{ + "id": "/relayerApiOrderConfigPayloadSchema", + "type": "object", + "properties": { + "makerAddress": { "$ref": "/addressSchema" }, + "takerAddress": { "$ref": "/addressSchema" }, + "makerAssetAmount": { "$ref": "/wholeNumberSchema" }, + "takerAssetAmount": { "$ref": "/wholeNumberSchema" }, + "makerAssetData": { "$ref": "/hexSchema" }, + "takerAssetData": { "$ref": "/hexSchema" }, + "exchangeAddress": { "$ref": "/addressSchema" }, + "expirationTimeSeconds": { "$ref": "/wholeNumberSchema" } + }, + "required": [ + "makerAddress", + "takerAddress", + "makerAssetAmount", + "takerAssetAmount", + "makerAssetData", + "takerAssetData", + "exchangeAddress", + "expirationTimeSeconds" + ] +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_order_config_response_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_order_config_response_schema.json new file mode 100644 index 000000000..8193861e1 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_order_config_response_schema.json @@ -0,0 +1,11 @@ +{ + "id": "/relayerApiOrderConfigResponseSchema", + "type": "object", + "properties": { + "makerFee": { "$ref": "/wholeNumberSchema" }, + "takerFee": { "$ref": "/wholeNumberSchema" }, + "feeRecipientAddress": { "$ref": "/addressSchema" }, + "senderAddress": { "$ref": "/addressSchema" } + }, + "required": ["makerFee", "takerFee", "feeRecipientAddress", "senderAddress"] +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_order_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_order_schema.json new file mode 100644 index 000000000..e0f6539b9 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_order_schema.json @@ -0,0 +1,9 @@ +{ + "id": "/relayerApiOrderSchema", + "type": "object", + "properties": { + "order": { "$ref": "/orderSchema" }, + "metaData": { "type": "object" } + }, + "required": ["order", "metaData"] +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_orderbook_response_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_orderbook_response_schema.json new file mode 100644 index 000000000..b44f2a740 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_orderbook_response_schema.json @@ -0,0 +1,9 @@ +{ + "id": "/relayerApiOrderbookResponseSchema", + "type": "object", + "properties": { + "bids": { "$ref": "/relayerApiOrdersResponseSchema" }, + "asks": { "$ref": "/relayerApiOrdersResponseSchema" } + }, + "required": ["bids", "asks"] +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_orders_channel_subscribe_payload_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_orders_channel_subscribe_payload_schema.json new file mode 100644 index 000000000..274ef1625 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_orders_channel_subscribe_payload_schema.json @@ -0,0 +1,14 @@ +{ + "id": "/relayerApiOrdersChannelSubscribePayloadSchema", + "type": "object", + "properties": { + "makerAssetProxyId": { "$ref": "/hexSchema" }, + "takerAssetProxyId": { "$ref": "/hexSchema" }, + "networkId": { "type": "number" }, + "makerAssetAddress": { "$ref": "/addressSchema" }, + "takerAssetAddress": { "$ref": "/addressSchema" }, + "makerAssetData": { "$ref": "/hexSchema" }, + "takerAssetData": { "$ref": "/hexSchema" }, + "traderAssetData": { "$ref": "/hexSchema" } + } +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_orders_channel_subscribe_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_orders_channel_subscribe_schema.json new file mode 100644 index 000000000..29561d09f --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_orders_channel_subscribe_schema.json @@ -0,0 +1,11 @@ +{ + "id": "/relayerApiOrdersChannelSubscribeSchema", + "type": "object", + "properties": { + "type": { "enum": ["subscribe"] }, + "channel": { "enum": ["orders"] }, + "requestId": { "type": "string" }, + "payload": { "$ref": "/relayerApiOrdersChannelSubscribePayloadSchema" } + }, + "required": ["type", "channel", "requestId"] +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_orders_channel_update_response_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_orders_channel_update_response_schema.json new file mode 100644 index 000000000..239e7c586 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_orders_channel_update_response_schema.json @@ -0,0 +1,11 @@ +{ + "id": "/relayerApiOrdersChannelUpdateSchema", + "type": "object", + "properties": { + "type": { "enum": ["update"] }, + "channel": { "enum": ["orders"] }, + "requestId": { "type": "string" }, + "payload": { "$ref": "/relayerApiOrdersSchema" } + }, + "required": ["type", "channel", "requestId"] +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_orders_response_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_orders_response_schema.json new file mode 100644 index 000000000..a5023a3fc --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_orders_response_schema.json @@ -0,0 +1,13 @@ +{ + "id": "/relayerApiOrdersResponseSchema", + "type": "object", + "allOf": [ + { "$ref": "/paginatedCollectionSchema" }, + { + "properties": { + "records": { "$ref": "/relayerApiOrdersSchema" } + }, + "required": ["records"] + } + ] +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_orders_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_orders_schema.json new file mode 100644 index 000000000..84e75cd04 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/relayer_api_orders_schema.json @@ -0,0 +1,5 @@ +{ + "id": "/relayerApiOrdersSchema", + "type": "array", + "items": { "$ref": "/relayerApiOrderSchema" } +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/request_opts_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/request_opts_schema.json new file mode 100644 index 000000000..2206f5016 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/request_opts_schema.json @@ -0,0 +1,7 @@ +{ + "id": "/RequestOptsSchema", + "type": "object", + "properties": { + "networkId": { "type": "number" } + } +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/signed_order_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/signed_order_schema.json new file mode 100644 index 000000000..137ae4a24 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/signed_order_schema.json @@ -0,0 +1,12 @@ +{ + "id": "/signedOrderSchema", + "allOf": [ + { "$ref": "/orderSchema" }, + { + "properties": { + "signature": { "$ref": "/hexSchema" } + }, + "required": ["signature"] + } + ] +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/signed_orders_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/signed_orders_schema.json new file mode 100644 index 000000000..e7c3a0b6c --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/signed_orders_schema.json @@ -0,0 +1,5 @@ +{ + "id": "/signedOrdersSchema", + "type": "array", + "items": { "$ref": "/signedOrderSchema" } +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/token_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/token_schema.json new file mode 100644 index 000000000..31e41c4b8 --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/token_schema.json @@ -0,0 +1,11 @@ +{ + "id": "/tokenSchema", + "properties": { + "name": { "type": "string" }, + "symbol": { "type": "string" }, + "decimals": { "type": "number" }, + "address": { "$ref": "/addressSchema" } + }, + "required": ["name", "symbol", "decimals", "address"], + "type": "object" +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/tx_data_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/tx_data_schema.json new file mode 100644 index 000000000..8c3daba4e --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/tx_data_schema.json @@ -0,0 +1,26 @@ +{ + "id": "/txDataSchema", + "properties": { + "from": { "$ref": "/addressSchema" }, + "to": { "$ref": "/addressSchema" }, + "value": { + "oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/jsNumberSchema" }] + }, + "gas": { + "oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/jsNumberSchema" }] + }, + "gasPrice": { + "oneOf": [{ "$ref": "/numberSchema" }, { "$ref": "/jsNumberSchema" }] + }, + "data": { + "type": "string", + "pattern": "^0x[0-9a-f]*$" + }, + "nonce": { + "type": "number", + "minimum": 0 + } + }, + "required": ["from"], + "type": "object" +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/whole_number_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/whole_number_schema.json new file mode 100644 index 000000000..aa469954c --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/whole_number_schema.json @@ -0,0 +1,12 @@ +{ + "id": "/wholeNumberSchema", + "anyOf": [ + { + "type": "string", + "pattern": "^\\d+$" + }, + { + "type": "integer" + } + ] +} diff --git a/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/zero_ex_transaction_schema.json b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/zero_ex_transaction_schema.json new file mode 100644 index 000000000..0c714f14d --- /dev/null +++ b/python-packages/json_schemas/src/zero_ex/json_schemas/schemas/zero_ex_transaction_schema.json @@ -0,0 +1,10 @@ +{ + "id": "/zeroExTransactionSchema", + "properties": { + "data": { "$ref": "/hexSchema" }, + "signerAddress": { "$ref": "/addressSchema" }, + "salt": { "$ref": "/wholeNumberSchema" } + }, + "required": ["data", "salt", "signerAddress"], + "type": "object" +} diff --git a/python-packages/json_schemas/test/test_doctest.py b/python-packages/json_schemas/test/test_doctest.py deleted file mode 100644 index 2aa576422..000000000 --- a/python-packages/json_schemas/test/test_doctest.py +++ /dev/null @@ -1,25 +0,0 @@ -"""Exercise doctests for all of our modules.""" - -from doctest import testmod -import pkgutil -import importlib - -import zero_ex.json_schemas - - -def test_all_doctests(): - """Gather zero_ex.json_schemas.* modules and doctest them.""" - # json_schemas module - module = "zero_ex.json_schemas" - print(module) - failure_count, _ = testmod(importlib.import_module(module)) - assert failure_count == 0 - - # any json_schemas.* sub-modules - for (_, modname, _) in pkgutil.walk_packages( - path=zero_ex.json_schemas.__path__, prefix="zero_ex.json_schemas" - ): - module = importlib.import_module(modname) - print(module) - (failure_count, _) = testmod(module) - assert failure_count == 0 diff --git a/python-packages/json_schemas/test/test_json_schemas.py b/python-packages/json_schemas/test/test_json_schemas.py index d0e9840b3..1d1efdd12 100644 --- a/python-packages/json_schemas/test/test_json_schemas.py +++ b/python-packages/json_schemas/test/test_json_schemas.py @@ -1,6 +1,7 @@ """Tests of zero_ex.json_schemas""" +from zero_ex.order_utils import make_empty_order, order_to_jsdict from zero_ex.json_schemas import _LOCAL_RESOLVER, assert_valid @@ -33,9 +34,9 @@ def test_assert_valid_caches_resources(): """ _LOCAL_RESOLVER._remote_cache.cache_clear() # pylint: disable=W0212 - assert_valid(EMPTY_ORDER, "/orderSchema") + assert_valid(order_to_jsdict(make_empty_order()), "/orderSchema") cache_info = ( _LOCAL_RESOLVER._remote_cache.cache_info() # pylint: disable=W0212 ) assert cache_info.currsize == 4 - assert cache_info.hits == 10 + assert cache_info.hits > 0 |