61 lines
1.3 KiB
TypeScript
61 lines
1.3 KiB
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import fs from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
|
|
import { createWalletFromBackup } from '../src/index';
|
|
|
|
const backupFilename =
|
|
process.env.QORTAL_TEST_BACKUP_FILE ||
|
|
'qortal_backup_ - (not used) - QWs9LiX3B677cTsTGUysRF2tX5sJDo9nop.json';
|
|
|
|
const backupPath = path.resolve(
|
|
process.cwd(),
|
|
'..',
|
|
'..',
|
|
'TEST-FILES',
|
|
backupFilename
|
|
);
|
|
|
|
const password = process.env.QORTAL_TEST_BACKUP_PASSWORD;
|
|
|
|
const hasBackupFile = async () => {
|
|
try {
|
|
await fs.access(backupPath);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
if (!password) {
|
|
test(
|
|
'backup decrypt (skipped: set QORTAL_TEST_BACKUP_PASSWORD)',
|
|
{ skip: true },
|
|
() => {
|
|
assert.ok(true);
|
|
}
|
|
);
|
|
} else {
|
|
test('backup decrypt derives correct Qortal address', async () => {
|
|
if (!(await hasBackupFile())) {
|
|
test(
|
|
'backup decrypt (skipped: backup file missing)',
|
|
{ skip: true },
|
|
() => {
|
|
assert.ok(true);
|
|
}
|
|
);
|
|
return;
|
|
}
|
|
|
|
const raw = await fs.readFile(backupPath, 'utf8');
|
|
const backup = JSON.parse(raw);
|
|
|
|
const wallet = await createWalletFromBackup(password, backup);
|
|
|
|
assert.equal(wallet.addresses[0].address, backup.address0);
|
|
assert.equal(wallet.walletVersion, backup.version);
|
|
});
|
|
}
|