mainnet-js 2.1.1 → 2.2.0

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 (37) hide show
  1. package/dist/index.html +1 -1
  2. package/dist/{mainnet-2.1.1.js → mainnet-2.2.0.js} +14 -304
  3. package/dist/module/index.d.ts +2 -2
  4. package/dist/module/index.d.ts.map +1 -1
  5. package/dist/module/index.js +2 -2
  6. package/dist/module/index.js.map +1 -1
  7. package/dist/module/rate/ExchangeRate.d.ts +0 -2
  8. package/dist/module/rate/ExchangeRate.d.ts.map +1 -1
  9. package/dist/module/rate/ExchangeRate.js +6 -38
  10. package/dist/module/rate/ExchangeRate.js.map +1 -1
  11. package/dist/module/test/fetch.d.ts +3 -0
  12. package/dist/module/test/fetch.d.ts.map +1 -0
  13. package/dist/module/test/fetch.js +24 -0
  14. package/dist/module/test/fetch.js.map +1 -0
  15. package/dist/module/wallet/Bcmr.d.ts.map +1 -1
  16. package/dist/module/wallet/Bcmr.js +22 -24
  17. package/dist/module/wallet/Bcmr.js.map +1 -1
  18. package/dist/module/wallet/Wif.d.ts +0 -2
  19. package/dist/module/wallet/Wif.d.ts.map +1 -1
  20. package/dist/module/wallet/Wif.js +0 -27
  21. package/dist/module/wallet/Wif.js.map +1 -1
  22. package/dist/tsconfig.tsbuildinfo +1 -1
  23. package/package.json +1 -2
  24. package/src/index.ts +2 -2
  25. package/src/rate/ExchangeRate.test.ts +8 -10
  26. package/src/rate/ExchangeRate.ts +6 -51
  27. package/src/test/fetch.ts +30 -0
  28. package/src/wallet/Bcmr.test.headless.js +12 -12
  29. package/src/wallet/Bcmr.test.ts +17 -17
  30. package/src/wallet/Bcmr.ts +19 -24
  31. package/src/wallet/Wif.test.ts +0 -12
  32. package/src/wallet/Wif.ts +0 -32
  33. package/dist/module/test/axios.d.ts +0 -3
  34. package/dist/module/test/axios.d.ts.map +0 -1
  35. package/dist/module/test/axios.js +0 -35
  36. package/dist/module/test/axios.js.map +0 -1
  37. package/src/test/axios.ts +0 -47
@@ -1,3 +1,4 @@
1
+ import { removeFetchMock, setupFetchMock } from "../test/fetch";
1
2
  import { BalanceResponse } from "../util/balanceObjectFromSatoshi";
2
3
  import { RegTestWallet } from "../wallet/Wif";
3
4
  import { ExchangeRate } from "./ExchangeRate";
