Skip to content

Commit 43bba1b

Browse files
authored
Add trading test case examples (#3604)
* add trading test case examples * fmt * fmt ts * fix mock api logic * fix base path * fmt * rm unused logs * Update the mock API response * Update the amounts and chain ID in the JSON-RPC simulation tests * skip submitSwapOrder tests * fix merge issues * rm basepath for verify_google_code * fmt * revert mockserver
1 parent 4583c39 commit 43bba1b

File tree

5 files changed

+261
-1
lines changed

5 files changed

+261
-1
lines changed

tee-worker/omni-executor/ts-tests/jsonrpc-mock-tests/jsonrpc.test.ts

Lines changed: 139 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import {
1414
encrypt,
1515
decryptWithAes,
1616
AddWalletResponse,
17+
TransferWithdrawResponse,
18+
SubmitSwapOrderResponse,
19+
SignLimitOrderResponse,
20+
NotifyLimitOrderResultResponse,
1721
} from './utils';
1822
import { signMessage } from 'viem/accounts';
1923
import { u8aToHex } from '@polkadot/util';
@@ -210,6 +214,140 @@ describe('Omni JsonRpc Mock Tests', function () {
210214
const mockAesKey = '0x3aefe1ec780dc389ed4e048eacaf25679a7f2e567d11f65071b51029dd63e79d';
211215

212216
const decryptedKey = await decryptWithAes(mockAesKey, mockResult as unknown as AesOutput, 'hex');
213-
console.log('decryptedKey', decryptedKey);
217+
expect(decryptedKey).not.to.be.undefined;
218+
});
219+
220+
it.skip('should transfer withdraw successfully', async function () {
221+
const transferParams = {
222+
request_id: 1,
223+
chain_id: 1,
224+
wallet_index: 0,
225+
recipient_address: '0x742d35Cc6634C0532925a3b8D4bd4A0F8b3f3c0',
226+
token_ca: '0xA0b86a33E6441b3F1c1e3f8B0c6c8b8d7e6f3e4a',
227+
amount: '1000000000000000000',
228+
google_code: '123456',
229+
lang: 'en',
230+
};
231+
const result: TransferWithdrawResponse = await omniApi.transferWithdraw(transferParams, id_token);
232+
233+
// expected result:
234+
// {
235+
// "backend_response": {
236+
// "code": 10000,
237+
// "message": "OK",
238+
// "data": {
239+
// "tx_hash": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
240+
// "transfer_id": "transfer_12345",
241+
// "chain_id": 1
242+
// }
243+
// }
244+
// }
245+
246+
expect(result.backend_response).to.be.not.undefined;
247+
expect(result.backend_response.code).to.be.equal(10000);
248+
expect(result.backend_response.message).to.be.equal('OK');
249+
});
250+
251+
it.skip('should submit swap order successfully (market order)', async function () {
252+
const swapOrderParams = {
253+
intent_id: 1,
254+
order_type: 'market' as const,
255+
swap_type: 1 as const,
256+
from_chain_id: 1,
257+
from_token_ca: '0xA0b86a33E6441b3F1c1e3f8B0c6c8b8d7e6f3e4a',
258+
from_amount: '0.001',
259+
to_chain_id: 56,
260+
to_token_ca: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
261+
double_out: false,
262+
is_one_click: true,
263+
usd_worth: '0.001',
264+
wallet_index: 0,
265+
};
266+
267+
const result: SubmitSwapOrderResponse = await omniApi.submitSwapOrder(swapOrderParams, id_token);
268+
269+
// expected result:
270+
// {
271+
// "backend_response": {
272+
// "market_order_response": {
273+
// "code": 10000,
274+
// "message": "OK",
275+
// "data": {
276+
// "tx_hash": ["0x1234567890abcdef..."]
277+
// }
278+
// }
279+
// }
280+
// }
281+
});
282+
283+
it.skip('should submit swap order successfully (limit order)', async function () {
284+
const swapOrderParams = {
285+
intent_id: 2,
286+
order_type: 'limit' as const,
287+
swap_type: 2 as const,
288+
from_chain_id: 1,
289+
from_token_ca: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
290+
from_amount: '0.001',
291+
to_chain_id: 1, // must same as from_chain_id
292+
to_token_ca: '0xA0b86a33E6441b3F1c1e3f8B0c6c8b8d7e6f3e4a',
293+
double_out: false,
294+
is_one_click: false,
295+
price_usd: '0.1',
296+
usd_worth: '0.001',
297+
wallet_index: 0,
298+
};
299+
300+
const result: SubmitSwapOrderResponse = await omniApi.submitSwapOrder(swapOrderParams, id_token);
301+
302+
// expected result:
303+
// {
304+
// "backend_response": {
305+
// "limit_order_response": {
306+
// "code": 10000,
307+
// "message": "OK",
308+
// "data": {
309+
// "order_id": 123456
310+
// }
311+
// }
312+
// }
313+
// }
314+
});
315+
316+
it.skip('should sign limit order successfully', async function () {
317+
const signLimitOrderParams = {
318+
intent_id: 1,
319+
order_id: 1,
320+
chain_id: 1,
321+
wallet_index: 0,
322+
unsigned_tx: ['0x570A5D26f7765Ecb712C0924E4De545B89fD43dF'],
323+
};
324+
325+
const result: SignLimitOrderResponse = await omniApi.signLimitOrder(signLimitOrderParams, id_token);
326+
327+
// expected result:
328+
// {
329+
// "intent_id": 1,
330+
// "order_id": 123456,
331+
// "chain_id": 1,
332+
// "signed_tx": ["0x1234567890abcdef...", "0xabcdef1234567890..."]
333+
// }
334+
335+
expect(result.intent_id).to.be.equal(1);
336+
expect(result.order_id).to.be.equal(1);
337+
expect(result.chain_id).to.be.equal(1);
338+
expect(result.signed_tx).to.be.an('array');
339+
expect(result.signed_tx.length).to.be.greaterThan(0);
340+
});
341+
342+
it.skip('should notify limit order result successfully', async function () {
343+
const notifyParams = {
344+
intent_id: 1,
345+
result: 'success',
346+
message: 'Order executed successfully',
347+
};
348+
349+
const result: NotifyLimitOrderResultResponse = await omniApi.notifyLimitOrderResult(notifyParams, id_token);
350+
351+
// expected result: null
214352
});
215353
});

