@psf/bch-js 6.8.3 → 7.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +10 -28
  3. package/fix-docs-contrast.sh +38 -0
  4. package/package.json +38 -47
  5. package/src/address.js +12 -23
  6. package/src/bch-js.js +81 -48
  7. package/src/bitcoincash.js +10 -11
  8. package/src/blockchain.js +57 -68
  9. package/src/control.js +11 -22
  10. package/src/crypto.js +3 -3
  11. package/src/dsproof.js +6 -17
  12. package/src/ecash.js +1 -1
  13. package/src/ecpair.js +3 -3
  14. package/src/electrumx.js +32 -44
  15. package/src/encryption.js +8 -17
  16. package/src/generating.js +8 -19
  17. package/src/hdnode.js +5 -5
  18. package/src/mining.js +11 -22
  19. package/src/mnemonic.js +8 -11
  20. package/src/price.js +7 -108
  21. package/src/psf-slp-indexer.js +21 -32
  22. package/src/raw-transactions.js +22 -35
  23. package/src/schnorr.js +5 -16
  24. package/src/script.js +4 -2
  25. package/src/slp/address.js +4 -4
  26. package/src/slp/ecpair.js +4 -4
  27. package/src/slp/nft1.js +6 -6
  28. package/src/slp/slp.js +11 -22
  29. package/src/slp/tokentype1.js +11 -22
  30. package/src/slp/utils.js +9 -19
  31. package/src/transaction-builder.js +5 -5
  32. package/src/transaction.js +5 -5
  33. package/src/util.js +5 -98
  34. package/src/utxo.js +6 -6
  35. package/test/e2e/bch-js-e2e-tests.js +4 -3
  36. package/test/e2e/ipfs/ipfs-e2e.js +8 -2
  37. package/test/e2e/rate-limits/anonymous-rate-limits.js +5 -4
  38. package/test/e2e/rate-limits/basic-auth-rate-limits.js +4 -3
  39. package/test/e2e/rate-limits/free-rate-limits.js +4 -3
  40. package/test/e2e/rate-limits/full-node-rate-limits.js +4 -3
  41. package/test/e2e/rate-limits/indexer-rate-limits.js +4 -3
  42. package/test/e2e/send-raw-transaction-bulk/sendrawtransaction.js +28 -18
  43. package/test/e2e/send-raw-transaction-single/sendrawtransaction.js +28 -18
  44. package/test/e2e/send-token/send-token.js +4 -4
  45. package/test/e2e/util/e2e-util.js +6 -3
  46. package/test/e2e/utxo/unsynced-indexer.js +1 -1
  47. package/test/integration/blockchain.js +5 -5
  48. package/test/integration/control.js +2 -2
  49. package/test/integration/{chains/bchn/dsproof.js → dsproof.js} +6 -2
  50. package/test/integration/electrumx.js +5 -12
  51. package/test/integration/price.js +3 -39
  52. package/test/integration/{chains/bchn/psf-slp-indexer.integration.js → psf-slp-indexer.integration.js} +5 -6
  53. package/test/integration/rawtransaction.js +39 -5
  54. package/test/integration/slp.js +147 -5
  55. package/test/integration/transaction-integration.js +27 -2
  56. package/test/integration/{chains/bchn/utxo-integration.js → utxo-integration.js} +3 -2
  57. package/test/unit/address.js +7 -4
  58. package/test/unit/bitcoin-cash.js +5 -3
  59. package/test/unit/blockchain.js +23 -22
  60. package/test/unit/control.js +6 -6
  61. package/test/unit/crypto.js +5 -3
  62. package/test/unit/dsproof.js +5 -4
  63. package/test/unit/ecash.js +3 -2
  64. package/test/unit/ecpairs.js +6 -4
  65. package/test/unit/electrumx.js +7 -7
  66. package/test/unit/encryption.js +6 -5
  67. package/test/unit/fixtures/bitcore-mock.js +1 -1
  68. package/test/unit/fixtures/block-mock.js +1 -1
  69. package/test/unit/fixtures/blockchain-mock.js +1 -1
  70. package/test/unit/fixtures/dsproof-mock.js +1 -1
  71. package/test/unit/fixtures/electrumx-mock.js +1 -1
  72. package/test/unit/fixtures/encryption-mock.js +1 -1
  73. package/test/unit/fixtures/ipfs-mock.js +1 -1
  74. package/test/unit/fixtures/openbazaar-mock.js +1 -1
  75. package/test/unit/fixtures/price-mocks.js +1 -1
  76. package/test/unit/fixtures/psf-slp-indexer-mock.js +1 -1
  77. package/test/unit/fixtures/rawtransaction-mock.js +1 -1
  78. package/test/unit/fixtures/slp/mock-utils.js +1 -1
  79. package/test/unit/fixtures/transaction-mock.js +1 -1
  80. package/test/unit/fixtures/utxo-mocks.js +1 -1
  81. package/test/unit/generating.js +5 -5
  82. package/test/unit/hdnode.js +6 -4
  83. package/test/unit/mining.js +8 -8
  84. package/test/unit/mnemonic.js +4 -2
  85. package/test/unit/price.js +5 -14
  86. package/test/unit/psf-slp-indexer.js +7 -7
  87. package/test/unit/raw-tranactions.js +14 -13
  88. package/test/unit/scripts.js +8 -6
  89. package/test/unit/slp-address.js +6 -4
  90. package/test/unit/slp-ecpair.js +5 -3
  91. package/test/unit/slp-nft1.js +7 -6
  92. package/test/unit/slp-tokentype1.js +7 -6
  93. package/test/unit/slp-utils.js +8 -7
  94. package/test/unit/transaction-builder.js +7 -4
  95. package/test/unit/transaction-unit.js +5 -4
  96. package/test/unit/util.js +11 -32
  97. package/test/unit/utxo-unit.js +6 -5
  98. package/test/unit/x402.js +193 -0
  99. package/test/integration/chains/abc/psf-slp-indexer-integration.js +0 -38
  100. package/test/integration/chains/abc/rawtransaction.js +0 -73
  101. package/test/integration/chains/abc/utxo-integration.js +0 -38
  102. package/test/integration/chains/bchn/rawtransaction.js +0 -71
  103. package/test/integration/chains/bchn/slp.js +0 -301
  104. package/test/integration/chains/bchn/transaction-integration.js +0 -37
  105. package/test/integration/chains/bchn/util.js +0 -103
  106. package/test/integration/chains/testnet/blockchain.js +0 -260
  107. package/test/integration/chains/testnet/control.js +0 -32
  108. package/test/integration/chains/testnet/electrumx.js +0 -376
  109. package/test/integration/chains/testnet/rawtransaction.js +0 -296
  110. package/test/integration/chains/testnet/slp.js +0 -172
  111. package/test/integration/chains/testnet/test-free-tier.sh +0 -9
  112. package/test/integration/chains/testnet/util.js +0 -109
