diff --git a/modules/fee-market/src/lib.rs b/modules/fee-market/src/lib.rs index b8ae6c4f7..d0d9d3c31 100644 --- a/modules/fee-market/src/lib.rs +++ b/modules/fee-market/src/lib.rs @@ -117,6 +117,8 @@ pub mod pallet { AlreadyEnrolled, /// This relayer doesn't enroll ever. NotEnrolled, + /// Locked collateral is too low to cover one order. + CollateralTooLow, /// Update locked collateral is not allow since some orders are not confirm. StillHasOrdersNotConfirmed, /// The fee is lower than MinimumRelayFee. @@ -206,6 +208,12 @@ pub mod pallet { T::Currency::free_balance(&who) >= lock_collateral, >::InsufficientBalance ); + + ensure!( + Self::collateral_to_order_capacity(lock_collateral) > 0, + >::CollateralTooLow + ); + if let Some(fee) = relay_fee { ensure!(fee >= T::MinimumRelayFee::get(), >::RelayFeeTooLow); } diff --git a/modules/fee-market/src/tests.rs b/modules/fee-market/src/tests.rs index 31ef88a18..f4e13c38d 100644 --- a/modules/fee-market/src/tests.rs +++ b/modules/fee-market/src/tests.rs @@ -402,7 +402,6 @@ impl pallet_bridge_messages::Config for Test { } frame_support::parameter_types! { - pub const FeeMarketPalletId: PalletId = PalletId(*b"da/feemk"); pub const TreasuryPalletId: PalletId = PalletId(*b"da/trsry"); pub const FeeMarketLockId: LockIdentifier = *b"da/feelf"; pub const MinimumRelayFee: Balance = 30; @@ -518,6 +517,10 @@ fn test_call_relayer_enroll_works() { FeeMarket::enroll_and_lock_collateral(Origin::signed(1), 200, None), >::InsufficientBalance ); + assert_err!( + FeeMarket::enroll_and_lock_collateral(Origin::signed(1), 99, None), + >::CollateralTooLow + ); assert_ok!(FeeMarket::enroll_and_lock_collateral(Origin::signed(1), 100, None)); assert!(FeeMarket::is_enrolled(&1)); @@ -530,10 +533,6 @@ fn test_call_relayer_enroll_works() { FeeMarket::enroll_and_lock_collateral(Origin::signed(1), 100, None), >::AlreadyEnrolled ); - - assert_ok!(FeeMarket::enroll_and_lock_collateral(Origin::signed(3), 250, None)); - - assert_ok!(FeeMarket::enroll_and_lock_collateral(Origin::signed(4), 0, None),); }); } @@ -548,14 +547,11 @@ fn test_call_relayer_increase_lock_collateral_works() { let _ = FeeMarket::enroll_and_lock_collateral(Origin::signed(12), 200, None); assert_eq!(FeeMarket::relayer(&12).collateral, 200); - // Increase locked balance from 200 to 500 + // Increase locked collateral from 200 to 500 assert_ok!(FeeMarket::update_locked_collateral(Origin::signed(12), 500)); assert_eq!(FeeMarket::relayer(&12).collateral, 500); - // Increase locked balance from 20 to 200 - let _ = FeeMarket::enroll_and_lock_collateral(Origin::signed(13), 20, None); - assert_ok!(FeeMarket::update_locked_collateral(Origin::signed(13), 200)); - + let _ = FeeMarket::enroll_and_lock_collateral(Origin::signed(13), 200, None); let _ = FeeMarket::enroll_and_lock_collateral(Origin::signed(14), 300, None); let market_fee = FeeMarket::market_fee().unwrap(); let _ = send_regular_message(market_fee);