@ledgerhq/coin-aptos 1.4.0-nightly.1 → 1.4.0-nightly.3

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 (150) hide show
  1. package/.turbo/turbo-build.log +2 -2
  2. package/CHANGELOG.md +20 -0
  3. package/lib/__tests__/api/index.test.js +67 -92
  4. package/lib/__tests__/api/index.test.js.map +1 -1
  5. package/lib/__tests__/bridge/broadcast.test.js +11 -17
  6. package/lib/__tests__/bridge/broadcast.test.js.map +1 -1
  7. package/lib/__tests__/bridge/buildTransaction.test.js +3 -12
  8. package/lib/__tests__/bridge/buildTransaction.test.js.map +1 -1
  9. package/lib/__tests__/bridge/createTransaction.test.js +2 -11
  10. package/lib/__tests__/bridge/createTransaction.test.js.map +1 -1
  11. package/lib/__tests__/bridge/estimateMaxSpendable.test.js +12 -21
  12. package/lib/__tests__/bridge/estimateMaxSpendable.test.js.map +1 -1
  13. package/lib/__tests__/bridge/getFeesForTransaction.test.js +29 -38
  14. package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  15. package/lib/__tests__/bridge/getTransactionStatus.test.js +18 -27
  16. package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
  17. package/lib/__tests__/bridge/index.test.js +3 -12
  18. package/lib/__tests__/bridge/index.test.js.map +1 -1
  19. package/lib/__tests__/bridge/prepareTransaction.test.js +22 -35
  20. package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -1
  21. package/lib/__tests__/bridge/signOperation.test.js +9 -18
  22. package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
  23. package/lib/__tests__/bridge/synchronisation.test.js +46 -65
  24. package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
  25. package/lib/__tests__/bridge/transaction.test.js +14 -23
  26. package/lib/__tests__/bridge/transaction.test.js.map +1 -1
  27. package/lib/__tests__/network/index.test.js +10 -16
  28. package/lib/__tests__/network/index.test.js.map +1 -1
  29. package/lib/__tests__/signer/index.test.js +6 -17
  30. package/lib/__tests__/signer/index.test.js.map +1 -1
  31. package/lib/api/graphql/queries.d.ts.map +1 -1
  32. package/lib/api/graphql/queries.js +1 -0
  33. package/lib/api/graphql/queries.js.map +1 -1
  34. package/lib/api/index.d.ts.map +1 -1
  35. package/lib/api/index.js +119 -142
  36. package/lib/api/index.js.map +1 -1
  37. package/lib/bridge/bridge.fixture.js +13 -13
  38. package/lib/bridge/bridge.fixture.js.map +1 -1
  39. package/lib/bridge/broadcast.js +3 -12
  40. package/lib/bridge/broadcast.js.map +1 -1
  41. package/lib/bridge/buildTransaction.js +3 -12
  42. package/lib/bridge/buildTransaction.js.map +1 -1
  43. package/lib/bridge/estimateMaxSpendable.js +3 -12
  44. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  45. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  46. package/lib/bridge/getFeesForTransaction.js +12 -37
  47. package/lib/bridge/getFeesForTransaction.js.map +1 -1
  48. package/lib/bridge/getTransactionStatus.js +2 -11
  49. package/lib/bridge/getTransactionStatus.js.map +1 -1
  50. package/lib/bridge/logic.js +17 -20
  51. package/lib/bridge/logic.js.map +1 -1
  52. package/lib/bridge/prepareTransaction.js +7 -13
  53. package/lib/bridge/prepareTransaction.js.map +1 -1
  54. package/lib/bridge/signOperation.js +42 -53
  55. package/lib/bridge/signOperation.js.map +1 -1
  56. package/lib/bridge/synchronisation.js +7 -17
  57. package/lib/bridge/synchronisation.js.map +1 -1
  58. package/lib/bridge/transaction.js +16 -2
  59. package/lib/bridge/transaction.js.map +1 -1
  60. package/lib/network/index.js +19 -30
  61. package/lib/network/index.js.map +1 -1
  62. package/lib/signer/index.js +3 -12
  63. package/lib/signer/index.js.map +1 -1
  64. package/lib/test/bot-specs.d.ts +2 -2
  65. package/lib/test/bot-specs.d.ts.map +1 -1
  66. package/lib/test/bot-specs.js +32 -26
  67. package/lib/test/bot-specs.js.map +1 -1
  68. package/lib/test/cli.js +5 -1
  69. package/lib/test/cli.js.map +1 -1
  70. package/lib/test/speculos-deviceActions.d.ts.map +1 -1
  71. package/lib/test/speculos-deviceActions.js +19 -20
  72. package/lib/test/speculos-deviceActions.js.map +1 -1
  73. package/lib-es/__tests__/api/index.test.js +67 -92
  74. package/lib-es/__tests__/api/index.test.js.map +1 -1
  75. package/lib-es/__tests__/bridge/broadcast.test.js +11 -17
  76. package/lib-es/__tests__/bridge/broadcast.test.js.map +1 -1
  77. package/lib-es/__tests__/bridge/buildTransaction.test.js +3 -12
  78. package/lib-es/__tests__/bridge/buildTransaction.test.js.map +1 -1
  79. package/lib-es/__tests__/bridge/createTransaction.test.js +2 -11
  80. package/lib-es/__tests__/bridge/createTransaction.test.js.map +1 -1
  81. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js +12 -21
  82. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js.map +1 -1
  83. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +29 -38
  84. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  85. package/lib-es/__tests__/bridge/getTransactionStatus.test.js +18 -27
  86. package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
  87. package/lib-es/__tests__/bridge/index.test.js +3 -12
  88. package/lib-es/__tests__/bridge/index.test.js.map +1 -1
  89. package/lib-es/__tests__/bridge/prepareTransaction.test.js +22 -35
  90. package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -1
  91. package/lib-es/__tests__/bridge/signOperation.test.js +9 -18
  92. package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
  93. package/lib-es/__tests__/bridge/synchronisation.test.js +46 -65
  94. package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
  95. package/lib-es/__tests__/bridge/transaction.test.js +14 -23
  96. package/lib-es/__tests__/bridge/transaction.test.js.map +1 -1
  97. package/lib-es/__tests__/network/index.test.js +10 -16
  98. package/lib-es/__tests__/network/index.test.js.map +1 -1
  99. package/lib-es/__tests__/signer/index.test.js +6 -17
  100. package/lib-es/__tests__/signer/index.test.js.map +1 -1
  101. package/lib-es/api/graphql/queries.d.ts.map +1 -1
  102. package/lib-es/api/graphql/queries.js +1 -0
  103. package/lib-es/api/graphql/queries.js.map +1 -1
  104. package/lib-es/api/index.d.ts.map +1 -1
  105. package/lib-es/api/index.js +119 -142
  106. package/lib-es/api/index.js.map +1 -1
  107. package/lib-es/bridge/bridge.fixture.js +13 -13
  108. package/lib-es/bridge/bridge.fixture.js.map +1 -1
  109. package/lib-es/bridge/broadcast.js +3 -12
  110. package/lib-es/bridge/broadcast.js.map +1 -1
  111. package/lib-es/bridge/buildTransaction.js +3 -12
  112. package/lib-es/bridge/buildTransaction.js.map +1 -1
  113. package/lib-es/bridge/estimateMaxSpendable.js +3 -12
  114. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  115. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  116. package/lib-es/bridge/getFeesForTransaction.js +12 -37
  117. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  118. package/lib-es/bridge/getTransactionStatus.js +2 -11
  119. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  120. package/lib-es/bridge/logic.js +17 -20
  121. package/lib-es/bridge/logic.js.map +1 -1
  122. package/lib-es/bridge/prepareTransaction.js +7 -13
  123. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  124. package/lib-es/bridge/signOperation.js +42 -53
  125. package/lib-es/bridge/signOperation.js.map +1 -1
  126. package/lib-es/bridge/synchronisation.js +7 -17
  127. package/lib-es/bridge/synchronisation.js.map +1 -1
  128. package/lib-es/bridge/transaction.js +16 -2
  129. package/lib-es/bridge/transaction.js.map +1 -1
  130. package/lib-es/network/index.js +19 -30
  131. package/lib-es/network/index.js.map +1 -1
  132. package/lib-es/signer/index.js +3 -12
  133. package/lib-es/signer/index.js.map +1 -1
  134. package/lib-es/test/bot-specs.d.ts +2 -2
  135. package/lib-es/test/bot-specs.d.ts.map +1 -1
  136. package/lib-es/test/bot-specs.js +33 -27
  137. package/lib-es/test/bot-specs.js.map +1 -1
  138. package/lib-es/test/cli.js +5 -1
  139. package/lib-es/test/cli.js.map +1 -1
  140. package/lib-es/test/speculos-deviceActions.d.ts.map +1 -1
  141. package/lib-es/test/speculos-deviceActions.js +20 -21
  142. package/lib-es/test/speculos-deviceActions.js.map +1 -1
  143. package/package.json +6 -5
  144. package/src/__tests__/bridge/getFeesForTransaction.test.ts +18 -20
  145. package/src/api/graphql/queries.ts +1 -0
  146. package/src/api/index.ts +1 -0
  147. package/src/bridge/getFeesForTransaction.ts +10 -23
  148. package/src/test/bot-specs.ts +39 -33
  149. package/src/test/speculos-deviceActions.ts +20 -27
  150. package/tsconfig.json +3 -2
