@ledgerhq/coin-aptos 2.2.0-nightly.2 → 2.2.0

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 (97) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +28 -15
  3. package/lib/__tests__/api/craftTransaction.unit.test.js +31 -16
  4. package/lib/__tests__/api/craftTransaction.unit.test.js.map +1 -1
  5. package/lib/__tests__/api/getBalance.unit.test.js +28 -68
  6. package/lib/__tests__/api/getBalance.unit.test.js.map +1 -1
  7. package/lib/__tests__/api/index.integ.test.js +11 -30
  8. package/lib/__tests__/api/index.integ.test.js.map +1 -1
  9. package/lib/__tests__/api/index.test.js.map +1 -1
  10. package/lib/__tests__/bridge/synchronisation.test.js +6 -15
  11. package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
  12. package/lib/__tests__/network/client.test.js +66 -69
  13. package/lib/__tests__/network/client.test.js.map +1 -1
  14. package/lib/api/index.d.ts +3 -3
  15. package/lib/api/index.d.ts.map +1 -1
  16. package/lib/api/index.js +2 -2
  17. package/lib/api/index.js.map +1 -1
  18. package/lib/bridge/synchronisation.d.ts.map +1 -1
  19. package/lib/bridge/synchronisation.js +2 -7
  20. package/lib/bridge/synchronisation.js.map +1 -1
  21. package/lib/logic/craftTransaction.d.ts +2 -2
  22. package/lib/logic/craftTransaction.d.ts.map +1 -1
  23. package/lib/logic/craftTransaction.js +3 -3
  24. package/lib/logic/craftTransaction.js.map +1 -1
  25. package/lib/logic/getBalance.d.ts +5 -0
  26. package/lib/logic/getBalance.d.ts.map +1 -0
  27. package/lib/logic/getBalance.js +12 -0
  28. package/lib/logic/getBalance.js.map +1 -0
  29. package/lib/network/client.d.ts +7 -3
  30. package/lib/network/client.d.ts.map +1 -1
  31. package/lib/network/client.js +62 -28
  32. package/lib/network/client.js.map +1 -1
  33. package/lib/types/assets.d.ts +4 -0
  34. package/lib/types/assets.d.ts.map +1 -1
  35. package/lib-es/__tests__/api/craftTransaction.unit.test.js +31 -16
  36. package/lib-es/__tests__/api/craftTransaction.unit.test.js.map +1 -1
  37. package/lib-es/__tests__/api/getBalance.unit.test.js +26 -69
  38. package/lib-es/__tests__/api/getBalance.unit.test.js.map +1 -1
  39. package/lib-es/__tests__/api/index.integ.test.js +11 -30
  40. package/lib-es/__tests__/api/index.integ.test.js.map +1 -1
  41. package/lib-es/__tests__/api/index.test.js.map +1 -1
  42. package/lib-es/__tests__/bridge/synchronisation.test.js +6 -15
  43. package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
  44. package/lib-es/__tests__/network/client.test.js +66 -69
  45. package/lib-es/__tests__/network/client.test.js.map +1 -1
  46. package/lib-es/api/index.d.ts +3 -3
  47. package/lib-es/api/index.d.ts.map +1 -1
  48. package/lib-es/api/index.js +2 -2
  49. package/lib-es/api/index.js.map +1 -1
  50. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  51. package/lib-es/bridge/synchronisation.js +2 -4
  52. package/lib-es/bridge/synchronisation.js.map +1 -1
  53. package/lib-es/logic/craftTransaction.d.ts +2 -2
  54. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  55. package/lib-es/logic/craftTransaction.js +3 -3
  56. package/lib-es/logic/craftTransaction.js.map +1 -1
  57. package/lib-es/logic/getBalance.d.ts +5 -0
  58. package/lib-es/logic/getBalance.d.ts.map +1 -0
  59. package/lib-es/logic/getBalance.js +8 -0
  60. package/lib-es/logic/getBalance.js.map +1 -0
  61. package/lib-es/network/client.d.ts +7 -3
  62. package/lib-es/network/client.d.ts.map +1 -1
  63. package/lib-es/network/client.js +62 -28
  64. package/lib-es/network/client.js.map +1 -1
  65. package/lib-es/types/assets.d.ts +4 -0
  66. package/lib-es/types/assets.d.ts.map +1 -1
  67. package/package.json +8 -8
  68. package/src/__tests__/api/craftTransaction.unit.test.ts +38 -23
  69. package/src/__tests__/api/getBalance.unit.test.ts +28 -82
  70. package/src/__tests__/api/index.integ.test.ts +15 -36
  71. package/src/__tests__/api/index.test.ts +6 -4
  72. package/src/__tests__/bridge/synchronisation.test.ts +6 -21
  73. package/src/__tests__/network/client.test.ts +89 -83
  74. package/src/api/index.ts +8 -6
  75. package/src/bridge/synchronisation.ts +2 -4
  76. package/src/logic/craftTransaction.ts +8 -6
  77. package/src/logic/getBalance.ts +15 -0
  78. package/src/network/client.ts +74 -31
  79. package/src/types/assets.ts +5 -0
  80. package/lib/__tests__/logic/getBalances.test.d.ts +0 -2
  81. package/lib/__tests__/logic/getBalances.test.d.ts.map +0 -1
  82. package/lib/__tests__/logic/getBalances.test.js +0 -63
  83. package/lib/__tests__/logic/getBalances.test.js.map +0 -1
  84. package/lib/logic/getBalances.d.ts +0 -5
  85. package/lib/logic/getBalances.d.ts.map +0 -1
  86. package/lib/logic/getBalances.js +0 -21
  87. package/lib/logic/getBalances.js.map +0 -1
  88. package/lib-es/__tests__/logic/getBalances.test.d.ts +0 -2
  89. package/lib-es/__tests__/logic/getBalances.test.d.ts.map +0 -1
  90. package/lib-es/__tests__/logic/getBalances.test.js +0 -61
  91. package/lib-es/__tests__/logic/getBalances.test.js.map +0 -1
  92. package/lib-es/logic/getBalances.d.ts +0 -5
  93. package/lib-es/logic/getBalances.d.ts.map +0 -1
  94. package/lib-es/logic/getBalances.js +0 -17
  95. package/lib-es/logic/getBalances.js.map +0 -1
  96. package/src/__tests__/logic/getBalances.test.ts +0 -80
  97. package/src/logic/getBalances.ts +0 -27
