@thru/thru-sdk 0.1.19 → 0.1.21

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 (88) hide show
  1. package/README.md +19 -0
  2. package/dist/{chunk-PH7P5EEU.js → chunk-SHMREHP5.js} +13 -9
  3. package/dist/chunk-SHMREHP5.js.map +1 -0
  4. package/dist/client.d.ts +2 -1
  5. package/dist/client.js +3 -2
  6. package/dist/client.js.map +1 -1
  7. package/dist/metafile-esm.json +1 -1
  8. package/dist/sdk.d.ts +3 -3
  9. package/dist/sdk.js +1 -1
  10. package/dist/{transactions-BzD9hYlc.d.ts → transactions-CLezIeXO.d.ts} +20 -18
  11. package/package.json +7 -3
  12. package/buf.gen.yaml +0 -12
  13. package/buf.lock +0 -9
  14. package/buf.yaml +0 -15
  15. package/dist/chunk-PH7P5EEU.js.map +0 -1
  16. package/proto/thru/common/v1/consensus.proto +0 -73
  17. package/proto/thru/common/v1/errors.proto +0 -65
  18. package/proto/thru/common/v1/filters.proto +0 -60
  19. package/proto/thru/common/v1/pagination.proto +0 -45
  20. package/proto/thru/core/v1/account.proto +0 -137
  21. package/proto/thru/core/v1/block.proto +0 -80
  22. package/proto/thru/core/v1/state.proto +0 -35
  23. package/proto/thru/core/v1/transaction.proto +0 -136
  24. package/proto/thru/core/v1/types.proto +0 -50
  25. package/proto/thru/services/v1/command_service.proto +0 -70
  26. package/proto/thru/services/v1/query_service.proto +0 -344
  27. package/proto/thru/services/v1/streaming_service.proto +0 -126
  28. package/thru-ts-client-sdk/__tests__/helpers/test-utils.ts +0 -228
  29. package/thru-ts-client-sdk/client.ts +0 -10
  30. package/thru-ts-client-sdk/core/__tests__/bound-client.test.ts +0 -354
  31. package/thru-ts-client-sdk/core/__tests__/client.test.ts +0 -53
  32. package/thru-ts-client-sdk/core/bound-client.ts +0 -156
  33. package/thru-ts-client-sdk/core/client.ts +0 -38
  34. package/thru-ts-client-sdk/defaults.ts +0 -26
  35. package/thru-ts-client-sdk/modules/__tests__/accounts.test.ts +0 -406
  36. package/thru-ts-client-sdk/modules/__tests__/blocks.test.ts +0 -199
  37. package/thru-ts-client-sdk/modules/__tests__/events.test.ts +0 -74
  38. package/thru-ts-client-sdk/modules/__tests__/height.test.ts +0 -39
  39. package/thru-ts-client-sdk/modules/__tests__/helpers.test.ts +0 -288
  40. package/thru-ts-client-sdk/modules/__tests__/keys.test.ts +0 -55
  41. package/thru-ts-client-sdk/modules/__tests__/proofs.test.ts +0 -119
  42. package/thru-ts-client-sdk/modules/__tests__/streaming.test.ts +0 -152
  43. package/thru-ts-client-sdk/modules/__tests__/transactions.test.ts +0 -730
  44. package/thru-ts-client-sdk/modules/__tests__/version.test.ts +0 -40
  45. package/thru-ts-client-sdk/modules/accounts.ts +0 -141
  46. package/thru-ts-client-sdk/modules/blocks.ts +0 -75
  47. package/thru-ts-client-sdk/modules/events.ts +0 -20
  48. package/thru-ts-client-sdk/modules/height.ts +0 -9
  49. package/thru-ts-client-sdk/modules/helpers.ts +0 -131
  50. package/thru-ts-client-sdk/modules/keys.ts +0 -29
  51. package/thru-ts-client-sdk/modules/proofs.ts +0 -20
  52. package/thru-ts-client-sdk/modules/streaming.ts +0 -133
  53. package/thru-ts-client-sdk/modules/transactions.ts +0 -374
  54. package/thru-ts-client-sdk/modules/version.ts +0 -10
  55. package/thru-ts-client-sdk/proto/buf/validate/validate_pb.ts +0 -4761
  56. package/thru-ts-client-sdk/proto/google/api/annotations_pb.ts +0 -39
  57. package/thru-ts-client-sdk/proto/google/api/client_pb.ts +0 -953
  58. package/thru-ts-client-sdk/proto/google/api/field_behavior_pb.ts +0 -157
  59. package/thru-ts-client-sdk/proto/google/api/http_pb.ts +0 -474
  60. package/thru-ts-client-sdk/proto/google/api/launch_stage_pb.ts +0 -118
  61. package/thru-ts-client-sdk/proto/thru/common/v1/consensus_pb.ts +0 -162
  62. package/thru-ts-client-sdk/proto/thru/common/v1/errors_pb.ts +0 -129
  63. package/thru-ts-client-sdk/proto/thru/common/v1/filters_pb.ts +0 -129
  64. package/thru-ts-client-sdk/proto/thru/common/v1/pagination_pb.ts +0 -79
  65. package/thru-ts-client-sdk/proto/thru/core/v1/account_pb.ts +0 -359
  66. package/thru-ts-client-sdk/proto/thru/core/v1/block_pb.ts +0 -259
  67. package/thru-ts-client-sdk/proto/thru/core/v1/state_pb.ts +0 -103
  68. package/thru-ts-client-sdk/proto/thru/core/v1/transaction_pb.ts +0 -528
  69. package/thru-ts-client-sdk/proto/thru/core/v1/types_pb.ts +0 -100
  70. package/thru-ts-client-sdk/proto/thru/services/v1/command_service_pb.ts +0 -146
  71. package/thru-ts-client-sdk/proto/thru/services/v1/query_service_pb.ts +0 -819
  72. package/thru-ts-client-sdk/proto/thru/services/v1/streaming_service_pb.ts +0 -390
  73. package/thru-ts-client-sdk/sdk.ts +0 -42
  74. package/thru-ts-client-sdk/test-scripts/counter.ts +0 -469
  75. package/thru-ts-client-sdk/test-scripts/create-account.ts +0 -74
  76. package/thru-ts-client-sdk/test-scripts/get-height.ts +0 -52
  77. package/thru-ts-client-sdk/transactions/Transaction.ts +0 -240
  78. package/thru-ts-client-sdk/transactions/TransactionBuilder.ts +0 -53
  79. package/thru-ts-client-sdk/transactions/__tests__/TransactionBuilder.test.ts +0 -411
  80. package/thru-ts-client-sdk/transactions/__tests__/utils.test.ts +0 -214
  81. package/thru-ts-client-sdk/transactions/index.ts +0 -3
  82. package/thru-ts-client-sdk/transactions/types.ts +0 -74
  83. package/thru-ts-client-sdk/transactions/utils.ts +0 -132
  84. package/thru-ts-client-sdk/types/types.ts +0 -8
  85. package/thru-ts-client-sdk/utils/utils.ts +0 -27
  86. package/tsconfig.json +0 -9
  87. package/tsup.config.ts +0 -14
  88. package/vitest.config.ts +0 -31