tee-worker/omni-executor/ts-tests/jsonrpc-mock-tests/utils/methods.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ enum JsonRpcMethods {
66
OmniGetNextIntentId = 'omni_getNextIntentId',
77
OmniAddWallet = 'omni_addWallet',
88
OmniExportWallet = 'omni_exportWallet',
9+
OmniTransferWithdraw = 'omni_transferWithdraw',
10+
OmniSubmitSwapOrder = 'omni_submitSwapOrder',
11+
OmniSignLimitOrder = 'omni_signLimitOrder',
12+
OmniNotifyLimitOrderResult = 'omni_notifyLimitOrderResult',
913
}
1014

1115
export { JsonRpcMethods };

tee-worker/omni-executor/ts-tests/jsonrpc-mock-tests/utils/omni-api.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import {
66
GetWeb3SignInMessageParams,
77
GetNextIntentIdParams,
88
ExportWalletParams,
9+
TransferWithdrawParams,
10+
SubmitSwapOrderParams,
11+
SignLimitOrderParams,
12+
NotifyLimitOrderResultParams,
913
} from './request-types';
1014
import {
1115
RequestEmailVerificationCodeResponse,
@@ -15,6 +19,10 @@ import {
1519
GetNextIntentIdResponse,
1620
ExportWalletResponse,
1721
AddWalletResponse,
22+
TransferWithdrawResponse,
23+
SubmitSwapOrderResponse,
24+
SignLimitOrderResponse,
25+
NotifyLimitOrderResultResponse,
1826
} from './response-types';
1927

2028
export class OmniApi {
@@ -75,6 +83,33 @@ export class OmniApi {
7583

7684
return response;
7785
}
86+
87+
async transferWithdraw(params: TransferWithdrawParams, token: string): Promise<TransferWithdrawResponse> {
88+
const response = await this.client.call(JsonRpcMethods.OmniTransferWithdraw, params, token);
89+
90+
return response;
91+
}
92+
93+
async submitSwapOrder(params: SubmitSwapOrderParams, token: string): Promise<SubmitSwapOrderResponse> {
94+
const response = await this.client.call(JsonRpcMethods.OmniSubmitSwapOrder, params, token);
95+
96+
return response;
97+
}
98+
99+
async signLimitOrder(params: SignLimitOrderParams, token: string): Promise<SignLimitOrderResponse> {
100+
const response = await this.client.call(JsonRpcMethods.OmniSignLimitOrder, params, token);
101+
102+
return response;
103+
}
104+
105+
async notifyLimitOrderResult(
106+
params: NotifyLimitOrderResultParams,
107+
token: string
108+
): Promise<NotifyLimitOrderResultResponse> {
109+
const response = await this.client.call(JsonRpcMethods.OmniNotifyLimitOrderResult, params, token);
110+
111+
return response;
112+
}
78113
}
79114

80115
export const omniApi = OmniApi.getInstance();

tee-worker/omni-executor/ts-tests/jsonrpc-mock-tests/utils/request-types.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,46 @@ export interface ExportWalletParams {
3838
wallet_index: number;
3939
wallet_address: string;
4040
}
41+
42+
export interface TransferWithdrawParams {
43+
request_id?: number;
44+
chain_id: number;
45+
wallet_index: number;
46+
recipient_address: string;
47+
token_ca: string;
48+
amount: string;
49+
google_code: string;
50+
lang?: string;
51+
}
52+
53+
export interface SubmitSwapOrderParams {
54+
intent_id: number;
55+
order_type: 'market' | 'limit';
56+
swap_type: 1 | 2;
57+
from_chain_id: number;
58+
from_token_ca?: string;
59+
from_amount: string;
60+
to_chain_id: number;
61+
to_token_ca?: string;
62+
double_out: boolean;
63+
is_one_click: boolean;
64+
token_cap?: string;
65+
price_usd?: string;
66+
usd_worth: string;
67+
trailing_percent?: number;
68+
wallet_index: number;
69+
}
70+
71+
export interface SignLimitOrderParams {
72+
intent_id: number;
73+
order_id: number;
74+
chain_id: number;
75+
wallet_index: number;
76+
unsigned_tx: string[];
77+
}
78+
79+
export interface NotifyLimitOrderResultParams {
80+
intent_id: number;
81+
result: string;
82+
message?: string;
83+
}

tee-worker/omni-executor/ts-tests/jsonrpc-mock-tests/utils/response-types.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,44 @@ export interface ExportWalletResponse {
4343
aad: string;
4444
nonce: string;
4545
}
46+
47+
export interface TransferWithdrawResponse {
48+
backend_response: {
49+
code: number;
50+
message: string;
51+
data: {
52+
tx_hash: string;
53+
transfer_id: string;
54+
chain_id: number;
55+
};
56+
};
57+
}
58+
59+
export interface SubmitSwapOrderResponse {
60+
backend_response: {
61+
limit_order_response?: {
62+
code: number;
63+
message: string;
64+
data: {
65+
order_id?: number;
66+
};
67+
};
68+
market_order_response?: {
69+
code: number;
70+
message: string;
71+
data: {
72+
tx_hash?: string[];
73+
};
74+
};
75+
};
76+
}
77+
78+
export interface SignLimitOrderResponse {
79+
intent_id: number;
80+
order_id: number;
81+
chain_id: number;
82+
signed_tx: string[];
83+
}
84+
85+
export type NotifyLimitOrderResultResponse = null;
4686
// todo: add other types

0 commit comments

Comments
 (0)