|
1 | | -/* |
2 | | -const ElectrumClient = require("../src/ElectrumClient") |
3 | | -const fs = require("fs") |
4 | | -const chai = require("chai") |
| 1 | +import ElectrumClient, {scriptToHash} from "../src/lib/ElectrumClient.js" |
| 2 | +import fs from "fs" |
| 3 | +import chai from "chai" |
5 | 4 | const assert = chai.assert |
6 | | -const config = require("../../../src/config/config.json") |
7 | 5 |
|
8 | | -describe("ElectrumClient", async () => { |
9 | | - let client |
10 | | - let tx |
| 6 | +const txData = fs.readFileSync("./test/data/tx.json", "utf8") |
| 7 | +const tx = JSON.parse(txData) |
11 | 8 |
|
12 | | - before(async () => { |
13 | | - const txData = fs.readFileSync("./test/data/tx.json", "utf8") |
14 | | - tx = JSON.parse(txData) |
| 9 | +const client = new ElectrumClient({ |
| 10 | + server: "electrumx-server.test.tbtc.network", |
| 11 | + port: 8443, |
| 12 | + protocol: "wss" |
| 13 | +}) |
15 | 14 |
|
16 | | - client = new ElectrumClient.Client(config.electrum.testnetPublic) |
| 15 | +describe("ElectrumClient", async () => { |
17 | 16 |
|
| 17 | + before(async () => { |
18 | 18 | await client.connect() |
19 | 19 | }) |
20 | 20 |
|
@@ -46,14 +46,14 @@ describe("ElectrumClient", async () => { |
46 | 46 | assert.deepEqual(result, expectedResult) |
47 | 47 | }) |
48 | 48 |
|
49 | | - it("getMerkleProof", async () => { |
50 | | - const expectedResult = tx.merkleProof |
| 49 | + it("getTransactionMerkle", async () => { |
| 50 | + const expectedResult = tx.merkleProof.match(/.{1,64}/g).map(hex=>hex.match(/[a-fA-F0-9]{2}/g).reverse().join('')) |
51 | 51 | const expectedPosition = tx.indexInBlock |
52 | | - const result = await client.getMerkleProof(tx.hash, tx.blockHeight) |
| 52 | + const result = await client.getTransactionMerkle(tx.hash, tx.blockHeight) |
53 | 53 |
|
54 | | - assert.equal(result.proof, expectedResult, "unexpected result") |
| 54 | + assert.deepEqual(result.merkle, expectedResult, "unexpected result") |
55 | 55 |
|
56 | | - assert.equal(result.position, expectedPosition, "unexpected result") |
| 56 | + assert.equal(result.pos, expectedPosition, "unexpected result") |
57 | 57 | }) |
58 | 58 |
|
59 | 59 | it("getHeadersChain", async () => { |
@@ -161,7 +161,7 @@ describe("ElectrumClient", async () => { |
161 | 161 | const mockEventEmission = function() { |
162 | 162 | client.electrumClient.subscribe.emit( |
163 | 163 | "blockchain.scripthash.subscribe", |
164 | | - [ElectrumClient.scriptToHash(script1), expectedStatus] |
| 164 | + [scriptToHash(script1), expectedStatus] |
165 | 165 | ) |
166 | 166 | } |
167 | 167 |
|
@@ -193,12 +193,12 @@ describe("ElectrumClient", async () => { |
193 | 193 | const mockEventsEmission = function() { |
194 | 194 | client.electrumClient.subscribe.emit( |
195 | 195 | "blockchain.scripthash.subscribe", |
196 | | - [ElectrumClient.scriptToHash(script2), unexpectedStatus] |
| 196 | + [scriptToHash(script2), unexpectedStatus] |
197 | 197 | ) |
198 | 198 |
|
199 | 199 | client.electrumClient.subscribe.emit( |
200 | 200 | "blockchain.scripthash.subscribe", |
201 | | - [ElectrumClient.scriptToHash(script1), expectedStatus] |
| 201 | + [scriptToHash(script1), expectedStatus] |
202 | 202 | ) |
203 | 203 | } |
204 | 204 |
|
@@ -249,7 +249,7 @@ describe("ElectrumClient", async () => { |
249 | 249 | // onRejected |
250 | 250 | assert.include( |
251 | 251 | reason.toString(), |
252 | | - "No such mempool or blockchain transaction" |
| 252 | + "Transaction not found" |
253 | 253 | ) |
254 | 254 | } |
255 | 255 | ) |
@@ -284,4 +284,4 @@ describe("ElectrumClient", async () => { |
284 | 284 | console.log("result", result) |
285 | 285 | }) |
286 | 286 | }) |
287 | | -})*/ |
| 287 | +}) |
0 commit comments