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.
- package/dist/types/wallet/index.d.ts +1 -0
- package/dist/wallet/index.js +19 -3
- package/dist/wallet/index.js.map +1 -1
- package/package.json +4 -3
- package/src/wallet/index.ts +29 -3
- package/tests/boost.test.ts +68 -98
- package/tests/derivation.test.ts +13 -27
- package/tests/electrum.test.ts +33 -34
- package/tests/receive.test.ts +216 -0
- package/tests/storage.test.ts +54 -41
- package/tests/transaction.test.ts +33 -43
- package/tests/utils.ts +60 -2
- package/tests/wallet.test.ts +35 -44
package/tests/wallet.test.ts
CHANGED
|
@@ -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
|
-
|
|
35
|
+
describe('Wallet Library', async function () {
|
|
38
36
|
this.timeout(testTimeout);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
59
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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'
|