Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Clean up repo #53

Merged
merged 25 commits into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ node_js:
script:
- yarn lint
- yarn build
- yarn test:api
- yarn test --silent --coverage --coverageReporters=text-lcov | coveralls ; test ${PIPESTATUS[0]} -eq 0
before_deploy:
- npm install --global gitbook-cli
Expand Down
13 changes: 10 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ module.exports = {
'!**/*.d.ts',
'!**/index.ts'
],
// Adding this because "Cannot use namespace '...' as a type."
globals: {
'ts-jest': {
diagnostics: {
warnOnly: true
}
}
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
rootDir: '.',
transform: {
'^.+\\.tsx?$': 'ts-jest'
'^.+\\.(ts|tsx)$': 'ts-jest'
},
// testRegex: 'spec\\.(ts|tsx)$' // TODO Skip api/ tests for now, as it's still WIP
testRegex: `packages/(abi|contracts|electron|light\.js|light\.js-react)/.*spec\\.(ts|tsx)$`
testRegex: 'spec\\.(ts|tsx)$'
};
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"scripts": {
"build": "lerna exec yarn build --stream",
"lint": "tslint 'packages/**/*.ts'",
"postinstall": "yarn build",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added this, so that when people clone this repo and install, all the packages are built.

"test": "jest",
"test:api": "cd packages/api && yarn test",
"update-docs": "scripts/update-docs.sh"
},
"devDependencies": {
Expand All @@ -33,6 +35,6 @@
"tslint-config-semistandard": "^7.0.0",
"typedoc": "^0.12.0",
"typedoc-plugin-markdown": "^1.1.13",
"typescript": "^3.0.1"
"typescript": "^3.1.6"
}
}
2 changes: 1 addition & 1 deletion packages/abi/src/decoder/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Slices } from '../types';
const NULL = '0000000000000000000000000000000000000000000000000000000000000000';

