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

Public extrinsic apply doesn't panic #178

Merged
merged 11 commits into from
May 31, 2018
3 changes: 2 additions & 1 deletion demo/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
staking: Some(StakingConfig {
current_era: 0,
intentions: vec![],
transaction_fee: 100,
transaction_base_fee: 100,
transaction_byte_fee: 1,
balances: vec![(god_key.clone(), 1u64 << 63)].into_iter().collect(),
validator_count: 12,
sessions_per_era: 24, // 24 hours per era.
Expand Down
31 changes: 19 additions & 12 deletions demo/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ mod tests {
#[test]
fn panic_execution_with_foreign_code_gives_error() {
let mut t: TestExternalities = map![
twox_128(&<staking::FreeBalance<Concrete>>::key_for(*Alice)).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(<staking::TransactionFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
twox_128(&<staking::FreeBalance<Concrete>>::key_for(*Alice)).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(<staking::TransactionBaseFee<Concrete>>::key()).to_vec() => vec![70u8; 8],
twox_128(<staking::TransactionByteFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
twox_128(&<system::BlockHash<Concrete>>::key_for(0)).to_vec() => vec![0u8; 32]
];

Expand All @@ -96,8 +97,9 @@ mod tests {
#[test]
fn panic_execution_with_native_equivalent_code_gives_error() {
let mut t: TestExternalities = map![
twox_128(&<staking::FreeBalance<Concrete>>::key_for(*Alice)).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(<staking::TransactionFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
twox_128(&<staking::FreeBalance<Concrete>>::key_for(*Alice)).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(<staking::TransactionBaseFee<Concrete>>::key()).to_vec() => vec![70u8; 8],
twox_128(<staking::TransactionByteFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
twox_128(&<system::BlockHash<Concrete>>::key_for(0)).to_vec() => vec![0u8; 32]
];

Expand All @@ -111,7 +113,8 @@ mod tests {
fn successful_execution_with_native_equivalent_code_gives_ok() {
let mut t: TestExternalities = map![
twox_128(&<staking::FreeBalance<Concrete>>::key_for(*Alice)).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(<staking::TransactionFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
twox_128(<staking::TransactionBaseFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
twox_128(<staking::TransactionByteFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
twox_128(&<system::BlockHash<Concrete>>::key_for(0)).to_vec() => vec![0u8; 32]
];

Expand All @@ -130,7 +133,8 @@ mod tests {
fn successful_execution_with_foreign_code_gives_ok() {
let mut t: TestExternalities = map![
twox_128(&<staking::FreeBalance<Concrete>>::key_for(*Alice)).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(<staking::TransactionFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
twox_128(<staking::TransactionBaseFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
twox_128(<staking::TransactionByteFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
twox_128(&<system::BlockHash<Concrete>>::key_for(0)).to_vec() => vec![0u8; 32]
];

Expand Down Expand Up @@ -162,7 +166,8 @@ mod tests {
intentions: vec![Alice.into(), Bob.into(), Charlie.into()],
validator_count: 3,
bonding_duration: 0,
transaction_fee: 1,
transaction_base_fee: 1,
transaction_byte_fee: 0,
}),
democracy: Some(Default::default()),
council: Some(Default::default()),
Expand Down Expand Up @@ -197,7 +202,7 @@ mod tests {
construct_block(
1,
[69u8; 32].into(),
hex!("a63d59c6a7347cd7a1dc1ec139723b531f0ac450e39b1c532d5ca69ff74ad811").into(),
hex!("76b0393b4958d3cb98bb51d9f4edb316af48485142b8721e94c3b52c75ec3243").into(),
vec![Extrinsic {
signed: Alice.into(),
index: 0,
Expand All @@ -210,7 +215,7 @@ mod tests {
construct_block(
2,
block1().1,
hex!("1c3623b2e3f7e43752debb9015bace4f6931593579b5af34457b931315f5e2ab").into(),
hex!("8ae9828a5988459d35fb428086170dead660176ee0766e89bc1a4b48153d4e88").into(),
vec![
Extrinsic {
signed: Bob.into(),
Expand Down Expand Up @@ -267,8 +272,9 @@ mod tests {
#[test]
fn panic_execution_gives_error() {
let mut t: TestExternalities = map![
twox_128(&<staking::FreeBalance<Concrete>>::key_for(*Alice)).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(<staking::TransactionFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
twox_128(&<staking::FreeBalance<Concrete>>::key_for(*Alice)).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(<staking::TransactionBaseFee<Concrete>>::key()).to_vec() => vec![70u8; 8],
twox_128(<staking::TransactionByteFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
twox_128(&<system::BlockHash<Concrete>>::key_for(0)).to_vec() => vec![0u8; 32]
];

Expand All @@ -283,7 +289,8 @@ mod tests {
fn successful_execution_gives_ok() {
let mut t: TestExternalities = map![
twox_128(&<staking::FreeBalance<Concrete>>::key_for(*Alice)).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0],
twox_128(<staking::TransactionFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
twox_128(<staking::TransactionBaseFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
twox_128(<staking::TransactionByteFee<Concrete>>::key()).to_vec() => vec![0u8; 8],
twox_128(&<system::BlockHash<Concrete>>::key_for(0)).to_vec() => vec![0u8; 32]
];

Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion polkadot/cli/src/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ args:
- chain:
long: chain
value_name: CHAIN_SPEC
help: Specify the chain specification (one of dev, local or poc-1)
help: Specify the chain specification (one of dev, local or poc-2)
takes_value: true
subcommands:
6 changes: 3 additions & 3 deletions polkadot/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl substrate_rpc::system::SystemApi for Configuration {
Ok(match self.0.chain_spec {
ChainSpec::Development => "dev",
ChainSpec::LocalTestnet => "local",
ChainSpec::PoC1Testnet => "poc-1",
ChainSpec::PoC2Testnet => "poc-2",
}.into())
}
}
Expand Down Expand Up @@ -174,14 +174,14 @@ pub fn run<I, T>(args: I) -> error::Result<()> where
match matches.value_of("chain") {
Some("dev") => config.chain_spec = ChainSpec::Development,
Some("local") => config.chain_spec = ChainSpec::LocalTestnet,
Some("poc-1") => config.chain_spec = ChainSpec::PoC1Testnet,
Some("poc-2") => config.chain_spec = ChainSpec::PoC2Testnet,
None => (),
Some(unknown) => panic!("Invalid chain name: {}", unknown),
}
info!("Chain specification: {}", match config.chain_spec {
ChainSpec::Development => "Development",
ChainSpec::LocalTestnet => "Local Testnet",
ChainSpec::PoC1Testnet => "PoC-1 Testnet",
ChainSpec::PoC2Testnet => "PoC-2 Testnet",
});

config.roles = role;
Expand Down
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions polkadot/service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub enum ChainSpec {
Development,
/// Whatever the current runtime is, with simple Alice/Bob auths.
LocalTestnet,
/// The PoC-1 testnet.
PoC1Testnet,
/// The PoC-2 testnet.
PoC2Testnet,
}

/// Service configuration.
Expand Down
10 changes: 6 additions & 4 deletions polkadot/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub struct ChainConfig {
boot_nodes: Vec<String>,
}

fn poc_1_testnet_config() -> ChainConfig {
fn poc_2_testnet_config() -> ChainConfig {
let initial_authorities = vec![
hex!["82c39b31a2b79a90f8e66e7a77fdb85a4ed5517f2ae39f6a80565e8ecae85cf5"].into(),
hex!["4de37a07567ebcbf8c64568428a835269a566723687058e017b6d69db00a77e7"].into(),
Expand All @@ -164,7 +164,8 @@ fn poc_1_testnet_config() -> ChainConfig {
staking: Some(StakingConfig {
current_era: 0,
intentions: initial_authorities.clone(),
transaction_fee: 100,
transaction_base_fee: 100,
transaction_byte_fee: 1,
balances: endowed_accounts.iter().map(|&k|(k, 1u128 << 60)).collect(),
validator_count: 12,
sessions_per_era: 24, // 24 hours per era.
Expand Down Expand Up @@ -222,7 +223,8 @@ fn testnet_config(initial_authorities: Vec<AuthorityId>) -> ChainConfig {
staking: Some(StakingConfig {
current_era: 0,
intentions: initial_authorities.clone(),
transaction_fee: 1,
transaction_base_fee: 1,
transaction_byte_fee: 0,
balances: endowed_accounts.iter().map(|&k|(k, (1u128 << 60))).collect(),
validator_count: 2,
sessions_per_era: 5,
Expand Down Expand Up @@ -364,7 +366,7 @@ impl<B, E> Service<B, E>
let ChainConfig { genesis_config, boot_nodes } = match config.chain_spec {
ChainSpec::Development => development_config(),
ChainSpec::LocalTestnet => local_testnet_config(),
ChainSpec::PoC1Testnet => poc_1_testnet_config(),
ChainSpec::PoC2Testnet => poc_2_testnet_config(),
};
config.network.boot_nodes.extend(boot_nodes);

Expand Down
Binary file not shown.
Binary file not shown.
59 changes: 59 additions & 0 deletions substrate/runtime-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,62 @@ mod hashable;
pub use self::storage::{StorageVec, StorageList, StorageValue, StorageMap};
pub use self::hashable::Hashable;
pub use self::dispatch::{Parameter, Dispatchable, Callable, AuxDispatchable, AuxCallable, IsSubType, IsAuxSubType};
pub use runtime_io::print;

#[macro_export]
macro_rules! fail {
( $y:expr ) => {{
$crate::print($y);
return;
}}
}

#[macro_export]
macro_rules! ensure {
( $x:expr, $y:expr ) => {{
if !$x {
fail!($y);
}
}};
($x:expr) => {{
if !$x {
$crate::print("Bailing! Cannot ensure: ");
$crate::print(stringify!($x));
return;
}
}}
}

#[macro_export]
macro_rules! ensure_unwrap {
($x:expr, $y: expr) => {
if let Some(v) = $x {
v
} else {
fail!{$y}
}
}
}

#[macro_export]
macro_rules! ensure_unwrap_err {
($x:expr, $y: expr) => {
if let Err(v) = $x {
v
} else {
fail!{$y}
}
}
}

#[macro_export]
#[cfg(feature = "std")]
macro_rules! assert_noop {
( $( $x:tt )* ) => {
let h = runtime_io::storage_root();
{
$( $x )*
}
assert_eq!(h, runtime_io::storage_root());
}
}