@mainnet-cash/indexeddb-storage 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.
- package/README.md +3 -0
- package/dist/index.html +9 -0
- package/dist/indexeddb-storage-2.1.0-alpha.5.js +118 -0
- package/dist/module/IndexedDBProvider.d.ts +14 -0
- package/dist/module/IndexedDBProvider.js +80 -0
- package/dist/module/IndexedDBProvider.js.map +1 -0
- package/dist/module/index.d.ts +1 -0
- package/dist/module/index.js +2 -0
- package/dist/module/index.js.map +1 -0
- package/dist/tsconfig.browser.tsbuildinfo +1 -0
- package/package.json +32 -0
- package/src/IndexedDBProvider.test.ts +69 -0
- package/src/IndexedDBProvider.ts +92 -0
- package/src/Wallet.test.headless.js +390 -0
- package/src/index.test.headless.js +64 -0
- package/src/index.ts +1 -0
- package/tsconfig.browser.json +6 -0
- package/tsconfig.json +28 -0
- package/webpack.config.cjs +103 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
const playwright = require("playwright");
|
|
2
|
+
const PAGE_URL = "http://localhost:8080/indexeddb-storage/index.html";
|
|
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
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
38
|
+
return await typeof TestNetWallet;
|
|
39
|
+
});
|
|
40
|
+
expect(result).toEqual("function");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test(`Should not have a "process"`, async () => {
|
|
44
|
+
expect(page).not.toBeNull();
|
|
45
|
+
const result = await page.evaluate(async () => {
|
|
46
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
47
|
+
return typeof process;
|
|
48
|
+
});
|
|
49
|
+
expect(result).toEqual("undefined");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test(`Should create regtest wallet`, async () => {
|
|
53
|
+
let params = { name: "Alice's Regtest", type: "wif", network: "regtest" };
|
|
54
|
+
const result = await page.evaluate(async (p) => {
|
|
55
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
56
|
+
return await createWalletResponse(p);
|
|
57
|
+
}, params);
|
|
58
|
+
expect(result.cashaddr.slice(0, 8)).toBe("bchreg:q");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test(`Should create testnet wallet`, async () => {
|
|
62
|
+
let params = { name: "Alice's TestNet", type: "wif", network: "testnet" };
|
|
63
|
+
const result = await page.evaluate(async (p) => {
|
|
64
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
65
|
+
return await createWalletResponse(p);
|
|
66
|
+
}, params);
|
|
67
|
+
expect(result.cashaddr.slice(0, 9)).toBe("bchtest:q");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test(`Should throw Error on regtest wif to Testnet`, async () => {
|
|
71
|
+
expect.assertions(1);
|
|
72
|
+
try {
|
|
73
|
+
const result = await page.evaluate(async (wif) => {
|
|
74
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
75
|
+
return await TestNetWallet.fromId(`wif:regtest:${wif}`);
|
|
76
|
+
}, process.env.PRIVATE_WIF);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
expect(e.message.split("\n")[0]).toContain(
|
|
79
|
+
"Error: Network prefix regtest to a testnet wallet"
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test(`Should throw Error on regtest hd to regtest wif`, async () => {
|
|
85
|
+
expect.assertions(1);
|
|
86
|
+
try {
|
|
87
|
+
const result = await page.evaluate(async (wif) => {
|
|
88
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
89
|
+
return await TestNetWallet.fromId(`hd:testnet:${wif}`);
|
|
90
|
+
}, process.env.PRIVATE_WIF);
|
|
91
|
+
} catch (e) {
|
|
92
|
+
expect(e.message.split("\n")[0]).toContain(
|
|
93
|
+
"Error: Unknown wallet type 'hd'"
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test(`Should create a random testnet wallet`, async () => {
|
|
99
|
+
let params = {};
|
|
100
|
+
const result = await page.evaluate(async (p) => {
|
|
101
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
102
|
+
let w = await TestNetWallet.newRandom();
|
|
103
|
+
return w.getDepositAddress();
|
|
104
|
+
}, params);
|
|
105
|
+
expect(result.slice(0, 9)).toBe("bchtest:q");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test(`Should create mainnet wallet`, async () => {
|
|
109
|
+
const result = await page.evaluate(async (p) => {
|
|
110
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
111
|
+
let w = await Wallet.newRandom();
|
|
112
|
+
return w.getDepositAddress();
|
|
113
|
+
});
|
|
114
|
+
expect(result.slice(0, 13)).toBe("bitcoincash:q");
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test(`Should get an empty balance from a mainnet wallet`, async () => {
|
|
118
|
+
const result = await page.evaluate(async (p) => {
|
|
119
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
120
|
+
let w = await Wallet.newRandom();
|
|
121
|
+
return w.getBalance();
|
|
122
|
+
});
|
|
123
|
+
expect(result.sat).toBe(0);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test(`Should return deposit address from testnet wallet`, async () => {
|
|
127
|
+
const result = await page.evaluate(async (wif) => {
|
|
128
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
129
|
+
const alice = await TestNetWallet.fromWIF(wif);
|
|
130
|
+
return alice.getDepositAddress();
|
|
131
|
+
}, process.env.PRIVATE_WIF);
|
|
132
|
+
expect(result.slice(0, 10)).toBe("bchtest:qp");
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test(`Should return deposit qr from testnet wallet`, async () => {
|
|
136
|
+
const result = await page.evaluate(async (wif) => {
|
|
137
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
138
|
+
const alice = await TestNetWallet.fromWIF(wif);
|
|
139
|
+
return alice.getDepositQr();
|
|
140
|
+
}, process.env.PRIVATE_WIF);
|
|
141
|
+
expect(
|
|
142
|
+
result.src.startsWith("data:image/svg+xml;base64,PD94bWwgdm")
|
|
143
|
+
).toBeTruthy();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test(`Should return deposit address from testnet wallet`, async () => {
|
|
147
|
+
const result = await page.evaluate(async (wif) => {
|
|
148
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
149
|
+
const alice = await TestNetWallet.fromWIF(wif);
|
|
150
|
+
return alice.getDepositAddress();
|
|
151
|
+
}, process.env.PRIVATE_WIF);
|
|
152
|
+
expect(result.slice(0, 9)).toBe("bchtest:q");
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
test(`Should return watch testnet balance`, async () => {
|
|
156
|
+
if (process.env.ALICE_TESTNET_ADDRESS) {
|
|
157
|
+
const result = await page.evaluate(async (addr) => {
|
|
158
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
159
|
+
const alice = await TestNetWallet.watchOnly(addr);
|
|
160
|
+
return alice.getBalance("sat");
|
|
161
|
+
}, process.env.ALICE_TESTNET_ADDRESS);
|
|
162
|
+
expect(result).toBeGreaterThan(0);
|
|
163
|
+
} else {
|
|
164
|
+
expect.assertions(1);
|
|
165
|
+
console.warn(
|
|
166
|
+
"SKIPPING testnet balance test, set ALICE_TESTNET_ADDRESS env"
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
test(`Should return watch named balance`, async () => {
|
|
172
|
+
if (process.env.ALICE_TESTNET_ADDRESS) {
|
|
173
|
+
const result = await page.evaluate(async (addr) => {
|
|
174
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
175
|
+
const alice = await TestNetWallet.named("alice");
|
|
176
|
+
return alice.getBalance("sat");
|
|
177
|
+
}, process.env.ALICE_TESTNET_ADDRESS);
|
|
178
|
+
expect(result).toBe(0);
|
|
179
|
+
} else {
|
|
180
|
+
expect.assertions(1);
|
|
181
|
+
console.warn(
|
|
182
|
+
"SKIPPING testnet balance test, set ALICE_TESTNET_ADDRESS env"
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test(`Should return reterive a named wallet`, async () => {
|
|
188
|
+
const result = await page.evaluate(async () => {
|
|
189
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
190
|
+
const alice = await TestNetWallet.named("alice");
|
|
191
|
+
const alice2 = await TestNetWallet.named("alice");
|
|
192
|
+
return [alice.cashaddr, alice2.cashaddr];
|
|
193
|
+
}, undefined);
|
|
194
|
+
expect(result[0]).toBe(result[1]);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test(`Should return testnet balance in usd`, async () => {
|
|
198
|
+
if (process.env.ALICE_TESTNET_ADDRESS) {
|
|
199
|
+
const result = await page.evaluate(async (addr) => {
|
|
200
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
201
|
+
const alice = await TestNetWallet.watchOnly(addr);
|
|
202
|
+
return alice.getBalance("usd");
|
|
203
|
+
}, process.env.ALICE_TESTNET_ADDRESS);
|
|
204
|
+
expect(result).toBeGreaterThan(0);
|
|
205
|
+
} else {
|
|
206
|
+
expect.assertions(1);
|
|
207
|
+
console.warn(
|
|
208
|
+
"SKIPPING testnet balance test, set ALICE_TESTNET_ADDRESS env"
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test(`Should return testnet balance in usd`, async () => {
|
|
214
|
+
const result = await page.evaluate(async () => {
|
|
215
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
216
|
+
return await Mainnet.convert(1, "bch", "sat");
|
|
217
|
+
});
|
|
218
|
+
expect(result).toBe(100000000);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test(`Should sign a message and verify it`, async () => {
|
|
222
|
+
const result = await page.evaluate(async (wif) => {
|
|
223
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
224
|
+
const alice = await walletFromId(`wif:regtest:${wif}`);
|
|
225
|
+
let result = await alice.sign("test");
|
|
226
|
+
return {
|
|
227
|
+
resp: await alice.verify("test", result.signature),
|
|
228
|
+
signature: result.signature,
|
|
229
|
+
};
|
|
230
|
+
}, process.env.PRIVATE_WIF);
|
|
231
|
+
expect(result.signature).toBe(
|
|
232
|
+
"IOEEiqRXRVK9gPUNpXuBjJUK47Y8XpseZejgwu59CoNSVv+3K1NkHdT64RXHP7cw4PZ6usRQ4ULrP/p5CJnrg9U="
|
|
233
|
+
);
|
|
234
|
+
expect(result.resp.valid).toBe(true);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test(`Should send to Bob; sendMax all of Bob's funds back`, async () => {
|
|
238
|
+
const result = await page.evaluate(async (wif) => {
|
|
239
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
240
|
+
const alice = await walletFromId(`wif:regtest:${wif}`);
|
|
241
|
+
const bob = await createWallet({
|
|
242
|
+
type: "wif",
|
|
243
|
+
network: "regtest",
|
|
244
|
+
name: "Bob's random wallet",
|
|
245
|
+
});
|
|
246
|
+
await alice.send([
|
|
247
|
+
{
|
|
248
|
+
cashaddr: bob.cashaddr,
|
|
249
|
+
value: 3000,
|
|
250
|
+
unit: "sat",
|
|
251
|
+
},
|
|
252
|
+
]);
|
|
253
|
+
return bob.sendMax(alice.cashaddr);
|
|
254
|
+
}, process.env.PRIVATE_WIF);
|
|
255
|
+
expect(result.balance.sat).toBe(0);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
test("Store and replace a Regtest wallet", async () => {
|
|
259
|
+
const result = await page.evaluate(async () => {
|
|
260
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
261
|
+
const name = `storereplace ${Math.random()}`;
|
|
262
|
+
|
|
263
|
+
const check1 = await RegTestWallet.namedExists(name);
|
|
264
|
+
const w1 = await RegTestWallet.named(name);
|
|
265
|
+
const check2 = await RegTestWallet.namedExists(name);
|
|
266
|
+
|
|
267
|
+
const seedId = (
|
|
268
|
+
await RegTestWallet.fromSeed(new Array(12).join("abandon "))
|
|
269
|
+
).toDbString();
|
|
270
|
+
const w3 = await RegTestWallet.replaceNamed(name, seedId);
|
|
271
|
+
const w4 = await RegTestWallet.named(name);
|
|
272
|
+
|
|
273
|
+
const w5 = await RegTestWallet.replaceNamed(
|
|
274
|
+
`${name}_nonexistent`,
|
|
275
|
+
seedId
|
|
276
|
+
);
|
|
277
|
+
const w6 = await RegTestWallet.named(`${name}_nonexistent`);
|
|
278
|
+
|
|
279
|
+
return {
|
|
280
|
+
check1,
|
|
281
|
+
check2,
|
|
282
|
+
w1: w1.toDbString(),
|
|
283
|
+
w4: w4.toDbString(),
|
|
284
|
+
w5: w5.toDbString(),
|
|
285
|
+
w6: w6.toDbString(),
|
|
286
|
+
seedId,
|
|
287
|
+
};
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
expect(result.check1).toBe(false);
|
|
291
|
+
expect(result.check2).toBe(true);
|
|
292
|
+
expect(result.w4).not.toBe(result.w1);
|
|
293
|
+
expect(result.w4).toBe(result.seedId);
|
|
294
|
+
expect(result.w6).toBe(result.w5);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
test("Test waiting and watching", async () => {
|
|
298
|
+
await page.evaluate(async (ALICE_ID) => {
|
|
299
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
300
|
+
const alice = await RegTestWallet.fromId(ALICE_ID);
|
|
301
|
+
|
|
302
|
+
const bob = await RegTestWallet.newRandom();
|
|
303
|
+
|
|
304
|
+
let waitTxResult = false;
|
|
305
|
+
setTimeout(async () => {
|
|
306
|
+
const result = await alice.waitForTransaction({
|
|
307
|
+
getBalance: true,
|
|
308
|
+
getTransactionInfo: true,
|
|
309
|
+
});
|
|
310
|
+
expect(result.balance.sat).toBeGreaterThan(0);
|
|
311
|
+
expect(result.transactionInfo.hash.length).toBe(64);
|
|
312
|
+
waitTxResult = true;
|
|
313
|
+
}, 0);
|
|
314
|
+
|
|
315
|
+
let waitBalanceResult = false;
|
|
316
|
+
setTimeout(async () => {
|
|
317
|
+
const result = await alice.waitForBalance(0.001, "bch");
|
|
318
|
+
expect(result.sat).toBeGreaterThan(0);
|
|
319
|
+
waitBalanceResult = true;
|
|
320
|
+
}, 0);
|
|
321
|
+
|
|
322
|
+
// let aliceWatchResult = false;
|
|
323
|
+
// const aliceWatchCancel = alice.watchAddressTransactions((_tx) => {
|
|
324
|
+
// aliceWatchCancel();
|
|
325
|
+
// aliceWatchResult = true;
|
|
326
|
+
// });
|
|
327
|
+
|
|
328
|
+
// let bobWatchResult = false;
|
|
329
|
+
// const bobWatchCancel = bob.watchAddress((_txHash) => {
|
|
330
|
+
// bobWatchCancel();
|
|
331
|
+
// bobWatchResult = true;
|
|
332
|
+
// });
|
|
333
|
+
|
|
334
|
+
let bobBalanceWatchResult = false;
|
|
335
|
+
const bobBalanceWatchCancel = bob.watchBalance((balance) => {
|
|
336
|
+
expect(balance.bch).toBe(0.001);
|
|
337
|
+
bobBalanceWatchCancel();
|
|
338
|
+
bobBalanceWatchResult = true;
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
// let blockWatchResult = false;
|
|
342
|
+
// const blockWatchCancel = bob.watchBlocks((block) => {
|
|
343
|
+
// expect(block.height).toBeGreaterThan(1);
|
|
344
|
+
// blockWatchCancel();
|
|
345
|
+
// blockWatchResult = true;
|
|
346
|
+
// });
|
|
347
|
+
|
|
348
|
+
// let blockWaitResult = false;
|
|
349
|
+
// setTimeout(async () => {
|
|
350
|
+
// const blockNumber = await (
|
|
351
|
+
// alice.provider
|
|
352
|
+
// ).getBlockHeight();
|
|
353
|
+
// const result = await alice.waitForBlock();
|
|
354
|
+
// expect(result.height).toBe(blockNumber + 1);
|
|
355
|
+
// blockWaitResult = true;
|
|
356
|
+
// }, 0);
|
|
357
|
+
|
|
358
|
+
// let blockNumberWaitResult = false;
|
|
359
|
+
// setTimeout(async () => {
|
|
360
|
+
// const blockNumber = await (
|
|
361
|
+
// alice.provider
|
|
362
|
+
// ).getBlockHeight();
|
|
363
|
+
// const result = await alice.waitForBlock(blockNumber + 2);
|
|
364
|
+
// expect(result.height).toBe(blockNumber + 2);
|
|
365
|
+
// blockNumberWaitResult = true;
|
|
366
|
+
// }, 0);
|
|
367
|
+
|
|
368
|
+
await alice.send({
|
|
369
|
+
cashaddr: bob.getDepositAddress(),
|
|
370
|
+
value: 0.001,
|
|
371
|
+
unit: "bch",
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
//! mining not supported in browser
|
|
375
|
+
// await mine({ cashaddr: alice.cashaddr, blocks: 1 });
|
|
376
|
+
// await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
377
|
+
// await mine({ cashaddr: alice.cashaddr, blocks: 1 });
|
|
378
|
+
|
|
379
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
380
|
+
expect(waitTxResult).toBe(true);
|
|
381
|
+
expect(waitBalanceResult).toBe(true);
|
|
382
|
+
// expect(aliceWatchResult).toBe(true);
|
|
383
|
+
// expect(bobWatchResult).toBe(true);
|
|
384
|
+
expect(bobBalanceWatchResult).toBe(true);
|
|
385
|
+
// expect(blockWatchResult).toBe(true);
|
|
386
|
+
// expect(blockWaitResult).toBe(true);
|
|
387
|
+
// expect(blockNumberWaitResult).toBe(true);
|
|
388
|
+
}, process.env.ALICE_ID);
|
|
389
|
+
});
|
|
390
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const playwright = require("playwright");
|
|
2
|
+
const PAGE_URL = "http://localhost:8080/indexeddb-storage/index.html";
|
|
3
|
+
|
|
4
|
+
describe(`WalletDatabase should handle indexeddb `, () => {
|
|
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
|
+
if (!page) {
|
|
15
|
+
throw new Error("Connection wasn't established");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Open the page
|
|
19
|
+
await page.goto(PAGE_URL, {
|
|
20
|
+
waitUntil: "networkidle0",
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterAll(async () => {
|
|
25
|
+
await browser.close();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test(`Should store and recall a testnet wallet`, async () => {
|
|
29
|
+
const result = await page.evaluate(async () => {
|
|
30
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
31
|
+
let w1 = await TestNetWallet.newRandom("Testnet Wallet 1");
|
|
32
|
+
let w1Again = await TestNetWallet.named("Testnet Wallet 1");
|
|
33
|
+
return [w1, w1Again];
|
|
34
|
+
});
|
|
35
|
+
let w1 = result[0];
|
|
36
|
+
let w2 = result[1];
|
|
37
|
+
expect(w1.name).toBe("Testnet Wallet 1");
|
|
38
|
+
expect(w1.cashaddr.slice(0, 9)).toBe("bchtest:q");
|
|
39
|
+
expect(w1.privateKeyWif.startsWith("c")).toBeTruthy();
|
|
40
|
+
expect(w1.network).toBe("testnet");
|
|
41
|
+
expect(w1.name).toBe(w2.name);
|
|
42
|
+
expect(w1.privateKeyWif).toBe(w2.privateKeyWif);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test(`Should store and recall a mainnet wallet`, async () => {
|
|
46
|
+
const result = await page.evaluate(async () => {
|
|
47
|
+
BaseWallet.StorageProvider = IndexedDBProvider;
|
|
48
|
+
let w1 = await Wallet.named("Mainnet Wallet 1");
|
|
49
|
+
let w1Again = await Wallet.named("Mainnet Wallet 1");
|
|
50
|
+
return [w1, w1Again];
|
|
51
|
+
});
|
|
52
|
+
let w1 = result[0];
|
|
53
|
+
let w2 = result[1];
|
|
54
|
+
expect(w1.name.startsWith("Mainnet Wallet 1")).toBeTruthy();
|
|
55
|
+
expect(w1.cashaddr.startsWith("bitcoincash:q")).toBeTruthy();
|
|
56
|
+
expect(w1.network).toBe("mainnet");
|
|
57
|
+
expect(
|
|
58
|
+
w1.privateKeyWif[0] == "K" || w1.privateKeyWif[0] == "L"
|
|
59
|
+
).toBeTruthy();
|
|
60
|
+
|
|
61
|
+
expect(w1.name).toBe(w2.name);
|
|
62
|
+
expect(w1.privateKeyWif).toBe(w2.privateKeyWif);
|
|
63
|
+
});
|
|
64
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as IndexedDBProvider } from "./IndexedDBProvider.js";
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"rootDir": "src",
|
|
5
|
+
"skipLibCheck": true,
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"allowSyntheticDefaultImports": true,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"downlevelIteration": true,
|
|
11
|
+
"composite": true,
|
|
12
|
+
"module": "esnext",
|
|
13
|
+
"target": "esnext",
|
|
14
|
+
"outDir": "./dist/module",
|
|
15
|
+
"moduleResolution": "node",
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"lib": ["es2020", "es2020.bigint", "dom"],
|
|
18
|
+
"typeRoots": ["node_modules/@types", "./src/types"]
|
|
19
|
+
},
|
|
20
|
+
"include": ["src/**/*.ts"],
|
|
21
|
+
"exclude": ["node_modules/**", "src/**/*test.ts"],
|
|
22
|
+
"references": [
|
|
23
|
+
{
|
|
24
|
+
"path": "../mainnet-js/"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"compileOnSave": false
|
|
28
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
const { merge } = require("webpack-merge");
|
|
2
|
+
const packageJson = require("./package.json");
|
|
3
|
+
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
4
|
+
const { webpack } = require("webpack");
|
|
5
|
+
const InjectBodyPlugin = require("inject-body-webpack-plugin").default;
|
|
6
|
+
const __basedir = require("path").resolve(__dirname, "../../");
|
|
7
|
+
const fs = require("fs");
|
|
8
|
+
|
|
9
|
+
fs.mkdirSync(__basedir + "/jest/playwright/indexeddb-storage", {
|
|
10
|
+
recursive: true,
|
|
11
|
+
});
|
|
12
|
+
fs.copyFileSync(
|
|
13
|
+
__basedir + "/jest/playwright/mainnet.js",
|
|
14
|
+
__basedir + "/jest/playwright/indexeddb-storage/mainnet.js"
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const baseConfig = {
|
|
18
|
+
mode: "development",
|
|
19
|
+
module: {
|
|
20
|
+
rules: [
|
|
21
|
+
{
|
|
22
|
+
test: /\.tsx?$/,
|
|
23
|
+
use: [
|
|
24
|
+
{
|
|
25
|
+
loader: "ts-loader",
|
|
26
|
+
options: {
|
|
27
|
+
configFile: "tsconfig.browser.json",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
exclude: [/node_modules/],
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
resolve: {
|
|
36
|
+
extensions: [".ts", ".tsx", ".js", ".wasm"],
|
|
37
|
+
extensionAlias: {
|
|
38
|
+
".js": [".ts", ".js"],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
optimization: {
|
|
42
|
+
minimize: false,
|
|
43
|
+
mangleWasmImports: true,
|
|
44
|
+
usedExports: true,
|
|
45
|
+
},
|
|
46
|
+
experiments: { topLevelAwait: true },
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const prodConfig = {
|
|
50
|
+
mode: "production",
|
|
51
|
+
optimization: {
|
|
52
|
+
minimize: true,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const browserConfig = {
|
|
57
|
+
target: "web",
|
|
58
|
+
entry: {
|
|
59
|
+
"indexeddb-storage": {
|
|
60
|
+
import: "./src/index.ts",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
output: {
|
|
64
|
+
filename: `[name]-${packageJson.version}.js`,
|
|
65
|
+
path: __dirname + "/dist",
|
|
66
|
+
crossOriginLoading: "anonymous",
|
|
67
|
+
libraryTarget: "umd",
|
|
68
|
+
},
|
|
69
|
+
plugins: [
|
|
70
|
+
//new BundleAnalyzerPlugin(),
|
|
71
|
+
new HtmlWebpackPlugin({
|
|
72
|
+
title: "The Empty Mainnet App",
|
|
73
|
+
}),
|
|
74
|
+
new InjectBodyPlugin({
|
|
75
|
+
content: `<script defer src="mainnet.js"></script><script>document.addEventListener("DOMContentLoaded", async (event) => Object.assign(globalThis, await __mainnetPromise))</script>`,
|
|
76
|
+
}),
|
|
77
|
+
],
|
|
78
|
+
resolve: {
|
|
79
|
+
alias: {},
|
|
80
|
+
fallback: {},
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const browserTestDiff = {
|
|
85
|
+
output: {
|
|
86
|
+
filename: "[name].js",
|
|
87
|
+
path: __basedir + "/jest/playwright/indexeddb-storage/",
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const browserTestConfig = merge(browserConfig, browserTestDiff);
|
|
92
|
+
|
|
93
|
+
let config = baseConfig;
|
|
94
|
+
|
|
95
|
+
if (process.env.NODE_ENV == "production") {
|
|
96
|
+
console.log("Running webpack in production mode");
|
|
97
|
+
config = merge(baseConfig, prodConfig);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Join configurations with the base configuration
|
|
101
|
+
module.exports = [browserConfig, browserTestConfig].map((c) =>
|
|
102
|
+
merge(config, c)
|
|
103
|
+
);
|