Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Linted the code
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed Aug 10, 2021
1 parent 52f3930 commit fb070a9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
5 changes: 4 additions & 1 deletion src/BitcoinHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,10 @@ const BitcoinHelpers = {
throw new Error("Electrum client not configured.")
}

const electrumClient = new ElectrumClient(BitcoinHelpers.electrumConfig, BitcoinHelpers.electrsConfig)
const electrumClient = new ElectrumClient(
BitcoinHelpers.electrumConfig,
BitcoinHelpers.electrsConfig
)

await electrumClient.connect()

Expand Down
3 changes: 2 additions & 1 deletion src/lib/ElectrumClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export default class Client {
* @param {Config} config Electrum client connection configuration.
* @param {string} apiUrl Url to the electrs server
*/
constructor(config, apiUrl) { // TODO: config will be removed once all ported
constructor(config, apiUrl) {
// TODO: config will be removed once all ported
this.electrumClient = new ElectrumClient(
config.server,
config.port,
Expand Down
7 changes: 5 additions & 2 deletions test/BitcoinSPVTest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BitcoinSPV } from "../src/lib/BitcoinSPV.js"
import ElectrumClient from "../src/lib/ElectrumClient.js"
import { electrumConfig } from "./config/network.js"
import { electrsConfig, electrumConfig } from "./config/network.js"
import { readFileSync } from "fs"
import { assert } from "chai"

Expand All @@ -12,7 +12,10 @@ describe("BitcoinSPV", async () => {
before(async () => {
const txData = readFileSync("./test/data/tx.json", "utf8")
tx = JSON.parse(txData)
electrumClient = new ElectrumClient(electrumConfig["testnet"])
electrumClient = new ElectrumClient(
electrumConfig["testnet"],
electrsConfig["testnet"]
)
bitcoinSPV = new BitcoinSPV(electrumClient)
await electrumClient.connect()
})
Expand Down
36 changes: 18 additions & 18 deletions test/ElectrumClientTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,31 +193,31 @@ describe("ElectrumClient", async () => {
console.log("result", result)
})

// This test cannot be executed as part of CI. It takes too long to wait
// for confirmations. Use this for manual testing.
// TODO: Make it possible with electrum server mock.
it.skip("wait for three more confirmations", async () => {
const txHash = tx.hash
// This test cannot be executed as part of CI. It takes too long to wait
// for confirmations. Use this for manual testing.
// TODO: Make it possible with electrum server mock.
it.skip("wait for three more confirmations", async () => {
const txHash = tx.hash

const currentTx = await client.getTransaction(txHash)
const currentTx = await client.getTransaction(txHash)

const requiredConfirmations = currentTx.confirmations + 3
const requiredConfirmations = currentTx.confirmations + 3

const callback = async function() {
// Get current state of the transaction.
const tx = await client.getTransaction(txHash)
const callback = async function() {
// Get current state of the transaction.
const tx = await client.getTransaction(txHash)

// Check if transaction has already enough number of confirmations.
// Check if transaction has already enough number of confirmations.

console.log("current confirmations:", tx.confirmations)
if (tx.confirmations >= requiredConfirmations) {
return tx.txid
}
console.log("current confirmations:", tx.confirmations)
if (tx.confirmations >= requiredConfirmations) {
return tx.txid
}
}

const result = await client.onNewBlock(callback)
const result = await client.onNewBlock(callback)

console.log("result", result)
})
console.log("result", result)
})
})
})

0 comments on commit fb070a9

Please sign in to comment.