Merge pull request #615 from 0xProject/refactor/json-schemas/for-v2
Refactor order schemas in json-schemas for v2
This commit is contained in:
12
package.json
12
package.json
@@ -20,13 +20,13 @@
|
||||
"install:all": "yarn install",
|
||||
"wsrun": "wsrun",
|
||||
"lerna:run": "lerna run",
|
||||
"watch": "wsrun watch $PKG -r --stages --done-criteria='complete|successfully'",
|
||||
"build": "wsrun build $PKG -r --stages",
|
||||
"clean": "wsrun clean $PKG -r --parallel",
|
||||
"watch": "wsrun watch $PKG --fast-exit -r --stages --done-criteria='complete|successfully'",
|
||||
"build": "wsrun build $PKG --fast-exit -r --stages",
|
||||
"clean": "wsrun clean $PKG --fast-exit -r --parallel",
|
||||
"rebuild": "run-s clean build",
|
||||
"test": "wsrun test $PKG --serial --exclude-missing",
|
||||
"stage_docs": "wsrun docs:stage $PKG --parallel --exclude-missing",
|
||||
"lint": "wsrun lint $PKG --parallel --exclude-missing"
|
||||
"test": "wsrun test $PKG --fast-exit --serial --exclude-missing",
|
||||
"stage_docs": "wsrun docs:stage $PKG --fast-exit --parallel --exclude-missing",
|
||||
"lint": "wsrun lint $PKG --fast-exit --parallel --exclude-missing"
|
||||
},
|
||||
"config": {
|
||||
"mnemonic": "concert load couple harbor equip island argue ramp clarify fence smart topic"
|
||||
|
@@ -47,7 +47,7 @@
|
||||
"typescript": "2.7.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0xproject/json-schemas": "^0.7.24",
|
||||
"@0xproject/json-schemas": "0.7.22",
|
||||
"@0xproject/typescript-typings": "^0.3.2",
|
||||
"@0xproject/utils": "^0.6.2",
|
||||
"lodash": "^4.17.4",
|
||||
|
@@ -51,7 +51,7 @@
|
||||
"homepage": "https://github.com/0xProject/0x-monorepo/packages/connect/README.md",
|
||||
"dependencies": {
|
||||
"@0xproject/assert": "^0.2.10",
|
||||
"@0xproject/json-schemas": "^0.7.24",
|
||||
"@0xproject/json-schemas": "0.7.22",
|
||||
"@0xproject/types": "^0.7.0",
|
||||
"@0xproject/typescript-typings": "^0.3.2",
|
||||
"@0xproject/utils": "^0.6.2",
|
||||
|
@@ -79,7 +79,7 @@
|
||||
"@0xproject/assert": "^0.2.10",
|
||||
"@0xproject/base-contract": "^0.3.2",
|
||||
"@0xproject/fill-scenarios": "^0.0.2",
|
||||
"@0xproject/json-schemas": "^0.7.24",
|
||||
"@0xproject/json-schemas": "0.7.22",
|
||||
"@0xproject/order-utils": "^0.0.5",
|
||||
"@0xproject/types": "^0.7.0",
|
||||
"@0xproject/typescript-typings": "^0.3.2",
|
||||
|
@@ -1,4 +1,14 @@
|
||||
[
|
||||
{
|
||||
"version": "0.8.0",
|
||||
"changes": [
|
||||
{
|
||||
"note":
|
||||
"Update Order & SignedOrder schemas, remove ECSignature schema and add Hex schema as part of V2 upgrades",
|
||||
"pr": 615
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1527008794,
|
||||
"version": "0.7.24",
|
||||
|
@@ -4,6 +4,12 @@ export const addressSchema = {
|
||||
pattern: '^0x[0-9a-f]{40}$',
|
||||
};
|
||||
|
||||
export const hexSchema = {
|
||||
id: '/Hex',
|
||||
type: 'string',
|
||||
pattern: '^0x([0-9a-f][0-9a-f])+$',
|
||||
};
|
||||
|
||||
export const numberSchema = {
|
||||
id: '/Number',
|
||||
type: 'string',
|
||||
|
@@ -1,20 +0,0 @@
|
||||
export const ecSignatureParameterSchema = {
|
||||
id: '/ECSignatureParameter',
|
||||
type: 'string',
|
||||
pattern: '^0[xX][0-9A-Fa-f]{64}$',
|
||||
};
|
||||
|
||||
export const ecSignatureSchema = {
|
||||
id: '/ECSignature',
|
||||
properties: {
|
||||
v: {
|
||||
type: 'number',
|
||||
minimum: 27,
|
||||
maximum: 28,
|
||||
},
|
||||
r: { $ref: '/ECSignatureParameter' },
|
||||
s: { $ref: '/ECSignatureParameter' },
|
||||
},
|
||||
required: ['v', 'r', 's'],
|
||||
type: 'object',
|
||||
};
|
@@ -1,30 +1,30 @@
|
||||
export const orderSchema = {
|
||||
id: '/Order',
|
||||
properties: {
|
||||
maker: { $ref: '/Address' },
|
||||
taker: { $ref: '/Address' },
|
||||
makerAddress: { $ref: '/Address' },
|
||||
takerAddress: { $ref: '/Address' },
|
||||
makerFee: { $ref: '/Number' },
|
||||
takerFee: { $ref: '/Number' },
|
||||
makerTokenAmount: { $ref: '/Number' },
|
||||
takerTokenAmount: { $ref: '/Number' },
|
||||
makerTokenAddress: { $ref: '/Address' },
|
||||
takerTokenAddress: { $ref: '/Address' },
|
||||
makerAssetAmount: { $ref: '/Number' },
|
||||
takerAssetAmount: { $ref: '/Number' },
|
||||
makerAssetData: { $ref: '/Hex' },
|
||||
takerAssetData: { $ref: '/Hex' },
|
||||
salt: { $ref: '/Number' },
|
||||
feeRecipient: { $ref: '/Address' },
|
||||
expirationUnixTimestampSec: { $ref: '/Number' },
|
||||
exchangeContractAddress: { $ref: '/Address' },
|
||||
feeRecipientAddress: { $ref: '/Address' },
|
||||
expirationTimeSeconds: { $ref: '/Number' },
|
||||
},
|
||||
required: [
|
||||
'maker',
|
||||
'taker',
|
||||
'makerAddress',
|
||||
'takerAddress',
|
||||
'makerFee',
|
||||
'takerFee',
|
||||
'makerTokenAmount',
|
||||
'takerTokenAmount',
|
||||
'makerAssetAmount',
|
||||
'takerAssetAmount',
|
||||
'makerAssetData',
|
||||
'takerAssetData',
|
||||
'salt',
|
||||
'feeRecipient',
|
||||
'expirationUnixTimestampSec',
|
||||
'exchangeContractAddress',
|
||||
'feeRecipientAddress',
|
||||
'expirationTimeSeconds',
|
||||
],
|
||||
type: 'object',
|
||||
};
|
||||
@@ -35,9 +35,9 @@ export const signedOrderSchema = {
|
||||
{ $ref: '/Order' },
|
||||
{
|
||||
properties: {
|
||||
ecSignature: { $ref: '/ECSignature' },
|
||||
signature: { $ref: '/Hex' },
|
||||
},
|
||||
required: ['ecSignature'],
|
||||
required: ['signature'],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
@@ -1,6 +1,5 @@
|
||||
import { addressSchema, numberSchema } from '../schemas/basic_type_schemas';
|
||||
import { addressSchema, hexSchema, numberSchema } from '../schemas/basic_type_schemas';
|
||||
import { blockParamSchema, blockRangeSchema } from '../schemas/block_range_schema';
|
||||
import { ecSignatureParameterSchema, ecSignatureSchema } from '../schemas/ec_signature_schema';
|
||||
import { indexFilterValuesSchema } from '../schemas/index_filter_values_schema';
|
||||
import { orderCancellationRequestsSchema } from '../schemas/order_cancel_schema';
|
||||
import { orderFillOrKillRequestsSchema } from '../schemas/order_fill_or_kill_requests_schema';
|
||||
@@ -31,8 +30,7 @@ import { jsNumber, txDataSchema } from '../schemas/tx_data_schema';
|
||||
export const schemas = {
|
||||
numberSchema,
|
||||
addressSchema,
|
||||
ecSignatureSchema,
|
||||
ecSignatureParameterSchema,
|
||||
hexSchema,
|
||||
indexFilterValuesSchema,
|
||||
orderCancellationRequestsSchema,
|
||||
orderFillOrKillRequestsSchema,
|
||||
|
@@ -14,8 +14,7 @@ const NULL_ADDRESS = '0x0000000000000000000000000000000000000000';
|
||||
const {
|
||||
numberSchema,
|
||||
addressSchema,
|
||||
ecSignatureSchema,
|
||||
ecSignatureParameterSchema,
|
||||
hexSchema,
|
||||
orderCancellationRequestsSchema,
|
||||
orderFillOrKillRequestsSchema,
|
||||
orderFillRequestsSchema,
|
||||
@@ -85,47 +84,15 @@ describe('Schema', () => {
|
||||
validateAgainstSchema(testCases, addressSchema, shouldFail);
|
||||
});
|
||||
});
|
||||
describe('#ecSignatureParameterSchema', () => {
|
||||
it('should validate valid parameters', () => {
|
||||
const testCases = [
|
||||
'0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33',
|
||||
'0X40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254',
|
||||
];
|
||||
validateAgainstSchema(testCases, ecSignatureParameterSchema);
|
||||
describe('#hexSchema', () => {
|
||||
it('should validate valid hex string', () => {
|
||||
const testCases = ['0x8b0292b11a196601ed2ce54b665cafeca0347d42', NULL_ADDRESS];
|
||||
validateAgainstSchema(testCases, hexSchema);
|
||||
});
|
||||
it('should fail for invalid parameters', () => {
|
||||
const testCases = [
|
||||
'0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc3', // shorter
|
||||
'0xzzzz9190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // invalid characters
|
||||
'40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // no 0x
|
||||
];
|
||||
it('should fail for invalid hex string', () => {
|
||||
const testCases = ['0x', '0', '0xzzzzzzB11a196601eD2ce54B665CaFEca0347D42'];
|
||||
const shouldFail = true;
|
||||
validateAgainstSchema(testCases, ecSignatureParameterSchema, shouldFail);
|
||||
});
|
||||
});
|
||||
describe('#ecSignatureSchema', () => {
|
||||
it('should validate valid signature', () => {
|
||||
const signature = {
|
||||
v: 27,
|
||||
r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33',
|
||||
s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254',
|
||||
};
|
||||
const testCases = [
|
||||
signature,
|
||||
{
|
||||
...signature,
|
||||
v: 28,
|
||||
},
|
||||
];
|
||||
validateAgainstSchema(testCases, ecSignatureSchema);
|
||||
});
|
||||
it('should fail for invalid signature', () => {
|
||||
const v = 27;
|
||||
const r = '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33';
|
||||
const s = '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254';
|
||||
const testCases = [{}, { v }, { r, s, v: 31 }];
|
||||
const shouldFail = true;
|
||||
validateAgainstSchema(testCases, ecSignatureSchema, shouldFail);
|
||||
validateAgainstSchema(testCases, hexSchema, shouldFail);
|
||||
});
|
||||
});
|
||||
describe('#orderHashSchema', () => {
|
||||
@@ -202,18 +169,17 @@ describe('Schema', () => {
|
||||
});
|
||||
describe('order including schemas', () => {
|
||||
const order = {
|
||||
maker: NULL_ADDRESS,
|
||||
taker: NULL_ADDRESS,
|
||||
makerAddress: NULL_ADDRESS,
|
||||
takerAddress: NULL_ADDRESS,
|
||||
makerFee: '1',
|
||||
takerFee: '2',
|
||||
makerTokenAmount: '1',
|
||||
takerTokenAmount: '2',
|
||||
makerTokenAddress: NULL_ADDRESS,
|
||||
takerTokenAddress: NULL_ADDRESS,
|
||||
makerAssetAmount: '1',
|
||||
takerAssetAmount: '2',
|
||||
makerAssetData: NULL_ADDRESS,
|
||||
takerAssetData: NULL_ADDRESS,
|
||||
salt: '67006738228878699843088602623665307406148487219438534730168799356281242528500',
|
||||
feeRecipient: NULL_ADDRESS,
|
||||
exchangeContractAddress: NULL_ADDRESS,
|
||||
expirationUnixTimestampSec: '42',
|
||||
feeRecipientAddress: NULL_ADDRESS,
|
||||
expirationTimeSeconds: '42',
|
||||
};
|
||||
describe('#orderSchema', () => {
|
||||
it('should validate valid order', () => {
|
||||
@@ -239,11 +205,8 @@ describe('Schema', () => {
|
||||
describe('signed order including schemas', () => {
|
||||
const signedOrder = {
|
||||
...order,
|
||||
ecSignature: {
|
||||
v: 27,
|
||||
r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33',
|
||||
s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254',
|
||||
},
|
||||
signature:
|
||||
'0x031b61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc3340349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254',
|
||||
};
|
||||
describe('#signedOrdersSchema', () => {
|
||||
it('should validate valid signed orders', () => {
|
||||
@@ -265,7 +228,7 @@ describe('Schema', () => {
|
||||
const testCases = [
|
||||
{
|
||||
...signedOrder,
|
||||
ecSignature: undefined,
|
||||
signature: undefined,
|
||||
},
|
||||
];
|
||||
const shouldFail = true;
|
||||
|
@@ -63,7 +63,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@0xproject/assert": "^0.2.10",
|
||||
"@0xproject/json-schemas": "^0.7.24",
|
||||
"@0xproject/json-schemas": "0.7.22",
|
||||
"@0xproject/types": "^0.7.0",
|
||||
"@0xproject/typescript-typings": "^0.3.2",
|
||||
"@0xproject/utils": "^0.6.2",
|
||||
|
@@ -80,7 +80,7 @@
|
||||
"@0xproject/base-contract": "^0.3.2",
|
||||
"@0xproject/contract-wrappers": "^0.0.2",
|
||||
"@0xproject/fill-scenarios": "^0.0.2",
|
||||
"@0xproject/json-schemas": "^0.7.24",
|
||||
"@0xproject/json-schemas": "0.7.22",
|
||||
"@0xproject/order-utils": "^0.0.5",
|
||||
"@0xproject/types": "^0.7.0",
|
||||
"@0xproject/typescript-typings": "^0.3.2",
|
||||
|
@@ -72,7 +72,7 @@
|
||||
"zeppelin-solidity": "1.8.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@0xproject/json-schemas": "^0.7.24",
|
||||
"@0xproject/json-schemas": "0.7.22",
|
||||
"@0xproject/sol-resolver": "^0.0.5",
|
||||
"@0xproject/types": "^0.7.0",
|
||||
"@0xproject/typescript-typings": "^0.3.2",
|
||||
|
@@ -35,7 +35,7 @@
|
||||
"@0xproject/types": "^0.7.0",
|
||||
"@0xproject/order-utils": "^0.0.5",
|
||||
"@0xproject/connect": "^0.6.13",
|
||||
"@0xproject/json-schemas": "^0.7.24",
|
||||
"@0xproject/json-schemas": "0.7.22",
|
||||
"@0xproject/typescript-typings": "^0.3.2",
|
||||
"@0xproject/utils": "^0.6.2",
|
||||
"chalk": "^2.3.0",
|
||||
|
@@ -1,6 +1,6 @@
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
|
||||
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
||||
|
||||
module.exports = {
|
||||
entry: ['./ts/index.tsx'],
|
||||
@@ -25,6 +25,11 @@ module.exports = {
|
||||
{
|
||||
test: /\.js$/,
|
||||
loader: 'source-map-loader',
|
||||
exclude: [
|
||||
// instead of /\/node_modules\//
|
||||
path.join(process.cwd(), 'node_modules'),
|
||||
path.join(process.cwd(), '../..', 'node_modules'),
|
||||
],
|
||||
},
|
||||
{
|
||||
test: /\.tsx?$/,
|
||||
|
@@ -6,6 +6,15 @@
|
||||
version "0.3.9"
|
||||
resolved "https://registry.yarnpkg.com/8fold-marked/-/8fold-marked-0.3.9.tgz#bb89c645612f8ccfaffac1ca6e3c11f168c9cf59"
|
||||
|
||||
"@0xproject/json-schemas@0.7.22":
|
||||
version "0.7.22"
|
||||
resolved "https://registry.yarnpkg.com/@0xproject/json-schemas/-/json-schemas-0.7.22.tgz#95cbdc9ec0eff3d1920903960284d491eb668f28"
|
||||
dependencies:
|
||||
"@0xproject/typescript-typings" "^0.3.0"
|
||||
"@types/node" "^8.0.53"
|
||||
jsonschema "^1.2.0"
|
||||
lodash.values "^4.3.0"
|
||||
|
||||
"@0xproject/types@^0.5.0":
|
||||
version "0.5.0"
|
||||
resolved "https://registry.yarnpkg.com/@0xproject/types/-/types-0.5.0.tgz#ba3cfbc11a8c6344b57c9680aa7df2ea84b9bf05"
|
||||
|
Reference in New Issue
Block a user