From 1217f221fe00f5444c7e83a2a469d05dbe446c4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Sant=C3=A1ngelo?= Date: Fri, 19 Feb 2021 14:00:02 -0300 Subject: [PATCH 1/3] feat: add network and chain types --- src/dapps/chain-id.ts | 27 +++++++++++++++++++++++++++ src/dapps/network.ts | 22 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/dapps/chain-id.ts create mode 100644 src/dapps/network.ts diff --git a/src/dapps/chain-id.ts b/src/dapps/chain-id.ts new file mode 100644 index 00000000..626ed936 --- /dev/null +++ b/src/dapps/chain-id.ts @@ -0,0 +1,27 @@ +import { generateValidator, JSONSchema, ValidateFunction } from "../validation"; + +/** + * Different supported chain ids + * @alpha + */ +export declare enum ChainId { + ETHEREUM_MAINNET = 1, + ETHEREUM_ROPSTEN = 3, + ETHEREUM_RINKEBY = 4, + ETHEREUM_GOERLI = 5, + ETHEREUM_KOVAN = 42, + MATIC_MAINNET = 89, + MATIC_MUMBAI = 13881, +} + +/** + * @alpha + */ +export namespace ChainId { + export const schema: JSONSchema = { + type: "number", + enum: Object.values(ChainId), + }; + + export const validate: ValidateFunction = generateValidator(schema); +} diff --git a/src/dapps/network.ts b/src/dapps/network.ts new file mode 100644 index 00000000..debf3d2b --- /dev/null +++ b/src/dapps/network.ts @@ -0,0 +1,22 @@ +import { generateValidator, JSONSchema, ValidateFunction } from "../validation"; + +/** + * Different supported networks + * @alpha + */ +export declare enum Network { + ETHEREUM = "ETHEREUM", + MATIC = "MATIC", +} + +/** + * @alpha + */ +export namespace Network { + export const schema: JSONSchema = { + type: "string", + enum: Object.values(Network), + }; + + export const validate: ValidateFunction = generateValidator(schema); +} From cb98bc76c54321379e69c3c3b128258585e86f27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Sant=C3=A1ngelo?= Date: Fri, 19 Feb 2021 14:12:36 -0300 Subject: [PATCH 2/3] feat: add tests --- src/dapps/chain-id.ts | 10 +++++----- src/dapps/meta-transactions.ts | 16 +++++++++------- src/dapps/network.ts | 14 +++++++------- src/index.ts | 6 ++++-- test/chain-id.spec.ts | 15 +++++++++++++++ test/network.spec.ts | 15 +++++++++++++++ 6 files changed, 55 insertions(+), 21 deletions(-) create mode 100644 test/chain-id.spec.ts create mode 100644 test/network.spec.ts diff --git a/src/dapps/chain-id.ts b/src/dapps/chain-id.ts index 626ed936..59219f2f 100644 --- a/src/dapps/chain-id.ts +++ b/src/dapps/chain-id.ts @@ -1,10 +1,10 @@ -import { generateValidator, JSONSchema, ValidateFunction } from "../validation"; +import { generateValidator, JSONSchema, ValidateFunction } from '../validation' /** * Different supported chain ids * @alpha */ -export declare enum ChainId { +export enum ChainId { ETHEREUM_MAINNET = 1, ETHEREUM_ROPSTEN = 3, ETHEREUM_RINKEBY = 4, @@ -19,9 +19,9 @@ export declare enum ChainId { */ export namespace ChainId { export const schema: JSONSchema = { - type: "number", + type: 'number', enum: Object.values(ChainId), - }; + } - export const validate: ValidateFunction = generateValidator(schema); + export const validate: ValidateFunction = generateValidator(schema) } diff --git a/src/dapps/meta-transactions.ts b/src/dapps/meta-transactions.ts index 22e8b9f6..6600f606 100644 --- a/src/dapps/meta-transactions.ts +++ b/src/dapps/meta-transactions.ts @@ -1,4 +1,4 @@ -import { generateValidator, JSONSchema, ValidateFunction } from "../validation" +import { generateValidator, JSONSchema, ValidateFunction } from '../validation' /** * Meta-transaction to be relayed @@ -14,19 +14,21 @@ export type MetaTransaction = { */ export namespace MetaTransaction { export const schema: JSONSchema = { - type: "object", + type: 'object', properties: { - from: { type: "string" }, + from: { type: 'string' }, params: { - type: "array", - items: [{ type: "string" }, { type: "string" }], + type: 'array', + items: [{ type: 'string' }, { type: 'string' }], additionalItems: false, minItems: 2, }, }, additionalProperties: false, - required: ["from", "params"], + required: ['from', 'params'], } - export const validate: ValidateFunction = generateValidator(schema) + export const validate: ValidateFunction = generateValidator( + schema + ) } diff --git a/src/dapps/network.ts b/src/dapps/network.ts index debf3d2b..5d7e5a3d 100644 --- a/src/dapps/network.ts +++ b/src/dapps/network.ts @@ -1,12 +1,12 @@ -import { generateValidator, JSONSchema, ValidateFunction } from "../validation"; +import { generateValidator, JSONSchema, ValidateFunction } from '../validation' /** * Different supported networks * @alpha */ -export declare enum Network { - ETHEREUM = "ETHEREUM", - MATIC = "MATIC", +export enum Network { + ETHEREUM = 'ETHEREUM', + MATIC = 'MATIC', } /** @@ -14,9 +14,9 @@ export declare enum Network { */ export namespace Network { export const schema: JSONSchema = { - type: "string", + type: 'string', enum: Object.values(Network), - }; + } - export const validate: ValidateFunction = generateValidator(schema); + export const validate: ValidateFunction = generateValidator(schema) } diff --git a/src/index.ts b/src/index.ts index 8a7141e7..a378e099 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,7 @@ // export the utils -export * from "./validation" +export * from './validation' // export all the types -export { MetaTransaction } from "./dapps/meta-transactions" +export { ChainId } from './dapps/chain-id' +export { Network } from './dapps/network' +export { MetaTransaction } from './dapps/meta-transactions' diff --git a/test/chain-id.spec.ts b/test/chain-id.spec.ts new file mode 100644 index 00000000..a5082f53 --- /dev/null +++ b/test/chain-id.spec.ts @@ -0,0 +1,15 @@ +import expect from 'expect' +import { ChainId } from '../src' +import { testTypeSignature } from './test-utils' + +describe('ChainId tests', () => { + const chainId: ChainId = ChainId.ETHEREUM_KOVAN + + testTypeSignature(ChainId, chainId) + + it('static tests must pass', () => { + expect(ChainId.validate(chainId)).toEqual(true) + expect(ChainId.validate(null)).toEqual(false) + expect(ChainId.validate({})).toEqual(false) + }) +}) diff --git a/test/network.spec.ts b/test/network.spec.ts new file mode 100644 index 00000000..ee9806bb --- /dev/null +++ b/test/network.spec.ts @@ -0,0 +1,15 @@ +import expect from 'expect' +import { Network } from '../src' +import { testTypeSignature } from './test-utils' + +describe('Network tests', () => { + const network: Network = Network.ETHEREUM + + testTypeSignature(Network, network) + + it('static tests must pass', () => { + expect(Network.validate(network)).toEqual(true) + expect(Network.validate(null)).toEqual(false) + expect(Network.validate({})).toEqual(false) + }) +}) From c35f78ce10be66a87f3948fe9cf95ca17995ff66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Sant=C3=A1ngelo?= Date: Fri, 19 Feb 2021 14:23:36 -0300 Subject: [PATCH 3/3] feat: update schema --- api-extractor.json | 4 ++-- report/schemas.api.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/api-extractor.json b/api-extractor.json index 25d4ee7c..68d83e0a 100644 --- a/api-extractor.json +++ b/api-extractor.json @@ -96,7 +96,7 @@ * * DEFAULT VALUE: false */ - "skipLibCheck": true, + "skipLibCheck": true }, /** * Configures how the API report file (*.api.md) will be generated. @@ -129,7 +129,7 @@ * SUPPORTED TOKENS: , , * DEFAULT VALUE: "/etc/" */ - "reportFolder": "/report/", + "reportFolder": "/report/" /** * Specifies the folder where the temporary report file is written. The file name portion is determined by * the "reportFileName" setting. diff --git a/report/schemas.api.md b/report/schemas.api.md index fe93b5b6..8f24a8d9 100644 --- a/report/schemas.api.md +++ b/report/schemas.api.md @@ -16,6 +16,32 @@ export type AbstractTypedSchema = { export { Ajv } +// @alpha +export enum ChainId { + // (undocumented) + ETHEREUM_GOERLI = 5, + // (undocumented) + ETHEREUM_KOVAN = 42, + // (undocumented) + ETHEREUM_MAINNET = 1, + // (undocumented) + ETHEREUM_RINKEBY = 4, + // (undocumented) + ETHEREUM_ROPSTEN = 3, + // (undocumented) + MATIC_MAINNET = 89, + // (undocumented) + MATIC_MUMBAI = 13881 +} + +// @alpha (undocumented) +export namespace ChainId { + const // (undocumented) + schema: JSONSchema; + const // (undocumented) + validate: ValidateFunction; +} + // @public export function generateValidator(schema: JSONSchema): ValidateFunction; @@ -36,6 +62,22 @@ export namespace MetaTransaction { validate: ValidateFunction; } +// @alpha +export enum Network { + // (undocumented) + ETHEREUM = "ETHEREUM", + // (undocumented) + MATIC = "MATIC" +} + +// @alpha (undocumented) +export namespace Network { + const // (undocumented) + schema: JSONSchema; + const // (undocumented) + validate: ValidateFunction; +} + export { ValidateFunction } // @public