@ledgerhq/coin-aptos 1.10.0-nightly.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 (175) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +18 -6
  3. package/CHANGELOG.md +6 -0
  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 -460
  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 +6 -6
  14. package/lib/__tests__/bridge/buildTransaction.test.js.map +1 -1
  15. package/lib/__tests__/bridge/getFeesForTransaction.test.js +9 -9
  16. package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  17. package/lib/__tests__/bridge/prepareTransaction.test.js +3 -3
  18. package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -1
  19. package/lib/__tests__/bridge/signOperation.test.js +3 -2
  20. package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
  21. package/lib/__tests__/bridge/synchronisation.test.js +6 -6
  22. package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
  23. package/lib/__tests__/network/client.test.d.ts +2 -0
  24. package/lib/__tests__/network/client.test.d.ts.map +1 -0
  25. package/lib/__tests__/network/client.test.js +478 -0
  26. package/lib/__tests__/network/client.test.js.map +1 -0
  27. package/lib/api/index.d.ts +4 -33
  28. package/lib/api/index.d.ts.map +1 -1
  29. package/lib/api/index.js +26 -196
  30. package/lib/api/index.js.map +1 -1
  31. package/lib/bridge/broadcast.d.ts +3 -2
  32. package/lib/bridge/broadcast.d.ts.map +1 -1
  33. package/lib/bridge/broadcast.js +4 -3
  34. package/lib/bridge/broadcast.js.map +1 -1
  35. package/lib/bridge/buildTransaction.d.ts +1 -1
  36. package/lib/bridge/buildTransaction.d.ts.map +1 -1
  37. package/lib/bridge/buildTransaction.js.map +1 -1
  38. package/lib/bridge/estimateMaxSpendable.js +2 -2
  39. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  40. package/lib/bridge/getFeesForTransaction.d.ts +1 -1
  41. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  42. package/lib/bridge/index.d.ts +1 -1
  43. package/lib/bridge/index.d.ts.map +1 -1
  44. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  45. package/lib/bridge/prepareTransaction.js +2 -2
  46. package/lib/bridge/prepareTransaction.js.map +1 -1
  47. package/lib/bridge/signOperation.js +3 -3
  48. package/lib/bridge/signOperation.js.map +1 -1
  49. package/lib/bridge/synchronisation.js +3 -3
  50. package/lib/bridge/synchronisation.js.map +1 -1
  51. package/lib/config.d.ts +13 -0
  52. package/lib/config.d.ts.map +1 -0
  53. package/lib/config.js +9 -0
  54. package/lib/config.js.map +1 -0
  55. package/lib/network/client.d.ts +34 -0
  56. package/lib/network/client.d.ts.map +1 -0
  57. package/lib/network/client.js +213 -0
  58. package/lib/network/client.js.map +1 -0
  59. package/lib/network/graphql/queries.d.ts.map +1 -0
  60. package/lib/network/graphql/queries.js.map +1 -0
  61. package/lib/network/graphql/types.d.ts.map +1 -0
  62. package/lib/{api → network}/graphql/types.js.map +1 -1
  63. package/lib/network/index.d.ts +2 -1
  64. package/lib/network/index.d.ts.map +1 -1
  65. package/lib/network/index.js +15 -0
  66. package/lib/network/index.js.map +1 -1
  67. package/lib/types/assets.d.ts +3 -0
  68. package/lib/types/assets.d.ts.map +1 -0
  69. package/lib/types/assets.js +3 -0
  70. package/lib/types/assets.js.map +1 -0
  71. package/lib-es/__tests__/api/index.integ.test.d.ts +2 -0
  72. package/lib-es/__tests__/api/index.integ.test.d.ts.map +1 -0
  73. package/lib-es/__tests__/api/index.integ.test.js +20 -0
  74. package/lib-es/__tests__/api/index.integ.test.js.map +1 -0
  75. package/lib-es/__tests__/api/index.test.js +52 -464
  76. package/lib-es/__tests__/api/index.test.js.map +1 -1
  77. package/lib-es/__tests__/bridge/broadcast.test.js +2 -2
  78. package/lib-es/__tests__/bridge/broadcast.test.js.map +1 -1
  79. package/lib-es/__tests__/bridge/buildTransaction.test.js +2 -2
  80. package/lib-es/__tests__/bridge/buildTransaction.test.js.map +1 -1
  81. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +2 -2
  82. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  83. package/lib-es/__tests__/bridge/prepareTransaction.test.js +2 -2
  84. package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -1
  85. package/lib-es/__tests__/bridge/signOperation.test.js +3 -2
  86. package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
  87. package/lib-es/__tests__/bridge/synchronisation.test.js +3 -3
  88. package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
  89. package/lib-es/__tests__/network/client.test.d.ts +2 -0
  90. package/lib-es/__tests__/network/client.test.d.ts.map +1 -0
  91. package/lib-es/__tests__/network/client.test.js +473 -0
  92. package/lib-es/__tests__/network/client.test.js.map +1 -0
  93. package/lib-es/api/index.d.ts +4 -33
  94. package/lib-es/api/index.d.ts.map +1 -1
  95. package/lib-es/api/index.js +24 -194
  96. package/lib-es/api/index.js.map +1 -1
  97. package/lib-es/bridge/broadcast.d.ts +3 -2
  98. package/lib-es/bridge/broadcast.d.ts.map +1 -1
  99. package/lib-es/bridge/broadcast.js +4 -3
  100. package/lib-es/bridge/broadcast.js.map +1 -1
  101. package/lib-es/bridge/buildTransaction.d.ts +1 -1
  102. package/lib-es/bridge/buildTransaction.d.ts.map +1 -1
  103. package/lib-es/bridge/buildTransaction.js.map +1 -1
  104. package/lib-es/bridge/estimateMaxSpendable.js +1 -1
  105. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  106. package/lib-es/bridge/getFeesForTransaction.d.ts +1 -1
  107. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  108. package/lib-es/bridge/index.d.ts +1 -1
  109. package/lib-es/bridge/index.d.ts.map +1 -1
  110. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  111. package/lib-es/bridge/prepareTransaction.js +1 -1
  112. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  113. package/lib-es/bridge/signOperation.js +1 -1
  114. package/lib-es/bridge/signOperation.js.map +1 -1
  115. package/lib-es/bridge/synchronisation.js +1 -1
  116. package/lib-es/bridge/synchronisation.js.map +1 -1
  117. package/lib-es/config.d.ts +13 -0
  118. package/lib-es/config.d.ts.map +1 -0
  119. package/lib-es/config.js +4 -0
  120. package/lib-es/config.js.map +1 -0
  121. package/lib-es/network/client.d.ts +34 -0
  122. package/lib-es/network/client.d.ts.map +1 -0
  123. package/lib-es/network/client.js +206 -0
  124. package/lib-es/network/client.js.map +1 -0
  125. package/lib-es/network/graphql/queries.d.ts.map +1 -0
  126. package/lib-es/network/graphql/queries.js.map +1 -0
  127. package/lib-es/network/graphql/types.d.ts.map +1 -0
  128. package/lib-es/{api → network}/graphql/types.js.map +1 -1
  129. package/lib-es/network/index.d.ts +2 -1
  130. package/lib-es/network/index.d.ts.map +1 -1
  131. package/lib-es/network/index.js +1 -0
  132. package/lib-es/network/index.js.map +1 -1
  133. package/lib-es/types/assets.d.ts +3 -0
  134. package/lib-es/types/assets.d.ts.map +1 -0
  135. package/lib-es/types/assets.js +2 -0
  136. package/lib-es/types/assets.js.map +1 -0
  137. package/package.json +2 -1
  138. package/src/__tests__/api/index.integ.test.ts +24 -0
  139. package/src/__tests__/api/index.test.ts +58 -547
  140. package/src/__tests__/bridge/broadcast.test.ts +2 -2
  141. package/src/__tests__/bridge/buildTransaction.test.ts +2 -2
  142. package/src/__tests__/bridge/getFeesForTransaction.test.ts +2 -2
  143. package/src/__tests__/bridge/prepareTransaction.test.ts +2 -2
  144. package/src/__tests__/bridge/signOperation.test.ts +6 -3
  145. package/src/__tests__/bridge/synchronisation.test.ts +4 -4
  146. package/src/__tests__/network/client.test.ts +569 -0
  147. package/src/api/index.ts +30 -250
  148. package/src/bridge/broadcast.ts +7 -7
  149. package/src/bridge/buildTransaction.ts +1 -1
  150. package/src/bridge/estimateMaxSpendable.ts +1 -1
  151. package/src/bridge/getFeesForTransaction.ts +1 -1
  152. package/src/bridge/index.ts +1 -1
  153. package/src/bridge/prepareTransaction.ts +2 -1
  154. package/src/bridge/signOperation.ts +1 -1
  155. package/src/bridge/synchronisation.ts +1 -1
  156. package/src/config.ts +19 -0
  157. package/src/network/client.ts +265 -0
  158. package/src/network/index.ts +2 -1
  159. package/src/types/assets.ts +3 -0
  160. package/lib/api/graphql/queries.d.ts.map +0 -1
  161. package/lib/api/graphql/queries.js.map +0 -1
  162. package/lib/api/graphql/types.d.ts.map +0 -1
  163. package/lib-es/api/graphql/queries.d.ts.map +0 -1
  164. package/lib-es/api/graphql/queries.js.map +0 -1
  165. package/lib-es/api/graphql/types.d.ts.map +0 -1
  166. /package/lib/{api → network}/graphql/queries.d.ts +0 -0
  167. /package/lib/{api → network}/graphql/queries.js +0 -0
  168. /package/lib/{api → network}/graphql/types.d.ts +0 -0
  169. /package/lib/{api → network}/graphql/types.js +0 -0
  170. /package/lib-es/{api → network}/graphql/queries.d.ts +0 -0
  171. /package/lib-es/{api → network}/graphql/queries.js +0 -0
  172. /package/lib-es/{api → network}/graphql/types.d.ts +0 -0
  173. /package/lib-es/{api → network}/graphql/types.js +0 -0
  174. /package/src/{api → network}/graphql/queries.ts +0 -0
  175. /package/src/{api → network}/graphql/types.ts +0 -0
