Skip to content

Commit

Permalink
Add replacedOrder to metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
lord-renkse committed Feb 28, 2024
1 parent ebdd683 commit 60bda10
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/schemas/definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
7 changes: 7 additions & 0 deletions src/schemas/replacedOrder/v0.1.0.json
Original file line number Diff line number Diff line change
@@ -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."
}
68 changes: 68 additions & 0 deletions src/schemas/v1.0.1.json
Original file line number Diff line number Diff line change
@@ -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#"
}
}
}
}
}
40 changes: 40 additions & 0 deletions test/schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 60bda10

Please sign in to comment.