@ledgerhq/coin-xrp 3.1.0-nightly.3 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +13 -27
- package/jest.config.js +0 -1
- package/lib/api/index.integ.test.js +37 -69
- package/lib/api/index.integ.test.js.map +1 -1
- package/lib/api/index.js +3 -7
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +4 -60
- package/lib/api/index.test.js.map +1 -1
- package/lib/logic/estimateFees.js +1 -1
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib-es/api/index.integ.test.js +37 -69
- package/lib-es/api/index.integ.test.js.map +1 -1
- package/lib-es/api/index.js +3 -7
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +4 -37
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/logic/estimateFees.js +1 -1
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/package.json +6 -8
- package/src/api/index.integ.test.ts +27 -59
- package/src/api/index.test.ts +6 -53
- package/src/api/index.ts +3 -10
- package/src/logic/estimateFees.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
> @ledgerhq/coin-xrp@3.1.0
|
|
2
|
+
> @ledgerhq/coin-xrp@3.1.0 build /home/runner/work/ledger-live/ledger-live/libs/coin-modules/coin-xrp
|
|
3
3
|
> tsc && tsc -m esnext --moduleResolution bundler --outDir lib-es
|
|
4
4
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,37 +1,20 @@
|
|
|
1
1
|
# @ledgerhq/coin-xrp
|
|
2
2
|
|
|
3
|
-
## 3.1.0
|
|
3
|
+
## 3.1.0
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
-
- [#
|
|
8
|
-
|
|
9
|
-
- [#9648](https://github.com/LedgerHQ/ledger-live/pull/9648) [`f1732a7`](https://github.com/LedgerHQ/ledger-live/commit/f1732a795e54f666b67e7686d59926037412caca) Thanks [@sprohaszka-ledger](https://github.com/sprohaszka-ledger)! - Remove SubAccount as it is an alias to TokenAccount
|
|
10
|
-
|
|
11
|
-
### Patch Changes
|
|
12
|
-
|
|
13
|
-
- Updated dependencies [[`44ae74c`](https://github.com/LedgerHQ/ledger-live/commit/44ae74c272ba803bed7c9f4fc3351e3ce8a15531), [`8ce7b0a`](https://github.com/LedgerHQ/ledger-live/commit/8ce7b0ab2d1d73ef071102f795e7c868c676b1f4), [`f1732a7`](https://github.com/LedgerHQ/ledger-live/commit/f1732a795e54f666b67e7686d59926037412caca)]:
|
|
14
|
-
- @ledgerhq/coin-framework@2.5.0-nightly.3
|
|
15
|
-
- @ledgerhq/types-live@6.65.0-nightly.1
|
|
16
|
-
|
|
17
|
-
## 3.1.0-nightly.2
|
|
18
|
-
|
|
19
|
-
### Patch Changes
|
|
20
|
-
|
|
21
|
-
- Updated dependencies [[`1e7d454`](https://github.com/LedgerHQ/ledger-live/commit/1e7d454d99f1f39880f39a120c59020725d26475), [`d694069`](https://github.com/LedgerHQ/ledger-live/commit/d6940698a49b7a0ed48f84d6e8184d80760cca4f)]:
|
|
22
|
-
- @ledgerhq/coin-framework@2.5.0-nightly.2
|
|
23
|
-
- @ledgerhq/types-live@6.65.0-nightly.0
|
|
24
|
-
- @ledgerhq/cryptoassets@13.14.0-nightly.2
|
|
25
|
-
- @ledgerhq/live-network@2.0.6-nightly.1
|
|
26
|
-
|
|
27
|
-
## 3.1.0-nightly.1
|
|
7
|
+
- [#9298](https://github.com/LedgerHQ/ledger-live/pull/9298) [`2785d49`](https://github.com/LedgerHQ/ledger-live/commit/2785d49ac320498f98ed39b4eccc48310ad35fe1) Thanks [@Canestin](https://github.com/Canestin)! - config coin-integration env for sonarqube
|
|
28
8
|
|
|
29
9
|
### Patch Changes
|
|
30
10
|
|
|
31
|
-
- Updated dependencies [[`
|
|
32
|
-
- @ledgerhq/coin-framework@2.5.0
|
|
11
|
+
- Updated dependencies [[`2785d49`](https://github.com/LedgerHQ/ledger-live/commit/2785d49ac320498f98ed39b4eccc48310ad35fe1), [`2effe04`](https://github.com/LedgerHQ/ledger-live/commit/2effe04d9d4b3e407ed25da3b9f11324a82126d3), [`2407a6e`](https://github.com/LedgerHQ/ledger-live/commit/2407a6e1f3153c30c52d4bac4c9334fa95c351da), [`40e98c3`](https://github.com/LedgerHQ/ledger-live/commit/40e98c392bd9192570e46c2d62cf0779bdfe01ec), [`a656e47`](https://github.com/LedgerHQ/ledger-live/commit/a656e47c1dc3ac8b578debf9cf80eab370c7086f)]:
|
|
12
|
+
- @ledgerhq/coin-framework@2.5.0
|
|
13
|
+
- @ledgerhq/types-live@6.65.0
|
|
14
|
+
- @ledgerhq/cryptoassets@13.14.0
|
|
15
|
+
- @ledgerhq/live-network@2.0.6
|
|
33
16
|
|
|
34
|
-
## 3.1.0-
|
|
17
|
+
## 3.1.0-next.0
|
|
35
18
|
|
|
36
19
|
### Minor Changes
|
|
37
20
|
|
|
@@ -39,8 +22,11 @@
|
|
|
39
22
|
|
|
40
23
|
### Patch Changes
|
|
41
24
|
|
|
42
|
-
- Updated dependencies [[`2785d49`](https://github.com/LedgerHQ/ledger-live/commit/2785d49ac320498f98ed39b4eccc48310ad35fe1)]:
|
|
43
|
-
- @ledgerhq/coin-framework@2.5.0-
|
|
25
|
+
- Updated dependencies [[`2785d49`](https://github.com/LedgerHQ/ledger-live/commit/2785d49ac320498f98ed39b4eccc48310ad35fe1), [`2effe04`](https://github.com/LedgerHQ/ledger-live/commit/2effe04d9d4b3e407ed25da3b9f11324a82126d3), [`2407a6e`](https://github.com/LedgerHQ/ledger-live/commit/2407a6e1f3153c30c52d4bac4c9334fa95c351da), [`40e98c3`](https://github.com/LedgerHQ/ledger-live/commit/40e98c392bd9192570e46c2d62cf0779bdfe01ec), [`a656e47`](https://github.com/LedgerHQ/ledger-live/commit/a656e47c1dc3ac8b578debf9cf80eab370c7086f)]:
|
|
26
|
+
- @ledgerhq/coin-framework@2.5.0-next.0
|
|
27
|
+
- @ledgerhq/types-live@6.65.0-next.0
|
|
28
|
+
- @ledgerhq/cryptoassets@13.14.0-next.0
|
|
29
|
+
- @ledgerhq/live-network@2.0.6-next.0
|
|
44
30
|
|
|
45
31
|
## 3.0.0
|
|
46
32
|
|
package/jest.config.js
CHANGED
|
@@ -14,7 +14,6 @@ module.exports = {
|
|
|
14
14
|
coverageReporters: ["json", ["lcov", { file: "xrp-lcov.info", projectRoot: "../" }], "text"],
|
|
15
15
|
workerThreads: true,
|
|
16
16
|
reporters: [
|
|
17
|
-
"default",
|
|
18
17
|
[
|
|
19
18
|
"jest-sonar",
|
|
20
19
|
{ outputName: "xrp-sonar-executionTests-report.xml", reportedFilePath: "absolute" },
|
|
@@ -1,20 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const ripple_binary_codec_1 = require("ripple-binary-codec");
|
|
4
3
|
const _1 = require(".");
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const ripple_binary_codec_1 = require("ripple-binary-codec");
|
|
5
|
+
const ripple_keypairs_1 = require("ripple-keypairs");
|
|
7
6
|
describe("Xrp Api", () => {
|
|
8
|
-
|
|
9
|
-
const
|
|
7
|
+
let module;
|
|
8
|
+
const address = "rh1HPuRVsYYvThxG2Bs1MfjmrVC73S16Fb";
|
|
9
|
+
const bigAddress = "rUxSkt6hQpWxXQwTNRUCYYRQ7BC2yRA3F8"; // An account with more that 4000 txs
|
|
10
|
+
const emptyAddress = "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB"; // Account with no transaction (at the time of this writing)
|
|
11
|
+
const xrpPubKey = process.env["PUB_KEY"];
|
|
12
|
+
const xrpSecretKey = process.env["SECRET_KEY"];
|
|
13
|
+
beforeAll(() => {
|
|
14
|
+
module = (0, _1.createApi)({ node: "https://s.altnet.rippletest.net:51234" });
|
|
15
|
+
});
|
|
10
16
|
describe("estimateFees", () => {
|
|
11
17
|
it("returns a default value", async () => {
|
|
12
18
|
// Given
|
|
13
19
|
const amount = BigInt(100);
|
|
14
20
|
// When
|
|
15
|
-
const result = await
|
|
21
|
+
const result = await module.estimateFees({
|
|
16
22
|
type: "send",
|
|
17
|
-
sender:
|
|
23
|
+
sender: address,
|
|
18
24
|
amount,
|
|
19
25
|
recipient: "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB",
|
|
20
26
|
});
|
|
@@ -25,21 +31,19 @@ describe("Xrp Api", () => {
|
|
|
25
31
|
describe("listOperations", () => {
|
|
26
32
|
it.skip("returns a list regarding address parameter", async () => {
|
|
27
33
|
// When
|
|
28
|
-
const [tx, _] = await
|
|
34
|
+
const [tx, _] = await module.listOperations(address, { minHeight: 200 });
|
|
29
35
|
// https://blockexplorer.one/xrp/testnet/address/rh1HPuRVsYYvThxG2Bs1MfjmrVC73S16Fb
|
|
30
36
|
// as of 2025-03-18, the address has 287 transactions
|
|
31
37
|
expect(tx.length).toBeGreaterThanOrEqual(287);
|
|
32
38
|
tx.forEach(operation => {
|
|
33
|
-
const isSenderOrReceipt = operation.senders.includes(
|
|
39
|
+
const isSenderOrReceipt = operation.senders.includes(address) || operation.recipients.includes(address);
|
|
34
40
|
expect(isSenderOrReceipt).toBeTruthy();
|
|
35
41
|
});
|
|
36
42
|
});
|
|
37
43
|
// TO FIX, ops length is 0 for some reason
|
|
38
44
|
it.skip("returns all operations", async () => {
|
|
39
|
-
// An account with more that 4000 txs
|
|
40
|
-
const SENDER_WITH_TRANSACTIONS = "rUxSkt6hQpWxXQwTNRUCYYRQ7BC2yRA3F8";
|
|
41
45
|
// When
|
|
42
|
-
const [ops, _] = await
|
|
46
|
+
const [ops, _] = await module.listOperations(bigAddress, { minHeight: 0 });
|
|
43
47
|
// Then
|
|
44
48
|
const checkSet = new Set(ops.map(elt => elt.tx.hash));
|
|
45
49
|
expect(checkSet.size).toEqual(ops.length);
|
|
@@ -54,7 +58,7 @@ describe("Xrp Api", () => {
|
|
|
54
58
|
describe("lastBlock", () => {
|
|
55
59
|
it("returns last block info", async () => {
|
|
56
60
|
// When
|
|
57
|
-
const result = await
|
|
61
|
+
const result = await module.lastBlock();
|
|
58
62
|
// Then
|
|
59
63
|
expect(result.hash).toBeDefined();
|
|
60
64
|
expect(result.height).toBeDefined();
|
|
@@ -62,83 +66,47 @@ describe("Xrp Api", () => {
|
|
|
62
66
|
});
|
|
63
67
|
});
|
|
64
68
|
describe("getBalance", () => {
|
|
65
|
-
// Account with no transaction (at the time of this writing)
|
|
66
|
-
const SENDER_WITH_NO_TRANSACTION = "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB";
|
|
67
69
|
it("returns an amount above 0 when address has transactions", async () => {
|
|
68
70
|
// When
|
|
69
|
-
const result = await
|
|
71
|
+
const result = await module.getBalance(address);
|
|
70
72
|
// Then
|
|
71
73
|
expect(result).toBeGreaterThan(BigInt(0));
|
|
72
74
|
});
|
|
73
75
|
it("returns 0 when address has no transaction", async () => {
|
|
74
76
|
// When
|
|
75
|
-
const result = await
|
|
77
|
+
const result = await module.getBalance(emptyAddress);
|
|
76
78
|
// Then
|
|
77
79
|
expect(result).toBe(BigInt(0));
|
|
78
80
|
});
|
|
79
81
|
});
|
|
80
82
|
describe("craftTransaction", () => {
|
|
81
|
-
const RECIPIENT = "rKRtUG15iBsCQRgrkeUEg5oX4Ae2zWZ89z";
|
|
82
83
|
it("returns a raw transaction", async () => {
|
|
83
84
|
// When
|
|
84
|
-
const result = await
|
|
85
|
+
const result = await module.craftTransaction({
|
|
85
86
|
type: "send",
|
|
86
|
-
sender:
|
|
87
|
-
recipient:
|
|
87
|
+
sender: address,
|
|
88
|
+
recipient: "rKRtUG15iBsCQRgrkeUEg5oX4Ae2zWZ89z",
|
|
88
89
|
amount: BigInt(10),
|
|
89
90
|
});
|
|
90
91
|
// Then
|
|
91
92
|
expect(result.length).toEqual(162);
|
|
92
93
|
});
|
|
93
|
-
it("should use default fees when user does not provide them for crafting a transaction", async () => {
|
|
94
|
-
const result = await api.craftTransaction({
|
|
95
|
-
type: "send",
|
|
96
|
-
sender: SENDER,
|
|
97
|
-
recipient: RECIPIENT,
|
|
98
|
-
amount: BigInt(10),
|
|
99
|
-
});
|
|
100
|
-
const decodedTransaction = (0, ripple_binary_codec_1.decode)(result);
|
|
101
|
-
expect(decodedTransaction.Fee).toEqual("10");
|
|
102
|
-
});
|
|
103
|
-
it("should use custom user fees when user provides it for crafting a transaction", async () => {
|
|
104
|
-
const customFees = 99n;
|
|
105
|
-
const result = await api.craftTransaction({
|
|
106
|
-
type: "send",
|
|
107
|
-
sender: SENDER,
|
|
108
|
-
recipient: RECIPIENT,
|
|
109
|
-
amount: BigInt(10),
|
|
110
|
-
}, customFees);
|
|
111
|
-
const decodedTransaction = (0, ripple_binary_codec_1.decode)(result);
|
|
112
|
-
expect(decodedTransaction.Fee).toEqual(customFees.toString());
|
|
113
|
-
});
|
|
114
94
|
});
|
|
115
|
-
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
})
|
|
130
|
-
xrpSecretKey,
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
// When
|
|
134
|
-
const result = await module.combine(rawTx, signedTx);
|
|
135
|
-
|
|
136
|
-
// Then
|
|
137
|
-
expect(result).toEqual(
|
|
138
|
-
"120000228000000024001BCDA6201B001F018161400000000000000A68400000000000000174473045022100D3B9B37F40961A8DBDE48535F9EF333E87F9D98BE90F7141E133541874826BDB0220065E9CA4D218F16087656BC30D66672F6103B03717A59FFC04C837A2157CE47C8114CF30F590D7A9067B2604D80D46090FBF342EBE988314CA26FB6B0EF6859436C2037BA0A9913208A59B98",
|
|
139
|
-
);
|
|
95
|
+
// To enable this test, you need to fill an `.env` file at the root of this package. Example can be found in `.env.integ.test.example`.
|
|
96
|
+
// The value hardcoded here depends on the value filled in the `.env` file.
|
|
97
|
+
describe.skip("combine", () => {
|
|
98
|
+
it("returns a signed raw transaction", async () => {
|
|
99
|
+
// Given
|
|
100
|
+
const rawTx = "120000228000000024001BCDA6201B001F018161400000000000000A6840000000000000018114CF30F590D7A9067B2604D80D46090FBF342EBE988314CA26FB6B0EF6859436C2037BA0A9913208A59B98";
|
|
101
|
+
const signedTx = (0, ripple_keypairs_1.sign)((0, ripple_binary_codec_1.encodeForSigning)({
|
|
102
|
+
...(0, ripple_binary_codec_1.decode)(rawTx),
|
|
103
|
+
SigningPubKey: xrpPubKey,
|
|
104
|
+
}), xrpSecretKey);
|
|
105
|
+
// When
|
|
106
|
+
const result = await module.combine(rawTx, signedTx);
|
|
107
|
+
// Then
|
|
108
|
+
expect(result).toEqual("120000228000000024001BCDA6201B001F018161400000000000000A68400000000000000174473045022100D3B9B37F40961A8DBDE48535F9EF333E87F9D98BE90F7141E133541874826BDB0220065E9CA4D218F16087656BC30D66672F6103B03717A59FFC04C837A2157CE47C8114CF30F590D7A9067B2604D80D46090FBF342EBE988314CA26FB6B0EF6859436C2037BA0A9913208A59B98");
|
|
109
|
+
});
|
|
140
110
|
});
|
|
141
|
-
});
|
|
142
111
|
});
|
|
143
|
-
*/
|
|
144
112
|
//# sourceMappingURL=index.integ.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.integ.test.js","sourceRoot":"","sources":["../../src/api/index.integ.test.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.integ.test.js","sourceRoot":"","sources":["../../src/api/index.integ.test.ts"],"names":[],"mappings":";;AACA,wBAA8B;AAC9B,6DAA+D;AAC/D,qDAAuC;AAEvC,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACvB,IAAI,MAAiB,CAAC;IACtB,MAAM,OAAO,GAAG,oCAAoC,CAAC;IACrD,MAAM,UAAU,GAAG,oC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AM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,uIAAuI;IACvI,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE;QAC5B,EAAE,CAAC,kCAAkC,EAAE,KAAK,IAAI,EAAE;YAChD,QAAQ;YACR,MAAM,KAAK,GACT,oKAAoK,CAAC;YACvK,MAAM,QAAQ,GAAG,IAAA,sBAAI,EACnB,IAAA,sCAAgB,EAAC;gBACf,GAAG,IAAA,4BAAM,EAAC,KAAK,CAAC;gBAChB,aAAa,EAAE,SAAS;aACzB,CAAC,EACF,YAAY,CACb,CAAC;YAEF,OAAO;YACP,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAErD,OAAO;YACP,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CACpB,sTAAsT,CACvT,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib/api/index.js
CHANGED
|
@@ -19,14 +19,10 @@ function createApi(config) {
|
|
|
19
19
|
listOperations: operations,
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
async function craft(transactionIntent
|
|
22
|
+
async function craft(transactionIntent) {
|
|
23
23
|
const nextSequenceNumber = await (0, logic_1.getNextValidSequence)(transactionIntent.sender);
|
|
24
|
-
const
|
|
25
|
-
const tx = await (0, logic_1.craftTransaction)({ address: transactionIntent.sender, nextSequenceNumber }, {
|
|
26
|
-
recipient: transactionIntent.recipient,
|
|
27
|
-
amount: transactionIntent.amount,
|
|
28
|
-
fee: estimatedFees,
|
|
29
|
-
});
|
|
24
|
+
const fees = await (0, logic_1.estimateFees)();
|
|
25
|
+
const tx = await (0, logic_1.craftTransaction)({ address: transactionIntent.sender, nextSequenceNumber }, { recipient: transactionIntent.recipient, amount: transactionIntent.amount, fee: fees.fee });
|
|
30
26
|
return tx.serializedTransaction;
|
|
31
27
|
}
|
|
32
28
|
async function operationsFromHeight(address, minHeight) {
|
package/lib/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";;;;;AAoBA,8BAYC;AA1BD,yCAAqC;AACrC,uDAAuD;AACvD,oCASkB;AAGlB,SAAgB,SAAS,CAAC,MAAiB;IACzC,gBAAU,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;IAE5E,OAAO;QACL,SAAS,EAAT,iBAAS;QACT,OAAO,EAAP,eAAO;QACP,gBAAgB,EAAE,KAAK;QACvB,YAAY,EAAE,GAAG,EAAE,CAAC,IAAA,oBAAY,GAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;QACzD,UAAU,EAAV,kBAAU;QACV,SAAS,EAAT,iBAAS;QACT,cAAc,EAAE,UAAU;KAC3B,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,KAAK,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";;;;;AAoBA,8BAYC;AA1BD,yCAAqC;AACrC,uDAAuD;AACvD,oCASkB;AAGlB,SAAgB,SAAS,CAAC,MAAiB;IACzC,gBAAU,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;IAE5E,OAAO;QACL,SAAS,EAAT,iBAAS;QACT,OAAO,EAAP,eAAO;QACP,gBAAgB,EAAE,KAAK;QACvB,YAAY,EAAE,G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a,KAAK,EAAE,EAAE,CAAC;YACzB,iBAAiB,GAAG,KAAK,CAAC;QAC5B,CAAC;aAAM,IAAI,mBAAmB,IAAI,KAAK,CAAC,aAAa,EAAE,CAAC;YACtD,IAAA,UAAG,EAAC,UAAU,EAAE,0CAA0C,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;YACjF,iBAAiB,GAAG,KAAK,CAAC;QAC5B,CAAC;QACD,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACzD,OAAO;YACL,GAAG,KAAK;YACR,gBAAgB,EAAE,mBAAmB;YACrC,kBAAkB,EAAE,iBAAiB;YACrC,aAAa,EAAE,aAAa;YAC5B,WAAW,EAAE,WAAW;SACzB,CAAC;IACJ,CAAC;IAED,MAAM,UAAU,GAAoB;QAClC,QAAQ,EAAE,GAAG;QACb,aAAa,EAAE,EAAE;QACjB,gBAAgB,EAAE,CAAC;QACnB,SAAS,EAAE,SAAS;QACpB,kBAAkB,EAAE,IAAI;QACxB,WAAW,EAAE,EAAE;KAChB,CAAC;IAEF,IAAI,KAAK,GAAG,MAAM,aAAa,CAAC,UAAU,CAAC,CAAC;IAC5C,OAAO,KAAK,CAAC,kBAAkB,EAAE,CAAC;QAChC,KAAK,GAAG,MAAM,aAAa,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC;AACxD,CAAC;AAED,KAAK,UAAU,UAAU,CACvB,OAAe,EACf,EAAE,SAAS,EAAc;IAEzB,iFAAiF;IACjF,OAAO,MAAM,oBAAoB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACxD,CAAC"}
|
package/lib/api/index.test.js
CHANGED
|
@@ -1,29 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
const
|
|
3
|
+
const logic_1 = require("../logic");
|
|
27
4
|
const index_1 = require("./index");
|
|
28
5
|
const mockGetServerInfos = jest.fn().mockResolvedValue({
|
|
29
6
|
info: {
|
|
@@ -181,7 +158,7 @@ describe("listOperations", () => {
|
|
|
181
158
|
tx: {
|
|
182
159
|
hash: "HASH_VALUE",
|
|
183
160
|
fees: fee,
|
|
184
|
-
date: new Date(1000000 +
|
|
161
|
+
date: new Date(1000000 + logic_1.RIPPLE_EPOCH * 1000),
|
|
185
162
|
block: {
|
|
186
163
|
hash: "HASH_VALUE_BLOCK",
|
|
187
164
|
height: 1,
|
|
@@ -208,7 +185,7 @@ describe("listOperations", () => {
|
|
|
208
185
|
tx: {
|
|
209
186
|
hash: "HASH_VALUE",
|
|
210
187
|
fees: fee,
|
|
211
|
-
date: new Date(1000000 +
|
|
188
|
+
date: new Date(1000000 + logic_1.RIPPLE_EPOCH * 1000),
|
|
212
189
|
block: {
|
|
213
190
|
hash: "HASH_VALUE_BLOCK",
|
|
214
191
|
height: 1,
|
|
@@ -230,7 +207,7 @@ describe("listOperations", () => {
|
|
|
230
207
|
tx: {
|
|
231
208
|
hash: "HASH_VALUE",
|
|
232
209
|
fees: fee,
|
|
233
|
-
date: new Date(1000000 +
|
|
210
|
+
date: new Date(1000000 + logic_1.RIPPLE_EPOCH * 1000),
|
|
234
211
|
block: {
|
|
235
212
|
hash: "HASH_VALUE_BLOCK",
|
|
236
213
|
height: 1,
|
|
@@ -249,37 +226,4 @@ describe("listOperations", () => {
|
|
|
249
226
|
]);
|
|
250
227
|
});
|
|
251
228
|
});
|
|
252
|
-
describe("Testing craftTransaction function", () => {
|
|
253
|
-
const DEFAULT_ESTIMATED_FEES = 100n;
|
|
254
|
-
const api = (0, index_1.createApi)({ node: "https://localhost" });
|
|
255
|
-
const logicCraftTransactionSpy = jest
|
|
256
|
-
.spyOn(LogicFunctions, "craftTransaction")
|
|
257
|
-
.mockImplementation((_address, _transaction, _publicKey) => {
|
|
258
|
-
return Promise.resolve({ xrplTransaction: {}, serializedTransaction: "" });
|
|
259
|
-
});
|
|
260
|
-
beforeAll(() => {
|
|
261
|
-
jest
|
|
262
|
-
.spyOn(LogicFunctions, "getNextValidSequence")
|
|
263
|
-
.mockImplementation(_address => Promise.resolve(0));
|
|
264
|
-
jest.spyOn(LogicFunctions, "estimateFees").mockImplementation(_networkInfo => {
|
|
265
|
-
return Promise.resolve({
|
|
266
|
-
networkInfo: {},
|
|
267
|
-
fee: DEFAULT_ESTIMATED_FEES,
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
it("should use custom user fees when user provides it for crafting a transaction", async () => {
|
|
272
|
-
const customFees = 99n;
|
|
273
|
-
await api.craftTransaction({}, customFees);
|
|
274
|
-
expect(logicCraftTransactionSpy).toHaveBeenCalledWith(expect.any(Object), expect.objectContaining({
|
|
275
|
-
fee: customFees,
|
|
276
|
-
}));
|
|
277
|
-
});
|
|
278
|
-
it("should use default fees when user does not provide them for crafting a transaction", async () => {
|
|
279
|
-
await api.craftTransaction({});
|
|
280
|
-
expect(logicCraftTransactionSpy).toHaveBeenCalledWith(expect.any(Object), expect.objectContaining({
|
|
281
|
-
fee: DEFAULT_ESTIMATED_FEES,
|
|
282
|
-
}));
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
229
|
//# sourceMappingURL=index.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/api/index.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/api/index.test.ts"],"names":[],"mappings":";;AAAA,oCAAwC;AACxC,mCAAoC;AAIpC,MAAM,kBAAkB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;IACrD,IAAI,EAAE;QACJ,gBAAgB,EAAE,KAAK;KACxB;CACF,CAAC,CAAC;AACH,MAAM,mBAAmB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AACtC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7B,cAAc,EAAE,GAAG,EAAE,CAAC,kBAAkB,EAAE;IAC1C,eAAe,EAAE,CAAC,OAAe,EAAE,OAA+B,EAAE,EAAE,CACpE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC;CACxC,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,MAAM,GAAG,GAAG,IAAA,iBAAS,EAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC,CAAC;IAErD,SAAS,CAAC,GAAG,EAAE;QACb,kBAAkB,CAAC,SAAS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IAAI,EAAE,IAAI,IAAI,CAAC,OAAO,GAAG,oBAAY,GAAG,IAAI,CAAC;oBAC7C,KAAK,EAAE;wBACL,IAAI,EAAE,kBAAkB;wBACxB,MAAM,EAAE,CAAC;wBACT,IAAI,EAAE,IAAI,IAAI,CAAC,sBAAsB,CAAC;qBACvC;iBACF;gBACD,IAAI,EAAE,YAAY;gBAClB,KAAK,EAAE,aAAa;gBACpB,OAAO,EAAE,CAAC,QAAQ,CAAC;gBACnB,UAAU,EAAE,CAAC,aAAa,CAAC;gBAC3B,OAAO,EAAE;oBACP,SAAS,EAAE,SAAS;oBACpB,QAAQ,EAAE,CAAC;iBACZ;aACF;SAC0B,CAAC,CAAC;IACjC,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.estimateFees = estimateFees;
|
|
7
|
-
const errors_1 = require("@ledgerhq/errors");
|
|
8
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
|
+
const errors_1 = require("@ledgerhq/errors");
|
|
9
9
|
const network_1 = require("../network");
|
|
10
10
|
const common_1 = require("./common");
|
|
11
11
|
// FIXME this could be cleaner
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estimateFees.js","sourceRoot":"","sources":["../../src/logic/estimateFees.ts"],"names":[],"mappings":";;;;;AAiBA,oCAqBC;AAtCD,6CAA+C;AAC/C,
|
|
1
|
+
{"version":3,"file":"estimateFees.js","sourceRoot":"","sources":["../../src/logic/estimateFees.ts"],"names":[],"mappings":";;;;;AAiBA,oCAqBC;AAtCD,gEAAqC;AACrC,6CAA+C;AAC/C,wCAA4C;AAE5C,qCAAyC;AAEzC,8BAA8B;AAC9B,MAAM,UAAU,GAAG,CAAC,KAAY,EAAE,EAAE;IAClC,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC;IAE1B,IAAI,GAAG,CAAC,QAAQ,CAAC,wBAAwB,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC;QAC9E,OAAO,IAAI,oBAAW,EAAE,CAAC;IAC3B,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEK,KAAK,UAAU,YAAY,CAChC,WAAgC;IAEhC,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,IAAA,wBAAc,GAAE,CAAC;YACpC,MAAM,SAAS,GAAG,IAAA,sBAAa,EAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC;YACpF,WAAW,GAAG;gBACZ,MAAM,EAAE,KAAK;gBACb,SAAS;gBACT,WAAW,EAAE,IAAI,sBAAS,CAAC,CAAC,CAAC,EAAE,iCAAiC;aACjE,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;gBACvB,MAAM,UAAU,CAAC,CAAC,CAAC,CAAC;YACtB,CAAC;YACD,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;IAED,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;AACxE,CAAC"}
|
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
import { decode } from "ripple-binary-codec";
|
|
2
1
|
import { createApi } from ".";
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { decode, encodeForSigning } from "ripple-binary-codec";
|
|
3
|
+
import { sign } from "ripple-keypairs";
|
|
5
4
|
describe("Xrp Api", () => {
|
|
6
|
-
|
|
7
|
-
const
|
|
5
|
+
let module;
|
|
6
|
+
const address = "rh1HPuRVsYYvThxG2Bs1MfjmrVC73S16Fb";
|
|
7
|
+
const bigAddress = "rUxSkt6hQpWxXQwTNRUCYYRQ7BC2yRA3F8"; // An account with more that 4000 txs
|
|
8
|
+
const emptyAddress = "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB"; // Account with no transaction (at the time of this writing)
|
|
9
|
+
const xrpPubKey = process.env["PUB_KEY"];
|
|
10
|
+
const xrpSecretKey = process.env["SECRET_KEY"];
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
module = createApi({ node: "https://s.altnet.rippletest.net:51234" });
|
|
13
|
+
});
|
|
8
14
|
describe("estimateFees", () => {
|
|
9
15
|
it("returns a default value", async () => {
|
|
10
16
|
// Given
|
|
11
17
|
const amount = BigInt(100);
|
|
12
18
|
// When
|
|
13
|
-
const result = await
|
|
19
|
+
const result = await module.estimateFees({
|
|
14
20
|
type: "send",
|
|
15
|
-
sender:
|
|
21
|
+
sender: address,
|
|
16
22
|
amount,
|
|
17
23
|
recipient: "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB",
|
|
18
24
|
});
|
|
@@ -23,21 +29,19 @@ describe("Xrp Api", () => {
|
|
|
23
29
|
describe("listOperations", () => {
|
|
24
30
|
it.skip("returns a list regarding address parameter", async () => {
|
|
25
31
|
// When
|
|
26
|
-
const [tx, _] = await
|
|
32
|
+
const [tx, _] = await module.listOperations(address, { minHeight: 200 });
|
|
27
33
|
// https://blockexplorer.one/xrp/testnet/address/rh1HPuRVsYYvThxG2Bs1MfjmrVC73S16Fb
|
|
28
34
|
// as of 2025-03-18, the address has 287 transactions
|
|
29
35
|
expect(tx.length).toBeGreaterThanOrEqual(287);
|
|
30
36
|
tx.forEach(operation => {
|
|
31
|
-
const isSenderOrReceipt = operation.senders.includes(
|
|
37
|
+
const isSenderOrReceipt = operation.senders.includes(address) || operation.recipients.includes(address);
|
|
32
38
|
expect(isSenderOrReceipt).toBeTruthy();
|
|
33
39
|
});
|
|
34
40
|
});
|
|
35
41
|
// TO FIX, ops length is 0 for some reason
|
|
36
42
|
it.skip("returns all operations", async () => {
|
|
37
|
-
// An account with more that 4000 txs
|
|
38
|
-
const SENDER_WITH_TRANSACTIONS = "rUxSkt6hQpWxXQwTNRUCYYRQ7BC2yRA3F8";
|
|
39
43
|
// When
|
|
40
|
-
const [ops, _] = await
|
|
44
|
+
const [ops, _] = await module.listOperations(bigAddress, { minHeight: 0 });
|
|
41
45
|
// Then
|
|
42
46
|
const checkSet = new Set(ops.map(elt => elt.tx.hash));
|
|
43
47
|
expect(checkSet.size).toEqual(ops.length);
|
|
@@ -52,7 +56,7 @@ describe("Xrp Api", () => {
|
|
|
52
56
|
describe("lastBlock", () => {
|
|
53
57
|
it("returns last block info", async () => {
|
|
54
58
|
// When
|
|
55
|
-
const result = await
|
|
59
|
+
const result = await module.lastBlock();
|
|
56
60
|
// Then
|
|
57
61
|
expect(result.hash).toBeDefined();
|
|
58
62
|
expect(result.height).toBeDefined();
|
|
@@ -60,83 +64,47 @@ describe("Xrp Api", () => {
|
|
|
60
64
|
});
|
|
61
65
|
});
|
|
62
66
|
describe("getBalance", () => {
|
|
63
|
-
// Account with no transaction (at the time of this writing)
|
|
64
|
-
const SENDER_WITH_NO_TRANSACTION = "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB";
|
|
65
67
|
it("returns an amount above 0 when address has transactions", async () => {
|
|
66
68
|
// When
|
|
67
|
-
const result = await
|
|
69
|
+
const result = await module.getBalance(address);
|
|
68
70
|
// Then
|
|
69
71
|
expect(result).toBeGreaterThan(BigInt(0));
|
|
70
72
|
});
|
|
71
73
|
it("returns 0 when address has no transaction", async () => {
|
|
72
74
|
// When
|
|
73
|
-
const result = await
|
|
75
|
+
const result = await module.getBalance(emptyAddress);
|
|
74
76
|
// Then
|
|
75
77
|
expect(result).toBe(BigInt(0));
|
|
76
78
|
});
|
|
77
79
|
});
|
|
78
80
|
describe("craftTransaction", () => {
|
|
79
|
-
const RECIPIENT = "rKRtUG15iBsCQRgrkeUEg5oX4Ae2zWZ89z";
|
|
80
81
|
it("returns a raw transaction", async () => {
|
|
81
82
|
// When
|
|
82
|
-
const result = await
|
|
83
|
+
const result = await module.craftTransaction({
|
|
83
84
|
type: "send",
|
|
84
|
-
sender:
|
|
85
|
-
recipient:
|
|
85
|
+
sender: address,
|
|
86
|
+
recipient: "rKRtUG15iBsCQRgrkeUEg5oX4Ae2zWZ89z",
|
|
86
87
|
amount: BigInt(10),
|
|
87
88
|
});
|
|
88
89
|
// Then
|
|
89
90
|
expect(result.length).toEqual(162);
|
|
90
91
|
});
|
|
91
|
-
it("should use default fees when user does not provide them for crafting a transaction", async () => {
|
|
92
|
-
const result = await api.craftTransaction({
|
|
93
|
-
type: "send",
|
|
94
|
-
sender: SENDER,
|
|
95
|
-
recipient: RECIPIENT,
|
|
96
|
-
amount: BigInt(10),
|
|
97
|
-
});
|
|
98
|
-
const decodedTransaction = decode(result);
|
|
99
|
-
expect(decodedTransaction.Fee).toEqual("10");
|
|
100
|
-
});
|
|
101
|
-
it("should use custom user fees when user provides it for crafting a transaction", async () => {
|
|
102
|
-
const customFees = 99n;
|
|
103
|
-
const result = await api.craftTransaction({
|
|
104
|
-
type: "send",
|
|
105
|
-
sender: SENDER,
|
|
106
|
-
recipient: RECIPIENT,
|
|
107
|
-
amount: BigInt(10),
|
|
108
|
-
}, customFees);
|
|
109
|
-
const decodedTransaction = decode(result);
|
|
110
|
-
expect(decodedTransaction.Fee).toEqual(customFees.toString());
|
|
111
|
-
});
|
|
112
92
|
});
|
|
113
|
-
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
})
|
|
128
|
-
xrpSecretKey,
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
// When
|
|
132
|
-
const result = await module.combine(rawTx, signedTx);
|
|
133
|
-
|
|
134
|
-
// Then
|
|
135
|
-
expect(result).toEqual(
|
|
136
|
-
"120000228000000024001BCDA6201B001F018161400000000000000A68400000000000000174473045022100D3B9B37F40961A8DBDE48535F9EF333E87F9D98BE90F7141E133541874826BDB0220065E9CA4D218F16087656BC30D66672F6103B03717A59FFC04C837A2157CE47C8114CF30F590D7A9067B2604D80D46090FBF342EBE988314CA26FB6B0EF6859436C2037BA0A9913208A59B98",
|
|
137
|
-
);
|
|
93
|
+
// To enable this test, you need to fill an `.env` file at the root of this package. Example can be found in `.env.integ.test.example`.
|
|
94
|
+
// The value hardcoded here depends on the value filled in the `.env` file.
|
|
95
|
+
describe.skip("combine", () => {
|
|
96
|
+
it("returns a signed raw transaction", async () => {
|
|
97
|
+
// Given
|
|
98
|
+
const rawTx = "120000228000000024001BCDA6201B001F018161400000000000000A6840000000000000018114CF30F590D7A9067B2604D80D46090FBF342EBE988314CA26FB6B0EF6859436C2037BA0A9913208A59B98";
|
|
99
|
+
const signedTx = sign(encodeForSigning({
|
|
100
|
+
...decode(rawTx),
|
|
101
|
+
SigningPubKey: xrpPubKey,
|
|
102
|
+
}), xrpSecretKey);
|
|
103
|
+
// When
|
|
104
|
+
const result = await module.combine(rawTx, signedTx);
|
|
105
|
+
// Then
|
|
106
|
+
expect(result).toEqual("120000228000000024001BCDA6201B001F018161400000000000000A68400000000000000174473045022100D3B9B37F40961A8DBDE48535F9EF333E87F9D98BE90F7141E133541874826BDB0220065E9CA4D218F16087656BC30D66672F6103B03717A59FFC04C837A2157CE47C8114CF30F590D7A9067B2604D80D46090FBF342EBE988314CA26FB6B0EF6859436C2037BA0A9913208A59B98");
|
|
107
|
+
});
|
|
138
108
|
});
|
|
139
|
-
});
|
|
140
109
|
});
|
|
141
|
-
*/
|
|
142
110
|
//# sourceMappingURL=index.integ.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.integ.test.js","sourceRoot":"","sources":["../../src/api/index.integ.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"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AAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAChC,EAAE,CAAC,2BAA2B,EAAE,KAAK,IAAI,EAAE;YACzC,OAAO;YACP,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC;gBAC3C,IAAI,EAAE,MAAM;gBACZ,MAAM,EAAE,OAAO;gBACf,SAAS,EAAE,oCAAoC;gBAC/C,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;aACnB,CAAC,CAAC;YAEH,OAAO;YACP,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,uIAAuI;IACvI,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE;QAC5B,EAAE,CAAC,kCAAkC,EAAE,KAAK,IAAI,EAAE;YAChD,QAAQ;YACR,MAAM,KAAK,GACT,oKAAoK,CAAC;YACvK,MAAM,QAAQ,GAAG,IAAI,CACnB,gBAAgB,CAAC;gBACf,GAAG,MAAM,CAAC,KAAK,CAAC;gBAChB,aAAa,EAAE,SAAS;aACzB,CAAC,EACF,YAAY,CACb,CAAC;YAEF,OAAO;YACP,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;YAErD,OAAO;YACP,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CACpB,sTAAsT,CACvT,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/lib-es/api/index.js
CHANGED
|
@@ -13,14 +13,10 @@ export function createApi(config) {
|
|
|
13
13
|
listOperations: operations,
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
-
async function craft(transactionIntent
|
|
16
|
+
async function craft(transactionIntent) {
|
|
17
17
|
const nextSequenceNumber = await getNextValidSequence(transactionIntent.sender);
|
|
18
|
-
const
|
|
19
|
-
const tx = await craftTransaction({ address: transactionIntent.sender, nextSequenceNumber }, {
|
|
20
|
-
recipient: transactionIntent.recipient,
|
|
21
|
-
amount: transactionIntent.amount,
|
|
22
|
-
fee: estimatedFees,
|
|
23
|
-
});
|
|
18
|
+
const fees = await estimateFees();
|
|
19
|
+
const tx = await craftTransaction({ address: transactionIntent.sender, nextSequenceNumber }, { recipient: transactionIntent.recipient, amount: transactionIntent.amount, fee: fees.fee });
|
|
24
20
|
return tx.serializedTransaction;
|
|
25
21
|
}
|
|
26
22
|
async function operationsFromHeight(address, minHeight) {
|
package/lib-es/api/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,UAA8B,MAAM,WAAW,CAAC;AACvD,OAAO,EACL,SAAS,EACT,OAAO,EACP,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,oBAAoB,EACpB,SAAS,EACT,cAAc,GACf,MAAM,UAAU,CAAC;AAGlB,MAAM,UAAU,SAAS,CAAC,MAAiB;IACzC,UAAU,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;IAE5E,OAAO;QACL,SAAS;QACT,OAAO;QACP,gBAAgB,EAAE,KAAK;QACvB,YAAY,EAAE,GAAG,EAAE,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC;QACzD,UAAU;QACV,SAAS;QACT,cAAc,EAAE,UAAU;KAC3B,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,KAAK,
|
|
1
|
+
{"version":3,"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AkB,EAAE,CAAC;QAChC,KAAK,GAAG,MAAM,aAAa,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,aAAa,IAAI,EAAE,CAAC,CAAC;AACxD,CAAC;AAED,KAAK,UAAU,UAAU,CACvB,OAAe,EACf,EAAE,SAAS,EAAc;IAEzB,iFAAiF;IACjF,OAAO,MAAM,oBAAoB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACxD,CAAC"}
|
package/lib-es/api/index.test.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RIPPLE_EPOCH } from "../logic";
|
|
2
2
|
import { createApi } from "./index";
|
|
3
3
|
const mockGetServerInfos = jest.fn().mockResolvedValue({
|
|
4
4
|
info: {
|
|
@@ -156,7 +156,7 @@ describe("listOperations", () => {
|
|
|
156
156
|
tx: {
|
|
157
157
|
hash: "HASH_VALUE",
|
|
158
158
|
fees: fee,
|
|
159
|
-
date: new Date(1000000 +
|
|
159
|
+
date: new Date(1000000 + RIPPLE_EPOCH * 1000),
|
|
160
160
|
block: {
|
|
161
161
|
hash: "HASH_VALUE_BLOCK",
|
|
162
162
|
height: 1,
|
|
@@ -183,7 +183,7 @@ describe("listOperations", () => {
|
|
|
183
183
|
tx: {
|
|
184
184
|
hash: "HASH_VALUE",
|
|
185
185
|
fees: fee,
|
|
186
|
-
date: new Date(1000000 +
|
|
186
|
+
date: new Date(1000000 + RIPPLE_EPOCH * 1000),
|
|
187
187
|
block: {
|
|
188
188
|
hash: "HASH_VALUE_BLOCK",
|
|
189
189
|
height: 1,
|
|
@@ -205,7 +205,7 @@ describe("listOperations", () => {
|
|
|
205
205
|
tx: {
|
|
206
206
|
hash: "HASH_VALUE",
|
|
207
207
|
fees: fee,
|
|
208
|
-
date: new Date(1000000 +
|
|
208
|
+
date: new Date(1000000 + RIPPLE_EPOCH * 1000),
|
|
209
209
|
block: {
|
|
210
210
|
hash: "HASH_VALUE_BLOCK",
|
|
211
211
|
height: 1,
|
|
@@ -224,37 +224,4 @@ describe("listOperations", () => {
|
|
|
224
224
|
]);
|
|
225
225
|
});
|
|
226
226
|
});
|
|
227
|
-
describe("Testing craftTransaction function", () => {
|
|
228
|
-
const DEFAULT_ESTIMATED_FEES = 100n;
|
|
229
|
-
const api = createApi({ node: "https://localhost" });
|
|
230
|
-
const logicCraftTransactionSpy = jest
|
|
231
|
-
.spyOn(LogicFunctions, "craftTransaction")
|
|
232
|
-
.mockImplementation((_address, _transaction, _publicKey) => {
|
|
233
|
-
return Promise.resolve({ xrplTransaction: {}, serializedTransaction: "" });
|
|
234
|
-
});
|
|
235
|
-
beforeAll(() => {
|
|
236
|
-
jest
|
|
237
|
-
.spyOn(LogicFunctions, "getNextValidSequence")
|
|
238
|
-
.mockImplementation(_address => Promise.resolve(0));
|
|
239
|
-
jest.spyOn(LogicFunctions, "estimateFees").mockImplementation(_networkInfo => {
|
|
240
|
-
return Promise.resolve({
|
|
241
|
-
networkInfo: {},
|
|
242
|
-
fee: DEFAULT_ESTIMATED_FEES,
|
|
243
|
-
});
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
it("should use custom user fees when user provides it for crafting a transaction", async () => {
|
|
247
|
-
const customFees = 99n;
|
|
248
|
-
await api.craftTransaction({}, customFees);
|
|
249
|
-
expect(logicCraftTransactionSpy).toHaveBeenCalledWith(expect.any(Object), expect.objectContaining({
|
|
250
|
-
fee: customFees,
|
|
251
|
-
}));
|
|
252
|
-
});
|
|
253
|
-
it("should use default fees when user does not provide them for crafting a transaction", async () => {
|
|
254
|
-
await api.craftTransaction({});
|
|
255
|
-
expect(logicCraftTransactionSpy).toHaveBeenCalledWith(expect.any(Object), expect.objectContaining({
|
|
256
|
-
fee: DEFAULT_ESTIMATED_FEES,
|
|
257
|
-
}));
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
227
|
//# sourceMappingURL=index.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/api/index.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/api/index.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAIpC,MAAM,kBAAkB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC;IACrD,IAAI,EAAE;QACJ,gBAAgB,EAAE,KAAK;KACxB;CACF,CAAC,CAAC;AACH,MAAM,mBAAmB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AACtC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC;IAC7B,cAAc,EAAE,GAAG,EAAE,CAAC,kBAAkB,EAAE;IAC1C,eAAe,EAAE,CAAC,OAAe,EAAE,OAA+B,EAAE,EAAE,CACpE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC;CACxC,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC9B,MAAM,GAAG,GAAG,SAAS,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,CAAC,CAAC;IAErD,SAAS,CAAC,GAAG,EAAE;QACb,kBAAkB,CAAC,SAAS,EAAE,CAAC;QAC/B,mBAAmB,CAAC,SAAS,EAAE,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,MAAM,aAAa,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;IAC5C,SAAS,cAAc,CAAC,GAAY,EAAE,MAA2B;QAC/D,OAAO;YACL,OAAO,EAAE,SAAS;YAClB,gBAAgB,EAAE,CAAC;YACnB,gBAAgB,EAAE,CAAC;YACnB,KAAK,EAAE,CAAC;YACR,SAAS,EAAE,KAAK;YAChB,YAA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SAAS,EAAE,SAAS;oBACpB,QAAQ,EAAE,CAAC;iBACZ;aACF;SAC0B,CAAC,CAAC;IACjC,CAAC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estimateFees.js","sourceRoot":"","sources":["../../src/logic/estimateFees.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,
|
|
1
|
+
{"version":3,"file":"estimateFees.js","sourceRoot":"","sources":["../../src/logic/estimateFees.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,8BAA8B;AAC9B,MAAM,UAAU,GAAG,CAAC,KAAY,EAAE,EAAE;IAClC,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC;IAE1B,IAAI,GAAG,CAAC,QAAQ,CAAC,wBAAwB,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC;QAC9E,OAAO,IAAI,WAAW,EAAE,CAAC;IAC3B,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,WAAgC;IAEhC,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,cAAc,EAAE,CAAC;YACpC,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC;YACpF,WAAW,GAAG;gBACZ,MAAM,EAAE,KAAK;gBACb,SAAS;gBACT,WAAW,EAAE,IAAI,SAAS,CAAC,CAAC,CAAC,EAAE,iCAAiC;aACjE,CAAC;QACJ,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,YAAY,KAAK,EAAE,CAAC;gBACvB,MAAM,UAAU,CAAC,CAAC,CAAC,CAAC;YACtB,CAAC;YACD,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;IAED,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;AACxE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-xrp",
|
|
3
|
-
"version": "3.1.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Ledger XRP Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -104,12 +104,12 @@
|
|
|
104
104
|
"ripple-address-codec": "^5.0.0",
|
|
105
105
|
"ripple-binary-codec": "^1.3.0",
|
|
106
106
|
"rxjs": "^7.8.1",
|
|
107
|
-
"@ledgerhq/coin-framework": "^2.5.0
|
|
108
|
-
"@ledgerhq/cryptoassets": "^13.14.0
|
|
107
|
+
"@ledgerhq/coin-framework": "^2.5.0",
|
|
108
|
+
"@ledgerhq/cryptoassets": "^13.14.0",
|
|
109
109
|
"@ledgerhq/devices": "8.4.4",
|
|
110
110
|
"@ledgerhq/errors": "^6.19.1",
|
|
111
|
-
"@ledgerhq/live-network": "^2.0.6
|
|
112
|
-
"@ledgerhq/types-live": "^6.65.0
|
|
111
|
+
"@ledgerhq/live-network": "^2.0.6",
|
|
112
|
+
"@ledgerhq/types-live": "^6.65.0",
|
|
113
113
|
"@ledgerhq/logs": "^6.12.0"
|
|
114
114
|
},
|
|
115
115
|
"devDependencies": {
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"ts-jest": "^29.1.1",
|
|
124
124
|
"jest-sonar": "0.2.16",
|
|
125
125
|
"typescript": "^5.4.5",
|
|
126
|
-
"@ledgerhq/types-cryptoassets": "^7.21.0
|
|
126
|
+
"@ledgerhq/types-cryptoassets": "^7.21.0"
|
|
127
127
|
},
|
|
128
128
|
"scripts": {
|
|
129
129
|
"clean": "rimraf lib lib-es",
|
|
@@ -136,10 +136,8 @@
|
|
|
136
136
|
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
|
|
137
137
|
"lint:fix": "pnpm lint --fix",
|
|
138
138
|
"test": "jest",
|
|
139
|
-
"test:debug": "node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand",
|
|
140
139
|
"test-watch": "jest --watch",
|
|
141
140
|
"test-integ": "DOTENV_CONFIG_PATH=.env.integ.test jest --config=jest.integ.config.js",
|
|
142
|
-
"test-integ:debug": "DOTENV_CONFIG_PATH=.env.integ.test node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --config=jest.integ.config.js",
|
|
143
141
|
"typecheck": "tsc --noEmit",
|
|
144
142
|
"unimported": "unimported"
|
|
145
143
|
}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Api } from "@ledgerhq/coin-framework/api/index";
|
|
2
2
|
import { createApi } from ".";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { decode, encodeForSigning } from "ripple-binary-codec";
|
|
4
|
+
import { sign } from "ripple-keypairs";
|
|
5
5
|
|
|
6
6
|
describe("Xrp Api", () => {
|
|
7
|
-
|
|
8
|
-
const
|
|
7
|
+
let module: Api<void>;
|
|
8
|
+
const address = "rh1HPuRVsYYvThxG2Bs1MfjmrVC73S16Fb";
|
|
9
|
+
const bigAddress = "rUxSkt6hQpWxXQwTNRUCYYRQ7BC2yRA3F8"; // An account with more that 4000 txs
|
|
10
|
+
const emptyAddress = "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB"; // Account with no transaction (at the time of this writing)
|
|
11
|
+
const xrpPubKey = process.env["PUB_KEY"]!;
|
|
12
|
+
const xrpSecretKey = process.env["SECRET_KEY"]!;
|
|
13
|
+
|
|
14
|
+
beforeAll(() => {
|
|
15
|
+
module = createApi({ node: "https://s.altnet.rippletest.net:51234" });
|
|
16
|
+
});
|
|
9
17
|
|
|
10
18
|
describe("estimateFees", () => {
|
|
11
19
|
it("returns a default value", async () => {
|
|
@@ -13,9 +21,9 @@ describe("Xrp Api", () => {
|
|
|
13
21
|
const amount = BigInt(100);
|
|
14
22
|
|
|
15
23
|
// When
|
|
16
|
-
const result = await
|
|
24
|
+
const result = await module.estimateFees({
|
|
17
25
|
type: "send",
|
|
18
|
-
sender:
|
|
26
|
+
sender: address,
|
|
19
27
|
amount,
|
|
20
28
|
recipient: "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB",
|
|
21
29
|
});
|
|
@@ -28,25 +36,22 @@ describe("Xrp Api", () => {
|
|
|
28
36
|
describe("listOperations", () => {
|
|
29
37
|
it.skip("returns a list regarding address parameter", async () => {
|
|
30
38
|
// When
|
|
31
|
-
const [tx, _] = await
|
|
39
|
+
const [tx, _] = await module.listOperations(address, { minHeight: 200 });
|
|
32
40
|
|
|
33
41
|
// https://blockexplorer.one/xrp/testnet/address/rh1HPuRVsYYvThxG2Bs1MfjmrVC73S16Fb
|
|
34
42
|
// as of 2025-03-18, the address has 287 transactions
|
|
35
43
|
expect(tx.length).toBeGreaterThanOrEqual(287);
|
|
36
44
|
tx.forEach(operation => {
|
|
37
45
|
const isSenderOrReceipt =
|
|
38
|
-
operation.senders.includes(
|
|
46
|
+
operation.senders.includes(address) || operation.recipients.includes(address);
|
|
39
47
|
expect(isSenderOrReceipt).toBeTruthy();
|
|
40
48
|
});
|
|
41
49
|
});
|
|
42
50
|
|
|
43
51
|
// TO FIX, ops length is 0 for some reason
|
|
44
52
|
it.skip("returns all operations", async () => {
|
|
45
|
-
// An account with more that 4000 txs
|
|
46
|
-
const SENDER_WITH_TRANSACTIONS = "rUxSkt6hQpWxXQwTNRUCYYRQ7BC2yRA3F8";
|
|
47
|
-
|
|
48
53
|
// When
|
|
49
|
-
const [ops, _] = await
|
|
54
|
+
const [ops, _] = await module.listOperations(bigAddress, { minHeight: 0 });
|
|
50
55
|
// Then
|
|
51
56
|
const checkSet = new Set(ops.map(elt => elt.tx.hash));
|
|
52
57
|
expect(checkSet.size).toEqual(ops.length);
|
|
@@ -64,7 +69,7 @@ describe("Xrp Api", () => {
|
|
|
64
69
|
describe("lastBlock", () => {
|
|
65
70
|
it("returns last block info", async () => {
|
|
66
71
|
// When
|
|
67
|
-
const result = await
|
|
72
|
+
const result = await module.lastBlock();
|
|
68
73
|
|
|
69
74
|
// Then
|
|
70
75
|
expect(result.hash).toBeDefined();
|
|
@@ -74,12 +79,9 @@ describe("Xrp Api", () => {
|
|
|
74
79
|
});
|
|
75
80
|
|
|
76
81
|
describe("getBalance", () => {
|
|
77
|
-
// Account with no transaction (at the time of this writing)
|
|
78
|
-
const SENDER_WITH_NO_TRANSACTION = "rKtXXTVno77jhu6tto1MAXjepyuaKaLcqB";
|
|
79
|
-
|
|
80
82
|
it("returns an amount above 0 when address has transactions", async () => {
|
|
81
83
|
// When
|
|
82
|
-
const result = await
|
|
84
|
+
const result = await module.getBalance(address);
|
|
83
85
|
|
|
84
86
|
// Then
|
|
85
87
|
expect(result).toBeGreaterThan(BigInt(0));
|
|
@@ -87,7 +89,7 @@ describe("Xrp Api", () => {
|
|
|
87
89
|
|
|
88
90
|
it("returns 0 when address has no transaction", async () => {
|
|
89
91
|
// When
|
|
90
|
-
const result = await
|
|
92
|
+
const result = await module.getBalance(emptyAddress);
|
|
91
93
|
|
|
92
94
|
// Then
|
|
93
95
|
expect(result).toBe(BigInt(0));
|
|
@@ -95,56 +97,23 @@ describe("Xrp Api", () => {
|
|
|
95
97
|
});
|
|
96
98
|
|
|
97
99
|
describe("craftTransaction", () => {
|
|
98
|
-
const RECIPIENT = "rKRtUG15iBsCQRgrkeUEg5oX4Ae2zWZ89z";
|
|
99
|
-
|
|
100
100
|
it("returns a raw transaction", async () => {
|
|
101
101
|
// When
|
|
102
|
-
const result = await
|
|
102
|
+
const result = await module.craftTransaction({
|
|
103
103
|
type: "send",
|
|
104
|
-
sender:
|
|
105
|
-
recipient:
|
|
104
|
+
sender: address,
|
|
105
|
+
recipient: "rKRtUG15iBsCQRgrkeUEg5oX4Ae2zWZ89z",
|
|
106
106
|
amount: BigInt(10),
|
|
107
107
|
});
|
|
108
108
|
|
|
109
109
|
// Then
|
|
110
110
|
expect(result.length).toEqual(162);
|
|
111
111
|
});
|
|
112
|
-
|
|
113
|
-
it("should use default fees when user does not provide them for crafting a transaction", async () => {
|
|
114
|
-
const result = await api.craftTransaction({
|
|
115
|
-
type: "send",
|
|
116
|
-
sender: SENDER,
|
|
117
|
-
recipient: RECIPIENT,
|
|
118
|
-
amount: BigInt(10),
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
const decodedTransaction = decode(result) as { Fee: string };
|
|
122
|
-
expect(decodedTransaction.Fee).toEqual("10");
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it("should use custom user fees when user provides it for crafting a transaction", async () => {
|
|
126
|
-
const customFees = 99n;
|
|
127
|
-
const result = await api.craftTransaction(
|
|
128
|
-
{
|
|
129
|
-
type: "send",
|
|
130
|
-
sender: SENDER,
|
|
131
|
-
recipient: RECIPIENT,
|
|
132
|
-
amount: BigInt(10),
|
|
133
|
-
},
|
|
134
|
-
customFees,
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
const decodedTransaction = decode(result) as { Fee: string };
|
|
138
|
-
expect(decodedTransaction.Fee).toEqual(customFees.toString());
|
|
139
|
-
});
|
|
140
112
|
});
|
|
141
|
-
});
|
|
142
113
|
|
|
143
|
-
// To enable this test, you need to fill an `.env` file at the root of this package. Example can be found in `.env.integ.test.example`.
|
|
144
|
-
// The value hardcoded here depends on the value filled in the `.env` file.
|
|
145
|
-
|
|
146
|
-
//const xrpPubKey = process.env["PUB_KEY"]!;
|
|
147
|
-
//const xrpSecretKey = process.env["SECRET_KEY"]!;
|
|
114
|
+
// To enable this test, you need to fill an `.env` file at the root of this package. Example can be found in `.env.integ.test.example`.
|
|
115
|
+
// The value hardcoded here depends on the value filled in the `.env` file.
|
|
116
|
+
describe.skip("combine", () => {
|
|
148
117
|
it("returns a signed raw transaction", async () => {
|
|
149
118
|
// Given
|
|
150
119
|
const rawTx =
|
|
@@ -167,4 +136,3 @@ describe("Xrp Api", () => {
|
|
|
167
136
|
});
|
|
168
137
|
});
|
|
169
138
|
});
|
|
170
|
-
*/
|
package/src/api/index.test.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as LogicFunctions from "../logic";
|
|
3
|
-
import { GetTransactionsOptions } from "../network";
|
|
4
|
-
import { NetworkInfo } from "../types";
|
|
1
|
+
import { RIPPLE_EPOCH } from "../logic";
|
|
5
2
|
import { createApi } from "./index";
|
|
3
|
+
import { GetTransactionsOptions } from "../network";
|
|
4
|
+
import { Operation } from "@ledgerhq/coin-framework/api/types";
|
|
6
5
|
|
|
7
6
|
const mockGetServerInfos = jest.fn().mockResolvedValue({
|
|
8
7
|
info: {
|
|
@@ -187,7 +186,7 @@ describe("listOperations", () => {
|
|
|
187
186
|
tx: {
|
|
188
187
|
hash: "HASH_VALUE",
|
|
189
188
|
fees: fee,
|
|
190
|
-
date: new Date(1000000 +
|
|
189
|
+
date: new Date(1000000 + RIPPLE_EPOCH * 1000),
|
|
191
190
|
block: {
|
|
192
191
|
hash: "HASH_VALUE_BLOCK",
|
|
193
192
|
height: 1,
|
|
@@ -214,7 +213,7 @@ describe("listOperations", () => {
|
|
|
214
213
|
tx: {
|
|
215
214
|
hash: "HASH_VALUE",
|
|
216
215
|
fees: fee,
|
|
217
|
-
date: new Date(1000000 +
|
|
216
|
+
date: new Date(1000000 + RIPPLE_EPOCH * 1000),
|
|
218
217
|
block: {
|
|
219
218
|
hash: "HASH_VALUE_BLOCK",
|
|
220
219
|
height: 1,
|
|
@@ -236,7 +235,7 @@ describe("listOperations", () => {
|
|
|
236
235
|
tx: {
|
|
237
236
|
hash: "HASH_VALUE",
|
|
238
237
|
fees: fee,
|
|
239
|
-
date: new Date(1000000 +
|
|
238
|
+
date: new Date(1000000 + RIPPLE_EPOCH * 1000),
|
|
240
239
|
block: {
|
|
241
240
|
hash: "HASH_VALUE_BLOCK",
|
|
242
241
|
height: 1,
|
|
@@ -256,49 +255,3 @@ describe("listOperations", () => {
|
|
|
256
255
|
},
|
|
257
256
|
);
|
|
258
257
|
});
|
|
259
|
-
|
|
260
|
-
describe("Testing craftTransaction function", () => {
|
|
261
|
-
const DEFAULT_ESTIMATED_FEES = 100n;
|
|
262
|
-
const api = createApi({ node: "https://localhost" });
|
|
263
|
-
const logicCraftTransactionSpy = jest
|
|
264
|
-
.spyOn(LogicFunctions, "craftTransaction")
|
|
265
|
-
.mockImplementation((_address, _transaction, _publicKey) => {
|
|
266
|
-
return Promise.resolve({ xrplTransaction: {} as never, serializedTransaction: "" });
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
beforeAll(() => {
|
|
270
|
-
jest
|
|
271
|
-
.spyOn(LogicFunctions, "getNextValidSequence")
|
|
272
|
-
.mockImplementation(_address => Promise.resolve(0));
|
|
273
|
-
|
|
274
|
-
jest.spyOn(LogicFunctions, "estimateFees").mockImplementation(_networkInfo => {
|
|
275
|
-
return Promise.resolve({
|
|
276
|
-
networkInfo: {} as NetworkInfo,
|
|
277
|
-
fee: DEFAULT_ESTIMATED_FEES,
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
it("should use custom user fees when user provides it for crafting a transaction", async () => {
|
|
283
|
-
const customFees = 99n;
|
|
284
|
-
await api.craftTransaction({} as TransactionIntent<void>, customFees);
|
|
285
|
-
|
|
286
|
-
expect(logicCraftTransactionSpy).toHaveBeenCalledWith(
|
|
287
|
-
expect.any(Object),
|
|
288
|
-
expect.objectContaining({
|
|
289
|
-
fee: customFees,
|
|
290
|
-
}),
|
|
291
|
-
);
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
it("should use default fees when user does not provide them for crafting a transaction", async () => {
|
|
295
|
-
await api.craftTransaction({} as TransactionIntent<void>);
|
|
296
|
-
|
|
297
|
-
expect(logicCraftTransactionSpy).toHaveBeenCalledWith(
|
|
298
|
-
expect.any(Object),
|
|
299
|
-
expect.objectContaining({
|
|
300
|
-
fee: DEFAULT_ESTIMATED_FEES,
|
|
301
|
-
}),
|
|
302
|
-
);
|
|
303
|
-
});
|
|
304
|
-
});
|
package/src/api/index.ts
CHANGED
|
@@ -32,19 +32,12 @@ export function createApi(config: XrpConfig): Api<void> {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
async function craft(
|
|
36
|
-
transactionIntent: TransactionIntent<void>,
|
|
37
|
-
customFees?: bigint,
|
|
38
|
-
): Promise<string> {
|
|
35
|
+
async function craft(transactionIntent: TransactionIntent<void>): Promise<string> {
|
|
39
36
|
const nextSequenceNumber = await getNextValidSequence(transactionIntent.sender);
|
|
40
|
-
const
|
|
37
|
+
const fees = await estimateFees();
|
|
41
38
|
const tx = await craftTransaction(
|
|
42
39
|
{ address: transactionIntent.sender, nextSequenceNumber },
|
|
43
|
-
{
|
|
44
|
-
recipient: transactionIntent.recipient,
|
|
45
|
-
amount: transactionIntent.amount,
|
|
46
|
-
fee: estimatedFees,
|
|
47
|
-
},
|
|
40
|
+
{ recipient: transactionIntent.recipient, amount: transactionIntent.amount, fee: fees.fee },
|
|
48
41
|
);
|
|
49
42
|
return tx.serializedTransaction;
|
|
50
43
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NetworkDown } from "@ledgerhq/errors";
|
|
2
1
|
import BigNumber from "bignumber.js";
|
|
2
|
+
import { NetworkDown } from "@ledgerhq/errors";
|
|
3
3
|
import { getServerInfos } from "../network";
|
|
4
4
|
import { NetworkInfo } from "../types";
|
|
5
5
|
import { parseAPIValue } from "./common";
|