Prefer static checking (#43)

This commit is contained in:
Jaco Greeff
2017-12-18 20:08:16 +01:00
committed by GitHub
parent 34be54abaf
commit c980d3e69b
17 changed files with 49 additions and 80 deletions
+2 -2
View File
@@ -33,8 +33,8 @@
"@polkadot/api-jsonrpc": "^0.6.7"
},
"dependencies": {
"@polkadot/primitives-json": "^0.3.1",
"@polkadot/util": "^0.9.1",
"@polkadot/primitives-json": "^0.4.1",
"@polkadot/util": "^0.10.1",
"babel-runtime": "^6.26.0"
}
}
+2 -2
View File
@@ -13,8 +13,8 @@ describe('formatInputs', () => {
['0x1234', '0xabcd']
)
).toEqual([
'0x0000000000000000000000000000000000001234',
'0x000000000000000000000000000000000000000000000000000000000000abcd'
'0x1234',
'0xabcd'
]);
});
});
+3 -3
View File
@@ -21,10 +21,10 @@ describe('formatOutput', () => {
)
).toEqual(
JSON.stringify({
parentHash: '0x0000000000000000000000000000000000000000000000000000000000001234',
parentHash: '0x1234',
number: new BN(0x1234),
stateRoot: '0x0000000000000000000000000000000000000000000000000000000000005678',
transactionRoot: '0x000000000000000000000000000000000000000000000000000000000000abcd',
stateRoot: '0x5678',
transactionRoot: '0xabcd',
digest: {
parachainActivityBitfield: Buffer.from([0x12, 0x34]),
logs: [
+2 -5
View File
@@ -3,7 +3,6 @@
import type { FormatterFunction } from './types';
const assert = require('@polkadot/util/assert');
const isUndefined = require('@polkadot/util/is/undefined');
const echo = require('./echo');
@@ -25,12 +24,10 @@ function formatSingleType (formatters: { [any]: FormatterFunction }, type: strin
}
}
function formatArrayType (formatters: { [any]: FormatterFunction }, type: string, value: any): any {
assert(Array.isArray(value), `Unable to format non-array '${value}' as '${type}'`);
function formatArrayType (formatters: { [any]: FormatterFunction }, type: string, value: Array<any>): any {
type = type.replace(arrayTypeRegex, '');
return (value: Array<any>).map((value) => {
return value.map((value) => {
return formatSingleType(formatters, type, value);
});
}
-6
View File
@@ -53,12 +53,6 @@ describe('util', () => {
});
describe('primitive[]', () => {
it('throws exception with array type, but non-array value', () => {
expect(
() => format(formatters, 'Address[]', 'not-an-array')
).toThrow(/Unable to format non-array/);
});
it('formats using the primitive type', () => {
format(formatters, 'Address[]', ['0x123', '0x234']);