Skip to content

Commit

Permalink
Restrict Court to LLM Staked -> Staked transfers only
Browse files Browse the repository at this point in the history
  • Loading branch information
kacperzuk-neti committed Jul 23, 2024
1 parent 74056ef commit 93c0ea2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
2 changes: 1 addition & 1 deletion substrate/frame/llm/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ benchmarks! {
let origin = RawOrigin::Signed(user.clone());
LLM::<T>::politics_lock(origin.clone().into(), amount.clone()).unwrap();
assert_eq!(LLMPolitics::<T>::get(&user), amount.clone());
}: _(origin, LLMAccount::Locked(user.clone()), LLMAccount::Liquid(user2.clone()), amount.clone())
}: _(origin, LLMAccount::Locked(user.clone()), LLMAccount::Locked(user2.clone()), amount.clone())
verify {
assert_eq!(LLMPolitics::<T>::get(&user), 0u8.into());
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/llm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ pub mod pallet {
},
};
let transfer_to = match to {
LLMAccount::Liquid(account) => account,
LLMAccount::Liquid(_) => return Err(Error::<T>::InvalidAccount.into()),
LLMAccount::Locked(account) => {
LLMPolitics::<T>::mutate(account.clone(), |b| *b += amount);
Self::deposit_event(Event::<T>::LLMPoliticsLocked(account, amount));
Expand Down
23 changes: 5 additions & 18 deletions substrate/frame/llm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -704,29 +704,16 @@ fn cant_force_transfer_from_liquid() {
}

#[test]
fn force_updates_balances_correctly_to_liquid() {
fn cant_force_transfer_to_liquid() {
new_test_ext().execute_with(|| {
assert_ok!(LLM::politics_lock(RuntimeOrigin::signed(1), 3));

let court = RuntimeOrigin::signed(1);
let id = LLM::llm_id();
let politipool = LLM::get_llm_politipool_account();
let from = LLMAccount::Locked(1);
let to = LLMAccount::Liquid(2);
let amount = 2;

assert_ok!(LLM::politics_lock(RuntimeOrigin::signed(1), 3));
assert_ok!(LLM::politics_lock(RuntimeOrigin::signed(2), 2));
let politipool_before = Assets::balance(id, politipool);
let from_before = Assets::balance(id, 1);
let to_before = Assets::balance(id, 2);

assert_ok!(LLM::force_transfer(court, from, to, amount));

assert_eq!(Assets::balance(id, politipool), politipool_before - amount);
assert_eq!(Assets::balance(id, 1), from_before);
assert_eq!(Assets::balance(id, 2), to_before + amount);
let amount = 1;

assert_eq!(LLMPolitics::<Test>::get(1), 3 - amount);
assert_eq!(LLMPolitics::<Test>::get(2), 2);
assert_noop!(LLM::force_transfer(court, from, to, amount), Error::<Test>::InvalidAccount);
});
}

Expand Down

0 comments on commit 93c0ea2

Please sign in to comment.