@@ -1,4 +1,4 @@
1
1
 
2
- > @ledgerhq/coin-aptos@1.9.5 build /home/runner/work/ledger-live/ledger-live/libs/coin-modules/coin-aptos
2
+ > @ledgerhq/coin-aptos@1.10.0-nightly.0 build /home/runner/work/ledger-live/ledger-live/libs/coin-modules/coin-aptos
3
3
  > tsc --outDir lib --module commonjs --moduleResolution node10 && tsc -m ES6 --outDir lib-es
4
4
 
@@ -1,16 +1,28 @@
1
1
  {
2
- "ignoreUnresolved": ["follow-redirects", "form-data", "proxy-from-env"],
3
- "ignoreUnused": ["@ledgerhq/devices", "invariant", "expect"],
2
+ "entry": [
3
+ "src/index.ts",
4
+ "src/api/index.ts",
5
+ "src/bridge/index.ts",
6
+ "src/network/index.ts",
7
+ "src/signer/index.ts"
8
+ ],
9
+ "ignoreUnused": [
10
+ "@ledgerhq/devices",
11
+ "@ledgerhq/types-cryptoassets",
12
+ "expect",
13
+ "invariant"
14
+ ],
4
15
  "ignoreUnimported": [
16
+ "src/bridge/bridge.fixture.ts",
5
17
  "src/bridge/deviceTransactionConfig.ts",
6
18
  "src/bridge/transaction.ts",
7
- "src/bridge/bridge.fixture.ts",
19
+ "src/config.ts",
8
20
  "src/errors.ts",
9
- "src/hw-signMessage.ts",
10
21
  "src/test/bot-specs.ts",
11
22
  "src/test/bridgeDatasetTest.ts",
12
23
  "src/test/cli.ts",
13
24
  "src/test/index.ts",
14
- "src/test/speculos-deviceActions.ts"
25
+ "src/test/speculos-deviceActions.ts",
26
+ "src/types/assets.ts"
15
27
  ]
16
- }
28
+ }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ledgerhq/coin-aptos
2
2
 
