From 94910f66aacf89558cff9f8283d21b12dc5cda94 Mon Sep 17 00:00:00 2001 From: Daniel Savu Date: Mon, 19 Apr 2021 11:18:39 +0100 Subject: [PATCH] fix(electrs): Improve promise error handling --- package.json | 2 +- src/external/electrs.ts | 3 ++- test/integration/parachain/staging/refund.test.ts | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 07c925c7a..47047d3e7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@interlay/polkabtc", - "version": "0.14.0", + "version": "0.14.1", "description": "JavaScript library to interact with PolkaBTC", "main": "build/index.js", "typings": "build/index.d.ts", diff --git a/src/external/electrs.ts b/src/external/electrs.ts index 72a8bf7d4..874f604a8 100644 --- a/src/external/electrs.ts +++ b/src/external/electrs.ts @@ -284,8 +284,9 @@ export class DefaultElectrsAPI implements ElectrsAPI { console.log("Did not find opreturn, retrying..."); if(timeoutMs < retryIntervalMs) { reject("Timeout elapsed"); + } else { + this.waitForOpreturn(data, timeoutMs - retryIntervalMs, retryIntervalMs).then(resolve).catch(reject); } - this.waitForOpreturn(data, timeoutMs - retryIntervalMs, retryIntervalMs).then(resolve); }, retryIntervalMs); }); }); diff --git a/test/integration/parachain/staging/refund.test.ts b/test/integration/parachain/staging/refund.test.ts index 23048c67b..97c53f23d 100644 --- a/test/integration/parachain/staging/refund.test.ts +++ b/test/integration/parachain/staging/refund.test.ts @@ -35,7 +35,7 @@ describe("refund", () => { }); it("should not generate a refund request", async () => { - const isueResult = await issue( + const issueResult = await issue( api, electrsAPI, bitcoinCoreClient, @@ -45,14 +45,14 @@ describe("refund", () => { false, false ); - const refund = await refundAPI.getRequestByIssueId(isueResult.request.id); + const refund = await refundAPI.getRequestByIssueId(issueResult.request.id); // The parachain returns an Option<> refund request if none was found, // which is deserialized as a refund request with blank/default fields assert.equal(refund.amount_btc.toString(), "0"); }).timeout(1000000); it("should generate a refund request", async () => { - const isueResult = await issue( + const issueResult = await issue( api, electrsAPI, bitcoinCoreClient, @@ -62,7 +62,7 @@ describe("refund", () => { true, true ); - const refund = await refundAPI.getRequestByIssueId(isueResult.request.id); + const refund = await refundAPI.getRequestByIssueId(issueResult.request.id); assert.notEqual(refund.amount_btc.toString(), "0"); }).timeout(1000000);