1
use crate::{
2
    admin::set_route,
3
    contract::instantiate,
4
    helpers::Scaled,
5
    msg::{FeeRecipient, InstantiateMsg},
6
    queries::{estimate_swap_result, SwapQuantity},
7
    state::get_all_swap_routes,
8
    testing::test_utils::{
9
        are_fpdecimals_approximately_equal, human_to_dec, mock_deps_eth_inj, mock_realistic_deps_eth_atom, Decimals, MultiplierQueryBehavior,
10
        TEST_USER_ADDR,
11
    },
12
    types::{FPCoin, SwapRoute},
13
};
14
use cosmwasm_std::{
15
    coin,
16
    testing::{message_info, mock_env},
17
    Addr,
18
};
19
use injective_cosmwasm::{OwnedDepsExt, TEST_MARKET_ID_1, TEST_MARKET_ID_2};
20
use injective_math::FPDecimal;
21

            
22
use std::ops::Neg;
23
use std::str::FromStr;
24

            
25
/*
26
    Tests focusing on queries with all values were taken from this spreadsheet:
27
`   https://docs.google.com/spreadsheets/d/1-0epjX580nDO_P2mm1tSjhvjJVppsvrO1BC4_wsBeyA/edit?usp=sharing
28
*/
29

            
30
#[test]
31
2
fn test_calculate_swap_price_external_fee_recipient_from_source_quantity() {
32
2
    let mut deps = mock_deps_eth_inj(MultiplierQueryBehavior::Success);
33
2
    let admin = &Addr::unchecked(TEST_USER_ADDR);
34
2

            
35
2
    instantiate(
36
2
        deps.as_mut_deps(),
37
2
        mock_env(),
38
2
        message_info(&Addr::unchecked(admin), &[coin(1_000u128, "usdt")]),
39
2
        InstantiateMsg {
40
2
            fee_recipient: FeeRecipient::Address(admin.to_owned()),
41
2
            admin: admin.to_owned(),
42
2
        },
43
2
    )
44
2
    .unwrap();
45
2
    set_route(
46
2
        deps.as_mut_deps(),
47
2
        &Addr::unchecked(TEST_USER_ADDR),
48
2
        "eth".to_string(),
49
2
        "inj".to_string(),
50
2
        vec![TEST_MARKET_ID_1.into(), TEST_MARKET_ID_2.into()],
51
2
    )
52
2
    .unwrap();
53
2

            
54
2
    let actual_swap_result = estimate_swap_result(
55
2
        deps.as_ref(),
56
2
        &mock_env(),
57
2
        "eth".to_string(),
58
2
        "inj".to_string(),
59
2
        SwapQuantity::InputQuantity(FPDecimal::from_str("12").unwrap()),
60
2
    )
61
2
    .unwrap();
62
2

            
63
2
    // in spreadsheet we expect 2888.224, but contract rounds average price up to be sure it doesn't deplete buffer
64
2
    assert_eq!(
65
2
        actual_swap_result.result_quantity,
66
2
        FPDecimal::must_from_str("2888.221"),
67
        "Wrong amount of swap execution estimate received when using source quantity"
68
    );
69

            
70
2
    assert_eq!(
71
2
        actual_swap_result.expected_fees.len(),
72
        2,
73
        "Wrong number of fee entries received when using source quantity"
74
    );
75

            
76
    // values from the spreadsheet
77
2
    let expected_fee_1 = FPCoin {
78
2
        amount: FPDecimal::must_from_str("5902.5"),
79
2
        denom: "usdt".to_string(),
80
2
    };
81
2

            
82
2
    // values from the spreadsheet
83
2
    let expected_fee_2 = FPCoin {
84
2
        amount: FPDecimal::must_from_str("5873.061097"),
85
2
        denom: "usdt".to_string(),
86
2
    };
87
2

            
88
2
    let max_diff = human_to_dec("0.00001", Decimals::Six);
89
2

            
90
2
    assert!(
91
2
        are_fpdecimals_approximately_equal(expected_fee_1.amount, actual_swap_result.expected_fees[0].amount, max_diff,),
92
        "Wrong amount of first trx fee received when using source quantity. Expected: {}, Actual: {}",
93
        expected_fee_1.amount,
94
        actual_swap_result.expected_fees[0].amount
95
    );
96

            
97
2
    assert!(
98
2
        are_fpdecimals_approximately_equal(expected_fee_2.amount, actual_swap_result.expected_fees[1].amount, max_diff,),
99
        "Wrong amount of second trx fee received when using source quantity. Expected: {}, Actual: {}",
100
        expected_fee_2.amount,
101
        actual_swap_result.expected_fees[1].amount
102
    );
103
2
}
104

            
105
#[test]
106
2
fn test_calculate_swap_price_external_fee_recipient_from_target_quantity() {
107
2
    let mut deps = mock_deps_eth_inj(MultiplierQueryBehavior::Success);
108
2
    let admin = &Addr::unchecked(TEST_USER_ADDR);
109
2

            
110
2
    instantiate(
111
2
        deps.as_mut_deps(),
112
2
        mock_env(),
113
2
        message_info(&Addr::unchecked(admin), &[coin(1_000u128, "usdt")]),
114
2
        InstantiateMsg {
115
2
            fee_recipient: FeeRecipient::Address(admin.to_owned()),
116
2
            admin: admin.to_owned(),
117
2
        },
118
2
    )
119
2
    .unwrap();
120
2
    set_route(
121
2
        deps.as_mut_deps(),
122
2
        &Addr::unchecked(TEST_USER_ADDR),
123
2
        "eth".to_string(),
124
2
        "inj".to_string(),
125
2
        vec![TEST_MARKET_ID_1.into(), TEST_MARKET_ID_2.into()],
126
2
    )
127
2
    .unwrap();
128
2

            
129
2
    let actual_swap_result = estimate_swap_result(
130
2
        deps.as_ref(),
131
2
        &mock_env(),
132
2
        "eth".to_string(),
133
2
        "inj".to_string(),
134
2
        SwapQuantity::OutputQuantity(FPDecimal::from_str("2888.221").unwrap()),
135
2
    )
136
2
    .unwrap();
137
2

            
138
2
    assert_eq!(
139
2
        actual_swap_result.result_quantity,
140
2
        FPDecimal::must_from_str("12"),
141
        "Wrong amount of swap execution estimate received when using target quantity"
142
    ); // value rounded to min tick
143

            
144
2
    assert_eq!(
145
2
        actual_swap_result.expected_fees.len(),
146
        2,
147
        "Wrong number of fee entries received when using target quantity"
148
    );
149

            
150
    // values from the spreadsheet
151
2
    let expected_fee_1 = FPCoin {
152
2
        amount: FPDecimal::must_from_str("5873.061097"),
153
2
        denom: "usdt".to_string(),
154
2
    };
155
2

            
156
2
    // values from the spreadsheet
157
2
    let expected_fee_2 = FPCoin {
158
2
        amount: FPDecimal::must_from_str("5902.5"),
159
2
        denom: "usdt".to_string(),
160
2
    };
161
2

            
162
2
    let max_diff = human_to_dec("0.00001", Decimals::Six);
163
2

            
164
2
    assert!(
165
2
        are_fpdecimals_approximately_equal(expected_fee_1.amount, actual_swap_result.expected_fees[0].amount, max_diff,),
166
        "Wrong amount of first trx fee received when using source quantity. Expected: {}, Actual: {}",
167
        expected_fee_1.amount,
168
        actual_swap_result.expected_fees[0].amount
169
    );
170

            
171
2
    assert!(
172
2
        are_fpdecimals_approximately_equal(expected_fee_2.amount, actual_swap_result.expected_fees[1].amount, max_diff,),
173
        "Wrong amount of second trx fee received when using source quantity. Expected: {}, Actual: {}",
174
        expected_fee_2.amount,
175
        actual_swap_result.expected_fees[1].amount
176
    );
177
2
}
178

            
179
#[test]
180
2
fn test_calculate_swap_price_self_fee_recipient_from_source_quantity() {
181
2
    let mut deps = mock_deps_eth_inj(MultiplierQueryBehavior::Success);
182
2
    let admin = &Addr::unchecked(TEST_USER_ADDR);
183
2

            
184
2
    instantiate(
185
2
        deps.as_mut_deps(),
186
2
        mock_env(),
187
2
        message_info(&Addr::unchecked(admin), &[coin(1_000u128, "usdt")]),
188
2
        InstantiateMsg {
189
2
            fee_recipient: FeeRecipient::SwapContract,
190
2
            admin: admin.to_owned(),
191
2
        },
192
2
    )
193
2
    .unwrap();
194
2

            
195
2
    set_route(
196
2
        deps.as_mut_deps(),
197
2
        &Addr::unchecked(TEST_USER_ADDR),
198
2
        "eth".to_string(),
199
2
        "inj".to_string(),
200
2
        vec![TEST_MARKET_ID_1.into(), TEST_MARKET_ID_2.into()],
201
2
    )
202
2
    .unwrap();
203
2

            
204
2
    let actual_swap_result = estimate_swap_result(
205
2
        deps.as_ref(),
206
2
        &mock_env(),
207
2
        "eth".to_string(),
208
2
        "inj".to_string(),
209
2
        SwapQuantity::InputQuantity(FPDecimal::from_str("12").unwrap()),
210
2
    )
211
2
    .unwrap();
212
2

            
213
2
    assert_eq!(
214
2
        actual_swap_result.result_quantity,
215
2
        FPDecimal::must_from_str("2893.886"),
216
        "Wrong amount of swap execution estimate received"
217
    ); // value rounded to min tick
218

            
219
2
    assert_eq!(actual_swap_result.expected_fees.len(), 2, "Wrong number of fee entries received");
220

            
221
    // values from the spreadsheet
222
2
    let expected_fee_1 = FPCoin {
223
2
        amount: FPDecimal::must_from_str("3541.5"),
224
2
        denom: "usdt".to_string(),
225
2
    };
226
2

            
227
2
    // values from the spreadsheet
228
2
    let expected_fee_2 = FPCoin {
229
2
        amount: FPDecimal::must_from_str("3530.891412"),
230
2
        denom: "usdt".to_string(),
231
2
    };
232
2

            
233
2
    let max_diff = human_to_dec("0.00001", Decimals::Six);
234
2

            
235
2
    assert!(
236
2
        are_fpdecimals_approximately_equal(expected_fee_1.amount, actual_swap_result.expected_fees[0].amount, max_diff,),
237
        "Wrong amount of first trx fee received when using source quantity. Expected: {}, Actual: {}",
238
        expected_fee_1.amount,
239
        actual_swap_result.expected_fees[0].amount
240
    );
241

            
242
2
    assert!(
243
2
        are_fpdecimals_approximately_equal(expected_fee_2.amount, actual_swap_result.expected_fees[1].amount, max_diff,),
244
        "Wrong amount of second trx fee received when using source quantity. Expected: {}, Actual: {}",
245
        expected_fee_2.amount,
246
        actual_swap_result.expected_fees[1].amount
247
    );
248
2
}
249

            
250
#[test]
251
2
fn test_calculate_swap_price_self_fee_recipient_from_target_quantity() {
252
2
    let mut deps = mock_deps_eth_inj(MultiplierQueryBehavior::Success);
253
2
    let admin = &Addr::unchecked(TEST_USER_ADDR);
254
2

            
255
2
    instantiate(
256
2
        deps.as_mut_deps(),
257
2
        mock_env(),
258
2
        message_info(&Addr::unchecked(admin), &[coin(1_000u128, "usdt")]),
259
2
        InstantiateMsg {
260
2
            fee_recipient: FeeRecipient::SwapContract,
261
2
            admin: admin.to_owned(),
262
2
        },
263
2
    )
264
2
    .unwrap();
265
2

            
266
2
    set_route(
267
2
        deps.as_mut_deps(),
268
2
        &Addr::unchecked(TEST_USER_ADDR),
269
2
        "eth".to_string(),
270
2
        "inj".to_string(),
271
2
        vec![TEST_MARKET_ID_1.into(), TEST_MARKET_ID_2.into()],
272
2
    )
273
2
    .unwrap();
274
2

            
275
2
    let actual_swap_result = estimate_swap_result(
276
2
        deps.as_ref(),
277
2
        &mock_env(),
278
2
        "eth".to_string(),
279
2
        "inj".to_string(),
280
2
        SwapQuantity::OutputQuantity(FPDecimal::from_str("2893.886").unwrap()),
281
2
    )
282
2
    .unwrap();
283
2

            
284
2
    assert_eq!(
285
2
        actual_swap_result.result_quantity,
286
2
        FPDecimal::must_from_str("12"),
287
        "Wrong amount of swap execution estimate received when using target quantity"
288
    ); // value rounded to min tick
289

            
290
2
    assert_eq!(
291
2
        actual_swap_result.expected_fees.len(),
292
        2,
293
        "Wrong number of fee entries received when using target quantity"
294
    );
295

            
296
    // values from the spreadsheet
297
2
    let expected_fee_1 = FPCoin {
298
2
        amount: FPDecimal::must_from_str("3530.891412"),
299
2
        denom: "usdt".to_string(),
300
2
    };
301
2

            
302
2
    // values from the spreadsheet
303
2
    let expected_fee_2 = FPCoin {
304
2
        amount: FPDecimal::must_from_str("3541.5"),
305
2
        denom: "usdt".to_string(),
306
2
    };
307
2

            
308
2
    let max_diff = human_to_dec("0.00001", Decimals::Six);
309
2

            
310
2
    assert!(
311
2
        are_fpdecimals_approximately_equal(expected_fee_1.amount, actual_swap_result.expected_fees[0].amount, max_diff,),
312
        "Wrong amount of first trx fee received when using source quantity. Expected: {}, Actual: {}",
313
        expected_fee_1.amount,
314
        actual_swap_result.expected_fees[0].amount
315
    );
316

            
317
2
    assert!(
318
2
        are_fpdecimals_approximately_equal(expected_fee_2.amount, actual_swap_result.expected_fees[1].amount, max_diff,),
319
        "Wrong amount of second trx fee received when using source quantity. Expected: {}, Actual: {}",
320
        expected_fee_2.amount,
321
        actual_swap_result.expected_fees[1].amount
322
    );
323
2
}
324

            
325
// these values were not taken from spreadsheet, we just assume that both direction of estimate
326
// should be almost symmetrical (almost due to complex sequence of roundings)
327
#[test]
328
2
fn test_calculate_estimate_when_selling_both_quantity_directions_simple() {
329
2
    let mut deps = mock_realistic_deps_eth_atom(MultiplierQueryBehavior::Success);
330
2
    let admin = &Addr::unchecked(TEST_USER_ADDR);
331
2

            
332
2
    instantiate(
333
2
        deps.as_mut_deps(),
334
2
        mock_env(),
335
2
        message_info(&Addr::unchecked(admin), &[coin(1_000u128, "usdt")]),
336
2
        InstantiateMsg {
337
2
            fee_recipient: FeeRecipient::Address(admin.to_owned()),
338
2
            admin: admin.to_owned(),
339
2
        },
340
2
    )
341
2
    .unwrap();
342
2
    set_route(
343
2
        deps.as_mut_deps(),
344
2
        &Addr::unchecked(TEST_USER_ADDR),
345
2
        "eth".to_string(),
346
2
        "usdt".to_string(),
347
2
        vec![TEST_MARKET_ID_1.into()],
348
2
    )
349
2
    .unwrap();
350
2

            
351
2
    let eth_input_amount = human_to_dec("4.08", Decimals::Eighteen);
352
2

            
353
2
    let input_swap_estimate = estimate_swap_result(
354
2
        deps.as_ref(),
355
2
        &mock_env(),
356
2
        "eth".to_string(),
357
2
        "usdt".to_string(),
358
2
        SwapQuantity::InputQuantity(eth_input_amount),
359
2
    )
360
2
    .unwrap();
361
2

            
362
2
    let expected_usdt_result_quantity = human_to_dec("8127.7324632", Decimals::Six);
363
2

            
364
2
    assert_eq!(
365
        input_swap_estimate.result_quantity, expected_usdt_result_quantity,
366
        "Wrong amount of swap execution estimate received when using source quantity"
367
    );
368

            
369
2
    assert_eq!(
370
2
        input_swap_estimate.expected_fees.len(),
371
        1,
372
        "Wrong number of fee entries received when using source quantity"
373
    );
374

            
375
2
    let expected_usdt_fee_amount = human_to_dec("20.3688555", Decimals::Six);
376
2

            
377
2
    let expected_fee = FPCoin {
378
2
        amount: expected_usdt_fee_amount,
379
2
        denom: "usdt".to_string(),
380
2
    };
381
2

            
382
2
    let max_diff = human_to_dec("0.1", Decimals::Eighteen);
383
2

            
384
2
    assert!(
385
2
        are_fpdecimals_approximately_equal(expected_fee.amount, input_swap_estimate.expected_fees[0].amount, max_diff,),
386
        "Wrong amount of trx fee received when using source quantity. Expected: {}, Actual: {}",
387
        expected_fee.amount,
388
        input_swap_estimate.expected_fees[0].amount
389
    );
390

            
391
2
    let output_swap_estimate = estimate_swap_result(
392
2
        deps.as_ref(),
393
2
        &mock_env(),
394
2
        "eth".to_string(),
395
2
        "usdt".to_string(),
396
2
        SwapQuantity::OutputQuantity(expected_usdt_result_quantity),
397
2
    )
398
2
    .unwrap();
399
2

            
400
2
    assert!(
401
2
        output_swap_estimate.result_quantity >= eth_input_amount,
402
        "Swap execution estimate when using target quantity wasn't higher than when using source quantity. Target amount: {} ETH, source amount: {} ETH",
403
        output_swap_estimate.result_quantity.scaled(Decimals::Eighteen.get_decimals().neg()),
404
        eth_input_amount.scaled(Decimals::Eighteen.get_decimals().neg())
405
    );
406

            
407
2
    assert!(
408
2
        are_fpdecimals_approximately_equal(output_swap_estimate.result_quantity, eth_input_amount, max_diff),
409
        "Wrong amount of swap execution estimate received when using target quantity"
410
    );
411

            
412
2
    assert_eq!(
413
2
        output_swap_estimate.expected_fees.len(),
414
        1,
415
        "Wrong number of fee entries received when using target quantity"
416
    );
417

            
418
2
    let max_diff = human_to_dec("0.1", Decimals::Six);
419
2

            
420
2
    assert!(
421
2
        are_fpdecimals_approximately_equal(expected_fee.amount, input_swap_estimate.expected_fees[0].amount, max_diff,),
422
        "Wrong amount of trx fee received when using source quantity. Expected: {}, Actual: {}",
423
        expected_fee.amount,
424
        input_swap_estimate.expected_fees[0].amount
425
    );
426
2
}
427

            
428
// these values were not taken from spreadsheet, we just assume that both direction of estimate
429
// should be almost symmetrical (almost due to complex sequence of roundings); for some reason
430
// target estimate is slightly higher than source estimate (that should not be the case)
431
#[test]
432
2
fn test_calculate_estimate_when_buying_both_quantity_directions_simple() {
433
2
    let mut deps = mock_realistic_deps_eth_atom(MultiplierQueryBehavior::Success);
434
2
    let admin = &Addr::unchecked(TEST_USER_ADDR);
435
2

            
436
2
    instantiate(
437
2
        deps.as_mut_deps(),
438
2
        mock_env(),
439
2
        message_info(&Addr::unchecked(admin), &[coin(1_000u128, "usdt")]),
440
2
        InstantiateMsg {
441
2
            fee_recipient: FeeRecipient::Address(admin.to_owned()),
442
2
            admin: admin.to_owned(),
443
2
        },
444
2
    )
445
2
    .unwrap();
446
2
    set_route(
447
2
        deps.as_mut_deps(),
448
2
        &Addr::unchecked(TEST_USER_ADDR),
449
2
        "eth".to_string(),
450
2
        "usdt".to_string(),
451
2
        vec![TEST_MARKET_ID_1.into()],
452
2
    )
453
2
    .unwrap();
454
2

            
455
2
    let usdt_input_amount = human_to_dec("8000", Decimals::Six);
456
2

            
457
2
    let input_swap_estimate = estimate_swap_result(
458
2
        deps.as_ref(),
459
2
        &mock_env(),
460
2
        "usdt".to_string(),
461
2
        "eth".to_string(),
462
2
        SwapQuantity::InputQuantity(usdt_input_amount),
463
2
    )
464
2
    .unwrap();
465
2

            
466
2
    let expected_eth_result_quantity = human_to_dec("3.994", Decimals::Eighteen);
467
2

            
468
2
    assert_eq!(
469
        input_swap_estimate.result_quantity, expected_eth_result_quantity,
470
        "Wrong amount of swap execution estimate received when using source quantity"
471
    );
472

            
473
2
    assert_eq!(
474
2
        input_swap_estimate.expected_fees.len(),
475
        1,
476
        "Wrong number of fee entries received when using source quantity"
477
    );
478

            
479
2
    let expected_usdt_fee_amount = human_to_dec("19.950124", Decimals::Six);
480
2

            
481
2
    let expected_fee = FPCoin {
482
2
        amount: expected_usdt_fee_amount,
483
2
        denom: "usdt".to_string(),
484
2
    };
485
2

            
486
2
    let mut max_diff = human_to_dec("0.00001", Decimals::Six);
487
2

            
488
2
    assert!(
489
2
        are_fpdecimals_approximately_equal(expected_fee.amount, input_swap_estimate.expected_fees[0].amount, max_diff,),
490
        "Wrong amount of trx fee received when using source quantity. Expected: {}, Actual: {}",
491
        expected_fee.amount,
492
        input_swap_estimate.expected_fees[0].amount
493
    );
494

            
495
2
    let output_swap_estimate = estimate_swap_result(
496
2
        deps.as_ref(),
497
2
        &mock_env(),
498
2
        "usdt".to_string(),
499
2
        "eth".to_string(),
500
2
        SwapQuantity::OutputQuantity(expected_eth_result_quantity),
501
2
    )
502
2
    .unwrap();
503
2

            
504
2
    // diff cannot be higher than 0.0025% of input amount
505
2
    max_diff = usdt_input_amount * FPDecimal::must_from_str("0.00025");
506
2

            
507
2
    assert!(
508
2
        are_fpdecimals_approximately_equal(output_swap_estimate.result_quantity, usdt_input_amount, max_diff),
509
        "Wrong amount of swap execution estimate received when using target quantity"
510
    );
511

            
512
2
    assert!(
513
2
        are_fpdecimals_approximately_equal(expected_fee.amount, input_swap_estimate.expected_fees[0].amount, max_diff,),
514
        "Wrong amount of trx fee received when using source quantity. Expected: {}, Actual: {}",
515
        expected_fee.amount,
516
        input_swap_estimate.expected_fees[0].amount
517
    );
518
2
}
519

            
520
#[test]
521
2
fn get_all_queries_returns_empty_array_if_no_routes_are_set() {
522
2
    let mut deps = mock_deps_eth_inj(MultiplierQueryBehavior::Success);
523
2
    let admin = &Addr::unchecked(TEST_USER_ADDR);
524
2

            
525
2
    instantiate(
526
2
        deps.as_mut_deps(),
527
2
        mock_env(),
528
2
        message_info(&Addr::unchecked(admin), &[coin(1_000u128, "usdt")]),
529
2
        InstantiateMsg {
530
2
            fee_recipient: FeeRecipient::SwapContract,
531
2
            admin: admin.to_owned(),
532
2
        },
533
2
    )
534
2
    .unwrap();
535
2

            
536
2
    let all_routes_result = get_all_swap_routes(deps.as_ref().storage, None, None);
537
2

            
538
2
    assert!(all_routes_result.is_ok(), "Error getting all routes");
539
2
    assert!(all_routes_result.unwrap().is_empty(), "Routes should be empty");
540
2
}
541

            
542
#[test]
543
2
fn get_all_queries_returns_expected_array_if_routes_are_set() {
544
2
    let mut deps = mock_deps_eth_inj(MultiplierQueryBehavior::Success);
545
2
    let admin = &Addr::unchecked(TEST_USER_ADDR);
546
2

            
547
2
    instantiate(
548
2
        deps.as_mut_deps(),
549
2
        mock_env(),
550
2
        message_info(&Addr::unchecked(admin), &[coin(1_000u128, "usdt")]),
551
2
        InstantiateMsg {
552
2
            fee_recipient: FeeRecipient::SwapContract,
553
2
            admin: admin.to_owned(),
554
2
        },
555
2
    )
556
2
    .unwrap();
557
2

            
558
2
    set_route(
559
2
        deps.as_mut_deps(),
560
2
        &Addr::unchecked(TEST_USER_ADDR),
561
2
        "eth".to_string(),
562
2
        "inj".to_string(),
563
2
        vec![TEST_MARKET_ID_1.into(), TEST_MARKET_ID_2.into()],
564
2
    )
565
2
    .unwrap();
566
2

            
567
2
    set_route(
568
2
        deps.as_mut_deps(),
569
2
        &Addr::unchecked(TEST_USER_ADDR),
570
2
        "eth".to_string(),
571
2
        "usdt".to_string(),
572
2
        vec![TEST_MARKET_ID_1.into()],
573
2
    )
574
2
    .unwrap();
575
2

            
576
2
    set_route(
577
2
        deps.as_mut_deps(),
578
2
        &Addr::unchecked(TEST_USER_ADDR),
579
2
        "usdt".to_string(),
580
2
        "inj".to_string(),
581
2
        vec![TEST_MARKET_ID_2.into()],
582
2
    )
583
2
    .unwrap();
584
2

            
585
2
    let all_routes_result = get_all_swap_routes(deps.as_ref().storage, None, None);
586
2
    assert!(all_routes_result.is_ok(), "Error getting all routes");
587

            
588
2
    let eth_inj_route = SwapRoute {
589
2
        source_denom: "eth".to_string(),
590
2
        target_denom: "inj".to_string(),
591
2
        steps: vec![TEST_MARKET_ID_1.into(), TEST_MARKET_ID_2.into()],
592
2
    };
593
2

            
594
2
    let eth_usdt_route = SwapRoute {
595
2
        source_denom: "eth".to_string(),
596
2
        target_denom: "usdt".to_string(),
597
2
        steps: vec![TEST_MARKET_ID_1.into()],
598
2
    };
599
2

            
600
2
    let usdt_inj_route = SwapRoute {
601
2
        source_denom: "usdt".to_string(),
602
2
        target_denom: "inj".to_string(),
603
2
        steps: vec![TEST_MARKET_ID_2.into()],
604
2
    };
605
2

            
606
2
    let all_routes = all_routes_result.unwrap();
607
2
    assert_eq!(
608
2
        all_routes,
609
2
        vec![eth_inj_route, eth_usdt_route, usdt_inj_route],
610
        "Incorrect routes returned"
611
    );
612

            
613
2
    let all_routes_result_paginated = get_all_swap_routes(deps.as_ref().storage, None, Some(1u32));
614
2
    assert_eq!(all_routes_result_paginated.unwrap().len(), 1);
615
2
}