Bump dev (incl. lint fixes) (#579)

* Bump dev (incl. lint fixes)

* Fix failures
This commit is contained in:
Jaco Greeff
2020-04-01 21:20:50 +02:00
committed by GitHub
parent 6429cc307c
commit cbec4add88
24 changed files with 374 additions and 283 deletions
+2 -2
View File
@@ -46,8 +46,8 @@ describe('bnToBn', (): void => {
it('converts Compact to BN', (): void => {
expect(
bnToBn({
toBn: (): BN => new BN(1234),
something: 'test'
something: 'test',
toBn: (): BN => new BN(1234)
}).toNumber()
).toEqual(1234);
});
+2 -2
View File
@@ -45,13 +45,13 @@ describe('bnToU8a', (): void => {
it('converts negative numbers (BE)', (): void => {
expect(
bnToU8a(new BN(-1234), { isNegative: true, isLe: false })
bnToU8a(new BN(-1234), { isLe: false, isNegative: true })
).toEqual(new Uint8Array([251, 46]));
});
it('converts negative numbers (bitLength)', (): void => {
expect(
bnToU8a(new BN(-1234), { isNegative: true, bitLength: 32 })
bnToU8a(new BN(-1234), { bitLength: 32, isNegative: true })
).toEqual(new Uint8Array([46, 251, 255, 255]));
});
+1 -1
View File
@@ -30,9 +30,9 @@ function bnToU8a (value: BN | BigInt | number | null, options?: Options): Uint8A
function bnToU8a (value: BN | BigInt | number | null, bitLength?: number, isLe?: boolean): Uint8Array;
function bnToU8a (value: BN | BigInt | number | null, arg1: number | Options = { bitLength: -1, isLe: true, isNegative: false }, arg2?: boolean): Uint8Array {
const _options: Options = {
bitLength: -1,
isLe: true,
isNegative: false,
bitLength: -1,
...isNumber(arg1) ? { bitLength: arg1, isLe: arg2 } : arg1
};
+15 -15
View File
@@ -76,20 +76,20 @@ describe('encode', (): void => {
describe('from Rust', (): void => {
// Copied from https://github.com/paritytech/parity-codec/blob/master/src/codec.rs
const testCases = [
{ value: new BN('0'), expected: '00' },
{ value: new BN('63'), expected: 'fc' },
{ value: new BN('64'), expected: '01 01' },
{ value: new BN('16383'), expected: 'fd ff' },
{ value: new BN('16384'), expected: '02 00 01 00' },
{ value: new BN('1073741823'), expected: 'fe ff ff ff' },
{ value: new BN('1073741824'), expected: '03 00 00 00 40' },
{ value: new BN(`${1}${'0'.repeat(32)}`, 2).subn(1), expected: '03 ff ff ff ff' },
{ value: new BN(`${1}${'0'.repeat(32)}`, 2), expected: '07 00 00 00 00 01' },
{ value: new BN(`${1}${'0'.repeat(40)}`, 2), expected: '0b 00 00 00 00 00 01' },
{ value: new BN(`${1}${'0'.repeat(48)}`, 2), expected: '0f 00 00 00 00 00 00 01' },
{ value: new BN(`${1}${'0'.repeat(56)}`, 2).subn(1), expected: '0f ff ff ff ff ff ff ff' },
{ value: new BN(`${1}${'0'.repeat(56)}`, 2), expected: '13 00 00 00 00 00 00 00 01' },
{ value: new BN(`${1}${'0'.repeat(64)}`, 2).subn(1), expected: '13 ff ff ff ff ff ff ff ff' }
{ expected: '00', value: new BN('0') },
{ expected: 'fc', value: new BN('63') },
{ expected: '01 01', value: new BN('64') },
{ expected: 'fd ff', value: new BN('16383') },
{ expected: '02 00 01 00', value: new BN('16384') },
{ expected: 'fe ff ff ff', value: new BN('1073741823') },
{ expected: '03 00 00 00 40', value: new BN('1073741824') },
{ expected: '03 ff ff ff ff', value: new BN(`${1}${'0'.repeat(32)}`, 2).subn(1) },
{ expected: '07 00 00 00 00 01', value: new BN(`${1}${'0'.repeat(32)}`, 2) },
{ expected: '0b 00 00 00 00 00 01', value: new BN(`${1}${'0'.repeat(40)}`, 2) },
{ expected: '0f 00 00 00 00 00 00 01', value: new BN(`${1}${'0'.repeat(48)}`, 2) },
{ expected: '0f ff ff ff ff ff ff ff', value: new BN(`${1}${'0'.repeat(56)}`, 2).subn(1) },
{ expected: '13 00 00 00 00 00 00 00 01', value: new BN(`${1}${'0'.repeat(56)}`, 2) },
{ expected: '13 ff ff ff ff ff ff ff ff', value: new BN(`${1}${'0'.repeat(64)}`, 2).subn(1) }
];
function testEncode (value: BN, expected: string): void {
@@ -104,6 +104,6 @@ describe('encode', (): void => {
});
}
testCases.forEach(({ value, expected }): void => testEncode(value, expected));
testCases.forEach(({ expected, value }): void => testEncode(value, expected));
});
});
+18 -18
View File
@@ -17,13 +17,13 @@ describe('formatBalance', (): void => {
it('formats 123,456,789,000 (decimals=15)', (): void => {
expect(
formatBalance(TESTVAL, { withSi: true, decimals: 15 })
formatBalance(TESTVAL, { decimals: 15, withSi: true })
).toEqual('123.456µ Unit');
});
it('formats BigInt numbers', (): void => {
expect(
formatBalance(123_456_789_000n, { withSi: true, decimals: 15 })
formatBalance(123_456_789_000n, { decimals: 15, withSi: true })
).toEqual('123.456µ Unit');
});
@@ -35,24 +35,24 @@ describe('formatBalance', (): void => {
it('formats 123,456,789,000 (decimals=36, option)', (): void => {
expect(
formatBalance(TESTVAL, { withSi: true, decimals: 36 })
formatBalance(TESTVAL, { decimals: 36, withSi: true })
).toEqual('0.123y Unit');
});
it('formats 123,456,789,000 (decimals=15, Compact)', (): void => {
const compact = {
something: 'else',
toBn: (): BN => TESTVAL,
unwrap: (): BN => TESTVAL,
something: 'else'
unwrap: (): BN => TESTVAL
};
expect(
formatBalance(compact, { withSi: true, decimals: 15 })
formatBalance(compact, { decimals: 15, withSi: true })
).toEqual('123.456µ Unit');
});
it('formats 123,456,789,000 (decimals=12)', (): void => {
expect(
formatBalance(TESTVAL, { withSi: true, decimals: 12 })
formatBalance(TESTVAL, { decimals: 12, withSi: true })
).toEqual('123.456m Unit');
});
@@ -173,13 +173,13 @@ describe('formatBalance', (): void => {
it('finds the SI value', (): void => {
expect(
formatBalance.findSi('k')
).toEqual({ power: 3, value: 'k', text: 'Kilo' });
).toEqual({ power: 3, text: 'Kilo', value: 'k' });
});
it('returns default on not found', (): void => {
expect(
formatBalance.findSi('blah')
).toEqual({ power: 0, value: '-', text: 'Unit' });
).toEqual({ power: 0, text: 'Unit', value: '-' });
});
});
@@ -214,15 +214,15 @@ describe('formatBalance', (): void => {
expect(
formatBalance.getOptions()
).toEqual([
{ power: 0, value: '-', text: 'TEST' },
{ power: 3, value: 'k', text: 'Kilo' },
{ power: 6, value: 'M', text: 'Mega' },
{ power: 9, value: 'G', text: 'Giga' },
{ power: 12, value: 'T', text: 'Tera' },
{ power: 15, value: 'P', text: 'Peta' },
{ power: 18, value: 'E', text: 'Exa' },
{ power: 21, value: 'Z', text: 'Zeta' },
{ power: 24, value: 'Y', text: 'Yotta' }
{ power: 0, text: 'TEST', value: '-' },
{ power: 3, text: 'Kilo', value: 'k' },
{ power: 6, text: 'Mega', value: 'M' },
{ power: 9, text: 'Giga', value: 'G' },
{ power: 12, text: 'Tera', value: 'T' },
{ power: 15, text: 'Peta', value: 'P' },
{ power: 18, text: 'Exa', value: 'E' },
{ power: 21, text: 'Zeta', value: 'Z' },
{ power: 24, text: 'Yotta', value: 'Y' }
]);
});
});
+17 -17
View File
@@ -7,23 +7,23 @@ import { SiDef } from '../types';
export const SI_MID = 8;
export const SI: SiDef[] = [
{ power: -24, value: 'y', text: 'yocto' },
{ power: -21, value: 'z', text: 'zepto' },
{ power: -18, value: 'a', text: 'atto' },
{ power: -15, value: 'f', text: 'femto' },
{ power: -12, value: 'p', text: 'pico' },
{ power: -9, value: 'n', text: 'nano' },
{ power: -6, value: 'µ', text: 'micro' },
{ power: -3, value: 'm', text: 'milli' },
{ power: 0, value: '-', text: 'Unit' }, // position 8
{ power: 3, value: 'k', text: 'Kilo' },
{ power: 6, value: 'M', text: 'Mega' },
{ power: 9, value: 'G', text: 'Giga' },
{ power: 12, value: 'T', text: 'Tera' },
{ power: 15, value: 'P', text: 'Peta' },
{ power: 18, value: 'E', text: 'Exa' },
{ power: 21, value: 'Z', text: 'Zeta' },
{ power: 24, value: 'Y', text: 'Yotta' }
{ power: -24, text: 'yocto', value: 'y' },
{ power: -21, text: 'zepto', value: 'z' },
{ power: -18, text: 'atto', value: 'a' },
{ power: -15, text: 'femto', value: 'f' },
{ power: -12, text: 'pico', value: 'p' },
{ power: -9, text: 'nano', value: 'n' },
{ power: -6, text: 'micro', value: 'µ' },
{ power: -3, text: 'milli', value: 'm' },
{ power: 0, text: 'Unit', value: '-' }, // position 8
{ power: 3, text: 'Kilo', value: 'k' },
{ power: 6, text: 'Mega', value: 'M' },
{ power: 9, text: 'Giga', value: 'G' },
{ power: 12, text: 'Tera', value: 'T' },
{ power: 15, text: 'Peta', value: 'P' },
{ power: 18, text: 'Exa', value: 'E' },
{ power: 21, text: 'Zeta', value: 'Z' },
{ power: 24, text: 'Yotta', value: 'Y' }
];
// Given a SI type (e.g. k, m, Y) find the SI definition