@ledgerhq/coin-ton 0.5.2 → 0.5.3
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 +2 -2
- package/CHANGELOG.md +14 -0
- package/lib/__tests__/fixtures/api.fixtures.d.ts +1 -1
- package/lib/__tests__/fixtures/api.fixtures.d.ts.map +1 -1
- package/lib/__tests__/fixtures/common.fixtures.js +4 -1
- package/lib/__tests__/fixtures/common.fixtures.js.map +1 -1
- package/lib/__tests__/integration/bridge.integration.test.js +2 -3
- package/lib/__tests__/integration/bridge.integration.test.js.map +1 -1
- package/lib/__tests__/unit/api.unit.test.js +18 -27
- package/lib/__tests__/unit/api.unit.test.js.map +1 -1
- package/lib/__tests__/unit/broadcast.unit.test.js +10 -13
- package/lib/__tests__/unit/broadcast.unit.test.js.map +1 -1
- package/lib/__tests__/unit/createTransaction.unit.test.js +2 -11
- package/lib/__tests__/unit/createTransaction.unit.test.js.map +1 -1
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js +19 -22
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -1
- package/lib/__tests__/unit/estimateMaxSpendable.unit.test.js +6 -15
- package/lib/__tests__/unit/estimateMaxSpendable.unit.test.js.map +1 -1
- package/lib/__tests__/unit/getTransactionStatus.unit.test.js +58 -48
- package/lib/__tests__/unit/getTransactionStatus.unit.test.js.map +1 -1
- package/lib/__tests__/unit/hw-getAddress.unit.test.js +12 -25
- package/lib/__tests__/unit/hw-getAddress.unit.test.js.map +1 -1
- package/lib/__tests__/unit/prepareTransaction.unit.test.js +46 -34
- package/lib/__tests__/unit/prepareTransaction.unit.test.js.map +1 -1
- package/lib/__tests__/unit/signOperation.unit.test.js +11 -22
- package/lib/__tests__/unit/signOperation.unit.test.js.map +1 -1
- package/lib/__tests__/unit/txn.unit.test.js +32 -39
- package/lib/__tests__/unit/txn.unit.test.js.map +1 -1
- package/lib/__tests__/unit/utils.unit.test.js +22 -8
- package/lib/__tests__/unit/utils.unit.test.js.map +1 -1
- package/lib/bridge/bridgeHelpers/api.js +65 -88
- package/lib/bridge/bridgeHelpers/api.js.map +1 -1
- package/lib/bridge/bridgeHelpers/txn.js +52 -66
- package/lib/bridge/bridgeHelpers/txn.js.map +1 -1
- package/lib/bridge/js.js +1 -10
- package/lib/bridge/js.js.map +1 -1
- package/lib/broadcast.js +3 -12
- package/lib/broadcast.js.map +1 -1
- package/lib/cli-transaction.js +6 -1
- package/lib/cli-transaction.js.map +1 -1
- package/lib/config.js +1 -1
- package/lib/config.js.map +1 -1
- package/lib/estimateMaxSpendable.js +7 -16
- package/lib/estimateMaxSpendable.js.map +1 -1
- package/lib/getTransactionStatus.js +14 -18
- package/lib/getTransactionStatus.js.map +1 -1
- package/lib/hw-getAddress.js +6 -15
- package/lib/hw-getAddress.js.map +1 -1
- package/lib/hw-signMessage.js +3 -12
- package/lib/hw-signMessage.js.map +1 -1
- package/lib/prepareTransaction.js +5 -15
- package/lib/prepareTransaction.js.map +1 -1
- package/lib/signOperation.js +23 -35
- package/lib/signOperation.js.map +1 -1
- package/lib/specs.js +12 -18
- package/lib/specs.js.map +1 -1
- package/lib/synchronisation.js +46 -55
- package/lib/synchronisation.js.map +1 -1
- package/lib/transaction.js +13 -2
- package/lib/transaction.js.map +1 -1
- package/lib/utils.js +11 -20
- package/lib/utils.js.map +1 -1
- package/lib-es/__tests__/fixtures/api.fixtures.d.ts +1 -1
- package/lib-es/__tests__/fixtures/api.fixtures.d.ts.map +1 -1
- package/lib-es/__tests__/fixtures/common.fixtures.js +4 -1
- package/lib-es/__tests__/fixtures/common.fixtures.js.map +1 -1
- package/lib-es/__tests__/integration/bridge.integration.test.js +2 -3
- package/lib-es/__tests__/integration/bridge.integration.test.js.map +1 -1
- package/lib-es/__tests__/unit/api.unit.test.js +18 -27
- package/lib-es/__tests__/unit/api.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/broadcast.unit.test.js +10 -13
- package/lib-es/__tests__/unit/broadcast.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/createTransaction.unit.test.js +2 -11
- package/lib-es/__tests__/unit/createTransaction.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js +19 -22
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.js +6 -15
- package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/getTransactionStatus.unit.test.js +58 -48
- package/lib-es/__tests__/unit/getTransactionStatus.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/hw-getAddress.unit.test.js +12 -25
- package/lib-es/__tests__/unit/hw-getAddress.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.js +46 -34
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/signOperation.unit.test.js +11 -22
- package/lib-es/__tests__/unit/signOperation.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/txn.unit.test.js +32 -39
- package/lib-es/__tests__/unit/txn.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/utils.unit.test.js +22 -8
- package/lib-es/__tests__/unit/utils.unit.test.js.map +1 -1
- package/lib-es/bridge/bridgeHelpers/api.js +65 -88
- package/lib-es/bridge/bridgeHelpers/api.js.map +1 -1
- package/lib-es/bridge/bridgeHelpers/txn.js +52 -66
- package/lib-es/bridge/bridgeHelpers/txn.js.map +1 -1
- package/lib-es/bridge/js.js +1 -10
- package/lib-es/bridge/js.js.map +1 -1
- package/lib-es/broadcast.js +3 -12
- package/lib-es/broadcast.js.map +1 -1
- package/lib-es/cli-transaction.js +6 -1
- package/lib-es/cli-transaction.js.map +1 -1
- package/lib-es/config.js +1 -1
- package/lib-es/config.js.map +1 -1
- package/lib-es/estimateMaxSpendable.js +7 -16
- package/lib-es/estimateMaxSpendable.js.map +1 -1
- package/lib-es/getTransactionStatus.js +14 -18
- package/lib-es/getTransactionStatus.js.map +1 -1
- package/lib-es/hw-getAddress.js +6 -15
- package/lib-es/hw-getAddress.js.map +1 -1
- package/lib-es/hw-signMessage.js +3 -12
- package/lib-es/hw-signMessage.js.map +1 -1
- package/lib-es/prepareTransaction.js +5 -15
- package/lib-es/prepareTransaction.js.map +1 -1
- package/lib-es/signOperation.js +23 -35
- package/lib-es/signOperation.js.map +1 -1
- package/lib-es/specs.js +12 -18
- package/lib-es/specs.js.map +1 -1
- package/lib-es/synchronisation.js +46 -55
- package/lib-es/synchronisation.js.map +1 -1
- package/lib-es/transaction.js +13 -2
- package/lib-es/transaction.js.map +1 -1
- package/lib-es/utils.js +11 -20
- package/lib-es/utils.js.map +1 -1
- package/package.json +4 -4
- package/tsconfig.json +0 -1
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { AmountRequired, InvalidAddress, InvalidAddressBecauseDestinationIsAlsoSource, NotEnoughBalance, RecipientRequired, } from "@ledgerhq/errors";
|
|
11
2
|
import BigNumber from "bignumber.js";
|
|
12
3
|
import { TonCommentInvalid, TonExcessFee } from "../../errors";
|
|
@@ -14,81 +5,100 @@ import getTransactionStatus from "../../getTransactionStatus";
|
|
|
14
5
|
import { account, transaction as baseTransaction, jettonTransaction, } from "../fixtures/common.fixtures";
|
|
15
6
|
describe("getTransactionStatus", () => {
|
|
16
7
|
describe("Recipient", () => {
|
|
17
|
-
it("should detect the missing recipient and have an error", () =>
|
|
18
|
-
const transaction =
|
|
19
|
-
const res =
|
|
8
|
+
it("should detect the missing recipient and have an error", async () => {
|
|
9
|
+
const transaction = { ...baseTransaction, recipient: "" };
|
|
10
|
+
const res = await getTransactionStatus(account, transaction);
|
|
20
11
|
expect(res.errors).toEqual(expect.objectContaining({
|
|
21
12
|
recipient: new RecipientRequired(),
|
|
22
13
|
}));
|
|
23
|
-
})
|
|
24
|
-
it("should detect the incorrect recipient and have an error", () =>
|
|
25
|
-
const transaction =
|
|
26
|
-
const res =
|
|
14
|
+
});
|
|
15
|
+
it("should detect the incorrect recipient and have an error", async () => {
|
|
16
|
+
const transaction = { ...baseTransaction, recipient: "isInvalid" };
|
|
17
|
+
const res = await getTransactionStatus(account, transaction);
|
|
27
18
|
expect(res.errors).toEqual(expect.objectContaining({
|
|
28
19
|
recipient: new InvalidAddress("", {
|
|
29
20
|
currencyName: account.currency.name,
|
|
30
21
|
}),
|
|
31
22
|
}));
|
|
32
|
-
})
|
|
33
|
-
it("should detect the recipient and the sender are the same and have an error", () =>
|
|
34
|
-
const transaction =
|
|
35
|
-
|
|
23
|
+
});
|
|
24
|
+
it("should detect the recipient and the sender are the same and have an error", async () => {
|
|
25
|
+
const transaction = {
|
|
26
|
+
...baseTransaction,
|
|
27
|
+
recipient: "UQDzd8aeBOU-jqYw_ZSuZjceI5p-F4b7HMprAsUJAtRPbMol",
|
|
28
|
+
};
|
|
29
|
+
const res = await getTransactionStatus(account, transaction);
|
|
36
30
|
expect(res.errors).toEqual(expect.objectContaining({
|
|
37
31
|
recipient: new InvalidAddressBecauseDestinationIsAlsoSource("", {
|
|
38
32
|
currencyName: account.currency.name,
|
|
39
33
|
}),
|
|
40
34
|
}));
|
|
41
|
-
})
|
|
35
|
+
});
|
|
42
36
|
});
|
|
43
37
|
describe("Sender", () => {
|
|
44
|
-
it("should detect the sender is not correct and have an error", () =>
|
|
45
|
-
const tempAccount =
|
|
46
|
-
const res =
|
|
38
|
+
it("should detect the sender is not correct and have an error", async () => {
|
|
39
|
+
const tempAccount = { ...account, freshAddress: "isInvalid" };
|
|
40
|
+
const res = await getTransactionStatus(tempAccount, baseTransaction);
|
|
47
41
|
expect(res.errors).toEqual(expect.objectContaining({
|
|
48
42
|
sender: new InvalidAddress(),
|
|
49
43
|
}));
|
|
50
|
-
})
|
|
44
|
+
});
|
|
51
45
|
});
|
|
52
46
|
describe("Amount", () => {
|
|
53
|
-
it("should detect the amount is missing and have an error", () =>
|
|
54
|
-
const transaction =
|
|
55
|
-
const res =
|
|
47
|
+
it("should detect the amount is missing and have an error", async () => {
|
|
48
|
+
const transaction = { ...baseTransaction, amount: new BigNumber(0) };
|
|
49
|
+
const res = await getTransactionStatus(account, transaction);
|
|
56
50
|
expect(res.errors).toEqual(expect.objectContaining({
|
|
57
51
|
amount: new AmountRequired(),
|
|
58
52
|
}));
|
|
59
|
-
})
|
|
60
|
-
it("should detect the amount is greater than the spendable amount and have an error", () =>
|
|
61
|
-
const transaction =
|
|
62
|
-
|
|
53
|
+
});
|
|
54
|
+
it("should detect the amount is greater than the spendable amount and have an error", async () => {
|
|
55
|
+
const transaction = {
|
|
56
|
+
...baseTransaction,
|
|
57
|
+
amount: BigNumber(1000000002),
|
|
58
|
+
fees: new BigNumber("20"),
|
|
59
|
+
};
|
|
60
|
+
const res = await getTransactionStatus(account, transaction);
|
|
63
61
|
expect(res.errors).toEqual(expect.objectContaining({
|
|
64
62
|
amount: new NotEnoughBalance(),
|
|
65
63
|
}));
|
|
66
|
-
})
|
|
67
|
-
it("should detect the amount is greater than the spendable amount of the token account and have an error", () =>
|
|
68
|
-
const transaction =
|
|
69
|
-
|
|
64
|
+
});
|
|
65
|
+
it("should detect the amount is greater than the spendable amount of the token account and have an error", async () => {
|
|
66
|
+
const transaction = {
|
|
67
|
+
...jettonTransaction,
|
|
68
|
+
amount: BigNumber(1000000002),
|
|
69
|
+
fees: new BigNumber("20"),
|
|
70
|
+
};
|
|
71
|
+
const res = await getTransactionStatus(account, transaction);
|
|
70
72
|
expect(res.errors).toEqual(expect.objectContaining({
|
|
71
73
|
amount: new NotEnoughBalance(),
|
|
72
74
|
}));
|
|
73
|
-
})
|
|
74
|
-
it("should detect the transaction is a jetton transfer and have a warning", () =>
|
|
75
|
-
const transaction =
|
|
76
|
-
|
|
75
|
+
});
|
|
76
|
+
it("should detect the transaction is a jetton transfer and have a warning", async () => {
|
|
77
|
+
const transaction = {
|
|
78
|
+
...jettonTransaction,
|
|
79
|
+
amount: BigNumber(1000000002),
|
|
80
|
+
fees: new BigNumber("20"),
|
|
81
|
+
};
|
|
82
|
+
const res = await getTransactionStatus(account, transaction);
|
|
77
83
|
expect(res.warnings).toEqual(expect.objectContaining({
|
|
78
84
|
amount: new TonExcessFee(),
|
|
79
85
|
}));
|
|
80
|
-
})
|
|
86
|
+
});
|
|
81
87
|
describe("Comment", () => {
|
|
82
|
-
it("should detect the comment is not valid and have an error", () =>
|
|
83
|
-
const transaction =
|
|
84
|
-
|
|
88
|
+
it("should detect the comment is not valid and have an error", async () => {
|
|
89
|
+
const transaction = {
|
|
90
|
+
...baseTransaction,
|
|
91
|
+
amount: new BigNumber("1"),
|
|
92
|
+
comment: { isEncrypted: false, text: "comment\nInvalid" },
|
|
93
|
+
};
|
|
94
|
+
const res = await getTransactionStatus(account, transaction);
|
|
85
95
|
expect(res.errors).toEqual(expect.objectContaining({
|
|
86
96
|
transaction: new TonCommentInvalid(),
|
|
87
97
|
}));
|
|
88
|
-
})
|
|
98
|
+
});
|
|
89
99
|
});
|
|
90
100
|
describe("Successful transaction", () => {
|
|
91
|
-
it("should not have errors", () =>
|
|
101
|
+
it("should not have errors", async () => {
|
|
92
102
|
const successfulResult = {
|
|
93
103
|
amount: baseTransaction.amount,
|
|
94
104
|
errors: {},
|
|
@@ -96,9 +106,9 @@ describe("getTransactionStatus", () => {
|
|
|
96
106
|
estimatedFees: baseTransaction.fees,
|
|
97
107
|
totalSpent: baseTransaction.amount.plus(baseTransaction.fees),
|
|
98
108
|
};
|
|
99
|
-
const res =
|
|
109
|
+
const res = await getTransactionStatus(account, baseTransaction);
|
|
100
110
|
expect(res).toEqual(successfulResult);
|
|
101
|
-
})
|
|
111
|
+
});
|
|
102
112
|
});
|
|
103
113
|
});
|
|
104
114
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getTransactionStatus.unit.test.js","sourceRoot":"","sources":["../../../src/__tests__/unit/getTransactionStatus.unit.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getTransactionStatus.unit.test.js","sourceRoot":"","sources":["../../../src/__tests__/unit/getTransactionStatus.unit.test.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,cAAc,EACd,4CAA4C,EAC5C,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,oBAAoB,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EACL,OAAO,EACP,WAAW,IAAI,eAAe,EAC9B,iBAAiB,GAClB,MAAM,6BAA6B,CAAC;AAErC,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;QACzB,EAAE,CAAC,uDAAuD,EAAE,KAAK,IAAI,EAAE;YACrE,MAAM,WAAW,GAAG,EAAE,GAAG,eAAe,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;YAC1D,MAAM,GAAG,GAAG,MAAM,oBAAoB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;YAC7D,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,OAAO,CACxB,MAAM,CAAC,gBAAgB,CAAC;gBACtB,SAAS,EAAE,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AW,EAAE,IAAI,iBAAiB,EAAE;iBACrC,CAAC,CACH,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;YACtC,EAAE,CAAC,wBAAwB,EAAE,KAAK,IAAI,EAAE;gBACtC,MAAM,gBAAgB,GAAG;oBACvB,MAAM,EAAE,eAAe,CAAC,MAAM;oBAC9B,MAAM,EAAE,EAAE;oBACV,QAAQ,EAAE,EAAE;oBACZ,aAAa,EAAE,eAAe,CAAC,IAAI;oBACnC,UAAU,EAAE,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC;iBAC9D,CAAC;gBACF,MAAM,GAAG,GAAG,MAAM,oBAAoB,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;gBACjE,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;YACxC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,28 +1,15 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
|
|
11
2
|
import resolver from "../../hw-getAddress";
|
|
12
3
|
import { getLedgerTonPath } from "../../utils";
|
|
13
4
|
const address = "0xc3f95102d5c8f2c83e49ce3acfb905edfb7f37de";
|
|
14
5
|
const publicKey = "mockedPublicKey";
|
|
15
|
-
const spyGetAddress = jest.fn().mockImplementation(() =>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
address: address.toLowerCase(),
|
|
19
|
-
});
|
|
6
|
+
const spyGetAddress = jest.fn().mockImplementation(async () => Promise.resolve({
|
|
7
|
+
publicKey,
|
|
8
|
+
address: address.toLowerCase(),
|
|
20
9
|
}));
|
|
21
|
-
const spyValidateAddress = jest.fn().mockImplementation(() =>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
address: address.toLowerCase(),
|
|
25
|
-
});
|
|
10
|
+
const spyValidateAddress = jest.fn().mockImplementation(async () => Promise.resolve({
|
|
11
|
+
publicKey,
|
|
12
|
+
address: address.toLowerCase(),
|
|
26
13
|
}));
|
|
27
14
|
const mockSignerFactory = (_, fn) => fn({
|
|
28
15
|
getAddress: spyGetAddress,
|
|
@@ -30,9 +17,9 @@ const mockSignerFactory = (_, fn) => fn({
|
|
|
30
17
|
signTransaction: jest.fn(),
|
|
31
18
|
});
|
|
32
19
|
describe("hw-getAddress", () => {
|
|
33
|
-
it("should return an encoded address and a public key when verifiy is false", () =>
|
|
20
|
+
it("should return an encoded address and a public key when verifiy is false", async () => {
|
|
34
21
|
const getAddress = resolver(mockSignerFactory);
|
|
35
|
-
const response =
|
|
22
|
+
const response = await getAddress("deviceId", {
|
|
36
23
|
path: "44'/607'/0'/0'/0'/0'",
|
|
37
24
|
verify: false,
|
|
38
25
|
currency: getCryptoCurrencyById("ton"),
|
|
@@ -43,10 +30,10 @@ describe("hw-getAddress", () => {
|
|
|
43
30
|
expect(spyGetAddress).toHaveBeenCalledWith(getLedgerTonPath("44'/607'/0'/0'/0'/0'"), {
|
|
44
31
|
bounceable: false,
|
|
45
32
|
});
|
|
46
|
-
})
|
|
47
|
-
it("should return an encoded address and a public key when verifiy is true", () =>
|
|
33
|
+
});
|
|
34
|
+
it("should return an encoded address and a public key when verifiy is true", async () => {
|
|
48
35
|
const getAddress = resolver(mockSignerFactory);
|
|
49
|
-
const response =
|
|
36
|
+
const response = await getAddress("deviceId", {
|
|
50
37
|
path: "44'/607'/0'/0'/0'/0'",
|
|
51
38
|
verify: true,
|
|
52
39
|
currency: getCryptoCurrencyById("ton"),
|
|
@@ -57,6 +44,6 @@ describe("hw-getAddress", () => {
|
|
|
57
44
|
expect(spyValidateAddress).toHaveBeenCalledWith(getLedgerTonPath("44'/607'/0'/0'/0'/0'"), {
|
|
58
45
|
bounceable: false,
|
|
59
46
|
});
|
|
60
|
-
})
|
|
47
|
+
});
|
|
61
48
|
});
|
|
62
49
|
//# sourceMappingURL=hw-getAddress.unit.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hw-getAddress.unit.test.js","sourceRoot":"","sources":["../../../src/__tests__/unit/hw-getAddress.unit.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hw-getAddress.unit.test.js","sourceRoot":"","sources":["../../../src/__tests__/unit/hw-getAddress.unit.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,QAAQ,MAAM,qBAAqB,CAAC;AAE3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,OAAO,GAAG,4CAA4C,CAAC;AAC7D,MAAM,SAAS,GAAG,iBAAiB,CAAC;AACpC,MAAM,aAAa,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,IAAI,EAAE,CAC5D,OAAO,CAAC,OAAO,CAAC;IACd,SAAS;IACT,OAAO,EAAE,OAAO,CAAC,WAAW,EAAE;CAC/B,CAAC,CACH,CAAC;AACF,MAAM,kBAAkB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,IAAI,EAAE,CACjE,OAAO,CAAC,O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CAAC,CAAC;QACH,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC3C,MAAM,CAAC,kBAAkB,CAAC,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,sBAAsB,CAAC,EAAE;YACxF,UAAU,EAAE,KAAK;SAClB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { estimateFee, fetchAccountInfo } from "../../bridge/bridgeHelpers/api";
|
|
11
2
|
import prepareTransaction from "../../prepareTransaction";
|
|
12
3
|
import { account, accountInfo, transaction as baseTransaction, fees, jettonTransaction, totalFees, } from "../fixtures/common.fixtures";
|
|
@@ -19,35 +10,56 @@ describe("prepareTransaction", () => {
|
|
|
19
10
|
fetchEstimateFeeMock.mockReturnValue(Promise.resolve(fees));
|
|
20
11
|
});
|
|
21
12
|
describe("Ton Transaction", () => {
|
|
22
|
-
it("should return the transaction with the updated amount and fees", () =>
|
|
23
|
-
const transaction =
|
|
24
|
-
expect(transaction).toEqual(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
13
|
+
it("should return the transaction with the updated amount and fees", async () => {
|
|
14
|
+
const transaction = await prepareTransaction(account, baseTransaction);
|
|
15
|
+
expect(transaction).toEqual({
|
|
16
|
+
...baseTransaction,
|
|
17
|
+
fees: totalFees,
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
it("should preserve the reference when no change is detected on the transaction", async () => {
|
|
21
|
+
const transaction = await prepareTransaction(account, { ...baseTransaction });
|
|
22
|
+
const transaction2 = await prepareTransaction(account, transaction);
|
|
29
23
|
expect(transaction).toBe(transaction2);
|
|
30
|
-
})
|
|
31
|
-
it("should create a coin transaction using the spendableBalance in the account", () =>
|
|
32
|
-
const transaction =
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
});
|
|
25
|
+
it("should create a coin transaction using the spendableBalance in the account", async () => {
|
|
26
|
+
const transaction = await prepareTransaction(account, {
|
|
27
|
+
...baseTransaction,
|
|
28
|
+
useAllAmount: true,
|
|
29
|
+
});
|
|
30
|
+
expect(transaction).toEqual({
|
|
31
|
+
...baseTransaction,
|
|
32
|
+
useAllAmount: true,
|
|
33
|
+
fees: totalFees,
|
|
34
|
+
amount: account.spendableBalance.minus(totalFees),
|
|
35
|
+
});
|
|
36
|
+
});
|
|
35
37
|
});
|
|
36
38
|
describe("Jetton Transaction", () => {
|
|
37
|
-
it("should return the transaction with the updated amount and fees", () =>
|
|
38
|
-
const transaction =
|
|
39
|
-
expect(transaction).toEqual(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
it("should return the transaction with the updated amount and fees", async () => {
|
|
40
|
+
const transaction = await prepareTransaction(account, jettonTransaction);
|
|
41
|
+
expect(transaction).toEqual({
|
|
42
|
+
...jettonTransaction,
|
|
43
|
+
fees: totalFees,
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
it("should preserve the reference when no change is detected on the transaction", async () => {
|
|
47
|
+
const transaction = await prepareTransaction(account, { ...jettonTransaction });
|
|
48
|
+
const transaction2 = await prepareTransaction(account, transaction);
|
|
44
49
|
expect(transaction).toBe(transaction2);
|
|
45
|
-
})
|
|
46
|
-
it("should create a coin transaction using the spendableBalance in the account", () =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
});
|
|
51
|
+
it("should create a coin transaction using the spendableBalance in the account", async () => {
|
|
52
|
+
const transaction = await prepareTransaction(account, {
|
|
53
|
+
...jettonTransaction,
|
|
54
|
+
useAllAmount: true,
|
|
55
|
+
});
|
|
56
|
+
expect(transaction).toEqual({
|
|
57
|
+
...jettonTransaction,
|
|
58
|
+
useAllAmount: true,
|
|
59
|
+
fees: totalFees,
|
|
60
|
+
amount: account.subAccounts?.[0].spendableBalance,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
51
63
|
});
|
|
52
64
|
});
|
|
53
65
|
//# sourceMappingURL=prepareTransaction.unit.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareTransaction.unit.test.js","sourceRoot":"","sources":["../../../src/__tests__/unit/prepareTransaction.unit.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prepareTransaction.unit.test.js","sourceRoot":"","sources":["../../../src/__tests__/unit/prepareTransaction.unit.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,kBAAkB,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EACL,OAAO,EACP,WAAW,EACX,WAAW,IAAI,eAAe,EAC9B,IAAI,EACJ,iBAAiB,EACjB,SAAS,GACV,MAAM,6BAA6B,CAAC;AAErC,IAAI,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;AAE5C,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,oBAAoB,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAC3D,oBAAo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-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { Address, Cell, beginCell, storeMessage } from "@ton/core";
|
|
11
2
|
import BigNumber from "bignumber.js";
|
|
12
3
|
import { fetchAccountInfo } from "../../bridge/bridgeHelpers/api";
|
|
13
4
|
import { buildSignOperation } from "../../signOperation";
|
|
14
5
|
import { account, accountInfo, totalFees, transaction } from "../fixtures/common.fixtures";
|
|
15
6
|
jest.mock("../../bridge/bridgeHelpers/api");
|
|
16
|
-
const spySignTransaction = jest.fn().mockImplementation(() =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.endCell());
|
|
27
|
-
}));
|
|
7
|
+
const spySignTransaction = jest.fn().mockImplementation(async () => Promise.resolve(beginCell()
|
|
8
|
+
.store(storeMessage({
|
|
9
|
+
info: {
|
|
10
|
+
type: "external-in",
|
|
11
|
+
dest: Address.parse("EQDzd8aeBOU-jqYw_ZSuZjceI5p-F4b7HMprAsUJAtRPbJfg"),
|
|
12
|
+
importFee: BigInt(0),
|
|
13
|
+
},
|
|
14
|
+
body: new Cell(),
|
|
15
|
+
}))
|
|
16
|
+
.endCell()));
|
|
28
17
|
const mockSignerContext = (_, fn) => {
|
|
29
18
|
return fn({
|
|
30
19
|
signTransaction: spySignTransaction,
|
|
@@ -41,7 +30,7 @@ describe("signOperation", () => {
|
|
|
41
30
|
const signOperation = buildSignOperation(mockSignerContext);
|
|
42
31
|
const signOpObservable = signOperation({
|
|
43
32
|
account,
|
|
44
|
-
transaction:
|
|
33
|
+
transaction: { ...transaction, fees: totalFees },
|
|
45
34
|
deviceId: "",
|
|
46
35
|
});
|
|
47
36
|
signOpObservable.subscribe(obs => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signOperation.unit.test.js","sourceRoot":"","sources":["../../../src/__tests__/unit/signOperation.unit.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"signOperation.unit.test.js","sourceRoot":"","sources":["../../../src/__tests__/unit/signOperation.unit.test.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE3F,IAAI,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;AAE5C,MAAM,kBAAkB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,IAAI,EAAE,CACjE,OAAO,CAAC,OAAO,CACb,SAAS,EAAE;KACR,KAAK,CACJ,YAAY,CAAC;IACX,IAAI,EAAE;QACJ,IAAI,EAAE,aAAa;QACnB,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,kDAAkD,CAAC;QACvE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;KACrB;IACD,IAAI,EAAE,IAAI,IAAI,EAAE;CACjB,CAAC,CACH;KACA,OAAO,EAAE,CACb,CACF,CAAC;AAEF,MAAM,iBAAiB,GAA6B,CAClD,CAAS,EACT,EAAqC,EACrC,EAAE;IACF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O,CAAC,YAAY,CAAC;oBAC/B,UAAU,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC;oBACnC,SAAS,EAAE,OAAO,CAAC,EAAE;oBACrB,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;oBACtB,KAAK,EAAE;wBACL,OAAO,EAAE;4BACP,WAAW,EAAE,KAAK;4BAClB,IAAI,EAAE,EAAE;yBACT;wBACD,YAAY,EAAE,EAAE;wBAChB,EAAE,EAAE,EAAE;qBACP;iBACF,CAAC,CAAC;gBACH,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CACpB,sHAAsH,CACvH,CAAC;gBACF,IAAI,EAAE,CAAC;YACT,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { encodeOperationId } from "@ledgerhq/coin-framework/lib/operation";
|
|
11
2
|
import BigNumber from "bignumber.js";
|
|
12
3
|
// eslint-disable-next-line no-restricted-imports
|
|
@@ -15,8 +6,7 @@ import { mapJettonTxToOps, mapTxToOps } from "../../bridge/bridgeHelpers/txn";
|
|
|
15
6
|
import { jettonTransferResponse, mockAccountId, mockAddress, tonTransactionResponse, } from "../fixtures/common.fixtures";
|
|
16
7
|
describe("Transaction functions", () => {
|
|
17
8
|
describe("mapTxToOps", () => {
|
|
18
|
-
it.skip("should map an IN ton transaction without total_fees to a ledger operation", () =>
|
|
19
|
-
var _a, _b;
|
|
9
|
+
it.skip("should map an IN ton transaction without total_fees to a ledger operation", async () => {
|
|
20
10
|
const { now, lt, hash, in_msg, total_fees, mc_block_seqno } = tonTransactionResponse.transactions[0];
|
|
21
11
|
const finalOperation = flatMap(tonTransactionResponse.transactions, mapTxToOps(mockAccountId, mockAddress, tonTransactionResponse.address_book));
|
|
22
12
|
expect(finalOperation).toEqual([
|
|
@@ -28,24 +18,23 @@ describe("Transaction functions", () => {
|
|
|
28
18
|
extra: { comment: { isEncrypted: false, text: "" }, explorerHash: hash, lt },
|
|
29
19
|
fee: BigNumber(total_fees),
|
|
30
20
|
hasFailed: false,
|
|
31
|
-
hash: in_msg
|
|
32
|
-
id: encodeOperationId(mockAccountId,
|
|
33
|
-
recipients: [in_msg
|
|
21
|
+
hash: in_msg?.hash,
|
|
22
|
+
id: encodeOperationId(mockAccountId, in_msg?.hash ?? "", "IN"),
|
|
23
|
+
recipients: [in_msg?.destination],
|
|
34
24
|
senders: ["EQCVnqqL0OOiZi2BQnjVGm-ZeUYgfUhHgAi-vn9F8-94HwrH"],
|
|
35
25
|
type: "IN",
|
|
36
|
-
value: BigNumber(
|
|
26
|
+
value: BigNumber(in_msg?.value ?? 0),
|
|
37
27
|
},
|
|
38
28
|
]);
|
|
39
|
-
})
|
|
40
|
-
it.skip("should map an IN ton transaction with total_fees to a ledger operation", () =>
|
|
41
|
-
|
|
42
|
-
const transactions = [Object.assign(Object.assign({}, tonTransactionResponse.transactions[0]), { total_fees: "15" })];
|
|
29
|
+
});
|
|
30
|
+
it.skip("should map an IN ton transaction with total_fees to a ledger operation", async () => {
|
|
31
|
+
const transactions = [{ ...tonTransactionResponse.transactions[0], total_fees: "15" }];
|
|
43
32
|
const { now, lt, hash, in_msg, total_fees, mc_block_seqno, account } = transactions[0];
|
|
44
33
|
const finalOperation = flatMap(transactions, mapTxToOps(mockAccountId, mockAddress, tonTransactionResponse.address_book));
|
|
45
34
|
expect(finalOperation).toEqual([
|
|
46
35
|
{
|
|
47
|
-
id: encodeOperationId(mockAccountId,
|
|
48
|
-
hash: in_msg
|
|
36
|
+
id: encodeOperationId(mockAccountId, in_msg?.hash ?? "", "NONE"),
|
|
37
|
+
hash: in_msg?.hash,
|
|
49
38
|
type: "NONE",
|
|
50
39
|
value: BigNumber(total_fees),
|
|
51
40
|
fee: BigNumber(0),
|
|
@@ -66,34 +55,36 @@ describe("Transaction functions", () => {
|
|
|
66
55
|
extra: { comment: { isEncrypted: false, text: "" }, explorerHash: hash, lt },
|
|
67
56
|
fee: BigNumber(total_fees),
|
|
68
57
|
hasFailed: false,
|
|
69
|
-
hash: in_msg
|
|
70
|
-
id: encodeOperationId(mockAccountId,
|
|
71
|
-
recipients: [in_msg
|
|
58
|
+
hash: in_msg?.hash,
|
|
59
|
+
id: encodeOperationId(mockAccountId, in_msg?.hash ?? "", "IN"),
|
|
60
|
+
recipients: [in_msg?.destination],
|
|
72
61
|
senders: ["EQCVnqqL0OOiZi2BQnjVGm-ZeUYgfUhHgAi-vn9F8-94HwrH"],
|
|
73
62
|
type: "IN",
|
|
74
|
-
value: BigNumber(
|
|
63
|
+
value: BigNumber(in_msg?.value ?? 0),
|
|
75
64
|
},
|
|
76
65
|
]);
|
|
77
|
-
})
|
|
78
|
-
it.skip("should map an OUT ton transaction to a ledger operation", () =>
|
|
79
|
-
var _f;
|
|
66
|
+
});
|
|
67
|
+
it.skip("should map an OUT ton transaction to a ledger operation", async () => {
|
|
80
68
|
// The IN transaction will be used as OUT transaction and it will be adjusted
|
|
81
69
|
const transactions = [
|
|
82
|
-
|
|
70
|
+
{
|
|
71
|
+
...tonTransactionResponse.transactions[0],
|
|
72
|
+
in_msg: null,
|
|
73
|
+
},
|
|
83
74
|
];
|
|
84
75
|
if (tonTransactionResponse.transactions[0].in_msg) {
|
|
85
76
|
transactions[0].out_msgs = [
|
|
86
|
-
|
|
77
|
+
{ ...tonTransactionResponse.transactions[0].in_msg, source: transactions[0].account },
|
|
87
78
|
];
|
|
88
79
|
}
|
|
89
80
|
const { now, lt, hash, out_msgs, total_fees, mc_block_seqno, account } = transactions[0];
|
|
90
81
|
const finalOperation = flatMap(transactions, mapTxToOps(mockAccountId, mockAddress, tonTransactionResponse.address_book));
|
|
91
82
|
expect(finalOperation).toEqual([
|
|
92
83
|
{
|
|
93
|
-
id: encodeOperationId(mockAccountId, hash
|
|
94
|
-
hash: out_msgs
|
|
84
|
+
id: encodeOperationId(mockAccountId, hash ?? "", "OUT"),
|
|
85
|
+
hash: out_msgs?.[0].hash,
|
|
95
86
|
type: "OUT",
|
|
96
|
-
value: BigNumber(
|
|
87
|
+
value: BigNumber(out_msgs[0].value ?? 0).plus(BigNumber(total_fees)),
|
|
97
88
|
fee: BigNumber(total_fees),
|
|
98
89
|
blockHeight: mc_block_seqno,
|
|
99
90
|
blockHash: null,
|
|
@@ -105,10 +96,10 @@ describe("Transaction functions", () => {
|
|
|
105
96
|
extra: { comment: { isEncrypted: false, text: "" }, explorerHash: hash, lt },
|
|
106
97
|
},
|
|
107
98
|
]);
|
|
108
|
-
})
|
|
99
|
+
});
|
|
109
100
|
});
|
|
110
101
|
describe("mapJettonToOps", () => {
|
|
111
|
-
it("should map an IN ton transaction without total_fees to a ledger operation", () =>
|
|
102
|
+
it("should map an IN ton transaction without total_fees to a ledger operation", async () => {
|
|
112
103
|
const { transaction_hash, amount, transaction_now, transaction_lt } = jettonTransferResponse.jetton_transfers[0];
|
|
113
104
|
const finalOperation = flatMap(jettonTransferResponse.jetton_transfers, mapJettonTxToOps(mockAccountId, mockAddress, tonTransactionResponse.address_book));
|
|
114
105
|
const tokenByCurrencyAddress = `${mockAccountId}+ton%2Fjetton%2Feqavlwfdxgf2lxm67y4yzc17wykd9a0guwpkms1gosm~!underscore!~~!underscore!~not`;
|
|
@@ -133,11 +124,13 @@ describe("Transaction functions", () => {
|
|
|
133
124
|
},
|
|
134
125
|
},
|
|
135
126
|
]);
|
|
136
|
-
})
|
|
137
|
-
it("should map an OUT jetton transaction to a ledger operation", () =>
|
|
127
|
+
});
|
|
128
|
+
it("should map an OUT jetton transaction to a ledger operation", async () => {
|
|
138
129
|
// The IN jetton transaction will be used as OUT transaction and it will be adjusted
|
|
139
130
|
const jettonTransfers = [
|
|
140
|
-
|
|
131
|
+
{
|
|
132
|
+
...jettonTransferResponse.jetton_transfers[0],
|
|
133
|
+
},
|
|
141
134
|
];
|
|
142
135
|
jettonTransfers[0].source = jettonTransfers[0].destination;
|
|
143
136
|
jettonTransfers[0].destination = jettonTransferResponse.jetton_transfers[0].source;
|
|
@@ -165,7 +158,7 @@ describe("Transaction functions", () => {
|
|
|
165
158
|
},
|
|
166
159
|
},
|
|
167
160
|
]);
|
|
168
|
-
})
|
|
161
|
+
});
|
|
169
162
|
});
|
|
170
163
|
});
|
|
171
164
|
//# sourceMappingURL=txn.unit.test.js.map
|