Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
tests for proxy and utility for tx-pause
Browse files Browse the repository at this point in the history
fmt
  • Loading branch information
nuke-web3 committed Oct 11, 2022
1 parent adb3ab8 commit ad27654
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 14 deletions.
10 changes: 4 additions & 6 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,10 @@ pub struct UnfilterableCallNames;
/// Make Balances::transfer_keep_alive unfilterable, accept all others.
impl Contains<FullNameOf<Runtime>> for UnfilterableCallNames {
fn contains(full_name: &FullNameOf<Runtime>) -> bool {
let unpausables: Vec<FullNameOf<Runtime>> = vec![
(
b"Balances".to_vec().try_into().unwrap(),
Some(b"transfer_keep_alive".to_vec().try_into().unwrap()),
),
];
let unpausables: Vec<FullNameOf<Runtime>> = vec![(
b"Balances".to_vec().try_into().unwrap(),
Some(b"transfer_keep_alive".to_vec().try_into().unwrap()),
)];

for unpausable_call in unpausables {
let (pallet_name, maybe_call_name) = full_name;
Expand Down
2 changes: 1 addition & 1 deletion frame/safe-mode/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub struct UnfilterableCalls;
impl Contains<RuntimeCall> for UnfilterableCalls {
fn contains(call: &RuntimeCall) -> bool {
match call {
RuntimeCall::Balances(_) => false,
RuntimeCall::Balances(_) => false,
_ => true,
}
}
Expand Down
17 changes: 10 additions & 7 deletions frame/safe-mode/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,16 @@ fn can_filter_balance_calls_when_activated() {
});
}


#[test]
fn can_filter_balance_in_batch_when_activated() {
new_test_ext().execute_with(|| {
let batch_call = RuntimeCall::Utility(pallet_utility::Call::batch { calls: vec![call_transfer()]});
let batch_call =
RuntimeCall::Utility(pallet_utility::Call::batch { calls: vec![call_transfer()] });

assert_ok!(batch_call.clone().dispatch(Origin::signed(0)));

assert_ok!(SafeMode::activate(Origin::signed(0)));

assert_ok!(batch_call.clone().dispatch(Origin::signed(0)));
System::assert_last_event(
pallet_utility::Event::BatchInterrupted {
Expand All @@ -161,13 +161,16 @@ fn can_filter_balance_in_proxy_when_activated() {
assert_ok!(Proxy::add_proxy(Origin::signed(1), 2, ProxyType::JustTransfer, 0));

assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, Box::new(call_transfer())));
System::assert_last_event( pallet_proxy::Event::ProxyExecuted { result: Ok(()) }.into() );
System::assert_last_event(pallet_proxy::Event::ProxyExecuted { result: Ok(()) }.into());

assert_ok!(SafeMode::force_activate(ForceActivateOrigin::Weak.signed()));

assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, Box::new(call_transfer())));
System::assert_last_event(
pallet_proxy::Event::ProxyExecuted { result: DispatchError::from(frame_system::Error::<Test>::CallFiltered).into() }.into(),
pallet_proxy::Event::ProxyExecuted {
result: DispatchError::from(frame_system::Error::<Test>::CallFiltered).into(),
}
.into(),
);
});
}
Expand Down Expand Up @@ -494,4 +497,4 @@ fn fails_when_explicit_origin_required() {

fn call_transfer() -> RuntimeCall {
RuntimeCall::Balances(pallet_balances::Call::transfer { dest: 1, value: 1 })
}
}
44 changes: 44 additions & 0 deletions frame/tx-pause/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,50 @@ fn can_unpause_specific_call() {
});
}

#[test]
fn can_filter_balance_in_batch_when_paused() {
new_test_ext().execute_with(|| {
let batch_call =
RuntimeCall::Utility(pallet_utility::Call::batch { calls: vec![call_transfer(1, 1)] });

assert_ok!(TxPause::pause_call(
Origin::signed(mock::PauseOrigin::get()),
name(b"Balances"),
name(b"transfer"),
));

assert_ok!(batch_call.clone().dispatch(Origin::signed(0)));
System::assert_last_event(
pallet_utility::Event::BatchInterrupted {
index: 0,
error: frame_system::Error::<Test>::CallFiltered.into(),
}
.into(),
);
});
}

#[test]
fn can_filter_balance_in_proxy_when_paused() {
new_test_ext().execute_with(|| {
assert_ok!(TxPause::pause_call(
Origin::signed(mock::PauseOrigin::get()),
name(b"Balances"),
name(b"transfer"),
));

assert_ok!(Proxy::add_proxy(Origin::signed(1), 2, ProxyType::JustTransfer, 0));

assert_ok!(Proxy::proxy(Origin::signed(2), 1, None, Box::new(call_transfer(1, 1))));
System::assert_last_event(
pallet_proxy::Event::ProxyExecuted {
result: DispatchError::from(frame_system::Error::<Test>::CallFiltered).into(),
}
.into(),
);
});
}

// GENERAL FAIL/NEGATIVE TESTS ---------------------

#[test]
Expand Down

0 comments on commit ad27654

Please sign in to comment.