@@ -1,7 +1,7 @@
1
- import type { AppSpec } from "@ledgerhq/coin-framework/bot/types";
2
1
  import type { Transaction } from "../types";
2
+ import type { AppSpec } from "@ledgerhq/coin-framework/bot/types";
3
3
  declare const _default: {
4
- aptos: AppSpec<Transaction>;
4
+ aptosSpecs: AppSpec<Transaction>;
5
5
  };
6
6
  export default _default;
7
7
  //# sourceMappingURL=bot-specs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bot-specs.d.ts","sourceRoot":"","sources":["../../src/test/bot-specs.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAElE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;;;;AA8E5C,wBAAyB"}
1
+ {"version":3,"file":"bot-specs.d.ts","sourceRoot":"","sources":["../../src/test/bot-specs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAG5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;;;;AAkFlE,wBAEE"}
@@ -1,24 +1,24 @@
1
1
  import invariant from "invariant";
2
+ import expect from "expect";
2
3
  import { DeviceModelId } from "@ledgerhq/devices";
4
+ import BigNumber from "bignumber.js";
3
5
  import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
4
- import { parseCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
5
- import { botTest, genericTestDestination, pickSiblings } from "@ledgerhq/coin-framework/bot/specs";
6
+ import { genericTestDestination, pickSiblings, botTest } from "@ledgerhq/coin-framework/bot/specs";
6
7
  import { acceptTransaction } from "./speculos-deviceActions";
7
- const currency = getCryptoCurrencyById("aptos");
8
- const minBalanceNewAccount = parseCurrencyUnit(currency.units[0], "0.0001");
9
- const maxAccountSiblings = 4;
10
- const aptos = {
8
+ const MIN_SAFE = new BigNumber(0.0001);
9
+ const maxAccount = 6;
10
+ const aptosSpecs = {
11
11
  name: "Aptos",
12
- currency,
12
+ currency: getCryptoCurrencyById("aptos"),
13
13
  appQuery: {
14
14
  model: DeviceModelId.nanoSP,
15
15
  appName: "Aptos",
16
16
  },
17
17
  genericDeviceAction: acceptTransaction,
18
- testTimeout: 5 * 60 * 1000,
19
- minViableAmount: minBalanceNewAccount,
18
+ testTimeout: 6 * 60 * 1000,
19
+ minViableAmount: MIN_SAFE,
20
20
  transactionCheck: ({ maxSpendable }) => {
21
- invariant(maxSpendable.gt(minBalanceNewAccount), "balance is too low");
21
+ invariant(maxSpendable.gt(MIN_SAFE), "balance is too low");
22
22
  },
23
23
  mutations: [
24
24
  {
@@ -27,8 +27,8 @@ const aptos = {
27
27
  maxRun: 1,
28
28
  testDestination: genericTestDestination,
29
29
  transaction: ({ account, siblings, bridge, maxSpendable }) => {
30
- invariant(maxSpendable.gt(minBalanceNewAccount), "balance is too low");
31
- const sibling = pickSiblings(siblings, maxAccountSiblings);
30
+ invariant(maxSpendable.gt(MIN_SAFE), "balance is too low");
31
+ const sibling = pickSiblings(siblings, maxAccount);
32
32
  const recipient = sibling.freshAddress;
33
33
  const amount = maxSpendable.div(2).integerValue();
34
34
  const transaction = bridge.createTransaction(account);
@@ -43,30 +43,36 @@ const aptos = {
43
43
  updates,
44
44
  };
45
45
  },
46
- test: ({ account, accountBeforeTransaction, operation }) => {
47
- botTest("account balance moved with operation.value", () => expect(account.balance.toString()).toBe(accountBeforeTransaction.balance.minus(operation.value).toString()));
46
+ test: ({ accountBeforeTransaction, operation, account }) => {
47
+ botTest("account spendable balance decreased with operation", () => expect(account.spendableBalance).toEqual(accountBeforeTransaction.spendableBalance.minus(operation.value)));
48
48
  },
49
49
  },
50
50
  {
51
- name: "Send max",
52
- maxRun: 2,
53
- testDestination: genericTestDestination,
51
+ name: "Transfer Max",
52
+ feature: "sendMax",
53
+ maxRun: 1,
54
54
  transaction: ({ account, siblings, bridge }) => {
55
- const sibling = pickSiblings(siblings, 4);
56
- const recipient = sibling.freshAddress;
57
- const transaction = bridge.createTransaction(account);
55
+ const updates = [
56
+ {
57
+ recipient: pickSiblings(siblings, maxAccount).freshAddress,
58
+ },
59
+ {
60
+ useAllAmount: true,
61
+ },
62
+ ];
58
63
  return {
59
- transaction,
60
- updates: [{ recipient }, { useAllAmount: true }],
64
+ transaction: bridge.createTransaction(account),
65
+ updates,
61
66
  };
62
67
  },
63
- test: ({ account, accountBeforeTransaction, operation }) => {
64
- botTest("Account balance should have decreased", () => {
65
- expect(account.balance.toNumber()).toEqual(accountBeforeTransaction.balance.minus(operation.value).toNumber());
66
- });
68
+ testDestination: genericTestDestination,
69
+ test: ({ account }) => {
70
+ botTest("account spendable balance is zero", () => expect(account.spendableBalance.toString()).toBe("0"));
67
71
  },
68
72
  },
69
73
  ],
70
74
  };
71
- export default { aptos };
75
+ export default {
76
+ aptosSpecs,
77
+ };
72
78
  //# sourceMappingURL=bot-specs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bot-specs.js","sourceRoot":"","sources":["../../src/test/bot-specs.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAA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AC3D;oBACD;wBACE,YAAY,EAAE,IAAI;qBACnB;iBACF,CAAC;gBAEF,OAAO;oBACL,WAAW,EAAE,MAAM,CAAC,iBAAiB,CAAC,OAAO,CAAC;oBAC9C,OAAO;iBACR,CAAC;YACJ,CAAC;YACD,eAAe,EAAE,sBAAsB;YACvC,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;gBACpB,OAAO,CAAC,mCAAmC,EAAE,GAAG,EAAE,CAChD,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CACtD,CAAC;YACJ,CAAC;SACF;KACF;CACF,CAAC;AAEF,eAAe;IACb,UAAU;CACX,CAAC"}
@@ -40,7 +40,11 @@ function inferTransactions(transactions) {
40
40
  const isDelisted = account.token.delisted === true;
41
41
  invariant(!isDelisted, "token is delisted");
42
42
  }
43
- return Object.assign(Object.assign({}, transaction), { family: "aptos", subAccountId: account.type === AccountType.TokenAccount ? account.id : null });
43
+ return {
44
+ ...transaction,
45
+ family: "aptos",
46
+ subAccountId: account.type === AccountType.TokenAccount ? account.id : null,
47
+ };
44
48
  });
45
49
  }
46
50
  export default function makeCliTools() {
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/test/cli.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAErC,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,OAAO,GAAG;IACd;QACE,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,GAAG;QACV,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,8CAA8C;KACrD;CACF,CAAC;AAEF,SAAS,aAAa,CAAC,OAAgB,EAAE,IAAyB;IAChE,SAAS,CAAC,OAAO,CAAC,Q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IACnB,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,YAAY;IAClC,OAAO;QACL,OAAO;QACP,aAAa;QACb,iBAAiB;KAClB,CAAC;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"speculos-deviceActions.d.ts","sourceRoot":"","sources":["../../src/test/speculos-deviceActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAM5C,OAAO,EAAE,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAa3D,eAAO,MAAM,iBAAiB,EAAE,YAAY,CAAC,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,CA+B1E,CAAC"}
1
+ {"version":3,"file":"speculos-deviceActions.d.ts","sourceRoot":"","sources":["../../src/test/speculos-deviceActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,OAAO,EAAE,KAAK,EAAE,MAAM,oCAAoC,CAAC;AAE3D,eAAO,MAAM,iBAAiB,EAAE,YAAY,CAAC,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,CAuC1E,CAAC"}
@@ -1,14 +1,4 @@
1
- import { deviceActionFlow, formatDeviceAmount, SpeculosButton, } from "@ledgerhq/coin-framework/bot/specs";
2
- const typeWording = {
3
- send: "Send",
4
- lock: "Lock",
5
- unlock: "Unlock",
6
- withdraw: "Withdraw",
7
- vote: "Vote",
8
- revoke: "Revoke",
9
- activate: "Activate",
10
- register: "Create Account",
11
- };
1
+ import { deviceActionFlow, SpeculosButton } from "@ledgerhq/coin-framework/bot/specs";
12
2
  export const acceptTransaction = deviceActionFlow({
13
3
  steps: [
14
4
  {
@@ -16,26 +6,35 @@ export const acceptTransaction = deviceActionFlow({
16
6
  button: SpeculosButton.RIGHT,
17
7
  },
18
8
  {
19
- title: "Type",
9
+ title: "Transaction",
10
+ button: SpeculosButton.RIGHT,
11
+ },
12
+ {
13
+ title: "Function",
14
+ button: SpeculosButton.RIGHT,
15
+ },
16
+ {
17
+ title: "Coin Type",
18
+ button: SpeculosButton.RIGHT,
19
+ },
20
+ {
21
+ title: "Receiver (1/2)",
22
+ button: SpeculosButton.RIGHT,
23
+ },
24
+ {
25
+ title: "Receiver (2/2)",
20
26
  button: SpeculosButton.RIGHT,
21
- expectedValue: ({ transaction }) => {
22
- return typeWording[transaction.mode];
23
- },
24
27
  },
25
28
  {
26
29
  title: "Amount",
27
30
  button: SpeculosButton.RIGHT,
28
- expectedValue: ({ account, status }) => formatDeviceAmount(account.currency, status.amount, {
29
- forceFloating: true,
30
- }),
31
31
  },
32
32
  {
33
- title: "Address",
33
+ title: "Gas Fee",
34
34
  button: SpeculosButton.RIGHT,
35
- expectedValue: ({ transaction }) => transaction.recipient,
36
35
  },
37
36
  {
38
- title: "Accept",
37
+ title: "Approve",
39
38
  button: SpeculosButton.BOTH,
40
39
  },
41
40
  ],
@@ -1 +1 @@
1
- {"version":3,"file":"speculos-deviceActions.js","sourceRoot":"","sources":["../../src/test/speculos-deviceActions.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,GACf,MAAM,oCAAoC,CAAC;AAG5C,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,IAAI,EAAE,MAAM;IACZ,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,gBAAgB;CAC3B,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAkD,gBAAgB,CAAC;IAC/F,KAAK,EAAE;QACL;YACE,KAAK,EAAE,QAAQ;YACf,MAAM,EAAE,cAAc,CAAC,KAAK;SAC7B;QACD;YACE,KAAK,EAAE,MAAM;YACb,MAAM,EAAE,cAAc,CAAC,KAAK;YAC5B,aAAa,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE;gBACjC,OAAO,WAAW,CAAC,WAAW,CAAC,IAAgC,CAAC,CAAC;YACnE,CAAC;SACF;QACD;YACE,KAAK,EAAE,QAAQ;YACf,MAAM,EAAE,cAAc,CAAC,KAAK;YAC5B,aAAa,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,CACrC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;gBAClD,aAAa,EAAE,IAAI;aACpB,CAAC;SACL;QACD;YACE,KAAK,EAAE,SAAS;YAChB,MAAM,EAAE,cAAc,CAAC,KAAK;YAC5B,aAAa,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,SAAS;SAC1D;QACD;YACE,KAAK,EAAE,QAAQ;YACf,MAAM,EAAE,cAAc,CAAC,IAAI;SAC5B;KACF;CACF,CAAC,CAAC"}
1
+ {"version":3,"file":"speculos-deviceActions.js","sourceRoot":"","sources":["../../src/test/speculos-deviceActions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAGtF,MAAM,CAAC,MAAM,iBAAiB,GAAkD,gBAAgB,CAAC;IAC/F,KAAK,EAAE;QACL;YACE,KAAK,EAAE,QAAQ;YACf,MAAM,EAAE,cAAc,CAAC,KAAK;SAC7B;QACD;YACE,KAAK,EAAE,aAAa;YACpB,MAAM,EAAE,cAAc,CAAC,KAAK;SAC7B;QACD;YACE,KAAK,EAAE,UAAU;YACjB,MAAM,EAAE,cAAc,CAAC,KAAK;SAC7B;QACD;YACE,KAAK,EAAE,WAAW;YAClB,MAAM,EAAE,cAAc,CAAC,KAAK;SAC7B;QACD;YACE,KAAK,EAAE,gBAAgB;YACvB,MAAM,EAAE,cAAc,CAAC,KAAK;SAC7B;QACD;YACE,KAAK,EAAE,gBAAgB;YACvB,MAAM,EAAE,cAAc,CAAC,KAAK;SAC7B;QACD;YACE,KAAK,EAAE,QAAQ;YACf,MAAM,EAAE,cAAc,CAAC,KAAK;SAC7B;QACD;YACE,KAAK,EAAE,SAAS;YAChB,MAAM,EAAE,cAAc,CAAC,KAAK;SAC7B;QACD;YACE,KAAK,EAAE,SAAS;YAChB,MAAM,EAAE,cAAc,CAAC,IAAI;SAC5B;KACF;CACF,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/coin-aptos",
3
- "version": "1.4.0-nightly.1",
3
+ "version": "1.4.0-nightly.3",
4
4
  "description": "Ledger Aptos Coin integration",
5
5
  "keywords": [
6
6
  "Ledger",
@@ -87,16 +87,17 @@
87
87
  "bignumber.js": "^9.1.2",
88
88
  "graphql": "^16.10.0",
89
89
  "invariant": "^2.2.4",
90
+ "expect": "^27.4.6",
90
91
  "lodash": "^4.17.21",
91
92
  "rxjs": "^7.8.1",
92
- "@ledgerhq/coin-framework": "^0.23.0-nightly.2",
93
- "@ledgerhq/cryptoassets": "^13.10.0-nightly.0",
93
+ "@ledgerhq/coin-framework": "^0.24.1-nightly.0",
94
+ "@ledgerhq/cryptoassets": "^13.10.0-nightly.1",
94
95
  "@ledgerhq/devices": "8.4.4",
95
96
  "@ledgerhq/errors": "^6.19.1",
96
97
  "@ledgerhq/live-env": "^2.5.0",
97
98
  "@ledgerhq/live-network": "^2.0.4",
98
99
  "@ledgerhq/logs": "^6.12.0",
99
- "@ledgerhq/types-live": "^6.58.0-nightly.2"
100
+ "@ledgerhq/types-live": "^6.58.0"
100
101
  },
101
102
  "devDependencies": {
102
103
  "@faker-js/faker": "^9.4.0",
@@ -111,7 +112,7 @@
111
112
  },
112
113
  "scripts": {
113
114
  "clean": "rimraf lib lib-es",
114
- "build": "tsc && tsc -m ES6 --outDir lib-es",
115
+ "build": "tsc --outDir lib --module commonjs --moduleResolution node10 && tsc -m ES6 --outDir lib-es",
115
116
  "coverage": "jest --coverage --testPathIgnorePatterns='/bridge.integration.test.ts|node_modules|lib-es|lib/' --coveragePathIgnorePatterns='src/test|src/types|src/index.ts|src/bridge/bridge.fixture.ts' --passWithNoTests && mv coverage/coverage-final.json coverage/coverage-aptos.json",
116
117
  "prewatch": "pnpm build",
117
118
  "watch": "tsc --watch",
@@ -42,8 +42,8 @@ describe("getFeesForTransaction Test", () => {
42
42
  success: false,
43
43
  vm_status: ["INSUFFICIENT_BALANCE"],
44
44
  expiration_timestamp_secs: 5,
45
- gas_used: "201",
46
- gas_unit_price: "101",
45
+ gas_used: "202",
46
+ gas_unit_price: "102",
47
47
  },
48
48
  ]);
49
49
 
@@ -58,10 +58,10 @@ describe("getFeesForTransaction Test", () => {
58
58
  const result = await getFeesForTransaction.getFee(account, transaction, aptosClient);
59
59
 
60
60
  const expected = {
61
- fees: new BigNumber(20301),
61
+ fees: new BigNumber(20604),
62
62
  estimate: {
63
- maxGasAmount: "201",
64
- gasUnitPrice: "101",
63
+ maxGasAmount: "202",
64
+ gasUnitPrice: "102",
65
65
  },
66
66
  errors: {},
67
67
  };
@@ -99,7 +99,7 @@ describe("getFeesForTransaction Test", () => {
99
99
 
100
100
  describe("when using getEstimatedGas", () => {
101
101
  describe("when key not in cache", () => {
102
- it("should return cached fee", async () => {
102
+ it("should return fee", async () => {
103
103
  simulateTransaction = jest.fn(() => [
104
104
  {
105
105
  success: true,
@@ -143,23 +143,21 @@ describe("getFeesForTransaction Test", () => {
143
143
  });
144
144
 
145
145
  it("should return cached fee", async () => {
146
- const mocked = jest.spyOn(getFeesForTransaction, "getFee");
147
-
148
- const account = createFixtureAccount();
149
- const transaction = createFixtureTransaction();
150
- const aptosClient = new AptosAPI(account.currency.id);
151
-
152
- transaction.amount = new BigNumber(10);
153
-
154
146
  simulateTransaction = jest.fn(() => [
155
147
  {
156
148
  success: true,
157
149
  vm_status: [],
158
150
  expiration_timestamp_secs: 5,
159
- gas_used: "9",
160
- gas_unit_price: "100",
151
+ gas_used: "202",
152
+ gas_unit_price: "102",
161
153
  },
162
154
  ]);
155
+ const account = createFixtureAccount();
156
+ account.xpub = "xpub";
157
+ const transaction = createFixtureTransaction();
158
+ const aptosClient = new AptosAPI(account.currency.id);
159
+
160
+ transaction.amount = new BigNumber(10);
163
161
 
164
162
  const result1 = await getFeesForTransaction.getEstimatedGas(
165
163
  account,
@@ -172,15 +170,15 @@ describe("getFeesForTransaction Test", () => {
172
170
  aptosClient,
173
171
  );
174
172
 
175
- expect(mocked).toHaveBeenCalledTimes(1);
173
+ expect(simulateTransaction.mock.calls).toHaveLength(1);
176
174
 
177
175
  const expected = {
178
176
  errors: {},
179
177
  estimate: {
180
- gasUnitPrice: "101",
181
- maxGasAmount: "201",
178
+ gasUnitPrice: "102",
179
+ maxGasAmount: "202",
182
180
  },
183
- fees: new BigNumber("20301"),
181
+ fees: new BigNumber("20604"),
184
182
  };
185
183
 
186
184
  expect(result1).toEqual(expected);
@@ -1,3 +1,4 @@
1
+ // We need to target CJS for the CJS build of the lib
1
2
  import { gql } from "@apollo/client";
2
3
 
3
4
  export const GetDelegatedStakingActivities = gql`
package/src/api/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ApolloClient, InMemoryCache } from "@apollo/client";
2
+
2
3
  import {
3
4
  AccountData,
4
5
  Aptos,
@@ -2,6 +2,7 @@ import { Ed25519PublicKey } from "@aptos-labs/ts-sdk";
2
2
  import { log } from "@ledgerhq/logs";
3
3
  import type { Account } from "@ledgerhq/types-live";
4
4
  import BigNumber from "bignumber.js";
5
+ import { makeLRUCache, seconds } from "@ledgerhq/live-network/cache";
5
6
  import { AptosAPI } from "../api";
6
7
  import buildTransaction from "./buildTransaction";
7
8
  import { DEFAULT_GAS, DEFAULT_GAS_PRICE, ESTIMATE_GAS_MUL } from "./logic";
@@ -16,18 +17,6 @@ type IGetEstimatedGasReturnType = {
16
17
  errors: TransactionErrors;
17
18
  };
18
19
 
19
- const CACHE = {
20
- amount: new BigNumber(0),
21
- estimate: Promise.resolve({
22
- fees: new BigNumber(0),
23
- estimate: {
24
- maxGasAmount: "",
25
- gasUnitPrice: "",
26
- },
27
- errors: {},
28
- }),
29
- };
30
-
31
20
  export const getFee = async (
32
21
  account: Account,
33
22
  transaction: Transaction,
@@ -81,20 +70,18 @@ export const getFee = async (
81
70
  return res;
82
71
  };
83
72
 
73
+ const CACHE = makeLRUCache(
74
+ getFee,
75
+ (_account: Account, transaction: Transaction, _aptosClient: AptosAPI) => {
76
+ return transaction.amount.toString();
77
+ },
78
+ seconds(30),
79
+ );
80
+
84
81
  export const getEstimatedGas = async (
85
82
  account: Account,
86
83
  transaction: Transaction,
87
84
  aptosClient: AptosAPI,
88
85
  ): Promise<IGetEstimatedGasReturnType> => {
89
- if (!CACHE.amount.eq(transaction.amount)) {
90
- CACHE.estimate = getFee(account, transaction, aptosClient);
91
- CACHE.amount = transaction.amount;
92
- }
93
-
94
- // XXX: we await Promise form getFee() in this place to make cache work for asynchronous calls
95
- // Example [if wee await getFee()]: thread 1 goes to getFee() and awaits there for transaction simulation.
96
- // at this moment thread 2 will enter getEstimatedGas() CACHE is not set yet, it will call getFee() as well
97
- // Current implementation: CACHE.estimate set immediately after getFee() is called, so thread 2 will not go under if clause
98
- // and both treads will wait for promise resolve in return statement.
99
- return await CACHE.estimate;
86
+ return await CACHE(account, transaction, aptosClient);
100
87
  };
@@ -1,28 +1,28 @@
1
1
  import invariant from "invariant";
2
+ import expect from "expect";
2
3
  import { DeviceModelId } from "@ledgerhq/devices";
4
+ import BigNumber from "bignumber.js";
5
+ import type { Transaction } from "../types";
3
6
  import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
4
- import { parseCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
5
- import { botTest, genericTestDestination, pickSiblings } from "@ledgerhq/coin-framework/bot/specs";
7
+ import { genericTestDestination, pickSiblings, botTest } from "@ledgerhq/coin-framework/bot/specs";
6
8
  import type { AppSpec } from "@ledgerhq/coin-framework/bot/types";
7
9
  import { acceptTransaction } from "./speculos-deviceActions";
8
- import type { Transaction } from "../types";
9
10
 
10
- const currency = getCryptoCurrencyById("aptos");
11
- const minBalanceNewAccount = parseCurrencyUnit(currency.units[0], "0.0001");
12
- const maxAccountSiblings = 4;
11
+ const MIN_SAFE = new BigNumber(0.0001);
12
+ const maxAccount = 6;
13
13
 
14
- const aptos: AppSpec<Transaction> = {
14
+ const aptosSpecs: AppSpec<Transaction> = {
15
15
  name: "Aptos",
16
- currency,
16
+ currency: getCryptoCurrencyById("aptos"),
17
17
  appQuery: {
18
18
  model: DeviceModelId.nanoSP,
19
19
  appName: "Aptos",
20
20
  },
21
21
  genericDeviceAction: acceptTransaction,
22
- testTimeout: 5 * 60 * 1000,
23
- minViableAmount: minBalanceNewAccount,
22
+ testTimeout: 6 * 60 * 1000,
23
+ minViableAmount: MIN_SAFE,
24
24
  transactionCheck: ({ maxSpendable }) => {
25
- invariant(maxSpendable.gt(minBalanceNewAccount), "balance is too low");
25
+ invariant(maxSpendable.gt(MIN_SAFE), "balance is too low");
26
26
  },
27
27
  mutations: [
28
28
  {
@@ -31,9 +31,8 @@ const aptos: AppSpec<Transaction> = {
31
31
  maxRun: 1,
32
32
  testDestination: genericTestDestination,
33
33
  transaction: ({ account, siblings, bridge, maxSpendable }) => {
34
- invariant(maxSpendable.gt(minBalanceNewAccount), "balance is too low");
35
-
36
- const sibling = pickSiblings(siblings, maxAccountSiblings);
34
+ invariant(maxSpendable.gt(MIN_SAFE), "balance is too low");
35
+ const sibling = pickSiblings(siblings, maxAccount);
37
36
  const recipient = sibling.freshAddress;
38
37
  const amount = maxSpendable.div(2).integerValue();
39
38
 
@@ -50,37 +49,44 @@ const aptos: AppSpec<Transaction> = {
50
49
  updates,
51
50
  };
52
51
  },
53
- test: ({ account, accountBeforeTransaction, operation }) => {
54
- botTest("account balance moved with operation.value", () =>
55
- expect(account.balance.toString()).toBe(
56
- accountBeforeTransaction.balance.minus(operation.value).toString(),
52
+
53
+ test: ({ accountBeforeTransaction, operation, account }) => {
54
+ botTest("account spendable balance decreased with operation", () =>
55
+ expect(account.spendableBalance).toEqual(
56
+ accountBeforeTransaction.spendableBalance.minus(operation.value),
57
57
  ),
58
58
  );
59
59
  },
60
60
  },
61
61
  {
62
- name: "Send max",
63
- maxRun: 2,
64
- testDestination: genericTestDestination,
62
+ name: "Transfer Max",
63
+ feature: "sendMax",
64
+ maxRun: 1,
65
65
  transaction: ({ account, siblings, bridge }) => {
66
- const sibling = pickSiblings(siblings, 4);
67
- const recipient = sibling.freshAddress;
68
- const transaction = bridge.createTransaction(account);
66
+ const updates: Array<Partial<Transaction>> = [
67
+ {
68
+ recipient: pickSiblings(siblings, maxAccount).freshAddress,
69
+ },
70
+ {
71
+ useAllAmount: true,
72
+ },
73
+ ];
69
74
 
70
75
  return {
71
- transaction,
72
- updates: [{ recipient }, { useAllAmount: true }],
76
+ transaction: bridge.createTransaction(account),
77
+ updates,
73
78
  };
74
79
  },
75
- test: ({ account, accountBeforeTransaction, operation }) => {
76
- botTest("Account balance should have decreased", () => {
77
- expect(account.balance.toNumber()).toEqual(
78
- accountBeforeTransaction.balance.minus(operation.value).toNumber(),
79
- );
80
- });
80
+ testDestination: genericTestDestination,
81
+ test: ({ account }) => {
82
+ botTest("account spendable balance is zero", () =>
83
+ expect(account.spendableBalance.toString()).toBe("0"),
84
+ );
81
85
  },
82
86
  },
83
87
  ],
84
88
  };
85
89
 
86
- export default { aptos };
90
+ export default {
91
+ aptosSpecs,
92
+ };
@@ -1,23 +1,8 @@
1
1
  import type { DeviceAction } from "@ledgerhq/coin-framework/bot/types";
2
2
  import type { Transaction } from "../types";
3
- import {
4
- deviceActionFlow,
5
- formatDeviceAmount,
6
- SpeculosButton,
7
- } from "@ledgerhq/coin-framework/bot/specs";
3
+ import { deviceActionFlow, SpeculosButton } from "@ledgerhq/coin-framework/bot/specs";
8
4
  import { State } from "@ledgerhq/coin-framework/bot/types";
9
5
 
10
- const typeWording = {
11
- send: "Send",
12
- lock: "Lock",
13
- unlock: "Unlock",
14
- withdraw: "Withdraw",
15
- vote: "Vote",
16
- revoke: "Revoke",
17
- activate: "Activate",
18
- register: "Create Account",
19
- };
20
-
21
6
  export const acceptTransaction: DeviceAction<Transaction, State<Transaction>> = deviceActionFlow({
22
7
  steps: [
23
8
  {
@@ -25,27 +10,35 @@ export const acceptTransaction: DeviceAction<Transaction, State<Transaction>> =
25
10
  button: SpeculosButton.RIGHT,
26
11
  },
27
12
  {
28
- title: "Type",
13
+ title: "Transaction",
14
+ button: SpeculosButton.RIGHT,
15
+ },
16
+ {
17
+ title: "Function",
18
+ button: SpeculosButton.RIGHT,
19
+ },
20
+ {
21
+ title: "Coin Type",
22
+ button: SpeculosButton.RIGHT,
23
+ },
24
+ {
25
+ title: "Receiver (1/2)",
26
+ button: SpeculosButton.RIGHT,
27
+ },
28
+ {
29
+ title: "Receiver (2/2)",
29
30
  button: SpeculosButton.RIGHT,
30
- expectedValue: ({ transaction }) => {
31
- return typeWording[transaction.mode as keyof typeof typeWording];
32
- },
33
31
  },
34
32
  {
35
33
  title: "Amount",
36
34
  button: SpeculosButton.RIGHT,
37
- expectedValue: ({ account, status }) =>
38
- formatDeviceAmount(account.currency, status.amount, {
39
- forceFloating: true,
40
- }),
41
35
  },
42
36
  {
43
- title: "Address",
37
+ title: "Gas Fee",
44
38
  button: SpeculosButton.RIGHT,
45
- expectedValue: ({ transaction }) => transaction.recipient,
46
39
  },
47
40
  {
48
- title: "Accept",
41
+ title: "Approve",
49
42
  button: SpeculosButton.BOTH,
50
43
  },
51
44
  ],
package/tsconfig.json CHANGED
@@ -3,12 +3,13 @@
3
3
  "compilerOptions": {
4
4
  "declaration": true,
5
5
  "declarationMap": true,
6
- "module": "commonjs",
7
6
  "downlevelIteration": true,
8
7
  "lib": ["es2020", "dom"],
9
8
  "rootDir": "./src",
10
9
  "outDir": "lib",
11
- "exactOptionalPropertyTypes": true
10
+ "exactOptionalPropertyTypes": true,
11
+ "module": "esnext",
12
+ "moduleResolution": "bundler",
12
13
  },
13
14
  "include": ["src/**/*", "deviceTransactionConfig.ts", "transaction.ts"]
14
15
  }