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.
- package/dist/index.html +1 -1
- package/dist/{mainnet-1.1.27.js → mainnet-1.1.29.js} +9 -9
- package/dist/module/rate/ExchangeRate.js +1 -1
- package/dist/module/rate/ExchangeRate.js.map +1 -1
- package/dist/module/wallet/Bcmr.js +1 -1
- package/dist/module/wallet/Bcmr.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/network/Rpc.test.ts +91 -89
- package/src/rate/ExchangeRate.test.ts +58 -45
- package/src/rate/ExchangeRate.ts +1 -1
- package/src/transaction/allocateFee.test.ts +272 -262
- package/src/wallet/Bcmr.ts +1 -1
- package/src/wallet/Util.test.ts +71 -61
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
});
|
package/src/rate/ExchangeRate.ts
CHANGED