Skip to content

emit LockSet on extend_lock #933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 29, 2023
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,
})));
});
}