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