beignet 0.0.48 → 0.0.49

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.
@@ -1,16 +1,17 @@
1
- import * as chai from 'chai';
2
1
  import { validateMnemonic } from 'bip39';
2
+ import { expect } from 'chai';
3
3
  import net from 'net';
4
- import tls from 'tls';
5
4
  import sinon from 'sinon';
5
+ import tls from 'tls';
6
6
 
7
7
  import {
8
- filterAddressesObjForGapLimit,
9
8
  filterAddressesObjForAddressesList,
9
+ filterAddressesObjForGapLimit,
10
10
  IAddress,
11
11
  IAddresses,
12
12
  Wallet
13
13
  } from '../';
14
+ import { servers } from '../example/helpers';
14
15
  import {
15
16
  EAddressType,
16
17
  EAvailableNetworks,
@@ -22,41 +23,38 @@ import {
22
23
  Result
23
24
  } from '../src';
24
25
  import { TEST_MNEMONIC } from './constants';
25
- import { servers } from '../example/helpers';
26
26
  import {
27
27
  EXPECTED_SHARED_RESULTS,
28
28
  EXPECTED_WALLET_RESULTS
29
29
  } from './expected-results';
30
30
 
31
- const expect = chai.expect;
32
-
33
31
  const testTimeout = 60000;
34
32
 
35
33
  let wallet: Wallet;
36
34
 
37
- before(async function () {
35
+ describe('Wallet Library', async function () {
38
36
  this.timeout(testTimeout);
39
- const res = await Wallet.create({
40
- mnemonic: TEST_MNEMONIC,
41
- network: EAvailableNetworks.testnet,
42
- addressType: EAddressType.p2wpkh,
43
- electrumOptions: {
44
- servers: servers[EAvailableNetworks.testnet],
45
- net,
46
- tls
47
- }
37
+
38
+ before(async function () {
39
+ this.timeout(testTimeout);
40
+ const res = await Wallet.create({
41
+ mnemonic: TEST_MNEMONIC,
42
+ network: EAvailableNetworks.testnet,
43
+ addressType: EAddressType.p2wpkh,
44
+ electrumOptions: {
45
+ servers: servers[EAvailableNetworks.testnet],
46
+ net,
47
+ tls
48
+ }
49
+ });
50
+ if (res.isErr()) throw res.error;
51
+ wallet = res.value;
52
+ await wallet.refreshWallet({});
48
53
  });
49
- if (res.isErr()) {
50
- console.log('error: ', res.error.message);
51
- //throw new Error(res.error.message);
52
- return;
53
- }
54
- wallet = res.value;
55
- await wallet.refreshWallet({});
56
- });
57
54
 
58
- describe('Wallet Library', async function () {
59
- this.timeout(testTimeout);
55
+ after(async function () {
56
+ await wallet?.electrum?.disconnect();
57
+ });
60
58
 
61
59
  it('Should successfully create a wallet.', () => {
62
60
  expect(wallet).not.to.be.null;
@@ -125,8 +123,7 @@ describe('Wallet Library', async function () {
125
123
 
126
124
  it('Should generate a bech32 receiving address at index 0 via its path', async () => {
127
125
  const address = await wallet.getAddressByPath({ path: "m/84'/1'/0'/0/0" });
128
- expect(address.isErr()).to.equal(false);
129
- if (address.isErr()) return;
126
+ if (address.isErr()) throw address.error;
130
127
  expect(address.value.address).to.equal(
131
128
  'tb1qmja98kkd540qtesjqdanfg0ywags845vehfg66'
132
129
  );
@@ -134,8 +131,7 @@ describe('Wallet Library', async function () {
134
131
 
135
132
  it('Should generate a segwit change address at index 1 via its path', async () => {
136
133
  const address = await wallet.getAddressByPath({ path: "m/49'/1'/0'/1/1" });
137
- expect(address.isErr()).to.equal(false);
138
- if (address.isErr()) return;
134
+ if (address.isErr()) throw address.error;
139
135
  expect(address.value.address).to.equal(
140
136
  '2NDRG1ZGhWMGGNW7Mp58BKcyBs4Hyat8Law'
141
137
  );
@@ -143,8 +139,7 @@ describe('Wallet Library', async function () {
143
139
 
144
140
  it('Should generate a testnet legacy receiving address at index 5 via its path', async () => {
145
141
  const address = await wallet.getAddressByPath({ path: "m/44'/1'/0'/0/5" });
146
- expect(address.isErr()).to.equal(false);
147
- if (address.isErr()) return;
142
+ if (address.isErr()) throw address.error;
148
143
  expect(address.value.address).to.equal(
149
144
  'mohdq3fadTtT4uSH4oNr4F1Dp3YM4pR3VF'
150
145
  );
@@ -152,8 +147,7 @@ describe('Wallet Library', async function () {
152
147
 
153
148
  it('getNextAvailableAddress: Should return the next available address/change index and the last used address/change index', async () => {
154
149
  const r = await wallet.getNextAvailableAddress();
155
- expect(r.isErr()).to.equal(false);
156
- if (r.isErr()) return;
150
+ if (r.isErr()) throw r.error;
157
151
  expect(r.value).to.deep.equal(
158
152
  EXPECTED_SHARED_RESULTS.getNextAvailableAddress
159
153
  );
@@ -161,8 +155,7 @@ describe('Wallet Library', async function () {
161
155
 
162
156
  it("Should return available UTXO's", async () => {
163
157
  const getUtxosRes: Result<IGetUtxosResponse> = await wallet.getUtxos({});
164
- expect(getUtxosRes.isErr()).to.equal(false);
165
- if (getUtxosRes.isErr()) return;
158
+ if (getUtxosRes.isErr()) throw getUtxosRes.error;
166
159
  expect(Array.isArray(getUtxosRes.value.utxos)).to.equal(true);
167
160
  expect(getUtxosRes.value.utxos.length).to.equal(3);
168
161
  expect(getUtxosRes.value.balance).to.equal(5855);
@@ -267,13 +260,13 @@ describe('Wallet Library', async function () {
267
260
  );
268
261
  expect(addressData1).to.not.be.undefined;
269
262
  if (!addressData1) return;
270
- const privateKey1: string = await wallet.getPrivateKey(addressData1.path);
263
+ const privateKey1: string = wallet.getPrivateKey(addressData1.path);
271
264
  expect(typeof privateKey1).to.equal('string');
272
265
  expect(privateKey1).to.equal(
273
266
  'cSkdqJTnvZ56deaW5PpVJPeUCAQfPV7xJocfiZxdgm9UHHmXuXzY'
274
267
  );
275
268
 
276
- const privateKey2: string = await wallet.getPrivateKey("m/84'/1'/0'/0/19");
269
+ const privateKey2: string = wallet.getPrivateKey("m/84'/1'/0'/0/19");
277
270
  expect(typeof privateKey2).to.equal('string');
278
271
  expect(privateKey2).to.equal(
279
272
  'cUcpwVpcwvVz17qnBzwNfNQpp9FsfXH1ogjKCkxgbB2ZzGGjrK2r'
@@ -283,8 +276,7 @@ describe('Wallet Library', async function () {
283
276
  it('Should successfully return the tx history for a given address', async () => {
284
277
  const address = 'tb1qmja98kkd540qtesjqdanfg0ywags845vehfg66';
285
278
  const history = await wallet.getAddressHistory(address);
286
- expect(history.isErr()).to.equal(false);
287
- if (history.isErr()) return;
279
+ if (history.isErr()) throw history.error;
288
280
  expect(history.value).to.deep.equal(EXPECTED_WALLET_RESULTS.addressHistory);
289
281
  });
290
282
 
@@ -292,8 +284,7 @@ describe('Wallet Library', async function () {
292
284
  const tx =
293
285
  'e12dec55bd19c709ed5cc3213aab814315fd9716afc99dfe914b9190fdcb8452';
294
286
  const txDetails = await wallet.getTransactionDetails(tx);
295
- expect(txDetails.isErr()).to.equal(false);
296
- if (txDetails.isErr()) return;
287
+ if (txDetails.isErr()) throw txDetails.error;
297
288
  expect(txDetails.value.confirmations).to.be.a('number');
298
289
  delete txDetails.value.confirmations;
299
290
  expect(txDetails.value).to.deep.equal(
@@ -370,13 +361,13 @@ describe('Wallet Library', async function () {
370
361
  );
371
362
  expect(addressData1).to.not.be.undefined;
372
363
  if (!addressData1) return;
373
- const privateKey1: string = await wallet.getPrivateKey(addressData1.path);
364
+ const privateKey1: string = wallet.getPrivateKey(addressData1.path);
374
365
  expect(typeof privateKey1).to.equal('string');
375
366
  expect(privateKey1).to.equal(
376
367
  'L2iqFGgLkMzQossGaQ9B2tmhSsLq3vgunnHb8vnLavXUh54GSLnK'
377
368
  );
378
369
 
379
- const privateKey2: string = await wallet.getPrivateKey("m/84'/0'/0'/0/19");
370
+ const privateKey2: string = wallet.getPrivateKey("m/84'/0'/0'/0/19");
380
371
  expect(typeof privateKey2).to.equal('string');
381
372
  expect(privateKey2).to.equal(
382
373
  'L2cB657yFF88YEebxoad3YgeezYKAu61AhmnDHMFo7GjjpPqBZG1'