@ledgerhq/coin-aptos 1.9.6-next.0 → 2.0.0-nightly.1

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 (259) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +18 -6
  3. package/CHANGELOG.md +19 -4
  4. package/jest.integ.config.js +8 -0
  5. package/lib/__tests__/api/index.integ.test.d.ts +2 -0
  6. package/lib/__tests__/api/index.integ.test.d.ts.map +1 -0
  7. package/lib/__tests__/api/index.integ.test.js +22 -0
  8. package/lib/__tests__/api/index.integ.test.js.map +1 -0
  9. package/lib/__tests__/api/index.test.js +48 -404
  10. package/lib/__tests__/api/index.test.js.map +1 -1
  11. package/lib/__tests__/bridge/broadcast.test.js +5 -5
  12. package/lib/__tests__/bridge/broadcast.test.js.map +1 -1
  13. package/lib/__tests__/bridge/buildTransaction.test.js +60 -5
  14. package/lib/__tests__/bridge/buildTransaction.test.js.map +1 -1
  15. package/lib/__tests__/bridge/getFeesForTransaction.test.js +115 -14
  16. package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  17. package/lib/__tests__/bridge/getTransactionStatus.test.js +175 -37
  18. package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
  19. package/lib/__tests__/bridge/logic.test.js +889 -115
  20. package/lib/__tests__/bridge/logic.test.js.map +1 -1
  21. package/lib/__tests__/bridge/prepareTransaction.test.js +3 -3
  22. package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -1
  23. package/lib/__tests__/bridge/signOperation.test.js +131 -4
  24. package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
  25. package/lib/__tests__/bridge/synchronisation.test.js +1215 -68
  26. package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
  27. package/lib/__tests__/network/client.test.d.ts +2 -0
  28. package/lib/__tests__/network/client.test.d.ts.map +1 -0
  29. package/lib/__tests__/network/client.test.js +478 -0
  30. package/lib/__tests__/network/client.test.js.map +1 -0
  31. package/lib/api/index.d.ts +4 -30
  32. package/lib/api/index.d.ts.map +1 -1
  33. package/lib/api/index.js +26 -170
  34. package/lib/api/index.js.map +1 -1
  35. package/lib/bridge/bridge.fixture.d.ts +2 -0
  36. package/lib/bridge/bridge.fixture.d.ts.map +1 -1
  37. package/lib/bridge/bridge.fixture.js +85 -13
  38. package/lib/bridge/bridge.fixture.js.map +1 -1
  39. package/lib/bridge/broadcast.d.ts +3 -2
  40. package/lib/bridge/broadcast.d.ts.map +1 -1
  41. package/lib/bridge/broadcast.js +4 -3
  42. package/lib/bridge/broadcast.js.map +1 -1
  43. package/lib/bridge/buildTransaction.d.ts +1 -1
  44. package/lib/bridge/buildTransaction.d.ts.map +1 -1
  45. package/lib/bridge/buildTransaction.js +29 -3
  46. package/lib/bridge/buildTransaction.js.map +1 -1
  47. package/lib/bridge/estimateMaxSpendable.js +3 -3
  48. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  49. package/lib/bridge/getFeesForTransaction.d.ts +1 -1
  50. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  51. package/lib/bridge/getFeesForTransaction.js +12 -7
  52. package/lib/bridge/getFeesForTransaction.js.map +1 -1
  53. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  54. package/lib/bridge/getTransactionStatus.js +28 -14
  55. package/lib/bridge/getTransactionStatus.js.map +1 -1
  56. package/lib/bridge/index.d.ts +1 -1
  57. package/lib/bridge/index.d.ts.map +1 -1
  58. package/lib/bridge/logic.d.ts +13 -8
  59. package/lib/bridge/logic.d.ts.map +1 -1
  60. package/lib/bridge/logic.js +152 -54
  61. package/lib/bridge/logic.js.map +1 -1
  62. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  63. package/lib/bridge/prepareTransaction.js +4 -4
  64. package/lib/bridge/prepareTransaction.js.map +1 -1
  65. package/lib/bridge/signOperation.d.ts.map +1 -1
  66. package/lib/bridge/signOperation.js +20 -6
  67. package/lib/bridge/signOperation.js.map +1 -1
  68. package/lib/bridge/synchronisation.d.ts +15 -0
  69. package/lib/bridge/synchronisation.d.ts.map +1 -1
  70. package/lib/bridge/synchronisation.js +129 -6
  71. package/lib/bridge/synchronisation.js.map +1 -1
  72. package/lib/config.d.ts +13 -0
  73. package/lib/config.d.ts.map +1 -0
  74. package/lib/config.js +9 -0
  75. package/lib/config.js.map +1 -0
  76. package/lib/constants.d.ts +5 -1
  77. package/lib/constants.d.ts.map +1 -1
  78. package/lib/constants.js +6 -2
  79. package/lib/constants.js.map +1 -1
  80. package/lib/network/client.d.ts +34 -0
  81. package/lib/network/client.d.ts.map +1 -0
  82. package/lib/network/client.js +213 -0
  83. package/lib/network/client.js.map +1 -0
  84. package/lib/network/graphql/queries.d.ts.map +1 -0
  85. package/lib/{api → network}/graphql/queries.js +6 -6
  86. package/lib/network/graphql/queries.js.map +1 -0
  87. package/lib/{api → network}/graphql/types.d.ts +9 -9
  88. package/lib/network/graphql/types.d.ts.map +1 -0
  89. package/lib/{api → network}/graphql/types.js.map +1 -1
  90. package/lib/network/index.d.ts +2 -1
  91. package/lib/network/index.d.ts.map +1 -1
  92. package/lib/network/index.js +15 -0
  93. package/lib/network/index.js.map +1 -1
  94. package/lib/test/bot-specs.d.ts.map +1 -1
  95. package/lib/test/bot-specs.js +40 -1
  96. package/lib/test/bot-specs.js.map +1 -1
  97. package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
  98. package/lib/test/bridgeDatasetTest.js +44 -62
  99. package/lib/test/bridgeDatasetTest.js.map +1 -1
  100. package/lib/test/speculos-deviceActions.d.ts +1 -0
  101. package/lib/test/speculos-deviceActions.d.ts.map +1 -1
  102. package/lib/test/speculos-deviceActions.js +37 -5
  103. package/lib/test/speculos-deviceActions.js.map +1 -1
  104. package/lib/types/assets.d.ts +3 -0
  105. package/lib/types/assets.d.ts.map +1 -0
  106. package/lib/types/assets.js +3 -0
  107. package/lib/types/assets.js.map +1 -0
  108. package/lib/types/index.d.ts +18 -7
  109. package/lib/types/index.d.ts.map +1 -1
  110. package/lib-es/__tests__/api/index.integ.test.d.ts +2 -0
  111. package/lib-es/__tests__/api/index.integ.test.d.ts.map +1 -0
  112. package/lib-es/__tests__/api/index.integ.test.js +20 -0
  113. package/lib-es/__tests__/api/index.integ.test.js.map +1 -0
  114. package/lib-es/__tests__/api/index.test.js +52 -408
  115. package/lib-es/__tests__/api/index.test.js.map +1 -1
  116. package/lib-es/__tests__/bridge/broadcast.test.js +2 -2
  117. package/lib-es/__tests__/bridge/broadcast.test.js.map +1 -1
  118. package/lib-es/__tests__/bridge/buildTransaction.test.js +60 -5
  119. package/lib-es/__tests__/bridge/buildTransaction.test.js.map +1 -1
  120. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +112 -11
  121. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  122. package/lib-es/__tests__/bridge/getTransactionStatus.test.js +177 -39
  123. package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
  124. package/lib-es/__tests__/bridge/logic.test.js +891 -117
  125. package/lib-es/__tests__/bridge/logic.test.js.map +1 -1
  126. package/lib-es/__tests__/bridge/prepareTransaction.test.js +2 -2
  127. package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -1
  128. package/lib-es/__tests__/bridge/signOperation.test.js +131 -4
  129. package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
  130. package/lib-es/__tests__/bridge/synchronisation.test.js +1213 -69
  131. package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
  132. package/lib-es/__tests__/network/client.test.d.ts +2 -0
  133. package/lib-es/__tests__/network/client.test.d.ts.map +1 -0
  134. package/lib-es/__tests__/network/client.test.js +473 -0
  135. package/lib-es/__tests__/network/client.test.js.map +1 -0
  136. package/lib-es/api/index.d.ts +4 -30
  137. package/lib-es/api/index.d.ts.map +1 -1
  138. package/lib-es/api/index.js +24 -168
  139. package/lib-es/api/index.js.map +1 -1
  140. package/lib-es/bridge/bridge.fixture.d.ts +2 -0
  141. package/lib-es/bridge/bridge.fixture.d.ts.map +1 -1
  142. package/lib-es/bridge/bridge.fixture.js +82 -12
  143. package/lib-es/bridge/bridge.fixture.js.map +1 -1
  144. package/lib-es/bridge/broadcast.d.ts +3 -2
  145. package/lib-es/bridge/broadcast.d.ts.map +1 -1
  146. package/lib-es/bridge/broadcast.js +4 -3
  147. package/lib-es/bridge/broadcast.js.map +1 -1
  148. package/lib-es/bridge/buildTransaction.d.ts +1 -1
  149. package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
  150. package/lib-es/bridge/buildTransaction.js +30 -4
  151. package/lib-es/bridge/buildTransaction.js.map +1 -1
  152. package/lib-es/bridge/estimateMaxSpendable.js +2 -2
  153. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  154. package/lib-es/bridge/getFeesForTransaction.d.ts +1 -1
  155. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  156. package/lib-es/bridge/getFeesForTransaction.js +13 -8
  157. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  158. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  159. package/lib-es/bridge/getTransactionStatus.js +28 -14
  160. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  161. package/lib-es/bridge/index.d.ts +1 -1
  162. package/lib-es/bridge/index.d.ts.map +1 -1
  163. package/lib-es/bridge/logic.d.ts +13 -8
  164. package/lib-es/bridge/logic.d.ts.map +1 -1
  165. package/lib-es/bridge/logic.js +146 -52
  166. package/lib-es/bridge/logic.js.map +1 -1
  167. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  168. package/lib-es/bridge/prepareTransaction.js +3 -3
  169. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  170. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  171. package/lib-es/bridge/signOperation.js +18 -4
  172. package/lib-es/bridge/signOperation.js.map +1 -1
  173. package/lib-es/bridge/synchronisation.d.ts +15 -0
  174. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  175. package/lib-es/bridge/synchronisation.js +124 -4
  176. package/lib-es/bridge/synchronisation.js.map +1 -1
  177. package/lib-es/config.d.ts +13 -0
  178. package/lib-es/config.d.ts.map +1 -0
  179. package/lib-es/config.js +4 -0
  180. package/lib-es/config.js.map +1 -0
  181. package/lib-es/constants.d.ts +5 -1
  182. package/lib-es/constants.d.ts.map +1 -1
  183. package/lib-es/constants.js +5 -1
  184. package/lib-es/constants.js.map +1 -1
  185. package/lib-es/network/client.d.ts +34 -0
  186. package/lib-es/network/client.d.ts.map +1 -0
  187. package/lib-es/network/client.js +206 -0
  188. package/lib-es/network/client.js.map +1 -0
  189. package/lib-es/network/graphql/queries.d.ts.map +1 -0
  190. package/lib-es/{api → network}/graphql/queries.js +6 -6
  191. package/lib-es/network/graphql/queries.js.map +1 -0
  192. package/lib-es/{api → network}/graphql/types.d.ts +9 -9
  193. package/lib-es/network/graphql/types.d.ts.map +1 -0
  194. package/lib-es/{api → network}/graphql/types.js.map +1 -1
  195. package/lib-es/network/index.d.ts +2 -1
  196. package/lib-es/network/index.d.ts.map +1 -1
  197. package/lib-es/network/index.js +1 -0
  198. package/lib-es/network/index.js.map +1 -1
  199. package/lib-es/test/bot-specs.d.ts.map +1 -1
  200. package/lib-es/test/bot-specs.js +41 -2
  201. package/lib-es/test/bot-specs.js.map +1 -1
  202. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
  203. package/lib-es/test/bridgeDatasetTest.js +44 -59
  204. package/lib-es/test/bridgeDatasetTest.js.map +1 -1
  205. package/lib-es/test/speculos-deviceActions.d.ts +1 -0
  206. package/lib-es/test/speculos-deviceActions.d.ts.map +1 -1
  207. package/lib-es/test/speculos-deviceActions.js +36 -4
  208. package/lib-es/test/speculos-deviceActions.js.map +1 -1
  209. package/lib-es/types/assets.d.ts +3 -0
  210. package/lib-es/types/assets.d.ts.map +1 -0
  211. package/lib-es/types/assets.js +2 -0
  212. package/lib-es/types/assets.js.map +1 -0
  213. package/lib-es/types/index.d.ts +18 -7
  214. package/lib-es/types/index.d.ts.map +1 -1
  215. package/package.json +10 -8
  216. package/src/__tests__/api/index.integ.test.ts +24 -0
  217. package/src/__tests__/api/index.test.ts +58 -477
  218. package/src/__tests__/bridge/broadcast.test.ts +2 -2
  219. package/src/__tests__/bridge/buildTransaction.test.ts +87 -5
  220. package/src/__tests__/bridge/getFeesForTransaction.test.ts +146 -11
  221. package/src/__tests__/bridge/getTransactionStatus.test.ts +217 -38
  222. package/src/__tests__/bridge/logic.test.ts +922 -118
  223. package/src/__tests__/bridge/prepareTransaction.test.ts +2 -2
  224. package/src/__tests__/bridge/signOperation.test.ts +147 -5
  225. package/src/__tests__/bridge/synchronisation.test.ts +1265 -71
  226. package/src/__tests__/network/client.test.ts +569 -0
  227. package/src/api/index.ts +30 -223
  228. package/src/bridge/bridge.fixture.ts +91 -12
  229. package/src/bridge/broadcast.ts +7 -7
  230. package/src/bridge/buildTransaction.ts +40 -7
  231. package/src/bridge/estimateMaxSpendable.ts +2 -2
  232. package/src/bridge/getFeesForTransaction.ts +15 -10
  233. package/src/bridge/getTransactionStatus.ts +35 -13
  234. package/src/bridge/index.ts +1 -1
  235. package/src/bridge/logic.ts +202 -63
  236. package/src/bridge/prepareTransaction.ts +5 -3
  237. package/src/bridge/signOperation.ts +20 -4
  238. package/src/bridge/synchronisation.ts +171 -4
  239. package/src/config.ts +19 -0
  240. package/src/constants.ts +12 -1
  241. package/src/network/client.ts +265 -0
  242. package/src/{api → network}/graphql/queries.ts +6 -6
  243. package/src/{api → network}/graphql/types.ts +9 -9
  244. package/src/network/index.ts +2 -1
  245. package/src/test/bot-specs.ts +63 -3
  246. package/src/test/bridgeDatasetTest.ts +46 -59
  247. package/src/test/speculos-deviceActions.ts +40 -4
  248. package/src/types/assets.ts +3 -0
  249. package/src/types/index.ts +15 -1
  250. package/lib/api/graphql/queries.d.ts.map +0 -1
  251. package/lib/api/graphql/queries.js.map +0 -1
  252. package/lib/api/graphql/types.d.ts.map +0 -1
  253. package/lib-es/api/graphql/queries.d.ts.map +0 -1
  254. package/lib-es/api/graphql/queries.js.map +0 -1
  255. package/lib-es/api/graphql/types.d.ts.map +0 -1
  256. /package/lib/{api → network}/graphql/queries.d.ts +0 -0
  257. /package/lib/{api → network}/graphql/types.js +0 -0
  258. /package/lib-es/{api → network}/graphql/queries.d.ts +0 -0
  259. /package/lib-es/{api → network}/graphql/types.js +0 -0
