UNPKG

@bsv/wallet-toolbox

Version:

BRC100 conforming wallet, wallet storage and wallet signer components

81 lines 3.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const TestUtilsWalletStorage_1 = require("../utils/TestUtilsWalletStorage"); const index_all_1 = require("../../src/index.all"); describe('KnexMigrations tests', () => { jest.setTimeout(99999999); const knexs = []; const env = TestUtilsWalletStorage_1._tu.getEnvFlags('test'); beforeAll(async () => { const localSQLiteFile = await TestUtilsWalletStorage_1._tu.newTmpFile('migratetest.sqlite', true, false, true); const knexSQLite = TestUtilsWalletStorage_1._tu.createLocalSQLite(localSQLiteFile); knexs.push(knexSQLite); if (env.runMySQL) { const knexMySQL = TestUtilsWalletStorage_1._tu.createLocalMySQL('migratetest'); knexs.push(knexMySQL); } }); afterAll(async () => { for (const knex of knexs) { await knex.destroy(); } }); let done0 = false; const waitFor0 = async () => { while (!done0) await (0, index_all_1.wait)(100); }; let done1 = false; const waitFor1 = async () => { while (!done1) await (0, index_all_1.wait)(100); }; test('0 migragte down', async () => { for (const knex of knexs) { const config = { migrationSource: new index_all_1.KnexMigrations('test', '0 migration test', '1'.repeat(64), 1000) }; const count = Object.keys(config.migrationSource.migrations).length; for (let i = 0; i < count; i++) { try { const r = await knex.migrate.down(config); expect(r).toBeTruthy(); } catch (eu) { break; } } } done0 = true; }); test('1 migragte to latest', async () => { await waitFor0(); for (const knex of knexs) { const config = { migrationSource: new index_all_1.KnexMigrations('test', '0 migration test', '1'.repeat(64), 1000) }; const latest = await index_all_1.KnexMigrations.latestMigration(); await knex.migrate.latest(config); const version = await knex.migrate.currentVersion(config); expect(version).toBe(latest); } done1 = true; }); test('2 getSettings', async () => { await waitFor1(); for (const knex of knexs) { const storage = new index_all_1.StorageKnex({ ...index_all_1.StorageKnex.defaultOptions(), chain: 'test', knex }); await storage.makeAvailable(); const r = await storage.getSettings(); expect(r.created_at instanceof Date).toBe(true); expect(r.updated_at instanceof Date).toBe(true); expect(r.chain).toBe('test'); expect(r.maxOutputScript).toBe(1000); } }); }); //# sourceMappingURL=KnexMigrations.test.js.map