class Decoder {
static decode (params: ParamType[] | undefined, data: string) {
static decode (params: ParamType[] | undefined, data?: string) {
if (!isArray(params)) {
throw new Error('Parameters should be array of ParamType');
}
Expand Down
4 changes: 2 additions & 2 deletions packages/abi/src/spec/event/decodedLogParam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import Token from '../../token';

class DecodedLogParam {
private _kind: ParamType;
private _name: string;
private _name: string | undefined;
private _token: Token;

constructor (name: string, kind: ParamType, token: Token) {
constructor (name: string | undefined, kind: ParamType, token: Token) {
if (!isInstanceOf(kind, ParamType)) {
throw new Error('kind not instanceof ParamType');
} else if (!isInstanceOf(token, Token)) {
Expand Down
10 changes: 1 addition & 9 deletions packages/abi/src/spec/event/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Event {
private _anonymous: boolean;
private _id: string;
private _inputs: EventParam[];
private _name: string;
private _name: string | undefined;
private _signature: string;

constructor (abi: AbiItem) {
Expand All @@ -28,14 +28,6 @@ class Event {
this.inputParamTypes()
);

if (!name) {
throw new Error(
`Event constructor: abi item does not have a name: ${JSON.stringify(
abi
)}`
);
}

this._id = id;
this._name = name;
this._signature = signature;
Expand Down
4 changes: 2 additions & 2 deletions packages/abi/src/spec/event/eventParam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { toParamType } from '../paramType/format';
class EventParam {
private _indexed: boolean;
private _kind: ParamType;
private _name: string;
private _name: string | undefined;

static toEventParams (params: (Param | AbiInput)[]) {
return params.map(
Expand All @@ -26,7 +26,7 @@ class EventParam {
);
}

constructor (name: string, type: TokenTypeEnum, indexed = false) {
constructor (name: string | undefined, type: TokenTypeEnum, indexed = false) {
this._name = name;
this._indexed = indexed;
this._kind = toParamType(type, indexed);
Expand Down
14 changes: 3 additions & 11 deletions packages/abi/src/spec/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Func {
private _constant: boolean;
private _id: string;
private _inputs: Param[];
private _name: string;
private _name: string | undefined;
private _outputs: Param[];
private _payable: boolean;
private _signature: string;
Expand All @@ -32,14 +32,6 @@ class Func {
this.inputParamTypes()
);

if (!name) {
throw new Error(
`Event constructor: abi item does not have a name: ${JSON.stringify(
abi
)}`
);
}

this._id = id;
this._name = name;
this._signature = signature;
Expand Down Expand Up @@ -77,11 +69,11 @@ class Func {
return this._signature;
}

decodeInput (data: string) {
decodeInput (data?: string) {
return Decoder.decode(this.inputParamTypes(), data);
}

decodeOutput (data: string) {
decodeOutput (data?: string) {
return Decoder.decode(this.outputParamTypes(), data);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/abi/src/spec/param.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { toParamType } from './paramType/format';

class Param {
private _kind: ParamType;
private _name: string;
private _name: string | undefined;

constructor (name: string, type: string) {
constructor (name: string | undefined, type: string) {
this._name = name;
this._kind = toParamType(type);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/abi/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Token from './token';

export interface AbiInput {
indexed?: boolean;
name: string;
name?: string;
type: TokenTypeEnum;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/abi/src/util/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const isChecksumValid = (address: string) => {
*
* @param address - The address to verify.
*/
export const isAddress = (address: string) => {
export const isAddress = (address?: string) => {
if (address && address.length === 42) {
if (!/^(0x)?[0-9a-f]{40}$/i.test(address)) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion packages/abi/src/util/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { padAddress } from './pad';
*
* @param data - Data to slice.
*/
export const sliceData = (data: string): string[] | null => {
export const sliceData = (data?: string): string[] | null => {
if (!data || !data.length) {
return [];
}
Expand Down
32 changes: 20 additions & 12 deletions packages/abi/src/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ const HEXDIGITS = [
'f'
];

export const isArray = (input: any): input is Array<any> =>
Array.isArray(input);
export function isArray<T> (input?: any): input is Array<T> {
return Array.isArray(input);
}

export const isError = (input: any): input is Error => input instanceof Error;
export function isError (input?: any): input is Error {
return input instanceof Error;
}

export const isFunction = (input: any): input is Function =>
typeof input === 'function';
export function isFunction (input?: any): input is Function {
return typeof input === 'function';
}

export const isHex = (input: any): boolean => {
export function isHex (input?: any): boolean {
if (!isString(input)) {
return false;
}
Expand All @@ -47,11 +51,15 @@ export const isHex = (input: any): boolean => {
}

return hex;
};
export const isObject = (input: any): input is object =>
Object.prototype.toString.call(input) === '[object Object]';
}
export function isObject (input?: any): input is object {
return Object.prototype.toString.call(input) === '[object Object]';
}

export const isString = (input: any): input is string =>
typeof input === 'string';
export function isString (input?: any): input is string {
return typeof input === 'string';
}

export const isInstanceOf = (input: any, clazz: any) => input instanceof clazz;
export function isInstanceOf (input: any, clazz: any) {
return input instanceof clazz;
}
36 changes: 25 additions & 11 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,36 @@
},
"scripts": {
"prebuild": "rimraf lib",
"build": "echo Skipped for now.",
"test": "jest"
"build": "tsc",
"test": "cross-env NODE_ENV=test mocha -r ts-node/register 'src/*.spec.js' 'src/**/*.spec.js'"
},
"devDependencies": {
"@types/lodash-es": "^4.17.1",
"@types/node": "^10.5.2"
"chai": "3.5.0",
"chai-as-promised": "6.0.0",
"coveralls": "^3.0.0",
"cross-env": "^5.1.1",
"jsdom": "^11.1.0",
"mocha": "^3.4.2",
"mock-local-storage": "1.0.2",
"mock-socket": "6.0.4",
"nock": "9.0.7",
"rimraf": "^2.6.2",
"sinon": "1.17.7",
"sinon-as-promised": "4.0.2",
"sinon-chai": "2.8.0",
"ts-node": "^7.0.1"
},
"dependencies": {
"@parity/abi": "^3.0.0",
"@parity/jsonrpc": "2.1.x",
"@parity/wordlist": "1.1.x",
"bignumber.js": "7.2.1",
"eventemitter3": "^3.1.0",
"js-sha3": "0.7.0",
"lodash": "^4.17.10",
"bignumber.js": "^7",
"blockies": "0.0.2",
"es6-error": "4.0.2",
"es6-promise": "^4.1.1",
"eventemitter3": "^2.0.2",
"isomorphic-fetch": "^2.2.1",
"js-sha3": "0.5.5",
"lodash": "^4.17.4",
"store": "^2.0.12",
"websocket": "^1.0.26"
"websocket": "^1.0.25"
}
}
2 changes: 1 addition & 1 deletion packages/api/src/api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ describe('Api', () => {
});

it('exposes util as static property', () => {
expect(Api.util).toEqual(util);
expect(Api.util).to.equal(util);
});
});
Loading