UNPKG

wallet-storage

Version:

BRC100 conforming wallet, wallet storage and wallet signer components

122 lines 6.25 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const index_client_1 = require("../../../src/index.client"); const TaskPurge_1 = require("../../../src/monitor/tasks/TaskPurge"); const sync_1 = require("../../../src/storage/sync"); const TestUtilsWalletStorage_1 = require("../../utils/TestUtilsWalletStorage"); const dotenv = __importStar(require("dotenv")); dotenv.config(); /** * NOTICE: These tests are designed to chain one after the other. * Disable the "await WaitFor*()" lines to run them individually. * * The inital import from staging dojo takes around 100 seconds... be patient. */ describe('Wallet sync tests', () => { jest.setTimeout(99999999); beforeAll(async () => { }); afterAll(async () => { }); let doWait = false; let done0 = false; const waitFor0 = async () => { while (doWait && !done0) await (0, index_client_1.wait)(100); }; let done1 = false; const waitFor1 = async () => { while (doWait && !done1) await (0, index_client_1.wait)(100); }; let done2 = false; const waitFor2 = async () => { while (doWait && !done2) await (0, index_client_1.wait)(100); }; const env = TestUtilsWalletStorage_1._tu.getEnv('test'); const identityKeyTone = '03ac2d10bdb0023f4145cc2eba2fcd2ad3070cb2107b0b48170c46a9440e4cc3fe'; const rootKeyHex = env.devKeys[identityKeyTone]; test('0 sync staging dojo to local MySQL', async () => { console.log('Importing from staging dojo to local MySQL stagingdojotone'); const chain = 'test'; const connection = JSON.parse(process.env.TEST_DOJO_CONNECTION || ''); const readerKnex = TestUtilsWalletStorage_1._tu.createMySQLFromConnection(connection); const reader = new sync_1.StorageMySQLDojoReader({ chain, knex: readerKnex }); const writer = await TestUtilsWalletStorage_1._tu.createMySQLTestWallet({ databaseName: 'stagingdojotone', chain: 'test', rootKeyHex, dropAll: true }); const identityKey = writer.identityKey; await writer.storage.syncFromReader(identityKey, new index_client_1.StorageSyncReader({ identityKey }, reader)); await reader.destroy(); await writer.activeStorage.destroy(); done0 = true; }); test('1 aggressively purge records from MySQL stagingdojotone', async () => { await waitFor0(); const { monitor, activeStorage } = await TestUtilsWalletStorage_1._tu.createMySQLTestWallet({ databaseName: 'stagingdojotone', chain: 'test', rootKeyHex }); { const task = new TaskPurge_1.TaskPurge(monitor, { purgeCompleted: true, purgeFailed: true, purgeSpent: true, purgeCompletedAge: 1, purgeFailedAge: 1, purgeSpentAge: 1, }); TaskPurge_1.TaskPurge.checkNow = true; monitor._tasks.push(task); await monitor.runTask('Purge'); } await activeStorage.destroy(); done1 = true; }); test('2 sync pruned MySQL stagingdojotone to SQLite walletLegacyTestData', async () => { await waitFor1(); console.log('syncing local MySQL stagingdojotone to local SQLite walletLegacyTestData in tmp folder'); const reader = await TestUtilsWalletStorage_1._tu.createMySQLTestWallet({ databaseName: 'stagingdojotone', chain: 'test', rootKeyHex }); const writer = await TestUtilsWalletStorage_1._tu.createSQLiteTestWallet({ databaseName: 'walletLegacyTestData', chain: 'test', rootKeyHex, dropAll: true }); const identityKey = writer.identityKey; await writer.storage.syncFromReader(identityKey, new index_client_1.StorageSyncReader({ identityKey }, reader.activeStorage)); await reader.activeStorage.destroy(); await writer.activeStorage.destroy(); console.log('REMEMBER: copy walletLegacyTestData.sqlite from tmp up to data!'); done2 = true; }); test('3 sync pruned MySQL stagingdojotone to MySQL walletLegacyTestData', async () => { await waitFor2(); console.log('syncing local MySQL stagingdojotone to local SQLite walletLegacyTestData in tmp folder'); const reader = await TestUtilsWalletStorage_1._tu.createMySQLTestWallet({ databaseName: 'stagingdojotone', chain: 'test', rootKeyHex }); const writer = await TestUtilsWalletStorage_1._tu.createMySQLTestWallet({ databaseName: 'walletLegacyTestData', chain: 'test', rootKeyHex, dropAll: true }); const identityKey = writer.identityKey; await writer.storage.syncFromReader(identityKey, new index_client_1.StorageSyncReader({ identityKey }, reader.activeStorage)); await reader.activeStorage.destroy(); await writer.activeStorage.destroy(); }); }); //# sourceMappingURL=Wallet.updateWalletLegacyTestData.man.test.js.map