@ledgerhq/coin-icon 0.4.1-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 +41 -0
- package/CHANGELOG.md +495 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +11 -0
- package/lib/__test__/api/index.unit.test.d.ts +2 -0
- package/lib/__test__/api/index.unit.test.d.ts.map +1 -0
- package/lib/__test__/api/index.unit.test.js +173 -0
- package/lib/__test__/api/index.unit.test.js.map +1 -0
- package/lib/__test__/unit/buildTransaction.test.d.ts +2 -0
- package/lib/__test__/unit/buildTransaction.test.d.ts.map +1 -0
- package/lib/__test__/unit/buildTransaction.test.js +76 -0
- package/lib/__test__/unit/buildTransaction.test.js.map +1 -0
- package/lib/__test__/unit/getFeesForTransaction.unit.test.d.ts +2 -0
- package/lib/__test__/unit/getFeesForTransaction.unit.test.d.ts.map +1 -0
- package/lib/__test__/unit/getFeesForTransaction.unit.test.js +101 -0
- package/lib/__test__/unit/getFeesForTransaction.unit.test.js.map +1 -0
- package/lib/__test__/unit/getTransactionStatus.unit.test.d.ts +2 -0
- package/lib/__test__/unit/getTransactionStatus.unit.test.d.ts.map +1 -0
- package/lib/__test__/unit/getTransactionStatus.unit.test.js +178 -0
- package/lib/__test__/unit/getTransactionStatus.unit.test.js.map +1 -0
- package/lib/__test__/unit/logic.unit.test.d.ts +2 -0
- package/lib/__test__/unit/logic.unit.test.d.ts.map +1 -0
- package/lib/__test__/unit/logic.unit.test.js +112 -0
- package/lib/__test__/unit/logic.unit.test.js.map +1 -0
- package/lib/__test__/unit/serializations.unit.test.d.ts +2 -0
- package/lib/__test__/unit/serializations.unit.test.d.ts.map +1 -0
- package/lib/__test__/unit/serializations.unit.test.js +73 -0
- package/lib/__test__/unit/serializations.unit.test.js.map +1 -0
- package/lib/__test__/unit/transaction.unit.test.d.ts +2 -0
- package/lib/__test__/unit/transaction.unit.test.d.ts.map +1 -0
- package/lib/__test__/unit/transaction.unit.test.js +130 -0
- package/lib/__test__/unit/transaction.unit.test.js.map +1 -0
- package/lib/account.d.ts +7 -0
- package/lib/account.d.ts.map +1 -0
- package/lib/account.js +26 -0
- package/lib/account.js.map +1 -0
- package/lib/api/api-type.d.ts +62 -0
- package/lib/api/api-type.d.ts.map +1 -0
- package/lib/api/api-type.js +3 -0
- package/lib/api/api-type.js.map +1 -0
- package/lib/api/index.d.ts +13 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +134 -0
- package/lib/api/index.js.map +1 -0
- package/lib/api/node.d.ts +31 -0
- package/lib/api/node.d.ts.map +1 -0
- package/lib/api/node.js +112 -0
- package/lib/api/node.js.map +1 -0
- package/lib/bridge/index.d.ts +13 -0
- package/lib/bridge/index.d.ts.map +1 -0
- package/lib/bridge/index.js +71 -0
- package/lib/bridge/index.js.map +1 -0
- package/lib/bridge.integration.test.d.ts +4 -0
- package/lib/bridge.integration.test.d.ts.map +1 -0
- package/lib/bridge.integration.test.js +105 -0
- package/lib/bridge.integration.test.js.map +1 -0
- package/lib/broadcast.d.ts +9 -0
- package/lib/broadcast.d.ts.map +1 -0
- package/lib/broadcast.js +25 -0
- package/lib/broadcast.js.map +1 -0
- package/lib/buildTransaction.d.ts +12 -0
- package/lib/buildTransaction.d.ts.map +1 -0
- package/lib/buildTransaction.js +55 -0
- package/lib/buildTransaction.js.map +1 -0
- package/lib/cli-transaction.d.ts +16 -0
- package/lib/cli-transaction.d.ts.map +1 -0
- package/lib/cli-transaction.js +35 -0
- package/lib/cli-transaction.js.map +1 -0
- package/lib/config.d.ts +15 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +17 -0
- package/lib/config.js.map +1 -0
- package/lib/constants.d.ts +14 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +17 -0
- package/lib/constants.js.map +1 -0
- package/lib/createTransaction.d.ts +8 -0
- package/lib/createTransaction.d.ts.map +1 -0
- package/lib/createTransaction.js +19 -0
- package/lib/createTransaction.js.map +1 -0
- package/lib/deviceTransactionConfig.d.ts +15 -0
- package/lib/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/deviceTransactionConfig.js +24 -0
- package/lib/deviceTransactionConfig.js.map +1 -0
- package/lib/errors.d.ts +10 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +8 -0
- package/lib/errors.js.map +1 -0
- package/lib/estimateMaxSpendable.d.ts +14 -0
- package/lib/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/estimateMaxSpendable.js +38 -0
- package/lib/estimateMaxSpendable.js.map +1 -0
- package/lib/getFeesForTransaction.d.ts +14 -0
- package/lib/getFeesForTransaction.d.ts.map +1 -0
- package/lib/getFeesForTransaction.js +44 -0
- package/lib/getFeesForTransaction.js.map +1 -0
- package/lib/getTransactionStatus.d.ts +4 -0
- package/lib/getTransactionStatus.d.ts.map +1 -0
- package/lib/getTransactionStatus.js +114 -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 +23 -0
- package/lib/hw-getAddress.js.map +1 -0
- package/lib/initAccount.d.ts +3 -0
- package/lib/initAccount.d.ts.map +1 -0
- package/lib/initAccount.js +13 -0
- package/lib/initAccount.js.map +1 -0
- package/lib/logic.d.ts +55 -0
- package/lib/logic.d.ts.map +1 -0
- package/lib/logic.js +124 -0
- package/lib/logic.js.map +1 -0
- package/lib/prepareTransaction.d.ts +9 -0
- package/lib/prepareTransaction.d.ts.map +1 -0
- package/lib/prepareTransaction.js +33 -0
- package/lib/prepareTransaction.js.map +1 -0
- package/lib/serialization.d.ts +7 -0
- package/lib/serialization.d.ts.map +1 -0
- package/lib/serialization.js +36 -0
- package/lib/serialization.js.map +1 -0
- package/lib/signOperation.d.ts +10 -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 +14 -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 +7 -0
- package/lib/specs.d.ts.map +1 -0
- package/lib/specs.js +100 -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 +44 -0
- package/lib/speculos-deviceActions.js.map +1 -0
- package/lib/synchronization.d.ts +3 -0
- package/lib/synchronization.d.ts.map +1 -0
- package/lib/synchronization.js +76 -0
- package/lib/synchronization.js.map +1 -0
- package/lib/transaction.d.ts +15 -0
- package/lib/transaction.d.ts.map +1 -0
- package/lib/transaction.js +39 -0
- package/lib/transaction.js.map +1 -0
- package/lib/types/bridge.fixture.d.ts +5 -0
- package/lib/types/bridge.fixture.d.ts.map +1 -0
- package/lib/types/bridge.fixture.js +77 -0
- package/lib/types/bridge.fixture.js.map +1 -0
- package/lib/types/index.d.ts +46 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +3 -0
- package/lib/types/index.js.map +1 -0
- package/lib-es/__test__/api/index.unit.test.d.ts +2 -0
- package/lib-es/__test__/api/index.unit.test.d.ts.map +1 -0
- package/lib-es/__test__/api/index.unit.test.js +145 -0
- package/lib-es/__test__/api/index.unit.test.js.map +1 -0
- package/lib-es/__test__/unit/buildTransaction.test.d.ts +2 -0
- package/lib-es/__test__/unit/buildTransaction.test.d.ts.map +1 -0
- package/lib-es/__test__/unit/buildTransaction.test.js +71 -0
- package/lib-es/__test__/unit/buildTransaction.test.js.map +1 -0
- package/lib-es/__test__/unit/getFeesForTransaction.unit.test.d.ts +2 -0
- package/lib-es/__test__/unit/getFeesForTransaction.unit.test.d.ts.map +1 -0
- package/lib-es/__test__/unit/getFeesForTransaction.unit.test.js +73 -0
- package/lib-es/__test__/unit/getFeesForTransaction.unit.test.js.map +1 -0
- package/lib-es/__test__/unit/getTransactionStatus.unit.test.d.ts +2 -0
- package/lib-es/__test__/unit/getTransactionStatus.unit.test.d.ts.map +1 -0
- package/lib-es/__test__/unit/getTransactionStatus.unit.test.js +153 -0
- package/lib-es/__test__/unit/getTransactionStatus.unit.test.js.map +1 -0
- package/lib-es/__test__/unit/logic.unit.test.d.ts +2 -0
- package/lib-es/__test__/unit/logic.unit.test.d.ts.map +1 -0
- package/lib-es/__test__/unit/logic.unit.test.js +107 -0
- package/lib-es/__test__/unit/logic.unit.test.js.map +1 -0
- package/lib-es/__test__/unit/serializations.unit.test.d.ts +2 -0
- package/lib-es/__test__/unit/serializations.unit.test.d.ts.map +1 -0
- package/lib-es/__test__/unit/serializations.unit.test.js +71 -0
- package/lib-es/__test__/unit/serializations.unit.test.js.map +1 -0
- package/lib-es/__test__/unit/transaction.unit.test.d.ts +2 -0
- package/lib-es/__test__/unit/transaction.unit.test.d.ts.map +1 -0
- package/lib-es/__test__/unit/transaction.unit.test.js +128 -0
- package/lib-es/__test__/unit/transaction.unit.test.js.map +1 -0
- package/lib-es/account.d.ts +7 -0
- package/lib-es/account.d.ts.map +1 -0
- package/lib-es/account.js +24 -0
- package/lib-es/account.js.map +1 -0
- package/lib-es/api/api-type.d.ts +62 -0
- package/lib-es/api/api-type.d.ts.map +1 -0
- package/lib-es/api/api-type.js +2 -0
- package/lib-es/api/api-type.js.map +1 -0
- package/lib-es/api/index.d.ts +13 -0
- package/lib-es/api/index.d.ts.map +1 -0
- package/lib-es/api/index.js +123 -0
- package/lib-es/api/index.js.map +1 -0
- package/lib-es/api/node.d.ts +31 -0
- package/lib-es/api/node.d.ts.map +1 -0
- package/lib-es/api/node.js +99 -0
- package/lib-es/api/node.js.map +1 -0
- package/lib-es/bridge/index.d.ts +13 -0
- package/lib-es/bridge/index.d.ts.map +1 -0
- package/lib-es/bridge/index.js +62 -0
- package/lib-es/bridge/index.js.map +1 -0
- package/lib-es/bridge.integration.test.d.ts +4 -0
- package/lib-es/bridge.integration.test.d.ts.map +1 -0
- package/lib-es/bridge.integration.test.js +99 -0
- package/lib-es/bridge.integration.test.js.map +1 -0
- package/lib-es/broadcast.d.ts +9 -0
- package/lib-es/broadcast.d.ts.map +1 -0
- package/lib-es/broadcast.js +21 -0
- package/lib-es/broadcast.js.map +1 -0
- package/lib-es/buildTransaction.d.ts +12 -0
- package/lib-es/buildTransaction.d.ts.map +1 -0
- package/lib-es/buildTransaction.js +48 -0
- package/lib-es/buildTransaction.js.map +1 -0
- package/lib-es/cli-transaction.d.ts +16 -0
- package/lib-es/cli-transaction.d.ts.map +1 -0
- package/lib-es/cli-transaction.js +29 -0
- package/lib-es/cli-transaction.js.map +1 -0
- package/lib-es/config.d.ts +15 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +12 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/constants.d.ts +14 -0
- package/lib-es/constants.d.ts.map +1 -0
- package/lib-es/constants.js +14 -0
- package/lib-es/constants.js.map +1 -0
- package/lib-es/createTransaction.d.ts +8 -0
- package/lib-es/createTransaction.d.ts.map +1 -0
- package/lib-es/createTransaction.js +15 -0
- package/lib-es/createTransaction.js.map +1 -0
- package/lib-es/deviceTransactionConfig.d.ts +15 -0
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/deviceTransactionConfig.js +22 -0
- package/lib-es/deviceTransactionConfig.js.map +1 -0
- package/lib-es/errors.d.ts +10 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +5 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/estimateMaxSpendable.d.ts +14 -0
- package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/estimateMaxSpendable.js +31 -0
- package/lib-es/estimateMaxSpendable.js.map +1 -0
- package/lib-es/getFeesForTransaction.d.ts +14 -0
- package/lib-es/getFeesForTransaction.d.ts.map +1 -0
- package/lib-es/getFeesForTransaction.js +42 -0
- package/lib-es/getFeesForTransaction.js.map +1 -0
- package/lib-es/getTransactionStatus.d.ts +4 -0
- package/lib-es/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/getTransactionStatus.js +109 -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 +21 -0
- package/lib-es/hw-getAddress.js.map +1 -0
- package/lib-es/initAccount.d.ts +3 -0
- package/lib-es/initAccount.d.ts.map +1 -0
- package/lib-es/initAccount.js +9 -0
- package/lib-es/initAccount.js.map +1 -0
- package/lib-es/logic.d.ts +55 -0
- package/lib-es/logic.d.ts.map +1 -0
- package/lib-es/logic.js +109 -0
- package/lib-es/logic.js.map +1 -0
- package/lib-es/prepareTransaction.d.ts +9 -0
- package/lib-es/prepareTransaction.d.ts.map +1 -0
- package/lib-es/prepareTransaction.js +26 -0
- package/lib-es/prepareTransaction.js.map +1 -0
- package/lib-es/serialization.d.ts +7 -0
- package/lib-es/serialization.d.ts.map +1 -0
- package/lib-es/serialization.js +29 -0
- package/lib-es/serialization.js.map +1 -0
- package/lib-es/signOperation.d.ts +10 -0
- package/lib-es/signOperation.d.ts.map +1 -0
- package/lib-es/signOperation.js +89 -0
- package/lib-es/signOperation.js.map +1 -0
- package/lib-es/signer.d.ts +14 -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 +7 -0
- package/lib-es/specs.d.ts.map +1 -0
- package/lib-es/specs.js +95 -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 +41 -0
- package/lib-es/speculos-deviceActions.js.map +1 -0
- package/lib-es/synchronization.d.ts +3 -0
- package/lib-es/synchronization.d.ts.map +1 -0
- package/lib-es/synchronization.js +69 -0
- package/lib-es/synchronization.js.map +1 -0
- package/lib-es/transaction.d.ts +15 -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/bridge.fixture.d.ts +5 -0
- package/lib-es/types/bridge.fixture.d.ts.map +1 -0
- package/lib-es/types/bridge.fixture.js +68 -0
- package/lib-es/types/bridge.fixture.js.map +1 -0
- package/lib-es/types/index.d.ts +46 -0
- package/lib-es/types/index.d.ts.map +1 -0
- package/lib-es/types/index.js +2 -0
- package/lib-es/types/index.js.map +1 -0
- package/package.json +85 -0
- package/src/__test__/api/index.unit.test.ts +151 -0
- package/src/__test__/unit/buildTransaction.test.ts +76 -0
- package/src/__test__/unit/getFeesForTransaction.unit.test.ts +76 -0
- package/src/__test__/unit/getTransactionStatus.unit.test.ts +172 -0
- package/src/__test__/unit/logic.unit.test.ts +145 -0
- package/src/__test__/unit/serializations.unit.test.ts +92 -0
- package/src/__test__/unit/transaction.unit.test.ts +144 -0
- package/src/account.ts +30 -0
- package/src/api/api-type.ts +65 -0
- package/src/api/index.ts +156 -0
- package/src/api/node.ts +115 -0
- package/src/bridge/index.ts +76 -0
- package/src/bridge.integration.test.ts +107 -0
- package/src/broadcast.ts +18 -0
- package/src/buildTransaction.ts +53 -0
- package/src/cli-transaction.ts +49 -0
- package/src/config.ts +29 -0
- package/src/constants.ts +14 -0
- package/src/createTransaction.ts +16 -0
- package/src/deviceTransactionConfig.ts +44 -0
- package/src/errors.ts +5 -0
- package/src/estimateMaxSpendable.ts +34 -0
- package/src/getFeesForTransaction.ts +46 -0
- package/src/getTransactionStatus.ts +139 -0
- package/src/hw-getAddress.ts +19 -0
- package/src/initAccount.ts +11 -0
- package/src/logic.ts +132 -0
- package/src/prepareTransaction.ts +24 -0
- package/src/serialization.ts +34 -0
- package/src/signOperation.ts +140 -0
- package/src/signer.ts +14 -0
- package/src/specs.ts +124 -0
- package/src/speculos-deviceActions.ts +46 -0
- package/src/synchronization.ts +70 -0
- package/src/transaction.ts +60 -0
- package/src/types/bridge.fixture.ts +75 -0
- package/src/types/index.ts +61 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ledgerhq/coin-icon",
|
|
3
|
+
"version": "0.4.1-next.0",
|
|
4
|
+
"description": "Ledger Icon Coin integration",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Ledger",
|
|
7
|
+
"LedgerWallet",
|
|
8
|
+
"icx",
|
|
9
|
+
"Icon",
|
|
10
|
+
"Hardware Wallet"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/LedgerHQ/ledger-live.git"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/LedgerHQ/ledger-live/issues"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/LedgerHQ/ledger-live/tree/develop/libs/coin-modules/coin-icon",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"typesVersions": {
|
|
24
|
+
"*": {
|
|
25
|
+
"lib/*": [
|
|
26
|
+
"lib/*"
|
|
27
|
+
],
|
|
28
|
+
"lib-es/*": [
|
|
29
|
+
"lib-es/*"
|
|
30
|
+
],
|
|
31
|
+
"*": [
|
|
32
|
+
"lib/*"
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"exports": {
|
|
37
|
+
"./lib/*": "./lib/*.js",
|
|
38
|
+
"./lib-es/*": "./lib-es/*.js",
|
|
39
|
+
"./*": {
|
|
40
|
+
"require": "./lib/*.js",
|
|
41
|
+
"default": "./lib-es/*.js"
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"license": "Apache-2.0",
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@faker-js/faker": "^8.4.1",
|
|
48
|
+
"bignumber.js": "^9.1.2",
|
|
49
|
+
"expect": "^27.4.6",
|
|
50
|
+
"icon-sdk-js": "1.5.2",
|
|
51
|
+
"invariant": "^2.2.2",
|
|
52
|
+
"lodash": "^4.17.21",
|
|
53
|
+
"prando": "^6.0.1",
|
|
54
|
+
"rxjs": "^7.8.1",
|
|
55
|
+
"@ledgerhq/coin-framework": "^0.17.0-next.0",
|
|
56
|
+
"@ledgerhq/cryptoassets": "^13.3.0-next.0",
|
|
57
|
+
"@ledgerhq/devices": "^8.4.2",
|
|
58
|
+
"@ledgerhq/errors": "^6.18.0",
|
|
59
|
+
"@ledgerhq/live-env": "^2.2.0-next.0",
|
|
60
|
+
"@ledgerhq/live-network": "^1.4.0-next.0",
|
|
61
|
+
"@ledgerhq/live-promise": "^0.1.0",
|
|
62
|
+
"@ledgerhq/logs": "^6.12.0",
|
|
63
|
+
"@ledgerhq/types-cryptoassets": "^7.15.0-next.0",
|
|
64
|
+
"@ledgerhq/types-live": "^6.50.0-next.0"
|
|
65
|
+
},
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@types/invariant": "^2.2.2",
|
|
68
|
+
"@types/jest": "^29.5.10",
|
|
69
|
+
"@types/lodash": "^4.14.191",
|
|
70
|
+
"jest": "^29.7.0",
|
|
71
|
+
"ts-jest": "^29.1.1"
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"coverage": "jest --coverage --testPathIgnorePatterns='/bridge.integration.test.ts|node_modules|lib-es|lib/' --passWithNoTests && mv coverage/coverage-final.json coverage/coverage-icon.json",
|
|
75
|
+
"clean": "rimraf lib lib-es",
|
|
76
|
+
"build": "tsc && tsc -m ES6 --outDir lib-es",
|
|
77
|
+
"prewatch": "pnpm build",
|
|
78
|
+
"watch": "tsc --watch",
|
|
79
|
+
"doc": "documentation readme src/** --section=API --pe ts --re ts --re d.ts",
|
|
80
|
+
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
|
|
81
|
+
"lint:fix": "pnpm lint --fix",
|
|
82
|
+
"test": "jest",
|
|
83
|
+
"unimported": "unimported"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import network from "@ledgerhq/live-network/network";
|
|
2
|
+
import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
3
|
+
|
|
4
|
+
import { fetchOperationList } from "../../api";
|
|
5
|
+
import { IconTransactionType } from "../../api/api-type";
|
|
6
|
+
import { isTestnet } from "../../logic";
|
|
7
|
+
import { getCoinConfig } from "../../config";
|
|
8
|
+
import querystring from "querystring";
|
|
9
|
+
import * as contants from "../../constants";
|
|
10
|
+
|
|
11
|
+
// Mock the necessary modules and functions
|
|
12
|
+
jest.mock("@ledgerhq/live-network/network");
|
|
13
|
+
jest.mock("@ledgerhq/coin-framework/operation");
|
|
14
|
+
jest.mock("@ledgerhq/cryptoassets");
|
|
15
|
+
jest.mock("../../logic");
|
|
16
|
+
jest.mock("../../config");
|
|
17
|
+
jest.mock("querystring");
|
|
18
|
+
jest.mock("@ledgerhq/logs");
|
|
19
|
+
|
|
20
|
+
describe("ICON API", () => {
|
|
21
|
+
const networkMock = network as jest.Mock;
|
|
22
|
+
const isTestnetMock = isTestnet as jest.Mock;
|
|
23
|
+
const getCoinConfigMock = getCoinConfig as jest.Mock;
|
|
24
|
+
const querystringMock = querystring.stringify as jest.Mock;
|
|
25
|
+
const mockedLogic = jest.mocked(contants);
|
|
26
|
+
|
|
27
|
+
isTestnetMock.mockReturnValue(true);
|
|
28
|
+
getCoinConfigMock.mockReturnValue({
|
|
29
|
+
infra: {
|
|
30
|
+
indexer: "mainnet-url",
|
|
31
|
+
indexer_testnet: "testnet-url",
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
jest.clearAllMocks();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("fetchOperationList", () => {
|
|
39
|
+
it("should recursively fetch operation list correctly", async () => {
|
|
40
|
+
const accountId = "accountId";
|
|
41
|
+
const addr = "hx123";
|
|
42
|
+
const skip = 0;
|
|
43
|
+
const network = { id: "icon" } as CryptoCurrency;
|
|
44
|
+
const maxLength = 10;
|
|
45
|
+
// @ts-expect-error type
|
|
46
|
+
mockedLogic.LIMIT = 10;
|
|
47
|
+
|
|
48
|
+
const tx1 = {
|
|
49
|
+
hash: "tx1",
|
|
50
|
+
from_address: addr,
|
|
51
|
+
to_address: "hx456",
|
|
52
|
+
transaction_fee: "10",
|
|
53
|
+
block_number: 12345,
|
|
54
|
+
block_timestamp: 1609459200000,
|
|
55
|
+
status: "0x1",
|
|
56
|
+
value: "1000",
|
|
57
|
+
} as IconTransactionType;
|
|
58
|
+
const tx2 = {
|
|
59
|
+
hash: "tx2",
|
|
60
|
+
from_address: "hx456",
|
|
61
|
+
to_address: addr,
|
|
62
|
+
transaction_fee: "5",
|
|
63
|
+
block_number: 12346,
|
|
64
|
+
block_timestamp: 1609459201000,
|
|
65
|
+
status: "0x1",
|
|
66
|
+
value: "2000",
|
|
67
|
+
} as IconTransactionType;
|
|
68
|
+
const txHistory = [tx1, tx2];
|
|
69
|
+
querystringMock.mockReturnValue("address=hx123&skip=0&limit=10");
|
|
70
|
+
networkMock.mockResolvedValue({ data: txHistory });
|
|
71
|
+
|
|
72
|
+
const result = await fetchOperationList(accountId, addr, skip, network, maxLength);
|
|
73
|
+
expect(result.length).toBe(2);
|
|
74
|
+
expect(networkMock).toHaveBeenCalledWith({
|
|
75
|
+
method: "GET",
|
|
76
|
+
url: `testnet-url/transactions/address/${addr}?address=${addr}&skip=${skip}&limit=${10}`,
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
it("should recursively fetch operation list correctly", async () => {
|
|
80
|
+
const accountId = "accountId";
|
|
81
|
+
const addr = "hx123";
|
|
82
|
+
const skip = 0;
|
|
83
|
+
const network = { id: "icon" } as CryptoCurrency;
|
|
84
|
+
const maxLength = 10;
|
|
85
|
+
// @ts-expect-error type
|
|
86
|
+
mockedLogic.LIMIT = 2; // set a small limit for easier testing
|
|
87
|
+
|
|
88
|
+
const tx1 = {
|
|
89
|
+
hash: "tx1",
|
|
90
|
+
from_address: addr,
|
|
91
|
+
to_address: "hx456",
|
|
92
|
+
transaction_fee: "10",
|
|
93
|
+
block_number: 12345,
|
|
94
|
+
block_timestamp: 1609459200000,
|
|
95
|
+
status: "0x1",
|
|
96
|
+
value: "1000",
|
|
97
|
+
} as IconTransactionType;
|
|
98
|
+
const tx2 = {
|
|
99
|
+
hash: "tx2",
|
|
100
|
+
from_address: "hx456",
|
|
101
|
+
to_address: addr,
|
|
102
|
+
transaction_fee: "5",
|
|
103
|
+
block_number: 12346,
|
|
104
|
+
block_timestamp: 1609459201000,
|
|
105
|
+
status: "0x1",
|
|
106
|
+
value: "2000",
|
|
107
|
+
} as IconTransactionType;
|
|
108
|
+
const tx3 = {
|
|
109
|
+
hash: "tx3",
|
|
110
|
+
from_address: addr,
|
|
111
|
+
to_address: "hx456",
|
|
112
|
+
transaction_fee: "15",
|
|
113
|
+
block_number: 12347,
|
|
114
|
+
block_timestamp: 1609459202000,
|
|
115
|
+
status: "0x1",
|
|
116
|
+
value: "1500",
|
|
117
|
+
} as IconTransactionType;
|
|
118
|
+
|
|
119
|
+
networkMock
|
|
120
|
+
.mockResolvedValueOnce({ data: [tx1, tx2] }) // First fetch returns two transactions
|
|
121
|
+
.mockResolvedValueOnce({ data: [tx3] }); // Second fetch returns one transaction
|
|
122
|
+
|
|
123
|
+
querystringMock
|
|
124
|
+
.mockReturnValueOnce("address=hx123&skip=0&limit=2")
|
|
125
|
+
.mockReturnValueOnce("address=hx123&skip=2&limit=2");
|
|
126
|
+
|
|
127
|
+
const result = await fetchOperationList(accountId, addr, skip, network, maxLength);
|
|
128
|
+
|
|
129
|
+
// Verify that the function was called recursively
|
|
130
|
+
expect(networkMock).toHaveBeenCalledTimes(2);
|
|
131
|
+
|
|
132
|
+
// Verify that the result includes all transactions fetched
|
|
133
|
+
expect(result.length).toBe(3);
|
|
134
|
+
expect(result).toEqual([
|
|
135
|
+
expect.objectContaining({ hash: "tx1" }),
|
|
136
|
+
expect.objectContaining({ hash: "tx2" }),
|
|
137
|
+
expect.objectContaining({ hash: "tx3" }),
|
|
138
|
+
]);
|
|
139
|
+
|
|
140
|
+
// Verify the URLs used in the network calls
|
|
141
|
+
expect(networkMock).toHaveBeenCalledWith({
|
|
142
|
+
method: "GET",
|
|
143
|
+
url: `testnet-url/transactions/address/${addr}?address=${addr}&skip=${skip}&limit=${2}`,
|
|
144
|
+
});
|
|
145
|
+
expect(networkMock).toHaveBeenCalledWith({
|
|
146
|
+
method: "GET",
|
|
147
|
+
url: `testnet-url/transactions/address/${addr}?address=${addr}&skip=${skip + 2}&limit=${2}`,
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { Transaction, IconAccount } from "../../types";
|
|
3
|
+
import { createFixtureAccount, createFixtureTransaction } from "../../types/bridge.fixture";
|
|
4
|
+
import { buildTransaction } from "../../buildTransaction";
|
|
5
|
+
|
|
6
|
+
const mockFrom = jest.fn().mockReturnThis();
|
|
7
|
+
const mockTo = jest.fn().mockReturnThis();
|
|
8
|
+
const mockValue = jest.fn().mockReturnThis();
|
|
9
|
+
const mockNid = jest.fn().mockReturnThis();
|
|
10
|
+
const mockNonce = jest.fn().mockReturnThis();
|
|
11
|
+
const mockTimestamp = jest.fn().mockReturnThis();
|
|
12
|
+
const mockVersion = jest.fn().mockReturnThis();
|
|
13
|
+
const mockStepLimit = jest.fn().mockReturnThis();
|
|
14
|
+
const mockBuild = jest.fn().mockReturnValue("mocked-transaction");
|
|
15
|
+
|
|
16
|
+
jest.mock("icon-sdk-js", () => ({
|
|
17
|
+
IconBuilder: {
|
|
18
|
+
IcxTransactionBuilder: jest.fn().mockImplementation(() => ({
|
|
19
|
+
from: mockFrom,
|
|
20
|
+
to: mockTo,
|
|
21
|
+
value: mockValue,
|
|
22
|
+
nid: mockNid,
|
|
23
|
+
nonce: mockNonce,
|
|
24
|
+
timestamp: mockTimestamp,
|
|
25
|
+
version: mockVersion,
|
|
26
|
+
stepLimit: mockStepLimit,
|
|
27
|
+
build: mockBuild,
|
|
28
|
+
})),
|
|
29
|
+
},
|
|
30
|
+
IconConverter: {
|
|
31
|
+
toHexNumber: jest.fn(value => `0x${value}`),
|
|
32
|
+
},
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
jest.mock("../../logic", () => ({
|
|
36
|
+
getNid: jest.fn().mockReturnValue(1),
|
|
37
|
+
getNonce: jest.fn().mockReturnValue(1),
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
describe("buildTransaction", () => {
|
|
41
|
+
const account = createFixtureAccount() as IconAccount;
|
|
42
|
+
const transaction = createFixtureTransaction({
|
|
43
|
+
mode: "send",
|
|
44
|
+
recipient: "WHATEVER",
|
|
45
|
+
}) as Transaction;
|
|
46
|
+
|
|
47
|
+
afterEach(() => {
|
|
48
|
+
jest.clearAllMocks();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("should build a transfer transaction", async () => {
|
|
52
|
+
const stepLimit = new BigNumber(100000);
|
|
53
|
+
const result = await buildTransaction(account, transaction, stepLimit);
|
|
54
|
+
|
|
55
|
+
expect(mockFrom).toHaveBeenCalledWith(account.freshAddress);
|
|
56
|
+
expect(mockTo).toHaveBeenCalledWith(transaction.recipient);
|
|
57
|
+
expect(mockValue).toHaveBeenCalledWith(expect.any(String));
|
|
58
|
+
expect(mockNid).toHaveBeenCalledWith(expect.any(String));
|
|
59
|
+
expect(mockNonce).toHaveBeenCalledWith(expect.any(String));
|
|
60
|
+
expect(mockTimestamp).toHaveBeenCalledWith(expect.any(String));
|
|
61
|
+
expect(mockVersion).toHaveBeenCalledWith(expect.any(String));
|
|
62
|
+
expect(mockStepLimit).toHaveBeenCalledWith(expect.any(String));
|
|
63
|
+
expect(result.unsigned).toBe("mocked-transaction");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("should throw an error for unsupported transaction mode", async () => {
|
|
67
|
+
const invalidTransaction: Transaction = {
|
|
68
|
+
...transaction,
|
|
69
|
+
mode: "invalid-mode",
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
await expect(buildTransaction(account, invalidTransaction)).rejects.toThrow(
|
|
73
|
+
"Unsupported transaction mode: invalid-mode",
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
|
|
3
|
+
import { getAbandonSeedAddress } from "@ledgerhq/cryptoassets";
|
|
4
|
+
import { IconAccount } from "../../types";
|
|
5
|
+
import { buildTransaction } from "../../buildTransaction";
|
|
6
|
+
import { getFees, getStepPrice } from "../../api/node";
|
|
7
|
+
import getEstimatedFees from "../../getFeesForTransaction";
|
|
8
|
+
import * as logic from "../../logic";
|
|
9
|
+
|
|
10
|
+
jest.mock("../../buildTransaction");
|
|
11
|
+
jest.mock("../../api/node");
|
|
12
|
+
jest.mock("@ledgerhq/cryptoassets");
|
|
13
|
+
jest.mock("../../logic");
|
|
14
|
+
|
|
15
|
+
const mockedLogic = jest.mocked(logic);
|
|
16
|
+
|
|
17
|
+
describe("getEstimatedFees", () => {
|
|
18
|
+
beforeAll(() => {
|
|
19
|
+
(global as any).FEES_SAFETY_BUFFER = new BigNumber(100);
|
|
20
|
+
});
|
|
21
|
+
it("should fetch the estimated fees correctly", async () => {
|
|
22
|
+
const account: IconAccount = {
|
|
23
|
+
currency: { id: "icon" },
|
|
24
|
+
spendableBalance: new BigNumber(1000),
|
|
25
|
+
pendingOperations: [],
|
|
26
|
+
iconResources: { nonce: 1 },
|
|
27
|
+
} as any;
|
|
28
|
+
|
|
29
|
+
const transaction = {
|
|
30
|
+
amount: new BigNumber(100),
|
|
31
|
+
recipient: "recipient-address",
|
|
32
|
+
fees: new BigNumber(10),
|
|
33
|
+
} as any;
|
|
34
|
+
|
|
35
|
+
const unsignedTx = {
|
|
36
|
+
/* mock unsigned transaction */
|
|
37
|
+
};
|
|
38
|
+
const stepLimit = new BigNumber(100000);
|
|
39
|
+
const stepPrice = new BigNumber(10);
|
|
40
|
+
|
|
41
|
+
(getAbandonSeedAddress as jest.Mock).mockReturnValue("fake-recipient-address");
|
|
42
|
+
mockedLogic.calculateAmount.mockReturnValue(new BigNumber(100));
|
|
43
|
+
(buildTransaction as jest.Mock).mockResolvedValue({ unsigned: unsignedTx });
|
|
44
|
+
(getFees as jest.Mock).mockResolvedValue(stepLimit);
|
|
45
|
+
(getStepPrice as jest.Mock).mockResolvedValue(stepPrice);
|
|
46
|
+
|
|
47
|
+
const estimatedFees = await getEstimatedFees({ account, transaction });
|
|
48
|
+
expect(estimatedFees.isEqualTo(stepLimit.multipliedBy(stepPrice))).toBe(true);
|
|
49
|
+
expect(transaction.stepLimit).toEqual(stepLimit);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("should return FEES_SAFETY_BUFFER if an error occurs", async () => {
|
|
53
|
+
const account = {
|
|
54
|
+
currency: { id: "icon" },
|
|
55
|
+
spendableBalance: new BigNumber(1000),
|
|
56
|
+
pendingOperations: [],
|
|
57
|
+
iconResources: { nonce: 1 },
|
|
58
|
+
} as any;
|
|
59
|
+
|
|
60
|
+
const transaction = {
|
|
61
|
+
amount: new BigNumber(100),
|
|
62
|
+
recipient: "recipient-address",
|
|
63
|
+
fees: new BigNumber(10),
|
|
64
|
+
} as any;
|
|
65
|
+
|
|
66
|
+
(getAbandonSeedAddress as jest.Mock).mockReturnValue("fake-recipient-address");
|
|
67
|
+
mockedLogic.calculateAmount.mockReturnValue(new BigNumber(100));
|
|
68
|
+
// @ts-expect-error type
|
|
69
|
+
mockedLogic.FEES_SAFETY_BUFFER = new BigNumber(100);
|
|
70
|
+
(buildTransaction as jest.Mock).mockRejectedValue(new Error("Error"));
|
|
71
|
+
// Mock getFees and getStepPrice if necessary, but they won't be called in this test case
|
|
72
|
+
|
|
73
|
+
const estimatedFees = await getEstimatedFees({ account, transaction });
|
|
74
|
+
expect(estimatedFees.isEqualTo(new BigNumber(100))).toBe(true);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import {
|
|
3
|
+
NotEnoughBalance,
|
|
4
|
+
RecipientRequired,
|
|
5
|
+
InvalidAddress,
|
|
6
|
+
FeeNotLoaded,
|
|
7
|
+
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
8
|
+
AmountRequired,
|
|
9
|
+
} from "@ledgerhq/errors";
|
|
10
|
+
import * as logic from "../../logic";
|
|
11
|
+
import { IconAccount, Transaction } from "../../types";
|
|
12
|
+
import { getSendTransactionStatus, getTransactionStatus } from "../../getTransactionStatus";
|
|
13
|
+
import * as TransactionStatus from "../../getTransactionStatus";
|
|
14
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
|
|
15
|
+
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
16
|
+
import { IconDoMaxSendInstead } from "../../errors";
|
|
17
|
+
|
|
18
|
+
jest.mock("../../logic");
|
|
19
|
+
jest.mock("../../api");
|
|
20
|
+
jest.mock("@ledgerhq/coin-framework/currencies/index");
|
|
21
|
+
|
|
22
|
+
const mockedLogic = jest.mocked(logic);
|
|
23
|
+
const mockedFormatCurrencyUnit = jest.mocked(formatCurrencyUnit);
|
|
24
|
+
|
|
25
|
+
describe("getSendTransactionStatus", () => {
|
|
26
|
+
let account: IconAccount;
|
|
27
|
+
let transaction: Transaction;
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
account = {
|
|
31
|
+
spendableBalance: new BigNumber(1000),
|
|
32
|
+
currency: {
|
|
33
|
+
name: "Icon",
|
|
34
|
+
units: [
|
|
35
|
+
{
|
|
36
|
+
code: "ICX",
|
|
37
|
+
name: "",
|
|
38
|
+
magnitude: 0,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
} as CryptoCurrency,
|
|
42
|
+
iconResources: {
|
|
43
|
+
totalDelegated: new BigNumber(0),
|
|
44
|
+
votingPower: new BigNumber(0),
|
|
45
|
+
nonce: 0,
|
|
46
|
+
},
|
|
47
|
+
} as IconAccount;
|
|
48
|
+
transaction = {
|
|
49
|
+
fees: new BigNumber(10),
|
|
50
|
+
recipient: "test-recipient",
|
|
51
|
+
useAllAmount: false,
|
|
52
|
+
} as Transaction;
|
|
53
|
+
mockedLogic.calculateAmount.mockReturnValue(new BigNumber(100));
|
|
54
|
+
mockedLogic.getMinimumBalance.mockReturnValue(new BigNumber(50));
|
|
55
|
+
mockedLogic.isSelfTransaction.mockReturnValue(false);
|
|
56
|
+
mockedLogic.isValidAddress.mockReturnValue(true);
|
|
57
|
+
mockedFormatCurrencyUnit.mockReturnValue("1 ICX");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should return FeeNotLoaded error if fees are not loaded", async () => {
|
|
61
|
+
transaction.fees = null;
|
|
62
|
+
const result = await getSendTransactionStatus(account, transaction);
|
|
63
|
+
expect(result.errors.fees).toBeInstanceOf(FeeNotLoaded);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("should return RecipientRequired error if recipient is missing", async () => {
|
|
67
|
+
transaction.recipient = "";
|
|
68
|
+
const result = await getSendTransactionStatus(account, transaction);
|
|
69
|
+
expect(result.errors.recipient).toBeInstanceOf(RecipientRequired);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("should return InvalidAddressBecauseDestinationIsAlsoSource error if recipient is the same as source", async () => {
|
|
73
|
+
mockedLogic.isSelfTransaction.mockReturnValue(true);
|
|
74
|
+
const result = await getSendTransactionStatus(account, transaction);
|
|
75
|
+
expect(result.errors.recipient).toBeInstanceOf(InvalidAddressBecauseDestinationIsAlsoSource);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("should return InvalidAddress error if recipient is invalid", async () => {
|
|
79
|
+
mockedLogic.isValidAddress.mockReturnValue(false);
|
|
80
|
+
const result = await getSendTransactionStatus(account, transaction);
|
|
81
|
+
expect(result.errors.recipient).toBeInstanceOf(InvalidAddress);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("should return AmountRequired error if amount is less than or equal to zero", async () => {
|
|
85
|
+
mockedLogic.calculateAmount.mockReturnValue(new BigNumber(0));
|
|
86
|
+
const result = await getSendTransactionStatus(account, transaction);
|
|
87
|
+
expect(result.errors.amount).toBeInstanceOf(AmountRequired);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("should return NotEnoughBalance error if total spent exceeds spendable balance", async () => {
|
|
91
|
+
account.spendableBalance = new BigNumber(50);
|
|
92
|
+
const result = await getSendTransactionStatus(account, transaction);
|
|
93
|
+
expect(result.errors.amount).toBeInstanceOf(NotEnoughBalance);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("should return proper TransactionStatus when everything is valid", async () => {
|
|
97
|
+
const result = await getSendTransactionStatus(account, transaction);
|
|
98
|
+
expect(result.errors).toEqual({});
|
|
99
|
+
expect(result.warnings).toEqual({});
|
|
100
|
+
expect(result.estimatedFees).toEqual(transaction.fees);
|
|
101
|
+
expect(result.amount).toEqual(new BigNumber(100));
|
|
102
|
+
expect(result.totalSpent).toEqual(new BigNumber(110));
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("should return IconDoMaxSendInstead error if leftover balance is less than minimumBalanceExistential but greater than zero", async () => {
|
|
106
|
+
account.spendableBalance = new BigNumber(120);
|
|
107
|
+
const result = await getSendTransactionStatus(account, transaction);
|
|
108
|
+
expect(result.errors.amount).toBeInstanceOf(IconDoMaxSendInstead);
|
|
109
|
+
expect(result.errors.amount.message).toBe(
|
|
110
|
+
"Balance cannot be below {{minimumBalance}}. Send max to empty account.",
|
|
111
|
+
);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe("getTransactionStatus", () => {
|
|
116
|
+
let account: IconAccount;
|
|
117
|
+
let transaction: Transaction;
|
|
118
|
+
|
|
119
|
+
beforeEach(() => {
|
|
120
|
+
account = {
|
|
121
|
+
spendableBalance: new BigNumber(1000),
|
|
122
|
+
currency: { name: "ICON", units: [{ code: "ICX" }] },
|
|
123
|
+
} as IconAccount;
|
|
124
|
+
transaction = {
|
|
125
|
+
fees: new BigNumber(10),
|
|
126
|
+
mode: "send",
|
|
127
|
+
useAllAmount: false,
|
|
128
|
+
} as Transaction;
|
|
129
|
+
mockedLogic.calculateAmount.mockReturnValue(new BigNumber(100));
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("should delegate to getSendTransactionStatus for send mode", async () => {
|
|
133
|
+
const sendTransactionStatus = {
|
|
134
|
+
errors: {},
|
|
135
|
+
warnings: {},
|
|
136
|
+
estimatedFees: new BigNumber(10),
|
|
137
|
+
amount: new BigNumber(100),
|
|
138
|
+
totalSpent: new BigNumber(110),
|
|
139
|
+
} as any;
|
|
140
|
+
jest
|
|
141
|
+
.spyOn(TransactionStatus, "getSendTransactionStatus")
|
|
142
|
+
.mockResolvedValue(sendTransactionStatus);
|
|
143
|
+
const result = await getTransactionStatus(account, transaction);
|
|
144
|
+
expect(result).toEqual(sendTransactionStatus);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("should handle default case correctly", async () => {
|
|
148
|
+
transaction.mode = "other";
|
|
149
|
+
const result = await getTransactionStatus(account, transaction);
|
|
150
|
+
expect(result.errors).toEqual({});
|
|
151
|
+
expect(result.warnings).toEqual({});
|
|
152
|
+
expect(result.estimatedFees).toEqual(transaction.fees);
|
|
153
|
+
expect(result.amount).toEqual(new BigNumber(100));
|
|
154
|
+
expect(result.totalSpent).toEqual(new BigNumber(110));
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("should return NotEnoughBalance error if totalSpent is greater than spendableBalance", async () => {
|
|
158
|
+
transaction.mode = "";
|
|
159
|
+
mockedLogic.calculateAmount.mockReturnValue(new BigNumber(1000));
|
|
160
|
+
transaction.fees = new BigNumber(100);
|
|
161
|
+
const result = await getTransactionStatus(account, transaction);
|
|
162
|
+
expect(result.errors.amount).toBeInstanceOf(NotEnoughBalance);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("should return AmountRequired error if amount is less than or equal to zero and useAllAmount is false", async () => {
|
|
166
|
+
transaction.mode = "";
|
|
167
|
+
mockedLogic.calculateAmount.mockReturnValue(new BigNumber(0));
|
|
168
|
+
transaction.useAllAmount = false;
|
|
169
|
+
const result = await getTransactionStatus(account, transaction);
|
|
170
|
+
expect(result.errors.amount).toBeInstanceOf(AmountRequired);
|
|
171
|
+
});
|
|
172
|
+
});
|