@@ -1,8 +1,12 @@
1
- import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/index";
2
- import { encodeAccountId } from "@ledgerhq/coin-framework/account";
3
1
  import { mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
4
- import { AptosAPI } from "../../api";
5
- import { getAccountShape } from "../../bridge/synchronisation";
2
+ import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/index";
3
+ import { decodeTokenAccountId } from "@ledgerhq/coin-framework/account";
4
+ import { emptyHistoryCache } from "@ledgerhq/coin-framework/account/index";
5
+ import { AptosAPI } from "../../network";
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";
6
10
  jest.mock("@ledgerhq/coin-framework/account", () => {
7
11
  const originalModule = jest.requireActual("@ledgerhq/coin-framework/account");
8
12
  const partialMockedModule = Object.keys(originalModule).reduce((pre, methodName) => {
@@ -12,18 +16,20 @@ jest.mock("@ledgerhq/coin-framework/account", () => {
12
16
  return {
13
17
  ...partialMockedModule,
14
18
  // mock all except these
19
+ encodeAccountId: originalModule.encodeAccountId,
15
20
  decodeAccountId: originalModule.decodeAccountId,
21
+ encodeTokenAccountId: originalModule.encodeTokenAccountId,
16
22
  };
17
23
  });
18
- const mockedEncodeAccountId = jest.mocked(encodeAccountId);
19
- jest.mock("../../api");
24
+ const mockedDecodeTokenAccountId = jest.mocked(decodeTokenAccountId);
25
+ jest.mock("../../network");
20
26
  let mockedAptosAPI;
21
27
  jest.mock("@ledgerhq/coin-framework/bridge/jsHelpers");
22
28
  jest.mock("invariant", () => jest.fn());
29
+ jest.mock("../../bridge/logic");
23
30
  describe("getAccountShape", () => {
24
31
  beforeEach(() => {
25
32
  mockedAptosAPI = jest.mocked(AptosAPI);
26
- jest.mocked(mergeOps).mockReturnValue([]);
27
33
  });
28
34
  afterEach(() => {
29
35
  jest.resetAllMocks();
@@ -38,6 +44,8 @@ describe("getAccountShape", () => {
38
44
  getAccountInfo: mockGetAccountInfo,
39
45
  }));
40
46
  const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
47
+ jest.mocked(mergeOps).mockReturnValue([]);
48
+ jest.mocked(txsToOps).mockReturnValue([[], []]);
41
49
  const account = await getAccountShape({
42
50
  id: "1",
43
51
  address: "address",
@@ -70,9 +78,8 @@ describe("getAccountShape", () => {
70
78
  },
71
79
  }, {});
72
80
  expect(account.xpub).toEqual("address");
73
- expect(mockedEncodeAccountId).toHaveBeenCalledTimes(1);
74
81
  expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
75
- expect(mockGetAccountSpy).toHaveBeenCalledWith("address", undefined);
82
+ expect(mockGetAccountSpy).toHaveBeenCalledWith("address");
76
83
  });
77
84
  it("account without xpub", async () => {
78
85
  const mockGetAccountInfo = jest.fn().mockImplementation(async () => ({
@@ -84,6 +91,8 @@ describe("getAccountShape", () => {
84
91
  getAccountInfo: mockGetAccountInfo,
85
92
  }));
86
93
  const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
94
+ jest.mocked(mergeOps).mockReturnValue([]);
95
+ jest.mocked(txsToOps).mockReturnValue([[], []]);
87
96
  const account = await getAccountShape({
88
97
  id: "1",
89
98
  address: "address",
@@ -115,9 +124,8 @@ describe("getAccountShape", () => {
115
124
  },
116
125
  }, {});
117
126
  expect(account.xpub).toEqual("1");
118
- expect(mockedEncodeAccountId).toHaveBeenCalledTimes(1);
119
127
  expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
120
- expect(mockGetAccountSpy).toHaveBeenCalledWith("address", undefined);
128
+ expect(mockGetAccountSpy).toHaveBeenCalledWith("address");
121
129
  });
122
130
  it("without initialAccount", async () => {
123
131
  const mockGetAccountInfo = jest.fn().mockImplementation(async () => ({
@@ -129,6 +137,8 @@ describe("getAccountShape", () => {
129
137
  getAccountInfo: mockGetAccountInfo,
130
138
  }));
131
139
  const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
140
+ jest.mocked(mergeOps).mockReturnValue([]);
141
+ jest.mocked(txsToOps).mockReturnValue([[], []]);
132
142
  const account = await getAccountShape({
133
143
  id: "1",
134
144
  address: "address",
@@ -140,9 +150,8 @@ describe("getAccountShape", () => {
140
150
  deviceId: "1",
141
151
  }, {});
142
152
  expect(account.xpub).toEqual("");
143
- expect(mockedEncodeAccountId).toHaveBeenCalledTimes(1);
144
153
  expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
145
- expect(mockGetAccountSpy).toHaveBeenCalledWith("address", undefined);
154
+ expect(mockGetAccountSpy).toHaveBeenCalledWith("address");
146
155
  });
147
156
  it("initialAccount with operations", async () => {
148
157
  const mockGetAccountInfo = jest.fn().mockImplementation(async () => ({
@@ -154,6 +163,8 @@ describe("getAccountShape", () => {
154
163
  getAccountInfo: mockGetAccountInfo,
155
164
  }));
156
165
  const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
166
+ jest.mocked(mergeOps).mockReturnValue([]);
167
+ jest.mocked(txsToOps).mockReturnValue([[], []]);
157
168
  const account = await getAccountShape({
158
169
  id: "1",
159
170
  address: "address",
@@ -176,22 +187,8 @@ describe("getAccountShape", () => {
176
187
  creationDate: new Date(),
177
188
  blockHeight: 0,
178
189
  currency: getCryptoCurrencyById("aptos"),
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
- ],
190
+ operationsCount: 0,
191
+ operations: [],
195
192
  pendingOperations: [],
196
193
  lastSyncDate: new Date(),
197
194
  balanceHistoryCache: {},
@@ -199,9 +196,8 @@ describe("getAccountShape", () => {
199
196
  },
200
197
  }, {});
201
198
  expect(account.xpub).toEqual("1");
202
- expect(mockedEncodeAccountId).toHaveBeenCalledTimes(1);
203
199
  expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
204
- expect(mockGetAccountSpy).toHaveBeenCalledWith("address", undefined);
200
+ expect(mockGetAccountSpy).toHaveBeenCalledWith("address");
205
201
  });
206
202
  it("initialAccount with operations with extra", async () => {
207
203
  const mockGetAccountInfo = jest.fn().mockImplementation(async () => ({
@@ -213,6 +209,8 @@ describe("getAccountShape", () => {
213
209
  getAccountInfo: mockGetAccountInfo,
214
210
  }));
215
211
  const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
212
+ jest.mocked(mergeOps).mockReturnValue([]);
213
+ jest.mocked(txsToOps).mockReturnValue([[], []]);
216
214
  const account = await getAccountShape({
217
215
  id: "1",
218
216
  address: "address",
@@ -235,23 +233,8 @@ describe("getAccountShape", () => {
235
233
  creationDate: new Date(),
236
234
  blockHeight: 0,
237
235
  currency: getCryptoCurrencyById("aptos"),
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
- ],
236
+ operationsCount: 0,
237
+ operations: [],
255
238
  pendingOperations: [],
256
239
  lastSyncDate: new Date(),
257
240
  balanceHistoryCache: {},
@@ -259,9 +242,8 @@ describe("getAccountShape", () => {
259
242
  },
260
243
  }, {});
261
244
  expect(account.xpub).toEqual("1");
262
- expect(mockedEncodeAccountId).toHaveBeenCalledTimes(1);
263
245
  expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
264
- expect(mockGetAccountSpy).toHaveBeenCalledWith("address", 1);
246
+ expect(mockGetAccountSpy).toHaveBeenCalledWith("address");
265
247
  });
266
248
  it("get publicKey from rest", async () => {
267
249
  const mockGetAccountInfo = jest.fn().mockImplementation(async () => ({
@@ -273,6 +255,8 @@ describe("getAccountShape", () => {
273
255
  getAccountInfo: mockGetAccountInfo,
274
256
  }));
275
257
  const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
258
+ jest.mocked(mergeOps).mockReturnValue([]);
259
+ jest.mocked(txsToOps).mockReturnValue([[], []]);
276
260
  const account = await getAccountShape({
277
261
  id: "1",
278
262
  address: "address",
@@ -295,23 +279,8 @@ describe("getAccountShape", () => {
295
279
  creationDate: new Date(),
296
280
  blockHeight: 0,
297
281
  currency: getCryptoCurrencyById("aptos"),
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
- ],
282
+ operationsCount: 0,
283
+ operations: [],
315
284
  pendingOperations: [],
316
285
  lastSyncDate: new Date(),
317
286
  balanceHistoryCache: {},
@@ -320,9 +289,1184 @@ describe("getAccountShape", () => {
320
289
  rest: { publicKey: "restPublicKey" },
321
290
  }, {});
322
291
  expect(account.xpub).toEqual("restPublicKey");
323
- expect(mockedEncodeAccountId).toHaveBeenCalledTimes(1);
324
292
  expect(mockedAptosAPI).toHaveBeenCalledTimes(1);
325
- expect(mockGetAccountSpy).toHaveBeenCalledWith("address", 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
+ ]);
326
1470
  });
327
1471
  });
328
1472
  //# sourceMappingURL=synchronisation.test.js.map