Formatting
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
import { expect, test, describe, beforeEach, afterEach } from "vitest";
|
||||
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import {
|
||||
existsSync,
|
||||
mkdirSync,
|
||||
readFileSync,
|
||||
rmSync,
|
||||
writeFileSync,
|
||||
} from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
@@ -12,7 +18,8 @@ import {
|
||||
} from "../../src/cli/mnemonic";
|
||||
import { BCHMnemonicURL } from "../../src/utils/bch-mnemonic-url";
|
||||
|
||||
const TEST_SEED = "page pencil stock planet limb cluster assault speak off joke private pioneer";
|
||||
const TEST_SEED =
|
||||
"page pencil stock planet limb cluster assault speak off joke private pioneer";
|
||||
|
||||
describe("mnemonic utilities", () => {
|
||||
let tempDir: string;
|
||||
@@ -68,7 +75,11 @@ describe("mnemonic utilities", () => {
|
||||
});
|
||||
|
||||
test("sanitizes filename to basename only", () => {
|
||||
const filename = createMnemonicFile(tempDir, TEST_SEED, "../../../evil-path");
|
||||
const filename = createMnemonicFile(
|
||||
tempDir,
|
||||
TEST_SEED,
|
||||
"../../../evil-path",
|
||||
);
|
||||
|
||||
expect(filename).toBe("evil-path");
|
||||
expect(existsSync(path.join(tempDir, "evil-path"))).toBe(true);
|
||||
@@ -95,7 +106,10 @@ describe("mnemonic utilities", () => {
|
||||
|
||||
try {
|
||||
writeFileSync(path.join(tempDir, "mnemonic-relative"), "test");
|
||||
const resolved = resolveMnemonicFilePath("/nonexistent", "mnemonic-relative");
|
||||
const resolved = resolveMnemonicFilePath(
|
||||
"/nonexistent",
|
||||
"mnemonic-relative",
|
||||
);
|
||||
expect(resolved).toBe(path.join(tempDir, "mnemonic-relative"));
|
||||
} finally {
|
||||
process.chdir(originalCwd);
|
||||
@@ -110,15 +124,18 @@ describe("mnemonic utilities", () => {
|
||||
});
|
||||
|
||||
test("throws when file not found anywhere", () => {
|
||||
expect(() => resolveMnemonicFilePath(tempDir, "nonexistent-file")).toThrow(
|
||||
/Mnemonic file not found/,
|
||||
);
|
||||
expect(() =>
|
||||
resolveMnemonicFilePath(tempDir, "nonexistent-file"),
|
||||
).toThrow(/Mnemonic file not found/);
|
||||
});
|
||||
|
||||
test("strips path components and looks up basename in mnemonicsDir", () => {
|
||||
writeFileSync(path.join(tempDir, "mnemonic-basename"), "test");
|
||||
|
||||
const resolved = resolveMnemonicFilePath(tempDir, "some/path/mnemonic-basename");
|
||||
const resolved = resolveMnemonicFilePath(
|
||||
tempDir,
|
||||
"some/path/mnemonic-basename",
|
||||
);
|
||||
expect(resolved).toBe(path.join(tempDir, "mnemonic-basename"));
|
||||
});
|
||||
});
|
||||
@@ -140,11 +157,16 @@ describe("mnemonic utilities", () => {
|
||||
});
|
||||
|
||||
test("throws when file not found", () => {
|
||||
expect(() => loadMnemonic(tempDir, "nonexistent")).toThrow(/Mnemonic file not found/);
|
||||
expect(() => loadMnemonic(tempDir, "nonexistent")).toThrow(
|
||||
/Mnemonic file not found/,
|
||||
);
|
||||
});
|
||||
|
||||
test("throws when file contains invalid data", () => {
|
||||
writeFileSync(path.join(tempDir, "mnemonic-invalid"), "not a valid mnemonic url");
|
||||
writeFileSync(
|
||||
path.join(tempDir, "mnemonic-invalid"),
|
||||
"not a valid mnemonic url",
|
||||
);
|
||||
|
||||
expect(() => loadMnemonic(tempDir, "mnemonic-invalid")).toThrow();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user