@@ -1,11 +1,12 @@
1
- const assert = require('assert')
2
- const assert2 = require('chai').assert
3
- const axios = require('axios')
4
- const BCHJS = require('../../src/bch-js')
1
+ import assert from 'assert'
2
+ import chai from 'chai'
3
+ import axios from 'axios'
4
+ import BCHJS from '../../src/bch-js.js'
5
+ import sinon from 'sinon'
6
+
7
+ import mockData from './fixtures/blockchain-mock.js'
8
+ const { assert: assert2 } = chai
5
9
  const bchjs = new BCHJS()
6
- const sinon = require('sinon')
7
-
8
- const mockData = require('./fixtures/blockchain-mock')
9
10
 
10
11
  describe('#Blockchain', () => {
11
12
  describe('#getBestBlockHash', () => {
@@ -60,7 +61,7 @@ describe('#Blockchain', () => {
60
61
  }
61
62
 
62
63
  it('should get block by hash', done => {
63
- const resolved = new Promise(resolve => resolve({ data: data }))
64
+ const resolved = new Promise(resolve => resolve({ data }))
64
65
  sandbox.stub(axios, 'post').returns(resolved)
65
66
 
66
67
  const blockhash =
@@ -129,7 +130,7 @@ describe('#Blockchain', () => {
129
130
  }
130
131
 
131
132
  it('should get blockchain info', done => {
132
- const resolved = new Promise(resolve => resolve({ data: data }))
133
+ const resolved = new Promise(resolve => resolve({ data }))
133
134
  sandbox.stub(axios, 'get').returns(resolved)
134
135
 
135
136
  bchjs.Blockchain.getBlockchainInfo()
@@ -147,7 +148,7 @@ describe('#Blockchain', () => {
147
148
  const data = 527810
148
149
 
149
150
  it('should get block count', done => {
150
- const resolved = new Promise(resolve => resolve({ data: data }))
151
+ const resolved = new Promise(resolve => resolve({ data }))
151
152
  sandbox.stub(axios, 'get').returns(resolved)
152
153
 
153
154
  bchjs.Blockchain.getBlockCount()
@@ -166,7 +167,7 @@ describe('#Blockchain', () => {
166
167
  '000000000000000001d127592d091d4c45062504663c9acab27a1b16c028e3c0'
167
168
 
168
169
  it('should get block hash by height', done => {
169
- const resolved = new Promise(resolve => resolve({ data: data }))
170
+ const resolved = new Promise(resolve => resolve({ data }))
170
171
  sandbox.stub(axios, 'get').returns(resolved)
171
172
 
172
173
  bchjs.Blockchain.getBlockHash(527810)
@@ -201,7 +202,7 @@ describe('#Blockchain', () => {
201
202
  }
202
203
 
203
204
  it('should get block header by hash', done => {
204
- const resolved = new Promise(resolve => resolve({ data: data }))
205
+ const resolved = new Promise(resolve => resolve({ data }))
205
206
  sandbox.stub(axios, 'get').returns(resolved)
206
207
 
207
208
  bchjs.Blockchain.getBlockHeader(
@@ -222,7 +223,7 @@ describe('#Blockchain', () => {
222
223
  const data = '577528469277.1339'
223
224
 
224
225
  it('should get difficulty', done => {
225
- const resolved = new Promise(resolve => resolve({ data: data }))
226
+ const resolved = new Promise(resolve => resolve({ data }))
226
227
  sandbox.stub(axios, 'get').returns(resolved)
227
228
 
228
229
  bchjs.Blockchain.getDifficulty()
@@ -240,7 +241,7 @@ describe('#Blockchain', () => {
240
241
  const data = 'Transaction not in mempool'
241
242
 
242
243
  it('should get mempool ancestors', done => {
243
- const resolved = new Promise(resolve => resolve({ data: data }))
244
+ const resolved = new Promise(resolve => resolve({ data }))
244
245
  sandbox.stub(axios, 'get').returns(resolved)
245
246
 
246
247
  bchjs.Blockchain.getMempoolAncestors(
@@ -263,7 +264,7 @@ describe('#Blockchain', () => {
263
264
  }
264
265
 
265
266
  it('should get mempool descendants', done => {
266
- const resolved = new Promise(resolve => resolve({ data: data }))
267
+ const resolved = new Promise(resolve => resolve({ data }))
267
268
  sandbox.stub(axios, 'get').returns(resolved)
268
269
 
269
270
  bchjs.Blockchain.getMempoolDescendants(
@@ -286,7 +287,7 @@ describe('#Blockchain', () => {
286
287
  }
287
288
 
288
289
  it('should get mempool entry', done => {
289
- const resolved = new Promise(resolve => resolve({ data: data }))
290
+ const resolved = new Promise(resolve => resolve({ data }))
290
291
  sandbox.stub(axios, 'get').returns(resolved)
291
292
 
292
293
  bchjs.Blockchain.getMempoolEntry(
@@ -314,7 +315,7 @@ describe('#Blockchain', () => {
314
315
  }
315
316
 
316
317
  it('should get mempool info', done => {
317
- const resolved = new Promise(resolve => resolve({ data: data }))
318
+ const resolved = new Promise(resolve => resolve({ data }))
318
319
  sandbox.stub(axios, 'get').returns(resolved)
319
320
 
320
321
  bchjs.Blockchain.getMempoolInfo()
@@ -355,7 +356,7 @@ describe('#Blockchain', () => {
355
356
  }
356
357
 
357
358
  it('should get mempool info', done => {
358
- const resolved = new Promise(resolve => resolve({ data: data }))
359
+ const resolved = new Promise(resolve => resolve({ data }))
359
360
  sandbox.stub(axios, 'get').returns(resolved)
360
361
 
361
362
  bchjs.Blockchain.getRawMempool()
@@ -451,7 +452,7 @@ describe('#Blockchain', () => {
451
452
  }
452
453
 
453
454
  it('should get TODO', done => {
454
- const resolved = new Promise(resolve => resolve({ data: data }))
455
+ const resolved = new Promise(resolve => resolve({ data }))
455
456
  sandbox.stub(axios, 'get').returns(resolved)
456
457
 
457
458
  bchjs.Blockchain.preciousBlock()
@@ -469,7 +470,7 @@ describe('#Blockchain', () => {
469
470
  const data = 'Cannot prune blocks because node is not in prune mode.'
470
471
 
471
472
  it('should prune blockchain', done => {
472
- const resolved = new Promise(resolve => resolve({ data: data }))
473
+ const resolved = new Promise(resolve => resolve({ data }))
473
474
  sandbox.stub(axios, 'post').returns(resolved)
474
475
 
475
476
  bchjs.Blockchain.pruneBlockchain(507)
@@ -487,7 +488,7 @@ describe('#Blockchain', () => {
487
488
  const data = true
488
489
 
489
490
  it('should verify blockchain', done => {
490
- const resolved = new Promise(resolve => resolve({ data: data }))
491
+ const resolved = new Promise(resolve => resolve({ data }))
491
492
  sandbox.stub(axios, 'get').returns(resolved)
492
493
 
493
494
  bchjs.Blockchain.verifyChain(3, 6)
@@ -505,7 +506,7 @@ describe('#Blockchain', () => {
505
506
  const data = "proof must be hexadecimal string (not '')"
506
507
 
507
508
  it('should verify utxo proof', done => {
508
- const resolved = new Promise(resolve => resolve({ data: data }))
509
+ const resolved = new Promise(resolve => resolve({ data }))
509
510
  sandbox.stub(axios, 'get').returns(resolved)
510
511
 
511
512
  bchjs.Blockchain.verifyTxOutProof('3')
@@ -1,8 +1,8 @@
1
- const assert = require('assert')
2
- const axios = require('axios')
3
- const BCHJS = require('../../src/bch-js')
1
+ import assert from 'assert'
2
+ import axios from 'axios'
3
+ import BCHJS from '../../src/bch-js.js'
4
+ import sinon from 'sinon'
4
5
  const bchjs = new BCHJS()
5
- const sinon = require('sinon')
6
6
 
7
7
  describe('#Control', () => {
8
8
  let sandbox
@@ -24,7 +24,7 @@ describe('#Control', () => {
24
24
  relayfee: 0.00001,
25
25
  errors: ''
26
26
  }
27
- const resolved = new Promise(resolve => resolve({ data: data }))
27
+ const resolved = new Promise(resolve => resolve({ data }))
28
28
  sandbox.stub(axios, 'get').returns(resolved)
29
29
 
30
30
  bchjs.Control.getNetworkInfo()
@@ -47,7 +47,7 @@ describe('#Control', () => {
47
47
  chunks_free: 1
48
48
  }
49
49
  }
50
- const resolved = new Promise(resolve => resolve({ data: data }))
50
+ const resolved = new Promise(resolve => resolve({ data }))
51
51
  sandbox.stub(axios, 'get').returns(resolved)
52
52
 
53
53
  bchjs.Control.getMemoryInfo()
@@ -1,8 +1,10 @@
1
+ import { createRequire } from 'module'
2
+ import assert from 'assert'
3
+ import BCHJS from '../../src/bch-js.js'
4
+ import { Buffer } from 'safe-buffer'
5
+ const require = createRequire(import.meta.url)
1
6
  const fixtures = require('./fixtures/crypto.json')
2
- const assert = require('assert')
3
- const BCHJS = require('../../src/bch-js')
4
7
  const bchjs = new BCHJS()
5
- const Buffer = require('safe-buffer').Buffer
6
8
 
7
9
  describe('#Crypto', () => {
8
10
  describe('#sha256', () => {
@@ -1,10 +1,11 @@
1
1
  // Public npm libraries
2
- const assert = require('chai').assert
3
- const sinon = require('sinon')
2
+ import chai from 'chai'
3
+ import sinon from 'sinon'
4
4
 
5
5
  // Unit under test (uut)
6
- const BCHJS = require('../../src/bch-js')
7
- const mockData = require('./fixtures/dsproof-mock')
6
+ import BCHJS from '../../src/bch-js.js'
7
+ import mockData from './fixtures/dsproof-mock.js'
8
+ const { assert } = chai
8
9
 
9
10
  let bchjs
10
11
  const txid = 'ee0df780b58f6f24467605b2589c44c3a50fc849fb8f91b89669a4ae0d86bc7e'
@@ -3,8 +3,9 @@
3
3
  */
4
4
 
5
5
  // Global npm libraries
6
- const assert = require('chai').assert
7
- const Ecash = require('../../src/ecash')
6
+ import chai from 'chai'
7
+ import Ecash from '../../src/ecash.js'
8
+ const { assert } = chai
8
9
  const uut = new Ecash()
9
10
 
10
11
  describe('#eCash', () => {
@@ -1,12 +1,14 @@
1
1
  // Public npm libraries.
2
- const assert = require('assert')
3
- const Buffer = require('safe-buffer').Buffer
2
+ import assert from 'assert'
3
+ import { Buffer } from 'safe-buffer'
4
4
 
5
5
  // Mocks
6
- const fixtures = require('./fixtures/ecpair.json')
6
+ import { createRequire } from 'module'
7
7
 
8
8
  // Unit under test (uut)
9
- const BCHJS = require('../../src/bch-js')
9
+ import BCHJS from '../../src/bch-js.js'
10
+ const require = createRequire(import.meta.url)
11
+ const fixtures = require('./fixtures/ecpair.json')
10
12
  // const bchjs = new BCHJS()
11
13
  let bchjs
12
14
 
@@ -1,12 +1,12 @@
1
- const chai = require('chai')
2
- const assert = chai.assert
3
- const axios = require('axios')
4
- const sinon = require('sinon')
1
+ import chai from 'chai'
2
+ import axios from 'axios'
3
+ import sinon from 'sinon'
5
4
 
6
- const BCHJS = require('../../src/bch-js')
7
- const bchjs = new BCHJS()
5
+ import BCHJS from '../../src/bch-js.js'
8
6
 
9
- const mockData = require('./fixtures/electrumx-mock')
7
+ import mockData from './fixtures/electrumx-mock.js'
8
+ const assert = chai.assert
9
+ const bchjs = new BCHJS()
10
10
 
11
11
  describe('#ElectrumX', () => {
12
12
  let sandbox
@@ -1,12 +1,13 @@
1
- const assert = require('chai').assert
2
- const sinon = require('sinon')
1
+ import chai from 'chai'
2
+ import sinon from 'sinon'
3
3
 
4
- const BCHJS = require('../../src/bch-js')
4
+ import BCHJS from '../../src/bch-js.js'
5
+
6
+ import mockData from './fixtures/encryption-mock.js'
7
+ const { assert } = chai
5
8
  // const bchjs = new BCHJS()
6
9
  let bchjs
7
10
 
8
- const mockData = require('./fixtures/encryption-mock')
9
-
10
11
  describe('#Encryption', () => {
11
12
  let sandbox
12
13
 
@@ -39,7 +39,7 @@ const utxo = [
39
39
  }
40
40
  ]
41
41
 
42
- module.exports = {
42
+ export default {
43
43
  balance,
44
44
  utxo
45
45
  }
@@ -2,7 +2,7 @@
2
2
  Mock data used for unit testing.
3
3
  */
4
4
 
5
- module.exports = {
5
+ export default {
6
6
  details: {
7
7
  hash: '000000001c6aeec19265e9cc3ded8ba5ef5e63fae7747f30bf9c02c7bc8883f0',
8
8
  size: 216,
@@ -2,7 +2,7 @@
2
2
  Mock data used for unit testing.
3
3
  */
4
4
 
5
- module.exports = {
5
+ export default {
6
6
  bestBlockHash:
7
7
  '0000000000000000008e1f65f875703872544aa888c7ca6587f055f8f5fbd4bf',
8
8
 
@@ -14,6 +14,6 @@ const dsproof = {
14
14
  ]
15
15
  }
16
16
 
17
- module.exports = {
17
+ export default {
18
18
  dsproof
19
19
  }
@@ -290,7 +290,7 @@ const txHistoryWithUnconfirmed = {
290
290
  ]
291
291
  }
292
292
 
293
- module.exports = {
293
+ export default {
294
294
  utxo,
295
295
  utxos,
296
296
  balance,
@@ -13,7 +13,7 @@ const failureMock = {
13
13
  publicKey: 'not found'
14
14
  }
15
15
 
16
- module.exports = {
16
+ export default {
17
17
  successMock,
18
18
  failureMock
19
19
  }
@@ -118,7 +118,7 @@ const paidFileData = {
118
118
  }
119
119
  }
120
120
 
121
- module.exports = {
121
+ export default {
122
122
  uploadData,
123
123
  paymentInfo,
124
124
  mockNewFileModel,
@@ -77,7 +77,7 @@ const tx = {
77
77
  '0200000001ac1e2e38764f9b81f3ff4317b4bd1a381dbdf311277a736f375d4ce217d3095f010000006a473044022000dd11c41a472f2e54348db996e60864d489429f12d1e044d49ff600b880c9590220715a926404bb0e2731a3795afb341ec1dad3f84ead7d27cd31fcc59abb14738c4121038476128287ac37c7a3cf7e8625fd5f024db1bc3d8e37395abe7bf42fda78d0d9ffffffff02e8030000000000001976a9142fe2c4c5ef359bb2fe1a849f891cecffbcfb4f7788acb0b40000000000001976a9142dbf5e1804c39a497b908c876097d63210c8490288ac00000000'
78
78
  }
79
79
 
80
- module.exports = {
80
+ export default {
81
81
  balance,
82
82
  utxo,
83
83
  tx
@@ -209,6 +209,6 @@ const mockRates = {
209
209
  ZWL: '80215.03'
210
210
  }
211
211
 
212
- module.exports = {
212
+ export default {
213
213
  mockRates
214
214
  }
@@ -203,7 +203,7 @@ const tokenMedia01 = {
203
203
  ps002Compatible: true
204
204
  }
205
205
 
206
- module.exports = {
206
+ export default {
207
207
  tokenStats,
208
208
  txData,
209
209
  balance,
@@ -55,7 +55,7 @@ const mockGetInputAddrsOutput = [
55
55
  }
56
56
  ]
57
57
 
58
- module.exports = {
58
+ export default {
59
59
  mockTx,
60
60
  mockParentTx1,
61
61
  mockGetInputAddrsOutput
@@ -1411,7 +1411,7 @@ mock503Error.response = {
1411
1411
  }
1412
1412
  }
1413
1413
 
1414
- module.exports = {
1414
+ export default {
1415
1415
  mockList,
1416
1416
  mockToken,
1417
1417
  mockTokens,
@@ -769,7 +769,7 @@ const genesisTestOpReturn03 = {
769
769
  qty: '100000000000000000'
770
770
  }
771
771
 
772
- module.exports = {
772
+ export default {
773
773
  nonSlpTxDetails,
774
774
  slpTxDetails,
775
775
  mockOpReturnData01,
@@ -476,7 +476,7 @@ const noUtxoErr = {
476
476
  'Key not found in database [bitcoincash:qp3sn6vlwz28ntmf3wmyra7jqttfx7z6zgtkygjhc7]'
477
477
  }
478
478
 
479
- module.exports = {
479
+ export default {
480
480
  mockUtxoData,
481
481
  mockHydratedUtxos,
482
482
  mockTwoHydratedAddrs,
@@ -1,10 +1,10 @@
1
1
  // Public npm libraries
2
- const assert = require('assert')
3
- const axios = require('axios')
4
- const sinon = require('sinon')
2
+ import assert from 'assert'
3
+ import axios from 'axios'
4
+ import sinon from 'sinon'
5
5
 
6
6
  // Unit under test (uut)
7
- const BCHJS = require('../../src/bch-js')
7
+ import BCHJS from '../../src/bch-js.js'
8
8
  // const bchjs = new BCHJS()
9
9
  let bchjs
10
10
 
@@ -20,7 +20,7 @@ describe('#Generating', () => {
20
20
 
21
21
  it('should generate', done => {
22
22
  const data = []
23
- const resolved = new Promise(resolve => resolve({ data: data }))
23
+ const resolved = new Promise(resolve => resolve({ data }))
24
24
  sandbox.stub(axios, 'post').returns(resolved)
25
25
 
26
26
  bchjs.Generating.generateToAddress(
@@ -1,13 +1,15 @@
1
1
  // Public npm libraries
2
- const assert = require('assert')
3
- const Buffer = require('safe-buffer').Buffer
2
+ import assert from 'assert'
3
+ import { Buffer } from 'safe-buffer'
4
4
 
5
5
  // Mocks
6
- const fixtures = require('./fixtures/hdnode.json')
6
+ import { createRequire } from 'module'
7
7
  // const slpFixtures = require('./fixtures/slp/address.json')
8
8
 
9
9
  // Unit under test (uut)
10
- const BCHJS = require('../../src/bch-js')
10
+ import BCHJS from '../../src/bch-js.js'
11
+ const require = createRequire(import.meta.url)
12
+ const fixtures = require('./fixtures/hdnode.json')
11
13
  let bchjs
12
14
 
13
15
  describe('#HDNode', () => {
@@ -1,10 +1,10 @@
1
1
  // Public npm libraries
2
- const assert = require('assert')
3
- const axios = require('axios')
4
- const sinon = require('sinon')
2
+ import assert from 'assert'
3
+ import axios from 'axios'
4
+ import sinon from 'sinon'
5
5
 
6
6
  // Unit under test (uut)
7
- const BCHJS = require('../../src/bch-js')
7
+ import BCHJS from '../../src/bch-js.js'
8
8
  let bchjs
9
9
 
10
10
  describe('#Mining', () => {
@@ -30,7 +30,7 @@ describe('#Mining', () => {
30
30
  sigops: 2
31
31
  }
32
32
 
33
- const resolved = new Promise(resolve => resolve({ data: data }))
33
+ const resolved = new Promise(resolve => resolve({ data }))
34
34
  sandbox.stub(axios, 'get').returns(resolved)
35
35
 
36
36
  bchjs.Mining.getBlockTemplate('')
@@ -59,7 +59,7 @@ describe('#Mining', () => {
59
59
  chain: 'main'
60
60
  }
61
61
 
62
- const resolved = new Promise(resolve => resolve({ data: data }))
62
+ const resolved = new Promise(resolve => resolve({ data }))
63
63
  sandbox.stub(axios, 'get').returns(resolved)
64
64
 
65
65
  bchjs.Mining.getMiningInfo()
@@ -78,7 +78,7 @@ describe('#Mining', () => {
78
78
  it('should get network hashps', done => {
79
79
  const data = 3586365937646890000
80
80
 
81
- const resolved = new Promise(resolve => resolve({ data: data }))
81
+ const resolved = new Promise(resolve => resolve({ data }))
82
82
  sandbox.stub(axios, 'get').returns(resolved)
83
83
 
84
84
  bchjs.Mining.getNetworkHashps()
@@ -98,7 +98,7 @@ describe('#Mining', () => {
98
98
  it('should TODO', done => {
99
99
  const data = {}
100
100
 
101
- const resolved = new Promise(resolve => resolve({ data: data }))
101
+ const resolved = new Promise(resolve => resolve({ data }))
102
102
  sandbox.stub(axios, 'post').returns(resolved)
103
103
 
104
104
  bchjs.Mining.submitBlock()
@@ -1,6 +1,8 @@
1
+ import { createRequire } from 'module'
2
+ import assert from 'assert'
3
+ import BCHJS from '../../src/bch-js.js'
4
+ const require = createRequire(import.meta.url)
1
5
  const fixtures = require('./fixtures/mnemonic.json')
2
- const assert = require('assert')
3
- const BCHJS = require('../../src/bch-js')
4
6
  const bchjs = new BCHJS()
5
7
 
6
8
  describe('#Mnemonic', () => {
@@ -1,8 +1,9 @@
1
- const assert = require('chai').assert
2
- const BCHJS = require('../../src/bch-js')
3
- const sinon = require('sinon')
1
+ import chai from 'chai'
2
+ import BCHJS from '../../src/bch-js.js'
3
+ import sinon from 'sinon'
4
4
 
5
- const mockDataLib = require('./fixtures/price-mocks')
5
+ import mockDataLib from './fixtures/price-mocks.js'
6
+ const { assert } = chai
6
7
  let mockData
7
8
 
8
9
  describe('#price', () => {
@@ -57,16 +58,6 @@ describe('#price', () => {
57
58
  })
58
59
  })
59
60
 
60
- describe('#getBchaUsd', () => {
61
- it('should get the USD price of BCHA', async () => {
62
- sandbox.stub(bchjs.Price.axios, 'get').resolves({ data: { usd: 18.87 } })
63
-
64
- const result = await bchjs.Price.getBchaUsd()
65
- // console.log(result)
66
-
67
- assert.isNumber(result)
68
- })
69
- })
70
61
  describe('#getBchUsd', () => {
71
62
  it('should get the USD price of BCH', async () => {
72
63
  sandbox.stub(bchjs.Price.axios, 'get').resolves({ data: { usd: 510.39 } })
@@ -1,12 +1,12 @@
1
- const chai = require('chai')
2
- const assert = chai.assert
3
- const axios = require('axios')
4
- const sinon = require('sinon')
1
+ import chai from 'chai'
2
+ import axios from 'axios'
3
+ import sinon from 'sinon'
5
4
 
6
- const BCHJS = require('../../src/bch-js')
7
- const bchjs = new BCHJS()
5
+ import BCHJS from '../../src/bch-js.js'
8
6
 
9
- const mockData = require('./fixtures/psf-slp-indexer-mock')
7
+ import mockData from './fixtures/psf-slp-indexer-mock.js'
8
+ const assert = chai.assert
9
+ const bchjs = new BCHJS()
10
10
 
11
11
  describe('#PsfSlpIndexer', () => {
12
12
  let sandbox