@ledgerhq/coin-casper 1.7.3 → 2.0.0-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/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +11 -35
- package/CHANGELOG.md +14 -0
- package/jest.config.js +2 -5
- package/lib/api/index.d.ts +8 -6
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.integ.test.js +12 -3
- package/lib/api/index.integ.test.js.map +1 -1
- package/lib/api/index.js +53 -91
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.d.ts +2 -0
- package/lib/api/index.test.d.ts.map +1 -0
- package/lib/api/index.test.js +274 -0
- package/lib/api/index.test.js.map +1 -0
- package/lib/api/types.d.ts +2 -67
- package/lib/api/types.d.ts.map +1 -1
- package/lib/bridge/bridgeHelpers/accountShape.d.ts.map +1 -1
- package/lib/bridge/bridgeHelpers/accountShape.js +5 -7
- package/lib/bridge/bridgeHelpers/accountShape.js.map +1 -1
- package/lib/bridge/bridgeHelpers/accountShape.test.d.ts +2 -0
- package/lib/bridge/bridgeHelpers/accountShape.test.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/accountShape.test.js +94 -0
- package/lib/bridge/bridgeHelpers/accountShape.test.js.map +1 -0
- package/lib/bridge/bridgeHelpers/addresses.d.ts +3 -9
- package/lib/bridge/bridgeHelpers/addresses.d.ts.map +1 -1
- package/lib/bridge/bridgeHelpers/addresses.js +5 -62
- package/lib/bridge/bridgeHelpers/addresses.js.map +1 -1
- package/lib/bridge/bridgeHelpers/txn.d.ts +2 -2
- package/lib/bridge/bridgeHelpers/txn.d.ts.map +1 -1
- package/lib/bridge/bridgeHelpers/txn.js +9 -11
- package/lib/bridge/bridgeHelpers/txn.js.map +1 -1
- package/lib/bridge/bridgeHelpers/txn.test.d.ts +2 -0
- package/lib/bridge/bridgeHelpers/txn.test.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/txn.test.js +306 -0
- package/lib/bridge/bridgeHelpers/txn.test.js.map +1 -0
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +7 -6
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/broadcast.test.d.ts +2 -0
- package/lib/bridge/broadcast.test.d.ts.map +1 -0
- package/lib/bridge/broadcast.test.js +72 -0
- package/lib/bridge/broadcast.test.js.map +1 -0
- package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -1
- package/lib/bridge/buildOptimisticOperation.js +2 -0
- package/lib/bridge/buildOptimisticOperation.js.map +1 -1
- package/lib/bridge/buildOptimisticOperation.test.d.ts +2 -0
- package/lib/bridge/buildOptimisticOperation.test.d.ts.map +1 -0
- package/lib/bridge/buildOptimisticOperation.test.js +76 -0
- package/lib/bridge/buildOptimisticOperation.test.js.map +1 -0
- package/lib/bridge/createTransaction.test.d.ts +2 -0
- package/lib/bridge/createTransaction.test.d.ts.map +1 -0
- package/lib/bridge/createTransaction.test.js +41 -0
- package/lib/bridge/createTransaction.test.js.map +1 -0
- package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/bridge/deviceTransactionConfig.js +13 -0
- package/lib/bridge/deviceTransactionConfig.js.map +1 -1
- package/lib/bridge/deviceTransactionConfig.test.d.ts +2 -0
- package/lib/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
- package/lib/bridge/deviceTransactionConfig.test.js +148 -0
- package/lib/bridge/deviceTransactionConfig.test.js.map +1 -0
- package/lib/bridge/estimateMaxSpendable.test.d.ts +2 -0
- package/lib/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
- package/lib/bridge/estimateMaxSpendable.test.js +133 -0
- package/lib/bridge/estimateMaxSpendable.test.js.map +1 -0
- package/lib/bridge/getTransactionStatus.test.d.ts +2 -0
- package/lib/bridge/getTransactionStatus.test.d.ts.map +1 -0
- package/lib/bridge/getTransactionStatus.test.js +214 -0
- package/lib/bridge/getTransactionStatus.test.js.map +1 -0
- package/lib/bridge/index.d.ts +2 -1
- package/lib/bridge/index.d.ts.map +1 -1
- package/lib/bridge/index.js +3 -1
- package/lib/bridge/index.js.map +1 -1
- package/lib/bridge/prepareTransaction.js +1 -1
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/prepareTransaction.test.d.ts +2 -0
- package/lib/bridge/prepareTransaction.test.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.test.js +159 -0
- package/lib/bridge/prepareTransaction.test.js.map +1 -0
- package/lib/bridge/signOperation.d.ts.map +1 -1
- package/lib/bridge/signOperation.js +14 -12
- package/lib/bridge/signOperation.js.map +1 -1
- package/lib/bridge/transaction.test.d.ts +2 -0
- package/lib/bridge/transaction.test.d.ts.map +1 -0
- package/lib/bridge/transaction.test.js +179 -0
- package/lib/bridge/transaction.test.js.map +1 -0
- package/lib/common-logic/utils.additional.test.d.ts +2 -0
- package/lib/common-logic/utils.additional.test.d.ts.map +1 -0
- package/lib/common-logic/utils.additional.test.js +58 -0
- package/lib/common-logic/utils.additional.test.js.map +1 -0
- package/lib/common-logic/utils.unit.test.js +6 -4
- package/lib/common-logic/utils.unit.test.js.map +1 -1
- package/lib/config.d.ts +10 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +16 -0
- package/lib/config.js.map +1 -0
- package/lib/consts.d.ts +3 -0
- package/lib/consts.d.ts.map +1 -1
- package/lib/consts.js +5 -1
- package/lib/consts.js.map +1 -1
- package/lib/hw-signMessage.test.d.ts +2 -0
- package/lib/hw-signMessage.test.d.ts.map +1 -0
- package/lib/hw-signMessage.test.js +80 -0
- package/lib/hw-signMessage.test.js.map +1 -0
- package/lib/signer/getAddress.js +1 -1
- package/lib/signer/getAddress.js.map +1 -1
- package/lib/signer/getAddress.test.d.ts +2 -0
- package/lib/signer/getAddress.test.d.ts.map +1 -0
- package/lib/signer/getAddress.test.js +133 -0
- package/lib/signer/getAddress.test.js.map +1 -0
- package/lib/test/bot-specs.d.ts.map +1 -1
- package/lib/test/bot-specs.js +1 -0
- package/lib/test/bot-specs.js.map +1 -1
- package/lib/test/fixtures.d.ts +131 -0
- package/lib/test/fixtures.d.ts.map +1 -0
- package/lib/test/fixtures.js +395 -0
- package/lib/test/fixtures.js.map +1 -0
- package/lib/test/index.d.ts +2 -0
- package/lib/test/index.d.ts.map +1 -1
- package/lib/test/index.js +2 -0
- package/lib/test/index.js.map +1 -1
- package/lib/test/speculos-deviceActions.d.ts.map +1 -1
- package/lib/test/speculos-deviceActions.js +4 -3
- package/lib/test/speculos-deviceActions.js.map +1 -1
- package/lib-es/api/index.d.ts +8 -6
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.integ.test.js +13 -4
- package/lib-es/api/index.integ.test.js.map +1 -1
- package/lib-es/api/index.js +51 -90
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.d.ts +2 -0
- package/lib-es/api/index.test.d.ts.map +1 -0
- package/lib-es/api/index.test.js +269 -0
- package/lib-es/api/index.test.js.map +1 -0
- package/lib-es/api/types.d.ts +2 -67
- package/lib-es/api/types.d.ts.map +1 -1
- package/lib-es/bridge/bridgeHelpers/accountShape.d.ts.map +1 -1
- package/lib-es/bridge/bridgeHelpers/accountShape.js +6 -8
- package/lib-es/bridge/bridgeHelpers/accountShape.js.map +1 -1
- package/lib-es/bridge/bridgeHelpers/accountShape.test.d.ts +2 -0
- package/lib-es/bridge/bridgeHelpers/accountShape.test.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/accountShape.test.js +89 -0
- package/lib-es/bridge/bridgeHelpers/accountShape.test.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/addresses.d.ts +3 -9
- package/lib-es/bridge/bridgeHelpers/addresses.d.ts.map +1 -1
- package/lib-es/bridge/bridgeHelpers/addresses.js +5 -60
- package/lib-es/bridge/bridgeHelpers/addresses.js.map +1 -1
- package/lib-es/bridge/bridgeHelpers/txn.d.ts +2 -2
- package/lib-es/bridge/bridgeHelpers/txn.d.ts.map +1 -1
- package/lib-es/bridge/bridgeHelpers/txn.js +10 -12
- package/lib-es/bridge/bridgeHelpers/txn.js.map +1 -1
- package/lib-es/bridge/bridgeHelpers/txn.test.d.ts +2 -0
- package/lib-es/bridge/bridgeHelpers/txn.test.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/txn.test.js +278 -0
- package/lib-es/bridge/bridgeHelpers/txn.test.js.map +1 -0
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +8 -7
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/broadcast.test.d.ts +2 -0
- package/lib-es/bridge/broadcast.test.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.test.js +70 -0
- package/lib-es/bridge/broadcast.test.js.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -1
- package/lib-es/bridge/buildOptimisticOperation.js +2 -0
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -1
- package/lib-es/bridge/buildOptimisticOperation.test.d.ts +2 -0
- package/lib-es/bridge/buildOptimisticOperation.test.d.ts.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.test.js +74 -0
- package/lib-es/bridge/buildOptimisticOperation.test.js.map +1 -0
- package/lib-es/bridge/createTransaction.test.d.ts +2 -0
- package/lib-es/bridge/createTransaction.test.d.ts.map +1 -0
- package/lib-es/bridge/createTransaction.test.js +36 -0
- package/lib-es/bridge/createTransaction.test.js.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -1
- package/lib-es/bridge/deviceTransactionConfig.js +13 -0
- package/lib-es/bridge/deviceTransactionConfig.js.map +1 -1
- package/lib-es/bridge/deviceTransactionConfig.test.d.ts +2 -0
- package/lib-es/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.test.js +143 -0
- package/lib-es/bridge/deviceTransactionConfig.test.js.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.test.d.ts +2 -0
- package/lib-es/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.test.js +131 -0
- package/lib-es/bridge/estimateMaxSpendable.test.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.test.d.ts +2 -0
- package/lib-es/bridge/getTransactionStatus.test.d.ts.map +1 -0
- package/lib-es/bridge/getTransactionStatus.test.js +212 -0
- package/lib-es/bridge/getTransactionStatus.test.js.map +1 -0
- package/lib-es/bridge/index.d.ts +2 -1
- package/lib-es/bridge/index.d.ts.map +1 -1
- package/lib-es/bridge/index.js +3 -1
- package/lib-es/bridge/index.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +1 -1
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.test.d.ts +2 -0
- package/lib-es/bridge/prepareTransaction.test.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.test.js +157 -0
- package/lib-es/bridge/prepareTransaction.test.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -1
- package/lib-es/bridge/signOperation.js +16 -14
- package/lib-es/bridge/signOperation.js.map +1 -1
- package/lib-es/bridge/transaction.test.d.ts +2 -0
- package/lib-es/bridge/transaction.test.d.ts.map +1 -0
- package/lib-es/bridge/transaction.test.js +154 -0
- package/lib-es/bridge/transaction.test.js.map +1 -0
- package/lib-es/common-logic/utils.additional.test.d.ts +2 -0
- package/lib-es/common-logic/utils.additional.test.d.ts.map +1 -0
- package/lib-es/common-logic/utils.additional.test.js +56 -0
- package/lib-es/common-logic/utils.additional.test.js.map +1 -0
- package/lib-es/common-logic/utils.unit.test.js +7 -5
- package/lib-es/common-logic/utils.unit.test.js.map +1 -1
- package/lib-es/config.d.ts +10 -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/consts.d.ts +3 -0
- package/lib-es/consts.d.ts.map +1 -1
- package/lib-es/consts.js +4 -0
- package/lib-es/consts.js.map +1 -1
- package/lib-es/hw-signMessage.test.d.ts +2 -0
- package/lib-es/hw-signMessage.test.d.ts.map +1 -0
- package/lib-es/hw-signMessage.test.js +78 -0
- package/lib-es/hw-signMessage.test.js.map +1 -0
- package/lib-es/signer/getAddress.js +2 -2
- package/lib-es/signer/getAddress.js.map +1 -1
- package/lib-es/signer/getAddress.test.d.ts +2 -0
- package/lib-es/signer/getAddress.test.d.ts.map +1 -0
- package/lib-es/signer/getAddress.test.js +105 -0
- package/lib-es/signer/getAddress.test.js.map +1 -0
- package/lib-es/test/bot-specs.d.ts.map +1 -1
- package/lib-es/test/bot-specs.js +1 -0
- package/lib-es/test/bot-specs.js.map +1 -1
- package/lib-es/test/fixtures.d.ts +131 -0
- package/lib-es/test/fixtures.d.ts.map +1 -0
- package/lib-es/test/fixtures.js +381 -0
- package/lib-es/test/fixtures.js.map +1 -0
- package/lib-es/test/index.d.ts +2 -0
- package/lib-es/test/index.d.ts.map +1 -1
- package/lib-es/test/index.js +2 -0
- package/lib-es/test/index.js.map +1 -1
- package/lib-es/test/speculos-deviceActions.d.ts.map +1 -1
- package/lib-es/test/speculos-deviceActions.js +5 -4
- package/lib-es/test/speculos-deviceActions.js.map +1 -1
- package/package.json +17 -12
- package/src/api/index.integ.test.ts +14 -4
- package/src/api/index.test.ts +386 -0
- package/src/api/index.ts +59 -117
- package/src/api/types.ts +2 -75
- package/src/bridge/bridgeHelpers/accountShape.test.ts +122 -0
- package/src/bridge/bridgeHelpers/accountShape.ts +7 -9
- package/src/bridge/bridgeHelpers/addresses.ts +6 -73
- package/src/bridge/bridgeHelpers/txn.test.ts +339 -0
- package/src/bridge/bridgeHelpers/txn.ts +18 -18
- package/src/bridge/broadcast.test.ts +89 -0
- package/src/bridge/broadcast.ts +9 -7
- package/src/bridge/buildOptimisticOperation.test.ts +89 -0
- package/src/bridge/buildOptimisticOperation.ts +2 -0
- package/src/bridge/createTransaction.test.ts +43 -0
- package/src/bridge/deviceTransactionConfig.test.ts +171 -0
- package/src/bridge/deviceTransactionConfig.ts +14 -0
- package/src/bridge/estimateMaxSpendable.test.ts +155 -0
- package/src/bridge/getTransactionStatus.test.ts +264 -0
- package/src/bridge/index.ts +8 -1
- package/src/bridge/prepareTransaction.test.ts +174 -0
- package/src/bridge/prepareTransaction.ts +1 -1
- package/src/bridge/signOperation.ts +16 -25
- package/src/bridge/transaction.test.ts +182 -0
- package/src/common-logic/utils.additional.test.ts +75 -0
- package/src/common-logic/utils.unit.test.ts +9 -7
- package/src/config.ts +22 -0
- package/src/consts.ts +5 -0
- package/src/hw-signMessage.test.ts +123 -0
- package/src/signer/getAddress.test.ts +134 -0
- package/src/signer/getAddress.ts +2 -2
- package/src/test/bot-specs.ts +1 -0
- package/src/test/fixtures.ts +448 -0
- package/src/test/index.ts +2 -0
- package/src/test/speculos-deviceActions.ts +6 -4
- package/tsconfig.json +1 -4
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { Account, Operation, OperationType } from "@ledgerhq/types-live";
|
|
3
|
+
import type { Transaction, CasperOperation } from "../types";
|
|
4
|
+
import { getEstimatedFees } from "../bridge/bridgeHelpers/fee";
|
|
5
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
6
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
|
|
7
|
+
import { CASPER_MINIMUM_VALID_AMOUNT_MOTES } from "../consts";
|
|
8
|
+
import { encodeAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
9
|
+
import { ITxnHistoryData } from "../api/types";
|
|
10
|
+
import { DerivationMode } from "@ledgerhq/types-live";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Sample Casper addresses for testing
|
|
14
|
+
*/
|
|
15
|
+
export const TEST_ADDRESSES = {
|
|
16
|
+
// Sample public key for SECP256K1 derivation
|
|
17
|
+
SECP256K1: "0202ba6dc98cbe677711a45bf028a03646f9e588996eb223fad2485e8bc391b01581",
|
|
18
|
+
// Sample recipient address for SECP256K1 format
|
|
19
|
+
RECIPIENT_SECP256K1: "0203A17118eC0e64c4e4FdbDbEe0eA14D118C9aAf08C6c81bbB776Cae607cEB84EcB",
|
|
20
|
+
// Sample recipient address for ED25519 format
|
|
21
|
+
RECIPIENT_ED25519: "01e28f293af356e7a15068e535c248ec07c887b2ab7a5d9557037a0e998e5d97bf",
|
|
22
|
+
// Invalid address for negative tests
|
|
23
|
+
INVALID: "notavalidaddress",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Sample transaction hashes for testing
|
|
28
|
+
*/
|
|
29
|
+
export const TEST_TRANSACTION_HASHES = {
|
|
30
|
+
VALID: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
|
|
31
|
+
PENDING: "pending0123456789abcdef0123456789abcdef0123456789abcdef01234567",
|
|
32
|
+
FAILED: "failed00123456789abcdef0123456789abcdef0123456789abcdef01234567",
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Sample transfer IDs for testing
|
|
37
|
+
*/
|
|
38
|
+
export const TEST_TRANSFER_IDS = {
|
|
39
|
+
VALID: "123456",
|
|
40
|
+
NUMERIC: "654321",
|
|
41
|
+
INVALID: "not-a-valid-id",
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Create a mock Casper account for testing
|
|
46
|
+
*
|
|
47
|
+
* @param options Optional parameters to override default values
|
|
48
|
+
* @returns A mock Casper account
|
|
49
|
+
*/
|
|
50
|
+
export const createMockAccount = (options?: Partial<Account>): Account => {
|
|
51
|
+
const seedIdentifier = options?.seedIdentifier || TEST_ADDRESSES.SECP256K1;
|
|
52
|
+
const currency = getCryptoCurrencyById("casper");
|
|
53
|
+
|
|
54
|
+
const account: Account = {
|
|
55
|
+
id: `js:2:casper:${seedIdentifier}:casper_wallet`,
|
|
56
|
+
seedIdentifier,
|
|
57
|
+
derivationMode: "casper_wallet",
|
|
58
|
+
index: options?.index || 0,
|
|
59
|
+
freshAddress: options?.freshAddress || seedIdentifier,
|
|
60
|
+
freshAddressPath: options?.freshAddressPath || "44'/506'/0'/0/1",
|
|
61
|
+
blockHeight: options?.blockHeight || 0,
|
|
62
|
+
balance:
|
|
63
|
+
options?.balance instanceof BigNumber
|
|
64
|
+
? options.balance
|
|
65
|
+
: new BigNumber(options?.balance || "10000000000"), // 10 CSPR
|
|
66
|
+
spendableBalance:
|
|
67
|
+
options?.spendableBalance instanceof BigNumber
|
|
68
|
+
? options.spendableBalance
|
|
69
|
+
: new BigNumber(options?.spendableBalance || "10000000000"), // 10 CSPR
|
|
70
|
+
operations: options?.operations || [],
|
|
71
|
+
pendingOperations: options?.pendingOperations || [],
|
|
72
|
+
type: "Account",
|
|
73
|
+
swapHistory: [],
|
|
74
|
+
syncHash: undefined,
|
|
75
|
+
nfts: [],
|
|
76
|
+
used: true,
|
|
77
|
+
currency,
|
|
78
|
+
operationsCount: 0,
|
|
79
|
+
subAccounts: [],
|
|
80
|
+
creationDate: new Date(),
|
|
81
|
+
lastSyncDate: new Date(),
|
|
82
|
+
balanceHistoryCache: {
|
|
83
|
+
HOUR: { latestDate: null, balances: [] },
|
|
84
|
+
DAY: { latestDate: null, balances: [] },
|
|
85
|
+
WEEK: { latestDate: null, balances: [] },
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return { ...account, ...options };
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Create a mock Casper transaction for testing
|
|
94
|
+
*
|
|
95
|
+
* @param options Optional parameters to override default values
|
|
96
|
+
* @returns A mock Casper transaction
|
|
97
|
+
*/
|
|
98
|
+
export const createMockTransaction = (options?: Partial<Transaction>): Transaction => {
|
|
99
|
+
const defaultFees = getEstimatedFees();
|
|
100
|
+
|
|
101
|
+
const transaction: Transaction = {
|
|
102
|
+
family: "casper",
|
|
103
|
+
amount:
|
|
104
|
+
options?.amount instanceof BigNumber
|
|
105
|
+
? options.amount
|
|
106
|
+
: new BigNumber(options?.amount || CASPER_MINIMUM_VALID_AMOUNT_MOTES),
|
|
107
|
+
recipient: options?.recipient || TEST_ADDRESSES.RECIPIENT_SECP256K1,
|
|
108
|
+
fees: options?.fees instanceof BigNumber ? options.fees : defaultFees,
|
|
109
|
+
transferId: options?.transferId,
|
|
110
|
+
useAllAmount: options?.useAllAmount || false,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
return { ...transaction, ...options };
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Create a mock Casper operation for testing
|
|
118
|
+
*
|
|
119
|
+
* @param account The account associated with the operation
|
|
120
|
+
* @param transaction The transaction details
|
|
121
|
+
* @param options Optional parameters to override default values
|
|
122
|
+
* @returns A mock Casper operation
|
|
123
|
+
*/
|
|
124
|
+
export const createMockOperation = (
|
|
125
|
+
account: Account,
|
|
126
|
+
transaction: Transaction,
|
|
127
|
+
options?: Partial<Operation>,
|
|
128
|
+
): CasperOperation => {
|
|
129
|
+
const hash = options?.hash || "0x" + Math.random().toString(16).substring(2, 10);
|
|
130
|
+
const type = (options?.type as OperationType) || "OUT";
|
|
131
|
+
|
|
132
|
+
const operation: CasperOperation = {
|
|
133
|
+
id: options?.id || encodeOperationId(account.id, hash, type),
|
|
134
|
+
hash,
|
|
135
|
+
type,
|
|
136
|
+
senders: [account.freshAddress],
|
|
137
|
+
recipients: [transaction.recipient],
|
|
138
|
+
accountId: account.id,
|
|
139
|
+
blockHash: options?.blockHash || null,
|
|
140
|
+
blockHeight: options?.blockHeight || null,
|
|
141
|
+
value: transaction.amount.plus(transaction.fees),
|
|
142
|
+
fee: transaction.fees,
|
|
143
|
+
date: options?.date || new Date(),
|
|
144
|
+
extra: {
|
|
145
|
+
transferId: transaction.transferId,
|
|
146
|
+
},
|
|
147
|
+
nftOperations: [],
|
|
148
|
+
subOperations: [],
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
return { ...operation, ...options } as CasperOperation;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Creates a set of accounts with different balances and statuses for comprehensive testing
|
|
156
|
+
*
|
|
157
|
+
* @returns An array of mock Casper accounts
|
|
158
|
+
*/
|
|
159
|
+
export const createMockAccountSet = (): Account[] => {
|
|
160
|
+
return [
|
|
161
|
+
// Standard account with balance
|
|
162
|
+
createMockAccount(),
|
|
163
|
+
|
|
164
|
+
// Empty account
|
|
165
|
+
createMockAccount({
|
|
166
|
+
balance: new BigNumber("0"),
|
|
167
|
+
spendableBalance: new BigNumber("0"),
|
|
168
|
+
}),
|
|
169
|
+
|
|
170
|
+
// Account with pending operations
|
|
171
|
+
createMockAccount({
|
|
172
|
+
pendingOperations: [
|
|
173
|
+
createMockOperation(
|
|
174
|
+
createMockAccount(),
|
|
175
|
+
createMockTransaction({ amount: new BigNumber("500000000") }),
|
|
176
|
+
{ type: "OUT", id: "pending-op-1" },
|
|
177
|
+
),
|
|
178
|
+
],
|
|
179
|
+
}),
|
|
180
|
+
|
|
181
|
+
// Account with high balance
|
|
182
|
+
createMockAccount({
|
|
183
|
+
balance: new BigNumber("100000000000000"), // 100,000 CSPR
|
|
184
|
+
spendableBalance: new BigNumber("100000000000000"),
|
|
185
|
+
}),
|
|
186
|
+
];
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Creates a set of transactions with different parameters for validation testing
|
|
191
|
+
*
|
|
192
|
+
* @returns An array of mock Casper transactions
|
|
193
|
+
*/
|
|
194
|
+
export const createMockTransactionSet = (): Transaction[] => {
|
|
195
|
+
return [
|
|
196
|
+
// Standard valid transaction
|
|
197
|
+
createMockTransaction({
|
|
198
|
+
amount: new BigNumber("1000000000"), // 1 CSPR
|
|
199
|
+
}),
|
|
200
|
+
|
|
201
|
+
// Transaction with invalid recipient
|
|
202
|
+
createMockTransaction({
|
|
203
|
+
recipient: TEST_ADDRESSES.INVALID,
|
|
204
|
+
}),
|
|
205
|
+
|
|
206
|
+
// Transaction with zero amount (should fail validation)
|
|
207
|
+
createMockTransaction({
|
|
208
|
+
amount: new BigNumber("0"),
|
|
209
|
+
}),
|
|
210
|
+
|
|
211
|
+
// Transaction with very high amount (should trigger warnings)
|
|
212
|
+
createMockTransaction({
|
|
213
|
+
amount: new BigNumber("999000000000"), // 999 CSPR
|
|
214
|
+
}),
|
|
215
|
+
|
|
216
|
+
// Transaction with transfer ID
|
|
217
|
+
createMockTransaction({
|
|
218
|
+
transferId: TEST_TRANSFER_IDS.VALID,
|
|
219
|
+
}),
|
|
220
|
+
|
|
221
|
+
// Transaction with invalid transfer ID
|
|
222
|
+
createMockTransaction({
|
|
223
|
+
transferId: TEST_TRANSFER_IDS.INVALID,
|
|
224
|
+
}),
|
|
225
|
+
|
|
226
|
+
// Transaction with useAllAmount flag
|
|
227
|
+
createMockTransaction({
|
|
228
|
+
useAllAmount: true,
|
|
229
|
+
}),
|
|
230
|
+
];
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Creates a set of operations with different types and statuses for testing
|
|
235
|
+
*
|
|
236
|
+
* @param account The account to associate with the operations
|
|
237
|
+
* @returns An array of mock Casper operations
|
|
238
|
+
*/
|
|
239
|
+
export const createMockOperationSet = (account: Account): CasperOperation[] => {
|
|
240
|
+
const standardTx = createMockTransaction({
|
|
241
|
+
amount: new BigNumber("1000000000"),
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
const largeTx = createMockTransaction({
|
|
245
|
+
amount: new BigNumber("5000000000"),
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
const smallTx = createMockTransaction({
|
|
249
|
+
amount: new BigNumber("100000000"),
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
const transferIdTx = createMockTransaction({
|
|
253
|
+
transferId: TEST_TRANSFER_IDS.VALID,
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
// Create operations with different dates for sorting tests
|
|
257
|
+
const now = new Date();
|
|
258
|
+
const yesterday = new Date(now);
|
|
259
|
+
yesterday.setDate(yesterday.getDate() - 1);
|
|
260
|
+
const lastWeek = new Date(now);
|
|
261
|
+
lastWeek.setDate(lastWeek.getDate() - 7);
|
|
262
|
+
const lastMonth = new Date(now);
|
|
263
|
+
lastMonth.setMonth(lastMonth.getMonth() - 1);
|
|
264
|
+
|
|
265
|
+
return [
|
|
266
|
+
// Standard OUT operation
|
|
267
|
+
createMockOperation(account, standardTx, {
|
|
268
|
+
type: "OUT",
|
|
269
|
+
hash: "0xoutoperation1",
|
|
270
|
+
date: now,
|
|
271
|
+
}),
|
|
272
|
+
|
|
273
|
+
// IN operation
|
|
274
|
+
createMockOperation(account, standardTx, {
|
|
275
|
+
type: "IN",
|
|
276
|
+
hash: "0xinoperation1",
|
|
277
|
+
date: yesterday,
|
|
278
|
+
senders: [TEST_ADDRESSES.RECIPIENT_SECP256K1], // Override sender
|
|
279
|
+
}),
|
|
280
|
+
|
|
281
|
+
// Large amount operation
|
|
282
|
+
createMockOperation(account, largeTx, {
|
|
283
|
+
type: "OUT",
|
|
284
|
+
hash: "0xoutlarge1",
|
|
285
|
+
date: lastWeek,
|
|
286
|
+
}),
|
|
287
|
+
|
|
288
|
+
// Small amount operation
|
|
289
|
+
createMockOperation(account, smallTx, {
|
|
290
|
+
type: "OUT",
|
|
291
|
+
hash: "0xoutsmall1",
|
|
292
|
+
date: lastMonth,
|
|
293
|
+
}),
|
|
294
|
+
|
|
295
|
+
// Operation with transfer ID
|
|
296
|
+
createMockOperation(account, transferIdTx, {
|
|
297
|
+
type: "OUT",
|
|
298
|
+
hash: "0xtransferid1",
|
|
299
|
+
date: lastMonth,
|
|
300
|
+
}),
|
|
301
|
+
|
|
302
|
+
// Operation with block height
|
|
303
|
+
createMockOperation(account, standardTx, {
|
|
304
|
+
type: "OUT",
|
|
305
|
+
hash: "0xwithblock1",
|
|
306
|
+
blockHeight: 12345,
|
|
307
|
+
blockHash: "0xblockhash123",
|
|
308
|
+
date: lastMonth,
|
|
309
|
+
}),
|
|
310
|
+
];
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Creates a mock signed operation for testing broadcast functionality
|
|
315
|
+
*
|
|
316
|
+
* @param account The account associated with the operation
|
|
317
|
+
* @param transaction The transaction to create the signed operation from
|
|
318
|
+
* @param options Optional parameters to override default values
|
|
319
|
+
* @returns A mock signed operation
|
|
320
|
+
*/
|
|
321
|
+
export const createMockSignedOperation = (
|
|
322
|
+
account: Account,
|
|
323
|
+
transaction: Transaction,
|
|
324
|
+
options?: {
|
|
325
|
+
signature?: string;
|
|
326
|
+
rawTxJson?: object;
|
|
327
|
+
operationOptions?: Partial<Operation>;
|
|
328
|
+
},
|
|
329
|
+
) => {
|
|
330
|
+
const operation = createMockOperation(account, transaction, options?.operationOptions);
|
|
331
|
+
|
|
332
|
+
return {
|
|
333
|
+
signature: options?.signature || "deadbeef1234567890abcdef",
|
|
334
|
+
operation,
|
|
335
|
+
rawData: {
|
|
336
|
+
tx: JSON.stringify(
|
|
337
|
+
options?.rawTxJson || {
|
|
338
|
+
hash: TEST_TRANSACTION_HASHES.VALID,
|
|
339
|
+
header: {
|
|
340
|
+
account: account.freshAddress,
|
|
341
|
+
timestamp: new Date().getTime(),
|
|
342
|
+
},
|
|
343
|
+
payment: {
|
|
344
|
+
target: transaction.recipient,
|
|
345
|
+
amount: transaction.amount.toString(),
|
|
346
|
+
},
|
|
347
|
+
fee: transaction.fees.toString(),
|
|
348
|
+
},
|
|
349
|
+
),
|
|
350
|
+
},
|
|
351
|
+
};
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Creates mock data for testing account shape functionality
|
|
356
|
+
*
|
|
357
|
+
* @returns Object containing mock data for account shape tests
|
|
358
|
+
*/
|
|
359
|
+
export const createMockAccountShapeData = () => {
|
|
360
|
+
const mockAddress = TEST_ADDRESSES.SECP256K1;
|
|
361
|
+
const mockCurrency = getCryptoCurrencyById("casper");
|
|
362
|
+
const mockDerivationMode: DerivationMode = "casper_wallet";
|
|
363
|
+
const mockAccountInfo = {
|
|
364
|
+
address: mockAddress,
|
|
365
|
+
currency: mockCurrency,
|
|
366
|
+
derivationMode: mockDerivationMode,
|
|
367
|
+
index: 0,
|
|
368
|
+
derivationPath: "44'/506'/0'/0/0",
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
const mockAccountId = encodeAccountId({
|
|
372
|
+
type: "js",
|
|
373
|
+
version: "2",
|
|
374
|
+
currencyId: mockCurrency.id,
|
|
375
|
+
xpubOrAddress: mockAddress,
|
|
376
|
+
derivationMode: mockDerivationMode,
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
const mockBlockHeight = 12345;
|
|
380
|
+
const mockPurseUref = "uref-1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef-007";
|
|
381
|
+
const mockAccountHash =
|
|
382
|
+
"account-hash-1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
383
|
+
const mockBalance = new BigNumber("1000000000");
|
|
384
|
+
|
|
385
|
+
const mockTxs: ITxnHistoryData[] = [
|
|
386
|
+
{
|
|
387
|
+
deploy_hash: "deploy-hash-1",
|
|
388
|
+
block_hash: "block-hash-1",
|
|
389
|
+
caller_public_key: mockAddress,
|
|
390
|
+
execution_type_id: 1,
|
|
391
|
+
cost: "10000",
|
|
392
|
+
payment_amount: "100000000",
|
|
393
|
+
timestamp: "2023-01-01T12:00:00Z",
|
|
394
|
+
status: "success",
|
|
395
|
+
args: {
|
|
396
|
+
id: {
|
|
397
|
+
parsed: 12345,
|
|
398
|
+
cl_type: {
|
|
399
|
+
Option: "U64",
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
amount: {
|
|
403
|
+
parsed: "500000000",
|
|
404
|
+
cl_type: "U512",
|
|
405
|
+
},
|
|
406
|
+
target: {
|
|
407
|
+
parsed: TEST_ADDRESSES.RECIPIENT_SECP256K1,
|
|
408
|
+
cl_type: "PublicKey",
|
|
409
|
+
},
|
|
410
|
+
},
|
|
411
|
+
amount: "500000000",
|
|
412
|
+
},
|
|
413
|
+
];
|
|
414
|
+
|
|
415
|
+
const mockOperations = [
|
|
416
|
+
{
|
|
417
|
+
id: "mock-operation-id",
|
|
418
|
+
hash: "deploy-hash-1",
|
|
419
|
+
type: "OUT",
|
|
420
|
+
value: new BigNumber("550000000"),
|
|
421
|
+
fee: new BigNumber("50000000"),
|
|
422
|
+
blockHeight: 12345,
|
|
423
|
+
blockHash: null,
|
|
424
|
+
hasFailed: false,
|
|
425
|
+
accountId: mockAccountId,
|
|
426
|
+
senders: [mockAccountHash],
|
|
427
|
+
recipients: ["recipient-account-hash"],
|
|
428
|
+
date: new Date("2023-01-01T12:00:00Z"),
|
|
429
|
+
extra: {
|
|
430
|
+
transferId: "12345",
|
|
431
|
+
},
|
|
432
|
+
},
|
|
433
|
+
];
|
|
434
|
+
|
|
435
|
+
return {
|
|
436
|
+
mockAddress,
|
|
437
|
+
mockCurrency,
|
|
438
|
+
mockDerivationMode,
|
|
439
|
+
mockAccountInfo,
|
|
440
|
+
mockAccountId,
|
|
441
|
+
mockBlockHeight,
|
|
442
|
+
mockPurseUref,
|
|
443
|
+
mockAccountHash,
|
|
444
|
+
mockBalance,
|
|
445
|
+
mockTxs,
|
|
446
|
+
mockOperations,
|
|
447
|
+
};
|
|
448
|
+
};
|
package/src/test/index.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { deviceActionFlow, SpeculosButton } from "@ledgerhq/coin-framework/bot/specs";
|
|
2
2
|
import { DeviceAction } from "@ledgerhq/coin-framework/bot/types";
|
|
3
|
-
|
|
3
|
+
|
|
4
4
|
import type { Transaction } from "../types";
|
|
5
|
+
import { casperAccountHashFromPublicKey } from "../bridge/bridgeHelpers/addresses";
|
|
6
|
+
import { CASPER_NETWORK } from "../consts";
|
|
5
7
|
|
|
6
8
|
export const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
7
9
|
steps: [
|
|
@@ -22,12 +24,12 @@ export const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlo
|
|
|
22
24
|
{
|
|
23
25
|
title: "Chain ID",
|
|
24
26
|
button: SpeculosButton.RIGHT,
|
|
25
|
-
expectedValue: () =>
|
|
27
|
+
expectedValue: () => CASPER_NETWORK,
|
|
26
28
|
},
|
|
27
29
|
{
|
|
28
30
|
title: "Account",
|
|
29
31
|
button: SpeculosButton.RIGHT,
|
|
30
|
-
expectedValue: ({ account }) =>
|
|
32
|
+
expectedValue: ({ account }) => casperAccountHashFromPublicKey(account.freshAddress),
|
|
31
33
|
},
|
|
32
34
|
{
|
|
33
35
|
title: "Fee",
|
|
@@ -38,7 +40,7 @@ export const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlo
|
|
|
38
40
|
{
|
|
39
41
|
title: "Target",
|
|
40
42
|
button: SpeculosButton.RIGHT,
|
|
41
|
-
expectedValue: ({ transaction }) =>
|
|
43
|
+
expectedValue: ({ transaction }) => casperAccountHashFromPublicKey(transaction.recipient),
|
|
42
44
|
},
|
|
43
45
|
{
|
|
44
46
|
title: "Amount",
|
package/tsconfig.json
CHANGED
|
@@ -5,11 +5,8 @@
|
|
|
5
5
|
"declarationMap": true,
|
|
6
6
|
"downlevelIteration": true,
|
|
7
7
|
"lib": ["es2020", "dom"],
|
|
8
|
-
"rootDir": "./src",
|
|
9
8
|
"outDir": "lib",
|
|
10
|
-
"exactOptionalPropertyTypes": true
|
|
11
|
-
"module": "esnext",
|
|
12
|
-
"moduleResolution": "bundler"
|
|
9
|
+
"exactOptionalPropertyTypes": true
|
|
13
10
|
},
|
|
14
11
|
"include": ["src/**/*", "deviceTransactionConfig.ts", "transaction.ts"]
|
|
15
12
|
}
|