UNPKG

@bsv/wallet-toolbox

Version:

BRC100 conforming wallet, wallet storage and wallet signer components

161 lines 6.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const sdk_1 = require("@bsv/sdk"); const src_1 = require("../../../src"); const sdk_2 = require("../../../src/sdk"); const TestUtilsWalletStorage_1 = require("../../utils/TestUtilsWalletStorage"); describe('specOps tests', () => { jest.setTimeout(99999999); test('00', () => { }); if (TestUtilsWalletStorage_1._tu.noTestEnv('test')) return; if (TestUtilsWalletStorage_1._tu.noTestEnv('main')) return; test('0 wallet balance specOp', async () => { const setup = await createSetup('test'); const r = await setup.wallet.listOutputs({ basket: sdk_2.specOpWalletBalance }); expect(r.totalOutputs > 0).toBe(true); expect(r.outputs.length === 0).toBe(true); await setup.wallet.destroy(); }); test('0a wallet balance method', async () => { const setup = await createSetup('test'); const r = await setup.wallet.balance(); expect(r > 0).toBe(true); await setup.wallet.destroy(); }); test('0b wallet balanceAndUtxos method', async () => { const setup = await createSetup('test'); const r = await setup.wallet.balanceAndUtxos('default'); expect(r.total > 0).toBe(true); expect(r.utxos.length === 0).toBe(true); await setup.wallet.destroy(); }); test('1 wallet invalid change outputs specOp', async () => { const setup = await createSetup('test'); const r = await setup.wallet.listOutputs({ basket: sdk_2.specOpInvalidChange //tags: ['release', 'all'] }); expect(r.totalOutputs).toBe(0); expect(r.outputs.length).toBe(0); await setup.wallet.destroy(); }); test('1a wallet reviewSpendableOutputs method', async () => { const setup = await createSetup('test'); const r = await setup.wallet.reviewSpendableOutputs(false, false, {}); expect(r.totalOutputs).toBe(0); expect(r.outputs.length).toBe(0); await setup.wallet.destroy(); }); test('2 update default basket params specOp', async () => { const setup = await createSetup('test'); const before = (0, src_1.verifyOne)(await setup.activeStorage.findOutputBaskets({ partial: { userId: setup.userId, name: 'default' } })); const r = await setup.wallet.listOutputs({ basket: sdk_2.specOpSetWalletChangeParams, tags: ['33', '6'] }); const after = (0, src_1.verifyOne)(await setup.activeStorage.findOutputBaskets({ partial: { userId: setup.userId, name: 'default' } })); expect(r.totalOutputs).toBe(0); expect(r.outputs.length).toBe(0); expect(after.minimumDesiredUTXOValue).toBe(6); expect(after.numberOfDesiredUTXOs).toBe(33); // Restore original values... await setup.wallet.listOutputs({ basket: sdk_2.specOpSetWalletChangeParams, tags: [before.numberOfDesiredUTXOs.toString(), before.minimumDesiredUTXOValue.toString()] }); await setup.wallet.destroy(); }); test('2a update default basket params specOp', async () => { const setup = await createSetup('test'); const before = (0, src_1.verifyOne)(await setup.activeStorage.findOutputBaskets({ partial: { userId: setup.userId, name: 'default' } })); await setup.wallet.setWalletChangeParams(33, 6); const after = (0, src_1.verifyOne)(await setup.activeStorage.findOutputBaskets({ partial: { userId: setup.userId, name: 'default' } })); expect(after.minimumDesiredUTXOValue).toBe(6); expect(after.numberOfDesiredUTXOs).toBe(33); // Restore original values... await setup.wallet.setWalletChangeParams(before.numberOfDesiredUTXOs, before.minimumDesiredUTXOValue); await setup.wallet.destroy(); }); test('3 wallet listNoSendActions method', async () => { const setup = await createSetup('test'); const r = await setup.wallet.listNoSendActions({ labels: [ // 'abort' ] }); expect(r.totalActions).toBeGreaterThanOrEqual(0); expect(r.actions.length).toBe(r.totalActions); await setup.wallet.destroy(); }); test('4 wallet listFailedActions method', async () => { const setup = await createSetup('test'); const r = await setup.wallet.listFailedActions({ labels: [ // 'unfail' ], limit: 1000 }); expect(r.totalActions).toBeGreaterThanOrEqual(0); expect(r.actions.length).toBe(r.totalActions); await setup.wallet.destroy(); }); test('5 Wallet specOpThrowReviewActions', async () => { const setup = await createSetup('test'); try { const r = await setup.wallet.createAction({ labels: [sdk_2.specOpThrowReviewActions], description: 'must throw' }); expect(true).toBe(false); } catch (eu) { const e = src_1.sdk.WalletError.fromUnknown(eu); expect(e.code).toBe('WERR_REVIEW_ACTIONS'); expect(e.reviewActionResults).toBeTruthy(); } await setup.wallet.destroy(); }); test('6 WalletClient specOpThrowReviewActions', async () => { const wallet = new sdk_1.WalletClient(undefined, '6.specOps.man.test'); try { const r = await wallet.createAction({ labels: [sdk_2.specOpThrowReviewActions], description: 'must throw' }); expect(true).toBe(false); } catch (eu) { const e = src_1.sdk.WalletError.fromUnknown(eu); expect(e.code).toBe('WERR_REVIEW_ACTIONS'); expect(e.reviewActionResults).toBeTruthy(); } }); }); async function createSetup(chain) { const env = TestUtilsWalletStorage_1._tu.getEnv(chain); if (!env.testIdentityKey) throw new src_1.sdk.WERR_INVALID_PARAMETER('env.testIdentityKey', 'valid'); if (!env.testFilePath) throw new src_1.sdk.WERR_INVALID_PARAMETER('env.testFilePath', 'valid'); const setup = await TestUtilsWalletStorage_1._tu.createTestWallet({ chain, rootKeyHex: env.devKeys[env.testIdentityKey], filePath: env.testFilePath, setActiveClient: false, addLocalBackup: false, useMySQLConnectionForClient: false }); console.log(`ACTIVE STORAGE: ${setup.storage.getActiveStoreName()}`); return setup; } //# sourceMappingURL=specOps.man.test.js.map