mainnet-js 2.0.0 → 2.1.0-alpha.5

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 (91) hide show
  1. package/dist/index.html +1 -1
  2. package/dist/{mainnet-2.0.0.js → mainnet-2.1.0-alpha.5.js} +18 -58
  3. package/dist/module/db/StorageProvider.d.ts +9 -9
  4. package/dist/module/db/StorageProvider.d.ts.map +1 -1
  5. package/dist/module/db/StorageProvider.js +2 -1
  6. package/dist/module/db/StorageProvider.js.map +1 -1
  7. package/dist/module/db/index.d.ts +1 -2
  8. package/dist/module/db/index.d.ts.map +1 -1
  9. package/dist/module/db/index.js +2 -2
  10. package/dist/module/db/index.js.map +1 -1
  11. package/dist/module/db/interface.d.ts +0 -12
  12. package/dist/module/db/interface.d.ts.map +1 -1
  13. package/dist/module/db/util.d.ts +0 -2
  14. package/dist/module/db/util.d.ts.map +1 -1
  15. package/dist/module/db/util.js +0 -23
  16. package/dist/module/db/util.js.map +1 -1
  17. package/dist/module/index.d.ts +0 -1
  18. package/dist/module/index.d.ts.map +1 -1
  19. package/dist/module/index.js +0 -4
  20. package/dist/module/index.js.map +1 -1
  21. package/dist/module/network/index.d.ts +1 -0
  22. package/dist/module/network/index.d.ts.map +1 -1
  23. package/dist/module/wallet/Base.d.ts +1 -1
  24. package/dist/module/wallet/Base.d.ts.map +1 -1
  25. package/dist/module/wallet/Base.js +6 -1
  26. package/dist/module/wallet/Base.js.map +1 -1
  27. package/dist/module/wallet/Bcmr.d.ts +3 -1
  28. package/dist/module/wallet/Bcmr.d.ts.map +1 -1
  29. package/dist/module/wallet/Bcmr.js +6 -8
  30. package/dist/module/wallet/Bcmr.js.map +1 -1
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +2 -12
  33. package/src/db/StorageProvider.ts +9 -9
  34. package/src/db/index.ts +1 -2
  35. package/src/db/interface.ts +0 -14
  36. package/src/db/util.ts +0 -26
  37. package/src/index.ts +0 -5
  38. package/src/network/index.ts +1 -0
  39. package/src/wallet/Base.ts +9 -2
  40. package/src/wallet/Bcmr.ts +8 -9
  41. package/src/wallet/Wif.test.ts +0 -42
  42. package/dist/module/db/IndexedDBProvider.d.ts +0 -16
  43. package/dist/module/db/IndexedDBProvider.d.ts.map +0 -1
  44. package/dist/module/db/IndexedDBProvider.js +0 -80
  45. package/dist/module/db/IndexedDBProvider.js.map +0 -1
  46. package/dist/module/db/SqlProvider.d.ts +0 -40
  47. package/dist/module/db/SqlProvider.d.ts.map +0 -1
  48. package/dist/module/db/SqlProvider.js +0 -198
  49. package/dist/module/db/SqlProvider.js.map +0 -1
  50. package/dist/module/db/getStorageProvider.d.ts +0 -3
  51. package/dist/module/db/getStorageProvider.d.ts.map +0 -1
  52. package/dist/module/db/getStorageProvider.js +0 -19
  53. package/dist/module/db/getStorageProvider.js.map +0 -1
  54. package/dist/module/webhook/Webhook.d.ts +0 -36
  55. package/dist/module/webhook/Webhook.d.ts.map +0 -1
  56. package/dist/module/webhook/Webhook.js +0 -77
  57. package/dist/module/webhook/Webhook.js.map +0 -1
  58. package/dist/module/webhook/WebhookBch.d.ts +0 -14
  59. package/dist/module/webhook/WebhookBch.d.ts.map +0 -1
  60. package/dist/module/webhook/WebhookBch.js +0 -141
  61. package/dist/module/webhook/WebhookBch.js.map +0 -1
  62. package/dist/module/webhook/WebhookWorker.d.ts +0 -23
  63. package/dist/module/webhook/WebhookWorker.d.ts.map +0 -1
  64. package/dist/module/webhook/WebhookWorker.js +0 -94
  65. package/dist/module/webhook/WebhookWorker.js.map +0 -1
  66. package/dist/module/webhook/index.d.ts +0 -5
  67. package/dist/module/webhook/index.d.ts.map +0 -1
  68. package/dist/module/webhook/index.js +0 -5
  69. package/dist/module/webhook/index.js.map +0 -1
  70. package/dist/module/webhook/interface.d.ts +0 -8
  71. package/dist/module/webhook/interface.d.ts.map +0 -1
  72. package/dist/module/webhook/interface.js +0 -2
  73. package/dist/module/webhook/interface.js.map +0 -1
  74. package/src/Wallet.test.headless.js +0 -369
  75. package/src/Wallet.test.ts +0 -519
  76. package/src/db/IndexedDBProvider.test.ts +0 -69
  77. package/src/db/IndexedDBProvider.ts +0 -93
  78. package/src/db/SqlProvider.test.ts +0 -282
  79. package/src/db/SqlProvider.ts +0 -297
  80. package/src/db/getStorageProvider.ts +0 -20
  81. package/src/db/index.test.headless.js +0 -62
  82. package/src/db/index.test.ts +0 -64
  83. package/src/wallet/createWallet.test.ts +0 -155
  84. package/src/webhook/Webhook.test.ts +0 -9
  85. package/src/webhook/Webhook.ts +0 -99
  86. package/src/webhook/WebhookBch.test.ts +0 -323
  87. package/src/webhook/WebhookBch.ts +0 -198
  88. package/src/webhook/WebhookWorker.test.ts +0 -96
  89. package/src/webhook/WebhookWorker.ts +0 -119
  90. package/src/webhook/index.ts +0 -4
  91. package/src/webhook/interface.ts +0 -7
