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

Check order capacity when relayer enroll #93

Merged
merged 2 commits into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -208,6 +210,12 @@ pub mod pallet {
T::Currency::free_balance(&who) >= lock_collateral,
<Error<T, I>>::InsufficientBalance
);

ensure!(
Self::collateral_to_order_capacity(lock_collateral) > 0,
boundless-forest marked this conversation as resolved.
Show resolved Hide resolved
<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 @@ -417,7 +417,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 @@ -533,6 +532,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 @@ -545,10 +548,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 @@ -563,14 +562,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