@ledgerhq/coin-aptos 2.0.0-nightly.3 → 2.0.0-nightly.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.
Files changed (159) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +17 -0
  3. package/lib/__tests__/api/index.test.js +5 -61
  4. package/lib/__tests__/api/index.test.js.map +1 -1
  5. package/lib/__tests__/bridge/buildTransaction.test.js +2 -57
  6. package/lib/__tests__/bridge/buildTransaction.test.js.map +1 -1
  7. package/lib/__tests__/bridge/getFeesForTransaction.test.js +8 -109
  8. package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  9. package/lib/__tests__/bridge/getTransactionStatus.test.js +37 -175
  10. package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
  11. package/lib/__tests__/bridge/logic.test.js +115 -889
  12. package/lib/__tests__/bridge/logic.test.js.map +1 -1
  13. package/lib/__tests__/bridge/signOperation.test.js +2 -128
  14. package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
  15. package/lib/__tests__/bridge/synchronisation.test.js +67 -1214
  16. package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
  17. package/lib/api/graphql/queries.js +6 -6
  18. package/lib/api/graphql/types.d.ts +9 -9
  19. package/lib/api/graphql/types.d.ts.map +1 -1
  20. package/lib/api/index.d.ts +2 -5
  21. package/lib/api/index.d.ts.map +1 -1
  22. package/lib/api/index.js +4 -30
  23. package/lib/api/index.js.map +1 -1
  24. package/lib/bridge/bridge.fixture.d.ts +0 -2
  25. package/lib/bridge/bridge.fixture.d.ts.map +1 -1
  26. package/lib/bridge/bridge.fixture.js +13 -85
  27. package/lib/bridge/bridge.fixture.js.map +1 -1
  28. package/lib/bridge/buildTransaction.d.ts.map +1 -1
  29. package/lib/bridge/buildTransaction.js +3 -29
  30. package/lib/bridge/buildTransaction.js.map +1 -1
  31. package/lib/bridge/estimateMaxSpendable.js +1 -1
  32. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  33. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  34. package/lib/bridge/getFeesForTransaction.js +7 -12
  35. package/lib/bridge/getFeesForTransaction.js.map +1 -1
  36. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  37. package/lib/bridge/getTransactionStatus.js +14 -28
  38. package/lib/bridge/getTransactionStatus.js.map +1 -1
  39. package/lib/bridge/logic.d.ts +8 -13
  40. package/lib/bridge/logic.d.ts.map +1 -1
  41. package/lib/bridge/logic.js +54 -152
  42. package/lib/bridge/logic.js.map +1 -1
  43. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  44. package/lib/bridge/prepareTransaction.js +2 -2
  45. package/lib/bridge/prepareTransaction.js.map +1 -1
  46. package/lib/bridge/signOperation.d.ts.map +1 -1
  47. package/lib/bridge/signOperation.js +3 -17
  48. package/lib/bridge/signOperation.js.map +1 -1
  49. package/lib/bridge/synchronisation.d.ts +0 -15
  50. package/lib/bridge/synchronisation.d.ts.map +1 -1
  51. package/lib/bridge/synchronisation.js +4 -127
  52. package/lib/bridge/synchronisation.js.map +1 -1
  53. package/lib/constants.d.ts +1 -5
  54. package/lib/constants.d.ts.map +1 -1
  55. package/lib/constants.js +2 -6
  56. package/lib/constants.js.map +1 -1
  57. package/lib/test/bot-specs.d.ts.map +1 -1
  58. package/lib/test/bot-specs.js +1 -40
  59. package/lib/test/bot-specs.js.map +1 -1
  60. package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
  61. package/lib/test/bridgeDatasetTest.js +62 -43
  62. package/lib/test/bridgeDatasetTest.js.map +1 -1
  63. package/lib/test/speculos-deviceActions.d.ts +0 -1
  64. package/lib/test/speculos-deviceActions.d.ts.map +1 -1
  65. package/lib/test/speculos-deviceActions.js +5 -37
  66. package/lib/test/speculos-deviceActions.js.map +1 -1
  67. package/lib/types/index.d.ts +7 -18
  68. package/lib/types/index.d.ts.map +1 -1
  69. package/lib-es/__tests__/api/index.test.js +5 -61
  70. package/lib-es/__tests__/api/index.test.js.map +1 -1
  71. package/lib-es/__tests__/bridge/buildTransaction.test.js +3 -58
  72. package/lib-es/__tests__/bridge/buildTransaction.test.js.map +1 -1
  73. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +9 -110
  74. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  75. package/lib-es/__tests__/bridge/getTransactionStatus.test.js +39 -177
  76. package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
  77. package/lib-es/__tests__/bridge/logic.test.js +117 -891
  78. package/lib-es/__tests__/bridge/logic.test.js.map +1 -1
  79. package/lib-es/__tests__/bridge/signOperation.test.js +2 -128
  80. package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
  81. package/lib-es/__tests__/bridge/synchronisation.test.js +69 -1213
  82. package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
  83. package/lib-es/api/graphql/queries.js +6 -6
  84. package/lib-es/api/graphql/types.d.ts +9 -9
  85. package/lib-es/api/graphql/types.d.ts.map +1 -1
  86. package/lib-es/api/index.d.ts +2 -5
  87. package/lib-es/api/index.d.ts.map +1 -1
  88. package/lib-es/api/index.js +4 -30
  89. package/lib-es/api/index.js.map +1 -1
  90. package/lib-es/bridge/bridge.fixture.d.ts +0 -2
  91. package/lib-es/bridge/bridge.fixture.d.ts.map +1 -1
  92. package/lib-es/bridge/bridge.fixture.js +12 -82
  93. package/lib-es/bridge/bridge.fixture.js.map +1 -1
  94. package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
  95. package/lib-es/bridge/buildTransaction.js +4 -30
  96. package/lib-es/bridge/buildTransaction.js.map +1 -1
  97. package/lib-es/bridge/estimateMaxSpendable.js +1 -1
  98. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  99. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  100. package/lib-es/bridge/getFeesForTransaction.js +8 -13
  101. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  102. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  103. package/lib-es/bridge/getTransactionStatus.js +14 -28
  104. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  105. package/lib-es/bridge/logic.d.ts +8 -13
  106. package/lib-es/bridge/logic.d.ts.map +1 -1
  107. package/lib-es/bridge/logic.js +52 -146
  108. package/lib-es/bridge/logic.js.map +1 -1
  109. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  110. package/lib-es/bridge/prepareTransaction.js +2 -2
  111. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  112. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  113. package/lib-es/bridge/signOperation.js +3 -17
  114. package/lib-es/bridge/signOperation.js.map +1 -1
  115. package/lib-es/bridge/synchronisation.d.ts +0 -15
  116. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  117. package/lib-es/bridge/synchronisation.js +3 -123
  118. package/lib-es/bridge/synchronisation.js.map +1 -1
  119. package/lib-es/constants.d.ts +1 -5
  120. package/lib-es/constants.d.ts.map +1 -1
  121. package/lib-es/constants.js +1 -5
  122. package/lib-es/constants.js.map +1 -1
  123. package/lib-es/test/bot-specs.d.ts.map +1 -1
  124. package/lib-es/test/bot-specs.js +2 -41
  125. package/lib-es/test/bot-specs.js.map +1 -1
  126. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
  127. package/lib-es/test/bridgeDatasetTest.js +59 -43
  128. package/lib-es/test/bridgeDatasetTest.js.map +1 -1
  129. package/lib-es/test/speculos-deviceActions.d.ts +0 -1
  130. package/lib-es/test/speculos-deviceActions.d.ts.map +1 -1
  131. package/lib-es/test/speculos-deviceActions.js +4 -36
  132. package/lib-es/test/speculos-deviceActions.js.map +1 -1
  133. package/lib-es/types/index.d.ts +7 -18
  134. package/lib-es/types/index.d.ts.map +1 -1
  135. package/package.json +5 -6
  136. package/src/__tests__/api/index.test.ts +5 -75
  137. package/src/__tests__/bridge/buildTransaction.test.ts +3 -85
  138. package/src/__tests__/bridge/getFeesForTransaction.test.ts +9 -144
  139. package/src/__tests__/bridge/getTransactionStatus.test.ts +38 -217
  140. package/src/__tests__/bridge/logic.test.ts +118 -922
  141. package/src/__tests__/bridge/signOperation.test.ts +2 -141
  142. package/src/__tests__/bridge/synchronisation.test.ts +71 -1265
  143. package/src/api/graphql/queries.ts +6 -6
  144. package/src/api/graphql/types.ts +9 -9
  145. package/src/api/index.ts +5 -32
  146. package/src/bridge/bridge.fixture.ts +12 -91
  147. package/src/bridge/buildTransaction.ts +6 -39
  148. package/src/bridge/estimateMaxSpendable.ts +1 -1
  149. package/src/bridge/getFeesForTransaction.ts +9 -14
  150. package/src/bridge/getTransactionStatus.ts +13 -35
  151. package/src/bridge/logic.ts +63 -202
  152. package/src/bridge/prepareTransaction.ts +3 -4
  153. package/src/bridge/signOperation.ts +3 -19
  154. package/src/bridge/synchronisation.ts +3 -170
  155. package/src/constants.ts +1 -12
  156. package/src/test/bot-specs.ts +3 -63
  157. package/src/test/bridgeDatasetTest.ts +59 -45
  158. package/src/test/speculos-deviceActions.ts +4 -40
  159. package/src/types/index.ts +1 -15
