Skip to content
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
21 changes: 18 additions & 3 deletions tokens/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1329,16 +1329,31 @@ impl<T: Config> MultiLockableCurrency<T::AccountId> for Pallet<T> {
.into_iter()
.filter_map(|lock| {
if lock.id == lock_id {
new_lock.take().map(|nl| BalanceLock {
id: lock.id,
amount: lock.amount.max(nl.amount),
new_lock.take().map(|nl| {
let new_amount = lock.amount.max(nl.amount);
Self::deposit_event(Event::LockSet {
lock_id,
currency_id,
who: who.clone(),
amount: new_amount,
});
BalanceLock {
id: lock.id,
amount: new_amount,
}
})
} else {
Some(lock)
}
})
.collect::<Vec<_>>();
if let Some(lock) = new_lock {
Self::deposit_event(Event::LockSet {
lock_id,
currency_id,
who: who.clone(),
amount: lock.amount,
});
locks.push(lock)
}
Self::update_locks(currency_id, who, &locks[..])
Expand Down
33 changes: 33 additions & 0 deletions tokens/src/tests_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,3 +422,36 @@ fn pallet_change_locks_events() {
})));
});
}

#[test]
fn pallet_multi_lockable_currency_extend_lock_events() {
ExtBuilder::default()
.balances(vec![(ALICE, DOT, 100)])
.build()
.execute_with(|| {
// lock already exists
assert_ok!(Tokens::set_lock(ID_1, DOT, &ALICE, 10));
assert_ok!(Tokens::extend_lock(ID_1, DOT, &ALICE, 20));
assert!(events().contains(&RuntimeEvent::Tokens(crate::Event::LockSet {
lock_id: ID_1,
currency_id: DOT,
who: ALICE,
amount: 20,
})));
// lock doesn't exist
assert_ok!(Tokens::extend_lock(ID_2, DOT, &ALICE, 10));
assert!(events().contains(&RuntimeEvent::Tokens(crate::Event::LockSet {
lock_id: ID_2,
currency_id: DOT,
who: ALICE,
amount: 10,
})));
assert_ok!(Tokens::extend_lock(ID_2, DOT, &ALICE, 20));
assert!(events().contains(&RuntimeEvent::Tokens(crate::Event::LockSet {
lock_id: ID_2,
currency_id: DOT,
who: ALICE,
amount: 20,
})));
});
}