Skip to content

Commit

Permalink
feat: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosantangelo committed Feb 19, 2021
1 parent 1217f22 commit cb98bc7
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 21 deletions.
10 changes: 5 additions & 5 deletions src/dapps/chain-id.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -19,9 +19,9 @@ export declare enum ChainId {
*/
export namespace ChainId {
export const schema: JSONSchema<ChainId> = {
type: "number",
type: 'number',
enum: Object.values(ChainId),
};
}

export const validate: ValidateFunction<ChainId> = generateValidator(schema);
export const validate: ValidateFunction<ChainId> = generateValidator(schema)
}
16 changes: 9 additions & 7 deletions src/dapps/meta-transactions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generateValidator, JSONSchema, ValidateFunction } from "../validation"
import { generateValidator, JSONSchema, ValidateFunction } from '../validation'

/**
* Meta-transaction to be relayed
Expand All @@ -14,19 +14,21 @@ export type MetaTransaction = {
*/
export namespace MetaTransaction {
export const schema: JSONSchema<MetaTransaction> = {
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<MetaTransaction> = generateValidator(schema)
export const validate: ValidateFunction<MetaTransaction> = generateValidator(
schema
)
}
14 changes: 7 additions & 7 deletions src/dapps/network.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
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',
}

/**
* @alpha
*/
export namespace Network {
export const schema: JSONSchema<Network> = {
type: "string",
type: 'string',
enum: Object.values(Network),
};
}

export const validate: ValidateFunction<Network> = generateValidator(schema);
export const validate: ValidateFunction<Network> = generateValidator(schema)
}
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
15 changes: 15 additions & 0 deletions test/chain-id.spec.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
15 changes: 15 additions & 0 deletions test/network.spec.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})

0 comments on commit cb98bc7

Please sign in to comment.