@@ -13,23 +14,20 @@ afterAll(async () => {
13
14
 
14
15
  describe("Exchange rate tests", () => {
15
16
  test("Get price in usd", async () => {
16
- ExchangeRate.setupAxiosMock(
17
+ setupFetchMock(
17
18
  "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin-cash&vs_currencies=usd",
18
19
  { "bitcoin-cash": { usd: 666.666 } }
19
20
  );
20
- ExchangeRate.setupAxiosMock(
21
- "https://markets.api.bitcoin.com/live/bitcoin",
22
- {
23
- BCH: 666.666,
24
- }
25
- );
21
+ setupFetchMock("https://markets.api.bitcoin.com/live/bitcoin", {
22
+ BCH: 666.666,
23
+ });
26
24
 
27
25
  let rate = await ExchangeRate.get("usd");
28
26
  expect(rate).toBe(666.666);
29
27
  });
30
28
 
31
29
  test("Test watchBalanceUsd", async () => {
32
- ExchangeRate.setupAxiosMock(
30
+ setupFetchMock(
33
31
  "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin-cash&vs_currencies=usd",
34
32
  { "bitcoin-cash": { usd: 666.666 } }
35
33
  );
@@ -45,7 +43,7 @@ describe("Exchange rate tests", () => {
45
43
  }
46
44
  }, 3000);
47
45
 
48
- ExchangeRate.setupAxiosMock(
46
+ setupFetchMock(
49
47
  "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin-cash&vs_currencies=usd",
50
48
  { "bitcoin-cash": { usd: 777.777 } }
51
49
  );
@@ -60,7 +58,7 @@ describe("Exchange rate tests", () => {
60
58
 
61
59
  await delay(3000);
62
60
 
63
- ExchangeRate.removeAxiosMock(
61
+ removeFetchMock(
64
62
  "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin-cash&vs_currencies=usd"
65
63
  );
66
64
  expect(cbCounter).toBe(2);
@@ -4,7 +4,6 @@ import {
4
4
  getRuntimePlatform,
5
5
  } from "../util/getRuntimePlatform.js";
6
6
  import ExchangeRateProvider from "../db/ExchangeRateProvider.js";
7
- import axios from "axios";
8
7
 
9
8
  export class ExchangeRate {
10
9
  symbol: string;
@@ -24,52 +23,6 @@ export class ExchangeRate {
24
23
  this.ttl = ttl;
25
24
  }
26
25
 
27
- static setupAxiosMock(mockUrl, responseData) {
28
- if (!(axios.interceptors as any).mocks) {
29
- (axios.interceptors as any).mocks = {};
30
-
31
- // install our interceptors
32
- (axios.interceptors as any).request.use((config) => {
33
- const url = config.url!;
34
-
35
- if ((axios.interceptors as any).mocks[url]) {
36
- // if we have set up a mocked response for this url, cancel the actual request with a cancelToken containing our mocked data
37
- const mockedResponse = (axios.interceptors as any).mocks[url];
38
- return {
39
- ...config,
40
- cancelToken: new axios.CancelToken((cancel) =>
41
- cancel({ status: 200, data: mockedResponse } as any)
42
- ),
43
- };
44
- }
45
-
46
- // otherwise proceed with usual request
47
- return config;
48
- });
49
-
50
- (axios.interceptors as any).response.use(
51
- function (response) {
52
- return response;
53
- },
54
- function (error: any) {
55
- // resolve response with our mocked data
56
- if (axios.isCancel(error)) {
57
- return Promise.resolve(error.message);
58
- }
59
-
60
- // handle all other errors gracefully
61
- return Promise.reject(error);
62
- }
63
- );
64
- }
65
-
66
- (axios.interceptors as any).mocks[mockUrl] = responseData;
67
- }
68
-
69
- static removeAxiosMock(mockUrl) {
70
- delete ((axios.interceptors as any).mocks || {})[mockUrl];
71
- }
72
-
73
26
  toString() {
74
27
  this.rate.toFixed(2);
75
28
  }
@@ -154,16 +107,18 @@ export async function getRateFromExchange(symbol: string): Promise<number> {
154
107
  switch (symbol) {
155
108
  case "usd":
156
109
  try {
157
- let response = await axios.get(
110
+ const response = await fetch(
158
111
  "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin-cash&vs_currencies=usd"
159
112
  );
160
- return response.data["bitcoin-cash"].usd;
113
+ const data = await response.json();
114
+ return data["bitcoin-cash"].usd;
161
115
  } catch (e1) {
162
116
  try {
163
- let response = await axios.get(
117
+ const response = await fetch(
164
118
  "https://markets.api.bitcoin.com/live/bitcoin"
165
119
  );
166
- return response.data["data"]["BCH"];
120
+ const data = await response.json();
121
+ return data["data"]["BCH"];
167
122
  } catch (e2: any) {
168
123
  return e2;
169
124
  }
@@ -0,0 +1,30 @@
1
+ const map = {};
2
+
3
+ const _fetch = globalThis.fetch;
4
+
5
+ globalThis.fetch = ((uri: any, ...rest: any) => {
6
+ if (!map[uri]) {
7
+ return _fetch(uri, ...rest);
8
+ }
9
+
10
+ return new Promise((resolve) =>
11
+ resolve({
12
+ json: () => {
13
+ return typeof map[uri] === "string" ? JSON.parse(map[uri]) : map[uri];
14
+ },
15
+ text: () => {
16
+ return typeof map[uri] === "string"
17
+ ? map[uri]
18
+ : JSON.stringify(map[uri], null, 2);
19
+ },
20
+ })
21
+ );
22
+ }) as any;
23
+
24
+ export function setupFetchMock(mockUrl, responseData) {
25
+ map[mockUrl] = responseData;
26
+ }
27
+
28
+ export function removeFetchMock(mockUrl) {
29
+ delete map[mockUrl];
30
+ }
@@ -102,7 +102,7 @@ describe(`Wallet should function in the browser`, () => {
102
102
  async ([id, registry]) => {
103
103
  BCMR.resetRegistries();
104
104
 
105
- setupAxiosMock(
105
+ setupFetchMock(
106
106
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry.json",
107
107
  registry
108
108
  );
@@ -128,7 +128,7 @@ describe(`Wallet should function in the browser`, () => {
128
128
  );
129
129
  expect(BCMR.metadataRegistries.length).toBe(1);
130
130
 
131
- removeAxiosMock(
131
+ removeFetchMock(
132
132
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry.json"
133
133
  );
134
134
  },
@@ -163,7 +163,7 @@ describe(`Wallet should function in the browser`, () => {
163
163
  opreturnData,
164
164
  ]);
165
165
 
166
- setupAxiosMock(
166
+ setupFetchMock(
167
167
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry.json",
168
168
  registry
169
169
  );
@@ -198,7 +198,7 @@ describe(`Wallet should function in the browser`, () => {
198
198
  expect(otherChain.length).toBe(1);
199
199
  expect(BCMR.metadataRegistries.length).toBe(1);
200
200
 
201
- removeAxiosMock(
201
+ removeFetchMock(
202
202
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry.json"
203
203
  );
204
204
  },
@@ -219,7 +219,7 @@ describe(`Wallet should function in the browser`, () => {
219
219
  const contentHash_v1 = sha256.hash(
220
220
  utf8ToBin(JSON.stringify(registry_v1, null, 2))
221
221
  );
222
- setupAxiosMock(
222
+ setupFetchMock(
223
223
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v1.json",
224
224
  JSON.stringify(registry_v1, null, 2)
225
225
  );
@@ -245,7 +245,7 @@ describe(`Wallet should function in the browser`, () => {
245
245
  const contentHash_v2 = sha256.hash(
246
246
  utf8ToBin(JSON.stringify(registry_v2, null, 2))
247
247
  );
248
- setupAxiosMock(
248
+ setupFetchMock(
249
249
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v2.json",
250
250
  JSON.stringify(registry_v2, null, 2)
251
251
  );
@@ -270,7 +270,7 @@ describe(`Wallet should function in the browser`, () => {
270
270
  const contentHash_v3 = sha256.hash(
271
271
  utf8ToBin(JSON.stringify(registry_v3, null, 2))
272
272
  );
273
- setupAxiosMock(
273
+ setupFetchMock(
274
274
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v3.json",
275
275
  JSON.stringify(registry_v3, null, 2)
276
276
  );
@@ -290,7 +290,7 @@ describe(`Wallet should function in the browser`, () => {
290
290
  const contentHash_v4 = sha256.hash(
291
291
  utf8ToBin(JSON.stringify(registry_v4, null, 2))
292
292
  );
293
- setupAxiosMock(
293
+ setupFetchMock(
294
294
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v4.json",
295
295
  JSON.stringify(registry_v4, null, 2)
296
296
  );
@@ -376,16 +376,16 @@ describe(`Wallet should function in the browser`, () => {
376
376
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v4.json"
377
377
  );
378
378
 
379
- removeAxiosMock(
379
+ removeFetchMock(
380
380
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v1.json"
381
381
  );
382
- removeAxiosMock(
382
+ removeFetchMock(
383
383
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v2.json"
384
384
  );
385
- removeAxiosMock(
385
+ removeFetchMock(
386
386
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v3.json"
387
387
  );
388
- removeAxiosMock(
388
+ removeFetchMock(
389
389
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v4.json"
390
390
  );
391
391
  },
@@ -1,5 +1,5 @@
1
+ import { setupFetchMock, removeFetchMock } from "../test/fetch.js";
1
2
  import { disconnectProviders, initProviders } from "../network/Connection.js";
2
- import { setupAxiosMock, removeAxiosMock } from "../test/axios.js";
3
3
  import { AuthChain, BCMR } from "./Bcmr.js";
4
4
  import { Registry } from "./bcmr-v2.schema.js";
5
5
  import { RegTestWallet, Wallet } from "./Wif";
@@ -104,7 +104,7 @@ describe(`Test BCMR support`, () => {
104
104
  });
105
105
 
106
106
  test("Add metadata from uri and get token info", async () => {
107
- setupAxiosMock(
107
+ setupFetchMock(
108
108
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry.json",
109
109
  registry
110
110
  );
@@ -130,13 +130,13 @@ describe(`Test BCMR support`, () => {
130
130
  );
131
131
  expect(BCMR.metadataRegistries.length).toBe(1);
132
132
 
133
- removeAxiosMock(
133
+ removeFetchMock(
134
134
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry.json"
135
135
  );
136
136
  });
137
137
 
138
138
  test("Add metadata from uri with contenthash and get token info", async () => {
139
- setupAxiosMock(
139
+ setupFetchMock(
140
140
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry.json",
141
141
  registryContent
142
142
  );
@@ -162,7 +162,7 @@ describe(`Test BCMR support`, () => {
162
162
  expect(tokenInfo?.token?.symbol).toBe("TOK");
163
163
  expect(tokenInfo?.token?.decimals).toBe(8);
164
164
 
165
- removeAxiosMock(
165
+ removeFetchMock(
166
166
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry.json"
167
167
  );
168
168
  });
@@ -413,7 +413,7 @@ describe(`Test BCMR support`, () => {
413
413
  opreturnData,
414
414
  ]);
415
415
 
416
- setupAxiosMock(
416
+ setupFetchMock(
417
417
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry.json",
418
418
  registry
419
419
  );
@@ -451,7 +451,7 @@ describe(`Test BCMR support`, () => {
451
451
  expect(otherChain.length).toBe(1);
452
452
  expect(BCMR.metadataRegistries.length).toBe(1);
453
453
 
454
- removeAxiosMock(
454
+ removeFetchMock(
455
455
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry.json"
456
456
  );
457
457
  });
@@ -590,7 +590,7 @@ describe(`Test BCMR support`, () => {
590
590
  const contentHash_v1 = sha256.hash(
591
591
  utf8ToBin(JSON.stringify(registry_v1, null, 2))
592
592
  );
593
- setupAxiosMock(
593
+ setupFetchMock(
594
594
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v1.json",
595
595
  JSON.stringify(registry_v1, null, 2)
596
596
  );
@@ -612,7 +612,7 @@ describe(`Test BCMR support`, () => {
612
612
  const contentHash_v2 = sha256.hash(
613
613
  utf8ToBin(JSON.stringify(registry_v2, null, 2))
614
614
  );
615
- setupAxiosMock(
615
+ setupFetchMock(
616
616
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v2.json",
617
617
  JSON.stringify(registry_v2, null, 2)
618
618
  );
@@ -637,7 +637,7 @@ describe(`Test BCMR support`, () => {
637
637
  const contentHash_v3 = sha256.hash(
638
638
  utf8ToBin(JSON.stringify(registry_v3, null, 2))
639
639
  );
640
- setupAxiosMock(
640
+ setupFetchMock(
641
641
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v3.json",
642
642
  JSON.stringify(registry_v3, null, 2)
643
643
  );
@@ -657,7 +657,7 @@ describe(`Test BCMR support`, () => {
657
657
  const contentHash_v4 = sha256.hash(
658
658
  utf8ToBin(JSON.stringify(registry_v4, null, 2))
659
659
  );
660
- setupAxiosMock(
660
+ setupFetchMock(
661
661
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v4.json",
662
662
  JSON.stringify(registry_v4, null, 2)
663
663
  );
@@ -743,16 +743,16 @@ describe(`Test BCMR support`, () => {
743
743
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v4.json"
744
744
  );
745
745
 
746
- removeAxiosMock(
746
+ removeFetchMock(
747
747
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v1.json"
748
748
  );
749
- removeAxiosMock(
749
+ removeFetchMock(
750
750
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v2.json"
751
751
  );
752
- removeAxiosMock(
752
+ removeFetchMock(
753
753
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v3.json"
754
754
  );
755
- removeAxiosMock(
755
+ removeFetchMock(
756
756
  "https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v4.json"
757
757
  );
758
758
  });
@@ -888,7 +888,7 @@ describe(`Test BCMR support`, () => {
888
888
  });
889
889
 
890
890
  test("Test fetching BCMR authchain from chaingraph", async () => {
891
- setupAxiosMock("https://gql.mainnet.cash/v1/graphql", {
891
+ setupFetchMock("https://gql.mainnet.cash/v1/graphql", {
892
892
  data: {
893
893
  transaction: [
894
894
  {
@@ -974,6 +974,6 @@ describe(`Test BCMR support`, () => {
974
974
  expect(result.at(-1)?.uris[0]).toBe(
975
975
  "ipfs.pat.mn/ipfs/QmS9hzxjnB9AhAoFXKSbk7jEMrU5Ew9vSrmnbJY45UY2Vz"
976
976
  );
977
- removeAxiosMock("https://gql.mainnet.cash/v1/graphql");
977
+ removeFetchMock("https://gql.mainnet.cash/v1/graphql");
978
978
  });
979
979
  });
@@ -7,7 +7,6 @@ import {
7
7
  Transaction,
8
8
  utf8ToBin,
9
9
  } from "@bitauth/libauth";
10
- import axios from "axios";
11
10
  import { Network, TxI } from "../interface.js";
12
11
  import ElectrumNetworkProvider from "../network/ElectrumNetworkProvider.js";
13
12
  import { ElectrumRawTransaction } from "../network/interface.js";
@@ -58,25 +57,22 @@ export class BCMR {
58
57
  // content hashes HTTPS Publication Outputs per spec
59
58
  if (contentHash) {
60
59
  // request as text and verify hash
61
- const response = await axios.get(uri, {
62
- responseType: "text",
63
- transformResponse: (val) => {
64
- return val;
65
- },
66
- });
67
- const hash = binToHex(sha256.hash(utf8ToBin(response.data as string)));
60
+ const response = await fetch(uri);
61
+ const data = await response.text();
62
+ const hash = binToHex(sha256.hash(utf8ToBin(data)));
68
63
  if (contentHash != hash) {
69
64
  throw new Error(
70
65
  `Content hash mismatch for URI: ${uri}\nreceived: ${hash}\nrequired: ${contentHash}`
71
66
  );
72
67
  }
73
68
 
74
- return JSON.parse(response.data) as Registry;
69
+ return JSON.parse(data) as Registry;
75
70
  }
76
71
 
77
72
  // request as JSON
78
- const response = await axios.get(uri);
79
- return response.data as Registry;
73
+ const response = await fetch(uri);
74
+ const data = await response.json();
75
+ return data as Registry;
80
76
  }
81
77
 
82
78
  /**
@@ -417,9 +413,13 @@ export class BCMR {
417
413
  throw new Error("Provide `chaingraphUrl` param.");
418
414
  }
419
415
 
420
- const response = await axios.post(
421
- options.chaingraphUrl,
422
- {
416
+ const response = await fetch(options.chaingraphUrl, {
417
+ method: "POST",
418
+ headers: {
419
+ Accept: "*/*",
420
+ "Content-Type": "application/json",
421
+ },
422
+ body: JSON.stringify({
423
423
  operationName: null,
424
424
  variables: {},
425
425
  query: `
@@ -458,19 +458,14 @@ export class BCMR {
458
458
  }
459
459
  }
460
460
  }`,
461
- },
462
- {
463
- responseType: "json",
464
- headers: {
465
- Accept: "*/*",
466
- "Content-Type": "application/json",
467
- },
468
- }
469
- );
461
+ }),
462
+ });
463
+
464
+ const responseData = await response.json();
470
465
 
471
466
  const result: AuthChain = [];
472
467
  const migrations =
473
- response.data.data.transaction[0]?.authchains[0].migrations;
468
+ responseData.data.transaction[0]?.authchains[0].migrations;
474
469
  if (!migrations) {
475
470
  return result;
476
471
  }
@@ -852,18 +852,6 @@ describe(`Wallet subscriptions`, () => {
852
852
  expect(blockWaitResult).toBe(true);
853
853
  expect(blockNumberWaitResult).toBe(true);
854
854
  });
855
-
856
- test.skip("Should get testnet satoshis and send them back", async () => {
857
- const wallet = (await TestNetWallet.newRandom()) as TestNetWallet;
858
- const txid = await wallet.getTestnetSatoshis();
859
- expect(txid.length).toBe(64);
860
- const balance = await wallet.getBalance("sat");
861
- expect(balance).toBe(10000);
862
-
863
- const response = await wallet.returnTestnetSatoshis();
864
- delay(3000);
865
- expect(response.balance!.sat!).toBe(0);
866
- });
867
855
  });
868
856
 
869
857
  describe(`Wallet extrema behavior regression testing`, () => {
package/src/wallet/Wif.ts CHANGED
@@ -77,7 +77,6 @@ import { sumTokenAmounts, sumUtxoValue } from "../util/sumUtxoValue.js";
77
77
  import { sumSendRequestAmounts } from "../util/sumSendRequestAmounts.js";
78
78
  import { ElectrumRawTransaction } from "../network/interface.js";
79
79
  import { getRelayFeeCache } from "../network/getRelayFeeCache.js";
80
- import axios from "axios";
81
80
  import {
82
81
  RegTestUtil,
83
82
  RegTestWatchUtil,
@@ -1759,37 +1758,6 @@ export class TestNetWallet extends Wallet {
1759
1758
  super(name, NetworkType.Testnet);
1760
1759
  }
1761
1760
 
1762
- // will receive 10000 testnet satoshi, rate limits apply
1763
- async getTestnetSatoshis(): Promise<string> {
1764
- try {
1765
- const response = await axios.post(
1766
- `${TestNetWallet.faucetServer}/faucet/get_testnet_bch`,
1767
- { cashaddr: this.cashaddr! }
1768
- );
1769
- const data = response.data;
1770
- return data.txId;
1771
- } catch (e) {
1772
- // console.log(e);
1773
- // console.log(e.response ? e.response.data : "");
1774
- throw e;
1775
- }
1776
- }
1777
-
1778
- // be nice and return them back
1779
- async returnTestnetSatoshis(): Promise<SendResponse> {
1780
- try {
1781
- const response = await axios.post(
1782
- `${TestNetWallet.faucetServer}/faucet/get_addresses`
1783
- );
1784
- const data = response.data;
1785
- return await this.sendMax(data.bchtest);
1786
- } catch (e: any) {
1787
- console.log(e);
1788
- console.log(e.response ? e.response.data : "");
1789
- throw e;
1790
- }
1791
- }
1792
-
1793
1761
  // interface to static util functions. see Util.ts
1794
1762
  public static get util() {
1795
1763
  return TestNetUtil;
@@ -1,3 +0,0 @@
1
- export declare function setupAxiosMock(mockUrl: any, responseData: any): void;
2
- export declare function removeAxiosMock(mockUrl: any): void;
3
- //# sourceMappingURL=axios.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"axios.d.ts","sourceRoot":"","sources":["../../../src/test/axios.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,CAAC,OAAO,KAAA,EAAE,YAAY,KAAA,QAwCnD;AAED,wBAAgB,eAAe,CAAC,OAAO,KAAA,QAEtC"}
@@ -1,35 +0,0 @@
1
- import axios from "axios";
2
- export function setupAxiosMock(mockUrl, responseData) {
3
- if (!axios.interceptors.mocks) {
4
- axios.interceptors.mocks = {};
5
- // install our interceptors
6
- axios.interceptors.request.use((config) => {
7
- const url = config.url;
8
- if (axios.interceptors.mocks[url]) {
9
- // if we have set up a mocked response for this url, cancel the actual request with a cancelToken containing our mocked data
10
- const mockedResponse = axios.interceptors.mocks[url];
11
- return {
12
- ...config,
13
- cancelToken: new axios.CancelToken((cancel) => cancel({ status: 200, data: mockedResponse })),
14
- };
15
- }
16
- // otherwise proceed with usual request
17
- return config;
18
- });
19
- axios.interceptors.response.use(function (response) {
20
- return response;
21
- }, function (error) {
22
- // resolve response with our mocked data
23
- if (axios.isCancel(error)) {
24
- return Promise.resolve(error.message);
25
- }
26
- // handle all other errors gracefully
27
- return Promise.reject(error);
28
- });
29
- }
30
- axios.interceptors.mocks[mockUrl] = responseData;
31
- }
32
- export function removeAxiosMock(mockUrl) {
33
- delete (axios.interceptors.mocks || {})[mockUrl];
34
- }
35
- //# sourceMappingURL=axios.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"axios.js","sourceRoot":"","sources":["../../../src/test/axios.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,UAAU,cAAc,CAAC,OAAO,EAAE,YAAY;IAClD,IAAI,CAAE,KAAK,CAAC,YAAoB,CAAC,KAAK,EAAE;QACrC,KAAK,CAAC,YAAoB,CAAC,KAAK,GAAG,EAAE,CAAC;QAEvC,2BAA2B;QAC1B,KAAK,CAAC,YAAoB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YACjD,MAAM,GAAG,GAAG,MAAM,CAAC,GAAI,CAAC;YAExB,IAAK,KAAK,CAAC,YAAoB,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;gBAC1C,4HAA4H;gBAC5H,MAAM,cAAc,GAAI,KAAK,CAAC,YAAoB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAC9D,OAAO;oBACL,GAAG,MAAM;oBACT,WAAW,EAAE,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC,MAAM,EAAE,EAAE,CAC5C,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,cAAc,EAAS,CAAC,CACrD;iBACF,CAAC;aACH;YAED,uCAAuC;YACvC,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CAAC;QAEF,KAAK,CAAC,YAAoB,CAAC,QAAQ,CAAC,GAAG,CACtC,UAAU,QAAQ;YAChB,OAAO,QAAQ,CAAC;QAClB,CAAC,EACD,UAAU,KAAU;YAClB,wCAAwC;YACxC,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;gBACzB,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;aACvC;YAED,qCAAqC;YACrC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/B,CAAC,CACF,CAAC;KACH;IAEA,KAAK,CAAC,YAAoB,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,OAAO;IACrC,OAAO,CAAE,KAAK,CAAC,YAAoB,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;AAC5D,CAAC"}
package/src/test/axios.ts DELETED
@@ -1,47 +0,0 @@
1
- import axios from "axios";
2
-
3
- export function setupAxiosMock(mockUrl, responseData) {
4
- if (!(axios.interceptors as any).mocks) {
5
- (axios.interceptors as any).mocks = {};
6
-
7
- // install our interceptors
8
- (axios.interceptors as any).request.use((config) => {
9
- const url = config.url!;
10
-
11
- if ((axios.interceptors as any).mocks[url]) {
12
- // if we have set up a mocked response for this url, cancel the actual request with a cancelToken containing our mocked data
13
- const mockedResponse = (axios.interceptors as any).mocks[url];
14
- return {
15
- ...config,
16
- cancelToken: new axios.CancelToken((cancel) =>
17
- cancel({ status: 200, data: mockedResponse } as any)
18
- ),
19
- };
20
- }
21
-
22
- // otherwise proceed with usual request
23
- return config;
24
- });
25
-
26
- (axios.interceptors as any).response.use(
27
- function (response) {
28
- return response;
29
- },
30
- function (error: any) {
31
- // resolve response with our mocked data
32
- if (axios.isCancel(error)) {
33
- return Promise.resolve(error.message);
34
- }
35
-
36
- // handle all other errors gracefully
37
- return Promise.reject(error);
38
- }
39
- );
40
- }
41
-
42
- (axios.interceptors as any).mocks[mockUrl] = responseData;
43
- }
44
-
45
- export function removeAxiosMock(mockUrl) {
46
- delete ((axios.interceptors as any).mocks || {})[mockUrl];
47
- }