Encoding/decoding qr tests (#169)

This commit is contained in:
Jaco Greeff
2019-07-30 08:08:46 +02:00
committed by GitHub
parent da82e913c4
commit 939fb73db7
2 changed files with 29 additions and 3 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
const DEFAULT_IMG_SIZE = 300;
const ADDRESS_PREFIX = 'substrate:';
const FRAME_SIZE = 1716;
const FRAME_SIZE = 2048;
const SUBSTRATE_ID = new Uint8Array([0x53]);
const CRYPTO_SR25519 = new Uint8Array([0x01]);
const CMD_SIGN_TX = new Uint8Array([0x00]);
+28 -2
View File
@@ -2,11 +2,36 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { u8aToHex, u8aToString } from '@polkadot/util';
import { u8aConcat, u8aToHex, u8aToString } from '@polkadot/util';
import { createAddressPayload, createSignPayload, createFrames, encodeNumber, encodeString } from './util';
import { createAddressPayload, createSignPayload, createFrames, decodeString, encodeNumber, encodeString } from './util';
import { randomAsU8a } from '@polkadot/util-crypto';
describe('util', (): void => {
describe('Uint8Array <-> string', (): void => {
let u8a: Uint8Array;
let str: string;
beforeEach((): void => {
u8a = new Uint8Array(256);
for (let i = 0; i < 256; i++) {
u8a[i] = i;
}
u8a = u8aConcat(u8a, randomAsU8a(4096));
str = decodeString(u8a);
});
it('decodes into string', (): void => {
expect(str).toHaveLength(u8a.length);
});
it('have encode <-> decode', (): void => {
expect(encodeString(str)).toEqual(u8a);
});
});
describe('encodeNumber', (): void => {
it('encodes 1 correctly', (): void => {
expect(
@@ -20,6 +45,7 @@ describe('util', (): void => {
).toEqual(new Uint8Array([1, 1]));
});
});
describe('createAddressPayload', (): void => {
it('encodes an address properly', (): void => {
expect(