diff --git a/src/schemas/definitions.json b/src/schemas/definitions.json index 78bf010..9df5a51 100644 --- a/src/schemas/definitions.json +++ b/src/schemas/definitions.json @@ -33,6 +33,13 @@ "type": "integer", "maximum": 10000, "minimum": 0 + }, + "orderUID": { + "$id": "#/definitions/orderUID", + "pattern": "^0x[a-fA-F0-9]{112}$", + "title": "Order UID", + "examples": ["0xff2e2e54d178997f173266817c1e9ed6fee1a1aae4b43971c53b543cffcc2969845c6f5599fbb25dbdd1b9b013daf85c03f3c63763e4bc4a"], + "type": "string" } } } diff --git a/src/schemas/replacedOrder/v0.1.0.json b/src/schemas/replacedOrder/v0.1.0.json new file mode 100644 index 0000000..c273abe --- /dev/null +++ b/src/schemas/replacedOrder/v0.1.0.json @@ -0,0 +1,7 @@ +{ + "$id": "#replacedOrder/v0.1.0.json", + "$schema": "http://json-schema.org/draft-07/schema", + "$ref": "../definitions.json#/definitions/orderUID", + "title": "replacedOrder", + "description": "The order UID of the order to be replaced." +} diff --git a/src/schemas/v1.0.1.json b/src/schemas/v1.0.1.json new file mode 100644 index 0000000..3472989 --- /dev/null +++ b/src/schemas/v1.0.1.json @@ -0,0 +1,68 @@ +{ + "$id": "https://cowswap.exchange/schemas/app-data/v0.11.0.json", + "$schema": "http://json-schema.org/draft-07/schema", + "description": "Metadata JSON document for adding information to orders.", + "required": ["version", "metadata"], + "title": "AppData Root Schema", + "type": "object", + "additionalProperties": false, + "properties": { + "version": { + "$ref": "definitions.json#/definitions/version", + "readOnly": true, + "default": "0.11.0" + }, + "appCode": { + "$id": "#/properties/appCode", + "description": "The code identifying the CLI, UI, service generating the order.", + "examples": ["CoW Swap"], + "title": "App Code", + "type": "string" + }, + "environment": { + "$id": "#/properties/environment", + "description": "Environment from which the order came from.", + "title": "Environment", + "type": "string", + "examples": ["production", "development", "staging", "ens"] + }, + "metadata": { + "$id": "#/properties/metadata", + "default": {}, + "description": "Each metadata will specify one aspect of the order.", + "required": [], + "title": "Metadata", + "type": "object", + "additionalProperties": false, + "properties": { + "signer": { + "$ref": "signer/v0.1.0.json#" + }, + "referrer": { + "$ref": "referrer/v0.2.0.json#" + }, + "utm": { + "$ref": "utm/v0.2.0.json#" + }, + "quote": { + "$ref": "quote/v1.0.0.json#" + }, + "orderClass": { + "$ref": "orderClass/v0.3.0.json#" + }, + "hooks": { + "$ref": "hooks/v0.1.0.json#" + }, + "widget": { + "$ref": "widget/v0.1.0.json#" + }, + "partnerFee": { + "$ref": "partnerFee/v0.1.0.json#" + }, + "replacedOrder": { + "$ref": "replacedOrder/v0.1.0.json#" + } + } + } + } +} diff --git a/test/schema.spec.ts b/test/schema.spec.ts index bf9487c..7f1fb37 100644 --- a/test/schema.spec.ts +++ b/test/schema.spec.ts @@ -10,6 +10,7 @@ import schemaV0_9_0 from '../schemas/v0.9.0.json' import schemaV0_10_0 from '../schemas/v0.10.0.json' import schemaV0_11_0 from '../schemas/v0.11.0.json' import schemaV1_0_0 from '../schemas/v1.0.0.json' +import schemaV1_0_1 from '../schemas/v1.0.1.json' const ADDRESS = '0xb6BAd41ae76A11D10f7b0E664C5007b908bC77C9' const REFERRER_V0_1_0 = { address: ADDRESS, version: '0.1.0' } @@ -886,6 +887,45 @@ describe('Schema v1.0.0: Update quote definition', () => { ) }) +describe('Schema v1.0.1: Add replaced order', () => { + const ajv = new Ajv() + const validator = ajv.compile(schemaV1_0_1) + + const BASE_DOCUMENT = { + version: '1.0.1', + metadata: {}, + } + + test( + 'Valid order id', + _buildAssertValidFn(validator, { + ...BASE_DOCUMENT, + metadata: { replacedOrder: "0xff2e2e54d178997f173266817c1e9ed6fee1a1aae4b43971c53b543cffcc2969845c6f5599fbb25dbdd1b9b013daf85c03f3c63763e4bc4a" }, + }) + ) + + + test( + 'Invalid order id length', + _buildAssertInvalidFn( + validator, + { + ...BASE_DOCUMENT, + metadata: { replacedOrder: "0xff2e2e54d178997f173266817c1e9ed6fee1a1aae4b43971c53b543cffcc2969845c6f5599fbb25dbdd1b9b013daf85c03f3c63763e44a" }, + }, + [ + { + instancePath: '/metadata/replacedOrder', + keyword: "pattern", + message: "must match pattern \"^0x[a-fA-F0-9]{112}$\"", + params: { pattern: "^0x[a-fA-F0-9]{112}$" }, + schemaPath: '#/properties/metadata/properties/replacedOrder/pattern', + }, + ] + ) + ) +}) + function _buildAssertValidFn(validator: ValidateFunction, doc: any) { return () => { // when