aboutsummaryrefslogtreecommitdiffstats
path: root/packages/json-schemas
diff options
context:
space:
mode:
authorKadinsky <kandinsky454@protonmail.ch>2018-10-23 05:01:30 +0800
committerGitHub <noreply@github.com>2018-10-23 05:01:30 +0800
commitbe97eebe022739bf7f993d17eda7d26ad4ef448a (patch)
treea782be168db5cfe63958da4758621a7b2a84ca30 /packages/json-schemas
parent19f9649e74f487714f7094e013480f7b8e81090c (diff)
parentdbf75a43c37af31858dfca4026ab12f0491c520f (diff)
downloaddexon-0x-contracts-be97eebe022739bf7f993d17eda7d26ad4ef448a.tar.gz
dexon-0x-contracts-be97eebe022739bf7f993d17eda7d26ad4ef448a.tar.zst
dexon-0x-contracts-be97eebe022739bf7f993d17eda7d26ad4ef448a.zip
Merge pull request #1173 from 0xProject/fixSchemaBug
Fix number schema bug
Diffstat (limited to 'packages/json-schemas')
-rw-r--r--packages/json-schemas/CHANGELOG.json10
-rw-r--r--packages/json-schemas/schemas/order_cancel_schema.json2
-rw-r--r--packages/json-schemas/schemas/order_fill_or_kill_requests_schema.json2
-rw-r--r--packages/json-schemas/schemas/order_fill_requests_schema.json2
-rw-r--r--packages/json-schemas/schemas/order_schema.json12
-rw-r--r--packages/json-schemas/schemas/relayer_api_asset_data_trade_info_schema.json4
-rw-r--r--packages/json-schemas/schemas/relayer_api_order_config_payload_schema.json6
-rw-r--r--packages/json-schemas/schemas/relayer_api_order_config_response_schema.json4
-rw-r--r--packages/json-schemas/schemas/whole_number_schema.json5
-rw-r--r--packages/json-schemas/schemas/zero_ex_transaction_schema.json2
-rw-r--r--packages/json-schemas/src/schemas.ts2
-rw-r--r--packages/json-schemas/test/schema_test.ts12
-rw-r--r--packages/json-schemas/tsconfig.json3
13 files changed, 48 insertions, 18 deletions
diff --git a/packages/json-schemas/CHANGELOG.json b/packages/json-schemas/CHANGELOG.json
index 8a88df6e2..3bd6552e3 100644
--- a/packages/json-schemas/CHANGELOG.json
+++ b/packages/json-schemas/CHANGELOG.json
@@ -1,5 +1,15 @@
[
{
+ "version": "2.0.1",
+ "changes": [
+ {
+ "note":
+ "Improve schemas by enforcing that amounts that must be whole numbers (e.g Order asset amounts) no longer allow decimal amounts",
+ "pr": 1173
+ }
+ ]
+ },
+ {
"version": "2.0.0",
"changes": [
{
diff --git a/packages/json-schemas/schemas/order_cancel_schema.json b/packages/json-schemas/schemas/order_cancel_schema.json
index 09d4068c6..8d0999941 100644
--- a/packages/json-schemas/schemas/order_cancel_schema.json
+++ b/packages/json-schemas/schemas/order_cancel_schema.json
@@ -4,7 +4,7 @@
"items": {
"properties": {
"order": { "$ref": "/orderSchema" },
- "takerTokenCancelAmount": { "$ref": "/numberSchema" }
+ "takerTokenCancelAmount": { "$ref": "/wholeNumberSchema" }
},
"required": ["order", "takerTokenCancelAmount"],
"type": "object"
diff --git a/packages/json-schemas/schemas/order_fill_or_kill_requests_schema.json b/packages/json-schemas/schemas/order_fill_or_kill_requests_schema.json
index c9549c72e..73bbf20bb 100644
--- a/packages/json-schemas/schemas/order_fill_or_kill_requests_schema.json
+++ b/packages/json-schemas/schemas/order_fill_or_kill_requests_schema.json
@@ -4,7 +4,7 @@
"items": {
"properties": {
"signedOrder": { "$ref": "/signedOrderSchema" },
- "fillTakerAmount": { "$ref": "/numberSchema" }
+ "fillTakerAmount": { "$ref": "/wholeNumberSchema" }
},
"required": ["signedOrder", "fillTakerAmount"],
"type": "object"
diff --git a/packages/json-schemas/schemas/order_fill_requests_schema.json b/packages/json-schemas/schemas/order_fill_requests_schema.json
index 98325653b..d06fb19a2 100644
--- a/packages/json-schemas/schemas/order_fill_requests_schema.json
+++ b/packages/json-schemas/schemas/order_fill_requests_schema.json
@@ -4,7 +4,7 @@
"items": {
"properties": {
"signedOrder": { "$ref": "/signedOrderSchema" },
- "takerTokenFillAmount": { "$ref": "/numberSchema" }
+ "takerTokenFillAmount": { "$ref": "/wholeNumberSchema" }
},
"required": ["signedOrder", "takerTokenFillAmount"],
"type": "object"
diff --git a/packages/json-schemas/schemas/order_schema.json b/packages/json-schemas/schemas/order_schema.json
index de2c8c7c2..c70b9e2dd 100644
--- a/packages/json-schemas/schemas/order_schema.json
+++ b/packages/json-schemas/schemas/order_schema.json
@@ -3,17 +3,17 @@
"properties": {
"makerAddress": { "$ref": "/addressSchema" },
"takerAddress": { "$ref": "/addressSchema" },
- "makerFee": { "$ref": "/numberSchema" },
- "takerFee": { "$ref": "/numberSchema" },
+ "makerFee": { "$ref": "/wholeNumberSchema" },
+ "takerFee": { "$ref": "/wholeNumberSchema" },
"senderAddress": { "$ref": "/addressSchema" },
- "makerAssetAmount": { "$ref": "/numberSchema" },
- "takerAssetAmount": { "$ref": "/numberSchema" },
+ "makerAssetAmount": { "$ref": "/wholeNumberSchema" },
+ "takerAssetAmount": { "$ref": "/wholeNumberSchema" },
"makerAssetData": { "$ref": "/hexSchema" },
"takerAssetData": { "$ref": "/hexSchema" },
- "salt": { "$ref": "/numberSchema" },
+ "salt": { "$ref": "/wholeNumberSchema" },
"exchangeAddress": { "$ref": "/addressSchema" },
"feeRecipientAddress": { "$ref": "/addressSchema" },
- "expirationTimeSeconds": { "$ref": "/numberSchema" }
+ "expirationTimeSeconds": { "$ref": "/wholeNumberSchema" }
},
"required": [
"makerAddress",
diff --git a/packages/json-schemas/schemas/relayer_api_asset_data_trade_info_schema.json b/packages/json-schemas/schemas/relayer_api_asset_data_trade_info_schema.json
index 0ab9b444f..e0f274c5d 100644
--- a/packages/json-schemas/schemas/relayer_api_asset_data_trade_info_schema.json
+++ b/packages/json-schemas/schemas/relayer_api_asset_data_trade_info_schema.json
@@ -3,8 +3,8 @@
"type": "object",
"properties": {
"assetData": { "$ref": "/hexSchema" },
- "minAmount": { "$ref": "/numberSchema" },
- "maxAmount": { "$ref": "/numberSchema" },
+ "minAmount": { "$ref": "/wholeNumberSchema" },
+ "maxAmount": { "$ref": "/wholeNumberSchema" },
"precision": { "type": "number" }
},
"required": ["assetData"]
diff --git a/packages/json-schemas/schemas/relayer_api_order_config_payload_schema.json b/packages/json-schemas/schemas/relayer_api_order_config_payload_schema.json
index bc95b61ef..f4583fc62 100644
--- a/packages/json-schemas/schemas/relayer_api_order_config_payload_schema.json
+++ b/packages/json-schemas/schemas/relayer_api_order_config_payload_schema.json
@@ -4,12 +4,12 @@
"properties": {
"makerAddress": { "$ref": "/addressSchema" },
"takerAddress": { "$ref": "/addressSchema" },
- "makerAssetAmount": { "$ref": "/numberSchema" },
- "takerAssetAmount": { "$ref": "/numberSchema" },
+ "makerAssetAmount": { "$ref": "/wholeNumberSchema" },
+ "takerAssetAmount": { "$ref": "/wholeNumberSchema" },
"makerAssetData": { "$ref": "/hexSchema" },
"takerAssetData": { "$ref": "/hexSchema" },
"exchangeAddress": { "$ref": "/addressSchema" },
- "expirationTimeSeconds": { "$ref": "/numberSchema" }
+ "expirationTimeSeconds": { "$ref": "/wholeNumberSchema" }
},
"required": [
"makerAddress",
diff --git a/packages/json-schemas/schemas/relayer_api_order_config_response_schema.json b/packages/json-schemas/schemas/relayer_api_order_config_response_schema.json
index 0742febdf..8193861e1 100644
--- a/packages/json-schemas/schemas/relayer_api_order_config_response_schema.json
+++ b/packages/json-schemas/schemas/relayer_api_order_config_response_schema.json
@@ -2,8 +2,8 @@
"id": "/relayerApiOrderConfigResponseSchema",
"type": "object",
"properties": {
- "makerFee": { "$ref": "/numberSchema" },
- "takerFee": { "$ref": "/numberSchema" },
+ "makerFee": { "$ref": "/wholeNumberSchema" },
+ "takerFee": { "$ref": "/wholeNumberSchema" },
"feeRecipientAddress": { "$ref": "/addressSchema" },
"senderAddress": { "$ref": "/addressSchema" }
},
diff --git a/packages/json-schemas/schemas/whole_number_schema.json b/packages/json-schemas/schemas/whole_number_schema.json
new file mode 100644
index 000000000..944ce820e
--- /dev/null
+++ b/packages/json-schemas/schemas/whole_number_schema.json
@@ -0,0 +1,5 @@
+{
+ "id": "/wholeNumberSchema",
+ "type": "string",
+ "pattern": "^\\d+$"
+}
diff --git a/packages/json-schemas/schemas/zero_ex_transaction_schema.json b/packages/json-schemas/schemas/zero_ex_transaction_schema.json
index ad3b11583..0c714f14d 100644
--- a/packages/json-schemas/schemas/zero_ex_transaction_schema.json
+++ b/packages/json-schemas/schemas/zero_ex_transaction_schema.json
@@ -3,7 +3,7 @@
"properties": {
"data": { "$ref": "/hexSchema" },
"signerAddress": { "$ref": "/addressSchema" },
- "salt": { "$ref": "/numberSchema" }
+ "salt": { "$ref": "/wholeNumberSchema" }
},
"required": ["data", "salt", "signerAddress"],
"type": "object"
diff --git a/packages/json-schemas/src/schemas.ts b/packages/json-schemas/src/schemas.ts
index 8318df617..8ece5de75 100644
--- a/packages/json-schemas/src/schemas.ts
+++ b/packages/json-schemas/src/schemas.ts
@@ -34,6 +34,7 @@ import * as signedOrderSchema from '../schemas/signed_order_schema.json';
import * as signedOrdersSchema from '../schemas/signed_orders_schema.json';
import * as tokenSchema from '../schemas/token_schema.json';
import * as txDataSchema from '../schemas/tx_data_schema.json';
+import * as wholeNumberSchema from '../schemas/whole_number_schema.json';
import * as zeroExTransactionSchema from '../schemas/zero_ex_transaction_schema.json';
export const schemas = {
@@ -74,4 +75,5 @@ export const schemas = {
relayerApiOrdersResponseSchema,
relayerApiAssetDataPairsSchema,
zeroExTransactionSchema,
+ wholeNumberSchema,
};
diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts
index 795261ef2..bfa2c5668 100644
--- a/packages/json-schemas/test/schema_test.ts
+++ b/packages/json-schemas/test/schema_test.ts
@@ -36,6 +36,7 @@ const {
relayerApiOrdersChannelUpdateSchema,
relayerApiOrdersResponseSchema,
relayerApiOrderSchema,
+ wholeNumberSchema,
} = schemas;
describe('Schema', () => {
@@ -73,6 +74,17 @@ describe('Schema', () => {
validateAgainstSchema(testCases, numberSchema, shouldFail);
});
});
+ describe('#wholeNumberSchema', () => {
+ it('should validate valid numbers', () => {
+ const testCases = ['5', '42', '0'];
+ validateAgainstSchema(testCases, wholeNumberSchema);
+ });
+ it('should fail for invalid numbers', () => {
+ const testCases = ['1.3', '0.2', '00.00', '.3', '1.', 'abacaba', 'и', '1..0'];
+ const shouldFail = true;
+ validateAgainstSchema(testCases, wholeNumberSchema, shouldFail);
+ });
+ });
describe('#addressSchema', () => {
it('should validate valid addresses', () => {
const testCases = ['0x8b0292b11a196601ed2ce54b665cafeca0347d42', NULL_ADDRESS];
diff --git a/packages/json-schemas/tsconfig.json b/packages/json-schemas/tsconfig.json
index 425dfcfe1..7b14166c0 100644
--- a/packages/json-schemas/tsconfig.json
+++ b/packages/json-schemas/tsconfig.json
@@ -43,6 +43,7 @@
"./schemas/js_number.json",
"./schemas/zero_ex_transaction_schema.json",
"./schemas/tx_data_schema.json",
- "./schemas/index_filter_values_schema.json"
+ "./schemas/index_filter_values_schema.json",
+ "./schemas/whole_number_schema.json"
]
}