@@ -1,228 +0,0 @@
1
- import { create } from "@bufbuild/protobuf";
2
- import { encodeAddress, encodeSignature } from "@thru/helpers";
3
- import { vi } from "vitest";
4
- import type { ThruClientContext } from "../../core/client";
5
- import type { Account, AccountFlags, AccountMeta } from "../../proto/thru/core/v1/account_pb";
6
- import { AccountFlagsSchema, AccountMetaSchema, AccountSchema } from "../../proto/thru/core/v1/account_pb";
7
- import type { Block, BlockHeader } from "../../proto/thru/core/v1/block_pb";
8
- import { BlockHeaderSchema, BlockSchema } from "../../proto/thru/core/v1/block_pb";
9
- import type { GetHeightResponse, ListBlocksResponse } from "../../proto/thru/services/v1/query_service_pb";
10
- import { GetHeightResponseSchema, ListBlocksResponseSchema } from "../../proto/thru/services/v1/query_service_pb";
11
-
12
- /**
13
- * Creates a mock ThruClientContext with mock gRPC clients.
14
- * Use vi.fn() for methods you want to track or customize.
15
- */
16
- export function createMockContext(overrides: Partial<ThruClientContext> = {}): ThruClientContext {
17
- return {
18
- baseUrl: "https://test.thruput.org",
19
- transport: {} as any,
20
- query: {
21
- getHeight: vi.fn(),
22
- getAccount: vi.fn(),
23
- getRawAccount: vi.fn(),
24
- getTransaction: vi.fn(),
25
- getRawTransaction: vi.fn(),
26
- getTransactionStatus: vi.fn(),
27
- getBlock: vi.fn(),
28
- getRawBlock: vi.fn(),
29
- listBlocks: vi.fn(),
30
- listAccounts: vi.fn(),
31
- listTransactionsForAccount: vi.fn(),
32
- getEvent: vi.fn(),
33
- generateStateProof: vi.fn(),
34
- getVersion: vi.fn(),
35
- ...overrides.query,
36
- } as any,
37
- command: {
38
- sendTransaction: vi.fn(),
39
- batchSendTransactions: vi.fn(),
40
- ...overrides.command,
41
- } as any,
42
- streaming: {
43
- trackTransaction: vi.fn(),
44
- streamBlocks: vi.fn(),
45
- streamAccountUpdates: vi.fn(),
46
- streamTransactions: vi.fn(),
47
- streamEvents: vi.fn(),
48
- ...overrides.streaming,
49
- } as any,
50
- ...overrides,
51
- };
52
- }
53
-
54
- /**
55
- * Generates a test Ed25519 public key (32 bytes)
56
- */
57
- export function generateTestPubkey(value: number = 0x42): Uint8Array {
58
- const key = new Uint8Array(32);
59
- key.fill(value & 0xff);
60
- return key;
61
- }
62
-
63
- /**
64
- * Generates a test Ed25519 signature (64 bytes)
65
- */
66
- export function generateTestSignature(value: number = 0x42): Uint8Array {
67
- const sig = new Uint8Array(64);
68
- sig.fill(value & 0xff);
69
- return sig;
70
- }
71
-
72
- /**
73
- * Generates a test address string (ta- prefixed)
74
- */
75
- export function generateTestAddress(value: number = 0x42): string {
76
- return encodeAddress(generateTestPubkey(value));
77
- }
78
-
79
- /**
80
- * Generates a test signature string (ts- prefixed)
81
- */
82
- export function generateTestSignatureString(value: number = 0x42): string {
83
- return encodeSignature(generateTestSignature(value));
84
- }
85
-
86
- /**
87
- * Creates a mock Account protobuf message
88
- */
89
- export function createMockAccount(overrides: {
90
- address?: { value: Uint8Array };
91
- meta?: Partial<AccountMeta>;
92
- data?: any;
93
- } = {}): Account {
94
- const address = overrides.address?.value ?? generateTestPubkey();
95
-
96
- // If meta is provided as partial, merge with defaults
97
- const meta = overrides.meta
98
- ? create(AccountMetaSchema, { ...createMockAccountMeta(), ...overrides.meta } as any)
99
- : createMockAccountMeta();
100
-
101
- return create(AccountSchema, {
102
- address: {
103
- value: address,
104
- },
105
- meta,
106
- data: overrides.data,
107
- });
108
- }
109
-
110
- /**
111
- * Creates a mock AccountMeta protobuf message
112
- */
113
- export function createMockAccountMeta(overrides: {
114
- version?: number;
115
- flags?: AccountFlags;
116
- dataSize?: number;
117
- seq?: bigint;
118
- owner?: { value: Uint8Array };
119
- balance?: bigint;
120
- nonce?: bigint;
121
- } = {}): AccountMeta {
122
- return create(AccountMetaSchema, {
123
- version: overrides.version ?? 1,
124
- flags: overrides.flags ?? createMockAccountFlags(),
125
- dataSize: overrides.dataSize ?? 0,
126
- seq: overrides.seq ?? 0n,
127
- owner: overrides.owner ?? { value: generateTestPubkey(0x01) },
128
- balance: overrides.balance ?? 1000n,
129
- nonce: overrides.nonce ?? 5n,
130
- });
131
- }
132
-
133
- /**
134
- * Creates a mock AccountFlags protobuf message
135
- */
136
- export function createMockAccountFlags(overrides: {
137
- isProgram?: boolean;
138
- isPrivileged?: boolean;
139
- isUncompressable?: boolean;
140
- isEphemeral?: boolean;
141
- isDeleted?: boolean;
142
- isNew?: boolean;
143
- isCompressed?: boolean;
144
- } = {}): AccountFlags {
145
- return create(AccountFlagsSchema, {
146
- isProgram: overrides.isProgram ?? false,
147
- isPrivileged: overrides.isPrivileged ?? false,
148
- isUncompressable: overrides.isUncompressable ?? false,
149
- isEphemeral: overrides.isEphemeral ?? false,
150
- isDeleted: overrides.isDeleted ?? false,
151
- isNew: overrides.isNew ?? false,
152
- isCompressed: overrides.isCompressed ?? false,
153
- });
154
- }
155
-
156
- /**
157
- * Creates a mock GetHeightResponse protobuf message
158
- */
159
- export function createMockHeightResponse(overrides: Partial<GetHeightResponse> = {}): GetHeightResponse {
160
- return create(GetHeightResponseSchema, {
161
- finalized: 1000n,
162
- locallyExecuted: 1001n,
163
- clusterExecuted: 1002n,
164
- ...overrides,
165
- });
166
- }
167
-
168
- /**
169
- * Creates a mock Block protobuf message
170
- * @param overrides - Partial block overrides. If header is provided as a partial object, it will be merged with defaults.
171
- */
172
- export function createMockBlock(overrides: Omit<Partial<Block>, "header"> & { header?: Partial<BlockHeader> } = {}): Block {
173
- // Extract header overrides if provided (as partial object)
174
- const headerOverrides = overrides.header;
175
- const { header: _, ...restOverrides } = overrides;
176
-
177
- // Create default header
178
- const defaultHeader: Partial<BlockHeader> = {
179
- slot: 1000n,
180
- version: 1,
181
- startSlot: 999n,
182
- expiryAfter: 100,
183
- maxBlockSize: 1024,
184
- maxComputeUnits: 1000000n,
185
- maxStateUnits: 10000,
186
- price: 1n,
187
- };
188
-
189
- // Merge header overrides if provided and create protobuf message
190
- const header = headerOverrides
191
- ? create(BlockHeaderSchema, { ...defaultHeader, ...headerOverrides } as any)
192
- : create(BlockHeaderSchema, defaultHeader as any);
193
-
194
- return create(BlockSchema, {
195
- header,
196
- ...restOverrides,
197
- });
198
- }
199
-
200
- /**
201
- * Creates a mock ListBlocksResponse protobuf message
202
- */
203
- export function createMockListBlocksResponse(overrides: Partial<ListBlocksResponse> = {}): ListBlocksResponse {
204
- return create(ListBlocksResponseSchema, {
205
- blocks: [],
206
- ...overrides,
207
- });
208
- }
209
-
210
- /**
211
- * Creates a mock keypair for testing
212
- */
213
- export function generateTestKeyPair(): {
214
- publicKey: Uint8Array;
215
- privateKey: Uint8Array;
216
- address: string;
217
- } {
218
- const publicKey = generateTestPubkey();
219
- const privateKey = new Uint8Array(64);
220
- privateKey.fill(0x42);
221
-
222
- return {
223
- publicKey,
224
- privateKey,
225
- address: encodeAddress(publicKey),
226
- };
227
- }
228
-
@@ -1,10 +0,0 @@
1
- import { createBoundThruClient, Thru } from "./core/bound-client";
2
- import { createThruClientContext, ThruClientConfig } from "./core/client";
3
-
4
- export type { Thru } from "./core/bound-client";
5
- export type { ThruClientConfig } from './core/client';
6
-
7
- export function createThruClient(config: ThruClientConfig = {}): Thru {
8
- const ctx = createThruClientContext(config);
9
- return createBoundThruClient(ctx);
10
- }
@@ -1,354 +0,0 @@
1
- import { create } from "@bufbuild/protobuf";
2
- import { describe, expect, it, vi } from "vitest";
3
- import { createMockAccount, createMockContext, createMockHeightResponse, generateTestPubkey } from "../../__tests__/helpers/test-utils";
4
- import * as keysModule from "../../modules/keys";
5
- import { ConsensusStatus } from "../../proto/thru/common/v1/consensus_pb";
6
- import { StreamAccountUpdatesResponseSchema, StreamBlocksResponseSchema, StreamEventsResponseSchema, StreamTransactionsResponseSchema } from "../../proto/thru/services/v1/streaming_service_pb";
7
- import { createBoundThruClient } from "../bound-client";
8
-
9
- describe("createBoundThruClient", () => {
10
- it("should create bound client with all modules", () => {
11
- const ctx = createMockContext();
12
- const client = createBoundThruClient(ctx);
13
-
14
- expect(client.ctx).toBe(ctx);
15
- expect(client.blocks).toBeDefined();
16
- expect(client.accounts).toBeDefined();
17
- expect(client.transactions).toBeDefined();
18
- expect(client.events).toBeDefined();
19
- expect(client.proofs).toBeDefined();
20
- expect(client.keys).toBeDefined();
21
- expect(client.version).toBeDefined();
22
- expect(client.helpers).toBeDefined();
23
- });
24
-
25
- it("should bind blocks module methods", () => {
26
- const ctx = createMockContext();
27
- vi.spyOn(ctx.query, "getBlock").mockResolvedValue({} as any);
28
- vi.spyOn(ctx.query, "getRawBlock").mockResolvedValue({} as any);
29
- vi.spyOn(ctx.query, "listBlocks").mockResolvedValue({} as any);
30
- vi.spyOn(ctx.query, "getHeight").mockResolvedValue(createMockHeightResponse());
31
- vi.spyOn(ctx.streaming, "streamBlocks").mockReturnValue(
32
- (async function* () {})()
33
- );
34
-
35
- const client = createBoundThruClient(ctx);
36
-
37
- expect(typeof client.blocks.get).toBe("function");
38
- expect(typeof client.blocks.getRaw).toBe("function");
39
- expect(typeof client.blocks.list).toBe("function");
40
- expect(typeof client.blocks.stream).toBe("function");
41
- expect(typeof client.blocks.getBlockHeight).toBe("function");
42
-
43
- // Verify bound functions don't require context parameter
44
- client.blocks.get({ slot: 1000n });
45
- expect(ctx.query.getBlock).toHaveBeenCalledTimes(1);
46
- });
47
-
48
- it("should bind accounts module methods", async () => {
49
- const ctx = createMockContext();
50
- const mockAccount = createMockAccount();
51
- vi.spyOn(ctx.query, "getAccount").mockResolvedValue(mockAccount);
52
- vi.spyOn(ctx.query, "getRawAccount").mockResolvedValue({} as any);
53
- vi.spyOn(ctx.query, "listAccounts").mockResolvedValue({ accounts: [] } as any);
54
- vi.spyOn(ctx.streaming, "streamAccountUpdates").mockReturnValue(
55
- (async function* () {})()
56
- );
57
-
58
- const client = createBoundThruClient(ctx);
59
-
60
- expect(typeof client.accounts.get).toBe("function");
61
- expect(typeof client.accounts.getRaw).toBe("function");
62
- expect(typeof client.accounts.list).toBe("function");
63
- expect(typeof client.accounts.stream).toBe("function");
64
- expect(typeof client.accounts.create).toBe("function");
65
-
66
- // Verify bound function works without context parameter
67
- const address = generateTestPubkey();
68
- await client.accounts.get(address);
69
- expect(ctx.query.getAccount).toHaveBeenCalledTimes(1);
70
- });
71
-
72
- it("should bind transactions module methods", () => {
73
- const ctx = createMockContext();
74
- vi.spyOn(ctx.query, "getTransaction").mockResolvedValue({} as any);
75
- vi.spyOn(ctx.query, "getRawTransaction").mockResolvedValue({} as any);
76
- vi.spyOn(ctx.query, "getTransactionStatus").mockResolvedValue({} as any);
77
- vi.spyOn(ctx.query, "listTransactionsForAccount").mockResolvedValue({ signatures: [] } as any);
78
- vi.spyOn(ctx.command, "sendTransaction").mockResolvedValue({ signature: { value: new Uint8Array(64) } } as any);
79
- vi.spyOn(ctx.command, "batchSendTransactions").mockResolvedValue({ signatures: [] } as any);
80
- vi.spyOn(ctx.streaming, "streamTransactions").mockReturnValue(
81
- (async function* () {})()
82
- );
83
- vi.spyOn(ctx.streaming, "trackTransaction").mockReturnValue(
84
- (async function* () {})()
85
- );
86
-
87
- const client = createBoundThruClient(ctx);
88
-
89
- expect(typeof client.transactions.get).toBe("function");
90
- expect(typeof client.transactions.getRaw).toBe("function");
91
- expect(typeof client.transactions.getStatus).toBe("function");
92
- expect(typeof client.transactions.listForAccount).toBe("function");
93
- expect(typeof client.transactions.stream).toBe("function");
94
- expect(typeof client.transactions.build).toBe("function");
95
- expect(typeof client.transactions.buildAndSign).toBe("function");
96
- expect(typeof client.transactions.send).toBe("function");
97
- expect(typeof client.transactions.batchSend).toBe("function");
98
- expect(typeof client.transactions.track).toBe("function");
99
- });
100
-
101
- it("should bind events module methods", () => {
102
- const ctx = createMockContext();
103
- vi.spyOn(ctx.query, "getEvent").mockResolvedValue({} as any);
104
- vi.spyOn(ctx.streaming, "streamEvents").mockReturnValue(
105
- (async function* () {})()
106
- );
107
-
108
- const client = createBoundThruClient(ctx);
109
-
110
- expect(typeof client.events.get).toBe("function");
111
- expect(typeof client.events.stream).toBe("function");
112
- });
113
-
114
- it("should bind proofs module methods", () => {
115
- const ctx = createMockContext();
116
- vi.spyOn(ctx.query, "generateStateProof").mockResolvedValue({} as any);
117
-
118
- const client = createBoundThruClient(ctx);
119
-
120
- expect(typeof client.proofs.generate).toBe("function");
121
- });
122
-
123
- it("should bind version module methods", async () => {
124
- const ctx = createMockContext();
125
- const mockVersionResponse = { versions: { "component": "1.0.0" } };
126
- vi.spyOn(ctx.query, "getVersion").mockResolvedValue(mockVersionResponse as any);
127
-
128
- const client = createBoundThruClient(ctx);
129
-
130
- expect(typeof client.version.get).toBe("function");
131
-
132
- // Verify bound function works without context parameter
133
- const result = await client.version.get();
134
- expect(result).toBe(mockVersionResponse);
135
- expect(ctx.query.getVersion).toHaveBeenCalledTimes(1);
136
- });
137
-
138
- it("should expose keys module (not bound, direct reference)", () => {
139
- const ctx = createMockContext();
140
- const client = createBoundThruClient(ctx);
141
-
142
- expect(typeof client.keys.generateKeyPair).toBe("function");
143
- expect(client.keys.generateKeyPair).toBe(keysModule.generateKeyPair);
144
- });
145
-
146
- it("should expose helpers (not bound, direct functions)", () => {
147
- const ctx = createMockContext();
148
- const client = createBoundThruClient(ctx);
149
-
150
- expect(typeof client.helpers.toSignature).toBe("function");
151
- expect(typeof client.helpers.toPubkey).toBe("function");
152
- expect(typeof client.helpers.toBlockHash).toBe("function");
153
- expect(typeof client.helpers.encodeSignature).toBe("function");
154
- expect(typeof client.helpers.decodeSignature).toBe("function");
155
- expect(typeof client.helpers.encodeAddress).toBe("function");
156
- expect(typeof client.helpers.decodeAddress).toBe("function");
157
- expect(typeof client.helpers.deriveProgramAddress).toBe("function");
158
- });
159
-
160
- it("should inject context into bound functions", async () => {
161
- const ctx = createMockContext();
162
- const mockAccount = createMockAccount();
163
- vi.spyOn(ctx.query, "getAccount").mockResolvedValue(mockAccount);
164
-
165
- const client = createBoundThruClient(ctx);
166
- const address = generateTestPubkey();
167
-
168
- // Call bound function without context parameter
169
- const result = await client.accounts.get(address);
170
-
171
- expect(result).toBe(mockAccount);
172
- expect(ctx.query.getAccount).toHaveBeenCalledTimes(1);
173
- // Verify the request was created with correct address
174
- const callArgs = (ctx.query.getAccount as any).mock.calls[0][0];
175
- expect(callArgs.address?.value).toEqual(address);
176
- });
177
-
178
- it("should preserve function signatures (bound functions don't have context parameter)", () => {
179
- const ctx = createMockContext();
180
- const client = createBoundThruClient(ctx);
181
-
182
- // Original function signature: getAccount(ctx, address, options?)
183
- // Bound function signature: getAccount(address, options?)
184
- // Should not require context as first parameter
185
-
186
- const address = generateTestPubkey();
187
-
188
- // This should work without context parameter
189
- expect(() => {
190
- client.accounts.get(address);
191
- }).not.toThrow();
192
- });
193
-
194
- it("should allow passing options to bound functions", async () => {
195
- const ctx = createMockContext();
196
- const mockAccount = createMockAccount();
197
- vi.spyOn(ctx.query, "getAccount").mockResolvedValue(mockAccount);
198
-
199
- const client = createBoundThruClient(ctx);
200
- const address = generateTestPubkey();
201
-
202
- await client.accounts.get(address, {
203
- view: 1, // AccountView enum value
204
- });
205
-
206
- expect(ctx.query.getAccount).toHaveBeenCalledTimes(1);
207
- const callArgs = (ctx.query.getAccount as any).mock.calls[0][0];
208
- expect(callArgs.view).toBe(1);
209
- });
210
-
211
- it("should expose context for advanced usage", () => {
212
- const ctx = createMockContext();
213
- const client = createBoundThruClient(ctx);
214
-
215
- expect(client.ctx).toBe(ctx);
216
- expect(client.ctx.baseUrl).toBe(ctx.baseUrl);
217
- expect(client.ctx.query).toBe(ctx.query);
218
- expect(client.ctx.command).toBe(ctx.command);
219
- expect(client.ctx.streaming).toBe(ctx.streaming);
220
- });
221
-
222
- it("should bind listForAccount and pass parameters correctly", async () => {
223
- const ctx = createMockContext();
224
- const mockResponse = { signatures: [] };
225
- vi.spyOn(ctx.query, "listTransactionsForAccount").mockResolvedValue(mockResponse as any);
226
-
227
- const client = createBoundThruClient(ctx);
228
- const account = generateTestPubkey();
229
-
230
- // Verify bound function works without context parameter
231
- const result = await client.transactions.listForAccount(account);
232
- expect(result).toBe(mockResponse);
233
- expect(ctx.query.listTransactionsForAccount).toHaveBeenCalledTimes(1);
234
- });
235
-
236
- it("should bind batchSend and pass parameters correctly", async () => {
237
- const ctx = createMockContext();
238
- const mockResponse = { signatures: [] };
239
- vi.spyOn(ctx.command, "batchSendTransactions").mockResolvedValue(mockResponse as any);
240
-
241
- const client = createBoundThruClient(ctx);
242
-
243
- // Verify bound function works without context parameter
244
- const result = await client.transactions.batchSend([new Uint8Array(100)]);
245
- expect(result).toBe(mockResponse);
246
- expect(ctx.command.batchSendTransactions).toHaveBeenCalledTimes(1);
247
- });
248
-
249
- it("should return async iterable from blocks.stream", async () => {
250
- const ctx = createMockContext();
251
- const mockResponse = create(StreamBlocksResponseSchema, {});
252
- vi.spyOn(ctx.streaming, "streamBlocks").mockReturnValue(
253
- (async function* () {
254
- yield mockResponse;
255
- })()
256
- );
257
-
258
- const client = createBoundThruClient(ctx);
259
-
260
- const iterable = client.blocks.stream();
261
- const results = [];
262
- for await (const response of iterable) {
263
- results.push(response);
264
- }
265
-
266
- expect(results).toHaveLength(1);
267
- expect(results[0]).toBe(mockResponse);
268
- expect(ctx.streaming.streamBlocks).toHaveBeenCalledTimes(1);
269
- });
270
-
271
- it("should return async iterable from accounts.stream", async () => {
272
- const ctx = createMockContext();
273
- const mockResponse = create(StreamAccountUpdatesResponseSchema, {});
274
- vi.spyOn(ctx.streaming, "streamAccountUpdates").mockReturnValue(
275
- (async function* () {
276
- yield mockResponse;
277
- })()
278
- );
279
-
280
- const client = createBoundThruClient(ctx);
281
- const address = generateTestPubkey();
282
-
283
- const iterable = client.accounts.stream(address);
284
- const results = [];
285
- for await (const response of iterable) {
286
- results.push(response);
287
- }
288
-
289
- expect(results).toHaveLength(1);
290
- expect(results[0]).toBe(mockResponse);
291
- const callArgs = (ctx.streaming.streamAccountUpdates as any).mock.calls[0][0];
292
- expect(callArgs.address?.value).toEqual(address);
293
- });
294
-
295
- it("should return async iterable from transactions.stream", async () => {
296
- const ctx = createMockContext();
297
- const mockResponse = create(StreamTransactionsResponseSchema, {});
298
- vi.spyOn(ctx.streaming, "streamTransactions").mockReturnValue(
299
- (async function* () {
300
- yield mockResponse;
301
- })()
302
- );
303
-
304
- const client = createBoundThruClient(ctx);
305
-
306
- const iterable = client.transactions.stream();
307
- const results = [];
308
- for await (const response of iterable) {
309
- results.push(response);
310
- }
311
-
312
- expect(results).toHaveLength(1);
313
- expect(results[0]).toBe(mockResponse);
314
- expect(ctx.streaming.streamTransactions).toHaveBeenCalledTimes(1);
315
- });
316
-
317
- it("should return async iterable from events.stream", async () => {
318
- const ctx = createMockContext();
319
- const mockResponse = create(StreamEventsResponseSchema, {});
320
- vi.spyOn(ctx.streaming, "streamEvents").mockReturnValue(
321
- (async function* () {
322
- yield mockResponse;
323
- })()
324
- );
325
-
326
- const client = createBoundThruClient(ctx);
327
-
328
- const iterable = client.events.stream();
329
- const results = [];
330
- for await (const response of iterable) {
331
- results.push(response);
332
- }
333
-
334
- expect(results).toHaveLength(1);
335
- expect(results[0]).toBe(mockResponse);
336
- expect(ctx.streaming.streamEvents).toHaveBeenCalledTimes(1);
337
- });
338
-
339
- it("should pass options to streaming methods", async () => {
340
- const ctx = createMockContext();
341
- vi.spyOn(ctx.streaming, "streamBlocks").mockReturnValue(
342
- (async function* () {})()
343
- );
344
-
345
- const client = createBoundThruClient(ctx);
346
-
347
- client.blocks.stream({ startSlot: 1000n, minConsensus: ConsensusStatus.FINALIZED });
348
-
349
- const callArgs = (ctx.streaming.streamBlocks as any).mock.calls[0][0];
350
- expect(callArgs.startSlot).toBe(1000n);
351
- expect(callArgs.minConsensus).toBe(ConsensusStatus.FINALIZED);
352
- });
353
- });
354
-
@@ -1,53 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { DEFAULT_HOST } from "../../defaults";
3
- import { createThruClientContext } from "../client";
4
-
5
- describe("createThruClientContext", () => {
6
- it("should create context with default host when no config provided", () => {
7
- const ctx = createThruClientContext();
8
-
9
- expect(ctx.baseUrl).toBe(DEFAULT_HOST);
10
- expect(ctx.transport).toBeDefined();
11
- expect(ctx.query).toBeDefined();
12
- expect(ctx.command).toBeDefined();
13
- expect(ctx.streaming).toBeDefined();
14
- });
15
-
16
- it("should create context with custom baseUrl", () => {
17
- const customUrl = "https://custom.thruput.org";
18
- const ctx = createThruClientContext({ baseUrl: customUrl });
19
-
20
- expect(ctx.baseUrl).toBe(customUrl);
21
- expect(ctx.transport).toBeDefined();
22
- expect(ctx.query).toBeDefined();
23
- expect(ctx.command).toBeDefined();
24
- expect(ctx.streaming).toBeDefined();
25
- });
26
-
27
- it("should create gRPC clients for all services", () => {
28
- const ctx = createThruClientContext();
29
-
30
- // QueryService should have methods
31
- expect(ctx.query).toBeDefined();
32
- expect(typeof ctx.query.getHeight).toBe("function");
33
- expect(typeof ctx.query.getAccount).toBe("function");
34
-
35
- // CommandService should have methods
36
- expect(ctx.command).toBeDefined();
37
- expect(typeof ctx.command.sendTransaction).toBe("function");
38
-
39
- // StreamingService should have methods
40
- expect(ctx.streaming).toBeDefined();
41
- expect(typeof ctx.streaming.trackTransaction).toBe("function");
42
- });
43
-
44
- it("should create transport with correct baseUrl", () => {
45
- const customUrl = "https://test.thruput.org";
46
- const ctx = createThruClientContext({ baseUrl: customUrl });
47
-
48
- // Transport should be created (we can't easily test internal config)
49
- expect(ctx.transport).toBeDefined();
50
- expect(ctx.baseUrl).toBe(customUrl);
51
- });
52
- });
53
-