@usearete/sdk 0.23.1 → 0.25.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/README.md +33 -1
- package/dist/index.cjs +577 -107
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +196 -8
- package/dist/index.esm.js +573 -108
- package/dist/index.esm.js.map +1 -1
- package/dist/testing.cjs +619 -0
- package/dist/testing.cjs.map +1 -0
- package/dist/testing.d.ts +482 -0
- package/dist/testing.esm.js +603 -0
- package/dist/testing.esm.js.map +1 -0
- package/package.json +18 -2
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
import { TransactionSimulationResult, TransactionSignatureStatus, TransactionTransport, BuiltInstruction, WalletExecutionContext, SendResult, TransactionFailureOutcome, TransactionVersion, TransactionInspectionResult, WalletAdapter, SendOptions, TransactionInspectionOptions, TransactionExecutionError, ConfirmedTransactionOutcome, SubscriptionQuery, FrameMode, SortConfig, ReplayWindow, Schema, FrameValidationDiagnostic, MemoryAdapter, QueryStore, FrameProcessor, Subscription, QuerySnapshot, WebSocketFactoryInit } from '@usearete/sdk';
|
|
2
|
+
|
|
3
|
+
/** Every relay route, as recorded in {@link FakeTransactionTransport.calls}. */
|
|
4
|
+
type FakeTransactionCall = 'latest-blockhash' | 'fee' | 'simulate' | 'send' | 'status' | 'height';
|
|
5
|
+
interface FakeTransactionTransportOptions {
|
|
6
|
+
/** Blockhash returned by `getLatestBlockhash` (default: 32 zero bytes). */
|
|
7
|
+
readonly blockhash?: string;
|
|
8
|
+
readonly lastValidBlockHeight?: bigint;
|
|
9
|
+
/** Height returned by `getBlockHeight` (default `10n`). */
|
|
10
|
+
readonly blockHeight?: bigint;
|
|
11
|
+
/** Fee returned by `getFeeForMessage` (default `5000n`). */
|
|
12
|
+
readonly feeLamports?: bigint | null;
|
|
13
|
+
/** Fields merged over the default successful simulation. */
|
|
14
|
+
readonly simulation?: Partial<TransactionSimulationResult>;
|
|
15
|
+
/**
|
|
16
|
+
* Signature `sendTransaction` answers with. Defaults to the first signature
|
|
17
|
+
* carried by the submitted wire transaction, as a real relay echoes it.
|
|
18
|
+
*/
|
|
19
|
+
readonly signature?: string | ((transaction: string) => string);
|
|
20
|
+
/** Fail the submission with this value, after recording the dispatch. */
|
|
21
|
+
readonly sendError?: unknown;
|
|
22
|
+
/** Record the dispatch, then never answer: a stalled relay. */
|
|
23
|
+
readonly stallSend?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Status answered by `getSignatureStatus`. Defaults to confirmed at slot
|
|
26
|
+
* `42n`; `null` means the relay does not know the signature (yet).
|
|
27
|
+
*/
|
|
28
|
+
readonly status?: Partial<Omit<TransactionSignatureStatus, 'signature'>> | null;
|
|
29
|
+
/** Fail every status poll with this value. */
|
|
30
|
+
readonly statusError?: unknown;
|
|
31
|
+
/** Answer the submission, then never answer a status poll. */
|
|
32
|
+
readonly stallStatus?: boolean;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A recording {@link TransactionTransport}. `calls` is how a test asserts
|
|
36
|
+
* "never sent": inspection records `fee` and `simulate`, and only a submission
|
|
37
|
+
* records `send`.
|
|
38
|
+
*/
|
|
39
|
+
interface FakeTransactionTransport extends TransactionTransport {
|
|
40
|
+
readonly calls: FakeTransactionCall[];
|
|
41
|
+
/** Wire transactions passed to `simulateTransaction`, in order. */
|
|
42
|
+
readonly simulated: string[];
|
|
43
|
+
/** Wire transactions passed to `sendTransaction`, in order. */
|
|
44
|
+
readonly sent: string[];
|
|
45
|
+
/** Messages passed to `getFeeForMessage`, in order. */
|
|
46
|
+
readonly feeMessages: string[];
|
|
47
|
+
/** Forget every recorded call. */
|
|
48
|
+
reset(): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The first signature a base64 wire transaction carries (compact-u16 count,
|
|
52
|
+
* then 64-byte signatures), or `undefined` when the bytes are not one.
|
|
53
|
+
*/
|
|
54
|
+
declare function firstSignatureOfWireTransaction(transaction: string): string | undefined;
|
|
55
|
+
/**
|
|
56
|
+
* Create a recording, scriptable {@link TransactionTransport} for tests: pass
|
|
57
|
+
* it as `ConnectOptions.transactions`, `useArete(stack, { transactions })`, or
|
|
58
|
+
* an adapter's `transport`. Nothing reaches a network.
|
|
59
|
+
*/
|
|
60
|
+
declare function createFakeTransactionTransport(options?: FakeTransactionTransportOptions): FakeTransactionTransport;
|
|
61
|
+
|
|
62
|
+
/** A deterministic, well-formed wallet address for fixtures. */
|
|
63
|
+
declare const FIXTURE_WALLET_ADDRESS: string;
|
|
64
|
+
interface WalletFixtureCall<TOptions> {
|
|
65
|
+
readonly instructions: readonly BuiltInstruction[];
|
|
66
|
+
readonly options: TOptions | undefined;
|
|
67
|
+
readonly context: WalletExecutionContext | undefined;
|
|
68
|
+
}
|
|
69
|
+
/** What one `signAndSend` call does. */
|
|
70
|
+
type WalletFixtureResponse = SendResult | TransactionFailureOutcome | Error | 'stall';
|
|
71
|
+
interface WalletFixtureOptions {
|
|
72
|
+
/** Wallet address (default {@link FIXTURE_WALLET_ADDRESS}). */
|
|
73
|
+
readonly publicKey?: string;
|
|
74
|
+
/** Additional signer addresses the wallet can satisfy. */
|
|
75
|
+
readonly signerAddresses?: readonly string[];
|
|
76
|
+
/** Advertised versions; omitted means unknown, as for a real adapter. */
|
|
77
|
+
readonly supportedTransactionVersions?: readonly TransactionVersion[];
|
|
78
|
+
/**
|
|
79
|
+
* Responses for successive sends; the last one repeats. A failure outcome
|
|
80
|
+
* is thrown as a `TransactionExecutionError`, `'stall'` never settles.
|
|
81
|
+
* Default: confirmed, with a distinct signature and slot per call.
|
|
82
|
+
*/
|
|
83
|
+
readonly responses?: readonly WalletFixtureResponse[];
|
|
84
|
+
/**
|
|
85
|
+
* Result of `inspectTransaction`, or `false` for a wallet without the
|
|
86
|
+
* inspection capability. Default: a successful simulation.
|
|
87
|
+
*/
|
|
88
|
+
readonly inspection?: TransactionInspectionResult | false;
|
|
89
|
+
}
|
|
90
|
+
interface WalletFixture extends WalletAdapter {
|
|
91
|
+
/** Every `signAndSend` call, in order. */
|
|
92
|
+
readonly sent: WalletFixtureCall<SendOptions>[];
|
|
93
|
+
/** Every `inspectTransaction` call, in order. */
|
|
94
|
+
readonly inspected: WalletFixtureCall<TransactionInspectionOptions>[];
|
|
95
|
+
/** Forget every recorded call. */
|
|
96
|
+
reset(): void;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* A recording {@link WalletAdapter} for tests. It holds no keys and builds no
|
|
100
|
+
* transactions: `signAndSend` answers from `responses`, so a test can drive a
|
|
101
|
+
* mutation through every outcome without a chain.
|
|
102
|
+
*/
|
|
103
|
+
declare function createWalletFixture(options?: WalletFixtureOptions): WalletFixture;
|
|
104
|
+
|
|
105
|
+
/** A deterministic, well-formed transaction signature for fixtures. */
|
|
106
|
+
declare const FIXTURE_SIGNATURE: string;
|
|
107
|
+
/** The slot fixture outcomes land in. */
|
|
108
|
+
declare const FIXTURE_SLOT = 4242;
|
|
109
|
+
/** Every status/phase pair the outcome model defines. */
|
|
110
|
+
type TransactionOutcomeFixtureName = 'confirmed' | 'not-submitted:build' | 'not-submitted:wallet' | 'not-submitted:send' | 'submitted-unknown:send' | 'submitted-unknown:confirmation' | 'chain-failed:confirmation' | 'chain-failed:chain';
|
|
111
|
+
declare function fixtures(): {
|
|
112
|
+
confirmed: ConfirmedTransactionOutcome;
|
|
113
|
+
'not-submitted:build': {
|
|
114
|
+
status: "not-submitted";
|
|
115
|
+
phase: "build" | "wallet" | "send";
|
|
116
|
+
cause: Error;
|
|
117
|
+
};
|
|
118
|
+
'not-submitted:wallet': {
|
|
119
|
+
status: "not-submitted";
|
|
120
|
+
phase: "build" | "wallet" | "send";
|
|
121
|
+
cause: Error;
|
|
122
|
+
};
|
|
123
|
+
'not-submitted:send': {
|
|
124
|
+
status: "not-submitted";
|
|
125
|
+
phase: "build" | "wallet" | "send";
|
|
126
|
+
cause: Error;
|
|
127
|
+
};
|
|
128
|
+
'submitted-unknown:send': {
|
|
129
|
+
status: "submitted-unknown";
|
|
130
|
+
phase: "send" | "confirmation";
|
|
131
|
+
signature: string;
|
|
132
|
+
cause: Error;
|
|
133
|
+
};
|
|
134
|
+
'submitted-unknown:confirmation': {
|
|
135
|
+
status: "submitted-unknown";
|
|
136
|
+
phase: "send" | "confirmation";
|
|
137
|
+
signature: string;
|
|
138
|
+
cause: Error;
|
|
139
|
+
};
|
|
140
|
+
'chain-failed:confirmation': {
|
|
141
|
+
status: "chain-failed";
|
|
142
|
+
phase: "confirmation" | "chain";
|
|
143
|
+
signature: string;
|
|
144
|
+
slot: number;
|
|
145
|
+
programError: {
|
|
146
|
+
code: number;
|
|
147
|
+
name: string;
|
|
148
|
+
message: string;
|
|
149
|
+
};
|
|
150
|
+
cause: {
|
|
151
|
+
InstructionError: (number | {
|
|
152
|
+
Custom: number;
|
|
153
|
+
})[];
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
'chain-failed:chain': {
|
|
157
|
+
status: "chain-failed";
|
|
158
|
+
phase: "confirmation" | "chain";
|
|
159
|
+
signature: string;
|
|
160
|
+
slot: number;
|
|
161
|
+
programError: {
|
|
162
|
+
code: number;
|
|
163
|
+
name: string;
|
|
164
|
+
message: string;
|
|
165
|
+
};
|
|
166
|
+
cause: {
|
|
167
|
+
InstructionError: (number | {
|
|
168
|
+
Custom: number;
|
|
169
|
+
})[];
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* One fresh outcome per status/phase pair of the transaction outcome model:
|
|
175
|
+
* `confirmed`, `not-submitted`, `submitted-unknown` and `chain-failed`.
|
|
176
|
+
*/
|
|
177
|
+
declare function createTransactionOutcomeFixtures(): ReturnType<typeof fixtures>;
|
|
178
|
+
/** One outcome by name, with optional field overrides. */
|
|
179
|
+
declare function transactionOutcomeFixture<TName extends TransactionOutcomeFixtureName>(name: TName, overrides?: Partial<ReturnType<typeof fixtures>[TName]>): ReturnType<typeof fixtures>[TName];
|
|
180
|
+
/**
|
|
181
|
+
* The structured error an adapter throws for a failure outcome, as
|
|
182
|
+
* `useMutation`, `execute` and `getTransactionFailureOutcome` classify it.
|
|
183
|
+
*/
|
|
184
|
+
declare function transactionFailureError(outcome: TransactionFailureOutcome): TransactionExecutionError;
|
|
185
|
+
|
|
186
|
+
/** The subscription a frame answers: a client `subscribe` message, or its id and query. */
|
|
187
|
+
interface FrameTarget {
|
|
188
|
+
readonly subscriptionId: string;
|
|
189
|
+
readonly query: SubscriptionQuery;
|
|
190
|
+
}
|
|
191
|
+
interface LiveFrameOptions {
|
|
192
|
+
/** Defaults to `'state'` for keyed queries and `'list'` otherwise. */
|
|
193
|
+
readonly mode?: FrameMode;
|
|
194
|
+
/** `"<slot>:<index>"` sequence. */
|
|
195
|
+
readonly seq?: string;
|
|
196
|
+
/** Tape offset, for replayable append views. */
|
|
197
|
+
readonly offset?: number;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Builders for WebSocket protocol v2 server frames, addressed to a
|
|
201
|
+
* subscription. Payloads use the wire shape (snake_case, u64 as decimal
|
|
202
|
+
* strings); the SDK's generated schemas normalize them as they would live.
|
|
203
|
+
*/
|
|
204
|
+
declare const frames: {
|
|
205
|
+
subscribed(target: FrameTarget, options?: {
|
|
206
|
+
readonly mode?: FrameMode;
|
|
207
|
+
readonly sort?: SortConfig;
|
|
208
|
+
readonly replayWindow?: ReplayWindow;
|
|
209
|
+
/**
|
|
210
|
+
* Advertise the whole-entity guarantee, as current servers do (the
|
|
211
|
+
* default). Pass `false` to act as an older server, whose patches for
|
|
212
|
+
* keys the client does not hold are kept.
|
|
213
|
+
*/
|
|
214
|
+
readonly wholeEntities?: boolean;
|
|
215
|
+
}): {
|
|
216
|
+
wholeEntities?: boolean | undefined;
|
|
217
|
+
replayWindow?: ReplayWindow | undefined;
|
|
218
|
+
sort?: SortConfig | undefined;
|
|
219
|
+
protocolVersion: 2;
|
|
220
|
+
subscriptionId: string;
|
|
221
|
+
op: "subscribed";
|
|
222
|
+
query: SubscriptionQuery;
|
|
223
|
+
mode: FrameMode;
|
|
224
|
+
};
|
|
225
|
+
snapshot(target: FrameTarget, rows: readonly {
|
|
226
|
+
readonly key: string;
|
|
227
|
+
readonly data: unknown;
|
|
228
|
+
}[], options?: {
|
|
229
|
+
readonly mode?: FrameMode;
|
|
230
|
+
readonly snapshotId?: string;
|
|
231
|
+
readonly authoritative?: boolean;
|
|
232
|
+
readonly complete?: boolean;
|
|
233
|
+
}): {
|
|
234
|
+
data: {
|
|
235
|
+
key: string;
|
|
236
|
+
data: unknown;
|
|
237
|
+
}[];
|
|
238
|
+
complete: boolean;
|
|
239
|
+
key?: string | undefined;
|
|
240
|
+
protocolVersion: 2;
|
|
241
|
+
subscriptionId: string;
|
|
242
|
+
snapshotId: string;
|
|
243
|
+
authoritative: boolean;
|
|
244
|
+
mode: FrameMode;
|
|
245
|
+
entity: string;
|
|
246
|
+
op: "snapshot";
|
|
247
|
+
};
|
|
248
|
+
upsert(target: FrameTarget, key: string, data: unknown, options?: LiveFrameOptions): {
|
|
249
|
+
append?: string[] | undefined;
|
|
250
|
+
offset?: number | undefined;
|
|
251
|
+
seq?: string | undefined;
|
|
252
|
+
protocolVersion: 2;
|
|
253
|
+
subscriptionId: string;
|
|
254
|
+
mode: FrameMode;
|
|
255
|
+
entity: string;
|
|
256
|
+
op: "upsert" | "patch" | "remove" | "delete";
|
|
257
|
+
key: string;
|
|
258
|
+
data: unknown;
|
|
259
|
+
};
|
|
260
|
+
patch(target: FrameTarget, key: string, data: unknown, options?: LiveFrameOptions & {
|
|
261
|
+
readonly append?: readonly string[];
|
|
262
|
+
}): {
|
|
263
|
+
append?: string[] | undefined;
|
|
264
|
+
offset?: number | undefined;
|
|
265
|
+
seq?: string | undefined;
|
|
266
|
+
protocolVersion: 2;
|
|
267
|
+
subscriptionId: string;
|
|
268
|
+
mode: FrameMode;
|
|
269
|
+
entity: string;
|
|
270
|
+
op: "upsert" | "patch" | "remove" | "delete";
|
|
271
|
+
key: string;
|
|
272
|
+
data: unknown;
|
|
273
|
+
};
|
|
274
|
+
remove(target: FrameTarget, key: string, options?: LiveFrameOptions): {
|
|
275
|
+
append?: string[] | undefined;
|
|
276
|
+
offset?: number | undefined;
|
|
277
|
+
seq?: string | undefined;
|
|
278
|
+
protocolVersion: 2;
|
|
279
|
+
subscriptionId: string;
|
|
280
|
+
mode: FrameMode;
|
|
281
|
+
entity: string;
|
|
282
|
+
op: "upsert" | "patch" | "remove" | "delete";
|
|
283
|
+
key: string;
|
|
284
|
+
data: unknown;
|
|
285
|
+
};
|
|
286
|
+
delete(target: FrameTarget, key: string, options?: LiveFrameOptions): {
|
|
287
|
+
append?: string[] | undefined;
|
|
288
|
+
offset?: number | undefined;
|
|
289
|
+
seq?: string | undefined;
|
|
290
|
+
protocolVersion: 2;
|
|
291
|
+
subscriptionId: string;
|
|
292
|
+
mode: FrameMode;
|
|
293
|
+
entity: string;
|
|
294
|
+
op: "upsert" | "patch" | "remove" | "delete";
|
|
295
|
+
key: string;
|
|
296
|
+
data: unknown;
|
|
297
|
+
};
|
|
298
|
+
error(target: FrameTarget | null, code: string, options?: {
|
|
299
|
+
readonly message?: string;
|
|
300
|
+
readonly fatal?: boolean;
|
|
301
|
+
readonly retryable?: boolean;
|
|
302
|
+
}): {
|
|
303
|
+
type: "error";
|
|
304
|
+
protocolVersion: 2;
|
|
305
|
+
subscriptionId: string | null;
|
|
306
|
+
code: string;
|
|
307
|
+
message: string;
|
|
308
|
+
fatal: boolean;
|
|
309
|
+
retryable: boolean;
|
|
310
|
+
};
|
|
311
|
+
};
|
|
312
|
+
interface FrameHarnessOptions {
|
|
313
|
+
readonly maxEntriesPerView?: number | null;
|
|
314
|
+
readonly schemas?: Record<string, Schema<unknown>>;
|
|
315
|
+
readonly patchSchemas?: Record<string, Schema<unknown>>;
|
|
316
|
+
readonly onValidationError?: (diagnostic: FrameValidationDiagnostic) => void;
|
|
317
|
+
}
|
|
318
|
+
interface FrameHarness {
|
|
319
|
+
readonly storage: MemoryAdapter;
|
|
320
|
+
readonly queries: QueryStore;
|
|
321
|
+
readonly processor: FrameProcessor;
|
|
322
|
+
/** Register a local subscription, as a view lease would, and return it. */
|
|
323
|
+
subscribe(subscriptionId: string, query: SubscriptionQuery, options?: {
|
|
324
|
+
readonly snapshot?: boolean;
|
|
325
|
+
}): Subscription;
|
|
326
|
+
/** Process one server frame exactly as it would arrive on the wire. */
|
|
327
|
+
process(frame: unknown): void;
|
|
328
|
+
/** The query's current snapshot, as view verbs read it. */
|
|
329
|
+
snapshot<T = unknown>(subscriptionId: string): QuerySnapshot<T> | undefined;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* The client store engine without a socket: feed it protocol v2 frames and
|
|
333
|
+
* read query snapshots. Every frame is serialized and parsed as it would be
|
|
334
|
+
* on the wire, so malformed fixtures fail the same way live frames do.
|
|
335
|
+
*/
|
|
336
|
+
declare function createFrameHarness(options?: FrameHarnessOptions): FrameHarness;
|
|
337
|
+
|
|
338
|
+
type Listener = ((event: never) => void) | null;
|
|
339
|
+
/**
|
|
340
|
+
* An in-memory WebSocket the SDK connects to through `auth.websocketFactory`.
|
|
341
|
+
* The client side is the standard `WebSocket` surface the SDK uses; the
|
|
342
|
+
* server side is `deliver`, `serverClose` and `fail`.
|
|
343
|
+
*/
|
|
344
|
+
declare class FakeWebSocket {
|
|
345
|
+
readonly url: string;
|
|
346
|
+
readonly init?: WebSocketFactoryInit | undefined;
|
|
347
|
+
static readonly CONNECTING = 0;
|
|
348
|
+
static readonly OPEN = 1;
|
|
349
|
+
static readonly CLOSING = 2;
|
|
350
|
+
static readonly CLOSED = 3;
|
|
351
|
+
readonly CONNECTING = 0;
|
|
352
|
+
readonly OPEN = 1;
|
|
353
|
+
readonly CLOSING = 2;
|
|
354
|
+
readonly CLOSED = 3;
|
|
355
|
+
readyState: number;
|
|
356
|
+
binaryType: 'blob' | 'arraybuffer';
|
|
357
|
+
onopen: Listener;
|
|
358
|
+
onmessage: ((event: {
|
|
359
|
+
data: unknown;
|
|
360
|
+
}) => void | Promise<void>) | null;
|
|
361
|
+
onerror: Listener;
|
|
362
|
+
onclose: ((event: {
|
|
363
|
+
code: number;
|
|
364
|
+
reason: string;
|
|
365
|
+
wasClean: boolean;
|
|
366
|
+
}) => void) | null;
|
|
367
|
+
/** Raw messages the client sent, in order. */
|
|
368
|
+
readonly sent: string[];
|
|
369
|
+
constructor(url: string, init?: WebSocketFactoryInit | undefined, autoOpen?: boolean);
|
|
370
|
+
/** Client side: queue an outgoing message. */
|
|
371
|
+
send(data: string): void;
|
|
372
|
+
/** Client side: close the socket. */
|
|
373
|
+
close(code?: number, reason?: string): void;
|
|
374
|
+
/** Server side: accept the connection (automatic unless disabled). */
|
|
375
|
+
open(): void;
|
|
376
|
+
/** Server side: deliver one message (objects are sent as JSON text). */
|
|
377
|
+
deliver(message: unknown): void;
|
|
378
|
+
/** Server side: close the connection with a code and reason. */
|
|
379
|
+
serverClose(code?: number, reason?: string): void;
|
|
380
|
+
/** Server side: fail the socket as a network error would. */
|
|
381
|
+
fail(): void;
|
|
382
|
+
/** Parsed `subscribe` messages this socket received. */
|
|
383
|
+
subscriptions(): Subscription[];
|
|
384
|
+
}
|
|
385
|
+
interface WebSocketHarnessOptions {
|
|
386
|
+
/** Open sockets automatically on the next microtask (default `true`). */
|
|
387
|
+
readonly autoOpen?: boolean;
|
|
388
|
+
/**
|
|
389
|
+
* Install {@link FakeWebSocket} as `globalThis.WebSocket` when the runtime has
|
|
390
|
+
* none (Node 20 and older), because the SDK reads the standard readyState
|
|
391
|
+
* constants from it. Default `true`; `restore()` removes it again.
|
|
392
|
+
*/
|
|
393
|
+
readonly installGlobal?: boolean;
|
|
394
|
+
}
|
|
395
|
+
interface WebSocketHarness {
|
|
396
|
+
/** Pass as `auth.websocketFactory` (core) or `<AreteProvider auth={…}>`. */
|
|
397
|
+
readonly websocketFactory: (url: string, init?: WebSocketFactoryInit) => WebSocket;
|
|
398
|
+
/** Every socket the client opened, oldest first. */
|
|
399
|
+
readonly sockets: readonly FakeWebSocket[];
|
|
400
|
+
/** The most recent socket; throws if the client never connected. */
|
|
401
|
+
latest(): FakeWebSocket;
|
|
402
|
+
/** Subscriptions sent on the latest socket, oldest first. */
|
|
403
|
+
subscriptions(): Subscription[];
|
|
404
|
+
/**
|
|
405
|
+
* The latest subscription for a view (or matching a predicate); throws when
|
|
406
|
+
* the client has not subscribed yet.
|
|
407
|
+
*/
|
|
408
|
+
subscription(match?: string | ((subscription: Subscription) => boolean)): Subscription;
|
|
409
|
+
/**
|
|
410
|
+
* Resolve with the latest subscription for a view (or matching a
|
|
411
|
+
* predicate) once the client has sent it; rejects after `timeoutMs`
|
|
412
|
+
* (default 1000). Subscribing is asynchronous, so tests usually await this.
|
|
413
|
+
*/
|
|
414
|
+
waitForSubscription(match?: string | ((subscription: Subscription) => boolean), timeoutMs?: number): Promise<Subscription>;
|
|
415
|
+
/** Deliver a server frame on the latest socket. */
|
|
416
|
+
send(frame: unknown): void;
|
|
417
|
+
/** Acknowledge a subscription and answer it with an authoritative snapshot. */
|
|
418
|
+
serve(target: FrameTarget, rows: readonly {
|
|
419
|
+
readonly key: string;
|
|
420
|
+
readonly data: unknown;
|
|
421
|
+
}[], options?: Parameters<typeof frames.subscribed>[1]): void;
|
|
422
|
+
/** Remove the global installed by `installGlobal`, if any. */
|
|
423
|
+
restore(): void;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* A scripted WebSocket server for tests. The SDK connects to it through
|
|
427
|
+
* `auth.websocketFactory`, so views, snapshots, live frames, reconnects and
|
|
428
|
+
* errors run through the real client without a network.
|
|
429
|
+
*/
|
|
430
|
+
declare function createWebSocketHarness(options?: WebSocketHarnessOptions): WebSocketHarness;
|
|
431
|
+
|
|
432
|
+
interface FetchStubRequest {
|
|
433
|
+
readonly url: string;
|
|
434
|
+
readonly method: string;
|
|
435
|
+
readonly headers: Headers;
|
|
436
|
+
/** Request body as text, when one was sent. */
|
|
437
|
+
readonly body: string | undefined;
|
|
438
|
+
}
|
|
439
|
+
/** A route's answer: a `Response`, or a value serialized as JSON with status 200. */
|
|
440
|
+
type FetchStubReply = Response | unknown;
|
|
441
|
+
interface FetchStubRoute {
|
|
442
|
+
/** Substring of the URL, a pattern, or a predicate. */
|
|
443
|
+
readonly match: string | RegExp | ((request: FetchStubRequest) => boolean);
|
|
444
|
+
/** Only match this HTTP method (case-insensitive). */
|
|
445
|
+
readonly method?: string;
|
|
446
|
+
/** Static reply, or a function computing one per request. */
|
|
447
|
+
readonly reply: FetchStubReply | ((request: FetchStubRequest) => FetchStubReply | Promise<FetchStubReply>);
|
|
448
|
+
/** Status for non-`Response` replies (default 200). */
|
|
449
|
+
readonly status?: number;
|
|
450
|
+
}
|
|
451
|
+
interface FetchStubOptions {
|
|
452
|
+
/** Answer for requests no route matches (default: a 404 JSON error). */
|
|
453
|
+
readonly fallback?: (request: FetchStubRequest) => FetchStubReply | Promise<FetchStubReply>;
|
|
454
|
+
}
|
|
455
|
+
interface FetchStub {
|
|
456
|
+
(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
457
|
+
/** Every request, in order. */
|
|
458
|
+
readonly calls: FetchStubRequest[];
|
|
459
|
+
/** Forget every recorded request. */
|
|
460
|
+
reset(): void;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* JSON with the SDK's wire rule for integers: `bigint` values are written as
|
|
464
|
+
* decimal strings, as the server sends u64 fields.
|
|
465
|
+
*/
|
|
466
|
+
declare function jsonResponse(body: unknown, init?: ResponseInit): Response;
|
|
467
|
+
/**
|
|
468
|
+
* A routed, recording `fetch` for tests: pass it as `ConnectOptions.fetch`,
|
|
469
|
+
* `createSession(…, { fetch })` or `<AreteProvider fetch={…}>`. Routes are
|
|
470
|
+
* tried in order; the first match answers.
|
|
471
|
+
*
|
|
472
|
+
* ```ts
|
|
473
|
+
* const fetch = createFetchStub([
|
|
474
|
+
* { match: '/accounts/Miner/', reply: { authority: 'wallet', rewards_ore: '12' } },
|
|
475
|
+
* { match: '/chain/exists/', reply: { exists: true } },
|
|
476
|
+
* ]);
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
479
|
+
declare function createFetchStub(routes?: readonly FetchStubRoute[], options?: FetchStubOptions): FetchStub;
|
|
480
|
+
|
|
481
|
+
export { FIXTURE_SIGNATURE, FIXTURE_SLOT, FIXTURE_WALLET_ADDRESS, FakeWebSocket, createFakeTransactionTransport, createFetchStub, createFrameHarness, createTransactionOutcomeFixtures, createWalletFixture, createWebSocketHarness, firstSignatureOfWireTransaction, frames, jsonResponse, transactionFailureError, transactionOutcomeFixture };
|
|
482
|
+
export type { FakeTransactionCall, FakeTransactionTransport, FakeTransactionTransportOptions, FetchStub, FetchStubOptions, FetchStubReply, FetchStubRequest, FetchStubRoute, FrameHarness, FrameHarnessOptions, FrameTarget, TransactionOutcomeFixtureName, WalletFixture, WalletFixtureCall, WalletFixtureOptions, WalletFixtureResponse, WebSocketHarness, WebSocketHarnessOptions };
|