@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.
Files changed (249) hide show
  1. package/.unimportedrc.json +2 -1
  2. package/CHANGELOG.md +42 -2699
  3. package/lib/api/index.d.ts +2 -2
  4. package/lib/api/index.d.ts.map +1 -1
  5. package/lib/api/index.js +25 -22
  6. package/lib/api/index.js.map +1 -1
  7. package/lib/bridge/broadcast.d.ts.map +1 -1
  8. package/lib/bridge/broadcast.js +2 -1
  9. package/lib/bridge/broadcast.js.map +1 -1
  10. package/lib/bridge/createTransaction.js +1 -1
  11. package/lib/bridge/createTransaction.js.map +1 -1
  12. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
  13. package/lib/bridge/estimateMaxSpendable.js +2 -1
  14. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  15. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  16. package/lib/bridge/getTransactionStatus.js +2 -1
  17. package/lib/bridge/getTransactionStatus.js.map +1 -1
  18. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  19. package/lib/bridge/prepareTransaction.js +4 -2
  20. package/lib/bridge/prepareTransaction.js.map +1 -1
  21. package/lib/bridge/synchronisation.d.ts.map +1 -1
  22. package/lib/bridge/synchronisation.js +6 -4
  23. package/lib/bridge/synchronisation.js.map +1 -1
  24. package/lib/common-logic/calculateGasFees.d.ts +2 -1
  25. package/lib/common-logic/calculateGasFees.d.ts.map +1 -1
  26. package/lib/common-logic/calculateGasFees.js +3 -3
  27. package/lib/common-logic/calculateGasFees.js.map +1 -1
  28. package/lib/common-logic/calculateTransactionInfo.d.ts +2 -1
  29. package/lib/common-logic/calculateTransactionInfo.d.ts.map +1 -1
  30. package/lib/common-logic/calculateTransactionInfo.js +2 -2
  31. package/lib/common-logic/calculateTransactionInfo.js.map +1 -1
  32. package/lib/common-logic/estimateGas.d.ts +2 -1
  33. package/lib/common-logic/estimateGas.d.ts.map +1 -1
  34. package/lib/common-logic/estimateGas.js +2 -2
  35. package/lib/common-logic/estimateGas.js.map +1 -1
  36. package/lib/common-logic/getThorClient.d.ts +2 -1
  37. package/lib/common-logic/getThorClient.d.ts.map +1 -1
  38. package/lib/common-logic/getThorClient.js +2 -2
  39. package/lib/common-logic/getThorClient.js.map +1 -1
  40. package/lib/common-logic/mapTransfersToOperations.d.ts +3 -2
  41. package/lib/common-logic/mapTransfersToOperations.d.ts.map +1 -1
  42. package/lib/common-logic/mapTransfersToOperations.js +4 -4
  43. package/lib/common-logic/mapTransfersToOperations.js.map +1 -1
  44. package/lib/config.d.ts +10 -4
  45. package/lib/config.d.ts.map +1 -1
  46. package/lib/config.js +9 -5
  47. package/lib/config.js.map +1 -1
  48. package/lib/logic/account/getBalance.d.ts +2 -1
  49. package/lib/logic/account/getBalance.d.ts.map +1 -1
  50. package/lib/logic/account/getBalance.js +3 -2
  51. package/lib/logic/account/getBalance.js.map +1 -1
  52. package/lib/logic/history/getBlock.d.ts +2 -1
  53. package/lib/logic/history/getBlock.d.ts.map +1 -1
  54. package/lib/logic/history/getBlock.js +3 -2
  55. package/lib/logic/history/getBlock.js.map +1 -1
  56. package/lib/logic/history/getBlockInfo.d.ts +2 -1
  57. package/lib/logic/history/getBlockInfo.d.ts.map +1 -1
  58. package/lib/logic/history/getBlockInfo.js +3 -2
  59. package/lib/logic/history/getBlockInfo.js.map +1 -1
  60. package/lib/logic/history/lastBlock.d.ts +2 -1
  61. package/lib/logic/history/lastBlock.d.ts.map +1 -1
  62. package/lib/logic/history/lastBlock.js +4 -3
  63. package/lib/logic/history/lastBlock.js.map +1 -1
  64. package/lib/logic/history/listOperations.d.ts +2 -1
  65. package/lib/logic/history/listOperations.d.ts.map +1 -1
  66. package/lib/logic/history/listOperations.js +5 -4
  67. package/lib/logic/history/listOperations.js.map +1 -1
  68. package/lib/logic/transaction/broadcast.d.ts +2 -1
  69. package/lib/logic/transaction/broadcast.d.ts.map +1 -1
  70. package/lib/logic/transaction/broadcast.js +3 -2
  71. package/lib/logic/transaction/broadcast.js.map +1 -1
  72. package/lib/logic/transaction/combine.d.ts +1 -1
  73. package/lib/logic/transaction/combine.d.ts.map +1 -1
  74. package/lib/logic/transaction/combine.js +4 -1
  75. package/lib/logic/transaction/combine.js.map +1 -1
  76. package/lib/logic/transaction/craftTransaction.d.ts +2 -1
  77. package/lib/logic/transaction/craftTransaction.d.ts.map +1 -1
  78. package/lib/logic/transaction/craftTransaction.js +11 -10
  79. package/lib/logic/transaction/craftTransaction.js.map +1 -1
  80. package/lib/logic/transaction/estimateFees.d.ts +2 -1
  81. package/lib/logic/transaction/estimateFees.d.ts.map +1 -1
  82. package/lib/logic/transaction/estimateFees.js +2 -2
  83. package/lib/logic/transaction/estimateFees.js.map +1 -1
  84. package/lib/network/getBlock.d.ts +2 -1
  85. package/lib/network/getBlock.d.ts.map +1 -1
  86. package/lib/network/getBlock.js +2 -2
  87. package/lib/network/getBlock.js.map +1 -1
  88. package/lib/network/getFees.d.ts +2 -1
  89. package/lib/network/getFees.d.ts.map +1 -1
  90. package/lib/network/getFees.js +2 -2
  91. package/lib/network/getFees.js.map +1 -1
  92. package/lib/network/sdk.d.ts +7 -6
  93. package/lib/network/sdk.d.ts.map +1 -1
  94. package/lib/network/sdk.js +18 -18
  95. package/lib/network/sdk.js.map +1 -1
  96. package/lib/test/context.d.ts +6 -0
  97. package/lib/test/context.d.ts.map +1 -0
  98. package/lib/test/context.js +15 -0
  99. package/lib/test/context.js.map +1 -0
  100. package/lib-es/api/index.d.ts +2 -2
  101. package/lib-es/api/index.d.ts.map +1 -1
  102. package/lib-es/api/index.js +25 -22
  103. package/lib-es/api/index.js.map +1 -1
  104. package/lib-es/bridge/broadcast.d.ts.map +1 -1
  105. package/lib-es/bridge/broadcast.js +2 -1
  106. package/lib-es/bridge/broadcast.js.map +1 -1
  107. package/lib-es/bridge/createTransaction.js +2 -2
  108. package/lib-es/bridge/createTransaction.js.map +1 -1
  109. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  110. package/lib-es/bridge/estimateMaxSpendable.js +2 -1
  111. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  112. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  113. package/lib-es/bridge/getTransactionStatus.js +2 -1
  114. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  115. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  116. package/lib-es/bridge/prepareTransaction.js +4 -2
  117. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  118. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  119. package/lib-es/bridge/synchronisation.js +6 -4
  120. package/lib-es/bridge/synchronisation.js.map +1 -1
  121. package/lib-es/common-logic/calculateGasFees.d.ts +2 -1
  122. package/lib-es/common-logic/calculateGasFees.d.ts.map +1 -1
  123. package/lib-es/common-logic/calculateGasFees.js +3 -3
  124. package/lib-es/common-logic/calculateGasFees.js.map +1 -1
  125. package/lib-es/common-logic/calculateTransactionInfo.d.ts +2 -1
  126. package/lib-es/common-logic/calculateTransactionInfo.d.ts.map +1 -1
  127. package/lib-es/common-logic/calculateTransactionInfo.js +2 -2
  128. package/lib-es/common-logic/calculateTransactionInfo.js.map +1 -1
  129. package/lib-es/common-logic/estimateGas.d.ts +2 -1
  130. package/lib-es/common-logic/estimateGas.d.ts.map +1 -1
  131. package/lib-es/common-logic/estimateGas.js +2 -2
  132. package/lib-es/common-logic/estimateGas.js.map +1 -1
  133. package/lib-es/common-logic/getThorClient.d.ts +2 -1
  134. package/lib-es/common-logic/getThorClient.d.ts.map +1 -1
  135. package/lib-es/common-logic/getThorClient.js +2 -2
  136. package/lib-es/common-logic/getThorClient.js.map +1 -1
  137. package/lib-es/common-logic/mapTransfersToOperations.d.ts +3 -2
  138. package/lib-es/common-logic/mapTransfersToOperations.d.ts.map +1 -1
  139. package/lib-es/common-logic/mapTransfersToOperations.js +4 -4
  140. package/lib-es/common-logic/mapTransfersToOperations.js.map +1 -1
  141. package/lib-es/config.d.ts +10 -4
  142. package/lib-es/config.d.ts.map +1 -1
  143. package/lib-es/config.js +9 -5
  144. package/lib-es/config.js.map +1 -1
  145. package/lib-es/logic/account/getBalance.d.ts +2 -1
  146. package/lib-es/logic/account/getBalance.d.ts.map +1 -1
  147. package/lib-es/logic/account/getBalance.js +3 -2
  148. package/lib-es/logic/account/getBalance.js.map +1 -1
  149. package/lib-es/logic/history/getBlock.d.ts +2 -1
  150. package/lib-es/logic/history/getBlock.d.ts.map +1 -1
  151. package/lib-es/logic/history/getBlock.js +3 -2
  152. package/lib-es/logic/history/getBlock.js.map +1 -1
  153. package/lib-es/logic/history/getBlockInfo.d.ts +2 -1
  154. package/lib-es/logic/history/getBlockInfo.d.ts.map +1 -1
  155. package/lib-es/logic/history/getBlockInfo.js +3 -2
  156. package/lib-es/logic/history/getBlockInfo.js.map +1 -1
  157. package/lib-es/logic/history/lastBlock.d.ts +2 -1
  158. package/lib-es/logic/history/lastBlock.d.ts.map +1 -1
  159. package/lib-es/logic/history/lastBlock.js +4 -3
  160. package/lib-es/logic/history/lastBlock.js.map +1 -1
  161. package/lib-es/logic/history/listOperations.d.ts +2 -1
  162. package/lib-es/logic/history/listOperations.d.ts.map +1 -1
  163. package/lib-es/logic/history/listOperations.js +5 -4
  164. package/lib-es/logic/history/listOperations.js.map +1 -1
  165. package/lib-es/logic/transaction/broadcast.d.ts +2 -1
  166. package/lib-es/logic/transaction/broadcast.d.ts.map +1 -1
  167. package/lib-es/logic/transaction/broadcast.js +3 -2
  168. package/lib-es/logic/transaction/broadcast.js.map +1 -1
  169. package/lib-es/logic/transaction/combine.d.ts +1 -1
  170. package/lib-es/logic/transaction/combine.d.ts.map +1 -1
  171. package/lib-es/logic/transaction/combine.js +4 -1
  172. package/lib-es/logic/transaction/combine.js.map +1 -1
  173. package/lib-es/logic/transaction/craftTransaction.d.ts +2 -1
  174. package/lib-es/logic/transaction/craftTransaction.d.ts.map +1 -1
  175. package/lib-es/logic/transaction/craftTransaction.js +11 -10
  176. package/lib-es/logic/transaction/craftTransaction.js.map +1 -1
  177. package/lib-es/logic/transaction/estimateFees.d.ts +2 -1
  178. package/lib-es/logic/transaction/estimateFees.d.ts.map +1 -1
  179. package/lib-es/logic/transaction/estimateFees.js +2 -2
  180. package/lib-es/logic/transaction/estimateFees.js.map +1 -1
  181. package/lib-es/network/getBlock.d.ts +2 -1
  182. package/lib-es/network/getBlock.d.ts.map +1 -1
  183. package/lib-es/network/getBlock.js +2 -2
  184. package/lib-es/network/getBlock.js.map +1 -1
  185. package/lib-es/network/getFees.d.ts +2 -1
  186. package/lib-es/network/getFees.d.ts.map +1 -1
  187. package/lib-es/network/getFees.js +2 -2
  188. package/lib-es/network/getFees.js.map +1 -1
  189. package/lib-es/network/sdk.d.ts +7 -6
  190. package/lib-es/network/sdk.d.ts.map +1 -1
  191. package/lib-es/network/sdk.js +18 -18
  192. package/lib-es/network/sdk.js.map +1 -1
  193. package/lib-es/test/context.d.ts +6 -0
  194. package/lib-es/test/context.d.ts.map +1 -0
  195. package/lib-es/test/context.js +11 -0
  196. package/lib-es/test/context.js.map +1 -0
  197. package/package.json +6 -6
  198. package/src/api/index.integ.test.ts +21 -24
  199. package/src/api/index.ts +74 -27
  200. package/src/api/index.unit.test.ts +68 -48
  201. package/src/bridge/broadcast.integ.test.ts +2 -1
  202. package/src/bridge/broadcast.test.ts +1 -1
  203. package/src/bridge/broadcast.ts +2 -1
  204. package/src/bridge/createTransaction.ts +2 -2
  205. package/src/bridge/estimateMaxSpendable.test.ts +19 -3
  206. package/src/bridge/estimateMaxSpendable.ts +2 -0
  207. package/src/bridge/getTransactionStatus.test.ts +11 -6
  208. package/src/bridge/getTransactionStatus.ts +2 -0
  209. package/src/bridge/prepareTransaction.test.ts +5 -1
  210. package/src/bridge/prepareTransaction.ts +4 -2
  211. package/src/bridge/synchronisation.ts +7 -3
  212. package/src/common-logic/calculateGasFees.test.ts +101 -27
  213. package/src/common-logic/calculateGasFees.ts +4 -2
  214. package/src/common-logic/calculateTransactionInfo.test.ts +71 -16
  215. package/src/common-logic/calculateTransactionInfo.ts +3 -1
  216. package/src/common-logic/estimateGas.test.ts +13 -10
  217. package/src/common-logic/estimateGas.ts +3 -1
  218. package/src/common-logic/getThorClient.test.ts +7 -7
  219. package/src/common-logic/getThorClient.ts +3 -3
  220. package/src/common-logic/mapTransfersToOperations.test.ts +48 -13
  221. package/src/common-logic/mapTransfersToOperations.ts +5 -2
  222. package/src/config.test.ts +3 -3
  223. package/src/config.ts +13 -6
  224. package/src/logic/account/getBalance.ts +4 -2
  225. package/src/logic/account/getBalance.unit.test.ts +6 -4
  226. package/src/logic/history/getBlock.ts +4 -2
  227. package/src/logic/history/getBlock.unit.test.ts +8 -5
  228. package/src/logic/history/getBlockInfo.ts +4 -2
  229. package/src/logic/history/getBlockInfo.unit.test.ts +6 -3
  230. package/src/logic/history/lastBlock.ts +5 -3
  231. package/src/logic/history/lastBlock.unit.test.ts +6 -3
  232. package/src/logic/history/listOperations.ts +6 -3
  233. package/src/logic/history/listOperations.unit.test.ts +10 -6
  234. package/src/logic/transaction/broadcast.msw.test.ts +7 -2
  235. package/src/logic/transaction/broadcast.ts +8 -2
  236. package/src/logic/transaction/broadcast.unit.test.ts +6 -3
  237. package/src/logic/transaction/combine.ts +6 -2
  238. package/src/logic/transaction/combine.unit.test.ts +3 -3
  239. package/src/logic/transaction/craftTransaction.ts +16 -9
  240. package/src/logic/transaction/craftTransaction.unit.test.ts +29 -28
  241. package/src/logic/transaction/estimateFees.ts +3 -0
  242. package/src/logic/transaction/estimateFees.unit.test.ts +15 -12
  243. package/src/network/getBlock.ts +3 -2
  244. package/src/network/getBlock.unit.test.ts +11 -6
  245. package/src/network/getFees.ts +6 -3
  246. package/src/network/sdk.integ.test.ts +8 -1
  247. package/src/network/sdk.test.ts +18 -7
  248. package/src/network/sdk.ts +25 -15
  249. package/src/test/context.ts +15 -0
@@ -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 (transactionId: string): Promise<BigNumber> => {
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",
@@ -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",
@@ -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 (address: string): Promise<AccountResponse> => {
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 (transaction: VechainSDKTransaction): Promise<string> => {
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
+ });