@deriverse/kit 1.0.39 → 1.0.42
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/dist/auto_buffer.d.ts +0 -2
- package/dist/auto_data.d.ts +0 -2
- package/dist/constants.d.ts +14 -0
- package/dist/constants.js +28 -0
- package/dist/engine/account-helpers.d.ts +59 -0
- package/dist/engine/account-helpers.js +177 -0
- package/dist/engine/account-helpers.test.d.ts +1 -0
- package/dist/engine/account-helpers.test.js +199 -0
- package/dist/engine/client-queries.d.ts +36 -0
- package/dist/engine/client-queries.js +498 -0
- package/dist/engine/client-queries.test.d.ts +1 -0
- package/dist/engine/client-queries.test.js +341 -0
- package/dist/engine/context-builders.d.ts +16 -0
- package/dist/engine/context-builders.js +158 -0
- package/dist/engine/context-builders.test.d.ts +1 -0
- package/dist/engine/context-builders.test.js +156 -0
- package/dist/engine/index.d.ts +101 -0
- package/dist/engine/index.js +745 -0
- package/dist/engine/index.test.d.ts +1 -0
- package/dist/engine/index.test.js +685 -0
- package/dist/engine/logs-decoder.d.ts +18 -0
- package/dist/engine/logs-decoder.js +525 -0
- package/dist/engine/logs-decoder.test.d.ts +1 -0
- package/dist/engine/logs-decoder.test.js +836 -0
- package/dist/engine/perp-instructions.d.ts +68 -0
- package/dist/engine/perp-instructions.js +497 -0
- package/dist/engine/perp-instructions.test.d.ts +1 -0
- package/dist/engine/perp-instructions.test.js +292 -0
- package/dist/engine/spot-instructions.d.ts +52 -0
- package/dist/engine/spot-instructions.js +399 -0
- package/dist/engine/spot-instructions.test.d.ts +1 -0
- package/dist/engine/spot-instructions.test.js +221 -0
- package/dist/engine/utils.d.ts +23 -0
- package/dist/engine/utils.js +332 -0
- package/dist/engine/utils.test.d.ts +1 -0
- package/dist/engine/utils.test.js +120 -0
- package/dist/index.d.ts +6 -247
- package/dist/index.js +14 -2923
- package/dist/instruction_models.d.ts +10 -9
- package/dist/instruction_models.js +88 -69
- package/dist/logs_models.d.ts +147 -5
- package/dist/logs_models.js +243 -13
- package/dist/structure_models.d.ts +104 -99
- package/dist/structure_models.js +152 -129
- package/dist/types/engine-args.d.ts +32 -0
- package/dist/types/engine-args.js +2 -0
- package/dist/types/enums.d.ts +43 -0
- package/dist/{types.js → types/enums.js} +3 -5
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.js +38 -0
- package/dist/types/log-message.d.ts +2 -0
- package/dist/types/log-message.js +2 -0
- package/dist/types/responses.d.ts +248 -0
- package/dist/types/responses.js +2 -0
- package/dist/types/schemas.d.ts +168 -0
- package/dist/types/schemas.js +239 -0
- package/dist/types/schemas.test.d.ts +1 -0
- package/dist/types/schemas.test.js +93 -0
- package/dist/utils.d.ts +0 -0
- package/dist/utils.js +1 -0
- package/package.json +26 -6
- package/dist/types.d.ts +0 -565
|
@@ -0,0 +1,685 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const vitest_1 = require("vitest");
|
|
13
|
+
const index_1 = require("./index");
|
|
14
|
+
const constants_1 = require("../constants");
|
|
15
|
+
const structure_models_1 = require("../structure_models");
|
|
16
|
+
// Mock account-helpers
|
|
17
|
+
vitest_1.vi.mock('./account-helpers', () => ({
|
|
18
|
+
getAccountByTag: vitest_1.vi.fn().mockResolvedValue('MockAccountByTag1111111111111111'),
|
|
19
|
+
getInstrAccountByTag: vitest_1.vi.fn().mockResolvedValue('MockInstrAccount111111111111111'),
|
|
20
|
+
getTokenAccount: vitest_1.vi.fn().mockResolvedValue('MockTokenAccount11111111111111111'),
|
|
21
|
+
getTokenId: vitest_1.vi.fn().mockResolvedValue(1),
|
|
22
|
+
getInstrId: vitest_1.vi.fn().mockResolvedValue(1),
|
|
23
|
+
findClientPrimaryAccount: vitest_1.vi.fn().mockResolvedValue('MockClientPrimary1111111111111111'),
|
|
24
|
+
findClientCommunityAccount: vitest_1.vi.fn().mockResolvedValue('MockClientCommunity11111111111111'),
|
|
25
|
+
findAccountsByTag: vitest_1.vi.fn().mockResolvedValue([]),
|
|
26
|
+
AccountHelperContext: {},
|
|
27
|
+
}));
|
|
28
|
+
// Mock spot-instructions
|
|
29
|
+
vitest_1.vi.mock('./spot-instructions', () => ({
|
|
30
|
+
buildDepositInstruction: vitest_1.vi.fn().mockResolvedValue({
|
|
31
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
32
|
+
accounts: [],
|
|
33
|
+
data: new Uint8Array([7]),
|
|
34
|
+
}),
|
|
35
|
+
buildWithdrawInstruction: vitest_1.vi.fn().mockResolvedValue({
|
|
36
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
37
|
+
accounts: [],
|
|
38
|
+
data: new Uint8Array([8]),
|
|
39
|
+
}),
|
|
40
|
+
buildSpotLpInstruction: vitest_1.vi.fn().mockResolvedValue({
|
|
41
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
42
|
+
accounts: [],
|
|
43
|
+
data: new Uint8Array([9]),
|
|
44
|
+
}),
|
|
45
|
+
buildNewSpotOrderInstruction: vitest_1.vi.fn().mockResolvedValue({
|
|
46
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
47
|
+
accounts: [],
|
|
48
|
+
data: new Uint8Array([10]),
|
|
49
|
+
}),
|
|
50
|
+
buildSpotQuotesReplaceInstruction: vitest_1.vi.fn().mockResolvedValue({
|
|
51
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
52
|
+
accounts: [],
|
|
53
|
+
data: new Uint8Array([11]),
|
|
54
|
+
}),
|
|
55
|
+
buildSpotOrderCancelInstruction: vitest_1.vi.fn().mockResolvedValue({
|
|
56
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
57
|
+
accounts: [],
|
|
58
|
+
data: new Uint8Array([12]),
|
|
59
|
+
}),
|
|
60
|
+
buildSpotMassCancelInstruction: vitest_1.vi.fn().mockResolvedValue({
|
|
61
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
62
|
+
accounts: [],
|
|
63
|
+
data: new Uint8Array([13]),
|
|
64
|
+
}),
|
|
65
|
+
buildSwapInstruction: vitest_1.vi.fn().mockResolvedValue({
|
|
66
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
67
|
+
accounts: [],
|
|
68
|
+
data: new Uint8Array([14]),
|
|
69
|
+
}),
|
|
70
|
+
SpotInstructionContext: {},
|
|
71
|
+
}));
|
|
72
|
+
// Mock perp-instructions
|
|
73
|
+
vitest_1.vi.mock('./perp-instructions', () => ({
|
|
74
|
+
buildUpgradeToPerpInstructions: vitest_1.vi.fn().mockResolvedValue([
|
|
75
|
+
{
|
|
76
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
77
|
+
accounts: [],
|
|
78
|
+
data: new Uint8Array([20]),
|
|
79
|
+
},
|
|
80
|
+
]),
|
|
81
|
+
buildPerpDepositInstruction: vitest_1.vi.fn().mockResolvedValue({
|
|
82
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
83
|
+
accounts: [],
|
|
84
|
+
data: new Uint8Array([21]),
|
|
85
|
+
}),
|
|
86
|
+
buildPerpBuySeatInstruction: vitest_1.vi.fn().mockResolvedValue({
|
|
87
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
88
|
+
accounts: [],
|
|
89
|
+
data: new Uint8Array([22]),
|
|
90
|
+
}),
|
|
91
|
+
buildPerpSellSeatInstruction: vitest_1.vi.fn().mockResolvedValue({
|
|
92
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
93
|
+
accounts: [],
|
|
94
|
+
data: new Uint8Array([23]),
|
|
95
|
+
}),
|
|
96
|
+
buildNewPerpOrderInstruction: vitest_1.vi.fn().mockResolvedValue({
|
|
97
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
98
|
+
accounts: [],
|
|
99
|
+
data: new Uint8Array([24]),
|
|
100
|
+
}),
|
|
101
|
+
buildPerpQuotesReplaceInstruction: vitest_1.vi.fn().mockResolvedValue({
|
|
102
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
103
|
+
accounts: [],
|
|
104
|
+
data: new Uint8Array([25]),
|
|
105
|
+
}),
|
|
106
|
+
buildPerpOrderCancelInstruction: vitest_1.vi.fn().mockResolvedValue({
|
|
107
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
108
|
+
accounts: [],
|
|
109
|
+
data: new Uint8Array([26]),
|
|
110
|
+
}),
|
|
111
|
+
buildPerpMassCancelInstruction: vitest_1.vi.fn().mockResolvedValue({
|
|
112
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
113
|
+
accounts: [],
|
|
114
|
+
data: new Uint8Array([27]),
|
|
115
|
+
}),
|
|
116
|
+
buildPerpChangeLeverageInstruction: vitest_1.vi.fn().mockResolvedValue({
|
|
117
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
118
|
+
accounts: [],
|
|
119
|
+
data: new Uint8Array([28]),
|
|
120
|
+
}),
|
|
121
|
+
buildPerpStatisticsResetInstruction: vitest_1.vi.fn().mockResolvedValue({
|
|
122
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
123
|
+
accounts: [],
|
|
124
|
+
data: new Uint8Array([29]),
|
|
125
|
+
}),
|
|
126
|
+
buildNewRefLinkInstruction: vitest_1.vi.fn().mockResolvedValue({
|
|
127
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
128
|
+
accounts: [],
|
|
129
|
+
data: new Uint8Array([30]),
|
|
130
|
+
}),
|
|
131
|
+
buildNewInstrumentInstructions: vitest_1.vi.fn().mockResolvedValue([
|
|
132
|
+
{
|
|
133
|
+
programAddress: 'MockProgram1111111111111111111111111',
|
|
134
|
+
accounts: [],
|
|
135
|
+
data: new Uint8Array([31]),
|
|
136
|
+
},
|
|
137
|
+
]),
|
|
138
|
+
PerpInstructionContext: {},
|
|
139
|
+
}));
|
|
140
|
+
// Mock context-builders
|
|
141
|
+
vitest_1.vi.mock('./context-builders', () => ({
|
|
142
|
+
getSpotContext: vitest_1.vi.fn().mockResolvedValue([]),
|
|
143
|
+
getPerpContext: vitest_1.vi.fn().mockResolvedValue([]),
|
|
144
|
+
getSpotCandles: vitest_1.vi.fn().mockResolvedValue([]),
|
|
145
|
+
}));
|
|
146
|
+
// Mock logs-decoder
|
|
147
|
+
vitest_1.vi.mock('./logs-decoder', () => ({
|
|
148
|
+
decodeTransactionLogs: vitest_1.vi.fn().mockReturnValue([]),
|
|
149
|
+
}));
|
|
150
|
+
// Import mocked modules for assertions
|
|
151
|
+
const spot_instructions_1 = require("./spot-instructions");
|
|
152
|
+
const perp_instructions_1 = require("./perp-instructions");
|
|
153
|
+
// Mock RPC for testing
|
|
154
|
+
const createMockRpc = () => ({
|
|
155
|
+
getAccountInfo: vitest_1.vi.fn().mockReturnValue({ send: vitest_1.vi.fn() }),
|
|
156
|
+
getMultipleAccounts: vitest_1.vi.fn().mockReturnValue({ send: vitest_1.vi.fn() }),
|
|
157
|
+
getProgramAccounts: vitest_1.vi.fn().mockReturnValue({ send: vitest_1.vi.fn() }),
|
|
158
|
+
getSlot: vitest_1.vi.fn().mockReturnValue({ send: vitest_1.vi.fn().mockResolvedValue(BigInt(12345)) }),
|
|
159
|
+
getMinimumBalanceForRentExemption: vitest_1.vi.fn().mockReturnValue({ send: vitest_1.vi.fn().mockResolvedValue(BigInt(1000000)) }),
|
|
160
|
+
});
|
|
161
|
+
// Helper to create mock token
|
|
162
|
+
function createMockToken(id, decimals = 9) {
|
|
163
|
+
const token = new structure_models_1.TokenStateModel();
|
|
164
|
+
token.id = id;
|
|
165
|
+
token.mask = decimals;
|
|
166
|
+
return token;
|
|
167
|
+
}
|
|
168
|
+
// Helper to create mock instrument header
|
|
169
|
+
function createMockInstrHeader(instrId) {
|
|
170
|
+
const header = new structure_models_1.InstrAccountHeaderModel();
|
|
171
|
+
header.instrId = instrId;
|
|
172
|
+
header.assetTokenId = 1;
|
|
173
|
+
header.crncyTokenId = 2;
|
|
174
|
+
header.mask = 0;
|
|
175
|
+
header.mapsAddress = 'MockMapsAddress111111111111111111111';
|
|
176
|
+
header.perpMapsAddress = 'MockPerpMapsAddress1111111111111111';
|
|
177
|
+
header.lutAddress = 'MockLutAddress1111111111111111111111';
|
|
178
|
+
header.perpClientsCount = 10;
|
|
179
|
+
return header;
|
|
180
|
+
}
|
|
181
|
+
// Helper to create mock instruments map
|
|
182
|
+
function createMockInstrumentsMap() {
|
|
183
|
+
const map = new Map();
|
|
184
|
+
map.set(1, {
|
|
185
|
+
address: 'MockInstrAddress111111111111111111111',
|
|
186
|
+
header: createMockInstrHeader(1),
|
|
187
|
+
spotBids: [],
|
|
188
|
+
spotAsks: [],
|
|
189
|
+
perpBids: [],
|
|
190
|
+
perpAsks: [],
|
|
191
|
+
});
|
|
192
|
+
return map;
|
|
193
|
+
}
|
|
194
|
+
// Helper to create mock tokens map
|
|
195
|
+
function createMockTokensMap() {
|
|
196
|
+
const map = new Map();
|
|
197
|
+
map.set(0, createMockToken(0, 9)); // DRVS token
|
|
198
|
+
map.set(1, createMockToken(1, 9));
|
|
199
|
+
map.set(2, createMockToken(2, 6));
|
|
200
|
+
return map;
|
|
201
|
+
}
|
|
202
|
+
// Helper to setup engine with client connected
|
|
203
|
+
function setupEngineWithClient() {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
const mockRpc = createMockRpc();
|
|
206
|
+
const engine = new index_1.Engine(mockRpc);
|
|
207
|
+
// Setup required state
|
|
208
|
+
engine.tokens = createMockTokensMap();
|
|
209
|
+
engine.instruments = createMockInstrumentsMap();
|
|
210
|
+
engine.rootAccount = 'MockRootAccount11111111111111111111';
|
|
211
|
+
engine.communityAccount = 'MockCommunityAccount111111111111111';
|
|
212
|
+
engine.drvsAuthority = 'MockDrvsAuthority11111111111111111';
|
|
213
|
+
engine.rootStateModel = new structure_models_1.RootStateModel();
|
|
214
|
+
engine.rootStateModel.tokensCount = 3;
|
|
215
|
+
engine.rootStateModel.instrCount = 1;
|
|
216
|
+
// Setup client state directly (bypass setSigner complexity)
|
|
217
|
+
engine.signer = 'MockSigner1111111111111111111111111111';
|
|
218
|
+
engine.clientPrimaryAccount = 'MockClientPrimary1111111111111111';
|
|
219
|
+
engine.clientCommunityAccount = 'MockClientCommunity11111111111111';
|
|
220
|
+
engine.originalClientId = 12345;
|
|
221
|
+
// Mock updateInstrData to avoid RPC calls
|
|
222
|
+
vitest_1.vi.spyOn(engine, 'updateInstrData').mockResolvedValue(undefined);
|
|
223
|
+
return { engine, mockRpc };
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
(0, vitest_1.describe)('Engine class', () => {
|
|
227
|
+
(0, vitest_1.describe)('constructor', () => {
|
|
228
|
+
(0, vitest_1.it)('uses default PROGRAM_ID when not provided', () => {
|
|
229
|
+
const mockRpc = createMockRpc();
|
|
230
|
+
const engine = new index_1.Engine(mockRpc);
|
|
231
|
+
(0, vitest_1.expect)(engine.programId).toBe(constants_1.PROGRAM_ID);
|
|
232
|
+
});
|
|
233
|
+
(0, vitest_1.it)('uses default VERSION when not provided', () => {
|
|
234
|
+
const mockRpc = createMockRpc();
|
|
235
|
+
const engine = new index_1.Engine(mockRpc);
|
|
236
|
+
(0, vitest_1.expect)(engine.version).toBe(constants_1.VERSION);
|
|
237
|
+
});
|
|
238
|
+
(0, vitest_1.it)('uses default commitment (confirmed) when not provided', () => {
|
|
239
|
+
const mockRpc = createMockRpc();
|
|
240
|
+
const engine = new index_1.Engine(mockRpc);
|
|
241
|
+
(0, vitest_1.expect)(engine.commitment).toBe('confirmed');
|
|
242
|
+
});
|
|
243
|
+
(0, vitest_1.it)('accepts custom programId', () => {
|
|
244
|
+
const mockRpc = createMockRpc();
|
|
245
|
+
const customProgramId = 'CustomProgramId11111111111111111111111111111';
|
|
246
|
+
const engine = new index_1.Engine(mockRpc, { programId: customProgramId });
|
|
247
|
+
(0, vitest_1.expect)(engine.programId).toBe(customProgramId);
|
|
248
|
+
});
|
|
249
|
+
(0, vitest_1.it)('accepts custom version', () => {
|
|
250
|
+
const mockRpc = createMockRpc();
|
|
251
|
+
const engine = new index_1.Engine(mockRpc, { version: 2 });
|
|
252
|
+
(0, vitest_1.expect)(engine.version).toBe(2);
|
|
253
|
+
});
|
|
254
|
+
(0, vitest_1.it)('accepts custom commitment', () => {
|
|
255
|
+
const mockRpc = createMockRpc();
|
|
256
|
+
const engine = new index_1.Engine(mockRpc, { commitment: 'finalized' });
|
|
257
|
+
(0, vitest_1.expect)(engine.commitment).toBe('finalized');
|
|
258
|
+
});
|
|
259
|
+
(0, vitest_1.it)('accepts uiNumbers option', () => {
|
|
260
|
+
const mockRpc = createMockRpc();
|
|
261
|
+
// Default is true, test with false
|
|
262
|
+
const engine = new index_1.Engine(mockRpc, { uiNumbers: false });
|
|
263
|
+
// uiNumbers is private, so we can't directly test it
|
|
264
|
+
// But it should not throw
|
|
265
|
+
(0, vitest_1.expect)(engine).toBeDefined();
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
(0, vitest_1.describe)('logsDecode', () => {
|
|
269
|
+
(0, vitest_1.it)('returns empty array for error logs', () => {
|
|
270
|
+
const mockRpc = createMockRpc();
|
|
271
|
+
const engine = new index_1.Engine(mockRpc);
|
|
272
|
+
// Initialize empty maps for the test
|
|
273
|
+
engine.instruments = new Map();
|
|
274
|
+
engine.tokens = new Map();
|
|
275
|
+
const errorLogs = ['Program returned error: insufficient funds'];
|
|
276
|
+
const result = engine.logsDecode(errorLogs);
|
|
277
|
+
(0, vitest_1.expect)(result).toEqual([]);
|
|
278
|
+
});
|
|
279
|
+
(0, vitest_1.it)('returns empty array for logs starting with Error', () => {
|
|
280
|
+
const mockRpc = createMockRpc();
|
|
281
|
+
const engine = new index_1.Engine(mockRpc);
|
|
282
|
+
engine.instruments = new Map();
|
|
283
|
+
engine.tokens = new Map();
|
|
284
|
+
const errorLogs = ['Program logged: "Error: some error"'];
|
|
285
|
+
const result = engine.logsDecode(errorLogs);
|
|
286
|
+
(0, vitest_1.expect)(result).toEqual([]);
|
|
287
|
+
});
|
|
288
|
+
(0, vitest_1.it)('returns empty array for non-program data logs', () => {
|
|
289
|
+
const mockRpc = createMockRpc();
|
|
290
|
+
const engine = new index_1.Engine(mockRpc);
|
|
291
|
+
engine.instruments = new Map();
|
|
292
|
+
engine.tokens = new Map();
|
|
293
|
+
const otherLogs = ['Program invoke', 'Some other log'];
|
|
294
|
+
const result = engine.logsDecode(otherLogs);
|
|
295
|
+
(0, vitest_1.expect)(result).toEqual([]);
|
|
296
|
+
});
|
|
297
|
+
(0, vitest_1.it)('returns empty array for empty log array', () => {
|
|
298
|
+
const mockRpc = createMockRpc();
|
|
299
|
+
const engine = new index_1.Engine(mockRpc);
|
|
300
|
+
engine.instruments = new Map();
|
|
301
|
+
engine.tokens = new Map();
|
|
302
|
+
const result = engine.logsDecode([]);
|
|
303
|
+
(0, vitest_1.expect)(result).toEqual([]);
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
(0, vitest_1.describe)('initial state', () => {
|
|
307
|
+
(0, vitest_1.it)('has undefined rootAccount before initialization', () => {
|
|
308
|
+
const mockRpc = createMockRpc();
|
|
309
|
+
const engine = new index_1.Engine(mockRpc);
|
|
310
|
+
(0, vitest_1.expect)(engine.rootAccount).toBeUndefined();
|
|
311
|
+
});
|
|
312
|
+
(0, vitest_1.it)('has undefined tokens and instruments before initialization', () => {
|
|
313
|
+
const mockRpc = createMockRpc();
|
|
314
|
+
const engine = new index_1.Engine(mockRpc);
|
|
315
|
+
(0, vitest_1.expect)(engine.tokens).toBeUndefined();
|
|
316
|
+
(0, vitest_1.expect)(engine.instruments).toBeUndefined();
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
// ============================================
|
|
321
|
+
// INSTRUCTION METHOD BEHAVIOR TESTS
|
|
322
|
+
// ============================================
|
|
323
|
+
(0, vitest_1.describe)('Engine instruction methods', () => {
|
|
324
|
+
(0, vitest_1.beforeEach)(() => {
|
|
325
|
+
vitest_1.vi.clearAllMocks();
|
|
326
|
+
});
|
|
327
|
+
(0, vitest_1.describe)('depositInstruction', () => {
|
|
328
|
+
(0, vitest_1.it)('throws when wallet not connected', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
329
|
+
const mockRpc = createMockRpc();
|
|
330
|
+
const engine = new index_1.Engine(mockRpc);
|
|
331
|
+
yield (0, vitest_1.expect)(engine.depositInstruction({ tokenId: 1, amount: 100 })).rejects.toThrow('Wallet');
|
|
332
|
+
}));
|
|
333
|
+
(0, vitest_1.it)('calls buildDepositInstruction with correct args', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
334
|
+
const { engine } = yield setupEngineWithClient();
|
|
335
|
+
yield engine.depositInstruction({ tokenId: 1, amount: 100 });
|
|
336
|
+
(0, vitest_1.expect)(spot_instructions_1.buildDepositInstruction).toHaveBeenCalledWith(vitest_1.expect.objectContaining({
|
|
337
|
+
programId: engine.programId,
|
|
338
|
+
tokens: engine.tokens,
|
|
339
|
+
instruments: engine.instruments,
|
|
340
|
+
}), { tokenId: 1, amount: 100 }, vitest_1.expect.any(Boolean), vitest_1.expect.any(Function));
|
|
341
|
+
}));
|
|
342
|
+
(0, vitest_1.it)('returns instruction from builder', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
343
|
+
const { engine } = yield setupEngineWithClient();
|
|
344
|
+
const result = yield engine.depositInstruction({ tokenId: 1, amount: 100 });
|
|
345
|
+
(0, vitest_1.expect)(result).toBeDefined();
|
|
346
|
+
(0, vitest_1.expect)(result.data[0]).toBe(7); // deposit tag
|
|
347
|
+
}));
|
|
348
|
+
});
|
|
349
|
+
(0, vitest_1.describe)('withdrawInstruction', () => {
|
|
350
|
+
(0, vitest_1.it)('throws when client account not found', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
351
|
+
const mockRpc = createMockRpc();
|
|
352
|
+
const engine = new index_1.Engine(mockRpc);
|
|
353
|
+
engine.tokens = createMockTokensMap();
|
|
354
|
+
engine.instruments = createMockInstrumentsMap();
|
|
355
|
+
// Set signer but no client account
|
|
356
|
+
engine.signer = 'MockSigner1111111111111111111111111111';
|
|
357
|
+
engine.clientPrimaryAccount = null;
|
|
358
|
+
yield (0, vitest_1.expect)(engine.withdrawInstruction({ tokenId: 1, amount: 50 })).rejects.toThrow('Client account not found');
|
|
359
|
+
}));
|
|
360
|
+
(0, vitest_1.it)('calls buildWithdrawInstruction with correct args', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
361
|
+
const { engine } = yield setupEngineWithClient();
|
|
362
|
+
yield engine.withdrawInstruction({ tokenId: 1, amount: 50 });
|
|
363
|
+
(0, vitest_1.expect)(spot_instructions_1.buildWithdrawInstruction).toHaveBeenCalledWith(vitest_1.expect.objectContaining({
|
|
364
|
+
programId: engine.programId,
|
|
365
|
+
tokens: engine.tokens,
|
|
366
|
+
}), { tokenId: 1, amount: 50 });
|
|
367
|
+
}));
|
|
368
|
+
});
|
|
369
|
+
(0, vitest_1.describe)('spotLpInstruction', () => {
|
|
370
|
+
(0, vitest_1.it)('throws when client account not found', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
371
|
+
const mockRpc = createMockRpc();
|
|
372
|
+
const engine = new index_1.Engine(mockRpc);
|
|
373
|
+
engine.tokens = createMockTokensMap();
|
|
374
|
+
engine.instruments = createMockInstrumentsMap();
|
|
375
|
+
// Set signer but no client account
|
|
376
|
+
engine.signer = 'MockSigner1111111111111111111111111111';
|
|
377
|
+
engine.clientPrimaryAccount = null;
|
|
378
|
+
yield (0, vitest_1.expect)(engine.spotLpInstruction({ instrId: 1, side: 0, amount: 100 })).rejects.toThrow('Client account not found');
|
|
379
|
+
}));
|
|
380
|
+
(0, vitest_1.it)('calls buildSpotLpInstruction with correct args', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
381
|
+
const { engine } = yield setupEngineWithClient();
|
|
382
|
+
yield engine.spotLpInstruction({ instrId: 1, side: 0, amount: 100 });
|
|
383
|
+
(0, vitest_1.expect)(spot_instructions_1.buildSpotLpInstruction).toHaveBeenCalledWith(vitest_1.expect.objectContaining({
|
|
384
|
+
programId: engine.programId,
|
|
385
|
+
}), { instrId: 1, side: 0, amount: 100 }, vitest_1.expect.any(Object));
|
|
386
|
+
}));
|
|
387
|
+
});
|
|
388
|
+
(0, vitest_1.describe)('newSpotOrderInstruction', () => {
|
|
389
|
+
(0, vitest_1.it)('throws when client account not found', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
390
|
+
const mockRpc = createMockRpc();
|
|
391
|
+
const engine = new index_1.Engine(mockRpc);
|
|
392
|
+
engine.tokens = createMockTokensMap();
|
|
393
|
+
engine.instruments = createMockInstrumentsMap();
|
|
394
|
+
// Set signer but no client account
|
|
395
|
+
engine.signer = 'MockSigner1111111111111111111111111111';
|
|
396
|
+
engine.clientPrimaryAccount = null;
|
|
397
|
+
yield (0, vitest_1.expect)(engine.newSpotOrderInstruction({ instrId: 1, side: 0, price: 100, qty: 10 })).rejects.toThrow('Client account not found');
|
|
398
|
+
}));
|
|
399
|
+
(0, vitest_1.it)('calls buildNewSpotOrderInstruction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
400
|
+
const { engine } = yield setupEngineWithClient();
|
|
401
|
+
yield engine.newSpotOrderInstruction({ instrId: 1, side: 0, price: 100, qty: 10 });
|
|
402
|
+
(0, vitest_1.expect)(spot_instructions_1.buildNewSpotOrderInstruction).toHaveBeenCalled();
|
|
403
|
+
}));
|
|
404
|
+
});
|
|
405
|
+
(0, vitest_1.describe)('spotQuotesReplaceInstruction', () => {
|
|
406
|
+
(0, vitest_1.it)('calls buildSpotQuotesReplaceInstruction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
407
|
+
const { engine } = yield setupEngineWithClient();
|
|
408
|
+
yield engine.spotQuotesReplaceInstruction({
|
|
409
|
+
instrId: 1,
|
|
410
|
+
orders: [
|
|
411
|
+
{ newPrice: 99, newQty: 10, oldId: 1, side: 0 },
|
|
412
|
+
{ newPrice: 101, newQty: 10, oldId: 2, side: 1 },
|
|
413
|
+
],
|
|
414
|
+
});
|
|
415
|
+
(0, vitest_1.expect)(spot_instructions_1.buildSpotQuotesReplaceInstruction).toHaveBeenCalled();
|
|
416
|
+
}));
|
|
417
|
+
});
|
|
418
|
+
(0, vitest_1.describe)('spotOrderCancelInstruction', () => {
|
|
419
|
+
(0, vitest_1.it)('calls buildSpotOrderCancelInstruction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
420
|
+
const { engine } = yield setupEngineWithClient();
|
|
421
|
+
yield engine.spotOrderCancelInstruction({ instrId: 1, orderId: 12345, side: 0 });
|
|
422
|
+
(0, vitest_1.expect)(spot_instructions_1.buildSpotOrderCancelInstruction).toHaveBeenCalled();
|
|
423
|
+
}));
|
|
424
|
+
});
|
|
425
|
+
(0, vitest_1.describe)('spotMassCancelInstruction', () => {
|
|
426
|
+
(0, vitest_1.it)('calls buildSpotMassCancelInstruction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
427
|
+
const { engine } = yield setupEngineWithClient();
|
|
428
|
+
yield engine.spotMassCancelInstruction({ instrId: 1 });
|
|
429
|
+
(0, vitest_1.expect)(spot_instructions_1.buildSpotMassCancelInstruction).toHaveBeenCalled();
|
|
430
|
+
}));
|
|
431
|
+
});
|
|
432
|
+
(0, vitest_1.describe)('swapInstruction', () => {
|
|
433
|
+
(0, vitest_1.it)('calls buildSwapInstruction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
434
|
+
const { engine } = yield setupEngineWithClient();
|
|
435
|
+
yield engine.swapInstruction({
|
|
436
|
+
assetMint: 'AssetMint1111111111111111111111111111',
|
|
437
|
+
crncyMint: 'CrncyMint1111111111111111111111111111',
|
|
438
|
+
amount: 100,
|
|
439
|
+
limitPrice: 100,
|
|
440
|
+
crncyInput: true,
|
|
441
|
+
refFeeRate: 0,
|
|
442
|
+
minAmountOut: 0,
|
|
443
|
+
});
|
|
444
|
+
(0, vitest_1.expect)(spot_instructions_1.buildSwapInstruction).toHaveBeenCalled();
|
|
445
|
+
}));
|
|
446
|
+
(0, vitest_1.it)('should not call buildSwapInstruction because refFeeRate out of maximum', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
447
|
+
const { engine } = yield setupEngineWithClient();
|
|
448
|
+
yield (0, vitest_1.expect)(engine.swapInstruction({
|
|
449
|
+
assetMint: 'AssetMint1111111111111111111111111111',
|
|
450
|
+
crncyMint: 'CrncyMint1111111111111111111111111111',
|
|
451
|
+
amount: 100,
|
|
452
|
+
limitPrice: 100,
|
|
453
|
+
crncyInput: true,
|
|
454
|
+
refFeeRate: 0.0003,
|
|
455
|
+
minAmountOut: 0,
|
|
456
|
+
})).rejects.toThrow();
|
|
457
|
+
}));
|
|
458
|
+
(0, vitest_1.it)('should not call buildSwapInstruction because minAmountOut below 0', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
459
|
+
const { engine } = yield setupEngineWithClient();
|
|
460
|
+
yield (0, vitest_1.expect)(engine.swapInstruction({
|
|
461
|
+
assetMint: 'AssetMint1111111111111111111111111111',
|
|
462
|
+
crncyMint: 'CrncyMint1111111111111111111111111111',
|
|
463
|
+
amount: 100,
|
|
464
|
+
limitPrice: 100,
|
|
465
|
+
crncyInput: true,
|
|
466
|
+
refFeeRate: 0.0002,
|
|
467
|
+
minAmountOut: -0.005,
|
|
468
|
+
})).rejects.toThrow();
|
|
469
|
+
}));
|
|
470
|
+
});
|
|
471
|
+
// Perp instructions
|
|
472
|
+
(0, vitest_1.describe)('upgradeToPerpInstructions', () => {
|
|
473
|
+
(0, vitest_1.it)('throws when wallet not connected', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
474
|
+
const mockRpc = createMockRpc();
|
|
475
|
+
const engine = new index_1.Engine(mockRpc);
|
|
476
|
+
engine.instruments = createMockInstrumentsMap();
|
|
477
|
+
yield (0, vitest_1.expect)(engine.upgradeToPerpInstructions({ instrId: 1 })).rejects.toThrow('Wallet is not connected');
|
|
478
|
+
}));
|
|
479
|
+
(0, vitest_1.it)('calls buildUpgradeToPerpInstructions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
480
|
+
const { engine } = yield setupEngineWithClient();
|
|
481
|
+
yield engine.upgradeToPerpInstructions({ instrId: 1 });
|
|
482
|
+
(0, vitest_1.expect)(perp_instructions_1.buildUpgradeToPerpInstructions).toHaveBeenCalled();
|
|
483
|
+
}));
|
|
484
|
+
});
|
|
485
|
+
(0, vitest_1.describe)('perpDepositInstruction', () => {
|
|
486
|
+
(0, vitest_1.it)('throws when client account not found', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
487
|
+
const mockRpc = createMockRpc();
|
|
488
|
+
const engine = new index_1.Engine(mockRpc);
|
|
489
|
+
engine.tokens = createMockTokensMap();
|
|
490
|
+
engine.instruments = createMockInstrumentsMap();
|
|
491
|
+
// Set signer but no client account
|
|
492
|
+
engine.signer = 'MockSigner1111111111111111111111111111';
|
|
493
|
+
engine.clientPrimaryAccount = null;
|
|
494
|
+
yield (0, vitest_1.expect)(engine.perpDepositInstruction({ instrId: 1, amount: 100 })).rejects.toThrow('Client account not found');
|
|
495
|
+
}));
|
|
496
|
+
(0, vitest_1.it)('calls buildPerpDepositInstruction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
497
|
+
const { engine } = yield setupEngineWithClient();
|
|
498
|
+
yield engine.perpDepositInstruction({ instrId: 1, amount: 100 });
|
|
499
|
+
(0, vitest_1.expect)(perp_instructions_1.buildPerpDepositInstruction).toHaveBeenCalled();
|
|
500
|
+
}));
|
|
501
|
+
});
|
|
502
|
+
(0, vitest_1.describe)('perpBuySeatInstruction', () => {
|
|
503
|
+
(0, vitest_1.it)('calls buildPerpBuySeatInstruction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
504
|
+
const { engine } = yield setupEngineWithClient();
|
|
505
|
+
yield engine.perpBuySeatInstruction({ instrId: 1, amount: 50 });
|
|
506
|
+
(0, vitest_1.expect)(perp_instructions_1.buildPerpBuySeatInstruction).toHaveBeenCalled();
|
|
507
|
+
}));
|
|
508
|
+
});
|
|
509
|
+
(0, vitest_1.describe)('perpSellSeatInstruction', () => {
|
|
510
|
+
(0, vitest_1.it)('calls buildPerpSellSeatInstruction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
511
|
+
const { engine } = yield setupEngineWithClient();
|
|
512
|
+
yield engine.perpSellSeatInstruction({ instrId: 1 });
|
|
513
|
+
(0, vitest_1.expect)(perp_instructions_1.buildPerpSellSeatInstruction).toHaveBeenCalled();
|
|
514
|
+
}));
|
|
515
|
+
});
|
|
516
|
+
(0, vitest_1.describe)('newPerpOrderInstruction', () => {
|
|
517
|
+
(0, vitest_1.it)('calls buildNewPerpOrderInstruction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
518
|
+
const { engine } = yield setupEngineWithClient();
|
|
519
|
+
yield engine.newPerpOrderInstruction({ instrId: 1, side: 0, price: 100, qty: 10 });
|
|
520
|
+
(0, vitest_1.expect)(perp_instructions_1.buildNewPerpOrderInstruction).toHaveBeenCalled();
|
|
521
|
+
}));
|
|
522
|
+
});
|
|
523
|
+
(0, vitest_1.describe)('perpQuotesReplaceInstruction', () => {
|
|
524
|
+
(0, vitest_1.it)('calls buildPerpQuotesReplaceInstruction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
525
|
+
const { engine } = yield setupEngineWithClient();
|
|
526
|
+
yield engine.perpQuotesReplaceInstruction({
|
|
527
|
+
instrId: 1,
|
|
528
|
+
orders: [
|
|
529
|
+
{ newPrice: 99, newQty: 10, oldId: 1, side: 0 },
|
|
530
|
+
{ newPrice: 101, newQty: 10, oldId: 2, side: 1 },
|
|
531
|
+
],
|
|
532
|
+
});
|
|
533
|
+
(0, vitest_1.expect)(perp_instructions_1.buildPerpQuotesReplaceInstruction).toHaveBeenCalled();
|
|
534
|
+
}));
|
|
535
|
+
});
|
|
536
|
+
(0, vitest_1.describe)('perpOrderCancelInstruction', () => {
|
|
537
|
+
(0, vitest_1.it)('calls buildPerpOrderCancelInstruction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
538
|
+
const { engine } = yield setupEngineWithClient();
|
|
539
|
+
yield engine.perpOrderCancelInstruction({ instrId: 1, orderId: 12345, side: 0 });
|
|
540
|
+
(0, vitest_1.expect)(perp_instructions_1.buildPerpOrderCancelInstruction).toHaveBeenCalled();
|
|
541
|
+
}));
|
|
542
|
+
});
|
|
543
|
+
(0, vitest_1.describe)('perpMassCancelInstruction', () => {
|
|
544
|
+
(0, vitest_1.it)('calls buildPerpMassCancelInstruction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
545
|
+
const { engine } = yield setupEngineWithClient();
|
|
546
|
+
yield engine.perpMassCancelInstruction({ instrId: 1 });
|
|
547
|
+
(0, vitest_1.expect)(perp_instructions_1.buildPerpMassCancelInstruction).toHaveBeenCalled();
|
|
548
|
+
}));
|
|
549
|
+
});
|
|
550
|
+
(0, vitest_1.describe)('perpChangeLeverageInstruction', () => {
|
|
551
|
+
(0, vitest_1.it)('calls buildPerpChangeLeverageInstruction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
552
|
+
const { engine } = yield setupEngineWithClient();
|
|
553
|
+
yield engine.perpChangeLeverageInstruction({ instrId: 1, leverage: 5 });
|
|
554
|
+
(0, vitest_1.expect)(perp_instructions_1.buildPerpChangeLeverageInstruction).toHaveBeenCalled();
|
|
555
|
+
}));
|
|
556
|
+
});
|
|
557
|
+
(0, vitest_1.describe)('perpStatisticsResetInstruction', () => {
|
|
558
|
+
(0, vitest_1.it)('calls buildPerpStatisticsResetInstruction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
559
|
+
const { engine } = yield setupEngineWithClient();
|
|
560
|
+
yield engine.perpStatisticsResetInstruction({ instrId: 1 });
|
|
561
|
+
(0, vitest_1.expect)(perp_instructions_1.buildPerpStatisticsResetInstruction).toHaveBeenCalled();
|
|
562
|
+
}));
|
|
563
|
+
});
|
|
564
|
+
(0, vitest_1.describe)('newRefLinkInstruction', () => {
|
|
565
|
+
(0, vitest_1.it)('calls buildNewRefLinkInstruction', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
566
|
+
const { engine } = yield setupEngineWithClient();
|
|
567
|
+
yield engine.newRefLinkInstruction();
|
|
568
|
+
(0, vitest_1.expect)(perp_instructions_1.buildNewRefLinkInstruction).toHaveBeenCalled();
|
|
569
|
+
}));
|
|
570
|
+
});
|
|
571
|
+
(0, vitest_1.describe)('newInstrumentInstructions', () => {
|
|
572
|
+
(0, vitest_1.it)('throws when wallet not connected', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
573
|
+
const mockRpc = createMockRpc();
|
|
574
|
+
const engine = new index_1.Engine(mockRpc);
|
|
575
|
+
yield (0, vitest_1.expect)(engine.newInstrumentInstructions({
|
|
576
|
+
assetMint: 'AssetMint1111111111111111111111111111',
|
|
577
|
+
crncyMint: 'CrncyMint1111111111111111111111111111',
|
|
578
|
+
initialPrice: 100,
|
|
579
|
+
})).rejects.toThrow('Wallet is not connected');
|
|
580
|
+
}));
|
|
581
|
+
(0, vitest_1.it)('calls buildNewInstrumentInstructions', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
582
|
+
const { engine } = yield setupEngineWithClient();
|
|
583
|
+
yield engine.newInstrumentInstructions({
|
|
584
|
+
assetMint: 'AssetMint1111111111111111111111111111',
|
|
585
|
+
crncyMint: 'CrncyMint1111111111111111111111111111',
|
|
586
|
+
initialPrice: 100,
|
|
587
|
+
});
|
|
588
|
+
(0, vitest_1.expect)(perp_instructions_1.buildNewInstrumentInstructions).toHaveBeenCalled();
|
|
589
|
+
}));
|
|
590
|
+
});
|
|
591
|
+
(0, vitest_1.describe)('getClientData', () => {
|
|
592
|
+
(0, vitest_1.it)('throws when client not found', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
593
|
+
const mockRpc = createMockRpc();
|
|
594
|
+
const engine = new index_1.Engine(mockRpc);
|
|
595
|
+
engine.signer = 'MockSigner1111111111111111111111111111';
|
|
596
|
+
engine.clientPrimaryAccount = null;
|
|
597
|
+
yield (0, vitest_1.expect)(engine.getClientData()).rejects.toThrow('Client account not found');
|
|
598
|
+
}));
|
|
599
|
+
});
|
|
600
|
+
(0, vitest_1.describe)('getClientSpotOrdersInfo', () => {
|
|
601
|
+
(0, vitest_1.it)('throws for invalid instrument', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
602
|
+
const { engine } = yield setupEngineWithClient();
|
|
603
|
+
yield (0, vitest_1.expect)(engine.getClientSpotOrdersInfo({ instrId: 999, clientId: 1 })).rejects.toThrow('Invalid Instrument ID');
|
|
604
|
+
}));
|
|
605
|
+
});
|
|
606
|
+
(0, vitest_1.describe)('getClientPerpOrdersInfo', () => {
|
|
607
|
+
(0, vitest_1.it)('throws for invalid instrument', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
608
|
+
const { engine } = yield setupEngineWithClient();
|
|
609
|
+
yield (0, vitest_1.expect)(engine.getClientPerpOrdersInfo({ instrId: 999, clientId: 1 })).rejects.toThrow('Invalid Instrument ID');
|
|
610
|
+
}));
|
|
611
|
+
});
|
|
612
|
+
(0, vitest_1.describe)('getClientSpotOrders', () => {
|
|
613
|
+
(0, vitest_1.it)('throws when originalClientId is null', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
614
|
+
const { engine } = yield setupEngineWithClient();
|
|
615
|
+
engine.originalClientId = null;
|
|
616
|
+
yield (0, vitest_1.expect)(engine.getClientSpotOrders({ instrId: 1, bidsEntry: 0, bidsCount: 0, asksEntry: 0, asksCount: 0 })).rejects.toThrow('Original client ID not found');
|
|
617
|
+
}));
|
|
618
|
+
});
|
|
619
|
+
(0, vitest_1.describe)('getClientPerpOrders', () => {
|
|
620
|
+
(0, vitest_1.it)('throws when originalClientId is null', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
621
|
+
const { engine } = yield setupEngineWithClient();
|
|
622
|
+
engine.originalClientId = null;
|
|
623
|
+
yield (0, vitest_1.expect)(engine.getClientPerpOrders({ instrId: 1, bidsEntry: 0, bidsCount: 0, asksEntry: 0, asksCount: 0 })).rejects.toThrow('Original client ID not found');
|
|
624
|
+
}));
|
|
625
|
+
});
|
|
626
|
+
});
|
|
627
|
+
// ============================================
|
|
628
|
+
// DATA UPDATE METHOD TESTS
|
|
629
|
+
// ============================================
|
|
630
|
+
(0, vitest_1.describe)('Engine data update methods', () => {
|
|
631
|
+
(0, vitest_1.beforeEach)(() => {
|
|
632
|
+
vitest_1.vi.clearAllMocks();
|
|
633
|
+
});
|
|
634
|
+
(0, vitest_1.describe)('addToken', () => {
|
|
635
|
+
(0, vitest_1.it)('throws when getAccountInfo returns null', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
636
|
+
const mockRpc = createMockRpc();
|
|
637
|
+
mockRpc.getAccountInfo = vitest_1.vi.fn().mockReturnValue({
|
|
638
|
+
send: vitest_1.vi.fn().mockResolvedValue({ value: null }),
|
|
639
|
+
});
|
|
640
|
+
const engine = new index_1.Engine(mockRpc);
|
|
641
|
+
engine.rootStateModel = { tokensCount: 10 };
|
|
642
|
+
yield (0, vitest_1.expect)(engine.addToken('TokenAccount111111111111111111111')).rejects.toThrow('Add Token Failed: getAccountInfo');
|
|
643
|
+
}));
|
|
644
|
+
});
|
|
645
|
+
(0, vitest_1.describe)('addInstr', () => {
|
|
646
|
+
(0, vitest_1.it)('throws when getAccountInfo returns null', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
647
|
+
const mockRpc = createMockRpc();
|
|
648
|
+
mockRpc.getAccountInfo = vitest_1.vi.fn().mockReturnValue({
|
|
649
|
+
send: vitest_1.vi.fn().mockResolvedValue({ value: null }),
|
|
650
|
+
});
|
|
651
|
+
const engine = new index_1.Engine(mockRpc);
|
|
652
|
+
engine.rootStateModel = { instrCount: 10 };
|
|
653
|
+
yield (0, vitest_1.expect)(engine.addInstr('InstrAccount111111111111111111111')).rejects.toThrow('Add Instrument Failed: getAccountInfo');
|
|
654
|
+
}));
|
|
655
|
+
});
|
|
656
|
+
(0, vitest_1.describe)('updateCommunity', () => {
|
|
657
|
+
(0, vitest_1.it)('throws when getAccountInfo returns null', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
658
|
+
const mockRpc = createMockRpc();
|
|
659
|
+
mockRpc.getAccountInfo = vitest_1.vi.fn().mockReturnValue({
|
|
660
|
+
send: vitest_1.vi.fn().mockResolvedValue({ value: null }),
|
|
661
|
+
});
|
|
662
|
+
const engine = new index_1.Engine(mockRpc);
|
|
663
|
+
engine.communityAccount = 'CommunityAccount1111111111111111111';
|
|
664
|
+
yield (0, vitest_1.expect)(engine.updateCommunity()).rejects.toThrow('Community Account: GetAccountInfo Failed');
|
|
665
|
+
}));
|
|
666
|
+
});
|
|
667
|
+
(0, vitest_1.describe)('updateRoot', () => {
|
|
668
|
+
(0, vitest_1.it)('throws when getAccountInfo returns null', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
669
|
+
const mockRpc = createMockRpc();
|
|
670
|
+
mockRpc.getAccountInfo = vitest_1.vi.fn().mockReturnValue({
|
|
671
|
+
send: vitest_1.vi.fn().mockResolvedValue({ value: null }),
|
|
672
|
+
});
|
|
673
|
+
const engine = new index_1.Engine(mockRpc);
|
|
674
|
+
engine.rootAccount = 'RootAccount11111111111111111111111';
|
|
675
|
+
yield (0, vitest_1.expect)(engine.updateRoot()).rejects.toThrow('Root Account: GetAccountInfo Failed');
|
|
676
|
+
}));
|
|
677
|
+
});
|
|
678
|
+
(0, vitest_1.describe)('updateInstrData', () => {
|
|
679
|
+
(0, vitest_1.it)('throws when instrument not found', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
680
|
+
const { engine } = yield setupEngineWithClient();
|
|
681
|
+
vitest_1.vi.mocked(engine.updateInstrData).mockRestore();
|
|
682
|
+
yield (0, vitest_1.expect)(engine.updateInstrData({ instrId: 999 })).rejects.toThrow('Instrument not found');
|
|
683
|
+
}));
|
|
684
|
+
});
|
|
685
|
+
});
|