@@ -1,7 +1,7 @@
1
1
  import { Hex, RawTransaction, Deserializer } from "@aptos-labs/ts-sdk";
2
- import type { TransactionIntent } from "@ledgerhq/coin-framework/api/types";
2
+ import type { TransactionIntent } from "@ledgerhq/coin-framework/lib/api/types";
3
3
  import { createApi } from "../../api";
4
- import type { AptosAsset } from "../../types/assets";
4
+ import type { AptosAsset, AptosExtra, AptosSender } from "../../types/assets";
5
5
  import { AptosAPI } from "../../network";
6
6
  import { APTOS_ASSET_ID } from "../../constants";
7
7
 
@@ -41,17 +41,20 @@ describe("craftTransaction", () => {
41
41
  getBalances: mockGetBalances,
42
42
  }));
43
43
 
44
+ const SENDER: AptosSender = {
45
+ xpub: "public-key",
46
+ freshAddress: SENDER_ADDR,
47
+ };
44
48
  const api = createApi({
45
49
  aptosSettings: {},
46
50
  });
47
51
 
48
- const txArg: TransactionIntent<AptosAsset> = {
52
+ const txArg: TransactionIntent<AptosAsset, AptosExtra, AptosSender> = {
49
53
  type: "send",
50
- sender: SENDER_ADDR,
51
- senderPublicKey: "public-key",
54
+ sender: SENDER,
52
55
  recipient: RECIPIENT_ADDR,
53
56
  amount: 10n,
54
- asset: { type: "token", standard: "coin", contractAddress: "0x42::token::Token" },
57
+ asset: { type: "native" },
55
58
  };
56
59
 
57
60
  const tx = await api.craftTransaction(txArg);
@@ -62,10 +65,10 @@ describe("craftTransaction", () => {
62
65
  expect(mockGenerateTransaction).toHaveBeenCalledTimes(1);
63
66
 
64
67
  expect(mockGenerateTransaction).toHaveBeenCalledWith(
65
- SENDER_ADDR,
68
+ SENDER.freshAddress,
66
69
  expect.objectContaining({
67
70
  function: "0x1::aptos_account::transfer_coins",
68
- typeArguments: ["0x42::token::Token"],
71
+ typeArguments: [APTOS_ASSET_ID],
69
72
  functionArguments: [RECIPIENT_ADDR, txArg.amount.toString()],
70
73
  }),
71
74
  expect.anything(),
@@ -82,14 +85,17 @@ describe("craftTransaction", () => {
82
85
  getBalances: mockGetBalances,
83
86
  }));
84
87
 
88
+ const SENDER: AptosSender = {
89
+ xpub: "public-key",
90
+ freshAddress: SENDER_ADDR,
91
+ };
85
92
  const api = createApi({
86
93
  aptosSettings: {},
87
94
  });
88
95
 
89
- const txArg: TransactionIntent<AptosAsset> = {
96
+ const txArg: TransactionIntent<AptosAsset, AptosExtra, AptosSender> = {
90
97
  type: "send",
91
- sender: SENDER_ADDR,
92
- senderPublicKey: "public-key",
98
+ sender: SENDER,
93
99
  recipient: RECIPIENT_ADDR,
94
100
  amount: 0n,
95
101
  asset: { type: "native" },
@@ -103,7 +109,7 @@ describe("craftTransaction", () => {
103
109
  expect(mockGenerateTransaction).toHaveBeenCalledTimes(1);
104
110
 
105
111
  expect(mockGenerateTransaction).toHaveBeenCalledWith(
106
- SENDER_ADDR,
112
+ SENDER.freshAddress,
107
113
  expect.objectContaining({
108
114
  function: "0x1::aptos_account::transfer_coins",
109
115
  typeArguments: [APTOS_ASSET_ID],
@@ -123,14 +129,17 @@ describe("craftTransaction", () => {
123
129
  getBalances: mockGetBalances,
124
130
  }));
125
131
 
132
+ const SENDER: AptosSender = {
133
+ xpub: "public-key",
134
+ freshAddress: SENDER_ADDR,
135
+ };
126
136
  const api = createApi({
127
137
  aptosSettings: {},
128
138
  });
129
139
 
130
- const txArg: TransactionIntent<AptosAsset> = {
140
+ const txArg: TransactionIntent<AptosAsset, AptosExtra, AptosSender> = {
131
141
  type: "send",
132
- sender: SENDER_ADDR,
133
- senderPublicKey: "public-key",
142
+ sender: SENDER,
134
143
  recipient: RECIPIENT_ADDR,
135
144
  amount: 10n,
136
145
  asset: { type: "token", standard: "coin", contractAddress: "0x42::token::Token" },
@@ -144,7 +153,7 @@ describe("craftTransaction", () => {
144
153
  expect(mockGenerateTransaction).toHaveBeenCalledTimes(1);
145
154
 
146
155
  expect(mockGenerateTransaction).toHaveBeenCalledWith(
147
- SENDER_ADDR,
156
+ SENDER.freshAddress,
148
157
  expect.objectContaining({
149
158
  function: "0x1::aptos_account::transfer_coins",
150
159
  typeArguments: ["0x42::token::Token"],
@@ -164,14 +173,17 @@ describe("craftTransaction", () => {
164
173
  getBalances: mockGetBalances,
165
174
  }));
166
175
 
176
+ const SENDER: AptosSender = {
177
+ xpub: "public-key",
178
+ freshAddress: SENDER_ADDR,
179
+ };
167
180
  const api = createApi({
168
181
  aptosSettings: {},
169
182
  });
170
183
 
171
- const txArg: TransactionIntent<AptosAsset> = {
184
+ const txArg: TransactionIntent<AptosAsset, AptosExtra, AptosSender> = {
172
185
  type: "send",
173
- sender: SENDER_ADDR,
174
- senderPublicKey: "public-key",
186
+ sender: SENDER,
175
187
  recipient: RECIPIENT_ADDR,
176
188
  amount: 0n,
177
189
  asset: { type: "token", standard: "fungible_asset", contractAddress: "0x42" },
@@ -185,7 +197,7 @@ describe("craftTransaction", () => {
185
197
  expect(mockGenerateTransaction).toHaveBeenCalledTimes(1);
186
198
 
187
199
  expect(mockGenerateTransaction).toHaveBeenCalledWith(
188
- SENDER_ADDR,
200
+ SENDER.freshAddress,
189
201
  expect.objectContaining({
190
202
  function: "0x1::primary_fungible_store::transfer",
191
203
  typeArguments: ["0x1::fungible_asset::Metadata"],
@@ -205,14 +217,17 @@ describe("craftTransaction", () => {
205
217
  getBalances: mockGetBalances,
206
218
  }));
207
219
 
220
+ const SENDER: AptosSender = {
221
+ xpub: "public-key",
222
+ freshAddress: SENDER_ADDR,
223
+ };
208
224
  const api = createApi({
209
225
  aptosSettings: {},
210
226
  });
211
227
 
212
- const txArg: TransactionIntent<AptosAsset> = {
228
+ const txArg: TransactionIntent<AptosAsset, AptosExtra, AptosSender> = {
213
229
  type: "send",
214
- sender: SENDER_ADDR,
215
- senderPublicKey: "public-key",
230
+ sender: SENDER,
216
231
  recipient: RECIPIENT_ADDR,
217
232
  amount: 10n,
218
233
  asset: { type: "token", standard: "asset", contractAddress: "0x42::token::Token" },
@@ -1,98 +1,44 @@
1
1
  import { AptosAPI } from "../../network";
2
- import { APTOS_ASSET_ID, TOKEN_TYPE } from "../../constants";
3
- import type { AptosConfig } from "../../config";
4
- import { createApi } from "../../api";
5
-
6
- jest.mock("@aptos-labs/ts-sdk");
7
- let mockedAptosApi: jest.Mocked<any>;
8
- jest.mock("../../network");
9
- jest.mock("../../config", () => ({
10
- setCoinConfig: jest.fn(),
11
- }));
12
-
13
- const mockAptosConfig: AptosConfig = {} as AptosConfig;
2
+ import { getBalance } from "../../logic/getBalance";
3
+ import { APTOS_ASSET_ID } from "../../constants";
4
+ import BigNumber from "bignumber.js";
5
+
6
+ jest.mock("../../network", () => {
7
+ return {
8
+ AptosAPI: jest.fn().mockImplementation(() => ({
9
+ getBalances: jest.fn(),
10
+ })),
11
+ };
12
+ });
14
13
 
15
14
  describe("getBalance", () => {
16
- beforeEach(() => {
17
- mockedAptosApi = jest.mocked(AptosAPI);
18
- });
19
-
20
- afterEach(() => {
21
- jest.resetAllMocks();
22
- });
23
-
24
- it("should return balance with value 10", async () => {
25
- mockedAptosApi.mockImplementation(() => ({
26
- getBalances: jest.fn().mockResolvedValue([{ contractAddress: APTOS_ASSET_ID, amount: 10n }]),
27
- }));
28
-
29
- const api = createApi(mockAptosConfig);
30
- const accountAddress = "0x4be47904b31063d60ac0dfde06e5dc203e647edbe853bae0e666ae5a763c3906";
31
-
32
- expect(await api.getBalance(accountAddress)).toStrictEqual([
33
- { value: 10n, asset: { type: "native" } },
34
- ]);
35
- });
15
+ let mockGetBalances: jest.Mock;
36
16
 
37
- it("should return empty array when no contract_address and no data", async () => {
38
- mockedAptosApi.mockImplementation(() => ({
39
- getBalances: jest.fn().mockResolvedValue([]),
40
- }));
41
-
42
- const accountAddress = "0xno_contract_and_no_data";
17
+ beforeEach(() => {
18
+ jest.clearAllMocks();
43
19
 
44
- const api = createApi(mockAptosConfig);
45
- expect(await api.getBalance(accountAddress)).toStrictEqual([]);
46
- });
20
+ mockGetBalances = jest
21
+ .fn()
22
+ .mockResolvedValue([{ asset_type: APTOS_ASSET_ID, amount: BigNumber(10) }]);
47
23
 
48
- it("should return balance with 'native' contract_address (APTOS_ASSET_ID)", async () => {
49
- mockedAptosApi.mockImplementation(() => ({
50
- getBalances: jest.fn().mockResolvedValue([{ contractAddress: APTOS_ASSET_ID, amount: 15n }]),
24
+ (AptosAPI as jest.Mock).mockImplementation(() => ({
25
+ getBalances: mockGetBalances,
51
26
  }));
52
-
53
- const api = createApi(mockAptosConfig);
54
- const accountAddress = "0x4be47904b31063d60ac0dfde06e5dc203e647edbe853bae0e666ae5a763c3906";
55
-
56
- expect(await api.getBalance(accountAddress)).toStrictEqual([
57
- { value: 15n, asset: { type: "native" } },
58
- ]);
59
27
  });
60
28
 
61
- it("should return token balance when contract_address is a coin token", async () => {
62
- const TOKEN_ASSET_ID = "0x1::my_token::Token";
63
- mockedAptosApi.mockImplementation(() => ({
64
- getBalances: jest.fn().mockResolvedValue([{ contractAddress: TOKEN_ASSET_ID, amount: 25n }]),
65
- }));
66
-
67
- const api = createApi(mockAptosConfig);
68
- const accountAddress = "0x4be47904b31063d60ac0dfde06e5dc203e647edbe853bae0e666ae5a763c3906";
69
-
70
- expect(await api.getBalance(accountAddress)).toStrictEqual([
71
- {
72
- value: 25n,
73
- asset: { type: "token", contractAddress: TOKEN_ASSET_ID, standard: TOKEN_TYPE.COIN },
74
- },
75
- ]);
29
+ afterEach(() => {
30
+ jest.clearAllMocks();
76
31
  });
77
32
 
78
- it("should return token balance when contract_address is a fungible_asset token", async () => {
79
- const TOKEN_ASSET_ID = "0x1";
80
- mockedAptosApi.mockImplementation(() => ({
81
- getBalances: jest.fn().mockResolvedValue([{ contractAddress: TOKEN_ASSET_ID, amount: 25n }]),
82
- }));
33
+ it("should returns balance with value 10", async () => {
34
+ mockGetBalances.mockResolvedValue([{ asset_type: APTOS_ASSET_ID, amount: new BigNumber(10) }]);
83
35
 
84
- const api = createApi(mockAptosConfig);
85
36
  const accountAddress = "0x4be47904b31063d60ac0dfde06e5dc203e647edbe853bae0e666ae5a763c3906";
37
+ const client = new AptosAPI("aptos");
38
+ const balance = await getBalance(client, accountAddress);
86
39
 
87
- expect(await api.getBalance(accountAddress)).toStrictEqual([
88
- {
89
- value: 25n,
90
- asset: {
91
- type: "token",
92
- contractAddress: TOKEN_ASSET_ID,
93
- standard: TOKEN_TYPE.FUNGIBLE_ASSET,
94
- },
95
- },
96
- ]);
40
+ expect(balance).toBeDefined();
41
+ expect(balance).toMatchObject([{ value: BigInt(10), asset: { type: "native" } }]);
42
+ expect(mockGetBalances).toHaveBeenCalledWith(accountAddress);
97
43
  });
98
44
  });
@@ -1,6 +1,7 @@
1
1
  import { Deserializer, Hex, Network, RawTransaction } from "@aptos-labs/ts-sdk";
2
2
  import { createApi } from "../../api";
3
3
  import { getEnv } from "@ledgerhq/live-env";
4
+ import type { AptosSender } from "../../types/assets";
4
5
  import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "../../constants";
5
6
 
6
7
  describe("createApi", () => {
@@ -11,20 +12,18 @@ describe("createApi", () => {
11
12
  indexer: getEnv("APTOS_INDEXER_ENDPOINT"),
12
13
  },
13
14
  });
14
- const assetTypeNative = "native";
15
- const assetTypeToken = "token";
16
15
 
17
- const sender = {
16
+ const sender: AptosSender = {
18
17
  xpub: "0x934887885b27a0407bf8a5e0bbc6b6371254bea94de5510e948bcc92dc0a519b",
19
18
  freshAddress: "0x0ef3b40f6ecd5583218d1985e0d54b54e8785ad2ec2d27ed1720ec16bb11686f",
20
19
  };
21
20
 
22
- const recipient = {
21
+ const recipient: AptosSender = {
23
22
  xpub: "0x7fd6bfaac17c2c763f624b1f95cd4911e3646a5b777b03cc24f93ed0ac3f3e2b",
24
23
  freshAddress: "0x4859a161dfe13081cf5a5eac409cd38f707c06176a21ddc875260c2ce63f3a28",
25
24
  };
26
25
 
27
- const tokenAccount = {
26
+ const tokenAccount: AptosSender = {
28
27
  xpub: "0xeacada8192f15185637e475d7783e14486e232d8b9978ffa127383847ffc5318",
29
28
  freshAddress: "0xb8922507317d85197d70c2bc1afc949c759fd0a62c8841a4300d1e2b63649bf6",
30
29
  };
@@ -57,8 +56,7 @@ describe("createApi", () => {
57
56
  type: "native",
58
57
  },
59
58
  type: "send",
60
- sender: sender.freshAddress,
61
- senderPublicKey: sender.xpub,
59
+ sender,
62
60
  amount,
63
61
  recipient: recipient.freshAddress,
64
62
  });
@@ -77,8 +75,7 @@ describe("createApi", () => {
77
75
  "0x50788befc1107c0cc4473848a92e5c783c635866ce3c98de71d2eeb7d2a34f85::usdc_coin::USDCoin",
78
76
  },
79
77
  type: "send",
80
- sender: sender.freshAddress,
81
- senderPublicKey: sender.xpub,
78
+ sender,
82
79
  amount,
83
80
  recipient: recipient.freshAddress,
84
81
  });
@@ -96,8 +93,7 @@ describe("createApi", () => {
96
93
  contractAddress: "0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b",
97
94
  },
98
95
  type: "send",
99
- sender: sender.freshAddress,
100
- senderPublicKey: sender.xpub,
96
+ sender,
101
97
  amount,
102
98
  recipient: recipient.freshAddress,
103
99
  });
@@ -111,8 +107,7 @@ describe("createApi", () => {
111
107
  const hex = await api.craftTransaction(
112
108
  {
113
109
  amount: 1n,
114
- sender: sender.freshAddress,
115
- senderPublicKey: sender.xpub,
110
+ sender: sender,
116
111
  recipient: recipient.freshAddress,
117
112
  type: "send",
118
113
  asset: { type: "native" },
@@ -133,8 +128,7 @@ describe("createApi", () => {
133
128
  const hex = await api.craftTransaction(
134
129
  {
135
130
  amount: 1n,
136
- sender: sender.freshAddress,
137
- senderPublicKey: sender.xpub,
131
+ sender: sender,
138
132
  recipient: recipient.freshAddress,
139
133
  type: "send",
140
134
  asset: {
@@ -160,8 +154,7 @@ describe("createApi", () => {
160
154
  const hex = await api.craftTransaction(
161
155
  {
162
156
  amount: 0n,
163
- sender: sender.freshAddress,
164
- senderPublicKey: sender.xpub,
157
+ sender: sender,
165
158
  recipient: recipient.freshAddress,
166
159
  type: "send",
167
160
  asset: {
@@ -189,8 +182,7 @@ describe("createApi", () => {
189
182
  const hex = await api.craftTransaction(
190
183
  {
191
184
  amount: 0n,
192
- sender: s.freshAddress,
193
- senderPublicKey: s.xpub,
185
+ sender: s,
194
186
  recipient: r.freshAddress,
195
187
  type: "send",
196
188
  asset: {
@@ -212,25 +204,12 @@ describe("createApi", () => {
212
204
  });
213
205
  });
214
206
 
215
- describe("getBalances", () => {
216
- it("returned balances should have one native asset", async () => {
207
+ describe("getBalance", () => {
208
+ it("return balances from account", async () => {
217
209
  const balances = await api.getBalance(sender.freshAddress);
218
- const nativeBalance = balances.filter(b => b.asset.type === assetTypeNative);
219
- expect(nativeBalance.length).toBe(1);
220
- expect(nativeBalance[0].value).toBeGreaterThan(0);
221
- });
222
210
 
223
- it("returned balances should have a token asset", async () => {
224
- const balances = await api.getBalance(tokenAccount.freshAddress);
225
- const tokenBalances = balances.filter(
226
- b =>
227
- b.asset.type === assetTypeToken &&
228
- b.asset.contractAddress ===
229
- "0x2ebb2ccac5e027a87fa0e2e5f656a3a4238d6a48d93ec9b610d570fc0aa0df12",
230
- );
231
- expect(tokenBalances.length).toBeGreaterThan(0);
232
- expect(balances.length).toBeGreaterThan(1);
233
- expect(balances[0].value).toBeGreaterThan(0);
211
+ expect(balances.length).toBeGreaterThan(0);
212
+ expect(balances[0].value).toBeGreaterThanOrEqual(0);
234
213
  });
235
214
  });
236
215
 
@@ -1,6 +1,6 @@
1
1
  import { Aptos } from "@aptos-labs/ts-sdk";
2
- import type { AlpacaApi } from "@ledgerhq/coin-framework/api/types";
3
- import type { AptosAsset } from "../../types/assets";
2
+ import type { Api } from "@ledgerhq/coin-framework/api/types";
3
+ import type { AptosAsset, AptosExtra, AptosFeeParameters, AptosSender } from "../../types/assets";
4
4
  import type { AptosConfig } from "../../config";
5
5
  import { createApi } from "../../api";
6
6
  import coinConfig from "../../config";
@@ -33,7 +33,8 @@ describe("createApi", () => {
33
33
  });
34
34
 
35
35
  it("should return an API object with alpaca api methods", () => {
36
- const api: AlpacaApi<AptosAsset> = createApi(mockAptosConfig);
36
+ const api: Api<AptosAsset, AptosExtra, AptosSender, AptosFeeParameters> =
37
+ createApi(mockAptosConfig);
37
38
 
38
39
  // Check that methods are set with what we expect
39
40
  expect(api.broadcast).toBeDefined();
@@ -69,7 +70,8 @@ describe("lastBlock", () => {
69
70
  }),
70
71
  }));
71
72
 
72
- const api: AlpacaApi<AptosAsset> = createApi(mockAptosConfig);
73
+ const api: Api<AptosAsset, AptosExtra, AptosSender, AptosFeeParameters> =
74
+ createApi(mockAptosConfig);
73
75
 
74
76
  expect(await api.lastBlock()).toStrictEqual({
75
77
  height: 123,
@@ -798,15 +798,10 @@ describe("getAccountShape", () => {
798
798
  blockHeight: 316278241,
799
799
  }));
800
800
 
801
- const TOKEN_CONTRACT_ADDRESS = "0xd111::staked_coin::StakedAptos";
802
-
803
- const mockGetBalances = jest
804
- .fn()
805
- .mockResolvedValue([{ contractAddress: TOKEN_CONTRACT_ADDRESS, amount: BigNumber(1234567) }]);
806
-
801
+ const mockGetBalance = jest.fn().mockImplementation(() => BigNumber(5000000));
807
802
  mockedAptosAPI.mockImplementation(() => ({
808
- getBalances: mockGetBalances,
809
803
  getAccountInfo: mockGetAccountInfo,
804
+ getBalance: mockGetBalance,
810
805
  }));
811
806
 
812
807
  const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
@@ -1317,14 +1312,9 @@ describe("getSubAccountShape", () => {
1317
1312
  ] as Operation[];
1318
1313
 
1319
1314
  it("returns the correct information", async () => {
1320
- const TOKEN_CONTRACT_ADDRESS = "0xd111::staked_coin::StakedAptos";
1321
-
1322
- const mockGetBalances = jest
1323
- .fn()
1324
- .mockResolvedValue([{ contractAddress: TOKEN_CONTRACT_ADDRESS, amount: BigNumber(1234567) }]);
1325
-
1315
+ const mockGetBalance = jest.fn().mockImplementation(() => BigNumber(1234567));
1326
1316
  mockedAptosAPI.mockImplementation(() => ({
1327
- getBalances: mockGetBalances,
1317
+ getBalance: mockGetBalance,
1328
1318
  }));
1329
1319
 
1330
1320
  const subAccount = await getSubAccountShape(currency, address, parentId, token, operations);
@@ -1431,14 +1421,9 @@ describe("getSubAccounts", () => {
1431
1421
  ] as Operation[];
1432
1422
 
1433
1423
  it("returns the correct information", async () => {
1434
- const TOKEN_CONTRACT_ADDRESS = "0xd111::staked_coin::StakedAptos";
1435
-
1436
- const mockGetBalances = jest
1437
- .fn()
1438
- .mockResolvedValue([{ contractAddress: TOKEN_CONTRACT_ADDRESS, amount: BigNumber(1234567) }]);
1439
-
1424
+ const mockGetBalance = jest.fn().mockImplementation(() => BigNumber(1234567));
1440
1425
  mockedAptosAPI.mockImplementation(() => ({
1441
- getBalances: mockGetBalances,
1426
+ getBalance: mockGetBalance,
1442
1427
  }));
1443
1428
 
1444
1429
  mockedDecodeTokenAccountId.mockReturnValue({