mainnet-js 1.1.27 → 1.1.29

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.
@@ -2,55 +2,68 @@ import { BalanceResponse } from "../util/balanceObjectFromSatoshi";
2
2
  import { RegTestWallet } from "../wallet/Wif";
3
3
  import { ExchangeRate } from "./ExchangeRate";
4
4
  import { delay } from "../util/delay";
5
+ import { initProviders, disconnectProviders } from "../network";
5
6
 
6
- test("Get price in usd", async () => {
7
- ExchangeRate.setupAxiosMock(
8
- "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin-cash&vs_currencies=usd",
9
- { "bitcoin-cash": { usd: 666.666 } }
10
- );
11
- ExchangeRate.setupAxiosMock("https://markets.api.bitcoin.com/live/bitcoin", {
12
- BCH: 666.666,
13
- });
14
-
15
- let rate = await ExchangeRate.get("usd");
16
- expect(rate).toBe(666.666);
7
+ beforeAll(async () => {
8
+ await initProviders();
9
+ });
10
+ afterAll(async () => {
11
+ await disconnectProviders();
17
12
  });
18
13
 
19
- test("Test watchBalanceUsd", async () => {
20
- ExchangeRate.setupAxiosMock(
21
- "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin-cash&vs_currencies=usd",
22
- { "bitcoin-cash": { usd: 666.666 } }
23
- );
24
-
25
- const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
26
- const bob = await RegTestWallet.newRandom();
27
- const balance = (await alice.getBalance()) as BalanceResponse;
28
- let cbCounter = 0;
29
- const cancelWatchFn = alice.watchBalanceUsd(async (newBalance) => {
30
- cbCounter++;
31
- if (cbCounter === 1) {
32
- expect(newBalance.usd!).toBeGreaterThan(balance.usd!);
33
- }
34
- }, 3000);
35
-
36
- ExchangeRate.setupAxiosMock(
37
- "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin-cash&vs_currencies=usd",
38
- { "bitcoin-cash": { usd: 777.777 } }
39
- );
40
-
41
- await delay(3000);
42
-
43
- await alice.send({
44
- cashaddr: bob.getDepositAddress(),
45
- value: 10000,
46
- unit: "sat",
14
+ describe("Exchange rate tests", () => {
15
+ test("Get price in usd", async () => {
16
+ ExchangeRate.setupAxiosMock(
17
+ "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin-cash&vs_currencies=usd",
18
+ { "bitcoin-cash": { usd: 666.666 } }
19
+ );
20
+ ExchangeRate.setupAxiosMock(
21
+ "https://markets.api.bitcoin.com/live/bitcoin",
22
+ {
23
+ BCH: 666.666,
24
+ }
25
+ );
26
+
27
+ let rate = await ExchangeRate.get("usd");
28
+ expect(rate).toBe(666.666);
47
29
  });
48
30
 
49
- await delay(3000);
31
+ test("Test watchBalanceUsd", async () => {
32
+ ExchangeRate.setupAxiosMock(
33
+ "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin-cash&vs_currencies=usd",
34
+ { "bitcoin-cash": { usd: 666.666 } }
35
+ );
36
+
37
+ const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
38
+ const bob = await RegTestWallet.newRandom();
39
+ const balance = (await alice.getBalance()) as BalanceResponse;
40
+ let cbCounter = 0;
41
+ const cancelWatchFn = alice.watchBalanceUsd(async (newBalance) => {
42
+ cbCounter++;
43
+ if (cbCounter === 1) {
44
+ expect(newBalance.usd!).toBeGreaterThan(balance.usd!);
45
+ }
46
+ }, 3000);
50
47
 
51
- ExchangeRate.removeAxiosMock(
52
- "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin-cash&vs_currencies=usd"
53
- );
54
- expect(cbCounter).toBe(2);
55
- await cancelWatchFn();
48
+ ExchangeRate.setupAxiosMock(
49
+ "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin-cash&vs_currencies=usd",
50
+ { "bitcoin-cash": { usd: 777.777 } }
51
+ );
52
+
53
+ await delay(3000);
54
+
55
+ await alice.send({
56
+ cashaddr: bob.getDepositAddress(),
57
+ value: 10000,
58
+ unit: "sat",
59
+ });
60
+
61
+ await delay(3000);
62
+
63
+ ExchangeRate.removeAxiosMock(
64
+ "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin-cash&vs_currencies=usd"
65
+ );
66
+ expect(cbCounter).toBe(2);
67
+ await cancelWatchFn();
68
+ });
56
69
  });
@@ -173,4 +173,4 @@ export async function getRateFromExchange(symbol: string): Promise<number> {
173
173
  }
174
174
  }
175
175
 
176
- setTimeout(() => ExchangeRate.get("usd"), 0);
176
+ await ExchangeRate.get("usd");