mirror of
https://github.com/pezkuwichain/pezkuwi-ui.git
synced 2026-06-23 09:31:04 +00:00
Encoding/decoding qr tests (#169)
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
const DEFAULT_IMG_SIZE = 300;
|
const DEFAULT_IMG_SIZE = 300;
|
||||||
const ADDRESS_PREFIX = 'substrate:';
|
const ADDRESS_PREFIX = 'substrate:';
|
||||||
const FRAME_SIZE = 1716;
|
const FRAME_SIZE = 2048;
|
||||||
const SUBSTRATE_ID = new Uint8Array([0x53]);
|
const SUBSTRATE_ID = new Uint8Array([0x53]);
|
||||||
const CRYPTO_SR25519 = new Uint8Array([0x01]);
|
const CRYPTO_SR25519 = new Uint8Array([0x01]);
|
||||||
const CMD_SIGN_TX = new Uint8Array([0x00]);
|
const CMD_SIGN_TX = new Uint8Array([0x00]);
|
||||||
|
|||||||
@@ -2,11 +2,36 @@
|
|||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// 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('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 => {
|
describe('encodeNumber', (): void => {
|
||||||
it('encodes 1 correctly', (): void => {
|
it('encodes 1 correctly', (): void => {
|
||||||
expect(
|
expect(
|
||||||
@@ -20,6 +45,7 @@ describe('util', (): void => {
|
|||||||
).toEqual(new Uint8Array([1, 1]));
|
).toEqual(new Uint8Array([1, 1]));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('createAddressPayload', (): void => {
|
describe('createAddressPayload', (): void => {
|
||||||
it('encodes an address properly', (): void => {
|
it('encodes an address properly', (): void => {
|
||||||
expect(
|
expect(
|
||||||
|
|||||||
Reference in New Issue
Block a user