@@ -1,369 +0,0 @@
1
- const playwright = require("playwright");
2
- const PAGE_URL = "http://localhost:8080";
3
-
4
- describe(`Wallet should function in the browser`, () => {
5
- let browser = null;
6
- let page = null;
7
-
8
- /**
9
- * Create the browser and page context
10
- */
11
- beforeAll(async () => {
12
- browser = await playwright["chromium"].launch();
13
- page = await browser.newPage();
14
-
15
- if (!page) {
16
- throw new Error("Connection wasn't established");
17
- }
18
-
19
- // Open the page
20
- await page.goto(PAGE_URL, {
21
- waitUntil: "networkidle0",
22
- });
23
- });
24
-
25
- afterAll(async () => {
26
- await browser.close();
27
- });
28
-
29
- test(`Should load page`, async () => {
30
- expect(page).not.toBeNull();
31
- expect(await page.title()).toEqual("The Empty Mainnet App");
32
- });
33
-
34
- test(`Should load module`, async () => {
35
- expect(page).not.toBeNull();
36
- const result = await page.evaluate(async () => {
37
- return await typeof TestNetWallet;
38
- });
39
- expect(result).toEqual("function");
40
- });
41
-
42
- test(`Should not have a "process"`, async () => {
43
- expect(page).not.toBeNull();
44
- const result = await page.evaluate(async () => {
45
- return typeof process;
46
- });
47
- expect(result).toEqual("undefined");
48
- });
49
-
50
- test(`Should create regtest wallet`, async () => {
51
- let params = { name: "Alice's Regtest", type: "wif", network: "regtest" };
52
- const result = await page.evaluate(async (p) => {
53
- return await createWalletResponse(p);
54
- }, params);
55
- expect(result.cashaddr.slice(0, 8)).toBe("bchreg:q");
56
- });
57
-
58
- test(`Should create testnet wallet`, async () => {
59
- let params = { name: "Alice's TestNet", type: "wif", network: "testnet" };
60
- const result = await page.evaluate(async (p) => {
61
- return await createWalletResponse(p);
62
- }, params);
63
- expect(result.cashaddr.slice(0, 9)).toBe("bchtest:q");
64
- });
65
-
66
- test(`Should throw Error on regtest wif to Testnet`, async () => {
67
- expect.assertions(1);
68
- try {
69
- const result = await page.evaluate(async (wif) => {
70
- return await TestNetWallet.fromId(`wif:regtest:${wif}`);
71
- }, process.env.PRIVATE_WIF);
72
- } catch (e) {
73
- expect(e.message.split("\n")[0]).toContain(
74
- "Error: Network prefix regtest to a testnet wallet"
75
- );
76
- }
77
- });
78
-
79
- test(`Should throw Error on regtest hd to regtest wif`, async () => {
80
- expect.assertions(1);
81
- try {
82
- const result = await page.evaluate(async (wif) => {
83
- return await TestNetWallet.fromId(`hd:testnet:${wif}`);
84
- }, process.env.PRIVATE_WIF);
85
- } catch (e) {
86
- expect(e.message.split("\n")[0]).toContain(
87
- "Error: Unknown wallet type 'hd'"
88
- );
89
- }
90
- });
91
-
92
- test(`Should create a random testnet wallet`, async () => {
93
- let params = {};
94
- const result = await page.evaluate(async (p) => {
95
- let w = await TestNetWallet.newRandom();
96
- return w.getDepositAddress();
97
- }, params);
98
- expect(result.slice(0, 9)).toBe("bchtest:q");
99
- });
100
-
101
- test(`Should create mainnet wallet`, async () => {
102
- const result = await page.evaluate(async (p) => {
103
- let w = await Wallet.newRandom();
104
- return w.getDepositAddress();
105
- });
106
- expect(result.slice(0, 13)).toBe("bitcoincash:q");
107
- });
108
-
109
- test(`Should get an empty balance from a mainnet wallet`, async () => {
110
- const result = await page.evaluate(async (p) => {
111
- let w = await Wallet.newRandom();
112
- return w.getBalance();
113
- });
114
- expect(result.sat).toBe(0);
115
- });
116
-
117
- test(`Should return deposit address from testnet wallet`, async () => {
118
- const result = await page.evaluate(async (wif) => {
119
- const alice = await TestNetWallet.fromWIF(wif);
120
- return alice.getDepositAddress();
121
- }, process.env.PRIVATE_WIF);
122
- expect(result.slice(0, 10)).toBe("bchtest:qp");
123
- });
124
-
125
- test(`Should return deposit qr from testnet wallet`, async () => {
126
- const result = await page.evaluate(async (wif) => {
127
- const alice = await TestNetWallet.fromWIF(wif);
128
- return alice.getDepositQr();
129
- }, process.env.PRIVATE_WIF);
130
- expect(
131
- result.src.startsWith("data:image/svg+xml;base64,PD94bWwgdm")
132
- ).toBeTruthy();
133
- });
134
-
135
- test(`Should return deposit address from testnet wallet`, async () => {
136
- const result = await page.evaluate(async (wif) => {
137
- const alice = await TestNetWallet.fromWIF(wif);
138
- return alice.getDepositAddress();
139
- }, process.env.PRIVATE_WIF);
140
- expect(result.slice(0, 9)).toBe("bchtest:q");
141
- });
142
-
143
- test(`Should return watch testnet balance`, async () => {
144
- if (process.env.ALICE_TESTNET_ADDRESS) {
145
- const result = await page.evaluate(async (addr) => {
146
- const alice = await TestNetWallet.watchOnly(addr);
147
- return alice.getBalance("sat");
148
- }, process.env.ALICE_TESTNET_ADDRESS);
149
- expect(result).toBeGreaterThan(0);
150
- } else {
151
- expect.assertions(1);
152
- console.warn(
153
- "SKIPPING testnet balance test, set ALICE_TESTNET_ADDRESS env"
154
- );
155
- }
156
- });
157
-
158
- test(`Should return watch named balance`, async () => {
159
- if (process.env.ALICE_TESTNET_ADDRESS) {
160
- const result = await page.evaluate(async (addr) => {
161
- const alice = await TestNetWallet.named("alice");
162
- return alice.getBalance("sat");
163
- }, process.env.ALICE_TESTNET_ADDRESS);
164
- expect(result).toBe(0);
165
- } else {
166
- expect.assertions(1);
167
- console.warn(
168
- "SKIPPING testnet balance test, set ALICE_TESTNET_ADDRESS env"
169
- );
170
- }
171
- });
172
-
173
- test(`Should return reterive a named wallet`, async () => {
174
- const result = await page.evaluate(async () => {
175
- const alice = await TestNetWallet.named("alice");
176
- const alice2 = await TestNetWallet.named("alice");
177
- return [alice.cashaddr, alice2.cashaddr];
178
- }, undefined);
179
- expect(result[0]).toBe(result[1]);
180
- });
181
-
182
- test(`Should return testnet balance in usd`, async () => {
183
- if (process.env.ALICE_TESTNET_ADDRESS) {
184
- const result = await page.evaluate(async (addr) => {
185
- const alice = await TestNetWallet.watchOnly(addr);
186
- return alice.getBalance("usd");
187
- }, process.env.ALICE_TESTNET_ADDRESS);
188
- expect(result).toBeGreaterThan(0);
189
- } else {
190
- expect.assertions(1);
191
- console.warn(
192
- "SKIPPING testnet balance test, set ALICE_TESTNET_ADDRESS env"
193
- );
194
- }
195
- });
196
-
197
- test(`Should return testnet balance in usd`, async () => {
198
- const result = await page.evaluate(async () => {
199
- return await Mainnet.convert(1, "bch", "sat");
200
- });
201
- expect(result).toBe(100000000);
202
- });
203
-
204
- test(`Should sign a message and verify it`, async () => {
205
- const result = await page.evaluate(async (wif) => {
206
- const alice = await walletFromId(`wif:regtest:${wif}`);
207
- let result = await alice.sign("test");
208
- return {
209
- resp: await alice.verify("test", result.signature),
210
- signature: result.signature,
211
- };
212
- }, process.env.PRIVATE_WIF);
213
- expect(result.signature).toBe(
214
- "IOEEiqRXRVK9gPUNpXuBjJUK47Y8XpseZejgwu59CoNSVv+3K1NkHdT64RXHP7cw4PZ6usRQ4ULrP/p5CJnrg9U="
215
- );
216
- expect(result.resp.valid).toBe(true);
217
- });
218
-
219
- test(`Should send to Bob; sendMax all of Bob's funds back`, async () => {
220
- const result = await page.evaluate(async (wif) => {
221
- const alice = await walletFromId(`wif:regtest:${wif}`);
222
- const bob = await createWallet({
223
- type: "wif",
224
- network: "regtest",
225
- name: "Bob's random wallet",
226
- });
227
- await alice.send([
228
- {
229
- cashaddr: bob.cashaddr,
230
- value: 3000,
231
- unit: "sat",
232
- },
233
- ]);
234
- return bob.sendMax(alice.cashaddr);
235
- }, process.env.PRIVATE_WIF);
236
- expect(result.balance.sat).toBe(0);
237
- });
238
-
239
- test("Store and replace a Regtest wallet", async () => {
240
- const result = await page.evaluate(async () => {
241
- const name = `storereplace ${Math.random()}`;
242
-
243
- const check1 = await RegTestWallet.namedExists(name);
244
- const w1 = await RegTestWallet.named(name);
245
- const check2 = await RegTestWallet.namedExists(name);
246
-
247
- const seedId = (
248
- await RegTestWallet.fromSeed(new Array(12).join("abandon "))
249
- ).toDbString();
250
- const w3 = await RegTestWallet.replaceNamed(name, seedId);
251
- const w4 = await RegTestWallet.named(name);
252
-
253
- const w5 = await RegTestWallet.replaceNamed(
254
- `${name}_nonexistent`,
255
- seedId
256
- );
257
- const w6 = await RegTestWallet.named(`${name}_nonexistent`);
258
-
259
- return {
260
- check1,
261
- check2,
262
- w1: w1.toDbString(),
263
- w4: w4.toDbString(),
264
- w5: w5.toDbString(),
265
- w6: w6.toDbString(),
266
- seedId,
267
- };
268
- });
269
-
270
- expect(result.check1).toBe(false);
271
- expect(result.check2).toBe(true);
272
- expect(result.w4).not.toBe(result.w1);
273
- expect(result.w4).toBe(result.seedId);
274
- expect(result.w6).toBe(result.w5);
275
- });
276
-
277
- test("Test waiting and watching", async () => {
278
- await page.evaluate(async (ALICE_ID) => {
279
- const alice = await RegTestWallet.fromId(ALICE_ID);
280
-
281
- const bob = await RegTestWallet.newRandom();
282
-
283
- let waitTxResult = false;
284
- setTimeout(async () => {
285
- const result = await alice.waitForTransaction({
286
- getBalance: true,
287
- getTransactionInfo: true,
288
- });
289
- expect(result.balance.sat).toBeGreaterThan(0);
290
- expect(result.transactionInfo.hash.length).toBe(64);
291
- waitTxResult = true;
292
- }, 0);
293
-
294
- let waitBalanceResult = false;
295
- setTimeout(async () => {
296
- const result = await alice.waitForBalance(0.001, "bch");
297
- expect(result.sat).toBeGreaterThan(0);
298
- waitBalanceResult = true;
299
- }, 0);
300
-
301
- // let aliceWatchResult = false;
302
- // const aliceWatchCancel = alice.watchAddressTransactions((_tx) => {
303
- // aliceWatchCancel();
304
- // aliceWatchResult = true;
305
- // });
306
-
307
- // let bobWatchResult = false;
308
- // const bobWatchCancel = bob.watchAddress((_txHash) => {
309
- // bobWatchCancel();
310
- // bobWatchResult = true;
311
- // });
312
-
313
- let bobBalanceWatchResult = false;
314
- const bobBalanceWatchCancel = bob.watchBalance((balance) => {
315
- expect(balance.bch).toBe(0.001);
316
- bobBalanceWatchCancel();
317
- bobBalanceWatchResult = true;
318
- });
319
-
320
- // let blockWatchResult = false;
321
- // const blockWatchCancel = bob.watchBlocks((block) => {
322
- // expect(block.height).toBeGreaterThan(1);
323
- // blockWatchCancel();
324
- // blockWatchResult = true;
325
- // });
326
-
327
- // let blockWaitResult = false;
328
- // setTimeout(async () => {
329
- // const blockNumber = await (
330
- // alice.provider
331
- // ).getBlockHeight();
332
- // const result = await alice.waitForBlock();
333
- // expect(result.height).toBe(blockNumber + 1);
334
- // blockWaitResult = true;
335
- // }, 0);
336
-
337
- // let blockNumberWaitResult = false;
338
- // setTimeout(async () => {
339
- // const blockNumber = await (
340
- // alice.provider
341
- // ).getBlockHeight();
342
- // const result = await alice.waitForBlock(blockNumber + 2);
343
- // expect(result.height).toBe(blockNumber + 2);
344
- // blockNumberWaitResult = true;
345
- // }, 0);
346
-
347
- await alice.send({
348
- cashaddr: bob.getDepositAddress(),
349
- value: 0.001,
350
- unit: "bch",
351
- });
352
-
353
- //! mining not supported in browser
354
- // await mine({ cashaddr: alice.cashaddr, blocks: 1 });
355
- // await new Promise((resolve) => setTimeout(resolve, 1000));
356
- // await mine({ cashaddr: alice.cashaddr, blocks: 1 });
357
-
358
- await new Promise((resolve) => setTimeout(resolve, 5000));
359
- expect(waitTxResult).toBe(true);
360
- expect(waitBalanceResult).toBe(true);
361
- // expect(aliceWatchResult).toBe(true);
362
- // expect(bobWatchResult).toBe(true);
363
- expect(bobBalanceWatchResult).toBe(true);
364
- // expect(blockWatchResult).toBe(true);
365
- // expect(blockWaitResult).toBe(true);
366
- // expect(blockNumberWaitResult).toBe(true);
367
- }, process.env.ALICE_ID);
368
- });
369
- });