@@ -449,3 +449,87 @@ fn sequential_trades_accumulate_slip_within_block() {
449449 no_slip_drop
450450 ) ;
451451}
452+
453+ #[ test]
454+ fn buy_succeeds_when_slip_cap_is_binding ( ) {
455+ let buy_amount = 100 * UNITS ;
456+ let tight_cap = Permill :: from_parts ( 1000 ) ; // 0.1%
457+
458+ TestNet :: reset ( ) ;
459+ Hydra :: execute_with ( || {
460+ init_omnipool ( ) ;
461+ assert_ok ! ( Omnipool :: set_slip_fee(
462+ RuntimeOrigin :: root( ) ,
463+ Some ( SlipFeeConfig {
464+ max_slip_fee: tight_cap
465+ } ) ,
466+ ) ) ;
467+
468+ let trader = AccountId :: from ( BOB ) ;
469+ assert_ok ! ( Currencies :: update_balance(
470+ RuntimeOrigin :: root( ) ,
471+ trader. clone( ) ,
472+ DAI ,
473+ ( 10_000_000 * UNITS ) as i128 ,
474+ ) ) ;
475+
476+ let dai_before = Currencies :: free_balance ( DAI , & trader) ;
477+ let hdx_before = Currencies :: free_balance ( HDX , & trader) ;
478+
479+ assert_ok ! ( Omnipool :: buy(
480+ RuntimeOrigin :: signed( trader. clone( ) ) ,
481+ HDX ,
482+ DAI ,
483+ buy_amount,
484+ u128 :: MAX ,
485+ ) ) ;
486+
487+ let hdx_received = Currencies :: free_balance ( HDX , & trader) - hdx_before;
488+ assert_eq ! ( hdx_received, buy_amount) ;
489+
490+ let dai_spent = dai_before - Currencies :: free_balance ( DAI , & trader) ;
491+ assert ! ( dai_spent > 0 ) ;
492+ } ) ;
493+ }
494+
495+ #[ test]
496+ fn buy_with_lrna_succeeds_when_slip_cap_is_binding ( ) {
497+ let buy_amount = 100 * UNITS ;
498+ let tight_cap = Permill :: from_parts ( 1000 ) ; // 0.1%
499+
500+ TestNet :: reset ( ) ;
501+ Hydra :: execute_with ( || {
502+ init_omnipool ( ) ;
503+ assert_ok ! ( Omnipool :: set_slip_fee(
504+ RuntimeOrigin :: root( ) ,
505+ Some ( SlipFeeConfig {
506+ max_slip_fee: tight_cap
507+ } ) ,
508+ ) ) ;
509+
510+ let trader = AccountId :: from ( BOB ) ;
511+ assert_ok ! ( Currencies :: update_balance(
512+ RuntimeOrigin :: root( ) ,
513+ trader. clone( ) ,
514+ LRNA ,
515+ ( 1_000_000 * UNITS ) as i128 ,
516+ ) ) ;
517+
518+ let lrna_before = Currencies :: free_balance ( LRNA , & trader) ;
519+ let dai_before = Currencies :: free_balance ( DAI , & trader) ;
520+
521+ assert_ok ! ( Omnipool :: buy(
522+ RuntimeOrigin :: signed( trader. clone( ) ) ,
523+ DAI ,
524+ LRNA ,
525+ buy_amount,
526+ u128 :: MAX ,
527+ ) ) ;
528+
529+ let dai_received = Currencies :: free_balance ( DAI , & trader) - dai_before;
530+ assert_eq ! ( dai_received, buy_amount) ;
531+
532+ let lrna_spent = lrna_before - Currencies :: free_balance ( LRNA , & trader) ;
533+ assert ! ( lrna_spent > 0 ) ;
534+ } ) ;
535+ }
0 commit comments