Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Check order capacity when relayer enroll (#93)
Browse files Browse the repository at this point in the history
* Add check logic

* Update test file
  • Loading branch information
boundless-forest authored May 30, 2022
1 parent f436048 commit 8c877be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
8 changes: 8 additions & 0 deletions modules/fee-market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -207,6 +209,12 @@ pub mod pallet {
T::Currency::free_balance(&who) >= lock_collateral,
<Error<T, I>>::InsufficientBalance
);

ensure!(
Self::collateral_to_order_capacity(lock_collateral) > 0,
<Error<T, I>>::CollateralTooLow
);

if let Some(fee) = relay_fee {
ensure!(fee >= T::MinimumRelayFee::get(), <Error<T, I>>::RelayFeeTooLow);
}
Expand Down
16 changes: 6 additions & 10 deletions modules/fee-market/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ impl SenderOrigin<AccountId> for Origin {
}

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;
Expand Down Expand Up @@ -524,6 +523,10 @@ fn test_call_relayer_enroll_works() {
FeeMarket::enroll_and_lock_collateral(Origin::signed(1), 200, None),
<Error<Test>>::InsufficientBalance
);
assert_err!(
FeeMarket::enroll_and_lock_collateral(Origin::signed(1), 99, None),
<Error<Test>>::CollateralTooLow
);

assert_ok!(FeeMarket::enroll_and_lock_collateral(Origin::signed(1), 100, None));
assert!(FeeMarket::is_enrolled(&1));
Expand All @@ -536,10 +539,6 @@ fn test_call_relayer_enroll_works() {
FeeMarket::enroll_and_lock_collateral(Origin::signed(1), 100, None),
<Error<Test>>::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),);
});
}

Expand All @@ -554,14 +553,11 @@ fn test_call_relayer_increase_lock_collateral_works() {
let _ = FeeMarket::enroll_and_lock_collateral(Origin::signed(12), 200, None);
assert_eq!(FeeMarket::relayer_locked_collateral(&12), 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_locked_collateral(&12), 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);
Expand Down

0 comments on commit 8c877be

Please sign in to comment.