3
+ ## 2.0.0-nightly.1
4
+
5
+ ### Major Changes
6
+
7
+ - [#10144](https://github.com/LedgerHQ/ledger-live/pull/10144) [`20ccc74`](https://github.com/LedgerHQ/ledger-live/commit/20ccc74b61e67906071f4a264497e6a9feac5b53) Thanks [@pvoliveira](https://github.com/pvoliveira)! - add initial Alpaca API integration for Aptos
8
+
3
9
  ## 1.10.0-nightly.0
4
10
 
5
11
  ### Minor Changes
@@ -0,0 +1,8 @@
1
+ /** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */
2
+ module.exports = {
3
+ preset: "ts-jest",
4
+ testEnvironment: "node",
5
+ testRegex: ".integ.test.ts$",
6
+ testPathIgnorePatterns: ["lib/", "lib-es/"],
7
+ testTimeout: 60000,
8
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.integ.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.integ.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/api/index.integ.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ts_sdk_1 = require("@aptos-labs/ts-sdk");
4
+ const api_1 = require("../../api");
5
+ describe("createApi", () => {
6
+ const api = (0, api_1.createApi)({ aptosSettings: { network: ts_sdk_1.Network.MAINNET } });
7
+ describe("lastBlock", () => {
8
+ it("returns the last block information", async () => {
9
+ const lastBlock = await api.lastBlock();
10
+ expect(lastBlock).toHaveProperty("hash");
11
+ expect(ts_sdk_1.Hex.isValid(lastBlock.hash ?? "").valid).toBeTruthy();
12
+ expect(lastBlock).toHaveProperty("height");
13
+ expect(lastBlock.height).toBeGreaterThan(0);
14
+ expect(lastBlock).toHaveProperty("time");
15
+ expect(lastBlock.time).not.toBeUndefined();
16
+ expect(lastBlock.time?.getFullYear()).toBeGreaterThan(0);
17
+ expect(lastBlock.time?.getMonth()).toBeGreaterThan(0);
18
+ expect(lastBlock.time?.getDay()).toBeGreaterThan(0);
19
+ });
20
+ });
21
+ });
22
+ //# sourceMappingURL=index.integ.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.integ.test.js","sourceRoot":"","sources":["../../../src/__tests__/api/index.integ.test.ts"],"names":[],"mappings":";;AAAA,+CAAkD;AAClD,mCAAsC;AAEtC,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,MAAM,GAAG,GAAG,IAAA,eAAS,EAAC,EAAE,aAAa,EAAE,EAAE,OAAO,EAAE,gBAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAEvE,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;QACzB,EAAE,CAAC,oCAAoC,EAAE,KAAK,IAAI,EAAE;YAClD,MAAM,SAAS,GAAG,MAAM,GAAG,CAAC,SAAS,EAAE,CAAC;YAExC,MAAM,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACzC,MAAM,CAAC,YAAG,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,CAAC;YAE7D,MAAM,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;YAC3C,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YAE5C,MAAM,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACzC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;YAC3C,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YACzD,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YACtD,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -3,475 +3,63 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const client_1 = require("@apollo/client");
7
6
  const ts_sdk_1 = require("@aptos-labs/ts-sdk");
8
- const live_network_1 = __importDefault(require("@ledgerhq/live-network"));
9
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
10
7
  const api_1 = require("../../api");
8
+ const config_1 = __importDefault(require("../../config"));
11
9
  jest.mock("@aptos-labs/ts-sdk");
12
- jest.mock("@apollo/client");
13
10
  let mockedAptos;
14
- let mockedApolloClient;
15
- let mockedPost = jest.fn();
16
- jest.mock("@ledgerhq/live-network/network");
17
- const mockedNetwork = jest.mocked(live_network_1.default);
18
- describe("Aptos API", () => {
19
- beforeEach(() => {
20
- mockedAptos = jest.mocked(ts_sdk_1.Aptos);
21
- mockedApolloClient = jest.mocked(client_1.ApolloClient);
22
- mockedPost = jest.mocked(ts_sdk_1.post);
23
- });
24
- afterEach(() => jest.clearAllMocks());
25
- it("builds the client properly for mainnet", () => {
26
- const api = new api_1.AptosAPI("aptos");
27
- expect(api.broadcast).toBeDefined();
28
- expect(typeof api.broadcast).toBe("function");
29
- expect(api.estimateGasPrice).toBeDefined();
30
- expect(typeof api.estimateGasPrice).toBe("function");
31
- expect(api.generateTransaction).toBeDefined();
32
- expect(typeof api.generateTransaction).toBe("function");
33
- expect(api.getAccount).toBeDefined();
34
- expect(typeof api.getAccount).toBe("function");
35
- expect(api.getAccountInfo).toBeDefined();
36
- expect(typeof api.getAccountInfo).toBe("function");
37
- expect(api.simulateTransaction).toBeDefined();
38
- expect(typeof api.simulateTransaction).toBe("function");
11
+ jest.mock("../../config", () => ({
12
+ setCoinConfig: jest.fn(),
13
+ }));
14
+ const mockAptosConfig = {};
15
+ describe("createApi", () => {
16
+ it("should set the coin config value", () => {
17
+ const setCoinConfigSpy = jest.spyOn(config_1.default, "setCoinConfig");
18
+ (0, api_1.createApi)(mockAptosConfig);
19
+ const config = setCoinConfigSpy.mock.calls[0][0]();
20
+ expect(setCoinConfigSpy).toHaveBeenCalled();
21
+ expect(config).toEqual(expect.objectContaining({
22
+ ...mockAptosConfig,
23
+ status: { type: "active" },
24
+ }));
39
25
  });
40
- it("builds the client properly for testnet", () => {
41
- const api = new api_1.AptosAPI("aptos_testnet");
26
+ it("should return an API object with alpaca api methods", () => {
27
+ const api = (0, api_1.createApi)(mockAptosConfig);
28
+ // Check that methods are set with what we expect
42
29
  expect(api.broadcast).toBeDefined();
43
- expect(typeof api.broadcast).toBe("function");
44
- expect(api.estimateGasPrice).toBeDefined();
45
- expect(typeof api.estimateGasPrice).toBe("function");
46
- expect(api.generateTransaction).toBeDefined();
47
- expect(typeof api.generateTransaction).toBe("function");
48
- expect(api.getAccount).toBeDefined();
49
- expect(typeof api.getAccount).toBe("function");
50
- expect(api.getAccountInfo).toBeDefined();
51
- expect(typeof api.getAccountInfo).toBe("function");
52
- expect(api.simulateTransaction).toBeDefined();
53
- expect(typeof api.simulateTransaction).toBe("function");
30
+ expect(api.combine).toBeDefined();
31
+ expect(api.craftTransaction).toBeDefined();
32
+ expect(api.estimateFees).toBeDefined();
33
+ expect(api.getBalance).toBeDefined();
34
+ expect(api.lastBlock).toBeDefined();
35
+ expect(api.listOperations).toBeDefined();
54
36
  });
55
- describe("getAccount", () => {
56
- it("calls getAccountInfo", async () => {
57
- const mockGetAccountInfo = jest.fn();
58
- mockedAptos.mockImplementation(() => ({
59
- getAccountInfo: mockGetAccountInfo,
60
- }));
61
- const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
62
- const api = new api_1.AptosAPI("aptos");
63
- await api.getAccount("address");
64
- expect(mockGetAccountSpy).toHaveBeenCalledWith({
65
- accountAddress: "address",
66
- });
67
- });
68
- });
69
- describe("getBalance", () => {
70
- let token;
71
- beforeEach(() => {
72
- token = {
73
- type: "TokenCurrency",
74
- id: "aptos_token",
75
- name: "Aptos Token",
76
- ticker: "APT",
77
- units: [{ name: "APT", code: "APT", magnitude: 6 }],
78
- contractAddress: "APTOS_1_ADDRESS",
79
- tokenType: "fungible_asset",
80
- parentCurrency: {
81
- type: "CryptoCurrency",
82
- id: "aptos",
83
- name: "Aptos",
84
- ticker: "APT",
85
- units: [{ name: "APT", code: "APT", magnitude: 6 }],
86
- color: "#000000",
87
- family: "aptos",
88
- scheme: "aptos",
89
- explorerViews: [],
90
- managerAppName: "Aptos",
91
- coinType: 637,
92
- },
93
- };
94
- });
95
- it("get coin balance", async () => {
96
- mockedAptos.mockImplementation(() => ({
97
- view: jest.fn().mockReturnValue(["1234"]),
98
- }));
99
- token.tokenType = "coin";
100
- const api = new api_1.AptosAPI("aptos");
101
- const balance = await api.getBalance("address", token);
102
- expect(balance).toEqual(new bignumber_js_1.default(1234));
103
- });
104
- it("get fungible assets balance", async () => {
105
- mockedAptos.mockImplementation(() => ({
106
- view: jest.fn().mockReturnValue(["12345"]),
107
- }));
108
- token.tokenType = "fungible_asset";
109
- const api = new api_1.AptosAPI("aptos");
110
- const balance = await api.getBalance("address", token);
111
- expect(balance).toEqual(new bignumber_js_1.default(12345));
112
- });
113
- it("return 0 balace if could not retrieve proper balance of fungible assets", async () => {
114
- mockedAptos.mockImplementation(() => ({
115
- view: jest.fn().mockImplementation(() => {
116
- throw new Error("error");
117
- }),
118
- }));
119
- token.tokenType = "fungible_asset";
120
- const api = new api_1.AptosAPI("aptos");
121
- const balance = await api.getBalance("address", token);
122
- expect(balance).toEqual(new bignumber_js_1.default(0));
123
- });
124
- });
125
- describe("getAccountInfo", () => {
126
- it("calls getCoinBalance, fetchTransactions and getHeight", async () => {
127
- mockedAptos.mockImplementation(() => ({
128
- view: jest.fn().mockReturnValue(["123"]),
129
- getTransactionByVersion: jest.fn().mockReturnValue({
130
- type: "user_transaction",
131
- version: "v1",
132
- }),
133
- getBlockByVersion: jest.fn().mockReturnValue({
134
- block_height: "1",
135
- block_hash: "83ca6d",
136
- }),
137
- }));
138
- mockedNetwork.mockResolvedValue(Promise.resolve({
139
- data: {
140
- account: {
141
- account_number: 1,
142
- sequence: 0,
143
- pub_key: { key: "k", "@type": "type" },
144
- base_account: {
145
- account_number: 2,
146
- sequence: 42,
147
- pub_key: { key: "k2", "@type": "type2" },
148
- },
149
- },
150
- block_height: "999",
151
- },
152
- status: 200,
153
- headers: {},
154
- statusText: "",
155
- config: {
156
- headers: {},
157
- },
158
- }));
159
- mockedApolloClient.mockImplementation(() => ({
160
- query: async () => ({
161
- data: {
162
- account_transactions: [{ transaction_version: 1 }],
163
- },
164
- loading: false,
165
- networkStatus: 7,
166
- }),
167
- }));
168
- const api = new api_1.AptosAPI("aptos");
169
- const accountInfo = await api.getAccountInfo("APTOS_1_ADDRESS", "1");
170
- expect(accountInfo.balance).toEqual(new bignumber_js_1.default(123));
171
- expect(accountInfo.transactions).toEqual([
172
- {
173
- type: "user_transaction",
174
- version: "v1",
175
- block: {
176
- height: 1,
177
- hash: "83ca6d",
178
- },
179
- },
180
- ]);
181
- expect(accountInfo.blockHeight).toEqual(999);
182
- });
183
- it("return balance = 0 if it fails to fetch balance", async () => {
184
- mockedAptos.mockImplementation(() => ({
185
- view: jest.fn().mockImplementation(() => {
186
- throw new Error("error");
187
- }),
188
- getTransactionByVersion: jest.fn().mockReturnValue({
189
- type: "user_transaction",
190
- version: "v1",
191
- }),
192
- getBlockByVersion: jest.fn().mockReturnValue({
193
- block_height: "1",
194
- block_hash: "83ca6d",
195
- }),
196
- }));
197
- mockedNetwork.mockResolvedValue(Promise.resolve({
198
- data: {
199
- account: {
200
- account_number: 1,
201
- sequence: 0,
202
- pub_key: { key: "k", "@type": "type" },
203
- base_account: {
204
- account_number: 2,
205
- sequence: 42,
206
- pub_key: { key: "k2", "@type": "type2" },
207
- },
208
- },
209
- block_height: "999",
210
- },
211
- status: 200,
212
- headers: {},
213
- statusText: "",
214
- config: {
215
- headers: {},
216
- },
217
- }));
218
- mockedApolloClient.mockImplementation(() => ({
219
- query: async () => ({
220
- data: {
221
- account_transactions: [{ transaction_version: 1 }],
222
- },
223
- loading: false,
224
- networkStatus: 7,
225
- }),
226
- }));
227
- const api = new api_1.AptosAPI("aptos");
228
- const accountInfo = await api.getAccountInfo("APTOS_1_ADDRESS", "1");
229
- expect(accountInfo.balance).toEqual(new bignumber_js_1.default(0));
230
- expect(accountInfo.transactions).toEqual([
231
- {
232
- type: "user_transaction",
233
- version: "v1",
234
- block: {
235
- height: 1,
236
- hash: "83ca6d",
237
- },
238
- },
239
- ]);
240
- expect(accountInfo.blockHeight).toEqual(999);
241
- });
242
- it("returns no transactions if it the address is empty", async () => {
243
- mockedAptos.mockImplementation(() => ({
244
- view: jest.fn().mockReturnValue(["123"]),
245
- getTransactionByVersion: jest.fn().mockReturnValue({
246
- type: "user_transaction",
247
- version: "v1",
248
- }),
249
- getBlockByVersion: jest.fn().mockReturnValue({
250
- block_height: "1",
251
- block_hash: "83ca6d",
252
- }),
253
- }));
254
- mockedNetwork.mockResolvedValue(Promise.resolve({
255
- data: {
256
- account: {
257
- account_number: 1,
258
- sequence: 0,
259
- pub_key: { key: "k", "@type": "type" },
260
- base_account: {
261
- account_number: 2,
262
- sequence: 42,
263
- pub_key: { key: "k2", "@type": "type2" },
264
- },
265
- },
266
- block_height: "999",
267
- },
268
- status: 200,
269
- headers: {},
270
- statusText: "",
271
- config: {
272
- headers: {},
273
- },
274
- }));
275
- mockedApolloClient.mockImplementation(() => ({
276
- query: async () => ({
277
- data: {
278
- account_transactions: [{ transaction_version: 1 }],
279
- },
280
- loading: false,
281
- networkStatus: 7,
282
- }),
283
- }));
284
- const api = new api_1.AptosAPI("aptos");
285
- const accountInfo = await api.getAccountInfo("", "1");
286
- expect(accountInfo.balance).toEqual(new bignumber_js_1.default(123));
287
- expect(accountInfo.transactions).toEqual([]);
288
- expect(accountInfo.blockHeight).toEqual(999);
289
- });
290
- it("returns a null transaction if it fails to getTransactionByVersion", async () => {
291
- mockedAptos.mockImplementation(() => ({
292
- view: jest.fn().mockReturnValue(["123"]),
293
- getTransactionByVersion: jest.fn().mockImplementation(() => {
294
- throw new Error("error");
295
- }),
296
- getBlockByVersion: jest.fn().mockReturnValue({
297
- block_height: "1",
298
- block_hash: "83ca6d",
299
- }),
300
- }));
301
- mockedNetwork.mockResolvedValue(Promise.resolve({
302
- data: {
303
- account: {
304
- account_number: 1,
305
- sequence: 0,
306
- pub_key: { key: "k", "@type": "type" },
307
- base_account: {
308
- account_number: 2,
309
- sequence: 42,
310
- pub_key: { key: "k2", "@type": "type2" },
311
- },
312
- },
313
- block_height: "999",
314
- },
315
- status: 200,
316
- headers: {},
317
- statusText: "",
318
- config: {
319
- headers: {},
320
- },
321
- }));
322
- mockedApolloClient.mockImplementation(() => ({
323
- query: async () => ({
324
- data: {
325
- account_transactions: [{ transaction_version: 1 }],
326
- },
327
- loading: false,
328
- networkStatus: 7,
329
- }),
330
- }));
331
- const api = new api_1.AptosAPI("aptos");
332
- const accountInfo = await api.getAccountInfo("APTOS_1_ADDRESS", "1");
333
- expect(accountInfo.balance).toEqual(new bignumber_js_1.default(123));
334
- expect(accountInfo.transactions).toEqual([null]);
335
- expect(accountInfo.blockHeight).toEqual(999);
336
- });
337
- });
338
- describe("estimateGasPrice", () => {
339
- it("estimates the gas price", async () => {
340
- const gasEstimation = { gas_estimate: 100 };
341
- mockedAptos.mockImplementation(() => ({
342
- getGasPriceEstimation: jest.fn().mockReturnValue(gasEstimation),
343
- }));
344
- const api = new api_1.AptosAPI("aptos");
345
- const gasPrice = await api.estimateGasPrice();
346
- expect(gasPrice.gas_estimate).toEqual(100);
347
- });
348
- });
349
- describe("generateTransaction", () => {
350
- const payload = {
351
- function: "0x1::coin::transfer",
352
- functionArguments: ["0x13", 1],
353
- };
354
- it("generates a transaction without expireTimestamp", async () => {
355
- const options = {
356
- maxGasAmount: "100",
357
- gasUnitPrice: "50",
358
- };
359
- const mockSimple = jest.fn().mockImplementation(async () => ({
360
- rawTransaction: null,
361
- }));
362
- mockedAptos.mockImplementation(() => ({
363
- transaction: {
364
- build: {
365
- simple: mockSimple,
366
- },
367
- },
368
- }));
369
- const mockSimpleSpy = jest.spyOn({ simple: mockSimple }, "simple");
370
- const api = new api_1.AptosAPI("aptos");
371
- await api.generateTransaction("APTOS_1_ADDRESS", payload, options);
372
- expect(mockSimpleSpy).toHaveBeenCalledWith({
373
- data: payload,
374
- options: {
375
- maxGasAmount: Number(options.maxGasAmount),
376
- gasUnitPrice: Number(options.gasUnitPrice),
377
- },
378
- sender: "APTOS_1_ADDRESS",
379
- });
380
- });
381
- it("generates a transaction with default expireTimestamp", async () => {
382
- const options = {
383
- maxGasAmount: "100",
384
- gasUnitPrice: "50",
385
- };
386
- const mockSimple = jest.fn().mockImplementation(async () => ({
387
- rawTransaction: null,
388
- }));
389
- const mockGetLedgerInfo = jest.fn().mockImplementation(async () => ({
390
- ledger_timestamp: "0",
391
- }));
392
- mockedAptos.mockImplementation(() => ({
393
- transaction: {
394
- build: {
395
- simple: mockSimple,
396
- },
397
- },
398
- getLedgerInfo: mockGetLedgerInfo,
399
- }));
400
- const mockSimpleSpy = jest.spyOn({ simple: mockSimple }, "simple");
401
- const api = new api_1.AptosAPI("aptos");
402
- await api.generateTransaction("APTOS_1_ADDRESS", payload, options);
403
- expect(mockSimpleSpy).toHaveBeenCalledWith({
404
- data: payload,
405
- options: {
406
- maxGasAmount: Number(options.maxGasAmount),
407
- gasUnitPrice: Number(options.gasUnitPrice),
408
- expireTimestamp: 120,
409
- },
410
- sender: "APTOS_1_ADDRESS",
411
- });
412
- });
413
- it("throws an error when failing to build a transaction", async () => {
414
- const options = {
415
- maxGasAmount: "100",
416
- gasUnitPrice: "50",
417
- };
418
- const mockSimple = jest.fn().mockImplementation(async () => null);
419
- mockedAptos.mockImplementation(() => ({
420
- transaction: {
421
- build: {
422
- simple: mockSimple,
423
- },
424
- },
425
- }));
426
- const api = new api_1.AptosAPI("aptos");
427
- expect(async () => await api.generateTransaction("APTOS_1_ADDRESS", payload, options)).rejects.toThrow();
428
- });
37
+ });
38
+ describe("lastBlock", () => {
39
+ beforeEach(() => {
40
+ mockedAptos = jest.mocked(ts_sdk_1.Aptos);
429
41
  });
430
- describe("simulateTransaction", () => {
431
- it("simulates a transaction with the correct options", async () => {
432
- const mockSimple = jest.fn().mockImplementation(async () => ({
433
- rawTransaction: null,
434
- }));
435
- mockedAptos.mockImplementation(() => ({
436
- transaction: {
437
- simulate: {
438
- simple: mockSimple,
439
- },
440
- },
441
- }));
442
- const mockSimpleSpy = jest.spyOn({ simple: mockSimple }, "simple");
443
- const api = new api_1.AptosAPI("aptos");
444
- const address = new ts_sdk_1.Ed25519PublicKey("APTOS_1_ADDRESS");
445
- const tx = new ts_sdk_1.RawTransaction(new ts_sdk_1.AccountAddress(Uint8Array.from(Buffer.from("APTOS_2_ADDRESS"))), BigInt(1), "", BigInt(100), BigInt(50), BigInt(1), { chainId: 1 });
446
- await api.simulateTransaction(address, tx);
447
- expect(mockSimpleSpy).toHaveBeenCalledWith({
448
- signerPublicKey: address,
449
- transaction: { rawTransaction: tx },
450
- options: {
451
- estimateGasUnitPrice: true,
452
- estimateMaxGasAmount: true,
453
- estimatePrioritizedGasUnitPrice: false,
454
- },
455
- });
456
- });
42
+ afterEach(() => {
43
+ jest.resetAllMocks();
457
44
  });
458
- describe("broadcast", () => {
459
- it("broadcasts the transaction", async () => {
460
- mockedPost.mockImplementation(async () => ({ data: { hash: "ok" } }));
461
- const mockedPostSpy = jest.spyOn({ post: mockedPost }, "post");
462
- mockedAptos.mockImplementation(() => ({
463
- config: "config",
464
- }));
465
- const api = new api_1.AptosAPI("aptos");
466
- await api.broadcast("signature");
467
- expect(mockedPostSpy).toHaveBeenCalledWith({
468
- contentType: "application/x.aptos.signed_transaction+bcs",
469
- aptosConfig: "config",
470
- body: Uint8Array.from(Buffer.from("signature", "hex")),
471
- path: "transactions",
472
- type: "Fullnode",
473
- originMethod: "",
474
- });
45
+ it("returns the last block information", async () => {
46
+ mockedAptos.mockImplementation(() => ({
47
+ getLedgerInfo: jest.fn().mockReturnValue({
48
+ block_height: "123",
49
+ }),
50
+ getBlockByHeight: jest.fn().mockReturnValue({
51
+ block_height: "123",
52
+ block_hash: "123hash",
53
+ block_timestamp: "1746021098623892",
54
+ first_version: "1",
55
+ last_version: "1",
56
+ }),
57
+ }));
58
+ const api = (0, api_1.createApi)(mockAptosConfig);
59
+ expect(await api.lastBlock()).toStrictEqual({
60
+ height: 123,
61
+ hash: "123hash",
62
+ time: new Date(1746021098623892),
475
63
  });
476
64
  });
477
65
  });