* Move test cryptoWaitReady top-level * Add missing mod.ts * Revert mod.ts add * Add types reference for tests * Adjust * adjust * node:fs & node:path
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
// Copyright 2017-2023 @polkadot/util-crypto authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// eslint-disable-next-line spaced-comment
|
|
/// <reference types="@polkadot/dev/node/test/node" />
|
|
|
|
import { cryptoWaitReady } from '..';
|
|
import { mnemonicGenerate } from './generate';
|
|
import { mnemonicValidate } from './validate';
|
|
|
|
await cryptoWaitReady();
|
|
|
|
describe('mnemonicGenerate', (): void => {
|
|
it('generates a valid mnemonic (default strength)', (): void => {
|
|
expect(
|
|
mnemonicValidate(mnemonicGenerate())
|
|
).toEqual(true);
|
|
});
|
|
|
|
for (const onlyJs of [false, true]) {
|
|
describe(`onlyJs=${(onlyJs && 'true') || 'false'}`, (): void => {
|
|
for (const num of <const> [12, 15, 18, 21, 24]) {
|
|
it(`generates a valid mnemonic (${num} words)`, (): void => {
|
|
const mnemonic = mnemonicGenerate(num, onlyJs);
|
|
const isValid = mnemonicValidate(mnemonic);
|
|
|
|
expect(mnemonic.split(' ')).toHaveLength(num);
|
|
expect(isValid).toEqual(true);
|
|
});
|
|
}
|
|
|
|
it('generates non-deterministic', (): void => {
|
|
const m1 = mnemonicGenerate(24, onlyJs);
|
|
const m2 = mnemonicGenerate(24, onlyJs);
|
|
|
|
expect(m1 === m2).toEqual(false);
|
|
expect(mnemonicValidate(m1)).toEqual(true);
|
|
expect(mnemonicValidate(m2)).toEqual(true);
|
|
});
|
|
});
|
|
}
|
|
});
|