@bigmi/core 0.6.3-alpha.0 → 0.6.3-alpha.2

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 (48) hide show
  1. package/dist/cjs/index.js.map +1 -1
  2. package/dist/cjs/version.d.ts +1 -1
  3. package/dist/cjs/version.js +1 -1
  4. package/dist/esm/index.js +0 -7
  5. package/dist/esm/index.js.map +1 -1
  6. package/dist/esm/version.d.ts +1 -1
  7. package/dist/esm/version.js +1 -1
  8. package/dist/types/index.d.ts.map +1 -1
  9. package/dist/types/version.d.ts +1 -1
  10. package/package.json +10 -1
  11. package/src/index.ts +0 -9
  12. package/src/version.ts +1 -1
  13. package/.env +0 -4
  14. package/CHANGELOG.md +0 -149
  15. package/package.json.tmp +0 -70
  16. package/src/chains/signet.spec.ts +0 -33
  17. package/src/transports/ankr/__mocks__/getBalance/valid.json +0 -9
  18. package/src/transports/ankr/__mocks__/getTransactionFee/invalid.json +0 -3
  19. package/src/transports/ankr/__mocks__/getTransactionFee/valid.json +0 -51
  20. package/src/transports/ankr/__mocks__/getTransactions/valid.json +0 -1186
  21. package/src/transports/ankr/ankr.spec.ts +0 -103
  22. package/src/transports/blockchair/__mocks__/getBalance/invalidAddress.json +0 -29
  23. package/src/transports/blockchair/__mocks__/getBalance/valid.json +0 -29
  24. package/src/transports/blockchair/__mocks__/getBalance/zeroBalance.json +0 -29
  25. package/src/transports/blockchair/__mocks__/getTransactionFee/invalid.json +0 -7
  26. package/src/transports/blockchair/__mocks__/getTransactionFee/valid.json +0 -37
  27. package/src/transports/blockchair/__mocks__/getUTXOs/invalidAddress.json +0 -28
  28. package/src/transports/blockchair/__mocks__/getUTXOs/rateLimited.json +0 -28
  29. package/src/transports/blockchair/__mocks__/getUTXOs/valid.json +0 -95
  30. package/src/transports/blockchair/__mocks__/getUTXOs/validPaginated.json +0 -869
  31. package/src/transports/blockchair/blockchair.spec.ts +0 -284
  32. package/src/transports/blockcypher/__mocks__/getBalance/invalid.json +0 -3
  33. package/src/transports/blockcypher/__mocks__/getBalance/valid.json +0 -13
  34. package/src/transports/blockcypher/__mocks__/getTransactionFee/invalid.json +0 -3
  35. package/src/transports/blockcypher/__mocks__/getTransactionFee/valid.json +0 -22
  36. package/src/transports/blockcypher/__mocks__/getUTXOs/empty.json +0 -12
  37. package/src/transports/blockcypher/__mocks__/getUTXOs/paginated.json +0 -2786
  38. package/src/transports/blockcypher/__mocks__/getUTXOs/rateLimited.json +0 -3
  39. package/src/transports/blockcypher/__mocks__/getUTXOs/valid.json +0 -27
  40. package/src/transports/blockcypher/blockcyper.spec.ts +0 -161
  41. package/src/transports/fallback.spec.ts +0 -128
  42. package/src/transports/mempool/__mocks__/getBalance/invalid.json +0 -1
  43. package/src/transports/mempool/__mocks__/getBalance/valid.json +0 -17
  44. package/src/transports/mempool/__mocks__/getTransactionFee/invalid.json +0 -1
  45. package/src/transports/mempool/__mocks__/getTransactionFee/valid.json +0 -58
  46. package/src/transports/mempool/__mocks__/getTransactions/valid.json +0 -1268
  47. package/src/transports/mempool/mempool.spec.ts +0 -126
  48. package/tsconfig.json +0 -12
