This repository has been archived by the owner on Jul 7, 2021. It is now read-only.
/
wallet.test.ts
212 lines (178 loc) · 5.74 KB
/
wallet.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import "jest-extended";
import { Coins } from "@arkecosystem/platform-sdk";
import { ARK } from "@arkecosystem/platform-sdk-ark";
import { Request } from "@arkecosystem/platform-sdk-http-got";
import { BigNumber } from "@arkecosystem/platform-sdk-support";
import nock from "nock";
import { v4 as uuidv4 } from "uuid";
import { identity } from "../../test/fixtures/identity";
import { container } from "../environment/container";
import { Identifiers } from "../environment/container.models";
import { Profile } from "../profiles/profile";
import { ProfileSetting } from "../profiles/profile.models";
import { Wallet } from "./wallet";
import { WalletData } from "./wallet.models";
let profile: Profile;
let subject: Wallet;
beforeEach(async () => {
nock.cleanAll();
nock(/.+/)
.get("/api/node/configuration")
.reply(200, require("../../test/fixtures/client/configuration.json"))
.get("/api/peers")
.reply(200, require("../../test/fixtures/client/peers.json"))
.get("/api/node/configuration/crypto")
.reply(200, require("../../test/fixtures/client/cryptoConfiguration.json"))
.get("/api/node/syncing")
.reply(200, require("../../test/fixtures/client/syncing.json"))
.get("/api/wallets/D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib")
.reply(200, require("../../test/fixtures/client/wallet.json"))
.get("/api/delegates?page=1")
.reply(200, require("../../test/fixtures/client/delegates-1.json"))
.get("/api/delegates?page=2")
.reply(200, require("../../test/fixtures/client/delegates-2.json"))
.persist();
container.set(Identifiers.HttpClient, new Request());
container.set(Identifiers.Coins, { ARK });
profile = new Profile("profile-id");
profile.settings().set(ProfileSetting.Name, "John Doe");
subject = new Wallet(uuidv4(), profile);
await subject.setCoin("ARK", "devnet");
await subject.setIdentity(identity.mnemonic);
});
beforeAll(() => nock.disableNetConnect());
it("should have a coin", () => {
expect(subject.coin()).toBeInstanceOf(Coins.Coin);
});
it("should have a network", () => {
expect(subject.network().toObject()).toEqual({
crypto: { slip44: 111 },
currency: { symbol: "DѦ", ticker: "DARK" },
explorer: "https://dexplorer.ark.io/",
hosts: ["https://dwallets.ark.io"],
hostsMultiSignature: [],
id: "devnet",
name: "Devnet",
type: "test",
voting: {
enabled: true,
maximum: 1,
maximumPerTransaction: 1,
},
});
});
it("should have an address", () => {
expect(subject.address()).toEqual(identity.address);
});
it("should have a publicKey", () => {
expect(subject.publicKey()).toEqual(identity.publicKey);
});
it("should have a balance", () => {
expect(subject.balance()).toBeInstanceOf(BigNumber);
expect(subject.balance().toString()).toBe("55827093444556");
});
it("should have a converted balance", () => {
subject.data().set(WalletData.Balance, 5);
subject.data().set(WalletData.ExchangeRate, 5);
expect(subject.convertedBalance()).toBeInstanceOf(BigNumber);
expect(subject.convertedBalance().toString()).toBe("25");
});
it("should have a nonce", () => {
expect(subject.nonce()).toEqual(BigNumber.make("111932"));
});
it("should have a manifest service", () => {
expect(subject.manifest()).toBeInstanceOf(Coins.Manifest);
});
it("should have a config service", () => {
expect(subject.config()).toBeInstanceOf(Coins.Config);
});
it("should have a guard service", () => {
expect(subject.guard()).toBeInstanceOf(Coins.Guard);
});
it("should have a client service", () => {
expect(subject.client()).toBeObject();
});
it("should have a identity service", () => {
expect(subject.identity()).toBeObject();
});
it("should have a ledger service", () => {
expect(subject.ledger()).toBeObject();
});
it("should have a link service", () => {
expect(subject.link()).toBeObject();
});
it("should have a message service", () => {
expect(subject.message()).toBeObject();
});
it("should have a peer service", () => {
expect(subject.peer()).toBeObject();
});
it("should have a transaction service", () => {
expect(subject.transaction()).toBeObject();
});
describe.each([123, 456, 789])("%s", (slip44) => {
it("should turn into an object", () => {
subject.coin().config().set("network.crypto.slip44", slip44);
subject.data().set("key", "value");
const actual: any = subject.toObject();
expect(actual).toContainAllKeys([
"id",
"address",
"coin",
"coinConfig",
"network",
"publicKey",
"data",
"settings",
]);
expect(actual.id).toBeString();
expect(actual.address).toBe("D61mfSggzbvQgTUe6JhYKH2doHaqJ3Dyib");
expect(actual.coin).toBe("ARK");
expect(actual.coinConfig).toEqual({
network: {
crypto: {
slip44,
},
currency: {
symbol: "DѦ",
ticker: "DARK",
},
explorer: "https://dexplorer.ark.io/",
hosts: ["https://dwallets.ark.io"],
hostsMultiSignature: [],
id: "devnet",
type: "test",
name: "Devnet",
voting: {
enabled: true,
maximum: 1,
maximumPerTransaction: 1,
},
},
});
expect(actual.network).toBe("devnet");
expect(actual.publicKey).toBe("034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192");
expect(actual.data).toEqual({
BALANCE: "55827093444556",
BROADCASTED_TRANSACTIONS: {},
EXCHANGE_RATE: 0,
SEQUENCE: "111932",
SIGNED_TRANSACTIONS: {},
VOTES: [],
VOTES_USED: 0,
VOTES_AVAILABLE: 0,
});
expect(actual.settings).toBeObject();
expect(actual.settings.AVATAR).toBeString();
});
});
it("should sync the exchange rate for ARK to BTC", async () => {
profile.settings().set(ProfileSetting.MarketProvider, "cryptocompare");
nock(/.+/)
.get("/data/dayAvg")
.query(true)
.reply(200, { BTC: 0.00005048, ConversionType: { type: "direct", conversionSymbol: "" } })
.persist();
await subject.syncExchangeRate();
expect(subject.data().get(WalletData.ExchangeRate)).toBe(0.00005048);
});