-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(permit): add permit info json schema (#294)
* chore: move coingecko and donwloadImages to the `scripts` folder * feat: add permitInfo json schema * feat: add permit info schema unittests
- Loading branch information
1 parent
79b3f29
commit 1c8409a
Showing
5 changed files
with
209 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"$id": "https://cow.fi/schemas/token-list/v0.0.1.json", | ||
"$schema": "http://json-schema.org/draft-07/schema", | ||
"title": "PermitInfo", | ||
"description": "Permit info for tokens", | ||
"type": "object", | ||
"patternProperties": { | ||
"^0x[a-fA-F0-9]{40}$": { | ||
"oneOf": [ | ||
{ | ||
"type": "object", | ||
"title": "PermitInfo", | ||
"description": "Individual permit info when a token is known to be permittable", | ||
"properties": { | ||
"version": { | ||
"type": "string", | ||
"description": "Optional version number, as a string", | ||
"pattern": "^\\d+$" | ||
}, | ||
"type": { | ||
"type": "string", | ||
"description": "Type of permit", | ||
"enum": [ | ||
"eip-2612", | ||
"dai-like" | ||
] | ||
} | ||
}, | ||
"required": [ | ||
"type" | ||
] | ||
}, | ||
{ | ||
"type": "boolean", | ||
"description": "When a token is known to not be permittable", | ||
"const": false | ||
} | ||
] | ||
} | ||
}, | ||
"additionalProperties": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
import {describe, it} from 'node:test' | ||
import assert from 'node:assert' | ||
import Ajv from 'ajv' | ||
|
||
import schema from './permitInfo.schema.json' assert {type: 'json'} | ||
|
||
|
||
describe('The permitInfo schema', () => { | ||
it('should be valid', () => { | ||
const ajv = new Ajv() | ||
|
||
assert.strictEqual(ajv.validateSchema(schema), true) | ||
}) | ||
}) | ||
|
||
describe('Valid PermitInfo data', () => { | ||
|
||
it('should be valid with `false` value', () => { | ||
const data = { | ||
'0x0000000000000000000000000000000000000000': false | ||
} | ||
|
||
const ajv = new Ajv() | ||
const result = ajv.validate(schema, data) | ||
|
||
assert.strictEqual(ajv.errors, null) | ||
assert.strictEqual(result, true) | ||
}) | ||
|
||
it('should be valid with `eip-2612` and no version', () => { | ||
const data = { | ||
'0x0000000000000000000000000000000000000000': { | ||
type: 'eip-2612' | ||
} | ||
} | ||
|
||
const ajv = new Ajv() | ||
const result = ajv.validate(schema, data) | ||
|
||
assert.strictEqual(ajv.errors, null) | ||
assert.strictEqual(result, true) | ||
}) | ||
|
||
it('should be valid with `eip-2612` and version', () => { | ||
const data = { | ||
'0x0000000000000000000000000000000000000000': { | ||
type: 'eip-2612', | ||
version: '1', | ||
} | ||
} | ||
|
||
const ajv = new Ajv() | ||
const result = ajv.validate(schema, data) | ||
|
||
assert.strictEqual(ajv.errors, null) | ||
assert.strictEqual(result, true) | ||
}) | ||
|
||
it('should be valid with `dai-like` and no version', () => { | ||
const data = { | ||
'0x0000000000000000000000000000000000000000': { | ||
type: 'dai-like' | ||
} | ||
} | ||
|
||
const ajv = new Ajv() | ||
const result = ajv.validate(schema, data) | ||
|
||
assert.strictEqual(ajv.errors, null) | ||
assert.strictEqual(result, true) | ||
}) | ||
|
||
it('should be valid with `dai-like` and version', () => { | ||
const data = { | ||
'0x0000000000000000000000000000000000000000': { | ||
type: 'dai-like', | ||
version: "2" | ||
} | ||
} | ||
|
||
const ajv = new Ajv() | ||
const result = ajv.validate(schema, data) | ||
|
||
assert.strictEqual(ajv.errors, null) | ||
assert.strictEqual(result, true) | ||
}) | ||
}) | ||
|
||
describe('Invalid PermitInfo data', () => { | ||
it('should be invalid with number version', () => { | ||
const data = { | ||
'0x0000000000000000000000000000000000000000': { | ||
type: 'eip-2612', | ||
version: 1, | ||
} | ||
} | ||
|
||
const ajv = new Ajv() | ||
const result = ajv.validate(schema, data) | ||
|
||
assert.strictEqual(result, false) | ||
assert.notEqual(ajv.errors, null) | ||
}) | ||
|
||
it('should be invalid with non integer version', () => { | ||
const data = { | ||
'0x0000000000000000000000000000000000000000': { | ||
type: 'eip-2612', | ||
version: '1.1' | ||
} | ||
} | ||
|
||
const ajv = new Ajv() | ||
const result = ajv.validate(schema, data) | ||
|
||
assert.strictEqual(result, false) | ||
assert.notEqual(ajv.errors, null) | ||
}) | ||
|
||
it('should be invalid with non address key', () => { | ||
const data = { | ||
'not an address': false | ||
} | ||
|
||
const ajv = new Ajv() | ||
const result = ajv.validate(schema, data) | ||
|
||
|
||
assert.strictEqual(result, false) | ||
assert.notEqual(ajv.errors, null) | ||
}) | ||
|
||
it('should be invalid with `true` value', () => { | ||
|
||
const data = { | ||
'0x0000000000000000000000000000000000000000': true | ||
} | ||
|
||
const ajv = new Ajv() | ||
const result = ajv.validate(schema, data) | ||
|
||
assert.strictEqual(result, false) | ||
assert.notEqual(ajv.errors, null) | ||
}) | ||
|
||
it('should be invalid with non existent type', () => { | ||
|
||
const data = { | ||
'0x0000000000000000000000000000000000000000': { | ||
type: 'non-existent' | ||
} | ||
} | ||
|
||
const ajv = new Ajv() | ||
const result = ajv.validate(schema, data) | ||
|
||
assert.strictEqual(result, false) | ||
assert.notEqual(ajv.errors, null) | ||
}) | ||
|
||
}) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters