diff --git a/tests/boost.test.ts b/tests/boost.test.ts index cdfbc50..3b784aa 100644 --- a/tests/boost.test.ts +++ b/tests/boost.test.ts @@ -89,9 +89,7 @@ describe('Boost', async function () { // balance is 0 const r = await wallet.getNextAvailableAddress(); - if (r.isErr()) { - throw r.error; - } + if (r.isErr()) throw r.error; const a1 = r.value.addressIndex.address; await rpc.sendToAddress(a1, '1'); await rpc.generateToAddress(1, await rpc.getNewAddress()); @@ -103,9 +101,7 @@ describe('Boost', async function () { amount: 99999743, satsPerByte: 1 }); - if (s1.isErr()) { - throw s1.error; - } + if (s1.isErr()) throw s1.error; await wallet.refreshWallet({}); expect(wallet.data.balance).to.be.below(256); const b2 = wallet.canBoost(s1.value); @@ -120,9 +116,7 @@ describe('Boost', async function () { address: 'bcrt1q6rz28mcfaxtmd6v789l9rrlrusdprr9pz3cppk', amount: 10000000 }); - if (s2.isErr()) { - throw s2.error; - } + if (s2.isErr()) throw s2.error; await rpc.generateToAddress(1, await rpc.getNewAddress()); // confirm tx await wallet.refreshWallet({}); const b3 = wallet.canBoost(s2.value); @@ -131,9 +125,7 @@ describe('Boost', async function () { it('Should generate CPFP for send transaction', async () => { const r = await wallet.getNextAvailableAddress(); - if (r.isErr()) { - throw r.error; - } + if (r.isErr()) throw r.error; const a1 = r.value.addressIndex.address; await rpc.sendToAddress(a1, '1'); await rpc.generateToAddress(1, await rpc.getNewAddress()); @@ -148,18 +140,14 @@ describe('Boost', async function () { satsPerByte: 1, rbf: false }); - if (s1.isErr()) { - throw s1.error; - } + if (s1.isErr()) throw s1.error; const oldTxId = s1.value; await wallet.refreshWallet({}); const b1 = wallet.canBoost(oldTxId); expect(b1).to.deep.equal({ canBoost: true, rbf: false, cpfp: true }); const setup = await wallet.transaction.setupCpfp({ txid: oldTxId }); - if (setup.isErr()) { - throw setup.error; - } + if (setup.isErr()) throw setup.error; expect(setup.value.inputs.length).to.equal(1); expect(setup.value.outputs.length).to.equal(1); expect(setup.value.boostType).to.equal(EBoostType.cpfp); @@ -169,9 +157,7 @@ describe('Boost', async function () { expect(setup.value.satsPerByte).to.be.above(6); const createRes = await wallet.transaction.createTransaction(); - if (createRes.isErr()) { - throw createRes.error; - } + if (createRes.isErr()) throw createRes.error; const newTxId = createRes.value.id; wallet.electrum.broadcastTransaction({ rawTx: createRes.value.hex }); @@ -181,9 +167,7 @@ describe('Boost', async function () { type: EBoostType.cpfp, fee: setup.value.fee }); - if (addBoost.isErr()) { - throw addBoost.error; - } + if (addBoost.isErr()) throw addBoost.error; const boosted = wallet.getBoostedTransactions(); expect(boosted).to.deep.equal({ [oldTxId]: { @@ -205,18 +189,14 @@ describe('Boost', async function () { it('Should generate RBF for send transaction', async () => { const r = await wallet.getNextAvailableAddress(); - if (r.isErr()) { - throw r.error; - } + if (r.isErr()) throw r.error; const a1 = r.value.addressIndex.address; await rpc.sendToAddress(a1, '0.0001'); // 10000 sats await rpc.generateToAddress(1, await rpc.getNewAddress()); await waitForElectrum(); const r1 = await wallet.refreshWallet({}); - if (r1.isErr()) { - throw r1.error; - } + if (r1.isErr()) throw r1.error; expect(wallet.data.balance).to.equal(10000); // create and send original transaction @@ -226,35 +206,25 @@ describe('Boost', async function () { satsPerByte: 1, rbf: true }); - if (s1.isErr()) { - throw s1.error; - } + if (s1.isErr()) throw s1.error; const oldTxId = s1.value; const r2 = await wallet.refreshWallet({}); - if (r2.isErr()) { - throw r2.error; - } + if (r2.isErr()) throw r2.error; const b1 = wallet.canBoost(oldTxId); expect(b1).to.deep.equal({ canBoost: true, rbf: true, cpfp: true }); // replace original transaction using RBF const setup = await wallet.transaction.setupRbf({ txid: oldTxId }); - if (setup.isErr()) { - throw setup.error; - } + if (setup.isErr()) throw setup.error; expect(setup.value.boostType).to.equal(EBoostType.rbf); expect(setup.value.minFee).to.be.above(1); const createRes = await wallet.transaction.createTransaction(); - if (createRes.isErr()) { - throw createRes.error; - } + if (createRes.isErr()) throw createRes.error; const newTxId = createRes.value.id; const broadcastResp = await wallet.electrum.broadcastTransaction({ rawTx: createRes.value.hex }); - if (broadcastResp.isErr()) { - throw broadcastResp.error; - } + if (broadcastResp.isErr()) throw broadcastResp.error; const addBoost = await wallet.addBoostedTransaction({ oldTxId, @@ -262,9 +232,7 @@ describe('Boost', async function () { type: EBoostType.rbf, fee: setup.value.fee }); - if (addBoost.isErr()) { - throw addBoost.error; - } + if (addBoost.isErr()) throw addBoost.error; const boosted = wallet.getBoostedTransactions(); expect(boosted).to.deep.equal({ [oldTxId]: { @@ -276,9 +244,7 @@ describe('Boost', async function () { }); const r3 = await wallet.refreshWallet({}); - if (r3.isErr()) { - throw r3.error; - } + if (r3.isErr()) throw r3.error; expect(Object.keys(wallet.transactions).length).to.equal(2); expect(wallet.transactions).not.to.have.property(oldTxId); diff --git a/tests/derivation.test.ts b/tests/derivation.test.ts index e159ae2..d44915e 100644 --- a/tests/derivation.test.ts +++ b/tests/derivation.test.ts @@ -16,8 +16,7 @@ describe('Derivation Methods', () => { addressType: EAddressType.p2wpkh, network: EAvailableNetworks.mainnet }); - expect(pathRes.isErr()).to.equal(false); - if (pathRes.isErr()) return; + if (pathRes.isErr()) throw pathRes.error; expect(pathRes.value.purpose).to.equal('84'); expect(pathRes.value.coinType).to.equal('0'); expect(pathRes.value.account).to.equal('0'); @@ -29,8 +28,7 @@ describe('Derivation Methods', () => { addressType: EAddressType.p2sh, network: EAvailableNetworks.mainnet }); - expect(pathRes.isErr()).to.equal(false); - if (pathRes.isErr()) return; + if (pathRes.isErr()) throw pathRes.error; expect(pathRes.value.purpose).to.equal('49'); expect(pathRes.value.coinType).to.equal('0'); expect(pathRes.value.account).to.equal('0'); @@ -42,8 +40,7 @@ describe('Derivation Methods', () => { addressType: EAddressType.p2pkh, network: EAvailableNetworks.mainnet }); - expect(pathRes.isErr()).to.equal(false); - if (pathRes.isErr()) return; + if (pathRes.isErr()) throw pathRes.error; expect(pathRes.value.purpose).to.equal('44'); expect(pathRes.value.coinType).to.equal('0'); expect(pathRes.value.account).to.equal('0'); @@ -58,8 +55,7 @@ describe('Derivation Methods', () => { index: 0, network: EAvailableNetworks.mainnet }); - expect(pathRes.isErr()).to.equal(false); - if (pathRes.isErr()) return; + if (pathRes.isErr()) throw pathRes.error; expect(pathRes.value).to.equal("m/84'/0'/0'/1/0"); }); it('Should return a valid testnet p2sh derivation string at index 40', () => { @@ -69,8 +65,7 @@ describe('Derivation Methods', () => { index: '40', network: EAvailableNetworks.testnet }); - expect(pathRes.isErr()).to.equal(false); - if (pathRes.isErr()) return; + if (pathRes.isErr()) throw pathRes.error; expect(pathRes.value).to.equal("m/49'/1'/0'/0/40"); }); it('Should return a valid mainnet p2pkh derivation string at index 8', () => { @@ -80,8 +75,7 @@ describe('Derivation Methods', () => { index: 8, network: EAvailableNetworks.mainnet }); - expect(pathRes.isErr()).to.equal(false); - if (pathRes.isErr()) return; + if (pathRes.isErr()) throw pathRes.error; expect(pathRes.value).to.equal("m/44'/0'/0'/0/8"); }); @@ -90,8 +84,7 @@ describe('Derivation Methods', () => { path: "m/84'/0'/0'/1/0", network: EAvailableNetworks.mainnet }); - expect(pathRes.isErr()).to.equal(false); - if (pathRes.isErr()) return; + if (pathRes.isErr()) throw pathRes.error; expect(pathRes.value.purpose).to.equal('84'); expect(pathRes.value.coinType).to.equal('0'); expect(pathRes.value.account).to.equal('0'); @@ -103,8 +96,7 @@ describe('Derivation Methods', () => { path: "m/49'/1'/0'/0/40", network: EAvailableNetworks.testnet }); - expect(pathRes.isErr()).to.equal(false); - if (pathRes.isErr()) return; + if (pathRes.isErr()) throw pathRes.error; expect(pathRes.value.purpose).to.equal('49'); expect(pathRes.value.coinType).to.equal('1'); expect(pathRes.value.account).to.equal('0'); @@ -116,8 +108,7 @@ describe('Derivation Methods', () => { path: "m/44'/0'/0'/0/8", network: EAvailableNetworks.mainnet }); - expect(pathRes.isErr()).to.equal(false); - if (pathRes.isErr()) return; + if (pathRes.isErr()) throw pathRes.error; expect(pathRes.value.purpose).to.equal('44'); expect(pathRes.value.coinType).to.equal('0'); expect(pathRes.value.account).to.equal('0'); @@ -127,20 +118,17 @@ describe('Derivation Methods', () => { it('Should return a valid address type from p2wpkh path', () => { const pathRes = getAddressTypeFromPath("m/84'/0'/0'/0/0"); - expect(pathRes.isErr()).to.equal(false); - if (pathRes.isErr()) return; + if (pathRes.isErr()) throw pathRes.error; expect(pathRes.value).to.equal(EAddressType.p2wpkh); }); it('Should return a valid address type from p2sh path', () => { const pathRes = getAddressTypeFromPath("m/49'/0'/0'/0/0"); - expect(pathRes.isErr()).to.equal(false); - if (pathRes.isErr()) return; + if (pathRes.isErr()) throw pathRes.error; expect(pathRes.value).to.equal(EAddressType.p2sh); }); it('Should return a valid address type from p2pkh path', () => { const pathRes = getAddressTypeFromPath("m/44'/0'/0'/0/0"); - expect(pathRes.isErr()).to.equal(false); - if (pathRes.isErr()) return; + if (pathRes.isErr()) throw pathRes.error; expect(pathRes.value).to.equal(EAddressType.p2pkh); }); }); diff --git a/tests/electrum.test.ts b/tests/electrum.test.ts index 485f1f7..0e82680 100644 --- a/tests/electrum.test.ts +++ b/tests/electrum.test.ts @@ -27,11 +27,7 @@ before(async function () { tls } }); - if (res.isErr()) { - console.log('error: ', res.error.message); - //throw new Error(res.error.message); - return; - } + if (res.isErr()) throw res.error; wallet = res.value; await wallet.refreshWallet({}); }); @@ -40,8 +36,7 @@ describe('Electrum Methods', async function (): Promise { this.timeout(testTimeout); it('connectToElectrum: Should connect to a random Electrum server', async () => { const connectResponse = await wallet.connectToElectrum(); - expect(connectResponse.isErr()).to.equal(false); - if (connectResponse.isErr()) return; + if (connectResponse.isErr()) throw connectResponse.error; expect(connectResponse.value).to.equal('Connected to Electrum server.'); }); @@ -54,15 +49,13 @@ describe('Electrum Methods', async function (): Promise { const addressBalance = await wallet.getAddressBalance( 'tb1qyvc8r7338383xjshqsz38mfn2eql879nhrf8y0' ); - expect(addressBalance.isErr()).to.equal(false); - if (addressBalance.isErr()) return; + if (addressBalance.isErr()) throw addressBalance.error; expect(addressBalance.value.confirmed).to.equal(20000); }); it('getNextAvailableAddress: Should return the next available address/change index and the last used address/change index', async () => { const r = await wallet.getNextAvailableAddress(); - expect(r.isErr()).to.equal(false); - if (r.isErr()) return; + if (r.isErr()) throw r.error; expect(r.value).to.deep.equal( EXPECTED_SHARED_RESULTS.getNextAvailableAddress ); @@ -70,8 +63,7 @@ describe('Electrum Methods', async function (): Promise { it("Should return available UTXO's", async () => { const getUtxosRes: Result = await wallet.getUtxos({}); - expect(getUtxosRes.isErr()).to.equal(false); - if (getUtxosRes.isErr()) return; + if (getUtxosRes.isErr()) throw getUtxosRes.error; expect(Array.isArray(getUtxosRes.value.utxos)).to.equal(true); expect(getUtxosRes.value.utxos.length).to.equal(3); expect(getUtxosRes.value.balance).to.equal(5855); diff --git a/tests/storage.test.ts b/tests/storage.test.ts index 1bc7e25..10b15da 100644 --- a/tests/storage.test.ts +++ b/tests/storage.test.ts @@ -40,11 +40,7 @@ before(async function () { tls } }); - if (res.isErr()) { - console.log('error: ', res.error.message); - //throw new Error(res.error.message); - return; - } + if (res.isErr()) throw res.error; wallet = res.value; }); @@ -100,8 +96,7 @@ describe('Storage Test', async function (): Promise { it('Should generate a bech32 receiving address at index 0 via its path', async () => { const address = await wallet.getAddressByPath({ path: "m/84'/1'/0'/0/0" }); - expect(address.isErr()).to.equal(false); - if (address.isErr()) return; + if (address.isErr()) throw address.error; expect(address.value.address).to.equal( 'tb1qmja98kkd540qtesjqdanfg0ywags845vehfg66' ); @@ -109,8 +104,7 @@ describe('Storage Test', async function (): Promise { it('Should generate a segwit change address at index 1 via its path', async () => { const address = await wallet.getAddressByPath({ path: "m/49'/1'/0'/1/1" }); - expect(address.isErr()).to.equal(false); - if (address.isErr()) return; + if (address.isErr()) throw address.error; expect(address.value.address).to.equal( '2NDRG1ZGhWMGGNW7Mp58BKcyBs4Hyat8Law' ); @@ -118,8 +112,7 @@ describe('Storage Test', async function (): Promise { it('Should generate a testnet legacy receiving address at index 5 via its path', async () => { const address = await wallet.getAddressByPath({ path: "m/44'/1'/0'/0/5" }); - expect(address.isErr()).to.equal(false); - if (address.isErr()) return; + if (address.isErr()) throw address.error; expect(address.value.address).to.equal( 'mohdq3fadTtT4uSH4oNr4F1Dp3YM4pR3VF' ); @@ -127,8 +120,7 @@ describe('Storage Test', async function (): Promise { it('getNextAvailableAddress: Should return the next available address/change index and the last used address/change index', async () => { const r = await wallet.getNextAvailableAddress(); - expect(r.isErr()).to.equal(false); - if (r.isErr()) return; + if (r.isErr()) throw r.error; expect(r.value).to.deep.equal( EXPECTED_SHARED_RESULTS.getNextAvailableAddress ); @@ -136,8 +128,7 @@ describe('Storage Test', async function (): Promise { it("Should return available UTXO's", async () => { const getUtxosRes: Result = await wallet.getUtxos({}); - expect(getUtxosRes.isErr()).to.equal(false); - if (getUtxosRes.isErr()) return; + if (getUtxosRes.isErr()) throw getUtxosRes.error; expect(Array.isArray(getUtxosRes.value.utxos)).to.equal(true); expect(getUtxosRes.value.utxos.length).to.equal(3); expect(getUtxosRes.value.balance).to.equal(5855); diff --git a/tests/transaction.test.ts b/tests/transaction.test.ts index f47b153..892d65e 100644 --- a/tests/transaction.test.ts +++ b/tests/transaction.test.ts @@ -30,10 +30,7 @@ before(async function () { tls } }); - if (res.isErr()) { - console.log('error: ', res.error.message); - return; - } + if (res.isErr()) throw res.error; wallet = res.value; await wallet.refreshWallet({}); }); @@ -53,9 +50,7 @@ describe('Transaction Test', async function (): Promise { it('Should successfully return fee information.', (): void => { const feeInfo = wallet.getFeeInfo({ satsPerByte: 5 }); - expect(feeInfo.isErr()).to.equal(false); - if (feeInfo.isErr()) return; - expect(feeInfo).not.to.be.null; + if (feeInfo.isErr()) throw feeInfo.error; expect(feeInfo.value.satsPerByte).to.equal(5); expect(feeInfo.value.totalFee).to.equal(830); expect(feeInfo.value.transactionByteCount).to.equal(166); @@ -72,15 +67,13 @@ describe('Transaction Test', async function (): Promise { shuffleOutputs: false, rbf: true }); - expect(sendRes.isErr()).to.equal(false); - if (sendRes.isErr()) return; + if (sendRes.isErr()) throw sendRes.error; expect(sendRes.value).to.equal( '020000000001014b44d379e48a8100d1c26f7220b8bbf7a4894ff015d5bc4064a28d08d25d808d0000000000000000000288130000000000001600143f1a7a1802e377d01602acf1cad403368ed3bb89ba21010000000000160014a6bd95db4dd6979189cad389daad006e236f4ba802483045022100dd709b656c271c7e2ab4c83e0245b9b8d9096a1c7a33eddc9a32113f436851d9022033f8e5cb016ae4c440badfa34e438ada7bea2cdd36e782c136e516350b502bca012102e86b90924963237c59e5389aab1cc5350c114549d1c5e7186a56ef33aea24ff900000000' ); const decodeRes = decodeRawTransaction(sendRes.value, wallet.network); - expect(decodeRes.isErr()).to.equal(false); - if (decodeRes.isErr()) return; + if (decodeRes.isErr()) throw decodeRes.error; expect(decodeRes.value).to.deep.equal( EXPECTED_TRANSACTION_RESULTS.decodeRawTransaction ); @@ -104,15 +97,13 @@ describe('Transaction Test', async function (): Promise { satsPerByte: 5, rbf: true }); - expect(sendManyRes.isErr()).to.equal(false); - if (sendManyRes.isErr()) return; + if (sendManyRes.isErr()) throw sendManyRes.error; expect(sendManyRes.value).to.equal( '020000000001014b44d379e48a8100d1c26f7220b8bbf7a4894ff015d5bc4064a28d08d25d808d000000000000000000038813000000000000160014a6b760eaa96a9ba91bae9465dfc4eabe711e1d6770170000000000001600146bcf920595e09b5d8f7b8d03b3694ad3057572892c0a010000000000160014a6bd95db4dd6979189cad389daad006e236f4ba80247304402207e7b5de41cb9bf33e434c2136390bf40d6b6552b69234a62f6bf48b89f0d44ac022056121c9a9d79d9d84896c9896a6fddb358b48667021ff2832b5c5871d90b701a012102e86b90924963237c59e5389aab1cc5350c114549d1c5e7186a56ef33aea24ff900000000' ); const decodeRes = decodeRawTransaction(sendManyRes.value, wallet.network); - expect(decodeRes.isErr()).to.equal(false); - if (decodeRes.isErr()) return; + if (decodeRes.isErr()) throw decodeRes.error; expect(decodeRes.value).to.deep.equal( EXPECTED_TRANSACTION_RESULTS.decodeRawSendManyTransaction ); @@ -126,7 +117,7 @@ describe('Transaction Test', async function (): Promise { satsPerByte: 5, broadcast: false }); - if (sweepPrivateKey.isErr()) return; + if (sweepPrivateKey.isErr()) throw sweepPrivateKey.error; expect(sweepPrivateKey.value.id).to.equal( '7fbef762e16676715bc94693a495923273259aa1190a5bf97bf18ab676393af5' ); @@ -145,7 +136,7 @@ describe('Transaction Test', async function (): Promise { broadcast: false, combineWithWalletUtxos: true }); - if (sweepPrivateKey.isErr()) return; + if (sweepPrivateKey.isErr()) throw sweepPrivateKey.error; expect(sweepPrivateKey.value.id).to.equal( 'ea6677d40bbf44dbc2d19d3765fd440aa2344f928d724dc021884fc5984e91ff' ); @@ -166,14 +157,13 @@ describe('Transaction Test', async function (): Promise { } ] }); - expect(setupResponse.isErr()).to.equal(false); - if (setupResponse.isErr()) return; + if (setupResponse.isErr()) throw setupResponse.error; + const privateKeyInfo: Result = await wallet.getPrivateKeyInfo( 'cUVwTLfHYrF7KGdTVU4AcP4yjtRTH3Y2BbTKHJbp2tsHDfpE8Zq5' ); - expect(privateKeyInfo.isErr()).to.equal(false); - if (privateKeyInfo.isErr()) return; + if (privateKeyInfo.isErr()) throw privateKeyInfo.error; const utxos = privateKeyInfo.value.utxos; const keyPair = privateKeyInfo.value.keyPair; expect(Array.isArray(utxos)).to.equal(true); @@ -185,13 +175,11 @@ describe('Transaction Test', async function (): Promise { inputs: utxos, keyPair }); - expect(addExternRes.isErr()).to.equal(false); - if (addExternRes.isErr()) return; + if (addExternRes.isErr()) throw addExternRes.error; const createTransaction = await wallet.transaction.createTransaction({ shuffleOutputs: false }); - expect(createTransaction.isErr()).to.equal(false); - if (createTransaction.isErr()) return; + if (createTransaction.isErr()) throw createTransaction.error; expect(createTransaction.value.id).to.equal( 'c0b4a54d9b4f88a32c7d7349f03c71c84a16b99b5c82159474768e734afecd81' ); diff --git a/tests/utils.ts b/tests/utils.ts index 3b33c23..555c142 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -44,7 +44,7 @@ export const initWaitForElectrumToSync = async ( const waitForElectrum = (): Promise => { return new Promise(async (resolve, reject) => { - let count; + let count: number; let running = true; const timer = setTimeout(async () => { diff --git a/tests/wallet.test.ts b/tests/wallet.test.ts index 7187620..b44aa33 100644 --- a/tests/wallet.test.ts +++ b/tests/wallet.test.ts @@ -46,11 +46,7 @@ before(async function () { tls } }); - if (res.isErr()) { - console.log('error: ', res.error.message); - //throw new Error(res.error.message); - return; - } + if (res.isErr()) throw res.error; wallet = res.value; await wallet.refreshWallet({}); }); @@ -125,8 +121,7 @@ describe('Wallet Library', async function () { it('Should generate a bech32 receiving address at index 0 via its path', async () => { const address = await wallet.getAddressByPath({ path: "m/84'/1'/0'/0/0" }); - expect(address.isErr()).to.equal(false); - if (address.isErr()) return; + if (address.isErr()) throw address.error; expect(address.value.address).to.equal( 'tb1qmja98kkd540qtesjqdanfg0ywags845vehfg66' ); @@ -134,8 +129,7 @@ describe('Wallet Library', async function () { it('Should generate a segwit change address at index 1 via its path', async () => { const address = await wallet.getAddressByPath({ path: "m/49'/1'/0'/1/1" }); - expect(address.isErr()).to.equal(false); - if (address.isErr()) return; + if (address.isErr()) throw address.error; expect(address.value.address).to.equal( '2NDRG1ZGhWMGGNW7Mp58BKcyBs4Hyat8Law' ); @@ -143,8 +137,7 @@ describe('Wallet Library', async function () { it('Should generate a testnet legacy receiving address at index 5 via its path', async () => { const address = await wallet.getAddressByPath({ path: "m/44'/1'/0'/0/5" }); - expect(address.isErr()).to.equal(false); - if (address.isErr()) return; + if (address.isErr()) throw address.error; expect(address.value.address).to.equal( 'mohdq3fadTtT4uSH4oNr4F1Dp3YM4pR3VF' ); @@ -152,8 +145,7 @@ describe('Wallet Library', async function () { it('getNextAvailableAddress: Should return the next available address/change index and the last used address/change index', async () => { const r = await wallet.getNextAvailableAddress(); - expect(r.isErr()).to.equal(false); - if (r.isErr()) return; + if (r.isErr()) throw r.error; expect(r.value).to.deep.equal( EXPECTED_SHARED_RESULTS.getNextAvailableAddress ); @@ -161,8 +153,7 @@ describe('Wallet Library', async function () { it("Should return available UTXO's", async () => { const getUtxosRes: Result = await wallet.getUtxos({}); - expect(getUtxosRes.isErr()).to.equal(false); - if (getUtxosRes.isErr()) return; + if (getUtxosRes.isErr()) throw getUtxosRes.error; expect(Array.isArray(getUtxosRes.value.utxos)).to.equal(true); expect(getUtxosRes.value.utxos.length).to.equal(3); expect(getUtxosRes.value.balance).to.equal(5855); @@ -267,13 +258,13 @@ describe('Wallet Library', async function () { ); expect(addressData1).to.not.be.undefined; if (!addressData1) return; - const privateKey1: string = await wallet.getPrivateKey(addressData1.path); + const privateKey1: string = wallet.getPrivateKey(addressData1.path); expect(typeof privateKey1).to.equal('string'); expect(privateKey1).to.equal( 'cSkdqJTnvZ56deaW5PpVJPeUCAQfPV7xJocfiZxdgm9UHHmXuXzY' ); - const privateKey2: string = await wallet.getPrivateKey("m/84'/1'/0'/0/19"); + const privateKey2: string = wallet.getPrivateKey("m/84'/1'/0'/0/19"); expect(typeof privateKey2).to.equal('string'); expect(privateKey2).to.equal( 'cUcpwVpcwvVz17qnBzwNfNQpp9FsfXH1ogjKCkxgbB2ZzGGjrK2r' @@ -283,8 +274,7 @@ describe('Wallet Library', async function () { it('Should successfully return the tx history for a given address', async () => { const address = 'tb1qmja98kkd540qtesjqdanfg0ywags845vehfg66'; const history = await wallet.getAddressHistory(address); - expect(history.isErr()).to.equal(false); - if (history.isErr()) return; + if (history.isErr()) throw history.error; expect(history.value).to.deep.equal(EXPECTED_WALLET_RESULTS.addressHistory); }); @@ -292,8 +282,7 @@ describe('Wallet Library', async function () { const tx = 'e12dec55bd19c709ed5cc3213aab814315fd9716afc99dfe914b9190fdcb8452'; const txDetails = await wallet.getTransactionDetails(tx); - expect(txDetails.isErr()).to.equal(false); - if (txDetails.isErr()) return; + if (txDetails.isErr()) throw txDetails.error; expect(txDetails.value.confirmations).to.be.a('number'); delete txDetails.value.confirmations; expect(txDetails.value).to.deep.equal( @@ -370,13 +359,13 @@ describe('Wallet Library', async function () { ); expect(addressData1).to.not.be.undefined; if (!addressData1) return; - const privateKey1: string = await wallet.getPrivateKey(addressData1.path); + const privateKey1: string = wallet.getPrivateKey(addressData1.path); expect(typeof privateKey1).to.equal('string'); expect(privateKey1).to.equal( 'L2iqFGgLkMzQossGaQ9B2tmhSsLq3vgunnHb8vnLavXUh54GSLnK' ); - const privateKey2: string = await wallet.getPrivateKey("m/84'/0'/0'/0/19"); + const privateKey2: string = wallet.getPrivateKey("m/84'/0'/0'/0/19"); expect(typeof privateKey2).to.equal('string'); expect(privateKey2).to.equal( 'L2cB657yFF88YEebxoad3YgeezYKAu61AhmnDHMFo7GjjpPqBZG1'