@ledgerhq/coin-ton 0.3.12-next.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.
- package/.eslintrc.js +20 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +19 -0
- package/CHANGELOG.md +15 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +12 -0
- package/lib/__tests__/fixtures/api.fixtures.d.ts +4 -0
- package/lib/__tests__/fixtures/api.fixtures.d.ts.map +1 -0
- package/lib/__tests__/fixtures/api.fixtures.js +33 -0
- package/lib/__tests__/fixtures/api.fixtures.js.map +1 -0
- package/lib/__tests__/fixtures/common.fixtures.d.ts +29 -0
- package/lib/__tests__/fixtures/common.fixtures.d.ts.map +1 -0
- package/lib/__tests__/fixtures/common.fixtures.js +124 -0
- package/lib/__tests__/fixtures/common.fixtures.js.map +1 -0
- package/lib/__tests__/integration/bridge.integration.test.d.ts +14 -0
- package/lib/__tests__/integration/bridge.integration.test.d.ts.map +1 -0
- package/lib/__tests__/integration/bridge.integration.test.js +136 -0
- package/lib/__tests__/integration/bridge.integration.test.js.map +1 -0
- package/lib/__tests__/unit/api.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/api.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/api.unit.test.js +77 -0
- package/lib/__tests__/unit/api.unit.test.js.map +1 -0
- package/lib/__tests__/unit/broadcast.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/broadcast.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/broadcast.unit.test.js +40 -0
- package/lib/__tests__/unit/broadcast.unit.test.js.map +1 -0
- package/lib/__tests__/unit/createTransaction.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/createTransaction.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/createTransaction.unit.test.js +34 -0
- package/lib/__tests__/unit/createTransaction.unit.test.js.map +1 -0
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js +74 -0
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -0
- package/lib/__tests__/unit/estimateMaxSpendable.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/estimateMaxSpendable.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/estimateMaxSpendable.unit.test.js +31 -0
- package/lib/__tests__/unit/estimateMaxSpendable.unit.test.js.map +1 -0
- package/lib/__tests__/unit/getTransactionStatus.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/getTransactionStatus.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/getTransactionStatus.unit.test.js +96 -0
- package/lib/__tests__/unit/getTransactionStatus.unit.test.js.map +1 -0
- package/lib/__tests__/unit/hw-getAddress.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/hw-getAddress.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/hw-getAddress.unit.test.js +67 -0
- package/lib/__tests__/unit/hw-getAddress.unit.test.js.map +1 -0
- package/lib/__tests__/unit/prepareTransaction.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/prepareTransaction.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/prepareTransaction.unit.test.js +42 -0
- package/lib/__tests__/unit/prepareTransaction.unit.test.js.map +1 -0
- package/lib/__tests__/unit/signOperation.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/signOperation.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/signOperation.unit.test.js +83 -0
- package/lib/__tests__/unit/signOperation.unit.test.js.map +1 -0
- package/lib/__tests__/unit/txn.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/txn.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/txn.unit.test.js +116 -0
- package/lib/__tests__/unit/txn.unit.test.js.map +1 -0
- package/lib/__tests__/unit/utils.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/utils.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/utils.unit.test.js +97 -0
- package/lib/__tests__/unit/utils.unit.test.js.map +1 -0
- package/lib/bridge/bridgeHelpers/api.d.ts +10 -0
- package/lib/bridge/bridgeHelpers/api.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/api.js +104 -0
- package/lib/bridge/bridgeHelpers/api.js.map +1 -0
- package/lib/bridge/bridgeHelpers/api.types.d.ts +164 -0
- package/lib/bridge/bridgeHelpers/api.types.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/api.types.js +3 -0
- package/lib/bridge/bridgeHelpers/api.types.js.map +1 -0
- package/lib/bridge/bridgeHelpers/txn.d.ts +5 -0
- package/lib/bridge/bridgeHelpers/txn.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/txn.js +166 -0
- package/lib/bridge/bridgeHelpers/txn.js.map +1 -0
- package/lib/bridge/js.d.ts +12 -0
- package/lib/bridge/js.d.ts.map +1 -0
- package/lib/bridge/js.js +65 -0
- package/lib/bridge/js.js.map +1 -0
- package/lib/broadcast.d.ts +5 -0
- package/lib/broadcast.d.ts.map +1 -0
- package/lib/broadcast.js +19 -0
- package/lib/broadcast.js.map +1 -0
- package/lib/cli-transaction.d.ts +12 -0
- package/lib/cli-transaction.d.ts.map +1 -0
- package/lib/cli-transaction.js +21 -0
- package/lib/cli-transaction.js.map +1 -0
- package/lib/config.d.ts +9 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +16 -0
- package/lib/config.js.map +1 -0
- package/lib/createTransaction.d.ts +5 -0
- package/lib/createTransaction.d.ts.map +1 -0
- package/lib/createTransaction.js +16 -0
- package/lib/createTransaction.js.map +1 -0
- package/lib/deviceTransactionConfig.d.ts +11 -0
- package/lib/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/deviceTransactionConfig.js +37 -0
- package/lib/deviceTransactionConfig.js.map +1 -0
- package/lib/errors.d.ts +4 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +9 -0
- package/lib/errors.js.map +1 -0
- package/lib/estimateMaxSpendable.d.ts +5 -0
- package/lib/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/estimateMaxSpendable.js +32 -0
- package/lib/estimateMaxSpendable.js.map +1 -0
- package/lib/getTransactionStatus.d.ts +5 -0
- package/lib/getTransactionStatus.d.ts.map +1 -0
- package/lib/getTransactionStatus.js +97 -0
- package/lib/getTransactionStatus.js.map +1 -0
- package/lib/hw-getAddress.d.ts +6 -0
- package/lib/hw-getAddress.d.ts.map +1 -0
- package/lib/hw-getAddress.js +31 -0
- package/lib/hw-getAddress.js.map +1 -0
- package/lib/hw-signMessage.d.ts +12 -0
- package/lib/hw-signMessage.d.ts.map +1 -0
- package/lib/hw-signMessage.js +33 -0
- package/lib/hw-signMessage.js.map +1 -0
- package/lib/prepareTransaction.d.ts +5 -0
- package/lib/prepareTransaction.d.ts.map +1 -0
- package/lib/prepareTransaction.js +29 -0
- package/lib/prepareTransaction.js.map +1 -0
- package/lib/signOperation.d.ts +11 -0
- package/lib/signOperation.d.ts.map +1 -0
- package/lib/signOperation.js +96 -0
- package/lib/signOperation.js.map +1 -0
- package/lib/signer.d.ts +27 -0
- package/lib/signer.d.ts.map +1 -0
- package/lib/signer.js +3 -0
- package/lib/signer.js.map +1 -0
- package/lib/specs.d.ts +8 -0
- package/lib/specs.d.ts.map +1 -0
- package/lib/specs.js +106 -0
- package/lib/specs.js.map +1 -0
- package/lib/speculos-deviceActions.d.ts +4 -0
- package/lib/speculos-deviceActions.d.ts.map +1 -0
- package/lib/speculos-deviceActions.js +34 -0
- package/lib/speculos-deviceActions.js.map +1 -0
- package/lib/synchronisation.d.ts +5 -0
- package/lib/synchronisation.d.ts.map +1 -0
- package/lib/synchronisation.js +95 -0
- package/lib/synchronisation.js.map +1 -0
- package/lib/transaction.d.ts +14 -0
- package/lib/transaction.d.ts.map +1 -0
- package/lib/transaction.js +41 -0
- package/lib/transaction.js.map +1 -0
- package/lib/types.d.ts +65 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/utils.d.ts +11 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +125 -0
- package/lib/utils.js.map +1 -0
- package/lib-es/__tests__/fixtures/api.fixtures.d.ts +4 -0
- package/lib-es/__tests__/fixtures/api.fixtures.d.ts.map +1 -0
- package/lib-es/__tests__/fixtures/api.fixtures.js +30 -0
- package/lib-es/__tests__/fixtures/api.fixtures.js.map +1 -0
- package/lib-es/__tests__/fixtures/common.fixtures.d.ts +29 -0
- package/lib-es/__tests__/fixtures/common.fixtures.d.ts.map +1 -0
- package/lib-es/__tests__/fixtures/common.fixtures.js +118 -0
- package/lib-es/__tests__/fixtures/common.fixtures.js.map +1 -0
- package/lib-es/__tests__/integration/bridge.integration.test.d.ts +14 -0
- package/lib-es/__tests__/integration/bridge.integration.test.d.ts.map +1 -0
- package/lib-es/__tests__/integration/bridge.integration.test.js +130 -0
- package/lib-es/__tests__/integration/bridge.integration.test.js.map +1 -0
- package/lib-es/__tests__/unit/api.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/api.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/api.unit.test.js +52 -0
- package/lib-es/__tests__/unit/api.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/broadcast.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/broadcast.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/broadcast.unit.test.js +35 -0
- package/lib-es/__tests__/unit/broadcast.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/createTransaction.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/createTransaction.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/createTransaction.unit.test.js +29 -0
- package/lib-es/__tests__/unit/createTransaction.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js +69 -0
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.js +26 -0
- package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/getTransactionStatus.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/getTransactionStatus.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/getTransactionStatus.unit.test.js +91 -0
- package/lib-es/__tests__/unit/getTransactionStatus.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/hw-getAddress.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/hw-getAddress.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/hw-getAddress.unit.test.js +62 -0
- package/lib-es/__tests__/unit/hw-getAddress.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.js +37 -0
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/signOperation.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/signOperation.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/signOperation.unit.test.js +78 -0
- package/lib-es/__tests__/unit/signOperation.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/txn.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/txn.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/txn.unit.test.js +111 -0
- package/lib-es/__tests__/unit/txn.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/utils.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/utils.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/utils.unit.test.js +95 -0
- package/lib-es/__tests__/unit/utils.unit.test.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/api.d.ts +10 -0
- package/lib-es/bridge/bridgeHelpers/api.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/api.js +93 -0
- package/lib-es/bridge/bridgeHelpers/api.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/api.types.d.ts +164 -0
- package/lib-es/bridge/bridgeHelpers/api.types.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/api.types.js +2 -0
- package/lib-es/bridge/bridgeHelpers/api.types.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/txn.d.ts +5 -0
- package/lib-es/bridge/bridgeHelpers/txn.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/txn.js +158 -0
- package/lib-es/bridge/bridgeHelpers/txn.js.map +1 -0
- package/lib-es/bridge/js.d.ts +12 -0
- package/lib-es/bridge/js.d.ts.map +1 -0
- package/lib-es/bridge/js.js +56 -0
- package/lib-es/bridge/js.js.map +1 -0
- package/lib-es/broadcast.d.ts +5 -0
- package/lib-es/broadcast.d.ts.map +1 -0
- package/lib-es/broadcast.js +17 -0
- package/lib-es/broadcast.js.map +1 -0
- package/lib-es/cli-transaction.d.ts +12 -0
- package/lib-es/cli-transaction.d.ts.map +1 -0
- package/lib-es/cli-transaction.js +15 -0
- package/lib-es/cli-transaction.js.map +1 -0
- package/lib-es/config.d.ts +9 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +11 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/createTransaction.d.ts +5 -0
- package/lib-es/createTransaction.d.ts.map +1 -0
- package/lib-es/createTransaction.js +14 -0
- package/lib-es/createTransaction.js.map +1 -0
- package/lib-es/deviceTransactionConfig.d.ts +11 -0
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/deviceTransactionConfig.js +35 -0
- package/lib-es/deviceTransactionConfig.js.map +1 -0
- package/lib-es/errors.d.ts +4 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +6 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/estimateMaxSpendable.d.ts +5 -0
- package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/estimateMaxSpendable.js +30 -0
- package/lib-es/estimateMaxSpendable.js.map +1 -0
- package/lib-es/getTransactionStatus.d.ts +5 -0
- package/lib-es/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/getTransactionStatus.js +93 -0
- package/lib-es/getTransactionStatus.js.map +1 -0
- package/lib-es/hw-getAddress.d.ts +6 -0
- package/lib-es/hw-getAddress.d.ts.map +1 -0
- package/lib-es/hw-getAddress.js +29 -0
- package/lib-es/hw-getAddress.js.map +1 -0
- package/lib-es/hw-signMessage.d.ts +12 -0
- package/lib-es/hw-signMessage.d.ts.map +1 -0
- package/lib-es/hw-signMessage.js +29 -0
- package/lib-es/hw-signMessage.js.map +1 -0
- package/lib-es/prepareTransaction.d.ts +5 -0
- package/lib-es/prepareTransaction.d.ts.map +1 -0
- package/lib-es/prepareTransaction.js +27 -0
- package/lib-es/prepareTransaction.js.map +1 -0
- package/lib-es/signOperation.d.ts +11 -0
- package/lib-es/signOperation.d.ts.map +1 -0
- package/lib-es/signOperation.js +91 -0
- package/lib-es/signOperation.js.map +1 -0
- package/lib-es/signer.d.ts +27 -0
- package/lib-es/signer.d.ts.map +1 -0
- package/lib-es/signer.js +2 -0
- package/lib-es/signer.js.map +1 -0
- package/lib-es/specs.d.ts +8 -0
- package/lib-es/specs.d.ts.map +1 -0
- package/lib-es/specs.js +99 -0
- package/lib-es/specs.js.map +1 -0
- package/lib-es/speculos-deviceActions.d.ts +4 -0
- package/lib-es/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/speculos-deviceActions.js +31 -0
- package/lib-es/speculos-deviceActions.js.map +1 -0
- package/lib-es/synchronisation.d.ts +5 -0
- package/lib-es/synchronisation.d.ts.map +1 -0
- package/lib-es/synchronisation.js +88 -0
- package/lib-es/synchronisation.js.map +1 -0
- package/lib-es/transaction.d.ts +14 -0
- package/lib-es/transaction.d.ts.map +1 -0
- package/lib-es/transaction.js +33 -0
- package/lib-es/transaction.js.map +1 -0
- package/lib-es/types.d.ts +65 -0
- package/lib-es/types.d.ts.map +1 -0
- package/lib-es/types.js +2 -0
- package/lib-es/types.js.map +1 -0
- package/lib-es/utils.d.ts +11 -0
- package/lib-es/utils.d.ts.map +1 -0
- package/lib-es/utils.js +112 -0
- package/lib-es/utils.js.map +1 -0
- package/package.json +86 -0
- package/src/__tests__/fixtures/api.fixtures.ts +39 -0
- package/src/__tests__/fixtures/common.fixtures.ts +139 -0
- package/src/__tests__/integration/bridge.integration.test.ts +135 -0
- package/src/__tests__/unit/api.unit.test.ts +60 -0
- package/src/__tests__/unit/broadcast.unit.test.ts +36 -0
- package/src/__tests__/unit/createTransaction.unit.test.ts +20 -0
- package/src/__tests__/unit/deviceTransactionConfig.unit.test.ts +69 -0
- package/src/__tests__/unit/estimateMaxSpendable.unit.test.ts +19 -0
- package/src/__tests__/unit/getTransactionStatus.unit.test.ts +119 -0
- package/src/__tests__/unit/hw-getAddress.unit.test.ts +58 -0
- package/src/__tests__/unit/prepareTransaction.unit.test.ts +52 -0
- package/src/__tests__/unit/signOperation.unit.test.ts +90 -0
- package/src/__tests__/unit/txn.unit.test.ts +121 -0
- package/src/__tests__/unit/utils.unit.test.ts +126 -0
- package/src/bridge/bridgeHelpers/api.ts +104 -0
- package/src/bridge/bridgeHelpers/api.types.ts +178 -0
- package/src/bridge/bridgeHelpers/txn.ts +166 -0
- package/src/bridge/js.ts +65 -0
- package/src/broadcast.ts +13 -0
- package/src/cli-transaction.ts +30 -0
- package/src/config.ts +21 -0
- package/src/createTransaction.ts +17 -0
- package/src/deviceTransactionConfig.ts +48 -0
- package/src/errors.ts +6 -0
- package/src/estimateMaxSpendable.ts +40 -0
- package/src/getTransactionStatus.ts +130 -0
- package/src/hw-getAddress.ts +28 -0
- package/src/hw-signMessage.ts +31 -0
- package/src/prepareTransaction.ts +27 -0
- package/src/signOperation.ts +115 -0
- package/src/signer.ts +32 -0
- package/src/specs.ts +122 -0
- package/src/speculos-deviceActions.ts +38 -0
- package/src/synchronisation.ts +91 -0
- package/src/transaction.ts +61 -0
- package/src/types.ts +82 -0
- package/src/utils.ts +120 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
|
|
2
|
+
import { Account } from "@ledgerhq/types-live";
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
|
+
import {
|
|
5
|
+
TonAccountInfo,
|
|
6
|
+
TonResponseEstimateFee,
|
|
7
|
+
TonResponseWalletInfo,
|
|
8
|
+
TonTransactionsList,
|
|
9
|
+
} from "../../bridge/bridgeHelpers/api.types";
|
|
10
|
+
import type { Transaction } from "../../types";
|
|
11
|
+
|
|
12
|
+
export const mockAddress = "UQDzd8aeBOU-jqYw_ZSuZjceI5p-F4b7HMprAsUJAtRPbMol";
|
|
13
|
+
export const mockAccountId =
|
|
14
|
+
"js:2:ton:b19891a06654f21c64147550b3321bef63acd25b5dd61b688b022c42fac4831d:ton";
|
|
15
|
+
|
|
16
|
+
export const account = {
|
|
17
|
+
id: mockAccountId,
|
|
18
|
+
freshAddress: mockAddress,
|
|
19
|
+
freshAddressPath: "44'/607'/0'/0'/0'/0'",
|
|
20
|
+
xpub: "",
|
|
21
|
+
type: "Account",
|
|
22
|
+
currency: getCryptoCurrencyById("ton"),
|
|
23
|
+
spendableBalance: new BigNumber("1000000000"),
|
|
24
|
+
balance: new BigNumber("1000000000"),
|
|
25
|
+
seedIdentifier: "seedIdentifier",
|
|
26
|
+
} as Account;
|
|
27
|
+
|
|
28
|
+
export const transaction = {
|
|
29
|
+
mode: "send",
|
|
30
|
+
recipient: "UQCOvQLYvTcbi5tL9MaDNzuVl3-J3vATimNm9yO5XPafLfV4",
|
|
31
|
+
amount: new BigNumber("1000000"),
|
|
32
|
+
useAllAmount: false,
|
|
33
|
+
comment: { isEncrypted: false, text: "" },
|
|
34
|
+
payload: "",
|
|
35
|
+
family: "ton",
|
|
36
|
+
} as unknown as Transaction;
|
|
37
|
+
|
|
38
|
+
export const fees = {
|
|
39
|
+
in_fwd_fee: 10000,
|
|
40
|
+
storage_fee: 10000,
|
|
41
|
+
gas_fee: 10000,
|
|
42
|
+
fwd_fee: 10000,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const totalFees = BigNumber(
|
|
46
|
+
fees.fwd_fee + fees.gas_fee + fees.in_fwd_fee + fees.storage_fee,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
export const lastBlockNumber = {
|
|
50
|
+
last: {
|
|
51
|
+
seqno: 38574413,
|
|
52
|
+
},
|
|
53
|
+
first: {
|
|
54
|
+
seqno: 3,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const tonAccount: TonAccountInfo = {
|
|
59
|
+
balance: "1000000000",
|
|
60
|
+
last_transaction_lt: "47055058000008",
|
|
61
|
+
last_transaction_hash: "psVQqt6rf/Lo6xyLzxx0to0jUIx8I2/4znOVf2KhAI0=",
|
|
62
|
+
status: "active",
|
|
63
|
+
seqno: 3,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const tonWallet: TonResponseWalletInfo = {
|
|
67
|
+
balance: "7726736262",
|
|
68
|
+
wallet_type: "wallet v4 r2",
|
|
69
|
+
seqno: 22,
|
|
70
|
+
wallet_id: 698983191,
|
|
71
|
+
last_transaction_lt: "47055058000008",
|
|
72
|
+
last_transaction_hash: "psVQqt6rf/Lo6xyLzxx0to0jUIx8I2/4znOVf2KhAI0=",
|
|
73
|
+
status: "active",
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const tonEstimateFee: TonResponseEstimateFee = {
|
|
77
|
+
source_fees: fees,
|
|
78
|
+
destination_fees: [],
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const tonTransactionResponse: TonTransactionsList = {
|
|
82
|
+
transactions: [
|
|
83
|
+
{
|
|
84
|
+
account: mockAddress,
|
|
85
|
+
hash: "hash",
|
|
86
|
+
lt: "lt",
|
|
87
|
+
now: 1718241443,
|
|
88
|
+
orig_status: "active",
|
|
89
|
+
end_status: "active",
|
|
90
|
+
total_fees: "0",
|
|
91
|
+
prev_trans_hash: "",
|
|
92
|
+
prev_trans_lt: "",
|
|
93
|
+
description: {
|
|
94
|
+
aborted: true,
|
|
95
|
+
destroyed: false,
|
|
96
|
+
compute_ph: {
|
|
97
|
+
success: false,
|
|
98
|
+
exit_code: -14,
|
|
99
|
+
},
|
|
100
|
+
credit_first: true,
|
|
101
|
+
},
|
|
102
|
+
block_ref: null,
|
|
103
|
+
in_msg: {
|
|
104
|
+
source: "0:959EAA8BD0E3A2662D814278D51A6F997946207D48478008BEBE7F45F3EF781F",
|
|
105
|
+
destination: mockAddress,
|
|
106
|
+
value: "13509565",
|
|
107
|
+
hash: "inMsgHash",
|
|
108
|
+
fwd_fee: "266669",
|
|
109
|
+
ihr_fee: "0",
|
|
110
|
+
created_lt: "47055058000007",
|
|
111
|
+
created_at: "1718241443",
|
|
112
|
+
opcode: "0xd53276db",
|
|
113
|
+
ihr_disabled: true,
|
|
114
|
+
bounce: false,
|
|
115
|
+
bounced: false,
|
|
116
|
+
import_fee: null,
|
|
117
|
+
message_content: {
|
|
118
|
+
hash: "Qa0w2xg42wA9taurO/aCVOqGTzjOeP3EpzD2Sl7tTss=",
|
|
119
|
+
body: "te6cckEBAQEADgAAGNUydtsAAAAAAAAAAfRC8y4=",
|
|
120
|
+
decoded: null,
|
|
121
|
+
},
|
|
122
|
+
init_state: null,
|
|
123
|
+
},
|
|
124
|
+
out_msgs: [],
|
|
125
|
+
account_state_before: null,
|
|
126
|
+
account_state_after: null,
|
|
127
|
+
mc_block_seqno: 3,
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
address_book: {},
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export const accountInfo: TonAccountInfo = {
|
|
134
|
+
balance: "7726736262",
|
|
135
|
+
last_transaction_lt: "47055058000008",
|
|
136
|
+
last_transaction_hash: "lastTransactionHash",
|
|
137
|
+
status: "active",
|
|
138
|
+
seqno: 22,
|
|
139
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { InvalidAddress, NotEnoughBalance } from "@ledgerhq/errors";
|
|
2
|
+
import { CurrenciesData, DatasetTest } from "@ledgerhq/types-live";
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
|
+
import { TonCommentInvalid } from "../../errors";
|
|
5
|
+
import { fromTransactionRaw } from "../../transaction";
|
|
6
|
+
import { Transaction } from "../../types";
|
|
7
|
+
|
|
8
|
+
const PUBKEY = "86196cb40cd25e9e696bc808e3f2c074ce0b39f2a2a9d482a68eafef86e4a060";
|
|
9
|
+
const ADDRESS = "UQCOvQLYvTcbi5tL9MaDNzuVl3-J3vATimNm9yO5XPafLfV4";
|
|
10
|
+
const ADDRESS_2 = "UQAui6M4jOYOezUGfmeONA22Ars9yjd34YIGdAR1Pcpp4sgR";
|
|
11
|
+
const PATH = "44'/607'/0'/0'/0'/0'";
|
|
12
|
+
|
|
13
|
+
const ton: CurrenciesData<Transaction> = {
|
|
14
|
+
scanAccounts: [
|
|
15
|
+
{
|
|
16
|
+
name: "ton seed 1",
|
|
17
|
+
apdus: `
|
|
18
|
+
=> e005000019068000002c8000025f80000000800000008000000080000000
|
|
19
|
+
<= 86196cb40cd25e9e696bc808e3f2c074ce0b39f2a2a9d482a68eafef86e4a0609000
|
|
20
|
+
=> e005000019068000002c8000025f80000000800000008000000180000000
|
|
21
|
+
<= b5177c2b32f9d72fa8c673cc3d61acec6a9f68eb5e4945445fdbb48a45eb48879000
|
|
22
|
+
`,
|
|
23
|
+
test: (expect, accounts) => {
|
|
24
|
+
for (const account of accounts) {
|
|
25
|
+
expect(account.derivationMode).toEqual("ton");
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
accounts: [
|
|
31
|
+
{
|
|
32
|
+
FIXME_tests: ["balance is sum of ops"],
|
|
33
|
+
raw: {
|
|
34
|
+
id: `js:2:ton:${PUBKEY}:ton`,
|
|
35
|
+
currencyId: "ton",
|
|
36
|
+
seedIdentifier: PUBKEY,
|
|
37
|
+
name: "TON 1",
|
|
38
|
+
derivationMode: "ton",
|
|
39
|
+
index: 0,
|
|
40
|
+
freshAddress: ADDRESS,
|
|
41
|
+
freshAddressPath: PATH,
|
|
42
|
+
xpub: PUBKEY,
|
|
43
|
+
blockHeight: 0,
|
|
44
|
+
operations: [],
|
|
45
|
+
pendingOperations: [],
|
|
46
|
+
lastSyncDate: "",
|
|
47
|
+
balance: "5000000000",
|
|
48
|
+
subAccounts: [],
|
|
49
|
+
},
|
|
50
|
+
transactions: [
|
|
51
|
+
{
|
|
52
|
+
name: "Not a valid address",
|
|
53
|
+
transaction: fromTransactionRaw({
|
|
54
|
+
family: "ton",
|
|
55
|
+
recipient: "novalidaddress",
|
|
56
|
+
fees: "10000000",
|
|
57
|
+
amount: "1000",
|
|
58
|
+
comment: { isEncrypted: false, text: "" },
|
|
59
|
+
}),
|
|
60
|
+
expectedStatus: {
|
|
61
|
+
errors: {
|
|
62
|
+
recipient: new InvalidAddress(),
|
|
63
|
+
},
|
|
64
|
+
warnings: {},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "Not enough balance",
|
|
69
|
+
transaction: fromTransactionRaw({
|
|
70
|
+
family: "ton",
|
|
71
|
+
recipient: ADDRESS_2,
|
|
72
|
+
fees: "10000000",
|
|
73
|
+
amount: (300 * 1e9).toString(),
|
|
74
|
+
comment: { isEncrypted: false, text: "" },
|
|
75
|
+
}),
|
|
76
|
+
expectedStatus: {
|
|
77
|
+
errors: {
|
|
78
|
+
amount: new NotEnoughBalance(),
|
|
79
|
+
},
|
|
80
|
+
warnings: {},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "Invalid transferID/Memo",
|
|
85
|
+
transaction: fromTransactionRaw({
|
|
86
|
+
family: "ton",
|
|
87
|
+
recipient: ADDRESS_2,
|
|
88
|
+
fees: "10000000",
|
|
89
|
+
amount: (1 * 1e9).toString(),
|
|
90
|
+
comment: { isEncrypted: false, text: "😀" },
|
|
91
|
+
}),
|
|
92
|
+
expectedStatus: {
|
|
93
|
+
errors: {
|
|
94
|
+
comment: new TonCommentInvalid(),
|
|
95
|
+
},
|
|
96
|
+
warnings: {},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: "New account and sufficient amount",
|
|
101
|
+
transaction: fromTransactionRaw({
|
|
102
|
+
family: "ton",
|
|
103
|
+
recipient: ADDRESS_2,
|
|
104
|
+
fees: "10000000",
|
|
105
|
+
amount: "10000000",
|
|
106
|
+
comment: { isEncrypted: false, text: "Valid" },
|
|
107
|
+
}),
|
|
108
|
+
expectedStatus: {
|
|
109
|
+
amount: new BigNumber("10000000"),
|
|
110
|
+
errors: {},
|
|
111
|
+
warnings: {},
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export const dataset: DatasetTest<Transaction> = {
|
|
120
|
+
implementations: ["js"],
|
|
121
|
+
currencies: {
|
|
122
|
+
ton,
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* NOTE: if tests are added to this file,
|
|
128
|
+
* like done in libs/coin-polkadot/src/bridge.integration.test.ts for example,
|
|
129
|
+
* this file fill need to be imported in ledger-live-common
|
|
130
|
+
* libs/ledger-live-common/src/families/ton/bridge.integration.test.ts
|
|
131
|
+
* like done for polkadot.
|
|
132
|
+
* cf.
|
|
133
|
+
* - libs/coin-polkadot/src/bridge.integration.test.ts
|
|
134
|
+
* - libs/ledger-live-common/src/families/polkadot/bridge.integration.test.ts
|
|
135
|
+
*/
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {
|
|
2
|
+
estimateFee,
|
|
3
|
+
fetchAccountInfo,
|
|
4
|
+
fetchLastBlockNumber,
|
|
5
|
+
fetchTransactions,
|
|
6
|
+
} from "../../bridge/bridgeHelpers/api";
|
|
7
|
+
import { setCoinConfig } from "../../config";
|
|
8
|
+
import mockServer, { API_TON_ENDPOINT } from "../fixtures/api.fixtures";
|
|
9
|
+
import {
|
|
10
|
+
lastBlockNumber,
|
|
11
|
+
mockAddress,
|
|
12
|
+
tonAccount,
|
|
13
|
+
tonEstimateFee,
|
|
14
|
+
tonTransactionResponse,
|
|
15
|
+
tonWallet,
|
|
16
|
+
} from "../fixtures/common.fixtures";
|
|
17
|
+
|
|
18
|
+
describe("getAccount", () => {
|
|
19
|
+
beforeAll(() => {
|
|
20
|
+
setCoinConfig(() => ({
|
|
21
|
+
status: {
|
|
22
|
+
type: "active",
|
|
23
|
+
},
|
|
24
|
+
infra: {
|
|
25
|
+
API_TON_ENDPOINT: API_TON_ENDPOINT,
|
|
26
|
+
},
|
|
27
|
+
}));
|
|
28
|
+
mockServer.listen();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
afterAll(() => {
|
|
32
|
+
mockServer.close();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should return last block number", async () => {
|
|
36
|
+
const result = await fetchLastBlockNumber();
|
|
37
|
+
expect(result).toEqual(lastBlockNumber.last.seqno);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should return the transactions of an address", async () => {
|
|
41
|
+
const result = await fetchTransactions(mockAddress);
|
|
42
|
+
expect(result).toEqual(tonTransactionResponse);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should return the ton account info of an address", async () => {
|
|
46
|
+
const result = await fetchAccountInfo(mockAddress);
|
|
47
|
+
expect(result).toEqual({
|
|
48
|
+
balance: tonAccount.balance,
|
|
49
|
+
last_transaction_lt: tonAccount.last_transaction_lt,
|
|
50
|
+
last_transaction_hash: tonAccount.last_transaction_hash,
|
|
51
|
+
status: tonAccount.status,
|
|
52
|
+
seqno: tonWallet.seqno,
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("should return the estimated fees", async () => {
|
|
57
|
+
const result = await estimateFee(mockAddress, "");
|
|
58
|
+
expect(result).toEqual(tonEstimateFee.source_fees);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/lib/operation";
|
|
2
|
+
import { broadcastTx } from "../../bridge/bridgeHelpers/api";
|
|
3
|
+
import broadcast from "../../broadcast";
|
|
4
|
+
import { buildOptimisticOperation } from "../../signOperation";
|
|
5
|
+
import { account, transaction } from "../fixtures/common.fixtures";
|
|
6
|
+
|
|
7
|
+
jest.mock("../../bridge/bridgeHelpers/api");
|
|
8
|
+
const mockedHash = "validHash";
|
|
9
|
+
|
|
10
|
+
describe("broadcast", () => {
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
const broadcastTxMock = jest.mocked(broadcastTx);
|
|
13
|
+
broadcastTxMock.mockReturnValue(Promise.resolve(mockedHash));
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should broadcast the coin transaction and add the hash in the optimistic transaction", async () => {
|
|
17
|
+
const optimisticCoinOperation = buildOptimisticOperation(account, transaction);
|
|
18
|
+
|
|
19
|
+
const finalOperation = await broadcast({
|
|
20
|
+
account,
|
|
21
|
+
signedOperation: {
|
|
22
|
+
operation: optimisticCoinOperation,
|
|
23
|
+
signature: "0xS1gn4tUR3",
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
expect(broadcastTx).toHaveBeenCalled();
|
|
28
|
+
expect(finalOperation).toEqual({
|
|
29
|
+
...optimisticCoinOperation,
|
|
30
|
+
id: encodeOperationId(account.id, mockedHash, "OUT"),
|
|
31
|
+
hash: mockedHash,
|
|
32
|
+
subOperations: [],
|
|
33
|
+
nftOperations: [],
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import createTransaction from "../../createTransaction";
|
|
3
|
+
import { account } from "../fixtures/common.fixtures";
|
|
4
|
+
|
|
5
|
+
describe("createTransaction", () => {
|
|
6
|
+
it("should create a valid transaction", async () => {
|
|
7
|
+
const res = createTransaction(account);
|
|
8
|
+
expect(res).toEqual({
|
|
9
|
+
family: "ton",
|
|
10
|
+
amount: new BigNumber(0),
|
|
11
|
+
fees: new BigNumber(0),
|
|
12
|
+
recipient: "",
|
|
13
|
+
useAllAmount: false,
|
|
14
|
+
comment: {
|
|
15
|
+
isEncrypted: false,
|
|
16
|
+
text: "",
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import getDeviceTransactionConfig from "../../deviceTransactionConfig";
|
|
3
|
+
import { account, transaction as baseTransaction } from "../fixtures/common.fixtures";
|
|
4
|
+
|
|
5
|
+
const status = {
|
|
6
|
+
errors: {},
|
|
7
|
+
warnings: {},
|
|
8
|
+
estimatedFees: new BigNumber(0),
|
|
9
|
+
amount: new BigNumber(0),
|
|
10
|
+
totalSpent: new BigNumber(0),
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
describe("deviceTransactionConfig", () => {
|
|
14
|
+
describe("TON transaction", () => {
|
|
15
|
+
it("should return the fields for a transaction when there is a valid comment", async () => {
|
|
16
|
+
const transaction = {
|
|
17
|
+
...baseTransaction,
|
|
18
|
+
comment: { isEncrypted: false, text: "validComment" },
|
|
19
|
+
};
|
|
20
|
+
const res = await getDeviceTransactionConfig({
|
|
21
|
+
account: account,
|
|
22
|
+
parentAccount: undefined,
|
|
23
|
+
transaction,
|
|
24
|
+
status,
|
|
25
|
+
});
|
|
26
|
+
expect(res).toEqual([
|
|
27
|
+
{
|
|
28
|
+
type: "address",
|
|
29
|
+
label: "To",
|
|
30
|
+
address: transaction.recipient,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
type: "amount",
|
|
34
|
+
label: "Amount",
|
|
35
|
+
},
|
|
36
|
+
{ type: "fees", label: "Fee" },
|
|
37
|
+
{ type: "text", label: "Comment", value: "validComment" },
|
|
38
|
+
]);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should return the fields for a transaction when useAllAmount is true and there is a valid comment", async () => {
|
|
42
|
+
const transaction = {
|
|
43
|
+
...baseTransaction,
|
|
44
|
+
useAllAmount: true,
|
|
45
|
+
comment: { isEncrypted: false, text: "validComment" },
|
|
46
|
+
};
|
|
47
|
+
const res = await getDeviceTransactionConfig({
|
|
48
|
+
account: account,
|
|
49
|
+
parentAccount: undefined,
|
|
50
|
+
transaction,
|
|
51
|
+
status,
|
|
52
|
+
});
|
|
53
|
+
expect(res).toEqual([
|
|
54
|
+
{
|
|
55
|
+
type: "address",
|
|
56
|
+
label: "To",
|
|
57
|
+
address: transaction.recipient,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
type: "text",
|
|
61
|
+
label: "Amount",
|
|
62
|
+
value: "ALL YOUR TONs",
|
|
63
|
+
},
|
|
64
|
+
{ type: "fees", label: "Fee" },
|
|
65
|
+
{ type: "text", label: "Comment", value: "validComment" },
|
|
66
|
+
]);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { estimateFee, fetchAccountInfo } from "../../bridge/bridgeHelpers/api";
|
|
2
|
+
import estimateMaxSpendable from "../../estimateMaxSpendable";
|
|
3
|
+
import { account, accountInfo, fees, totalFees, transaction } from "../fixtures/common.fixtures";
|
|
4
|
+
|
|
5
|
+
jest.mock("../../bridge/bridgeHelpers/api");
|
|
6
|
+
|
|
7
|
+
describe("estimateMaxSpendable", () => {
|
|
8
|
+
beforeAll(() => {
|
|
9
|
+
const fetchAccountInfoMock = jest.mocked(fetchAccountInfo);
|
|
10
|
+
fetchAccountInfoMock.mockReturnValue(Promise.resolve(accountInfo));
|
|
11
|
+
const fetchEstimateFeeMock = jest.mocked(estimateFee);
|
|
12
|
+
fetchEstimateFeeMock.mockReturnValue(Promise.resolve(fees));
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should return the max spendable for a TON transaction", async () => {
|
|
16
|
+
const res = await estimateMaxSpendable({ account, transaction });
|
|
17
|
+
expect(res).toEqual(account.balance.minus(totalFees));
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AmountRequired,
|
|
3
|
+
InvalidAddress,
|
|
4
|
+
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
5
|
+
NotEnoughBalance,
|
|
6
|
+
RecipientRequired,
|
|
7
|
+
} from "@ledgerhq/errors";
|
|
8
|
+
import BigNumber from "bignumber.js";
|
|
9
|
+
import { TonCommentInvalid } from "../../errors";
|
|
10
|
+
import getTransactionStatus from "../../getTransactionStatus";
|
|
11
|
+
import { account, transaction as baseTransaction } from "../fixtures/common.fixtures";
|
|
12
|
+
|
|
13
|
+
describe("getTransactionStatus", () => {
|
|
14
|
+
describe("Recipient", () => {
|
|
15
|
+
it("should detect the missing recipient and have an error", async () => {
|
|
16
|
+
const transaction = { ...baseTransaction, recipient: "" };
|
|
17
|
+
const res = await getTransactionStatus(account, transaction);
|
|
18
|
+
expect(res.errors).toEqual(
|
|
19
|
+
expect.objectContaining({
|
|
20
|
+
recipient: new RecipientRequired(),
|
|
21
|
+
}),
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should detect the incorrect recipient and have an error", async () => {
|
|
26
|
+
const transaction = { ...baseTransaction, recipient: "isInvalid" };
|
|
27
|
+
const res = await getTransactionStatus(account, transaction);
|
|
28
|
+
expect(res.errors).toEqual(
|
|
29
|
+
expect.objectContaining({
|
|
30
|
+
recipient: new InvalidAddress("", {
|
|
31
|
+
currencyName: account.currency.name,
|
|
32
|
+
}),
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should detect the recipient and the sender are the same and have an error", async () => {
|
|
38
|
+
const transaction = {
|
|
39
|
+
...baseTransaction,
|
|
40
|
+
recipient: "UQDzd8aeBOU-jqYw_ZSuZjceI5p-F4b7HMprAsUJAtRPbMol",
|
|
41
|
+
};
|
|
42
|
+
const res = await getTransactionStatus(account, transaction);
|
|
43
|
+
expect(res.errors).toEqual(
|
|
44
|
+
expect.objectContaining({
|
|
45
|
+
recipient: new InvalidAddressBecauseDestinationIsAlsoSource("", {
|
|
46
|
+
currencyName: account.currency.name,
|
|
47
|
+
}),
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe("Sender", () => {
|
|
54
|
+
it("should detect the sender is not correct and have an error", async () => {
|
|
55
|
+
const tempAccount = { ...account, freshAddress: "isInvalid" };
|
|
56
|
+
const res = await getTransactionStatus(tempAccount, baseTransaction);
|
|
57
|
+
expect(res.errors).toEqual(
|
|
58
|
+
expect.objectContaining({
|
|
59
|
+
sender: new InvalidAddress(),
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe("Amount", () => {
|
|
66
|
+
it("should detect the amount is missing and have an error", async () => {
|
|
67
|
+
const transaction = { ...baseTransaction, amount: new BigNumber(0) };
|
|
68
|
+
const res = await getTransactionStatus(account, transaction);
|
|
69
|
+
expect(res.errors).toEqual(
|
|
70
|
+
expect.objectContaining({
|
|
71
|
+
amount: new AmountRequired(),
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("should detect the amount is greater than the spendable amount and have an error", async () => {
|
|
77
|
+
const transaction = {
|
|
78
|
+
...baseTransaction,
|
|
79
|
+
amount: BigNumber(1000000002),
|
|
80
|
+
fees: new BigNumber("20"),
|
|
81
|
+
};
|
|
82
|
+
const res = await getTransactionStatus(account, transaction);
|
|
83
|
+
expect(res.errors).toEqual(
|
|
84
|
+
expect.objectContaining({
|
|
85
|
+
amount: new NotEnoughBalance(),
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe("Comment", () => {
|
|
91
|
+
it("should detect the comment is not valid and have an error", async () => {
|
|
92
|
+
const transaction = {
|
|
93
|
+
...baseTransaction,
|
|
94
|
+
comment: { isEncrypted: false, text: "comment\nInvalid" },
|
|
95
|
+
};
|
|
96
|
+
const res = await getTransactionStatus(account, transaction);
|
|
97
|
+
expect(res.errors).toEqual(
|
|
98
|
+
expect.objectContaining({
|
|
99
|
+
transaction: new TonCommentInvalid(),
|
|
100
|
+
}),
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe("Successful transaction", () => {
|
|
106
|
+
it("should not have errors", async () => {
|
|
107
|
+
const successfulResult = {
|
|
108
|
+
amount: baseTransaction.amount,
|
|
109
|
+
errors: {},
|
|
110
|
+
warnings: {},
|
|
111
|
+
estimatedFees: baseTransaction.fees,
|
|
112
|
+
totalSpent: baseTransaction.amount.plus(baseTransaction.fees),
|
|
113
|
+
};
|
|
114
|
+
const res = await getTransactionStatus(account, baseTransaction);
|
|
115
|
+
expect(res).toEqual(successfulResult);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
|
|
2
|
+
import resolver from "../../hw-getAddress";
|
|
3
|
+
import { TonSigner } from "../../signer";
|
|
4
|
+
import { getLedgerTonPath } from "../../utils";
|
|
5
|
+
|
|
6
|
+
const address = "0xc3f95102d5c8f2c83e49ce3acfb905edfb7f37de";
|
|
7
|
+
const publicKey = "mockedPublicKey";
|
|
8
|
+
const spyGetAddress = jest.fn().mockImplementation(async () =>
|
|
9
|
+
Promise.resolve({
|
|
10
|
+
publicKey,
|
|
11
|
+
address: address.toLowerCase(),
|
|
12
|
+
}),
|
|
13
|
+
);
|
|
14
|
+
const spyValidateAddress = jest.fn().mockImplementation(async () =>
|
|
15
|
+
Promise.resolve({
|
|
16
|
+
publicKey,
|
|
17
|
+
address: address.toLowerCase(),
|
|
18
|
+
}),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const mockSignerFactory = <T>(_: string, fn: (signer: TonSigner) => Promise<T>): Promise<T> =>
|
|
22
|
+
fn({
|
|
23
|
+
getAddress: spyGetAddress,
|
|
24
|
+
validateAddress: spyValidateAddress,
|
|
25
|
+
signTransaction: jest.fn(),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("hw-getAddress", () => {
|
|
29
|
+
it("should return an encoded address and a public key when verifiy is false", async () => {
|
|
30
|
+
const getAddress = resolver(mockSignerFactory);
|
|
31
|
+
const response = await getAddress("deviceId", {
|
|
32
|
+
path: "44'/607'/0'/0'/0'/0'",
|
|
33
|
+
verify: false,
|
|
34
|
+
currency: getCryptoCurrencyById("ton"),
|
|
35
|
+
derivationMode: "ton",
|
|
36
|
+
});
|
|
37
|
+
expect(response.address).toBe(address);
|
|
38
|
+
expect(response.publicKey).toBe(publicKey);
|
|
39
|
+
expect(spyGetAddress).toHaveBeenCalledWith(getLedgerTonPath("44'/607'/0'/0'/0'/0'"), {
|
|
40
|
+
bounceable: false,
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("should return an encoded address and a public key when verifiy is true", async () => {
|
|
45
|
+
const getAddress = resolver(mockSignerFactory);
|
|
46
|
+
const response = await getAddress("deviceId", {
|
|
47
|
+
path: "44'/607'/0'/0'/0'/0'",
|
|
48
|
+
verify: true,
|
|
49
|
+
currency: getCryptoCurrencyById("ton"),
|
|
50
|
+
derivationMode: "ton",
|
|
51
|
+
});
|
|
52
|
+
expect(response.address).toBe(address);
|
|
53
|
+
expect(response.publicKey).toBe(publicKey);
|
|
54
|
+
expect(spyValidateAddress).toHaveBeenCalledWith(getLedgerTonPath("44'/607'/0'/0'/0'/0'"), {
|
|
55
|
+
bounceable: false,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|