@@ -1,284 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from 'vitest'
2
- import { getBalance } from '../../actions/getBalance.js'
3
- import { getTransactionFee } from '../../actions/getTransactionFee.js'
4
- import { getUTXOs } from '../../actions/getUTXOs.js'
5
- import { bitcoin } from '../../chains/bitcoin.js'
6
- import { BaseError } from '../../errors/base.js'
7
- import { InsufficientUTXOBalanceError } from '../../errors/utxo.js'
8
- import { createClient, rpcSchema } from '../../factories/createClient.js'
9
- import { createMockResponse } from '../../test/utils.js'
10
- import {
11
- INVALID_TX_ID,
12
- TX_FEE,
13
- VALID_TX_ID,
14
- } from '../__mocks__/getTransactionFee.js'
15
- import type { UTXOSchema } from '../types.js'
16
- import getInvalidBalanceReponse from './__mocks__/getBalance/invalidAddress.json'
17
- import getBalanceReponse from './__mocks__/getBalance/valid.json'
18
- import getZeroBalanceReponse from './__mocks__/getBalance/zeroBalance.json'
19
- import getTransactionFeeInvalidResponse from './__mocks__/getTransactionFee/invalid.json'
20
- import getTransactionFeeValidResponse from './__mocks__/getTransactionFee/valid.json'
21
- import getUTXOsInvalidResponse from './__mocks__/getUTXOs/invalidAddress.json'
22
- import getUTXOsResponse from './__mocks__/getUTXOs/valid.json'
23
- import getUTXOsPaginatedResponse from './__mocks__/getUTXOs/validPaginated.json'
24
- import { blockchair } from './blockchair.js'
25
- import type {
26
- BlockChairDashboardAddressResponse,
27
- BlockchairAddressBalanceData,
28
- BlockchairResponse,
29
- } from './blockchair.types.js'
30
-
31
- const address = import.meta.env.VITE_TEST_ADDRESS
32
- const apiKey = import.meta.env.VITE_TEST_BLOCKCHAIR_KEY
33
-
34
- const USE_MOCK = true
35
-
36
- const publicClient = createClient({
37
- chain: bitcoin,
38
- rpcSchema: rpcSchema<UTXOSchema>(),
39
- transport: blockchair({
40
- apiKey,
41
- }),
42
- })
43
-
44
- describe('Blockchair Transport', () => {
45
- beforeEach(() => {
46
- vi.restoreAllMocks()
47
- })
48
-
49
- describe('getBalance', () => {
50
- it('should fetch correct balance for valid address', async () => {
51
- if (USE_MOCK) {
52
- vi.spyOn(global, 'fetch').mockResolvedValue(
53
- createMockResponse(getBalanceReponse as BlockchairAddressBalanceData)
54
- )
55
- }
56
-
57
- const balance = await getBalance(publicClient, { address })
58
- expect(balance).toBeTypeOf('bigint')
59
- })
60
-
61
- it('should throw error for non-existent address', async () => {
62
- if (USE_MOCK) {
63
- vi.spyOn(global, 'fetch').mockResolvedValue(
64
- createMockResponse(
65
- getInvalidBalanceReponse as BlockchairAddressBalanceData
66
- )
67
- )
68
- }
69
-
70
- const nonExistentAddress =
71
- '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNaNUIBNSUENopnoidsacn'
72
- await expect(
73
- getBalance(publicClient, { address: nonExistentAddress })
74
- ).rejects.toThrow()
75
- })
76
- })
77
-
78
- it('should throw error for zero balance address', async () => {
79
- if (USE_MOCK) {
80
- vi.spyOn(global, 'fetch').mockResolvedValue(
81
- createMockResponse(
82
- getZeroBalanceReponse as BlockchairAddressBalanceData
83
- )
84
- )
85
- }
86
-
87
- const zeroBalanceAddress = '12LRT14SgNFFQ3hMRThAyXNao24BBy5cyU'
88
- await expect(
89
- getBalance(publicClient, { address: zeroBalanceAddress })
90
- ).rejects.toThrow()
91
- })
92
-
93
- describe('getUTXOs', () => {
94
- it('should return utxos with correct structure', async () => {
95
- if (USE_MOCK) {
96
- vi.spyOn(global, 'fetch').mockResolvedValue(
97
- createMockResponse(
98
- getUTXOsResponse as BlockchairResponse<BlockChairDashboardAddressResponse>
99
- )
100
- )
101
- }
102
-
103
- const utxos = await getUTXOs(publicClient, { address })
104
-
105
- expect(utxos.length).toBeGreaterThan(0)
106
- expect(utxos[0]).toMatchObject({
107
- blockHeight: expect.any(Number),
108
- scriptHex: expect.any(String),
109
- txId: expect.any(String),
110
- value: expect.any(Number),
111
- vout: expect.any(Number),
112
- })
113
- })
114
-
115
- it('should throw error when minValue exceeds balance', async () => {
116
- if (USE_MOCK) {
117
- vi.spyOn(global, 'fetch').mockImplementation((request) => {
118
- const url = new URL(request.toString())
119
-
120
- if (url.pathname.includes('/addresses/balances')) {
121
- return Promise.resolve(
122
- createMockResponse(
123
- getBalanceReponse as BlockchairAddressBalanceData
124
- )
125
- )
126
- }
127
-
128
- if (url.pathname.includes('/dashboards/addresses')) {
129
- return Promise.resolve(
130
- createMockResponse(
131
- getUTXOsResponse as BlockchairResponse<BlockChairDashboardAddressResponse>
132
- )
133
- )
134
- }
135
-
136
- throw new BaseError(`Unexpected URL: ${url.pathname}`)
137
- })
138
- }
139
-
140
- const hugeValue = 999999999999999999n
141
- await expect(
142
- getUTXOs(publicClient, {
143
- address,
144
- minValue: Number(hugeValue),
145
- })
146
- ).rejects.toThrow(InsufficientUTXOBalanceError)
147
- })
148
-
149
- it('should handle empty UTXO response', async () => {
150
- if (USE_MOCK) {
151
- vi.spyOn(global, 'fetch').mockResolvedValue(
152
- createMockResponse(
153
- getUTXOsInvalidResponse as BlockchairResponse<null>
154
- )
155
- )
156
- }
157
-
158
- const emptyAddress = '12LRT14SgNFFQ3hMRThAyXNao24BBy5cyU'
159
-
160
- if (USE_MOCK) {
161
- const utxos = await getUTXOs(publicClient, { address: emptyAddress })
162
- expect(utxos.length).toBe(0)
163
- } else {
164
- await expect(
165
- getUTXOs(publicClient, { address: emptyAddress })
166
- ).rejects.toMatchObject({
167
- status: 404,
168
- })
169
- }
170
- })
171
-
172
- describe('pagination', () => {
173
- const addressWithManyUTXOs = '1GrwDkr33gT6LuumniYjKEGjTLhsL5kmqC'
174
- const minValue = 5_610_592_350
175
-
176
- const createPaginatedMockResponse = (offset: number, limit: number) => ({
177
- ...getUTXOsPaginatedResponse,
178
- data: {
179
- ...getUTXOsPaginatedResponse.data,
180
- utxo: getUTXOsPaginatedResponse.data.utxo.slice(
181
- offset,
182
- offset + limit
183
- ),
184
- addresses: {
185
- [addressWithManyUTXOs]: {
186
- ...getUTXOsPaginatedResponse.data.addresses[addressWithManyUTXOs],
187
- unspent_output_count: getUTXOsPaginatedResponse.data.utxo.length,
188
- },
189
- },
190
- },
191
- })
192
-
193
- it('should handle pagination correctly', async () => {
194
- if (USE_MOCK) {
195
- vi.spyOn(global, 'fetch').mockImplementation((request) => {
196
- const url = new URL(request.toString())
197
-
198
- if (url.pathname.includes('/addresses/balances')) {
199
- return Promise.resolve(
200
- createMockResponse({
201
- data: {
202
- [addressWithManyUTXOs]: 1000000000000,
203
- },
204
- context: { code: 200 },
205
- } as BlockchairResponse<BlockchairAddressBalanceData>)
206
- )
207
- }
208
-
209
- if (url.pathname.includes('/dashboards/addresses')) {
210
- const offset = Number.parseInt(
211
- url.searchParams.get('offset')?.split(',')[1] || '0',
212
- 10
213
- )
214
- const limit = 100
215
- return Promise.resolve(
216
- createMockResponse(
217
- createPaginatedMockResponse(
218
- offset,
219
- limit
220
- ) as BlockchairResponse<BlockChairDashboardAddressResponse>
221
- )
222
- )
223
- }
224
-
225
- throw new BaseError(`Unexpected URL: ${url.pathname}`)
226
- })
227
- }
228
-
229
- const utxos = await getUTXOs(publicClient, {
230
- address: addressWithManyUTXOs,
231
- minValue,
232
- })
233
-
234
- expect(utxos.length).toBeGreaterThan(0)
235
- expect(new Set(utxos.map((utxo) => utxo.txId)).size).toBe(utxos.length)
236
- if (USE_MOCK) {
237
- expect(global.fetch).toHaveBeenCalled()
238
- }
239
-
240
- const totalValue = utxos.reduce((sum, utxo) => sum + utxo.value, 0)
241
- expect(totalValue).toBeGreaterThanOrEqual(minValue)
242
- })
243
- })
244
- })
245
-
246
- describe('getTransactionFee', () => {
247
- it('should fetch correct transaction fee for valid transaction', async () => {
248
- if (USE_MOCK) {
249
- const mockData = {
250
- data: {
251
- [VALID_TX_ID]:
252
- getTransactionFeeValidResponse.data[
253
- '8f210660cd99c5e6dc77b6cb09d4d522d3fbc5fd97ad3e65403d49aa7aa5dc23'
254
- ],
255
- },
256
- context: getTransactionFeeValidResponse.context,
257
- }
258
-
259
- mockData.data[VALID_TX_ID].transaction.fee = TX_FEE
260
- vi.spyOn(global, 'fetch').mockResolvedValue(
261
- createMockResponse(mockData)
262
- )
263
- }
264
-
265
- const result = await getTransactionFee(publicClient, {
266
- txId: VALID_TX_ID,
267
- })
268
- expect(result).toBeDefined()
269
- expect(result).toBe(BigInt(TX_FEE))
270
- })
271
-
272
- it('should throw error for non-existent transaction', async () => {
273
- if (USE_MOCK) {
274
- vi.spyOn(global, 'fetch').mockResolvedValue(
275
- createMockResponse(getTransactionFeeInvalidResponse)
276
- )
277
- }
278
-
279
- await expect(
280
- getTransactionFee(publicClient, { txId: INVALID_TX_ID })
281
- ).rejects.toThrow()
282
- })
283
- })
284
- })
@@ -1,3 +0,0 @@
1
- {
2
- "error": "Address 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNaNUIBNSUENopnoidsacn is invalid: Address 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNaNUIBNSUENopnoidsacn is of unknown size."
3
- }
@@ -1,13 +0,0 @@
1
- {
2
- "address": "bc1qpvk0kjdg0kantu9z78qz7gqk53q643auz33yaw",
3
- "total_received": 190653,
4
- "total_sent": 157447,
5
- "balance": 33206,
6
- "unconfirmed_balance": 0,
7
- "final_balance": 33206,
8
- "n_tx": 19,
9
- "unconfirmed_n_tx": 0,
10
- "final_n_tx": 19,
11
- "txrefs": [],
12
- "tx_url": "https://api.blockcypher.com/v1/btc/main/txs/"
13
- }
@@ -1,3 +0,0 @@
1
- {
2
- "error": "Transaction not found"
3
- }
@@ -1,22 +0,0 @@
1
- {
2
- "block_height": 896390,
3
- "hash": "8f210660cd99c5e6dc77b6cb09d4d522d3fbc5fd97ad3e65403d49aa7aa5dc23",
4
- "addresses": [
5
- "bc1qpvk0kjdg0kantu9z78qz7gqk53q643auz33yaw",
6
- "bc1qjmggdm4r9rqkfq335w72duu47386jhdw6wye0m"
7
- ],
8
- "total": 10269001908,
9
- "fees": 1036,
10
- "size": 450,
11
- "vsize": 288,
12
- "preference": "medium",
13
- "relayed_by": "127.0.0.1",
14
- "received": "2024-03-15T12:00:00Z",
15
- "ver": 1,
16
- "double_spend": false,
17
- "vin_sz": 2,
18
- "vout_sz": 3,
19
- "confirmations": 1040,
20
- "inputs": [],
21
- "outputs": []
22
- }
@@ -1,12 +0,0 @@
1
- {
2
- "address": "12LRT14SgNFFQ3hMRThAyXNao24BBy5cyU",
3
- "total_received": 0,
4
- "total_sent": 0,
5
- "balance": 0,
6
- "unconfirmed_balance": 0,
7
- "final_balance": 0,
8
- "n_tx": 0,
9
- "unconfirmed_n_tx": 0,
10
- "final_n_tx": 0,
11
- "tx_url": "https://api.blockcypher.com/v1/btc/main/txs/"
12
- }