@@ -1,12 +1,8 @@
1
- import { mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
2
1
  import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/index";
3
- import { decodeTokenAccountId } from "@ledgerhq/coin-framework/account";
4
- import { emptyHistoryCache } from "@ledgerhq/coin-framework/account/index";
2
+ import { encodeAccountId } from "@ledgerhq/coin-framework/account";
3
+ import { mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
5
4
  import { AptosAPI } from "../../api";
6
- import { getAccountShape, mergeSubAccounts, getSubAccountShape, getSubAccounts, } from "../../bridge/synchronisation";
7
- import BigNumber from "bignumber.js";
8
- import { createFixtureAccount } from "../../bridge/bridge.fixture";
9
- import { txsToOps } from "../../bridge/logic";
5
+ import { getAccountShape } from "../../bridge/synchronisation";
10
6
  jest.mock("@ledgerhq/coin-framework/account", () => {
11
7
  const originalModule = jest.requireActual("@ledgerhq/coin-framework/account");
12
8
  const partialMockedModule = Object.keys(originalModule).reduce((pre, methodName) => {
@@ -16,20 +12,18 @@ jest.mock("@ledgerhq/coin-framework/account", () => {
16
12
  return {
17
13
  ...partialMockedModule,
18
14
  // mock all except these
19
- encodeAccountId: originalModule.encodeAccountId,
20
15
  decodeAccountId: originalModule.decodeAccountId,
21
- encodeTokenAccountId: originalModule.encodeTokenAccountId,
22
16
  };
23
17
  });
24
- const mockedDecodeTokenAccountId = jest.mocked(decodeTokenAccountId);
25
- jest.mock("@ledgerhq/coin-framework/bridge/jsHelpers");
26
- jest.mock("invariant", () => jest.fn());
18
+ const mockedEncodeAccountId = jest.mocked(encodeAccountId);
27
19
  jest.mock("../../api");
28
20
  let mockedAptosAPI;
29
- jest.mock("../../bridge/logic");
21
+ jest.mock("@ledgerhq/coin-framework/bridge/jsHelpers");
22
+ jest.mock("invariant", () => jest.fn());
30
23
  describe("getAccountShape", () => {
31
24
  beforeEach(() => {
32
25
  mockedAptosAPI = jest.mocked(AptosAPI);
26
+ jest.mocked(mergeOps).mockReturnValue([]);
33
27
  });
34
28
  afterEach(() => {
35
29
  jest.resetAllMocks();
@@ -44,8 +38,6 @@ describe("getAccountShape", () => {
44
38
  getAccountInfo: mockGetAccountInfo,
45
39
  }));
46
40
  const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
47
- jest.mocked(mergeOps).mockReturnValue([]);
48
- jest.mocked(txsToOps).mockReturnValue([[], []]);
49
41
  const account = await getAccountShape({
50
42
  id: "1",
51
43
  address: "address",
@@ -78,8 +70,9 @@ describe("getAccountShape", () => {
78
70
  },
79
71
  }, {});
80
72
  expect(account.xpub).toEqual("address");
73
+ expect(mockedEncodeAccountId).toHaveBeenCalledTimes(1);
81
74
  expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
82
- expect(mockGetAccountSpy).toHaveBeenCalledWith("address");
75
+ expect(mockGetAccountSpy).toHaveBeenCalledWith("address", undefined);
83
76
  });
84
77
  it("account without xpub", async () => {
85
78
  const mockGetAccountInfo = jest.fn().mockImplementation(async () => ({
@@ -91,8 +84,6 @@ describe("getAccountShape", () => {
91
84
  getAccountInfo: mockGetAccountInfo,
92
85
  }));
93
86
  const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
94
- jest.mocked(mergeOps).mockReturnValue([]);
95
- jest.mocked(txsToOps).mockReturnValue([[], []]);
96
87
  const account = await getAccountShape({
97
88
  id: "1",
98
89
  address: "address",
@@ -124,8 +115,9 @@ describe("getAccountShape", () => {
124
115
  },
125
116
  }, {});
126
117
  expect(account.xpub).toEqual("1");
118
+ expect(mockedEncodeAccountId).toHaveBeenCalledTimes(1);
127
119
  expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
128
- expect(mockGetAccountSpy).toHaveBeenCalledWith("address");
120
+ expect(mockGetAccountSpy).toHaveBeenCalledWith("address", undefined);
129
121
  });
130
122
  it("without initialAccount", async () => {
131
123
  const mockGetAccountInfo = jest.fn().mockImplementation(async () => ({
@@ -137,8 +129,6 @@ describe("getAccountShape", () => {
137
129
  getAccountInfo: mockGetAccountInfo,
138
130
  }));
139
131
  const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
140
- jest.mocked(mergeOps).mockReturnValue([]);
141
- jest.mocked(txsToOps).mockReturnValue([[], []]);
142
132
  const account = await getAccountShape({
143
133
  id: "1",
144
134
  address: "address",
@@ -150,8 +140,9 @@ describe("getAccountShape", () => {
150
140
  deviceId: "1",
151
141
  }, {});
152
142
  expect(account.xpub).toEqual("");
143
+ expect(mockedEncodeAccountId).toHaveBeenCalledTimes(1);
153
144
  expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
154
- expect(mockGetAccountSpy).toHaveBeenCalledWith("address");
145
+ expect(mockGetAccountSpy).toHaveBeenCalledWith("address", undefined);
155
146
  });
156
147
  it("initialAccount with operations", async () => {
157
148
  const mockGetAccountInfo = jest.fn().mockImplementation(async () => ({
@@ -163,8 +154,6 @@ describe("getAccountShape", () => {
163
154
  getAccountInfo: mockGetAccountInfo,
164
155
  }));
165
156
  const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
166
- jest.mocked(mergeOps).mockReturnValue([]);
167
- jest.mocked(txsToOps).mockReturnValue([[], []]);
168
157
  const account = await getAccountShape({
169
158
  id: "1",
170
159
  address: "address",
@@ -187,8 +176,22 @@ describe("getAccountShape", () => {
187
176
  creationDate: new Date(),
188
177
  blockHeight: 0,
189
178
  currency: getCryptoCurrencyById("aptos"),
190
- operationsCount: 0,
191
- operations: [],
179
+ t: 1,
180
+ operations: [
181
+ {
182
+ id: "1",
183
+ hash: "hash",
184
+ type: "OUT",
185
+ value: BigInt(10),
186
+ fee: BigInt(0),
187
+ blockHeight: 0,
188
+ blockHash: "blockHash",
189
+ accountId: "1",
190
+ senders: ["sender"],
191
+ recipients: ["recipient"],
192
+ date: new Date(),
193
+ },
194
+ ],
192
195
  pendingOperations: [],
193
196
  lastSyncDate: new Date(),
194
197
  balanceHistoryCache: {},
@@ -196,8 +199,9 @@ describe("getAccountShape", () => {
196
199
  },
197
200
  }, {});
198
201
  expect(account.xpub).toEqual("1");
202
+ expect(mockedEncodeAccountId).toHaveBeenCalledTimes(1);
199
203
  expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
200
- expect(mockGetAccountSpy).toHaveBeenCalledWith("address");
204
+ expect(mockGetAccountSpy).toHaveBeenCalledWith("address", undefined);
201
205
  });
202
206
  it("initialAccount with operations with extra", async () => {
203
207
  const mockGetAccountInfo = jest.fn().mockImplementation(async () => ({
@@ -209,8 +213,6 @@ describe("getAccountShape", () => {
209
213
  getAccountInfo: mockGetAccountInfo,
210
214
  }));
211
215
  const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
212
- jest.mocked(mergeOps).mockReturnValue([]);
213
- jest.mocked(txsToOps).mockReturnValue([[], []]);
214
216
  const account = await getAccountShape({
215
217
  id: "1",
216
218
  address: "address",
@@ -233,8 +235,23 @@ describe("getAccountShape", () => {
233
235
  creationDate: new Date(),
234
236
  blockHeight: 0,
235
237
  currency: getCryptoCurrencyById("aptos"),
236
- operationsCount: 0,
237
- operations: [],
238
+ t: 1,
239
+ operations: [
240
+ {
241
+ id: "1",
242
+ hash: "hash",
243
+ type: "OUT",
244
+ value: BigInt(10),
245
+ fee: BigInt(0),
246
+ blockHeight: 0,
247
+ blockHash: "blockHash",
248
+ accountId: "1",
249
+ senders: ["sender"],
250
+ recipients: ["recipient"],
251
+ date: new Date(),
252
+ extra: { version: 1 },
253
+ },
254
+ ],
238
255
  pendingOperations: [],
239
256
  lastSyncDate: new Date(),
240
257
  balanceHistoryCache: {},
@@ -242,8 +259,9 @@ describe("getAccountShape", () => {
242
259
  },
243
260
  }, {});
244
261
  expect(account.xpub).toEqual("1");
262
+ expect(mockedEncodeAccountId).toHaveBeenCalledTimes(1);
245
263
  expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
246
- expect(mockGetAccountSpy).toHaveBeenCalledWith("address");
264
+ expect(mockGetAccountSpy).toHaveBeenCalledWith("address", 1);
247
265
  });
248
266
  it("get publicKey from rest", async () => {
249
267
  const mockGetAccountInfo = jest.fn().mockImplementation(async () => ({
@@ -255,8 +273,6 @@ describe("getAccountShape", () => {
255
273
  getAccountInfo: mockGetAccountInfo,
256
274
  }));
257
275
  const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
258
- jest.mocked(mergeOps).mockReturnValue([]);
259
- jest.mocked(txsToOps).mockReturnValue([[], []]);
260
276
  const account = await getAccountShape({
261
277
  id: "1",
262
278
  address: "address",
@@ -279,8 +295,23 @@ describe("getAccountShape", () => {
279
295
  creationDate: new Date(),
280
296
  blockHeight: 0,
281
297
  currency: getCryptoCurrencyById("aptos"),
282
- operationsCount: 0,
283
- operations: [],
298
+ t: 1,
299
+ operations: [
300
+ {
301
+ id: "1",
302
+ hash: "hash",
303
+ type: "OUT",
304
+ value: BigInt(10),
305
+ fee: BigInt(0),
306
+ blockHeight: 0,
307
+ blockHash: "blockHash",
308
+ accountId: "1",
309
+ senders: ["sender"],
310
+ recipients: ["recipient"],
311
+ date: new Date(),
312
+ extra: { version: 1 },
313
+ },
314
+ ],
284
315
  pendingOperations: [],
285
316
  lastSyncDate: new Date(),
286
317
  balanceHistoryCache: {},
@@ -289,1184 +320,9 @@ describe("getAccountShape", () => {
289
320
  rest: { publicKey: "restPublicKey" },
290
321
  }, {});
291
322
  expect(account.xpub).toEqual("restPublicKey");
323
+ expect(mockedEncodeAccountId).toHaveBeenCalledTimes(1);
292
324
  expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
293
- expect(mockGetAccountSpy).toHaveBeenCalledWith("address");
294
- });
295
- it("initialAccount with operations with subOperations", async () => {
296
- const mockGetAccountInfo = jest.fn().mockImplementation(async () => ({
297
- balance: BigNumber(68254118),
298
- transactions: [
299
- {
300
- version: "2532591427",
301
- hash: "0x3f35",
302
- state_change_hash: "0xb480",
303
- event_root_hash: "0x3fa1",
304
- state_checkpoint_hash: null,
305
- gas_used: "12",
306
- success: true,
307
- vm_status: "Executed successfully",
308
- accumulator_root_hash: "0x319f",
309
- changes: [
310
- {
311
- address: "0x4e5e",
312
- state_key_hash: "0x3c0c",
313
- data: {
314
- type: "0x1::coin::CoinStore<0xd111::staked_coin::StakedAptos>",
315
- data: {
316
- coin: {
317
- value: "4000000",
318
- },
319
- deposit_events: {
320
- counter: "9",
321
- guid: {
322
- id: {
323
- addr: "0x4e5e",
324
- creation_num: "4",
325
- },
326
- },
327
- },
328
- frozen: false,
329
- withdraw_events: {
330
- counter: "6",
331
- guid: {
332
- id: {
333
- addr: "0x4e5e",
334
- creation_num: "5",
335
- },
336
- },
337
- },
338
- },
339
- },
340
- type: "write_resource",
341
- },
342
- {
343
- address: "0xa0d8",
344
- state_key_hash: "0x1709",
345
- data: {
346
- type: "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
347
- data: {
348
- coin: {
349
- value: "68254118",
350
- },
351
- deposit_events: {
352
- counter: "46",
353
- guid: {
354
- id: {
355
- addr: "0xa0d8",
356
- creation_num: "2",
357
- },
358
- },
359
- },
360
- frozen: false,
361
- withdraw_events: {
362
- counter: "89",
363
- guid: {
364
- id: {
365
- addr: "0xa0d8",
366
- creation_num: "3",
367
- },
368
- },
369
- },
370
- },
371
- },
372
- type: "write_resource",
373
- },
374
- {
375
- address: "0xa0d8",
376
- state_key_hash: "0x5520",
377
- data: {
378
- type: "0x1::coin::CoinStore<0xd111::staked_coin::StakedAptos>",
379
- data: {
380
- coin: {
381
- value: "1000000",
382
- },
383
- deposit_events: {
384
- counter: "7",
385
- guid: {
386
- id: {
387
- addr: "0xa0d8",
388
- creation_num: "10",
389
- },
390
- },
391
- },
392
- frozen: false,
393
- withdraw_events: {
394
- counter: "13",
395
- guid: {
396
- id: {
397
- addr: "0xa0d8",
398
- creation_num: "11",
399
- },
400
- },
401
- },
402
- },
403
- },
404
- type: "write_resource",
405
- },
406
- {
407
- address: "0xa0d8",
408
- state_key_hash: "0x6f1e",
409
- data: {
410
- type: "0x1::account::Account",
411
- data: {
412
- authentication_key: "0xa0d8",
413
- coin_register_events: {
414
- counter: "5",
415
- guid: {
416
- id: {
417
- addr: "0xa0d8",
418
- creation_num: "0",
419
- },
420
- },
421
- },
422
- guid_creation_num: "12",
423
- key_rotation_events: {
424
- counter: "0",
425
- guid: {
426
- id: {
427
- addr: "0xa0d8",
428
- creation_num: "1",
429
- },
430
- },
431
- },
432
- rotation_capability_offer: {
433
- for: {
434
- vec: [],
435
- },
436
- },
437
- sequence_number: "122",
438
- signer_capability_offer: {
439
- for: {
440
- vec: [],
441
- },
442
- },
443
- },
444
- },
445
- type: "write_resource",
446
- },
447
- {
448
- state_key_hash: "0x6e4b",
449
- handle: "0x1b85",
450
- key: "0x0619",
451
- value: "0x1ddaf8da3b1497010000000000000000",
452
- data: null,
453
- type: "write_table_item",
454
- },
455
- ],
456
- sender: "0xa0d8",
457
- sequence_number: "121",
458
- max_gas_amount: "12",
459
- gas_unit_price: "100",
460
- expiration_timestamp_secs: "1743177404",
461
- payload: {
462
- function: "0x1::aptos_account::transfer_coins",
463
- type_arguments: ["0xd111::staked_coin::StakedAptos"],
464
- arguments: ["0x4e5e", "1500000"],
465
- type: "entry_function_payload",
466
- },
467
- signature: {
468
- public_key: "0x474d",
469
- signature: "0x0ad8",
470
- type: "ed25519_signature",
471
- },
472
- events: [
473
- {
474
- guid: {
475
- creation_number: "11",
476
- account_address: "0xa0d8",
477
- },
478
- sequence_number: "12",
479
- type: "0x1::coin::WithdrawEvent",
480
- data: {
481
- amount: "1500000",
482
- },
483
- },
484
- {
485
- guid: {
486
- creation_number: "4",
487
- account_address: "0x4e5e",
488
- },
489
- sequence_number: "8",
490
- type: "0x1::coin::DepositEvent",
491
- data: {
492
- amount: "1500000",
493
- },
494
- },
495
- {
496
- guid: {
497
- creation_number: "0",
498
- account_address: "0x0",
499
- },
500
- sequence_number: "0",
501
- type: "0x1::transaction_fee::FeeStatement",
502
- data: {
503
- execution_gas_units: "6",
504
- io_gas_units: "6",
505
- storage_fee_octas: "0",
506
- storage_fee_refund_octas: "0",
507
- total_charge_gas_units: "12",
508
- },
509
- },
510
- ],
511
- timestamp: "1743177360481259",
512
- type: "user_transaction",
513
- block: {
514
- height: 311948147,
515
- hash: "0x6d02",
516
- },
517
- },
518
- {
519
- version: "2532549325",
520
- hash: "0x9a6b",
521
- state_change_hash: "0xa424",
522
- event_root_hash: "0x0321",
523
- state_checkpoint_hash: null,
524
- gas_used: "12",
525
- success: true,
526
- vm_status: "Executed successfully",
527
- accumulator_root_hash: "0xede9",
528
- changes: [
529
- {
530
- address: "0x4e5e",
531
- state_key_hash: "0x3c0c",
532
- data: {
533
- type: "0x1::coin::CoinStore<0xd111::staked_coin::StakedAptos>",
534
- data: {
535
- coin: {
536
- value: "2500000",
537
- },
538
- deposit_events: {
539
- counter: "8",
540
- guid: {
541
- id: {
542
- addr: "0x4e5e",
543
- creation_num: "4",
544
- },
545
- },
546
- },
547
- frozen: false,
548
- withdraw_events: {
549
- counter: "6",
550
- guid: {
551
- id: {
552
- addr: "0x4e5e",
553
- creation_num: "5",
554
- },
555
- },
556
- },
557
- },
558
- },
559
- type: "write_resource",
560
- },
561
- {
562
- address: "0xa0d8",
563
- state_key_hash: "0x1709",
564
- data: {
565
- type: "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
566
- data: {
567
- coin: {
568
- value: "68255318",
569
- },
570
- deposit_events: {
571
- counter: "46",
572
- guid: {
573
- id: {
574
- addr: "0xa0d8",
575
- creation_num: "2",
576
- },
577
- },
578
- },
579
- frozen: false,
580
- withdraw_events: {
581
- counter: "89",
582
- guid: {
583
- id: {
584
- addr: "0xa0d8",
585
- creation_num: "3",
586
- },
587
- },
588
- },
589
- },
590
- },
591
- type: "write_resource",
592
- },
593
- {
594
- address: "0xa0d8",
595
- state_key_hash: "0x5520",
596
- data: {
597
- type: "0x1::coin::CoinStore<0xd111::staked_coin::StakedAptos>",
598
- data: {
599
- coin: {
600
- value: "2500000",
601
- },
602
- deposit_events: {
603
- counter: "7",
604
- guid: {
605
- id: {
606
- addr: "0xa0d8",
607
- creation_num: "10",
608
- },
609
- },
610
- },
611
- frozen: false,
612
- withdraw_events: {
613
- counter: "12",
614
- guid: {
615
- id: {
616
- addr: "0xa0d8",
617
- creation_num: "11",
618
- },
619
- },
620
- },
621
- },
622
- },
623
- type: "write_resource",
624
- },
625
- {
626
- address: "0xa0d8",
627
- state_key_hash: "0x6f1e",
628
- data: {
629
- type: "0x1::account::Account",
630
- data: {
631
- authentication_key: "0xa0d8",
632
- coin_register_events: {
633
- counter: "5",
634
- guid: {
635
- id: {
636
- addr: "0xa0d8",
637
- creation_num: "0",
638
- },
639
- },
640
- },
641
- guid_creation_num: "12",
642
- key_rotation_events: {
643
- counter: "0",
644
- guid: {
645
- id: {
646
- addr: "0xa0d8",
647
- creation_num: "1",
648
- },
649
- },
650
- },
651
- rotation_capability_offer: {
652
- for: {
653
- vec: [],
654
- },
655
- },
656
- sequence_number: "121",
657
- signer_capability_offer: {
658
- for: {
659
- vec: [],
660
- },
661
- },
662
- },
663
- },
664
- type: "write_resource",
665
- },
666
- {
667
- state_key_hash: "0x6e4b",
668
- handle: "0x1b85",
669
- key: "0x0619",
670
- value: "0xe86e0039581497010000000000000000",
671
- data: null,
672
- type: "write_table_item",
673
- },
674
- ],
675
- sender: "0xa0d8",
676
- sequence_number: "120",
677
- max_gas_amount: "12",
678
- gas_unit_price: "100",
679
- expiration_timestamp_secs: "1743176706",
680
- payload: {
681
- function: "0x1::aptos_account::transfer_coins",
682
- type_arguments: ["0xd111::staked_coin::StakedAptos"],
683
- arguments: ["0x4e5e", "2500000"],
684
- type: "entry_function_payload",
685
- },
686
- signature: {
687
- public_key: "0x474d",
688
- signature: "0xb70e",
689
- type: "ed25519_signature",
690
- },
691
- events: [
692
- {
693
- guid: {
694
- creation_number: "11",
695
- account_address: "0xa0d8",
696
- },
697
- sequence_number: "11",
698
- type: "0x1::coin::WithdrawEvent",
699
- data: {
700
- amount: "2500000",
701
- },
702
- },
703
- {
704
- guid: {
705
- creation_number: "4",
706
- account_address: "0x4e5e",
707
- },
708
- sequence_number: "7",
709
- type: "0x1::coin::DepositEvent",
710
- data: {
711
- amount: "2500000",
712
- },
713
- },
714
- {
715
- guid: {
716
- creation_number: "0",
717
- account_address: "0x0",
718
- },
719
- sequence_number: "0",
720
- type: "0x1::transaction_fee::FeeStatement",
721
- data: {
722
- execution_gas_units: "6",
723
- io_gas_units: "6",
724
- storage_fee_octas: "0",
725
- storage_fee_refund_octas: "0",
726
- total_charge_gas_units: "12",
727
- },
728
- },
729
- ],
730
- timestamp: "1743176594693251",
731
- type: "user_transaction",
732
- block: {
733
- height: 311942427,
734
- hash: "0x8655",
735
- },
736
- },
737
- ],
738
- blockHeight: 316278241,
739
- }));
740
- const mockGetBalance = jest.fn().mockImplementation(() => BigNumber(5000000));
741
- mockedAptosAPI.mockImplementation(() => ({
742
- getAccountInfo: mockGetAccountInfo,
743
- getBalance: mockGetBalance,
744
- }));
745
- const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
746
- mockedDecodeTokenAccountId.mockReturnValue({
747
- token: {
748
- type: "TokenCurrency",
749
- id: "aptos/coin/dstapt_0xd111::staked_coin::stakedaptos",
750
- contractAddress: "0xd111::staked_coin::StakedAptos",
751
- parentCurrency: {
752
- type: "CryptoCurrency",
753
- id: "aptos",
754
- coinType: 637,
755
- name: "Aptos",
756
- managerAppName: "Aptos",
757
- ticker: "APT",
758
- scheme: "aptos",
759
- color: "#231F20",
760
- family: "aptos",
761
- units: [
762
- {
763
- name: "APT",
764
- code: "APT",
765
- magnitude: 8,
766
- },
767
- ],
768
- explorerViews: [
769
- {
770
- address: "https://explorer.aptoslabs.com/account/$address?network=mainnet",
771
- tx: "https://explorer.aptoslabs.com/txn/$hash?network=mainnet",
772
- },
773
- ],
774
- },
775
- name: "dstAPT",
776
- tokenType: "coin",
777
- ticker: "dstAPT",
778
- disableCountervalue: false,
779
- delisted: false,
780
- units: [
781
- {
782
- name: "dstAPT",
783
- code: "dstAPT",
784
- magnitude: 8,
785
- },
786
- ],
787
- },
788
- accountId: "js:2:aptos:6415:aptos",
789
- });
790
- const operations = [
791
- {
792
- id: "js:2:aptos:474d:aptos-0x3f35-OUT",
793
- hash: "0x3f35",
794
- type: "FEES",
795
- value: BigNumber(1200),
796
- fee: BigNumber(1200),
797
- blockHash: "0x6d02",
798
- blockHeight: 311948147,
799
- senders: ["0xa0d8"],
800
- recipients: ["0x4e5e"],
801
- accountId: "js:2:aptos:474d:aptos",
802
- date: new Date("2025-03-28T15:56:00.481Z"),
803
- extra: {
804
- version: "2532591427",
805
- },
806
- transactionSequenceNumber: 121,
807
- hasFailed: false,
808
- },
809
- {
810
- id: "js:2:aptos:474d:aptos-0x9a6b-OUT",
811
- hash: "0x9a6b",
812
- type: "FEES",
813
- value: BigNumber(1200),
814
- fee: BigNumber(1200),
815
- blockHash: "0x8655",
816
- blockHeight: 311942427,
817
- senders: ["0xa0d8"],
818
- recipients: ["0x4e5e"],
819
- accountId: "js:2:aptos:474d:aptos",
820
- date: new Date("2025-03-28T15:43:14.693Z"),
821
- extra: {
822
- version: "2532549325",
823
- },
824
- transactionSequenceNumber: 120,
825
- hasFailed: false,
826
- },
827
- ];
828
- const tokenOperations = [
829
- {
830
- id: "js:2:aptos:474d:aptos-0x3f35-OUT",
831
- hash: "0x3f35",
832
- type: "OUT",
833
- value: BigNumber(1500000),
834
- fee: BigNumber(1200),
835
- blockHash: "0x6d02",
836
- blockHeight: 311948147,
837
- senders: ["0xa0d8"],
838
- recipients: ["0x4e5e"],
839
- accountId: "js:2:aptos:474d:aptos+aptos%2Fcoin%2Fdstapt~!underscore!~0xd111%3A%3Astaked~!underscore!~coin%3A%3Astakedaptos",
840
- date: new Date("2025-03-28T15:56:00.481Z"),
841
- extra: {
842
- version: "2532591427",
843
- },
844
- transactionSequenceNumber: 121,
845
- hasFailed: false,
846
- },
847
- {
848
- id: "js:2:aptos:474d:aptos-0x9a6b-OUT",
849
- hash: "0x9a6b",
850
- type: "OUT",
851
- value: BigNumber(2500000),
852
- fee: BigNumber(1200),
853
- blockHash: "0x8655",
854
- blockHeight: 311942427,
855
- senders: ["0xa0d8"],
856
- recipients: ["0x4e5e"],
857
- accountId: "js:2:aptos:474d:aptos+aptos%2Fcoin%2Fdstapt~!underscore!~0xd111%3A%3Astaked~!underscore!~coin%3A%3Astakedaptos",
858
- date: new Date("2025-03-28T15:43:14.693Z"),
859
- extra: {
860
- version: "2532549325",
861
- },
862
- transactionSequenceNumber: 120,
863
- hasFailed: false,
864
- },
865
- ];
866
- jest.mocked(mergeOps).mockReturnValue(operations);
867
- jest.mocked(txsToOps).mockReturnValue([operations, tokenOperations]);
868
- const info = {
869
- currency: {
870
- type: "CryptoCurrency",
871
- id: "aptos",
872
- coinType: 637,
873
- name: "Aptos",
874
- managerAppName: "Aptos",
875
- ticker: "APT",
876
- scheme: "aptos",
877
- color: "#231F20",
878
- family: "aptos",
879
- units: [
880
- {
881
- name: "APT",
882
- code: "APT",
883
- magnitude: 8,
884
- },
885
- ],
886
- },
887
- index: 0,
888
- address: "0xa0d8",
889
- derivationPath: "44'/637'/0'",
890
- derivationMode: "aptos",
891
- initialAccount: {
892
- type: "Account",
893
- id: "js:2:aptos:474d:aptos",
894
- used: true,
895
- seedIdentifier: "3086",
896
- derivationMode: "aptos",
897
- index: 0,
898
- freshAddress: "0xa0d8",
899
- freshAddressPath: "44'/637'/0'/0'/0'",
900
- blockHeight: 316272224,
901
- creationDate: "2025-01-16T14:17:41.076Z",
902
- balance: BigNumber(68254118),
903
- spendableBalance: BigNumber(68254118),
904
- operations: [],
905
- operationsCount: 0,
906
- pendingOperations: [],
907
- currency: {
908
- type: "CryptoCurrency",
909
- id: "aptos",
910
- coinType: 637,
911
- name: "Aptos",
912
- managerAppName: "Aptos",
913
- ticker: "APT",
914
- scheme: "aptos",
915
- color: "#231F20",
916
- family: "aptos",
917
- units: [
918
- {
919
- name: "APT",
920
- code: "APT",
921
- magnitude: 8,
922
- },
923
- ],
924
- },
925
- lastSyncDate: new Date(),
926
- swapHistory: [],
927
- balanceHistoryCache: emptyHistoryCache,
928
- xpub: "474d",
929
- subAccounts: [
930
- {
931
- type: "TokenAccount",
932
- id: "js:2:aptos:474d:aptos+aptos%2Fcoin%2Fdstapt~!underscore!~0xd111%3A%3Astaked~!underscore!~coin%3A%3Astakedaptos",
933
- parentId: "js:2:aptos:474d:aptos",
934
- token: {
935
- type: "TokenCurrency",
936
- id: "aptos/coin/dstapt_0xd111::staked_coin::stakedaptos",
937
- contractAddress: "0xd111::staked_coin::StakedAptos",
938
- parentCurrency: {
939
- type: "CryptoCurrency",
940
- id: "aptos",
941
- coinType: 637,
942
- name: "Aptos",
943
- managerAppName: "Aptos",
944
- ticker: "APT",
945
- scheme: "aptos",
946
- color: "#231F20",
947
- family: "aptos",
948
- units: [
949
- {
950
- name: "APT",
951
- code: "APT",
952
- magnitude: 8,
953
- },
954
- ],
955
- },
956
- name: "dstAPT",
957
- tokenType: "coin",
958
- ticker: "dstAPT",
959
- disableCountervalue: false,
960
- delisted: false,
961
- units: [
962
- {
963
- name: "dstAPT",
964
- code: "dstAPT",
965
- magnitude: 8,
966
- },
967
- ],
968
- },
969
- balance: BigNumber(5000000),
970
- spendableBalance: BigNumber(5000000),
971
- creationDate: "2025-03-11T09:33:46.840Z",
972
- operations: [],
973
- operationsCount: 0,
974
- pendingOperations: [],
975
- swapHistory: [],
976
- balanceHistoryCache: emptyHistoryCache,
977
- },
978
- ],
979
- },
980
- };
981
- const result = await getAccountShape(info, {});
982
- expect(result.operations).toHaveLength(2);
983
- expect(result.operations?.at(0)?.subOperations).toHaveLength(2);
984
- expect(result.operations?.at(1)?.subOperations).toHaveLength(2);
985
- expect(result.subAccounts).toHaveLength(1);
986
- expect(mockedAptosAPI).toHaveBeenCalledTimes(2);
987
- expect(mockGetAccountSpy).toHaveBeenCalledWith("0xa0d8");
988
- });
989
- });
990
- describe("mergeSubAccounts", () => {
991
- const initialSubAccount = {
992
- type: "TokenAccount",
993
- id: "subAccountId",
994
- parentId: "accountId",
995
- token: {
996
- type: "TokenCurrency",
997
- id: "aptos/coin/dstapt_0xd111::staked_coin::stakedaptos",
998
- contractAddress: "0xd111::staked_coin::StakedAptos",
999
- parentCurrency: {
1000
- type: "CryptoCurrency",
1001
- id: "aptos",
1002
- coinType: 637,
1003
- name: "Aptos",
1004
- managerAppName: "Aptos",
1005
- ticker: "APT",
1006
- scheme: "aptos",
1007
- color: "#231F20",
1008
- family: "aptos",
1009
- units: [
1010
- {
1011
- name: "APT",
1012
- code: "APT",
1013
- magnitude: 8,
1014
- },
1015
- ],
1016
- explorerViews: [
1017
- {
1018
- address: "https://explorer.aptoslabs.com/account/$address?network=mainnet",
1019
- tx: "https://explorer.aptoslabs.com/txn/$hash?network=mainnet",
1020
- },
1021
- ],
1022
- },
1023
- name: "dstAPT",
1024
- tokenType: "coin",
1025
- ticker: "dstAPT",
1026
- disableCountervalue: false,
1027
- delisted: false,
1028
- units: [
1029
- {
1030
- name: "dstAPT",
1031
- code: "dstAPT",
1032
- magnitude: 8,
1033
- },
1034
- ],
1035
- },
1036
- balance: BigNumber(100),
1037
- spendableBalance: BigNumber(100),
1038
- creationDate: new Date(),
1039
- operationsCount: 0,
1040
- operations: [],
1041
- pendingOperations: [],
1042
- balanceHistoryCache: emptyHistoryCache,
1043
- swapHistory: [],
1044
- };
1045
- const initialAccount = createFixtureAccount({
1046
- subAccounts: [initialSubAccount],
1047
- });
1048
- it("return new subAccount if no old subAccounts", () => {
1049
- expect(mergeSubAccounts(undefined, [initialSubAccount])).toEqual([initialSubAccount]);
1050
- });
1051
- it("merge subAccounts properly if initialAccount has the same as new subAccounts", () => {
1052
- expect(mergeSubAccounts(initialAccount, [initialSubAccount])).toEqual([initialSubAccount]);
1053
- });
1054
- it("adds new sub account to initialAccount properly", () => {
1055
- const newSubAccount = {
1056
- type: "TokenAccount",
1057
- id: "js:2:aptos:474d:aptos+aptos%2Ffungible~!underscore!~asset%2Fcellana~!underscore!~0x2ebb",
1058
- parentId: "js:2:aptos:474d:aptos",
1059
- token: {
1060
- type: "TokenCurrency",
1061
- id: "aptos/fungible_asset/cellana_0x2ebb",
1062
- contractAddress: "0x2ebb",
1063
- parentCurrency: {
1064
- type: "CryptoCurrency",
1065
- id: "aptos",
1066
- coinType: 637,
1067
- name: "Aptos",
1068
- managerAppName: "Aptos",
1069
- ticker: "APT",
1070
- scheme: "aptos",
1071
- color: "#231F20",
1072
- family: "aptos",
1073
- units: [
1074
- {
1075
- name: "APT",
1076
- code: "APT",
1077
- magnitude: 8,
1078
- },
1079
- ],
1080
- explorerViews: [
1081
- {
1082
- address: "https://explorer.aptoslabs.com/account/$address?network=mainnet",
1083
- tx: "https://explorer.aptoslabs.com/txn/$hash?network=mainnet",
1084
- },
1085
- ],
1086
- },
1087
- name: "CELLANA",
1088
- tokenType: "fungible_asset",
1089
- ticker: "CELL",
1090
- disableCountervalue: false,
1091
- delisted: false,
1092
- units: [
1093
- {
1094
- name: "CELLANA",
1095
- code: "CELL",
1096
- magnitude: 8,
1097
- },
1098
- ],
1099
- },
1100
- balance: BigNumber(22980368),
1101
- spendableBalance: BigNumber(22980368),
1102
- creationDate: new Date(),
1103
- operationsCount: 0,
1104
- operations: [],
1105
- pendingOperations: [],
1106
- swapHistory: [],
1107
- balanceHistoryCache: emptyHistoryCache,
1108
- };
1109
- expect(mergeSubAccounts(initialAccount, [newSubAccount])).toEqual([
1110
- initialSubAccount,
1111
- newSubAccount,
1112
- ]);
1113
- });
1114
- it("merge subAccounts properly when new subAccounts is different", () => {
1115
- expect(mergeSubAccounts(initialAccount, [{ ...initialSubAccount, balance: BigNumber(150) }])).toEqual([{ ...initialSubAccount, balance: BigNumber(150) }]);
1116
- });
1117
- });
1118
- describe("getSubAccountShape", () => {
1119
- beforeEach(() => {
1120
- mockedAptosAPI = jest.mocked(AptosAPI);
1121
- });
1122
- afterEach(() => {
1123
- jest.resetAllMocks();
1124
- });
1125
- const currency = {
1126
- type: "CryptoCurrency",
1127
- id: "aptos",
1128
- coinType: 637,
1129
- name: "Aptos",
1130
- managerAppName: "Aptos",
1131
- ticker: "APT",
1132
- scheme: "aptos",
1133
- color: "#231F20",
1134
- family: "aptos",
1135
- units: [
1136
- {
1137
- name: "APT",
1138
- code: "APT",
1139
- magnitude: 8,
1140
- },
1141
- ],
1142
- explorerViews: [
1143
- {
1144
- address: "https://explorer.aptoslabs.com/account/$address?network=mainnet",
1145
- tx: "https://explorer.aptoslabs.com/txn/$hash?network=mainnet",
1146
- },
1147
- ],
1148
- };
1149
- const address = "0xa0d8";
1150
- const parentId = "js:2:aptos:474d:aptos";
1151
- const token = {
1152
- type: "TokenCurrency",
1153
- id: "aptos/coin/dstapt_0xd111::staked_coin::stakedaptos",
1154
- contractAddress: "0xd111::staked_coin::StakedAptos",
1155
- parentCurrency: {
1156
- type: "CryptoCurrency",
1157
- id: "aptos",
1158
- coinType: 637,
1159
- name: "Aptos",
1160
- managerAppName: "Aptos",
1161
- ticker: "APT",
1162
- scheme: "aptos",
1163
- color: "#231F20",
1164
- family: "aptos",
1165
- units: [
1166
- {
1167
- name: "APT",
1168
- code: "APT",
1169
- magnitude: 8,
1170
- },
1171
- ],
1172
- explorerViews: [
1173
- {
1174
- address: "https://explorer.aptoslabs.com/account/$address?network=mainnet",
1175
- tx: "https://explorer.aptoslabs.com/txn/$hash?network=mainnet",
1176
- },
1177
- ],
1178
- },
1179
- name: "dstAPT",
1180
- tokenType: "coin",
1181
- ticker: "dstAPT",
1182
- disableCountervalue: false,
1183
- delisted: false,
1184
- units: [
1185
- {
1186
- name: "dstAPT",
1187
- code: "dstAPT",
1188
- magnitude: 8,
1189
- },
1190
- ],
1191
- };
1192
- const firstOperationDate = new Date(10);
1193
- const operations = [
1194
- {
1195
- id: "js:2:aptos:474d:aptos-0x2011-IN",
1196
- hash: "0x2011",
1197
- type: "IN",
1198
- value: BigNumber(2000000),
1199
- fee: BigNumber(1200),
1200
- blockHash: "0xf29363a5a78d784c702a8ea352ac3e1461092cc2347b305adcace14aa7b15d60",
1201
- blockHeight: 315151047,
1202
- senders: ["0x4e5e"],
1203
- recipients: ["0xa0d8"],
1204
- accountId: "js:2:aptos:474d:aptos+aptos%2Fcoin%2Fdstapt~!underscore!~0xd111%3A%3Astaked~!underscore!~coin%3A%3Astakedaptos",
1205
- date: new Date(1000),
1206
- extra: {
1207
- version: "2553182323",
1208
- },
1209
- transactionSequenceNumber: 32,
1210
- hasFailed: false,
1211
- },
1212
- {
1213
- id: "js:2:aptos:474d:aptos-0x06a6-IN",
1214
- hash: "0x06a6",
1215
- type: "IN",
1216
- value: BigNumber(2000000),
1217
- fee: BigNumber(1200),
1218
- blockHash: "0xbae2",
1219
- blockHeight: 313836935,
1220
- senders: ["0x4e5e"],
1221
- recipients: ["0xa0d8"],
1222
- accountId: "js:2:aptos:474d:aptos+aptos%2Fcoin%2Fdstapt~!underscore!~0xd111%3A%3Astaked~!underscore!~coin%3A%3Astakedaptos",
1223
- date: firstOperationDate,
1224
- extra: {
1225
- version: "2544815758",
1226
- },
1227
- transactionSequenceNumber: 31,
1228
- hasFailed: false,
1229
- },
1230
- ];
1231
- it("returns the correct information", async () => {
1232
- const mockGetBalance = jest.fn().mockImplementation(() => BigNumber(1234567));
1233
- mockedAptosAPI.mockImplementation(() => ({
1234
- getBalance: mockGetBalance,
1235
- }));
1236
- const subAccount = await getSubAccountShape(currency, address, parentId, token, operations);
1237
- expect(subAccount).toEqual({
1238
- type: "TokenAccount",
1239
- id: "js:2:aptos:474d:aptos+aptos%2Fcoin%2Fdstapt~!underscore!~0xd111%3A%3Astaked~!underscore!~coin%3A%3Astakedaptos",
1240
- parentId,
1241
- token,
1242
- balance: BigNumber(1234567),
1243
- spendableBalance: BigNumber(1234567),
1244
- creationDate: firstOperationDate,
1245
- operations,
1246
- operationsCount: operations.length,
1247
- pendingOperations: [],
1248
- balanceHistoryCache: emptyHistoryCache,
1249
- swapHistory: [],
1250
- });
1251
- expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
1252
- });
1253
- });
1254
- describe("getSubAccounts", () => {
1255
- beforeEach(() => {
1256
- mockedAptosAPI = jest.mocked(AptosAPI);
1257
- });
1258
- afterEach(() => {
1259
- jest.resetAllMocks();
1260
- });
1261
- const address = "0x4e5e";
1262
- const infos = {
1263
- currency: {
1264
- type: "CryptoCurrency",
1265
- id: "aptos",
1266
- coinType: 637,
1267
- name: "Aptos",
1268
- managerAppName: "Aptos",
1269
- ticker: "APT",
1270
- scheme: "aptos",
1271
- color: "#231F20",
1272
- family: "aptos",
1273
- units: [
1274
- {
1275
- name: "APT",
1276
- code: "APT",
1277
- magnitude: 8,
1278
- },
1279
- ],
1280
- explorerViews: [
1281
- {
1282
- address: "https://explorer.aptoslabs.com/account/$address?network=mainnet",
1283
- tx: "https://explorer.aptoslabs.com/txn/$hash?network=mainnet",
1284
- },
1285
- ],
1286
- },
1287
- address,
1288
- index: 1,
1289
- derivationPath: "44'/637'/0'",
1290
- derivationMode: "aptos",
1291
- };
1292
- const accountId = "js:2:aptos:3282:aptos";
1293
- const lastTokenOperations = [
1294
- {
1295
- id: "js:2:aptos:474d:aptos-0x2011-IN",
1296
- hash: "0x2011",
1297
- type: "IN",
1298
- value: BigNumber(2000000),
1299
- fee: BigNumber(1200),
1300
- blockHash: "0xf29363a5a78d784c702a8ea352ac3e1461092cc2347b305adcace14aa7b15d60",
1301
- blockHeight: 315151047,
1302
- senders: ["0x4e5e"],
1303
- recipients: ["0xa0d8"],
1304
- accountId: "js:2:aptos:474d:aptos+aptos%2Fcoin%2Fdstapt~!underscore!~0xd111%3A%3Astaked~!underscore!~coin%3A%3Astakedaptos",
1305
- date: new Date(1000),
1306
- extra: {
1307
- version: "2553182323",
1308
- },
1309
- transactionSequenceNumber: 32,
1310
- hasFailed: false,
1311
- },
1312
- {
1313
- id: "js:2:aptos:474d:aptos-0x06a6-IN",
1314
- hash: "0x06a6",
1315
- type: "IN",
1316
- value: BigNumber(2000000),
1317
- fee: BigNumber(1200),
1318
- blockHash: "0xbae2",
1319
- blockHeight: 313836935,
1320
- senders: ["0x4e5e"],
1321
- recipients: ["0xa0d8"],
1322
- accountId: "js:2:aptos:474d:aptos+aptos%2Fcoin%2Fdstapt~!underscore!~0xd111%3A%3Astaked~!underscore!~coin%3A%3Astakedaptos",
1323
- date: new Date(10),
1324
- extra: {
1325
- version: "2544815758",
1326
- },
1327
- transactionSequenceNumber: 31,
1328
- hasFailed: false,
1329
- },
1330
- ];
1331
- it("returns the correct information", async () => {
1332
- const mockGetBalance = jest.fn().mockImplementation(() => BigNumber(1234567));
1333
- mockedAptosAPI.mockImplementation(() => ({
1334
- getBalance: mockGetBalance,
1335
- }));
1336
- mockedDecodeTokenAccountId.mockReturnValue({
1337
- token: {
1338
- type: "TokenCurrency",
1339
- id: "aptos/coin/dstapt_0xd111::staked_coin::stakedaptos",
1340
- contractAddress: "0xd111::staked_coin::StakedAptos",
1341
- parentCurrency: {
1342
- type: "CryptoCurrency",
1343
- id: "aptos",
1344
- coinType: 637,
1345
- name: "Aptos",
1346
- managerAppName: "Aptos",
1347
- ticker: "APT",
1348
- scheme: "aptos",
1349
- color: "#231F20",
1350
- family: "aptos",
1351
- units: [
1352
- {
1353
- name: "APT",
1354
- code: "APT",
1355
- magnitude: 8,
1356
- },
1357
- ],
1358
- explorerViews: [
1359
- {
1360
- address: "https://explorer.aptoslabs.com/account/$address?network=mainnet",
1361
- tx: "https://explorer.aptoslabs.com/txn/$hash?network=mainnet",
1362
- },
1363
- ],
1364
- },
1365
- name: "dstAPT",
1366
- tokenType: "coin",
1367
- ticker: "dstAPT",
1368
- disableCountervalue: false,
1369
- delisted: false,
1370
- units: [
1371
- {
1372
- name: "dstAPT",
1373
- code: "dstAPT",
1374
- magnitude: 8,
1375
- },
1376
- ],
1377
- },
1378
- accountId: "js:2:aptos:6415:aptos",
1379
- });
1380
- const result = await getSubAccounts(infos, address, accountId, lastTokenOperations);
1381
- expect(result).toEqual([
1382
- {
1383
- type: "TokenAccount",
1384
- id: "js:2:aptos:3282:aptos+aptos%2Fcoin%2Fdstapt~!underscore!~0xd111%3A%3Astaked~!underscore!~coin%3A%3Astakedaptos",
1385
- parentId: "js:2:aptos:3282:aptos",
1386
- token: {
1387
- type: "TokenCurrency",
1388
- id: "aptos/coin/dstapt_0xd111::staked_coin::stakedaptos",
1389
- contractAddress: "0xd111::staked_coin::StakedAptos",
1390
- parentCurrency: {
1391
- type: "CryptoCurrency",
1392
- id: "aptos",
1393
- coinType: 637,
1394
- name: "Aptos",
1395
- managerAppName: "Aptos",
1396
- ticker: "APT",
1397
- scheme: "aptos",
1398
- color: "#231F20",
1399
- family: "aptos",
1400
- units: [
1401
- {
1402
- name: "APT",
1403
- code: "APT",
1404
- magnitude: 8,
1405
- },
1406
- ],
1407
- explorerViews: [
1408
- {
1409
- address: "https://explorer.aptoslabs.com/account/$address?network=mainnet",
1410
- tx: "https://explorer.aptoslabs.com/txn/$hash?network=mainnet",
1411
- },
1412
- ],
1413
- },
1414
- name: "dstAPT",
1415
- tokenType: "coin",
1416
- ticker: "dstAPT",
1417
- disableCountervalue: false,
1418
- delisted: false,
1419
- units: [
1420
- {
1421
- name: "dstAPT",
1422
- code: "dstAPT",
1423
- magnitude: 8,
1424
- },
1425
- ],
1426
- },
1427
- balance: BigNumber(1234567),
1428
- spendableBalance: BigNumber(1234567),
1429
- creationDate: new Date(10),
1430
- operations: [
1431
- {
1432
- accountId: "js:2:aptos:474d:aptos+aptos%2Fcoin%2Fdstapt~!underscore!~0xd111%3A%3Astaked~!underscore!~coin%3A%3Astakedaptos",
1433
- blockHash: "0xf29363a5a78d784c702a8ea352ac3e1461092cc2347b305adcace14aa7b15d60",
1434
- blockHeight: 315151047,
1435
- date: new Date(1000),
1436
- extra: { version: "2553182323" },
1437
- fee: BigNumber(1200),
1438
- hasFailed: false,
1439
- hash: "0x2011",
1440
- id: "js:2:aptos:474d:aptos-0x2011-IN",
1441
- recipients: ["0xa0d8"],
1442
- senders: ["0x4e5e"],
1443
- transactionSequenceNumber: 32,
1444
- type: "IN",
1445
- value: BigNumber(2000000),
1446
- },
1447
- {
1448
- accountId: "js:2:aptos:474d:aptos+aptos%2Fcoin%2Fdstapt~!underscore!~0xd111%3A%3Astaked~!underscore!~coin%3A%3Astakedaptos",
1449
- blockHash: "0xbae2",
1450
- blockHeight: 313836935,
1451
- date: new Date(10),
1452
- fee: BigNumber(1200),
1453
- extra: { version: "2544815758" },
1454
- hasFailed: false,
1455
- hash: "0x06a6",
1456
- id: "js:2:aptos:474d:aptos-0x06a6-IN",
1457
- recipients: ["0xa0d8"],
1458
- senders: ["0x4e5e"],
1459
- transactionSequenceNumber: 31,
1460
- type: "IN",
1461
- value: BigNumber(2000000),
1462
- },
1463
- ],
1464
- operationsCount: 2,
1465
- pendingOperations: [],
1466
- balanceHistoryCache: emptyHistoryCache,
1467
- swapHistory: [],
1468
- },
1469
- ]);
325
+ expect(mockGetAccountSpy).toHaveBeenCalledWith("address", 1);
1470
326
  });
1471
327
  });
1472
328
  //# sourceMappingURL=synchronisation.test.js.map