@ledgerhq/coin-tezos 6.5.0 → 6.6.0-nightly.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/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +4 -30
- package/CHANGELOG.md +20 -0
- package/jest.integ.config.js +1 -0
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +188 -40
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +79 -10
- package/lib/api/index.test.js.map +1 -1
- package/lib/api/types.d.ts +7 -5
- package/lib/api/types.d.ts.map +1 -1
- package/lib/config.d.ts +4 -3
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -3
- package/lib/index.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +7 -0
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/craftTransaction.test.js +1 -0
- package/lib/logic/craftTransaction.test.js.map +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.integ.test.js +8 -2
- package/lib/logic/estimateFees.integ.test.js.map +1 -1
- package/lib/logic/estimateFees.js +119 -45
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/getBalance.js +1 -1
- package/lib/logic/getBalance.js.map +1 -1
- package/lib/logic/getStakes.d.ts +3 -0
- package/lib/logic/getStakes.d.ts.map +1 -0
- package/lib/logic/getStakes.js +26 -0
- package/lib/logic/getStakes.js.map +1 -0
- package/lib/logic/getStakes.test.d.ts +2 -0
- package/lib/logic/getStakes.test.d.ts.map +1 -0
- package/lib/logic/getStakes.test.js +133 -0
- package/lib/logic/getStakes.test.js.map +1 -0
- package/lib/logic/index.d.ts +2 -0
- package/lib/logic/index.d.ts.map +1 -1
- package/lib/logic/index.js +5 -1
- package/lib/logic/index.js.map +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +56 -10
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/listOperations.test.js +14 -10
- package/lib/logic/listOperations.test.js.map +1 -1
- package/lib/logic/validateIntent.d.ts +3 -0
- package/lib/logic/validateIntent.d.ts.map +1 -0
- package/lib/logic/validateIntent.js +179 -0
- package/lib/logic/validateIntent.js.map +1 -0
- package/lib/logic/validateIntent.test.d.ts +2 -0
- package/lib/logic/validateIntent.test.d.ts.map +1 -0
- package/lib/logic/validateIntent.test.js +249 -0
- package/lib/logic/validateIntent.test.js.map +1 -0
- package/{lib-es/bridge → lib}/transaction.d.ts +1 -1
- package/lib/transaction.d.ts.map +1 -0
- package/lib/{bridge/transaction.js → transaction.js} +3 -3
- package/lib/transaction.js.map +1 -0
- package/lib/types/bridge.d.ts +3 -0
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib/types/bridge.fixture.d.ts.map +1 -1
- package/lib/types/bridge.fixture.js +1 -0
- package/lib/types/bridge.fixture.js.map +1 -1
- package/lib/types/bridge.js.map +1 -1
- package/lib/utils.d.ts +48 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +112 -0
- package/lib/utils.js.map +1 -0
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +189 -41
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +79 -10
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/api/types.d.ts +7 -5
- package/lib-es/api/types.d.ts.map +1 -1
- package/lib-es/config.d.ts +4 -3
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js.map +1 -1
- package/lib-es/index.d.ts +1 -1
- package/lib-es/index.d.ts.map +1 -1
- package/lib-es/index.js +1 -1
- package/lib-es/index.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +7 -0
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/craftTransaction.test.js +1 -0
- package/lib-es/logic/craftTransaction.test.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.integ.test.js +8 -2
- package/lib-es/logic/estimateFees.integ.test.js.map +1 -1
- package/lib-es/logic/estimateFees.js +119 -45
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/getBalance.js +1 -1
- package/lib-es/logic/getBalance.js.map +1 -1
- package/lib-es/logic/getStakes.d.ts +3 -0
- package/lib-es/logic/getStakes.d.ts.map +1 -0
- package/lib-es/logic/getStakes.js +20 -0
- package/lib-es/logic/getStakes.js.map +1 -0
- package/lib-es/logic/getStakes.test.d.ts +2 -0
- package/lib-es/logic/getStakes.test.d.ts.map +1 -0
- package/lib-es/logic/getStakes.test.js +128 -0
- package/lib-es/logic/getStakes.test.js.map +1 -0
- package/lib-es/logic/index.d.ts +2 -0
- package/lib-es/logic/index.d.ts.map +1 -1
- package/lib-es/logic/index.js +2 -0
- package/lib-es/logic/index.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +56 -10
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/listOperations.test.js +14 -10
- package/lib-es/logic/listOperations.test.js.map +1 -1
- package/lib-es/logic/validateIntent.d.ts +3 -0
- package/lib-es/logic/validateIntent.d.ts.map +1 -0
- package/lib-es/logic/validateIntent.js +173 -0
- package/lib-es/logic/validateIntent.js.map +1 -0
- package/lib-es/logic/validateIntent.test.d.ts +2 -0
- package/lib-es/logic/validateIntent.test.d.ts.map +1 -0
- package/lib-es/logic/validateIntent.test.js +221 -0
- package/lib-es/logic/validateIntent.test.js.map +1 -0
- package/{lib/bridge → lib-es}/transaction.d.ts +1 -1
- package/lib-es/transaction.d.ts.map +1 -0
- package/lib-es/{bridge/transaction.js → transaction.js} +3 -3
- package/lib-es/transaction.js.map +1 -0
- package/lib-es/types/bridge.d.ts +3 -0
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/lib-es/types/bridge.fixture.d.ts.map +1 -1
- package/lib-es/types/bridge.fixture.js +1 -0
- package/lib-es/types/bridge.fixture.js.map +1 -1
- package/lib-es/types/bridge.js.map +1 -1
- package/lib-es/utils.d.ts +48 -0
- package/lib-es/utils.d.ts.map +1 -0
- package/lib-es/utils.js +105 -0
- package/lib-es/utils.js.map +1 -0
- package/package.json +9 -12
- package/src/api/index.test.ts +87 -15
- package/src/api/index.ts +204 -55
- package/src/api/types.ts +11 -6
- package/src/config.ts +9 -2
- package/src/index.ts +1 -2
- package/src/logic/craftTransaction.test.ts +1 -0
- package/src/logic/craftTransaction.ts +8 -0
- package/src/logic/estimateFees.integ.test.ts +8 -2
- package/src/logic/estimateFees.ts +140 -49
- package/src/logic/getBalance.ts +1 -1
- package/src/logic/getStakes.test.ts +145 -0
- package/src/logic/getStakes.ts +20 -0
- package/src/logic/index.ts +2 -0
- package/src/logic/listOperations.test.ts +64 -54
- package/src/logic/listOperations.ts +57 -9
- package/src/logic/validateIntent.test.ts +262 -0
- package/src/logic/validateIntent.ts +207 -0
- package/src/{bridge/transaction.ts → transaction.ts} +4 -4
- package/src/types/bridge.fixture.ts +1 -0
- package/src/types/bridge.ts +6 -1
- package/src/utils.ts +115 -0
- package/lib/bridge/broadcast.d.ts +0 -4
- package/lib/bridge/broadcast.d.ts.map +0 -1
- package/lib/bridge/broadcast.js +0 -11
- package/lib/bridge/broadcast.js.map +0 -1
- package/lib/bridge/broadcast.test.d.ts +0 -2
- package/lib/bridge/broadcast.test.d.ts.map +0 -1
- package/lib/bridge/broadcast.test.js +0 -36
- package/lib/bridge/broadcast.test.js.map +0 -1
- package/lib/bridge/buildOptimisticOperation.d.ts +0 -4
- package/lib/bridge/buildOptimisticOperation.d.ts.map +0 -1
- package/lib/bridge/buildOptimisticOperation.js +0 -28
- package/lib/bridge/buildOptimisticOperation.js.map +0 -1
- package/lib/bridge/createTransaction.d.ts +0 -4
- package/lib/bridge/createTransaction.d.ts.map +0 -1
- package/lib/bridge/createTransaction.js +0 -24
- package/lib/bridge/createTransaction.js.map +0 -1
- package/lib/bridge/estimateMaxSpendable.d.ts +0 -5
- package/lib/bridge/estimateMaxSpendable.d.ts.map +0 -1
- package/lib/bridge/estimateMaxSpendable.js +0 -30
- package/lib/bridge/estimateMaxSpendable.js.map +0 -1
- package/lib/bridge/getFeesForTransaction.d.ts +0 -21
- package/lib/bridge/getFeesForTransaction.d.ts.map +0 -1
- package/lib/bridge/getFeesForTransaction.js +0 -39
- package/lib/bridge/getFeesForTransaction.js.map +0 -1
- package/lib/bridge/getTransactionStatus.d.ts +0 -4
- package/lib/bridge/getTransactionStatus.d.ts.map +0 -1
- package/lib/bridge/getTransactionStatus.js +0 -108
- package/lib/bridge/getTransactionStatus.js.map +0 -1
- package/lib/bridge/getTransactionStatus.test.d.ts +0 -2
- package/lib/bridge/getTransactionStatus.test.d.ts.map +0 -1
- package/lib/bridge/getTransactionStatus.test.js +0 -107
- package/lib/bridge/getTransactionStatus.test.js.map +0 -1
- package/lib/bridge/index.d.ts +0 -10
- package/lib/bridge/index.d.ts.map +0 -1
- package/lib/bridge/index.js +0 -59
- package/lib/bridge/index.js.map +0 -1
- package/lib/bridge/logic.d.ts +0 -10
- package/lib/bridge/logic.d.ts.map +0 -1
- package/lib/bridge/logic.js +0 -155
- package/lib/bridge/logic.js.map +0 -1
- package/lib/bridge/preload.d.ts +0 -9
- package/lib/bridge/preload.d.ts.map +0 -1
- package/lib/bridge/preload.js +0 -23
- package/lib/bridge/preload.js.map +0 -1
- package/lib/bridge/prepareTransaction.d.ts +0 -5
- package/lib/bridge/prepareTransaction.d.ts.map +0 -1
- package/lib/bridge/prepareTransaction.integ.test.d.ts +0 -2
- package/lib/bridge/prepareTransaction.integ.test.d.ts.map +0 -1
- package/lib/bridge/prepareTransaction.integ.test.js +0 -34
- package/lib/bridge/prepareTransaction.integ.test.js.map +0 -1
- package/lib/bridge/prepareTransaction.js +0 -57
- package/lib/bridge/prepareTransaction.js.map +0 -1
- package/lib/bridge/prepareTransaction.test.d.ts +0 -2
- package/lib/bridge/prepareTransaction.test.d.ts.map +0 -1
- package/lib/bridge/prepareTransaction.test.js +0 -178
- package/lib/bridge/prepareTransaction.test.js.map +0 -1
- package/lib/bridge/serialization.d.ts +0 -7
- package/lib/bridge/serialization.d.ts.map +0 -1
- package/lib/bridge/serialization.js +0 -26
- package/lib/bridge/serialization.js.map +0 -1
- package/lib/bridge/signOperation.d.ts +0 -16
- package/lib/bridge/signOperation.d.ts.map +0 -1
- package/lib/bridge/signOperation.js +0 -88
- package/lib/bridge/signOperation.js.map +0 -1
- package/lib/bridge/signOperation.test.d.ts +0 -2
- package/lib/bridge/signOperation.test.d.ts.map +0 -1
- package/lib/bridge/signOperation.test.js +0 -283
- package/lib/bridge/signOperation.test.js.map +0 -1
- package/lib/bridge/synchronization.d.ts +0 -5
- package/lib/bridge/synchronization.d.ts.map +0 -1
- package/lib/bridge/synchronization.integ.test.d.ts +0 -2
- package/lib/bridge/synchronization.integ.test.d.ts.map +0 -1
- package/lib/bridge/synchronization.integ.test.js +0 -32
- package/lib/bridge/synchronization.integ.test.js.map +0 -1
- package/lib/bridge/synchronization.js +0 -100
- package/lib/bridge/synchronization.js.map +0 -1
- package/lib/bridge/transaction.d.ts.map +0 -1
- package/lib/bridge/transaction.js.map +0 -1
- package/lib-es/bridge/broadcast.d.ts +0 -4
- package/lib-es/bridge/broadcast.d.ts.map +0 -1
- package/lib-es/bridge/broadcast.js +0 -7
- package/lib-es/bridge/broadcast.js.map +0 -1
- package/lib-es/bridge/broadcast.test.d.ts +0 -2
- package/lib-es/bridge/broadcast.test.d.ts.map +0 -1
- package/lib-es/bridge/broadcast.test.js +0 -31
- package/lib-es/bridge/broadcast.test.js.map +0 -1
- package/lib-es/bridge/buildOptimisticOperation.d.ts +0 -4
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +0 -1
- package/lib-es/bridge/buildOptimisticOperation.js +0 -21
- package/lib-es/bridge/buildOptimisticOperation.js.map +0 -1
- package/lib-es/bridge/createTransaction.d.ts +0 -4
- package/lib-es/bridge/createTransaction.d.ts.map +0 -1
- package/lib-es/bridge/createTransaction.js +0 -17
- package/lib-es/bridge/createTransaction.js.map +0 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts +0 -5
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +0 -1
- package/lib-es/bridge/estimateMaxSpendable.js +0 -23
- package/lib-es/bridge/estimateMaxSpendable.js.map +0 -1
- package/lib-es/bridge/getFeesForTransaction.d.ts +0 -21
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +0 -1
- package/lib-es/bridge/getFeesForTransaction.js +0 -33
- package/lib-es/bridge/getFeesForTransaction.js.map +0 -1
- package/lib-es/bridge/getTransactionStatus.d.ts +0 -4
- package/lib-es/bridge/getTransactionStatus.d.ts.map +0 -1
- package/lib-es/bridge/getTransactionStatus.js +0 -101
- package/lib-es/bridge/getTransactionStatus.js.map +0 -1
- package/lib-es/bridge/getTransactionStatus.test.d.ts +0 -2
- package/lib-es/bridge/getTransactionStatus.test.d.ts.map +0 -1
- package/lib-es/bridge/getTransactionStatus.test.js +0 -102
- package/lib-es/bridge/getTransactionStatus.test.js.map +0 -1
- package/lib-es/bridge/index.d.ts +0 -10
- package/lib-es/bridge/index.d.ts.map +0 -1
- package/lib-es/bridge/index.js +0 -53
- package/lib-es/bridge/index.js.map +0 -1
- package/lib-es/bridge/logic.d.ts +0 -10
- package/lib-es/bridge/logic.d.ts.map +0 -1
- package/lib-es/bridge/logic.js +0 -145
- package/lib-es/bridge/logic.js.map +0 -1
- package/lib-es/bridge/preload.d.ts +0 -9
- package/lib-es/bridge/preload.d.ts.map +0 -1
- package/lib-es/bridge/preload.js +0 -17
- package/lib-es/bridge/preload.js.map +0 -1
- package/lib-es/bridge/prepareTransaction.d.ts +0 -5
- package/lib-es/bridge/prepareTransaction.d.ts.map +0 -1
- package/lib-es/bridge/prepareTransaction.integ.test.d.ts +0 -2
- package/lib-es/bridge/prepareTransaction.integ.test.d.ts.map +0 -1
- package/lib-es/bridge/prepareTransaction.integ.test.js +0 -29
- package/lib-es/bridge/prepareTransaction.integ.test.js.map +0 -1
- package/lib-es/bridge/prepareTransaction.js +0 -50
- package/lib-es/bridge/prepareTransaction.js.map +0 -1
- package/lib-es/bridge/prepareTransaction.test.d.ts +0 -2
- package/lib-es/bridge/prepareTransaction.test.d.ts.map +0 -1
- package/lib-es/bridge/prepareTransaction.test.js +0 -173
- package/lib-es/bridge/prepareTransaction.test.js.map +0 -1
- package/lib-es/bridge/serialization.d.ts +0 -7
- package/lib-es/bridge/serialization.d.ts.map +0 -1
- package/lib-es/bridge/serialization.js +0 -20
- package/lib-es/bridge/serialization.js.map +0 -1
- package/lib-es/bridge/signOperation.d.ts +0 -16
- package/lib-es/bridge/signOperation.d.ts.map +0 -1
- package/lib-es/bridge/signOperation.js +0 -83
- package/lib-es/bridge/signOperation.js.map +0 -1
- package/lib-es/bridge/signOperation.test.d.ts +0 -2
- package/lib-es/bridge/signOperation.test.d.ts.map +0 -1
- package/lib-es/bridge/signOperation.test.js +0 -255
- package/lib-es/bridge/signOperation.test.js.map +0 -1
- package/lib-es/bridge/synchronization.d.ts +0 -5
- package/lib-es/bridge/synchronization.d.ts.map +0 -1
- package/lib-es/bridge/synchronization.integ.test.d.ts +0 -2
- package/lib-es/bridge/synchronization.integ.test.d.ts.map +0 -1
- package/lib-es/bridge/synchronization.integ.test.js +0 -27
- package/lib-es/bridge/synchronization.integ.test.js.map +0 -1
- package/lib-es/bridge/synchronization.js +0 -70
- package/lib-es/bridge/synchronization.js.map +0 -1
- package/lib-es/bridge/transaction.d.ts.map +0 -1
- package/lib-es/bridge/transaction.js.map +0 -1
- package/src/bridge/broadcast.test.ts +0 -36
- package/src/bridge/broadcast.ts +0 -13
- package/src/bridge/buildOptimisticOperation.ts +0 -28
- package/src/bridge/createTransaction.ts +0 -19
- package/src/bridge/estimateMaxSpendable.ts +0 -37
- package/src/bridge/getFeesForTransaction.ts +0 -49
- package/src/bridge/getTransactionStatus.test.ts +0 -124
- package/src/bridge/getTransactionStatus.ts +0 -123
- package/src/bridge/index.ts +0 -74
- package/src/bridge/logic.ts +0 -171
- package/src/bridge/preload.ts +0 -18
- package/src/bridge/prepareTransaction.integ.test.ts +0 -35
- package/src/bridge/prepareTransaction.test.ts +0 -205
- package/src/bridge/prepareTransaction.ts +0 -69
- package/src/bridge/serialization.ts +0 -27
- package/src/bridge/signOperation.test.ts +0 -284
- package/src/bridge/signOperation.ts +0 -130
- package/src/bridge/synchronization.integ.test.ts +0 -33
- package/src/bridge/synchronization.ts +0 -100
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import BigNumber from "bignumber.js";
|
|
2
|
-
import { createFixtureAccount, createFixtureTransaction } from "../types/bridge.fixture";
|
|
3
|
-
import prepareTransaction from "./prepareTransaction";
|
|
4
|
-
import { faker } from "@faker-js/faker";
|
|
5
|
-
import coinConfig, { TezosCoinConfig } from "../config";
|
|
6
|
-
import { mockConfig } from "../test/config";
|
|
7
|
-
import { COST_PER_BYTE, getRevealFee } from "@taquito/taquito";
|
|
8
|
-
|
|
9
|
-
const mockTezosEstimate = jest.fn();
|
|
10
|
-
jest.mock("../logic/tezosToolkit", () => ({
|
|
11
|
-
getTezosToolkit: () => ({
|
|
12
|
-
setProvider: jest.fn(),
|
|
13
|
-
estimate: {
|
|
14
|
-
transfer: () => mockTezosEstimate(),
|
|
15
|
-
},
|
|
16
|
-
}),
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
describe("prepareTransaction", () => {
|
|
20
|
-
beforeAll(() => {
|
|
21
|
-
coinConfig.setCoinConfig((): TezosCoinConfig => mockConfig as TezosCoinConfig);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
mockTezosEstimate.mockReset();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("returns the same transaction when account balance is 0", async () => {
|
|
29
|
-
// Given
|
|
30
|
-
const tx = createFixtureTransaction({ amount: BigNumber(0) });
|
|
31
|
-
|
|
32
|
-
// When
|
|
33
|
-
const newTx = await prepareTransaction(createFixtureAccount(), tx);
|
|
34
|
-
|
|
35
|
-
// Then
|
|
36
|
-
expect(newTx).toBe(tx);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("returns error when amount is 0", async () => {
|
|
40
|
-
// Given
|
|
41
|
-
const tx = createFixtureTransaction({
|
|
42
|
-
amount: BigNumber(0),
|
|
43
|
-
recipient: "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb",
|
|
44
|
-
});
|
|
45
|
-
mockTezosEstimate.mockRejectedValue({
|
|
46
|
-
id: "proto.020-PsParisC.contract.empty_transaction",
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// When
|
|
50
|
-
const newTx = await prepareTransaction(createFixtureAccount({ balance: BigNumber(10) }), tx);
|
|
51
|
-
|
|
52
|
-
// Then
|
|
53
|
-
expect(newTx.taquitoError).toEqual("proto.020-PsParisC.contract.empty_transaction");
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("returns new transaction with estimated fees by TezosToolkit", async () => {
|
|
57
|
-
// Given
|
|
58
|
-
const tx = createFixtureTransaction({
|
|
59
|
-
amount: BigNumber(200),
|
|
60
|
-
recipient: "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb",
|
|
61
|
-
});
|
|
62
|
-
const tezosEstimate = {
|
|
63
|
-
suggestedFeeMutez: faker.number.int(20),
|
|
64
|
-
gasLimit: faker.number.int(20),
|
|
65
|
-
storageLimit: faker.number.int(20),
|
|
66
|
-
};
|
|
67
|
-
mockTezosEstimate.mockResolvedValue(tezosEstimate);
|
|
68
|
-
|
|
69
|
-
// When
|
|
70
|
-
const newTx = await prepareTransaction(createFixtureAccount({ balance: BigNumber(1_000) }), tx);
|
|
71
|
-
|
|
72
|
-
// Then
|
|
73
|
-
expect(newTx).toEqual({
|
|
74
|
-
...tx,
|
|
75
|
-
fees: new BigNumber(tezosEstimate.suggestedFeeMutez),
|
|
76
|
-
estimatedFees: new BigNumber(tezosEstimate.suggestedFeeMutez),
|
|
77
|
-
gasLimit: new BigNumber(tezosEstimate.gasLimit),
|
|
78
|
-
storageLimit: new BigNumber(tezosEstimate.storageLimit),
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("returns new transaction with estimated fees by TezosToolkit when useAllAmount from revealed account to revealed account", async () => {
|
|
83
|
-
// Given
|
|
84
|
-
const tx = createFixtureTransaction({
|
|
85
|
-
amount: BigNumber(200),
|
|
86
|
-
recipient: "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb",
|
|
87
|
-
useAllAmount: true,
|
|
88
|
-
});
|
|
89
|
-
const tezosEstimate = {
|
|
90
|
-
suggestedFeeMutez: faker.number.int(20),
|
|
91
|
-
gasLimit: faker.number.int(20),
|
|
92
|
-
storageLimit: faker.number.int(20),
|
|
93
|
-
opSize: faker.number.int(20),
|
|
94
|
-
burnFeeMutez: faker.number.int(0),
|
|
95
|
-
};
|
|
96
|
-
mockTezosEstimate.mockResolvedValue(tezosEstimate);
|
|
97
|
-
const account = createFixtureAccount({ balance: BigNumber(1_000) });
|
|
98
|
-
|
|
99
|
-
// When
|
|
100
|
-
const newTx = await prepareTransaction(account, tx);
|
|
101
|
-
|
|
102
|
-
// Then
|
|
103
|
-
const gasLimit = 500; // hardcoded in the function
|
|
104
|
-
const maxAmount = account.balance.minus(tezosEstimate.suggestedFeeMutez);
|
|
105
|
-
|
|
106
|
-
expect(newTx).toEqual({
|
|
107
|
-
...tx,
|
|
108
|
-
fees: new BigNumber(tezosEstimate.suggestedFeeMutez),
|
|
109
|
-
estimatedFees: new BigNumber(tezosEstimate.suggestedFeeMutez),
|
|
110
|
-
gasLimit: new BigNumber(tezosEstimate.gasLimit),
|
|
111
|
-
storageLimit: new BigNumber(tezosEstimate.storageLimit),
|
|
112
|
-
amount: maxAmount.minus(gasLimit - (tezosEstimate.opSize + gasLimit * 0.1)),
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it("returns new transaction with estimated fees by TezosToolkit when useAllAmount from revealed account to account with zero balance", async () => {
|
|
117
|
-
// Given
|
|
118
|
-
const tx = createFixtureTransaction({
|
|
119
|
-
amount: BigNumber(0),
|
|
120
|
-
recipient: "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb",
|
|
121
|
-
useAllAmount: true,
|
|
122
|
-
});
|
|
123
|
-
const tezosEstimate = {
|
|
124
|
-
suggestedFeeMutez: faker.number.int(20),
|
|
125
|
-
gasLimit: faker.number.int(20),
|
|
126
|
-
storageLimit: faker.number.int(20),
|
|
127
|
-
opSize: faker.number.int(20),
|
|
128
|
-
burnFeeMutez: faker.number.int({ min: 1, max: 20 }),
|
|
129
|
-
};
|
|
130
|
-
mockTezosEstimate.mockResolvedValue(tezosEstimate);
|
|
131
|
-
const account = createFixtureAccount({ balance: BigNumber(1_000) });
|
|
132
|
-
// When
|
|
133
|
-
const newTx = await prepareTransaction(account, tx);
|
|
134
|
-
|
|
135
|
-
// Then
|
|
136
|
-
const gasLimit = 500; // hardcoded in the function
|
|
137
|
-
const computedFees = new BigNumber(
|
|
138
|
-
tezosEstimate.suggestedFeeMutez + tezosEstimate.burnFeeMutez - 20 * COST_PER_BYTE,
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
const maxAmount = account.balance.minus(computedFees);
|
|
142
|
-
|
|
143
|
-
expect(newTx).toEqual({
|
|
144
|
-
...tx,
|
|
145
|
-
fees: new BigNumber(tezosEstimate.suggestedFeeMutez),
|
|
146
|
-
estimatedFees: new BigNumber(tezosEstimate.suggestedFeeMutez),
|
|
147
|
-
gasLimit: new BigNumber(tezosEstimate.gasLimit),
|
|
148
|
-
storageLimit: new BigNumber(tezosEstimate.storageLimit),
|
|
149
|
-
amount: maxAmount.minus(gasLimit - (tezosEstimate.opSize + gasLimit * 0.1)),
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("returns new transaction with estimated fees by TezosToolkit when useAllAmount from unrevealed account to revealed account", async () => {
|
|
154
|
-
// Given
|
|
155
|
-
const tx = createFixtureTransaction({
|
|
156
|
-
amount: BigNumber(200),
|
|
157
|
-
recipient: "tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb",
|
|
158
|
-
useAllAmount: true,
|
|
159
|
-
});
|
|
160
|
-
const tezosEstimate = {
|
|
161
|
-
suggestedFeeMutez: faker.number.int(20),
|
|
162
|
-
gasLimit: faker.number.int(20),
|
|
163
|
-
storageLimit: faker.number.int(20),
|
|
164
|
-
opSize: faker.number.int(20),
|
|
165
|
-
burnFeeMutez: faker.number.int(0),
|
|
166
|
-
};
|
|
167
|
-
mockTezosEstimate.mockResolvedValue(tezosEstimate);
|
|
168
|
-
const account = createFixtureAccount({ balance: BigNumber(1_000) });
|
|
169
|
-
account.tezosResources.revealed = false;
|
|
170
|
-
// When
|
|
171
|
-
const newTx = await prepareTransaction(account, tx);
|
|
172
|
-
|
|
173
|
-
// Then
|
|
174
|
-
const gasLimit = 500; // hardcoded in the function
|
|
175
|
-
const computedFees = new BigNumber(
|
|
176
|
-
tezosEstimate.suggestedFeeMutez + getRevealFee(account.freshAddress),
|
|
177
|
-
);
|
|
178
|
-
|
|
179
|
-
const maxAmount = account.balance.minus(computedFees);
|
|
180
|
-
|
|
181
|
-
expect(newTx).toEqual({
|
|
182
|
-
...tx,
|
|
183
|
-
fees: new BigNumber(tezosEstimate.suggestedFeeMutez),
|
|
184
|
-
estimatedFees: new BigNumber(
|
|
185
|
-
tezosEstimate.suggestedFeeMutez + getRevealFee(account.freshAddress),
|
|
186
|
-
),
|
|
187
|
-
gasLimit: new BigNumber(tezosEstimate.gasLimit),
|
|
188
|
-
storageLimit: new BigNumber(tezosEstimate.storageLimit),
|
|
189
|
-
amount: maxAmount.minus(gasLimit - (tezosEstimate.opSize + gasLimit * 0.1)),
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
// it("returns the passed transaction if fees are the same", async () => {
|
|
194
|
-
// // Given
|
|
195
|
-
// const fees = new BigNumber(faker.number.int(50));
|
|
196
|
-
// mockEstimateFees.mockResolvedValue(fees);
|
|
197
|
-
// const tx = createFixtureTransaction({ fees });
|
|
198
|
-
|
|
199
|
-
// // When
|
|
200
|
-
// const newTx = await prepareTransaction(createFixtureAccount(), tx);
|
|
201
|
-
|
|
202
|
-
// // Then
|
|
203
|
-
// expect(newTx).toBe(tx);
|
|
204
|
-
// });
|
|
205
|
-
});
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import BigNumber from "bignumber.js";
|
|
2
|
-
import { AccountBridge } from "@ledgerhq/types-live";
|
|
3
|
-
import { TezosAccount, Transaction } from "../types";
|
|
4
|
-
import { validateRecipient } from "../logic";
|
|
5
|
-
import getEstimatedFees from "./getFeesForTransaction";
|
|
6
|
-
import coinConfig from "../config";
|
|
7
|
-
|
|
8
|
-
function bnEq(a: BigNumber | null | undefined, b: BigNumber | null | undefined): boolean {
|
|
9
|
-
return !a && !b ? true : !a || !b ? false : a.eq(b);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function maxBigNumber(a: BigNumber, b: BigNumber): BigNumber {
|
|
13
|
-
return a.isGreaterThan(b) ? a : b;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const prepareTransaction: AccountBridge<
|
|
17
|
-
Transaction,
|
|
18
|
-
TezosAccount
|
|
19
|
-
>["prepareTransaction"] = async (account, transaction) => {
|
|
20
|
-
if (account.balance.lte(0)) {
|
|
21
|
-
return Promise.resolve(transaction);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// basic check to confirm the transaction is "complete"
|
|
25
|
-
if (transaction.mode !== "undelegate") {
|
|
26
|
-
if (!transaction.recipient) {
|
|
27
|
-
return Promise.resolve(transaction);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const { recipientError } = await validateRecipient(transaction.recipient);
|
|
31
|
-
if (recipientError) {
|
|
32
|
-
return Promise.resolve(transaction);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const estimation = await getEstimatedFees({ account, transaction });
|
|
37
|
-
const minGasLimit = coinConfig.getCoinConfig().fees.minGasLimit;
|
|
38
|
-
const minStorageLimit = coinConfig.getCoinConfig().fees.minStorageLimit;
|
|
39
|
-
const minFees = coinConfig.getCoinConfig().fees.minFees;
|
|
40
|
-
const minEstimatedFees = coinConfig.getCoinConfig().fees.minEstimatedFees;
|
|
41
|
-
|
|
42
|
-
estimation.gasLimit = maxBigNumber(estimation.gasLimit, new BigNumber(minGasLimit));
|
|
43
|
-
estimation.storageLimit = maxBigNumber(estimation.storageLimit, new BigNumber(minStorageLimit));
|
|
44
|
-
estimation.fees = maxBigNumber(estimation.fees, new BigNumber(minFees));
|
|
45
|
-
estimation.estimatedFees = maxBigNumber(
|
|
46
|
-
estimation.estimatedFees,
|
|
47
|
-
new BigNumber(minEstimatedFees),
|
|
48
|
-
);
|
|
49
|
-
const tx: Transaction = {
|
|
50
|
-
...transaction,
|
|
51
|
-
...estimation,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// nothing changed
|
|
55
|
-
if (
|
|
56
|
-
bnEq(tx.estimatedFees, transaction.estimatedFees) &&
|
|
57
|
-
bnEq(tx.fees, transaction.fees) &&
|
|
58
|
-
bnEq(tx.gasLimit, transaction.gasLimit) &&
|
|
59
|
-
bnEq(tx.storageLimit, transaction.storageLimit) &&
|
|
60
|
-
bnEq(tx.amount, transaction.amount) &&
|
|
61
|
-
tx.taquitoError === transaction.taquitoError
|
|
62
|
-
) {
|
|
63
|
-
return transaction;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return tx;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export default prepareTransaction;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { TezosAccount, TezosAccountRaw, TezosResources, TezosResourcesRaw } from "../types";
|
|
2
|
-
import { Account, AccountRaw } from "@ledgerhq/types-live";
|
|
3
|
-
|
|
4
|
-
export function toTezosResourcesRaw(r: TezosResources): TezosResourcesRaw {
|
|
5
|
-
const { revealed, counter } = r;
|
|
6
|
-
return { revealed, counter };
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function fromTezosResourcesRaw(r: TezosResourcesRaw): TezosResources {
|
|
10
|
-
const { revealed, counter } = r;
|
|
11
|
-
return { revealed, counter };
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function assignToAccountRaw(account: Account, accountRaw: AccountRaw) {
|
|
15
|
-
const tezosAccount = account as TezosAccount;
|
|
16
|
-
if (tezosAccount.tezosResources) {
|
|
17
|
-
(accountRaw as TezosAccountRaw).tezosResources = toTezosResourcesRaw(
|
|
18
|
-
tezosAccount.tezosResources,
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function assignFromAccountRaw(accountRaw: AccountRaw, account: Account) {
|
|
24
|
-
const tezosResourcesRaw = (accountRaw as TezosAccountRaw).tezosResources;
|
|
25
|
-
if (tezosResourcesRaw)
|
|
26
|
-
(account as TezosAccount).tezosResources = fromTezosResourcesRaw(tezosResourcesRaw);
|
|
27
|
-
}
|
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
import BigNumber from "bignumber.js";
|
|
2
|
-
import { getRevealFee, OpKind } from "@taquito/taquito";
|
|
3
|
-
import { SignOperationEvent } from "@ledgerhq/types-live";
|
|
4
|
-
import buildSignOperation, { getOperationContents } from "./signOperation";
|
|
5
|
-
import config, { type TezosCoinConfig } from "../config";
|
|
6
|
-
import { TezosSigner } from "../types";
|
|
7
|
-
import { createFixtureAccount, createFixtureTransaction } from "../types/bridge.fixture";
|
|
8
|
-
import { mockConfig } from "../test/config";
|
|
9
|
-
|
|
10
|
-
const mockForgeOperations = jest.fn();
|
|
11
|
-
const mockEstimateReveal = jest.fn();
|
|
12
|
-
jest.mock("@taquito/taquito", () => ({
|
|
13
|
-
...jest.requireActual("@taquito/taquito"),
|
|
14
|
-
TezosToolkit: jest.fn().mockReturnValue({
|
|
15
|
-
setProvider: jest.fn(),
|
|
16
|
-
rpc: {
|
|
17
|
-
getBlock: jest.fn().mockResolvedValue({ hash: "hash" }),
|
|
18
|
-
getContract: jest.fn().mockResolvedValue({ counter: "12" }),
|
|
19
|
-
forgeOperations: () => mockForgeOperations(),
|
|
20
|
-
},
|
|
21
|
-
estimate: {
|
|
22
|
-
reveal: () => mockEstimateReveal(),
|
|
23
|
-
},
|
|
24
|
-
}),
|
|
25
|
-
}));
|
|
26
|
-
|
|
27
|
-
describe("signOperation", () => {
|
|
28
|
-
const mockSign = jest.fn().mockResolvedValue({
|
|
29
|
-
bytes: "SIG_BYTES",
|
|
30
|
-
sig: "SIG",
|
|
31
|
-
prefixSig: "PREFIX_SIG",
|
|
32
|
-
sbytes: "03SBYTES",
|
|
33
|
-
});
|
|
34
|
-
const fakeSigner = {
|
|
35
|
-
getAddress: jest.fn(),
|
|
36
|
-
signOperation: jest.fn(),
|
|
37
|
-
createLedgerSigner: () => ({
|
|
38
|
-
publicKey: () => Promise.resolve("PUBKEY"),
|
|
39
|
-
publicKeyHash: () => Promise.resolve("PUBKEYHASH"),
|
|
40
|
-
sign: (arg: unknown) => mockSign(arg),
|
|
41
|
-
secretKey: () => Promise.resolve(undefined),
|
|
42
|
-
}),
|
|
43
|
-
};
|
|
44
|
-
const signerContext = <T>(_deviceId: string, fn: (signer: TezosSigner) => Promise<T>) =>
|
|
45
|
-
fn(fakeSigner);
|
|
46
|
-
const signOperation = buildSignOperation(signerContext);
|
|
47
|
-
const deviceId = "dummyDeviceId";
|
|
48
|
-
|
|
49
|
-
beforeAll(() => {
|
|
50
|
-
config.setCoinConfig((): TezosCoinConfig => mockConfig as TezosCoinConfig);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
afterEach(() => {
|
|
54
|
-
mockForgeOperations.mockClear();
|
|
55
|
-
mockEstimateReveal.mockClear();
|
|
56
|
-
mockSign.mockClear();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("returns events in the right order", done => {
|
|
60
|
-
// GIVEN
|
|
61
|
-
const account = createFixtureAccount();
|
|
62
|
-
const transaction = createFixtureTransaction({ fees: BigNumber(0) });
|
|
63
|
-
mockForgeOperations.mockResolvedValue("FORGED_OP");
|
|
64
|
-
|
|
65
|
-
// WHEN & THEN
|
|
66
|
-
const expectedEvent = [
|
|
67
|
-
{
|
|
68
|
-
type: "device-signature-requested",
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
type: "device-signature-granted",
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
type: "signed",
|
|
75
|
-
},
|
|
76
|
-
];
|
|
77
|
-
let eventIdx = 0;
|
|
78
|
-
signOperation({ account, deviceId, transaction }).forEach(e => {
|
|
79
|
-
try {
|
|
80
|
-
expect(e.type).toEqual(expectedEvent[eventIdx].type);
|
|
81
|
-
eventIdx++;
|
|
82
|
-
|
|
83
|
-
if (eventIdx === expectedEvent.length) {
|
|
84
|
-
done();
|
|
85
|
-
}
|
|
86
|
-
} catch (err) {
|
|
87
|
-
done(err);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("returns signature value from LedgerSigner", done => {
|
|
93
|
-
// GIVEN
|
|
94
|
-
const account = createFixtureAccount();
|
|
95
|
-
const transaction = createFixtureTransaction({ fees: new BigNumber(0) });
|
|
96
|
-
mockForgeOperations.mockResolvedValue("f0463d");
|
|
97
|
-
|
|
98
|
-
// WHEN & THEN
|
|
99
|
-
const subscriber = signOperation({ account, deviceId, transaction }).subscribe(
|
|
100
|
-
(e: SignOperationEvent) => {
|
|
101
|
-
if (e.type === "signed") {
|
|
102
|
-
const signature = e.signedOperation.signature;
|
|
103
|
-
expect(signature).toEqual("SBYTES");
|
|
104
|
-
expect(mockForgeOperations).toHaveBeenCalledTimes(1);
|
|
105
|
-
expect(mockSign).toHaveBeenCalledTimes(1);
|
|
106
|
-
expect(mockSign.mock.lastCall[0]).toEqual(
|
|
107
|
-
Buffer.concat([Buffer.from("03", "hex"), Buffer.from("f0463d", "hex")]).toString("hex"),
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
// Cleanup
|
|
111
|
-
subscriber.unsubscribe();
|
|
112
|
-
done();
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe("getOperationContents - revealed account", () => {
|
|
120
|
-
const account = createFixtureAccount({ freshAddress: "tz1addr" });
|
|
121
|
-
|
|
122
|
-
it("mode - send", async () => {
|
|
123
|
-
const transaction = createFixtureTransaction({
|
|
124
|
-
family: "tezos",
|
|
125
|
-
amount: new BigNumber(0),
|
|
126
|
-
recipient: "RECIPIENT_ADD",
|
|
127
|
-
fees: new BigNumber(0),
|
|
128
|
-
mode: "send",
|
|
129
|
-
gasLimit: new BigNumber(0),
|
|
130
|
-
storageLimit: new BigNumber(0),
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
const { type, contents } = await getOperationContents({
|
|
134
|
-
account,
|
|
135
|
-
transaction,
|
|
136
|
-
counter: 0,
|
|
137
|
-
public_key: "pk",
|
|
138
|
-
public_key_hash: "pkh",
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
expect(type).toBe("OUT");
|
|
142
|
-
expect(contents.length).toEqual(1);
|
|
143
|
-
expect(contents).toStrictEqual([
|
|
144
|
-
{
|
|
145
|
-
kind: OpKind.TRANSACTION,
|
|
146
|
-
amount: transaction.amount.toString(),
|
|
147
|
-
destination: transaction.recipient,
|
|
148
|
-
source: "tz1addr",
|
|
149
|
-
counter: "1",
|
|
150
|
-
fee: new BigNumber(0).toString(),
|
|
151
|
-
gas_limit: new BigNumber(0).toString(),
|
|
152
|
-
storage_limit: new BigNumber(0).toString(),
|
|
153
|
-
},
|
|
154
|
-
]);
|
|
155
|
-
expect(mockEstimateReveal).not.toHaveBeenCalled();
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("mode - delegate", async () => {
|
|
159
|
-
const transaction = createFixtureTransaction({
|
|
160
|
-
family: "tezos",
|
|
161
|
-
amount: new BigNumber(0),
|
|
162
|
-
recipient: "RECIPIENT_ADD",
|
|
163
|
-
fees: new BigNumber(0),
|
|
164
|
-
mode: "delegate",
|
|
165
|
-
gasLimit: new BigNumber(0),
|
|
166
|
-
storageLimit: new BigNumber(0),
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
const { type, contents } = await getOperationContents({
|
|
170
|
-
account,
|
|
171
|
-
transaction,
|
|
172
|
-
counter: 0,
|
|
173
|
-
public_key: "pk",
|
|
174
|
-
public_key_hash: "pkh",
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
expect(type).toBe("DELEGATE");
|
|
178
|
-
expect(contents.length).toEqual(1);
|
|
179
|
-
expect(contents).toStrictEqual([
|
|
180
|
-
{
|
|
181
|
-
kind: OpKind.DELEGATION,
|
|
182
|
-
source: "tz1addr",
|
|
183
|
-
counter: "1",
|
|
184
|
-
fee: new BigNumber(0).toString(),
|
|
185
|
-
gas_limit: new BigNumber(0).toString(),
|
|
186
|
-
storage_limit: new BigNumber(0).toString(),
|
|
187
|
-
delegate: transaction.recipient,
|
|
188
|
-
},
|
|
189
|
-
]);
|
|
190
|
-
expect(mockEstimateReveal).not.toHaveBeenCalled();
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it("mode - undelegate", async () => {
|
|
194
|
-
const transaction = createFixtureTransaction({
|
|
195
|
-
family: "tezos",
|
|
196
|
-
amount: new BigNumber(0),
|
|
197
|
-
recipient: "",
|
|
198
|
-
fees: new BigNumber(0),
|
|
199
|
-
mode: "undelegate",
|
|
200
|
-
gasLimit: new BigNumber(0),
|
|
201
|
-
storageLimit: new BigNumber(0),
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
const { type, contents } = await getOperationContents({
|
|
205
|
-
account,
|
|
206
|
-
transaction,
|
|
207
|
-
counter: 0,
|
|
208
|
-
public_key: "pk",
|
|
209
|
-
public_key_hash: "pkh",
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
expect(type).toBe("UNDELEGATE");
|
|
213
|
-
expect(contents.length).toEqual(1);
|
|
214
|
-
expect(contents).toStrictEqual([
|
|
215
|
-
{
|
|
216
|
-
kind: OpKind.DELEGATION,
|
|
217
|
-
source: "tz1addr",
|
|
218
|
-
counter: "1",
|
|
219
|
-
fee: new BigNumber(0).toString(),
|
|
220
|
-
gas_limit: new BigNumber(0).toString(),
|
|
221
|
-
storage_limit: new BigNumber(0).toString(),
|
|
222
|
-
},
|
|
223
|
-
]);
|
|
224
|
-
expect(mockEstimateReveal).not.toHaveBeenCalled();
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
describe("getOperationContents - not revealed account", () => {
|
|
228
|
-
const account = createFixtureAccount({
|
|
229
|
-
freshAddress: "tz1addr",
|
|
230
|
-
// We don't use `counter` in the OperationContents computation
|
|
231
|
-
tezosResources: { revealed: false, counter: -10 },
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it("mode - send", async () => {
|
|
235
|
-
// Given
|
|
236
|
-
mockEstimateReveal.mockResolvedValue({
|
|
237
|
-
gasLimit: 100,
|
|
238
|
-
storageLimit: 200,
|
|
239
|
-
});
|
|
240
|
-
const transaction = createFixtureTransaction({
|
|
241
|
-
family: "tezos",
|
|
242
|
-
amount: new BigNumber(0),
|
|
243
|
-
recipient: "RECIPIENT_ADD",
|
|
244
|
-
fees: new BigNumber(0),
|
|
245
|
-
mode: "send",
|
|
246
|
-
gasLimit: new BigNumber(0),
|
|
247
|
-
storageLimit: new BigNumber(0),
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
const { type, contents } = await getOperationContents({
|
|
251
|
-
account,
|
|
252
|
-
transaction,
|
|
253
|
-
counter: 0,
|
|
254
|
-
public_key: "pk",
|
|
255
|
-
public_key_hash: "pkh",
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
expect(type).toBe("OUT");
|
|
259
|
-
expect(contents.length).toEqual(2);
|
|
260
|
-
expect(contents).toStrictEqual([
|
|
261
|
-
{
|
|
262
|
-
kind: OpKind.REVEAL,
|
|
263
|
-
fee: getRevealFee(account.freshAddress).toString(),
|
|
264
|
-
gas_limit: "100",
|
|
265
|
-
storage_limit: "200",
|
|
266
|
-
source: "pkh",
|
|
267
|
-
counter: "1",
|
|
268
|
-
public_key: "pk",
|
|
269
|
-
},
|
|
270
|
-
{
|
|
271
|
-
kind: OpKind.TRANSACTION,
|
|
272
|
-
amount: transaction.amount.toString(),
|
|
273
|
-
destination: transaction.recipient,
|
|
274
|
-
source: "tz1addr",
|
|
275
|
-
counter: "2",
|
|
276
|
-
fee: new BigNumber(0).toString(),
|
|
277
|
-
gas_limit: new BigNumber(0).toString(),
|
|
278
|
-
storage_limit: new BigNumber(0).toString(),
|
|
279
|
-
},
|
|
280
|
-
]);
|
|
281
|
-
expect(mockEstimateReveal).toHaveBeenCalledTimes(1);
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
});
|