@ledgerhq/coin-vechain 3.0.0 → 4.0.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/.unimportedrc.json +2 -1
- package/CHANGELOG.md +42 -2699
- package/lib/api/index.d.ts +2 -2
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +25 -22
- package/lib/api/index.js.map +1 -1
- package/lib/bridge/broadcast.d.ts.map +1 -1
- package/lib/bridge/broadcast.js +2 -1
- package/lib/bridge/broadcast.js.map +1 -1
- package/lib/bridge/createTransaction.js +1 -1
- package/lib/bridge/createTransaction.js.map +1 -1
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +2 -1
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +2 -1
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib/bridge/prepareTransaction.js +4 -2
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/synchronisation.d.ts.map +1 -1
- package/lib/bridge/synchronisation.js +6 -4
- package/lib/bridge/synchronisation.js.map +1 -1
- package/lib/common-logic/calculateGasFees.d.ts +2 -1
- package/lib/common-logic/calculateGasFees.d.ts.map +1 -1
- package/lib/common-logic/calculateGasFees.js +3 -3
- package/lib/common-logic/calculateGasFees.js.map +1 -1
- package/lib/common-logic/calculateTransactionInfo.d.ts +2 -1
- package/lib/common-logic/calculateTransactionInfo.d.ts.map +1 -1
- package/lib/common-logic/calculateTransactionInfo.js +2 -2
- package/lib/common-logic/calculateTransactionInfo.js.map +1 -1
- package/lib/common-logic/estimateGas.d.ts +2 -1
- package/lib/common-logic/estimateGas.d.ts.map +1 -1
- package/lib/common-logic/estimateGas.js +2 -2
- package/lib/common-logic/estimateGas.js.map +1 -1
- package/lib/common-logic/getThorClient.d.ts +2 -1
- package/lib/common-logic/getThorClient.d.ts.map +1 -1
- package/lib/common-logic/getThorClient.js +2 -2
- package/lib/common-logic/getThorClient.js.map +1 -1
- package/lib/common-logic/mapTransfersToOperations.d.ts +3 -2
- package/lib/common-logic/mapTransfersToOperations.d.ts.map +1 -1
- package/lib/common-logic/mapTransfersToOperations.js +4 -4
- package/lib/common-logic/mapTransfersToOperations.js.map +1 -1
- package/lib/config.d.ts +10 -4
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +9 -5
- package/lib/config.js.map +1 -1
- package/lib/logic/account/getBalance.d.ts +2 -1
- package/lib/logic/account/getBalance.d.ts.map +1 -1
- package/lib/logic/account/getBalance.js +3 -2
- package/lib/logic/account/getBalance.js.map +1 -1
- package/lib/logic/history/getBlock.d.ts +2 -1
- package/lib/logic/history/getBlock.d.ts.map +1 -1
- package/lib/logic/history/getBlock.js +3 -2
- package/lib/logic/history/getBlock.js.map +1 -1
- package/lib/logic/history/getBlockInfo.d.ts +2 -1
- package/lib/logic/history/getBlockInfo.d.ts.map +1 -1
- package/lib/logic/history/getBlockInfo.js +3 -2
- package/lib/logic/history/getBlockInfo.js.map +1 -1
- package/lib/logic/history/lastBlock.d.ts +2 -1
- package/lib/logic/history/lastBlock.d.ts.map +1 -1
- package/lib/logic/history/lastBlock.js +4 -3
- package/lib/logic/history/lastBlock.js.map +1 -1
- package/lib/logic/history/listOperations.d.ts +2 -1
- package/lib/logic/history/listOperations.d.ts.map +1 -1
- package/lib/logic/history/listOperations.js +5 -4
- package/lib/logic/history/listOperations.js.map +1 -1
- package/lib/logic/transaction/broadcast.d.ts +2 -1
- package/lib/logic/transaction/broadcast.d.ts.map +1 -1
- package/lib/logic/transaction/broadcast.js +3 -2
- package/lib/logic/transaction/broadcast.js.map +1 -1
- package/lib/logic/transaction/combine.d.ts +1 -1
- package/lib/logic/transaction/combine.d.ts.map +1 -1
- package/lib/logic/transaction/combine.js +4 -1
- package/lib/logic/transaction/combine.js.map +1 -1
- package/lib/logic/transaction/craftTransaction.d.ts +2 -1
- package/lib/logic/transaction/craftTransaction.d.ts.map +1 -1
- package/lib/logic/transaction/craftTransaction.js +11 -10
- package/lib/logic/transaction/craftTransaction.js.map +1 -1
- package/lib/logic/transaction/estimateFees.d.ts +2 -1
- package/lib/logic/transaction/estimateFees.d.ts.map +1 -1
- package/lib/logic/transaction/estimateFees.js +2 -2
- package/lib/logic/transaction/estimateFees.js.map +1 -1
- package/lib/network/getBlock.d.ts +2 -1
- package/lib/network/getBlock.d.ts.map +1 -1
- package/lib/network/getBlock.js +2 -2
- package/lib/network/getBlock.js.map +1 -1
- package/lib/network/getFees.d.ts +2 -1
- package/lib/network/getFees.d.ts.map +1 -1
- package/lib/network/getFees.js +2 -2
- package/lib/network/getFees.js.map +1 -1
- package/lib/network/sdk.d.ts +7 -6
- package/lib/network/sdk.d.ts.map +1 -1
- package/lib/network/sdk.js +18 -18
- package/lib/network/sdk.js.map +1 -1
- package/lib/test/context.d.ts +6 -0
- package/lib/test/context.d.ts.map +1 -0
- package/lib/test/context.js +15 -0
- package/lib/test/context.js.map +1 -0
- package/lib-es/api/index.d.ts +2 -2
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +25 -22
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/bridge/broadcast.d.ts.map +1 -1
- package/lib-es/bridge/broadcast.js +2 -1
- package/lib-es/bridge/broadcast.js.map +1 -1
- package/lib-es/bridge/createTransaction.js +2 -2
- package/lib-es/bridge/createTransaction.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +2 -1
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +2 -1
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +4 -2
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/synchronisation.d.ts.map +1 -1
- package/lib-es/bridge/synchronisation.js +6 -4
- package/lib-es/bridge/synchronisation.js.map +1 -1
- package/lib-es/common-logic/calculateGasFees.d.ts +2 -1
- package/lib-es/common-logic/calculateGasFees.d.ts.map +1 -1
- package/lib-es/common-logic/calculateGasFees.js +3 -3
- package/lib-es/common-logic/calculateGasFees.js.map +1 -1
- package/lib-es/common-logic/calculateTransactionInfo.d.ts +2 -1
- package/lib-es/common-logic/calculateTransactionInfo.d.ts.map +1 -1
- package/lib-es/common-logic/calculateTransactionInfo.js +2 -2
- package/lib-es/common-logic/calculateTransactionInfo.js.map +1 -1
- package/lib-es/common-logic/estimateGas.d.ts +2 -1
- package/lib-es/common-logic/estimateGas.d.ts.map +1 -1
- package/lib-es/common-logic/estimateGas.js +2 -2
- package/lib-es/common-logic/estimateGas.js.map +1 -1
- package/lib-es/common-logic/getThorClient.d.ts +2 -1
- package/lib-es/common-logic/getThorClient.d.ts.map +1 -1
- package/lib-es/common-logic/getThorClient.js +2 -2
- package/lib-es/common-logic/getThorClient.js.map +1 -1
- package/lib-es/common-logic/mapTransfersToOperations.d.ts +3 -2
- package/lib-es/common-logic/mapTransfersToOperations.d.ts.map +1 -1
- package/lib-es/common-logic/mapTransfersToOperations.js +4 -4
- package/lib-es/common-logic/mapTransfersToOperations.js.map +1 -1
- package/lib-es/config.d.ts +10 -4
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js +9 -5
- package/lib-es/config.js.map +1 -1
- package/lib-es/logic/account/getBalance.d.ts +2 -1
- package/lib-es/logic/account/getBalance.d.ts.map +1 -1
- package/lib-es/logic/account/getBalance.js +3 -2
- package/lib-es/logic/account/getBalance.js.map +1 -1
- package/lib-es/logic/history/getBlock.d.ts +2 -1
- package/lib-es/logic/history/getBlock.d.ts.map +1 -1
- package/lib-es/logic/history/getBlock.js +3 -2
- package/lib-es/logic/history/getBlock.js.map +1 -1
- package/lib-es/logic/history/getBlockInfo.d.ts +2 -1
- package/lib-es/logic/history/getBlockInfo.d.ts.map +1 -1
- package/lib-es/logic/history/getBlockInfo.js +3 -2
- package/lib-es/logic/history/getBlockInfo.js.map +1 -1
- package/lib-es/logic/history/lastBlock.d.ts +2 -1
- package/lib-es/logic/history/lastBlock.d.ts.map +1 -1
- package/lib-es/logic/history/lastBlock.js +4 -3
- package/lib-es/logic/history/lastBlock.js.map +1 -1
- package/lib-es/logic/history/listOperations.d.ts +2 -1
- package/lib-es/logic/history/listOperations.d.ts.map +1 -1
- package/lib-es/logic/history/listOperations.js +5 -4
- package/lib-es/logic/history/listOperations.js.map +1 -1
- package/lib-es/logic/transaction/broadcast.d.ts +2 -1
- package/lib-es/logic/transaction/broadcast.d.ts.map +1 -1
- package/lib-es/logic/transaction/broadcast.js +3 -2
- package/lib-es/logic/transaction/broadcast.js.map +1 -1
- package/lib-es/logic/transaction/combine.d.ts +1 -1
- package/lib-es/logic/transaction/combine.d.ts.map +1 -1
- package/lib-es/logic/transaction/combine.js +4 -1
- package/lib-es/logic/transaction/combine.js.map +1 -1
- package/lib-es/logic/transaction/craftTransaction.d.ts +2 -1
- package/lib-es/logic/transaction/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/transaction/craftTransaction.js +11 -10
- package/lib-es/logic/transaction/craftTransaction.js.map +1 -1
- package/lib-es/logic/transaction/estimateFees.d.ts +2 -1
- package/lib-es/logic/transaction/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/transaction/estimateFees.js +2 -2
- package/lib-es/logic/transaction/estimateFees.js.map +1 -1
- package/lib-es/network/getBlock.d.ts +2 -1
- package/lib-es/network/getBlock.d.ts.map +1 -1
- package/lib-es/network/getBlock.js +2 -2
- package/lib-es/network/getBlock.js.map +1 -1
- package/lib-es/network/getFees.d.ts +2 -1
- package/lib-es/network/getFees.d.ts.map +1 -1
- package/lib-es/network/getFees.js +2 -2
- package/lib-es/network/getFees.js.map +1 -1
- package/lib-es/network/sdk.d.ts +7 -6
- package/lib-es/network/sdk.d.ts.map +1 -1
- package/lib-es/network/sdk.js +18 -18
- package/lib-es/network/sdk.js.map +1 -1
- package/lib-es/test/context.d.ts +6 -0
- package/lib-es/test/context.d.ts.map +1 -0
- package/lib-es/test/context.js +11 -0
- package/lib-es/test/context.js.map +1 -0
- package/package.json +6 -6
- package/src/api/index.integ.test.ts +21 -24
- package/src/api/index.ts +74 -27
- package/src/api/index.unit.test.ts +68 -48
- package/src/bridge/broadcast.integ.test.ts +2 -1
- package/src/bridge/broadcast.test.ts +1 -1
- package/src/bridge/broadcast.ts +2 -1
- package/src/bridge/createTransaction.ts +2 -2
- package/src/bridge/estimateMaxSpendable.test.ts +19 -3
- package/src/bridge/estimateMaxSpendable.ts +2 -0
- package/src/bridge/getTransactionStatus.test.ts +11 -6
- package/src/bridge/getTransactionStatus.ts +2 -0
- package/src/bridge/prepareTransaction.test.ts +5 -1
- package/src/bridge/prepareTransaction.ts +4 -2
- package/src/bridge/synchronisation.ts +7 -3
- package/src/common-logic/calculateGasFees.test.ts +101 -27
- package/src/common-logic/calculateGasFees.ts +4 -2
- package/src/common-logic/calculateTransactionInfo.test.ts +71 -16
- package/src/common-logic/calculateTransactionInfo.ts +3 -1
- package/src/common-logic/estimateGas.test.ts +13 -10
- package/src/common-logic/estimateGas.ts +3 -1
- package/src/common-logic/getThorClient.test.ts +7 -7
- package/src/common-logic/getThorClient.ts +3 -3
- package/src/common-logic/mapTransfersToOperations.test.ts +48 -13
- package/src/common-logic/mapTransfersToOperations.ts +5 -2
- package/src/config.test.ts +3 -3
- package/src/config.ts +13 -6
- package/src/logic/account/getBalance.ts +4 -2
- package/src/logic/account/getBalance.unit.test.ts +6 -4
- package/src/logic/history/getBlock.ts +4 -2
- package/src/logic/history/getBlock.unit.test.ts +8 -5
- package/src/logic/history/getBlockInfo.ts +4 -2
- package/src/logic/history/getBlockInfo.unit.test.ts +6 -3
- package/src/logic/history/lastBlock.ts +5 -3
- package/src/logic/history/lastBlock.unit.test.ts +6 -3
- package/src/logic/history/listOperations.ts +6 -3
- package/src/logic/history/listOperations.unit.test.ts +10 -6
- package/src/logic/transaction/broadcast.msw.test.ts +7 -2
- package/src/logic/transaction/broadcast.ts +8 -2
- package/src/logic/transaction/broadcast.unit.test.ts +6 -3
- package/src/logic/transaction/combine.ts +6 -2
- package/src/logic/transaction/combine.unit.test.ts +3 -3
- package/src/logic/transaction/craftTransaction.ts +16 -9
- package/src/logic/transaction/craftTransaction.unit.test.ts +29 -28
- package/src/logic/transaction/estimateFees.ts +3 -0
- package/src/logic/transaction/estimateFees.unit.test.ts +15 -12
- package/src/network/getBlock.ts +3 -2
- package/src/network/getBlock.unit.test.ts +11 -6
- package/src/network/getFees.ts +6 -3
- package/src/network/sdk.integ.test.ts +8 -1
- package/src/network/sdk.test.ts +18 -7
- package/src/network/sdk.ts +25 -15
- package/src/test/context.ts +15 -0
package/src/network/getFees.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
2
|
import network from "@ledgerhq/live-network";
|
|
3
|
-
import { getNodeUrl } from "../config";
|
|
3
|
+
import { getNodeUrl, type VechainCurrencyConfig } from "../config";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Get fees paid for the transaction
|
|
7
7
|
* @param transactionId - the id of the transaction
|
|
8
8
|
* @return the fee paid in VTHO or 0
|
|
9
9
|
*/
|
|
10
|
-
export const getFees = async (
|
|
10
|
+
export const getFees = async (
|
|
11
|
+
config: VechainCurrencyConfig,
|
|
12
|
+
transactionId: string,
|
|
13
|
+
): Promise<BigNumber> => {
|
|
11
14
|
const { data } = await network<{ paid: string }>({
|
|
12
15
|
method: "GET",
|
|
13
|
-
url: `${getNodeUrl()}/transactions/${transactionId}/receipt`,
|
|
16
|
+
url: `${getNodeUrl(config)}/transactions/${transactionId}/receipt`,
|
|
14
17
|
params: { id: transactionId },
|
|
15
18
|
});
|
|
16
19
|
|
|
@@ -3,9 +3,10 @@ import { http, HttpResponse } from "msw";
|
|
|
3
3
|
import { setupServer } from "msw/node";
|
|
4
4
|
import { EventLog, TransferLog, VetTxsQuery } from "../types";
|
|
5
5
|
import { TEST_VECHAIN_ENDPOINT } from "../test/constants";
|
|
6
|
-
import { setCoinConfig } from "../config";
|
|
6
|
+
import { setCoinConfig, type VechainCurrencyConfig } from "../config";
|
|
7
7
|
|
|
8
8
|
const BASE_URL = TEST_VECHAIN_ENDPOINT;
|
|
9
|
+
const config: VechainCurrencyConfig = { status: { type: "active" }, node: { url: BASE_URL } };
|
|
9
10
|
const LAST_BLOCK_COUNT = 24580112;
|
|
10
11
|
const MAX_OPS_IN_BLOCK_RANGE = 1000;
|
|
11
12
|
const N_OPS_IN_BLOCK = 3;
|
|
@@ -114,6 +115,7 @@ describe("sdk", () => {
|
|
|
114
115
|
describe("when logged operations are less than 1000 in the given range", () => {
|
|
115
116
|
test("retrieves all the operations", async () => {
|
|
116
117
|
const operations = await getOperations(
|
|
118
|
+
config,
|
|
117
119
|
"my-account-id",
|
|
118
120
|
"0xmy-address",
|
|
119
121
|
LAST_BLOCK_COUNT - 332,
|
|
@@ -128,6 +130,7 @@ describe("sdk", () => {
|
|
|
128
130
|
describe("when logged operations are more than 1000 in the given range", () => {
|
|
129
131
|
test("retrieves all the operations", async () => {
|
|
130
132
|
const operations = await getOperations(
|
|
133
|
+
config,
|
|
131
134
|
"my-account-id",
|
|
132
135
|
"0xmy-address",
|
|
133
136
|
LAST_BLOCK_COUNT - 333,
|
|
@@ -148,6 +151,7 @@ describe("sdk", () => {
|
|
|
148
151
|
test("rethrows the error", async () => {
|
|
149
152
|
try {
|
|
150
153
|
await getOperations(
|
|
154
|
+
config,
|
|
151
155
|
"my-account-id",
|
|
152
156
|
"0xmy-address",
|
|
153
157
|
LAST_BLOCK_COUNT - 5,
|
|
@@ -167,6 +171,7 @@ describe("sdk", () => {
|
|
|
167
171
|
describe("when logged operations are less than 1000 in the given range", () => {
|
|
168
172
|
test("retrieves all the operations", async () => {
|
|
169
173
|
const operations = await getTokenOperations(
|
|
174
|
+
config,
|
|
170
175
|
"my-account-id",
|
|
171
176
|
"0xmy-address",
|
|
172
177
|
"0xmy-token-address",
|
|
@@ -182,6 +187,7 @@ describe("sdk", () => {
|
|
|
182
187
|
describe("when logged operations are more than 1000 in the given range", () => {
|
|
183
188
|
test("retrieves all the operations", async () => {
|
|
184
189
|
const operations = await getTokenOperations(
|
|
190
|
+
config,
|
|
185
191
|
"my-account-id",
|
|
186
192
|
"0xmy-address",
|
|
187
193
|
"0xmy-token-address",
|
|
@@ -203,6 +209,7 @@ describe("sdk", () => {
|
|
|
203
209
|
test("rethrows the error", async () => {
|
|
204
210
|
try {
|
|
205
211
|
await getTokenOperations(
|
|
212
|
+
config,
|
|
206
213
|
"my-account-id",
|
|
207
214
|
"0xmy-address",
|
|
208
215
|
"0xmy-token-address",
|
package/src/network/sdk.test.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from "./sdk";
|
|
12
12
|
import { getFees } from "./getFees";
|
|
13
13
|
import type { AccountResponse, VechainSDKTransaction } from "../types";
|
|
14
|
+
import { mockVechainConfig } from "../test/context";
|
|
14
15
|
|
|
15
16
|
const LAST_BLOCK_COUNT = 24580112;
|
|
16
17
|
const mockAccount = {
|
|
@@ -105,21 +106,21 @@ const throws500ServerError = () => {
|
|
|
105
106
|
describe("sdk", () => {
|
|
106
107
|
describe("getAccount", () => {
|
|
107
108
|
test("retrieves an account", async () => {
|
|
108
|
-
const account = await getAccount("0xmy-address");
|
|
109
|
+
const account = await getAccount(mockVechainConfig, "0xmy-address");
|
|
109
110
|
expect(account).toBe(mockAccount);
|
|
110
111
|
});
|
|
111
112
|
});
|
|
112
113
|
|
|
113
114
|
describe("getLastBlockHeight", () => {
|
|
114
115
|
test("retrieves the last block height", async () => {
|
|
115
|
-
const account = await getLastBlockHeight();
|
|
116
|
+
const account = await getLastBlockHeight(mockVechainConfig);
|
|
116
117
|
expect(account).toBe(LAST_BLOCK_COUNT);
|
|
117
118
|
});
|
|
118
119
|
});
|
|
119
120
|
|
|
120
121
|
describe("getBlockRef", () => {
|
|
121
122
|
test("retrieves the block ref to use in transaction", async () => {
|
|
122
|
-
const account = await getBlockRef();
|
|
123
|
+
const account = await getBlockRef(mockVechainConfig);
|
|
123
124
|
expect(account).toBe("abcdefghiklmnopqrs");
|
|
124
125
|
});
|
|
125
126
|
});
|
|
@@ -129,14 +130,14 @@ describe("sdk", () => {
|
|
|
129
130
|
test("retrieves fees paid for the transaction", async () => {
|
|
130
131
|
mockGetFees.mockImplementationOnce(async () => ({ data: {} }));
|
|
131
132
|
|
|
132
|
-
const account = await getFees("0xtransaxtion");
|
|
133
|
+
const account = await getFees(mockVechainConfig, "0xtransaxtion");
|
|
133
134
|
expect(account).toStrictEqual(new BigNumber(0));
|
|
134
135
|
});
|
|
135
136
|
});
|
|
136
137
|
|
|
137
138
|
describe("when the transaction's receipt has data.paid", () => {
|
|
138
139
|
test("retrieves fees paid for the transaction", async () => {
|
|
139
|
-
const account = await getFees("0xtransaxtion");
|
|
140
|
+
const account = await getFees(mockVechainConfig, "0xtransaxtion");
|
|
140
141
|
expect(account).toStrictEqual(new BigNumber(42));
|
|
141
142
|
});
|
|
142
143
|
});
|
|
@@ -145,7 +146,7 @@ describe("sdk", () => {
|
|
|
145
146
|
describe("submit", () => {
|
|
146
147
|
describe("when transaction id is included in the transaction payload returned by the server", () => {
|
|
147
148
|
test("returns the transaction id", async () => {
|
|
148
|
-
const transactionId = await submit(mockTransaction);
|
|
149
|
+
const transactionId = await submit(mockVechainConfig, mockTransaction);
|
|
149
150
|
expect(transactionId).toBe("123");
|
|
150
151
|
});
|
|
151
152
|
});
|
|
@@ -155,7 +156,7 @@ describe("sdk", () => {
|
|
|
155
156
|
mockSubmit.mockImplementationOnce(async () => ({ data: {} }));
|
|
156
157
|
|
|
157
158
|
try {
|
|
158
|
-
await submit(mockTransaction);
|
|
159
|
+
await submit(mockVechainConfig, mockTransaction);
|
|
159
160
|
} catch (err: unknown) {
|
|
160
161
|
const error = err as { message: string };
|
|
161
162
|
expect(error.message).toMatch("Expected an ID");
|
|
@@ -175,6 +176,7 @@ describe("sdk", () => {
|
|
|
175
176
|
test("rethrows the error", async () => {
|
|
176
177
|
try {
|
|
177
178
|
await getOperations(
|
|
179
|
+
mockVechainConfig,
|
|
178
180
|
"my-account-id",
|
|
179
181
|
"0xmy-address",
|
|
180
182
|
LAST_BLOCK_COUNT - 1,
|
|
@@ -192,6 +194,7 @@ describe("sdk", () => {
|
|
|
192
194
|
describe("when logs retrieved in each network request are within the maximum allowed limit", () => {
|
|
193
195
|
test("retrieves all the operations", async () => {
|
|
194
196
|
const operations = await getOperations(
|
|
197
|
+
mockVechainConfig,
|
|
195
198
|
"my-account-id",
|
|
196
199
|
"0xmy-address",
|
|
197
200
|
LAST_BLOCK_COUNT - 1,
|
|
@@ -207,6 +210,7 @@ describe("sdk", () => {
|
|
|
207
210
|
test("returns an empty array without querying the network", async () => {
|
|
208
211
|
mockGetTransferLogs.mockClear();
|
|
209
212
|
const operations = await getOperations(
|
|
213
|
+
mockVechainConfig,
|
|
210
214
|
"my-account-id",
|
|
211
215
|
"0xmy-address",
|
|
212
216
|
LAST_BLOCK_COUNT + 1,
|
|
@@ -227,6 +231,7 @@ describe("sdk", () => {
|
|
|
227
231
|
test("throws an error: Unable to split Vechain operations range further", async () => {
|
|
228
232
|
try {
|
|
229
233
|
await getOperations(
|
|
234
|
+
mockVechainConfig,
|
|
230
235
|
"my-account-id",
|
|
231
236
|
"0xmy-address",
|
|
232
237
|
LAST_BLOCK_COUNT - 1,
|
|
@@ -244,6 +249,7 @@ describe("sdk", () => {
|
|
|
244
249
|
describe("and Vechain operations range can be split further", () => {
|
|
245
250
|
test("retrieves all the operations", async () => {
|
|
246
251
|
const operations = await getOperations(
|
|
252
|
+
mockVechainConfig,
|
|
247
253
|
"my-account-id",
|
|
248
254
|
"0xmy-address",
|
|
249
255
|
LAST_BLOCK_COUNT - 6,
|
|
@@ -266,6 +272,7 @@ describe("sdk", () => {
|
|
|
266
272
|
test("rethrows the error", async () => {
|
|
267
273
|
try {
|
|
268
274
|
await getOperations(
|
|
275
|
+
mockVechainConfig,
|
|
269
276
|
"my-account-id",
|
|
270
277
|
"0xmy-address",
|
|
271
278
|
LAST_BLOCK_COUNT - 1,
|
|
@@ -283,6 +290,7 @@ describe("sdk", () => {
|
|
|
283
290
|
describe("when logs retrieved in each network request are within the maximum allowed limit", () => {
|
|
284
291
|
test("retrieves all the operations", async () => {
|
|
285
292
|
const operations = await getTokenOperations(
|
|
293
|
+
mockVechainConfig,
|
|
286
294
|
"my-account-id",
|
|
287
295
|
"0xmy-address",
|
|
288
296
|
"0xmy-token-address",
|
|
@@ -299,6 +307,7 @@ describe("sdk", () => {
|
|
|
299
307
|
test("returns an empty array without querying the network", async () => {
|
|
300
308
|
mockGetEventLogs.mockClear();
|
|
301
309
|
const operations = await getTokenOperations(
|
|
310
|
+
mockVechainConfig,
|
|
302
311
|
"my-account-id",
|
|
303
312
|
"0xmy-address",
|
|
304
313
|
"0xmy-token-address",
|
|
@@ -320,6 +329,7 @@ describe("sdk", () => {
|
|
|
320
329
|
test("throws an error: Unable to split Vechain operations range further", async () => {
|
|
321
330
|
try {
|
|
322
331
|
await getTokenOperations(
|
|
332
|
+
mockVechainConfig,
|
|
323
333
|
"my-account-id",
|
|
324
334
|
"0xmy-address",
|
|
325
335
|
"0xmt-token-address",
|
|
@@ -338,6 +348,7 @@ describe("sdk", () => {
|
|
|
338
348
|
describe("and Vechain operations range can be split further", () => {
|
|
339
349
|
test("retrieves all the operations", async () => {
|
|
340
350
|
const operations = await getTokenOperations(
|
|
351
|
+
mockVechainConfig,
|
|
341
352
|
"my-account-id",
|
|
342
353
|
"0xmy-address",
|
|
343
354
|
"0xmt-token-address",
|
package/src/network/sdk.ts
CHANGED
|
@@ -13,26 +13,29 @@ import {
|
|
|
13
13
|
mapTokenTransfersToOperations,
|
|
14
14
|
padAddress,
|
|
15
15
|
} from "../common-logic";
|
|
16
|
-
import { getNodeUrl } from "../config";
|
|
16
|
+
import { getNodeUrl, type VechainCurrencyConfig } from "../config";
|
|
17
17
|
|
|
18
18
|
const NET_ERROR_LOG_TRANSFERS_LIMIT = {
|
|
19
19
|
status: 403,
|
|
20
20
|
msgPattern: /exceeds the maximum allowed/,
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
-
export const getAccount = async (
|
|
23
|
+
export const getAccount = async (
|
|
24
|
+
config: VechainCurrencyConfig,
|
|
25
|
+
address: string,
|
|
26
|
+
): Promise<AccountResponse> => {
|
|
24
27
|
const { data } = await network<AccountResponse>({
|
|
25
28
|
method: "GET",
|
|
26
|
-
url: `${getNodeUrl()}/accounts/${address}`,
|
|
29
|
+
url: `${getNodeUrl(config)}/accounts/${address}`,
|
|
27
30
|
});
|
|
28
31
|
|
|
29
32
|
return data;
|
|
30
33
|
};
|
|
31
34
|
|
|
32
|
-
export const getLastBlockHeight = async (): Promise<number> => {
|
|
35
|
+
export const getLastBlockHeight = async (config: VechainCurrencyConfig): Promise<number> => {
|
|
33
36
|
const { data } = await network<{ number: number }>({
|
|
34
37
|
method: "GET",
|
|
35
|
-
url: `${getNodeUrl()}/blocks/best`,
|
|
38
|
+
url: `${getNodeUrl(config)}/blocks/best`,
|
|
36
39
|
});
|
|
37
40
|
|
|
38
41
|
return data.number;
|
|
@@ -47,6 +50,7 @@ export const getLastBlockHeight = async (): Promise<number> => {
|
|
|
47
50
|
* @returns an array of operations
|
|
48
51
|
*/
|
|
49
52
|
const fetchRangeOfOperations = async (
|
|
53
|
+
config: VechainCurrencyConfig,
|
|
50
54
|
accountId: string,
|
|
51
55
|
addr: string,
|
|
52
56
|
startAt: number,
|
|
@@ -64,11 +68,11 @@ const fetchRangeOfOperations = async (
|
|
|
64
68
|
|
|
65
69
|
const { data } = await network<TransferLog[]>({
|
|
66
70
|
method: "POST",
|
|
67
|
-
url: `${getNodeUrl()}/logs/transfer`,
|
|
71
|
+
url: `${getNodeUrl(config)}/logs/transfer`,
|
|
68
72
|
data: JSON.stringify(query),
|
|
69
73
|
});
|
|
70
74
|
|
|
71
|
-
return mapVetTransfersToOperations(data, accountId, addr);
|
|
75
|
+
return mapVetTransfersToOperations(config, data, accountId, addr);
|
|
72
76
|
};
|
|
73
77
|
|
|
74
78
|
/**
|
|
@@ -80,6 +84,7 @@ const fetchRangeOfOperations = async (
|
|
|
80
84
|
* @returns an array of operations
|
|
81
85
|
*/
|
|
82
86
|
const fetchRangeOfTokenOperations = async (
|
|
87
|
+
config: VechainCurrencyConfig,
|
|
83
88
|
accountId: string,
|
|
84
89
|
addr: string,
|
|
85
90
|
tokenAddr: string,
|
|
@@ -114,11 +119,11 @@ const fetchRangeOfTokenOperations = async (
|
|
|
114
119
|
|
|
115
120
|
const { data } = await network<EventLog[]>({
|
|
116
121
|
method: "POST",
|
|
117
|
-
url: `${getNodeUrl()}/logs/event`,
|
|
122
|
+
url: `${getNodeUrl(config)}/logs/event`,
|
|
118
123
|
data: JSON.stringify(query),
|
|
119
124
|
});
|
|
120
125
|
|
|
121
|
-
return mapTokenTransfersToOperations(data, accountId, addr);
|
|
126
|
+
return mapTokenTransfersToOperations(config, data, accountId, addr);
|
|
122
127
|
};
|
|
123
128
|
|
|
124
129
|
/**
|
|
@@ -213,13 +218,14 @@ const getLogsWithPagination = async (
|
|
|
213
218
|
* @returns an array of operations
|
|
214
219
|
*/
|
|
215
220
|
export const getOperations = async (
|
|
221
|
+
config: VechainCurrencyConfig,
|
|
216
222
|
accountId: string,
|
|
217
223
|
addr: string,
|
|
218
224
|
startAt: number,
|
|
219
225
|
stopAt: number,
|
|
220
226
|
): Promise<Operation[]> => {
|
|
221
227
|
const fetchRange = async (from: number, to: number) =>
|
|
222
|
-
fetchRangeOfOperations(accountId, addr, from, to);
|
|
228
|
+
fetchRangeOfOperations(config, accountId, addr, from, to);
|
|
223
229
|
return getLogsWithPagination(startAt, stopAt, fetchRange);
|
|
224
230
|
};
|
|
225
231
|
|
|
@@ -234,6 +240,7 @@ export const getOperations = async (
|
|
|
234
240
|
* @returns an array of operations
|
|
235
241
|
*/
|
|
236
242
|
export const getTokenOperations = async (
|
|
243
|
+
config: VechainCurrencyConfig,
|
|
237
244
|
accountId: string,
|
|
238
245
|
addr: string,
|
|
239
246
|
tokenAddr: string,
|
|
@@ -241,7 +248,7 @@ export const getTokenOperations = async (
|
|
|
241
248
|
stopAt: number,
|
|
242
249
|
): Promise<Operation[]> => {
|
|
243
250
|
const fetchRange = async (from: number, to: number) =>
|
|
244
|
-
fetchRangeOfTokenOperations(accountId, addr, tokenAddr, from, to);
|
|
251
|
+
fetchRangeOfTokenOperations(config, accountId, addr, tokenAddr, from, to);
|
|
245
252
|
return getLogsWithPagination(startAt, stopAt, fetchRange);
|
|
246
253
|
};
|
|
247
254
|
|
|
@@ -250,14 +257,17 @@ export const getTokenOperations = async (
|
|
|
250
257
|
* @param transaction - The transaction to submit
|
|
251
258
|
* @returns transaction ID
|
|
252
259
|
*/
|
|
253
|
-
export const submit = async (
|
|
260
|
+
export const submit = async (
|
|
261
|
+
config: VechainCurrencyConfig,
|
|
262
|
+
transaction: VechainSDKTransaction,
|
|
263
|
+
): Promise<string> => {
|
|
254
264
|
const encodedRawTx = {
|
|
255
265
|
raw: `0x${Buffer.from(transaction.encoded).toString("hex")}`,
|
|
256
266
|
};
|
|
257
267
|
|
|
258
268
|
const { data } = await network<{ id: string }>({
|
|
259
269
|
method: "POST",
|
|
260
|
-
url: `${getNodeUrl()}/transactions`,
|
|
270
|
+
url: `${getNodeUrl(config)}/transactions`,
|
|
261
271
|
data: encodedRawTx,
|
|
262
272
|
});
|
|
263
273
|
|
|
@@ -271,10 +281,10 @@ export const submit = async (transaction: VechainSDKTransaction): Promise<string
|
|
|
271
281
|
* Get the block ref to use in a transaction
|
|
272
282
|
* @returns the block ref of head
|
|
273
283
|
*/
|
|
274
|
-
export const getBlockRef = async (): Promise<string> => {
|
|
284
|
+
export const getBlockRef = async (config: VechainCurrencyConfig): Promise<string> => {
|
|
275
285
|
const { data } = await network<{ id: string }>({
|
|
276
286
|
method: "GET",
|
|
277
|
-
url: `${getNodeUrl()}/blocks/best`,
|
|
287
|
+
url: `${getNodeUrl(config)}/blocks/best`,
|
|
278
288
|
});
|
|
279
289
|
|
|
280
290
|
return data.id.slice(0, 18);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { VechainContext, VechainCurrencyConfig } from "../config";
|
|
2
|
+
|
|
3
|
+
/** The resolved config every mocked endpoint points at. */
|
|
4
|
+
export const mockVechainConfig: VechainCurrencyConfig = {
|
|
5
|
+
status: { type: "active" },
|
|
6
|
+
node: { url: "https://vechain.coin.ledger.com" },
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/** A {@link VechainContext} backed by the mocked config, for api tests. */
|
|
10
|
+
export const createMockVechainContext = (
|
|
11
|
+
config: VechainCurrencyConfig = mockVechainConfig,
|
|
12
|
+
): VechainContext => ({
|
|
13
|
+
config: async () => config,
|
|
14
|
+
logger: () => {},
|
|
15
|
+
});
|