Skip to content

Commit

Permalink
fix(types): Bump polkadot-js/api to decode CompactSolution for 24 noms (
Browse files Browse the repository at this point in the history
#553)

* fix(types): Bump polkadot-js/api to decode CompactSolution for 24 nominees

* Lint
  • Loading branch information
emostov committed May 16, 2021
1 parent bf47b11 commit c67ae2f
Show file tree
Hide file tree
Showing 31 changed files with 525 additions and 922 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
},
"dependencies": {
"@polkadot/api": "beta",
"@polkadot/apps-config": "beta",
"@polkadot/util-crypto": "beta",
"@polkadot/apps-config": "^0.90.1",
"@polkadot/util-crypto": "^6.4.1",
"@substrate/calc": "^0.2.0",
"confmgr": "^1.0.6",
"express": "^4.17.1",
Expand Down
19 changes: 1 addition & 18 deletions src/chains-config/metadata-consts/dockConsts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,7 @@ import { MetadataConsts } from '../../types/chains-config';
export const dockMainnetDefinitions: MetadataConsts[] = [
{
runtimeVersions: [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
],
extrinsicBaseWeight: BigInt(125000000),
},
Expand Down
16 changes: 2 additions & 14 deletions src/chains-config/metadata-consts/kusamaConsts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,8 @@ import { extrinsicBaseWeight, perClass } from './substrateConsts';
export const kusamaDefinitions: MetadataConsts[] = [
{
runtimeVersions: [
1062,
2005,
2007,
2008,
2011,
2012,
2013,
2015,
2019,
2022,
2023,
2024,
2025,
2026,
1062, 2005, 2007, 2008, 2011, 2012, 2013, 2015, 2019, 2022, 2023, 2024,
2025, 2026,
],
extrinsicBaseWeight,
},
Expand Down
21 changes: 1 addition & 20 deletions src/chains-config/metadata-consts/polkadotConsts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,7 @@ import { extrinsicBaseWeight, perClass } from './substrateConsts';
export const polkadotDefinitions: MetadataConsts[] = [
{
runtimeVersions: [
0,
1,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
23,
24,
25,
26,
0, 1, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 23, 24, 25, 26,
],
extrinsicBaseWeight,
},
Expand Down
17 changes: 1 addition & 16 deletions src/chains-config/metadata-consts/westendConsts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,7 @@ import { extrinsicBaseWeight, perClass } from './substrateConsts';
export const westendDefinitions: MetadataConsts[] = [
{
runtimeVersions: [
6,
7,
8,
20,
28,
29,
30,
31,
32,
33,
24,
35,
41,
43,
44,
45,
6, 7, 8, 20, 28, 29, 30, 31, 32, 33, 24, 35, 41, 43, 44, 45,
],
extrinsicBaseWeight,
},
Expand Down
22 changes: 10 additions & 12 deletions src/controllers/AbstractController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,16 @@ export default abstract class AbstractController<T extends AbstractService> {
*
* @param cb ExpressHandler
*/
protected static catchWrap = (cb: RequestHandler): RequestHandler => async (
req,
res,
next
): Promise<void> => {
try {
// eslint-disable-next-line @typescript-eslint/await-thenable
await cb(req, res, next);
} catch (err) {
next(err);
}
};
protected static catchWrap =
(cb: RequestHandler): RequestHandler =>
async (req, res, next): Promise<void> => {
try {
// eslint-disable-next-line @typescript-eslint/await-thenable
await cb(req, res, next);
} catch (err) {
next(err);
}
};

/**
* Create or retrieve the corresponding BlockHash for the given block identifier.
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/AbstractControllers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ const MockController = class MockController extends AbstractController<AbstractS
};
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const MockService = new (class MockService extends AbstractService {})(
(api as unknown) as ApiPromise
api as unknown as ApiPromise
);

const controller = new MockController(
(api as unknown) as ApiPromise,
api as unknown as ApiPromise,
'/mock',
MockService
);

// Mock arguments for Express RequestHandler
const req = ('req' as unknown) as Request;
const res = ('res' as unknown) as Response;
const req = 'req' as unknown as Request;
const res = 'res' as unknown as Response;

describe('AbstractController', () => {
describe('catchWrap', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/logging/consoleOverride.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function consoleOverride(logger: Logger): void {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
logger[winstonLevel].call(
logger,
(format.apply(format, args as [string]) as unknown) as object
format.apply(format, args as [string]) as unknown as object
);
};
});
Expand Down
2 changes: 1 addition & 1 deletion src/logging/transformers/nodeUtilFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as winston from 'winston';
export const nodeUtilFormat = winston.format(
(info: TransformableInfo, _opts: unknown) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const args = info[(SPLAT as unknown) as string];
const args = info[SPLAT as unknown as string];
if (args) {
info.message = format(info.message, ...args);
}
Expand Down
3 changes: 2 additions & 1 deletion src/logging/transformers/stripTimestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { format } from 'winston';
/**
* Regex that matches timestamps with the format of `YYYY-MM-DD HH:MM`
*/
const timestampRegex = /[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]/;
const timestampRegex =
/[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]/;

/**
* Slice out the timestamp from a message so it is not redundant with the winston
Expand Down
5 changes: 2 additions & 3 deletions src/middleware/error/errorMiddleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import {

const errorMiddlewareCallsNextWithErr = callsNextWithErr(errorMiddleware);

const errorMiddlewareCatchesErrWithStatus = catchesErrWithStatus(
errorMiddleware
);
const errorMiddlewareCatchesErrWithStatus =
catchesErrWithStatus(errorMiddleware);

describe('errorMiddleware', () => {
errorMiddlewareCallsNextWithErr('ILegacyError', {
Expand Down
10 changes: 4 additions & 6 deletions src/middleware/error/httpErrorMiddleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import {
catchesErrWithStatus,
} from './testTools';

const httpErrorMiddlewareCallsNextWithErr = callsNextWithErr(
httpErrorMiddleware
);
const httpErrorMiddlewareCallsNextWithErr =
callsNextWithErr(httpErrorMiddleware);

const httpErrorMiddlewareCatchesErrWithStatus = catchesErrWithStatus(
httpErrorMiddleware
);
const httpErrorMiddlewareCatchesErrWithStatus =
catchesErrWithStatus(httpErrorMiddleware);

describe('httpErrorMiddleware', () => {
httpErrorMiddlewareCallsNextWithErr('Error', new Error('This is an error'));
Expand Down
146 changes: 70 additions & 76 deletions src/middleware/error/testTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,29 @@ const mockReq = {} as Request;
* @param name name of the error type
* @param err error
*/
export const callsNextWithErr = (ware: ErrorRequestHandler) => (
name: string,
err: unknown
): void => {
it(`calls next on error of type ${name}`, () => {
const next = jest.fn();
const send = jest.fn();
const status = jest.fn((_code: number) => {
return {
send,
};
});
export const callsNextWithErr =
(ware: ErrorRequestHandler) =>
(name: string, err: unknown): void => {
it(`calls next on error of type ${name}`, () => {
const next = jest.fn();
const send = jest.fn();
const status = jest.fn((_code: number) => {
return {
send,
};
});

ware(
err,
mockReq,
({ headersSent: false, status } as unknown) as Response,
next
);
expect(status).not.toBeCalled();
expect(send).not.toBeCalled();
expect(next).toBeCalledTimes(1);
});
};
ware(
err,
mockReq,
{ headersSent: false, status } as unknown as Response,
next
);
expect(status).not.toBeCalled();
expect(send).not.toBeCalled();
expect(next).toBeCalledTimes(1);
});
};

/**
* Assert that a middleware function (`ware`) will catch `err` and set status to
Expand All @@ -46,32 +45,30 @@ export const callsNextWithErr = (ware: ErrorRequestHandler) => (
* @param err error
* @param code expected code to be sent as status
*/
export const catchesErrWithStatus = (ware: ErrorRequestHandler) => (
name: string,
err: unknown,
code: number
): void => {
it(`catches ${name} and sends status code ${code}`, () => {
const next = jest.fn();
const send = jest.fn();
const status = jest.fn((_code: number) => {
return {
send,
};
});
export const catchesErrWithStatus =
(ware: ErrorRequestHandler) =>
(name: string, err: unknown, code: number): void => {
it(`catches ${name} and sends status code ${code}`, () => {
const next = jest.fn();
const send = jest.fn();
const status = jest.fn((_code: number) => {
return {
send,
};
});

ware(
err,
mockReq,
({ headersSent: false, status } as unknown) as Response,
next
);
expect(send).toBeCalledTimes(1);
expect(status).toBeCalledWith<[number]>(code);
expect(status).toBeCalledTimes(1);
expect(next).not.toBeCalled();
});
};
ware(
err,
mockReq,
{ headersSent: false, status } as unknown as Response,
next
);
expect(send).toBeCalledTimes(1);
expect(status).toBeCalledWith<[number]>(code);
expect(status).toBeCalledTimes(1);
expect(next).not.toBeCalled();
});
};

/**
* Assert that a middleware function (`ware`) will catch `err`, set status to
Expand All @@ -83,34 +80,31 @@ export const catchesErrWithStatus = (ware: ErrorRequestHandler) => (
* @param code expected code to be sent as status
* @param response expected response body
*/
export const catchesErrWithResponse = (ware: ErrorRequestHandler) => (
name: string,
err: unknown,
code: number,
response: unknown
): void => {
it(`catches ${name} and sends status code ${code}`, () => {
const next = jest.fn();
const send = jest.fn();
const status = jest.fn((_code: number) => {
return {
send,
};
});
export const catchesErrWithResponse =
(ware: ErrorRequestHandler) =>
(name: string, err: unknown, code: number, response: unknown): void => {
it(`catches ${name} and sends status code ${code}`, () => {
const next = jest.fn();
const send = jest.fn();
const status = jest.fn((_code: number) => {
return {
send,
};
});

ware(
err,
mockReq,
({ headersSent: false, status } as unknown) as Response,
next
);
expect(send).toBeCalledTimes(1);
expect(send).toBeCalledWith(response);
expect(status).toBeCalledWith<[number]>(code);
expect(status).toBeCalledTimes(1);
expect(next).not.toBeCalled();
});
};
ware(
err,
mockReq,
{ headersSent: false, status } as unknown as Response,
next
);
expect(send).toBeCalledTimes(1);
expect(send).toBeCalledWith(response);
expect(status).toBeCalledWith<[number]>(code);
expect(status).toBeCalledTimes(1);
expect(next).not.toBeCalled();
});
};

export function callsNextWithSentHeaders(
ware: ErrorRequestHandler,
Expand All @@ -128,7 +122,7 @@ export function callsNextWithSentHeaders(
ware(
err,
mockReq,
({ headersSent: true, status } as unknown) as Response,
{ headersSent: true, status } as unknown as Response,
next
);
expect(send).not.toBeCalled();
Expand Down
Loading

0 comments on commit c67ae2f

Please sign in to comment.