@ledgerhq/coin-tron 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +20 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +25 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/jest.integ.config.js +7 -0
- package/lib/bridge/broadcast.d.ts +7 -0
- package/lib/bridge/broadcast.d.ts.map +1 -0
- package/lib/bridge/broadcast.js +26 -0
- package/lib/bridge/broadcast.js.map +1 -0
- package/lib/bridge/buildOptimisticOperation.d.ts +5 -0
- package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib/bridge/buildOptimisticOperation.js +101 -0
- package/lib/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib/bridge/createTransaction.d.ts +4 -0
- package/lib/bridge/createTransaction.d.ts.map +1 -0
- package/lib/bridge/createTransaction.js +19 -0
- package/lib/bridge/createTransaction.js.map +1 -0
- package/lib/bridge/deviceTransactionConfig.d.ts +20 -0
- package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/bridge/deviceTransactionConfig.js +65 -0
- package/lib/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib/bridge/estimateMaxSpendable.d.ts +5 -0
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/bridge/estimateMaxSpendable.js +30 -0
- package/lib/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib/bridge/getEstimateFees.d.ts +6 -0
- package/lib/bridge/getEstimateFees.d.ts.map +1 -0
- package/lib/bridge/getEstimateFees.js +52 -0
- package/lib/bridge/getEstimateFees.js.map +1 -0
- package/lib/bridge/getTransactionStatus.d.ts +4 -0
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib/bridge/getTransactionStatus.js +218 -0
- package/lib/bridge/getTransactionStatus.js.map +1 -0
- package/lib/bridge/index.d.ts +10 -0
- package/lib/bridge/index.d.ts.map +1 -0
- package/lib/bridge/index.js +60 -0
- package/lib/bridge/index.js.map +1 -0
- package/lib/bridge/preload.d.ts +8 -0
- package/lib/bridge/preload.d.ts.map +1 -0
- package/lib/bridge/preload.js +32 -0
- package/lib/bridge/preload.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts +4 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.js +19 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- package/lib/bridge/serialization.d.ts +9 -0
- package/lib/bridge/serialization.d.ts.map +1 -0
- package/lib/bridge/serialization.js +238 -0
- package/lib/bridge/serialization.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +5 -0
- package/lib/bridge/signOperation.d.ts.map +1 -0
- package/lib/bridge/signOperation.js +92 -0
- package/lib/bridge/signOperation.js.map +1 -0
- package/lib/bridge/synchronization.d.ts +5 -0
- package/lib/bridge/synchronization.d.ts.map +1 -0
- package/lib/bridge/synchronization.integ.test.d.ts +3 -0
- package/lib/bridge/synchronization.integ.test.d.ts.map +1 -0
- package/lib/bridge/synchronization.integ.test.js +96 -0
- package/lib/bridge/synchronization.integ.test.js.map +1 -0
- package/lib/bridge/synchronization.js +216 -0
- package/lib/bridge/synchronization.js.map +1 -0
- package/lib/bridge/transaction.d.ts +15 -0
- package/lib/bridge/transaction.d.ts.map +1 -0
- package/lib/bridge/transaction.js +61 -0
- package/lib/bridge/transaction.js.map +1 -0
- package/lib/config.d.ts +10 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +17 -0
- package/lib/config.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +21 -0
- package/lib/index.js.map +1 -0
- package/lib/logic/constants.d.ts +4 -0
- package/lib/logic/constants.d.ts.map +1 -0
- package/lib/logic/constants.js +7 -0
- package/lib/logic/constants.js.map +1 -0
- package/lib/logic/pagination.d.ts +3 -0
- package/lib/logic/pagination.d.ts.map +1 -0
- package/lib/logic/pagination.js +19 -0
- package/lib/logic/pagination.js.map +1 -0
- package/lib/logic/utils.d.ts +12 -0
- package/lib/logic/utils.d.ts.map +1 -0
- package/lib/logic/utils.js +177 -0
- package/lib/logic/utils.js.map +1 -0
- package/lib/network/format.d.ts +9 -0
- package/lib/network/format.d.ts.map +1 -0
- package/lib/network/format.js +127 -0
- package/lib/network/format.js.map +1 -0
- package/lib/network/index.d.ts +30 -0
- package/lib/network/index.d.ts.map +1 -0
- package/lib/network/index.integ.test.d.ts +2 -0
- package/lib/network/index.integ.test.d.ts.map +1 -0
- package/lib/network/index.integ.test.js +38 -0
- package/lib/network/index.integ.test.js.map +1 -0
- package/lib/network/index.js +555 -0
- package/lib/network/index.js.map +1 -0
- package/lib/network/index.test.d.ts +2 -0
- package/lib/network/index.test.d.ts.map +1 -0
- package/lib/network/index.test.js +66 -0
- package/lib/network/index.test.js.map +1 -0
- package/lib/network/superRepresentativesData.mock.d.ts +69 -0
- package/lib/network/superRepresentativesData.mock.d.ts.map +1 -0
- package/lib/network/superRepresentativesData.mock.js +2208 -0
- package/lib/network/superRepresentativesData.mock.js.map +1 -0
- package/lib/network/types.d.ts +122 -0
- package/lib/network/types.d.ts.map +1 -0
- package/lib/network/types.fixture.d.ts +498 -0
- package/lib/network/types.fixture.d.ts.map +1 -0
- package/lib/network/types.fixture.js +4375 -0
- package/lib/network/types.fixture.js.map +1 -0
- package/lib/network/types.js +13 -0
- package/lib/network/types.js.map +1 -0
- package/lib/signer/getAddress.d.ts +6 -0
- package/lib/signer/getAddress.d.ts.map +1 -0
- package/lib/signer/getAddress.js +19 -0
- package/lib/signer/getAddress.js.map +1 -0
- package/lib/signer/index.d.ts +6 -0
- package/lib/signer/index.d.ts.map +1 -0
- package/lib/signer/index.js +11 -0
- package/lib/signer/index.js.map +1 -0
- package/lib/test/bot-deviceActions.d.ts +4 -0
- package/lib/test/bot-deviceActions.d.ts.map +1 -0
- package/lib/test/bot-deviceActions.js +103 -0
- package/lib/test/bot-deviceActions.js.map +1 -0
- package/lib/test/bot-specs.d.ts +7 -0
- package/lib/test/bot-specs.d.ts.map +1 -0
- package/lib/test/bot-specs.js +433 -0
- package/lib/test/bot-specs.js.map +1 -0
- package/lib/test/bridgeDatasetTest.d.ts +4 -0
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib/test/bridgeDatasetTest.js +1284 -0
- package/lib/test/bridgeDatasetTest.js.map +1 -0
- package/lib/test/cli.d.ts +52 -0
- package/lib/test/cli.d.ts.map +1 -0
- package/lib/test/cli.js +155 -0
- package/lib/test/cli.js.map +1 -0
- package/lib/test/index.d.ts +6 -0
- package/lib/test/index.d.ts.map +1 -0
- package/lib/test/index.js +26 -0
- package/lib/test/index.js.map +1 -0
- package/lib/types/bridge.d.ts +245 -0
- package/lib/types/bridge.d.ts.map +1 -0
- package/lib/types/bridge.js +16 -0
- package/lib/types/bridge.js.map +1 -0
- package/lib/types/errors.d.ts +49 -0
- package/lib/types/errors.d.ts.map +1 -0
- package/lib/types/errors.js +21 -0
- package/lib/types/errors.js.map +1 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +21 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/signer.d.ts +10 -0
- package/lib/types/signer.d.ts.map +1 -0
- package/lib/types/signer.js +3 -0
- package/lib/types/signer.js.map +1 -0
- package/lib-es/bridge/broadcast.d.ts +7 -0
- package/lib-es/bridge/broadcast.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.js +24 -0
- package/lib-es/bridge/broadcast.js.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts +5 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.js +94 -0
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib-es/bridge/createTransaction.d.ts +4 -0
- package/lib-es/bridge/createTransaction.d.ts.map +1 -0
- package/lib-es/bridge/createTransaction.js +14 -0
- package/lib-es/bridge/createTransaction.js.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts +20 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.js +63 -0
- package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts +5 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.js +25 -0
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib-es/bridge/getEstimateFees.d.ts +6 -0
- package/lib-es/bridge/getEstimateFees.d.ts.map +1 -0
- package/lib-es/bridge/getEstimateFees.js +47 -0
- package/lib-es/bridge/getEstimateFees.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/bridge/getTransactionStatus.js +213 -0
- package/lib-es/bridge/getTransactionStatus.js.map +1 -0
- package/lib-es/bridge/index.d.ts +10 -0
- package/lib-es/bridge/index.d.ts.map +1 -0
- package/lib-es/bridge/index.js +53 -0
- package/lib-es/bridge/index.js.map +1 -0
- package/lib-es/bridge/preload.d.ts +8 -0
- package/lib-es/bridge/preload.d.ts.map +1 -0
- package/lib-es/bridge/preload.js +27 -0
- package/lib-es/bridge/preload.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts +4 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.js +15 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- package/lib-es/bridge/serialization.d.ts +9 -0
- package/lib-es/bridge/serialization.d.ts.map +1 -0
- package/lib-es/bridge/serialization.js +229 -0
- package/lib-es/bridge/serialization.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +5 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.js +85 -0
- package/lib-es/bridge/signOperation.js.map +1 -0
- package/lib-es/bridge/synchronization.d.ts +5 -0
- package/lib-es/bridge/synchronization.d.ts.map +1 -0
- package/lib-es/bridge/synchronization.integ.test.d.ts +3 -0
- package/lib-es/bridge/synchronization.integ.test.d.ts.map +1 -0
- package/lib-es/bridge/synchronization.integ.test.js +89 -0
- package/lib-es/bridge/synchronization.integ.test.js.map +1 -0
- package/lib-es/bridge/synchronization.js +209 -0
- package/lib-es/bridge/synchronization.js.map +1 -0
- package/lib-es/bridge/transaction.d.ts +15 -0
- package/lib-es/bridge/transaction.d.ts.map +1 -0
- package/lib-es/bridge/transaction.js +55 -0
- package/lib-es/bridge/transaction.js.map +1 -0
- package/lib-es/config.d.ts +10 -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/index.d.ts +3 -0
- package/lib-es/index.d.ts.map +1 -0
- package/lib-es/index.js +3 -0
- package/lib-es/index.js.map +1 -0
- package/lib-es/logic/constants.d.ts +4 -0
- package/lib-es/logic/constants.d.ts.map +1 -0
- package/lib-es/logic/constants.js +4 -0
- package/lib-es/logic/constants.js.map +1 -0
- package/lib-es/logic/pagination.d.ts +3 -0
- package/lib-es/logic/pagination.d.ts.map +1 -0
- package/lib-es/logic/pagination.js +15 -0
- package/lib-es/logic/pagination.js.map +1 -0
- package/lib-es/logic/utils.d.ts +12 -0
- package/lib-es/logic/utils.d.ts.map +1 -0
- package/lib-es/logic/utils.js +167 -0
- package/lib-es/logic/utils.js.map +1 -0
- package/lib-es/network/format.d.ts +9 -0
- package/lib-es/network/format.d.ts.map +1 -0
- package/lib-es/network/format.js +117 -0
- package/lib-es/network/format.js.map +1 -0
- package/lib-es/network/index.d.ts +30 -0
- package/lib-es/network/index.d.ts.map +1 -0
- package/lib-es/network/index.integ.test.d.ts +2 -0
- package/lib-es/network/index.integ.test.d.ts.map +1 -0
- package/lib-es/network/index.integ.test.js +36 -0
- package/lib-es/network/index.integ.test.js.map +1 -0
- package/lib-es/network/index.js +524 -0
- package/lib-es/network/index.js.map +1 -0
- package/lib-es/network/index.test.d.ts +2 -0
- package/lib-es/network/index.test.d.ts.map +1 -0
- package/lib-es/network/index.test.js +63 -0
- package/lib-es/network/index.test.js.map +1 -0
- package/lib-es/network/superRepresentativesData.mock.d.ts +69 -0
- package/lib-es/network/superRepresentativesData.mock.d.ts.map +1 -0
- package/lib-es/network/superRepresentativesData.mock.js +2206 -0
- package/lib-es/network/superRepresentativesData.mock.js.map +1 -0
- package/lib-es/network/types.d.ts +122 -0
- package/lib-es/network/types.d.ts.map +1 -0
- package/lib-es/network/types.fixture.d.ts +498 -0
- package/lib-es/network/types.fixture.d.ts.map +1 -0
- package/lib-es/network/types.fixture.js +4371 -0
- package/lib-es/network/types.fixture.js.map +1 -0
- package/lib-es/network/types.js +8 -0
- package/lib-es/network/types.js.map +1 -0
- package/lib-es/signer/getAddress.d.ts +6 -0
- package/lib-es/signer/getAddress.d.ts.map +1 -0
- package/lib-es/signer/getAddress.js +17 -0
- package/lib-es/signer/getAddress.js.map +1 -0
- package/lib-es/signer/index.d.ts +6 -0
- package/lib-es/signer/index.d.ts.map +1 -0
- package/lib-es/signer/index.js +6 -0
- package/lib-es/signer/index.js.map +1 -0
- package/lib-es/test/bot-deviceActions.d.ts +4 -0
- package/lib-es/test/bot-deviceActions.d.ts.map +1 -0
- package/lib-es/test/bot-deviceActions.js +100 -0
- package/lib-es/test/bot-deviceActions.js.map +1 -0
- package/lib-es/test/bot-specs.d.ts +7 -0
- package/lib-es/test/bot-specs.d.ts.map +1 -0
- package/lib-es/test/bot-specs.js +428 -0
- package/lib-es/test/bot-specs.js.map +1 -0
- package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib-es/test/bridgeDatasetTest.js +1278 -0
- package/lib-es/test/bridgeDatasetTest.js.map +1 -0
- package/lib-es/test/cli.d.ts +52 -0
- package/lib-es/test/cli.d.ts.map +1 -0
- package/lib-es/test/cli.js +149 -0
- package/lib-es/test/cli.js.map +1 -0
- package/lib-es/test/index.d.ts +6 -0
- package/lib-es/test/index.d.ts.map +1 -0
- package/lib-es/test/index.js +6 -0
- package/lib-es/test/index.js.map +1 -0
- package/lib-es/types/bridge.d.ts +245 -0
- package/lib-es/types/bridge.d.ts.map +1 -0
- package/lib-es/types/bridge.js +11 -0
- package/lib-es/types/bridge.js.map +1 -0
- package/lib-es/types/errors.d.ts +49 -0
- package/lib-es/types/errors.d.ts.map +1 -0
- package/lib-es/types/errors.js +18 -0
- package/lib-es/types/errors.js.map +1 -0
- package/lib-es/types/index.d.ts +4 -0
- package/lib-es/types/index.d.ts.map +1 -0
- package/lib-es/types/index.js +5 -0
- package/lib-es/types/index.js.map +1 -0
- package/lib-es/types/signer.d.ts +10 -0
- package/lib-es/types/signer.d.ts.map +1 -0
- package/lib-es/types/signer.js +2 -0
- package/lib-es/types/signer.js.map +1 -0
- package/package.json +133 -0
- package/src/bridge/broadcast.ts +24 -0
- package/src/bridge/buildOptimisticOperation.ts +133 -0
- package/src/bridge/createTransaction.ts +16 -0
- package/src/bridge/deviceTransactionConfig.ts +99 -0
- package/src/bridge/estimateMaxSpendable.ts +32 -0
- package/src/bridge/getEstimateFees.ts +52 -0
- package/src/bridge/getTransactionStatus.ts +263 -0
- package/src/bridge/index.ts +78 -0
- package/src/bridge/preload.ts +24 -0
- package/src/bridge/prepareTransaction.ts +12 -0
- package/src/bridge/serialization.ts +288 -0
- package/src/bridge/signOperation.ts +123 -0
- package/src/bridge/synchronization.integ.test.ts +105 -0
- package/src/bridge/synchronization.ts +284 -0
- package/src/bridge/transaction.ts +84 -0
- package/src/config.ts +24 -0
- package/src/index.ts +3 -0
- package/src/logic/constants.ts +4 -0
- package/src/logic/pagination.ts +21 -0
- package/src/logic/utils.ts +231 -0
- package/src/network/format.ts +148 -0
- package/src/network/index.integ.test.ts +33 -0
- package/src/network/index.test.ts +61 -0
- package/src/network/index.ts +747 -0
- package/src/network/superRepresentativesData.mock.ts +2205 -0
- package/src/network/types.fixture.ts +4476 -0
- package/src/network/types.ts +147 -0
- package/src/signer/getAddress.ts +13 -0
- package/src/signer/index.ts +7 -0
- package/src/test/bot-deviceActions.ts +121 -0
- package/src/test/bot-specs.ts +457 -0
- package/src/test/bridgeDatasetTest.ts +1343 -0
- package/src/test/cli.ts +219 -0
- package/src/test/index.ts +6 -0
- package/src/types/bridge.ts +304 -0
- package/src/types/errors.ts +22 -0
- package/src/types/index.ts +4 -0
- package/src/types/signer.ts +9 -0
- package/tsconfig.json +14 -0
- package/types/tronweb/index.d.ts +5 -0
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import invariant from "invariant";
|
|
3
|
+
import expect from "expect";
|
|
4
|
+
import type { Transaction } from "../types";
|
|
5
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/index";
|
|
6
|
+
import { parseCurrencyUnit } from "@ledgerhq/coin-framework/currencies";
|
|
7
|
+
import { botTest, pickSiblings } from "@ledgerhq/coin-framework/bot/specs";
|
|
8
|
+
import type { AppSpec, TransactionDestinationTestInput } from "@ledgerhq/coin-framework/bot/types";
|
|
9
|
+
// import { getUnfreezeData, getNextRewardDate } from "./react";
|
|
10
|
+
import { DeviceModelId } from "@ledgerhq/devices";
|
|
11
|
+
import { acceptTransaction } from "./bot-deviceActions";
|
|
12
|
+
const currency = getCryptoCurrencyById("tron");
|
|
13
|
+
const minimalAmount = parseCurrencyUnit(currency.units[0], "1");
|
|
14
|
+
const maxAccount = 10;
|
|
15
|
+
|
|
16
|
+
/*const getDecimalPart = (value: BigNumber, magnitude: number) =>
|
|
17
|
+
value.minus(value.modulo(10 ** magnitude));*/
|
|
18
|
+
|
|
19
|
+
// FIXME TRON have a bug where the amounts from the API have imprecisions
|
|
20
|
+
const expectedApproximate = (value: BigNumber, expected: BigNumber, delta = 50) => {
|
|
21
|
+
if (value.minus(expected).abs().gt(delta)) {
|
|
22
|
+
expect(value.toString()).toEqual(value.toString());
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const testDestination = <T>({
|
|
27
|
+
destination,
|
|
28
|
+
operation,
|
|
29
|
+
destinationBeforeTransaction,
|
|
30
|
+
sendingOperation,
|
|
31
|
+
}: TransactionDestinationTestInput<T>): void => {
|
|
32
|
+
const amount = sendingOperation.value.minus(sendingOperation.fee);
|
|
33
|
+
botTest("account balance increased with transaction amount", () =>
|
|
34
|
+
expectedApproximate(destination.balance, destinationBeforeTransaction.balance.plus(amount)),
|
|
35
|
+
);
|
|
36
|
+
botTest("operation amount is consistent with sendingOperation", () =>
|
|
37
|
+
expectedApproximate(operation.value, amount),
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const tron: AppSpec<Transaction> = {
|
|
42
|
+
name: "Tron",
|
|
43
|
+
currency,
|
|
44
|
+
appQuery: {
|
|
45
|
+
model: DeviceModelId.nanoSP,
|
|
46
|
+
appName: "Tron",
|
|
47
|
+
firmware: "1.1.1",
|
|
48
|
+
appVersion: "0.5.0",
|
|
49
|
+
},
|
|
50
|
+
genericDeviceAction: acceptTransaction,
|
|
51
|
+
testTimeout: 2 * 60 * 1000,
|
|
52
|
+
minViableAmount: minimalAmount,
|
|
53
|
+
mutations: [
|
|
54
|
+
{
|
|
55
|
+
name: "move 50% to another account",
|
|
56
|
+
maxRun: 2,
|
|
57
|
+
testDestination,
|
|
58
|
+
transaction: ({ account, siblings, bridge, maxSpendable }) => {
|
|
59
|
+
invariant(maxSpendable.gt(minimalAmount), "balance is too low");
|
|
60
|
+
const sibling = pickSiblings(siblings, maxAccount);
|
|
61
|
+
const recipient = sibling.freshAddress;
|
|
62
|
+
const amount = maxSpendable.div(2).integerValue();
|
|
63
|
+
return {
|
|
64
|
+
transaction: bridge.createTransaction(account),
|
|
65
|
+
updates: [
|
|
66
|
+
{
|
|
67
|
+
recipient,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
amount,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
test: ({ accountBeforeTransaction, operation, account }) => {
|
|
76
|
+
botTest("account spendable balance decreased with operation", () =>
|
|
77
|
+
expectedApproximate(
|
|
78
|
+
account.spendableBalance,
|
|
79
|
+
accountBeforeTransaction.spendableBalance.minus(operation.value),
|
|
80
|
+
),
|
|
81
|
+
);
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: "send max to another account",
|
|
86
|
+
maxRun: 1,
|
|
87
|
+
testDestination,
|
|
88
|
+
transaction: ({ account, siblings, bridge, maxSpendable }) => {
|
|
89
|
+
invariant(maxSpendable.gt(minimalAmount), "balance is too low");
|
|
90
|
+
const sibling = pickSiblings(siblings, maxAccount);
|
|
91
|
+
const recipient = sibling.freshAddress;
|
|
92
|
+
return {
|
|
93
|
+
transaction: bridge.createTransaction(account),
|
|
94
|
+
updates: [
|
|
95
|
+
{
|
|
96
|
+
recipient,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
useAllAmount: true,
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
test: ({ account }) => {
|
|
105
|
+
botTest("account spendable balance is zero", () =>
|
|
106
|
+
expectedApproximate(account.spendableBalance, new BigNumber(0)),
|
|
107
|
+
);
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
/*
|
|
111
|
+
We do not manage staking anymore
|
|
112
|
+
{
|
|
113
|
+
name: "freeze 25% to bandwidth | energy",
|
|
114
|
+
maxRun: 1,
|
|
115
|
+
transaction: ({ siblings, account, bridge, maxSpendable }) => {
|
|
116
|
+
expectSiblingsHaveSpendablePartGreaterThan(siblings, 0.5);
|
|
117
|
+
|
|
118
|
+
invariant(maxSpendable.gt(minimalAmount), "balance is too low");
|
|
119
|
+
let amount = getDecimalPart(
|
|
120
|
+
maxSpendable.div(4),
|
|
121
|
+
currency.units[0].magnitude,
|
|
122
|
+
).integerValue();
|
|
123
|
+
|
|
124
|
+
if (amount.lt(minimalAmount)) {
|
|
125
|
+
amount = minimalAmount;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const energy = get(account, `tronResources.energy`, new BigNumber(0));
|
|
129
|
+
return {
|
|
130
|
+
transaction: bridge.createTransaction(account),
|
|
131
|
+
updates: [
|
|
132
|
+
{
|
|
133
|
+
mode: "freeze",
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
resource: energy.eq(0) ? "ENERGY" : "BANDWIDTH",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
amount,
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
};
|
|
143
|
+
},
|
|
144
|
+
test: ({ account, accountBeforeTransaction, transaction }) => {
|
|
145
|
+
const resourceType = (transaction.resource || "").toLocaleLowerCase();
|
|
146
|
+
const resourceBeforeTransaction = get(
|
|
147
|
+
accountBeforeTransaction,
|
|
148
|
+
`tronResources.frozen.${resourceType}.amount`,
|
|
149
|
+
new BigNumber(0),
|
|
150
|
+
);
|
|
151
|
+
const expectedAmount = new BigNumber(transaction.amount).plus(resourceBeforeTransaction);
|
|
152
|
+
const currentRessourceAmount = get(
|
|
153
|
+
account,
|
|
154
|
+
`tronResources.frozen.${resourceType}.amount`,
|
|
155
|
+
new BigNumber(0),
|
|
156
|
+
);
|
|
157
|
+
botTest("frozen amount is accumulated in resources", () =>
|
|
158
|
+
expect(expectedAmount.toString()).toBe(currentRessourceAmount.toString()),
|
|
159
|
+
);
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: "unfreeze bandwith / energy",
|
|
164
|
+
maxRun: 1,
|
|
165
|
+
transaction: ({ account, bridge }) => {
|
|
166
|
+
const TP = new BigNumber(get(account, "tronResources.tronPower", "0"));
|
|
167
|
+
invariant(TP.gt(0), "no frozen assets");
|
|
168
|
+
const { canUnfreezeBandwidth, canUnfreezeEnergy } = getUnfreezeData(account as TronAccount);
|
|
169
|
+
invariant(canUnfreezeBandwidth || canUnfreezeEnergy, "freeze period not expired yet");
|
|
170
|
+
const resourceToUnfreeze = canUnfreezeBandwidth ? "BANDWIDTH" : "ENERGY";
|
|
171
|
+
return {
|
|
172
|
+
transaction: bridge.createTransaction(account),
|
|
173
|
+
updates: [
|
|
174
|
+
{
|
|
175
|
+
mode: "unfreeze",
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
resource: resourceToUnfreeze,
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
};
|
|
182
|
+
},
|
|
183
|
+
test: ({ account, accountBeforeTransaction, transaction }) => {
|
|
184
|
+
const TxResource = (transaction.resource || "").toLocaleLowerCase();
|
|
185
|
+
const currentFrozen = get(account, `tronResources.frozen.${TxResource}`, undefined);
|
|
186
|
+
botTest("no current frozen", () => expect(currentFrozen).toBeUndefined());
|
|
187
|
+
const TPBeforeTx = new BigNumber(
|
|
188
|
+
get(accountBeforeTransaction, "tronResources.tronPower", 0),
|
|
189
|
+
);
|
|
190
|
+
const currentTP = new BigNumber(get(account, "tronResources.tronPower", 0));
|
|
191
|
+
const expectedTronPower = TPBeforeTx.minus(transaction.amount);
|
|
192
|
+
botTest("tron power", () => expectedApproximate(currentTP, expectedTronPower));
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
name: "submit vote",
|
|
197
|
+
maxRun: 1,
|
|
198
|
+
transaction: ({ account, bridge, preloadedData }) => {
|
|
199
|
+
const TP = new BigNumber(get(account, "tronResources.tronPower", "0"));
|
|
200
|
+
invariant(TP.gt(0), "no tron power to vote");
|
|
201
|
+
const currentTPVoted = get(account, "tronResources.votes", []).reduce(
|
|
202
|
+
(acc, curr) => acc.plus(new BigNumber(get(curr, "voteCount", 0))),
|
|
203
|
+
new BigNumber(0),
|
|
204
|
+
);
|
|
205
|
+
invariant(TP.gt(currentTPVoted), "you have no tron power left");
|
|
206
|
+
const { superRepresentatives } = preloadedData;
|
|
207
|
+
invariant(
|
|
208
|
+
superRepresentatives && superRepresentatives.length,
|
|
209
|
+
"there are no super representatives to vote for, or the list has not been loaded yet",
|
|
210
|
+
);
|
|
211
|
+
const count = 1 + Math.floor(5 * Math.random());
|
|
212
|
+
const candidates = sampleSize(superRepresentatives.slice(0, 40), count);
|
|
213
|
+
let remaining = TP;
|
|
214
|
+
const votes = candidates
|
|
215
|
+
.map(c => {
|
|
216
|
+
if (!remaining.gt(0)) return null;
|
|
217
|
+
const voteCount = remaining.eq(1)
|
|
218
|
+
? remaining.integerValue().toNumber()
|
|
219
|
+
: remaining.times(Math.random()).integerValue().toNumber();
|
|
220
|
+
if (voteCount === 0) return null;
|
|
221
|
+
remaining = remaining.minus(voteCount);
|
|
222
|
+
return {
|
|
223
|
+
address: c.address,
|
|
224
|
+
voteCount,
|
|
225
|
+
};
|
|
226
|
+
})
|
|
227
|
+
.filter(Boolean);
|
|
228
|
+
return {
|
|
229
|
+
transaction: bridge.createTransaction(account) as Transaction,
|
|
230
|
+
updates: [
|
|
231
|
+
{
|
|
232
|
+
mode: "vote",
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
votes,
|
|
236
|
+
},
|
|
237
|
+
] as Array<Partial<Transaction>>,
|
|
238
|
+
};
|
|
239
|
+
},
|
|
240
|
+
test: ({ account, transaction }) => {
|
|
241
|
+
const votes = sortBy(transaction.votes, ["address"]);
|
|
242
|
+
const currentVotes = sortBy(get(account, "tronResources.votes", []), ["address"]);
|
|
243
|
+
botTest("current votes", () => expect(currentVotes).toEqual(votes));
|
|
244
|
+
},
|
|
245
|
+
},*/
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* FIXME
|
|
249
|
+
*
|
|
250
|
+
* Our bad implementation of TRC10/TRC20 operations and sync make those tests impossible to
|
|
251
|
+
* work properly.
|
|
252
|
+
*
|
|
253
|
+
* To make them work we need to rework the link between Operation and SubOperations which is wrong as of now and
|
|
254
|
+
* rework our fee estimation (TRC20 do have fees which are ignored today until the next sync creates an OUT tx to represent it).
|
|
255
|
+
*/
|
|
256
|
+
|
|
257
|
+
// {
|
|
258
|
+
// name: "move some TRC10",
|
|
259
|
+
// maxRun: 1,
|
|
260
|
+
// transaction: ({ account, siblings, bridge }) => {
|
|
261
|
+
// const trc10Account = sample(
|
|
262
|
+
// (account.subAccounts || []).filter(
|
|
263
|
+
// (a) => a.type === "TokenAccount" && a.token.tokenType === "trc10"
|
|
264
|
+
// )
|
|
265
|
+
// );
|
|
266
|
+
// invariant(trc10Account, "no trc10 account");
|
|
267
|
+
// if (!trc10Account) throw new Error("no trc10 account");
|
|
268
|
+
// invariant(trc10Account?.balance.gt(0), "trc10 account has no balance");
|
|
269
|
+
// const sibling = pickSiblings(siblings, maxAccount);
|
|
270
|
+
// const recipient = sibling.freshAddress;
|
|
271
|
+
// return {
|
|
272
|
+
// transaction: bridge.createTransaction(account),
|
|
273
|
+
// updates: [
|
|
274
|
+
// {
|
|
275
|
+
// recipient,
|
|
276
|
+
// subAccountId: trc10Account.id,
|
|
277
|
+
// },
|
|
278
|
+
// Math.random() < 0.5
|
|
279
|
+
// ? {
|
|
280
|
+
// useAllAmount: true,
|
|
281
|
+
// }
|
|
282
|
+
// : {
|
|
283
|
+
// amount: trc10Account.balance
|
|
284
|
+
// .times(Math.random())
|
|
285
|
+
// .integerValue(),
|
|
286
|
+
// },
|
|
287
|
+
// ],
|
|
288
|
+
// };
|
|
289
|
+
// },
|
|
290
|
+
// test: ({ accountBeforeTransaction, account, transaction }) => {
|
|
291
|
+
// invariant(accountBeforeTransaction.subAccounts, "sub accounts before");
|
|
292
|
+
// const trc10accountBefore = (
|
|
293
|
+
// accountBeforeTransaction.subAccounts as SubAccount[]
|
|
294
|
+
// ).find((s) => s.id === transaction.subAccountId);
|
|
295
|
+
// invariant(trc10accountBefore, "trc10 acc was here before");
|
|
296
|
+
// if (!trc10accountBefore) throw new Error("no trc10before account");
|
|
297
|
+
|
|
298
|
+
// invariant(account.subAccounts, "sub accounts");
|
|
299
|
+
// const trc10account = (account.subAccounts as SubAccount[]).find(
|
|
300
|
+
// (s) => s.id === transaction.subAccountId
|
|
301
|
+
// );
|
|
302
|
+
// invariant(trc10account, "trc10 acc is still here");
|
|
303
|
+
// if (!trc10account) throw new Error("no trc10 account");
|
|
304
|
+
|
|
305
|
+
// if (transaction.useAllAmount) {
|
|
306
|
+
// botTest("trc10 balance became zero", () =>
|
|
307
|
+
// expect(trc10account.balance.toString()).toBe("0")
|
|
308
|
+
// );
|
|
309
|
+
// } else {
|
|
310
|
+
// botTest("trc10 balance decreased with operation", () =>
|
|
311
|
+
// expect(trc10account.balance.toString()).toBe(
|
|
312
|
+
// trc10accountBefore.balance.minus(transaction.amount).toString()
|
|
313
|
+
// )
|
|
314
|
+
// );
|
|
315
|
+
// }
|
|
316
|
+
// },
|
|
317
|
+
// },
|
|
318
|
+
|
|
319
|
+
// {
|
|
320
|
+
// name: "move some TRC20",
|
|
321
|
+
// maxRun: 1,
|
|
322
|
+
// transaction: ({ account, siblings, bridge }) => {
|
|
323
|
+
// const balance = account.spendableBalance;
|
|
324
|
+
// const energy = get(account, "tronResources.energy", new BigNumber(0));
|
|
325
|
+
// invariant(
|
|
326
|
+
// energy.gt(0) || balance.gt(minimalAmount),
|
|
327
|
+
// "trx and energy too low"
|
|
328
|
+
// );
|
|
329
|
+
// const trc20Account = sample(
|
|
330
|
+
// (account.subAccounts || []).filter(
|
|
331
|
+
// (a) => a.type === "TokenAccount" && a.token.tokenType === "trc20"
|
|
332
|
+
// )
|
|
333
|
+
// );
|
|
334
|
+
// invariant(trc20Account, "no trc20 account");
|
|
335
|
+
// invariant(trc20Account?.balance.gt(0), "trc20 account has no balance");
|
|
336
|
+
// if (!trc20Account) throw new Error("no trc20 account");
|
|
337
|
+
|
|
338
|
+
// const sibling = pickSiblings(siblings, maxAccount);
|
|
339
|
+
// invariant(
|
|
340
|
+
// sibling.balance.gt(0),
|
|
341
|
+
// "recipient cannot receive trc20 because it has no balance"
|
|
342
|
+
// );
|
|
343
|
+
// const recipient = sibling.freshAddress;
|
|
344
|
+
// return {
|
|
345
|
+
// transaction: bridge.createTransaction(account),
|
|
346
|
+
// updates: [
|
|
347
|
+
// {
|
|
348
|
+
// recipient,
|
|
349
|
+
// subAccountId: trc20Account.id,
|
|
350
|
+
// },
|
|
351
|
+
// Math.random() < 0.5
|
|
352
|
+
// ? {
|
|
353
|
+
// useAllAmount: true,
|
|
354
|
+
// }
|
|
355
|
+
// : {
|
|
356
|
+
// amount: trc20Account.balance
|
|
357
|
+
// .times(Math.random())
|
|
358
|
+
// .integerValue(),
|
|
359
|
+
// },
|
|
360
|
+
// ],
|
|
361
|
+
// };
|
|
362
|
+
// },
|
|
363
|
+
// test: ({ accountBeforeTransaction, account, transaction }) => {
|
|
364
|
+
// invariant(accountBeforeTransaction.subAccounts, "sub accounts before");
|
|
365
|
+
// const trc20accountBefore = (
|
|
366
|
+
// accountBeforeTransaction.subAccounts as SubAccount[]
|
|
367
|
+
// ).find((s) => s.id === transaction.subAccountId);
|
|
368
|
+
// invariant(trc20accountBefore, "trc20 acc was here before");
|
|
369
|
+
// if (!trc20accountBefore) throw new Error("no trc20 before account");
|
|
370
|
+
// invariant(account.subAccounts, "sub accounts");
|
|
371
|
+
// const trc20account = (account.subAccounts as SubAccount[]).find(
|
|
372
|
+
// (s) => s.id === transaction.subAccountId
|
|
373
|
+
// );
|
|
374
|
+
// invariant(trc20account, "trc20 acc is still here");
|
|
375
|
+
// if (!trc20account) throw new Error("no trc20 account");
|
|
376
|
+
|
|
377
|
+
// if (transaction.useAllAmount) {
|
|
378
|
+
// botTest("trc10 balance became zero", () =>
|
|
379
|
+
// expect(trc20account.balance.toString()).toBe("0")
|
|
380
|
+
// );
|
|
381
|
+
// } else {
|
|
382
|
+
// botTest("trc10 balance decreased with operation", () =>
|
|
383
|
+
// expect(trc20account.balance.toString()).toBe(
|
|
384
|
+
// trc20accountBefore.balance.minus(transaction.amount).toString()
|
|
385
|
+
// )
|
|
386
|
+
// );
|
|
387
|
+
// }
|
|
388
|
+
|
|
389
|
+
// if (
|
|
390
|
+
// get(trc20accountBefore, "tronResources.energy", new BigNumber(0)).eq(
|
|
391
|
+
// 0
|
|
392
|
+
// )
|
|
393
|
+
// ) {
|
|
394
|
+
// botTest("account balance decreased", () =>
|
|
395
|
+
// expect(account.balance.lt(accountBeforeTransaction.balance)).toBe(
|
|
396
|
+
// true
|
|
397
|
+
// )
|
|
398
|
+
// );
|
|
399
|
+
// } else {
|
|
400
|
+
// botTest("energy decreased", () =>
|
|
401
|
+
// expect(
|
|
402
|
+
// get(account, "tronResources.energy", new BigNumber(0)).lt(
|
|
403
|
+
// get(
|
|
404
|
+
// accountBeforeTransaction,
|
|
405
|
+
// "tronResources.energy",
|
|
406
|
+
// new BigNumber(0)
|
|
407
|
+
// )
|
|
408
|
+
// )
|
|
409
|
+
// ).toBe(true)
|
|
410
|
+
// );
|
|
411
|
+
// botTest("balance didn't change", () =>
|
|
412
|
+
// expect(account.balance.eq(accountBeforeTransaction.balance)).toBe(
|
|
413
|
+
// true
|
|
414
|
+
// )
|
|
415
|
+
// );
|
|
416
|
+
// }
|
|
417
|
+
// },
|
|
418
|
+
// },
|
|
419
|
+
/*
|
|
420
|
+
We do not manage staking anymore
|
|
421
|
+
{
|
|
422
|
+
name: "claim rewards",
|
|
423
|
+
maxRun: 1,
|
|
424
|
+
transaction: ({ account, bridge }) => {
|
|
425
|
+
const nextRewardDate = getNextRewardDate(account as TronAccount);
|
|
426
|
+
const today = Date.now();
|
|
427
|
+
const unwithdrawnReward = new BigNumber(
|
|
428
|
+
get(account, "tronResources.unwithdrawnReward", "0"),
|
|
429
|
+
);
|
|
430
|
+
invariant(unwithdrawnReward.gt(0), "no rewards to claim");
|
|
431
|
+
invariant(
|
|
432
|
+
nextRewardDate && nextRewardDate <= today,
|
|
433
|
+
"you can't claim twice in less than 24 hours",
|
|
434
|
+
);
|
|
435
|
+
return {
|
|
436
|
+
transaction: bridge.createTransaction(account),
|
|
437
|
+
updates: [
|
|
438
|
+
{
|
|
439
|
+
mode: "claimReward",
|
|
440
|
+
},
|
|
441
|
+
],
|
|
442
|
+
};
|
|
443
|
+
},
|
|
444
|
+
test: ({ account }) => {
|
|
445
|
+
const rewards = new BigNumber(get(account, "tronResources.unwithdrawnReward", "0"));
|
|
446
|
+
const nextRewardDate = getNextRewardDate(account as TronAccount);
|
|
447
|
+
botTest("rewards is zero", () => expect(rewards.eq(0)).toBe(true));
|
|
448
|
+
botTest("next reward date settled", () =>
|
|
449
|
+
expect(nextRewardDate && nextRewardDate > Date.now()).toBe(true),
|
|
450
|
+
);
|
|
451
|
+
},
|
|
452
|
+
},*/
|
|
453
|
+
],
|
|
454
|
+
};
|
|
455
|
+
export default {
|
|
456
|
+
tron,
|
|
457
|
+
};
|