Skip to content

Commit

Permalink
Add SudoUncheckedWeightCall (#167)
Browse files Browse the repository at this point in the history
* Add SudoUncheckedWeightCall

* Add test_sudo_unchecked_weight()

* Fix CI

Use nightly fmt.

* .
  • Loading branch information
liuchengxu authored Sep 21, 2020
1 parent ce22986 commit e843bd6
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/frame/sudo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::{
};
use codec::Encode;
use core::marker::PhantomData;
use frame_support::weights::Weight;

/// The subset of the `frame_sudo::Trait` that a client must implement.
#[module]
Expand All @@ -39,6 +40,20 @@ pub struct SudoCall<'a, T: Sudo> {
pub call: &'a Encoded,
}

/// Execute a transaction with sudo permissions without checking the call weight.
#[derive(Clone, Debug, Eq, PartialEq, Call, Encode)]
pub struct SudoUncheckedWeightCall<'a, T: Sudo> {
/// Runtime marker.
pub _runtime: PhantomData<T>,
/// Encoded transaction.
pub call: &'a Encoded,
/// Call weight.
///
/// This argument is actually unused in runtime, you can pass any value of
/// `Weight` type when using this call.
pub weight: Weight,
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -78,4 +93,29 @@ mod tests {
}
);
}

#[async_std::test]
async fn test_sudo_unchecked_weight() {
env_logger::try_init().ok();
let alice = PairSigner::<TestRuntime, _>::new(AccountKeyring::Alice.pair());
let (client, _) = test_client().await;

let call = client
.encode(TransferCall {
to: &AccountKeyring::Bob.to_account_id(),
amount: 10_000,
})
.unwrap();

let res = client
.sudo_unchecked_weight_and_watch(&alice, &call, 0u64)
.await;
assert!(
if let Err(Error::Runtime(RuntimeError::BadOrigin)) = res {
true
} else {
false
}
);
}
}

0 comments on commit e843bd6

Please sign in to comment.