Make isLe required in conversion (#180)
* Make isLe required in conversion * Update logger Date format * Fallback encoding sizes
This commit is contained in:
@@ -9,25 +9,25 @@ import { bnToU8a } from './index';
|
||||
describe('bnToU8a', () => {
|
||||
it('converts null values to 0x00', () => {
|
||||
expect(
|
||||
bnToU8a(null)
|
||||
bnToU8a(null, -1, false)
|
||||
).toEqual(new Uint8Array([]));
|
||||
});
|
||||
|
||||
it('converts null values to 0x00000000 (bitLength)', () => {
|
||||
expect(
|
||||
bnToU8a(null, 32)
|
||||
bnToU8a(null, 32, false)
|
||||
).toEqual(new Uint8Array([0, 0, 0, 0]));
|
||||
});
|
||||
|
||||
it('converts BN values to a prefixed hex representation', () => {
|
||||
expect(
|
||||
bnToU8a(new BN(0x123456))
|
||||
bnToU8a(new BN(0x123456), -1, false)
|
||||
).toEqual(new Uint8Array([0x12, 0x34, 0x56]));
|
||||
});
|
||||
|
||||
it('converts BN values to a prefixed hex representation (bitLength)', () => {
|
||||
expect(
|
||||
bnToU8a(new BN(0x123456), 32)
|
||||
bnToU8a(new BN(0x123456), 32, false)
|
||||
).toEqual(new Uint8Array([0x00, 0x12, 0x34, 0x56]));
|
||||
});
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import bnToHex from './toHex';
|
||||
*
|
||||
* bnToU8a(new BN(0x1234)); // => [0x12, 0x34]
|
||||
*/
|
||||
export default function bnToU8a (value?: BN | number, bitLength: number = -1, isLe: boolean = false): Uint8Array {
|
||||
export default function bnToU8a (value: BN | number, bitLength: number, isLe: boolean): Uint8Array {
|
||||
const byteLength = Math.ceil(bitLength / 8);
|
||||
|
||||
if (!value) {
|
||||
|
||||
@@ -29,7 +29,9 @@ describe('logger', () => {
|
||||
};
|
||||
global.console = spy;
|
||||
|
||||
dateMatch = expect.stringMatching(/20[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/);
|
||||
|
||||
// dateMatch = expect.stringMatching(/20[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/);
|
||||
dateMatch = expect.stringMatching(/20[0-9]{2}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}/);
|
||||
prefixMatch = expect.stringMatching(/TEST:/);
|
||||
});
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ function apply (log: LogType, type: string, values: Logger$Data): void {
|
||||
// @ts-ignore Not sure how to coax TS here...
|
||||
console[logTo[log]].apply(
|
||||
console, [
|
||||
chalk(new Date().toString()), chalk(type)
|
||||
chalk(new Date().toISOString()), chalk(type)
|
||||
].concat(values)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
import { u8aToBn } from './index';
|
||||
|
||||
describe('u8aToBn', () => {
|
||||
it('converts values', () => {
|
||||
it('converts values (big-endian)', () => {
|
||||
expect(
|
||||
u8aToBn(
|
||||
new Uint8Array([0x12, 0x34])
|
||||
new Uint8Array([0x12, 0x34]),
|
||||
false
|
||||
).toString(16)
|
||||
).toEqual('1234');
|
||||
});
|
||||
@@ -25,12 +26,13 @@ describe('u8aToBn', () => {
|
||||
it('converts empty', () => {
|
||||
expect(
|
||||
u8aToBn(
|
||||
new Uint8Array([])
|
||||
new Uint8Array([]),
|
||||
true
|
||||
).toString(16)
|
||||
).toEqual('0');
|
||||
});
|
||||
|
||||
it('handled overflows correctly', () => {
|
||||
it('handled overflows correctly (little-endian)', () => {
|
||||
expect(
|
||||
u8aToBn(
|
||||
new Uint8Array([ 0, 1, 0, 0, 0, 0, 0, 0 ]),
|
||||
|
||||
@@ -18,7 +18,7 @@ import u8aToHex from './toHex';
|
||||
*
|
||||
* u8aToHex(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0xf])); // 0x68656c0f
|
||||
*/
|
||||
export default function u8aToBn (value?: Uint8Array, isLe: boolean = false): BN {
|
||||
export default function u8aToBn (value: Uint8Array, isLe: boolean): BN {
|
||||
return hexToBn(
|
||||
u8aToHex(value),
|
||||
isLe
|
||||
|
||||
Reference in New Issue
Block a user