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

Commit

Permalink
5 random fixes (#1) (#435)
Browse files Browse the repository at this point in the history
* ok_or → ok_or_else

* Correct the sides of the given and expected args

* Indent } properly

* Convert identation from tabs to spaces.

* Convert identation from tabs to spaces. [2]
  • Loading branch information
pepyakin authored and rphmeier committed Jul 27, 2018
1 parent 4b80964 commit 895b35b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
30 changes: 15 additions & 15 deletions substrate/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fn is_node_name_valid(_name: &str) -> Result<(), &str> {
let name = _name.to_string();
if name.chars().count() >= MAX_NODE_NAME_LENGTH {
return Err("Node name too long");
}
}

let invalid_chars = r"[\\.@]";
let re = Regex::new(invalid_chars).unwrap();
Expand Down Expand Up @@ -384,9 +384,9 @@ fn revert_chain<F>(matches: &clap::ArgMatches, spec: ChainSpec<FactoryGenesis<F>
}

fn parse_address(default: &str, port_param: &str, matches: &clap::ArgMatches) -> Result<SocketAddr, String> {
let mut address: SocketAddr = default.parse().ok().ok_or(format!("Invalid address specified for --{}.", port_param))?;
let mut address: SocketAddr = default.parse().ok().ok_or_else(|| format!("Invalid address specified for --{}.", port_param))?;
if let Some(port) = matches.value_of(port_param) {
let port: u16 = port.parse().ok().ok_or(format!("Invalid port for --{} specified.", port_param))?;
let port: u16 = port.parse().ok().ok_or_else(|| format!("Invalid port for --{} specified.", port_param))?;
address.set_port(port);
}

Expand Down Expand Up @@ -485,18 +485,18 @@ fn kill_color(s: &str) -> String {
mod tests {
use super::*;

#[test]
fn tests_node_name_good() {
assert!(is_node_name_valid("short name").is_ok());
}
#[test]
fn tests_node_name_good() {
assert!(is_node_name_valid("short name").is_ok());
}

#[test]
#[test]
fn tests_node_name_bad() {
assert!(is_node_name_valid("long names are not very cool for the ui").is_err());
assert!(is_node_name_valid("Dots.not.Ok").is_err());
assert!(is_node_name_valid("http://visit.me").is_err());
assert!(is_node_name_valid("https://visit.me").is_err());
assert!(is_node_name_valid("www.visit.me").is_err());
assert!(is_node_name_valid("email@domain").is_err());
}
assert!(is_node_name_valid("long names are not very cool for the ui").is_err());
assert!(is_node_name_valid("Dots.not.Ok").is_err());
assert!(is_node_name_valid("http://visit.me").is_err());
assert!(is_node_name_valid("https://visit.me").is_err());
assert!(is_node_name_valid("www.visit.me").is_err());
assert!(is_node_name_valid("email@domain").is_err());
}
}
2 changes: 1 addition & 1 deletion substrate/runtime-io/without_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn panic(info: &::core::panic::PanicInfo) -> ! {

#[alloc_error_handler]
pub extern fn oom(_: ::core::alloc::Layout) -> ! {
static OOM_MSG: &str = "Runtime memory exhausted. Aborting";
static OOM_MSG: &str = "Runtime memory exhausted. Aborting";

unsafe {
ext_print_utf8(OOM_MSG.as_ptr(), OOM_MSG.len() as u32);
Expand Down
4 changes: 2 additions & 2 deletions substrate/state-machine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ pub fn execute_using_consensus_failure_handler<

// make a copy.
let code = ext::Ext::new(overlay, backend).storage(b":code")
.ok_or(Box::new(ExecutionError::CodeEntryDoesNotExist) as Box<Error>)?
.ok_or_else(|| Box::new(ExecutionError::CodeEntryDoesNotExist) as Box<Error>)?
.to_vec();

let result = {
Expand Down Expand Up @@ -509,7 +509,7 @@ mod tests {
},
"test",
&[],
ExecutionManager::Both(|we, _ne| {
ExecutionManager::Both(|we, _ne| {
consensus_failed = true;
println!("HELLO!");
we
Expand Down
8 changes: 4 additions & 4 deletions substrate/test-runtime/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ pub fn execute_block(block: Block) {
let txs = block.extrinsics.iter().map(Encode::encode).collect::<Vec<_>>();
let txs = txs.iter().map(Vec::as_slice).collect::<Vec<_>>();
let txs_root = enumerated_trie_root(&txs).into();
info_expect_equal_hash(&header.extrinsics_root, &txs_root);
assert!(header.extrinsics_root == txs_root, "Transaction trie root must be valid.");
info_expect_equal_hash(&txs_root, &header.extrinsics_root);
assert!(txs_root == header.extrinsics_root, "Transaction trie root must be valid.");

// execute transactions
block.extrinsics.iter().for_each(|e| { execute_transaction_backend(e).map_err(|_| ()).expect("Extrinsic error"); });

// check storage root.
let storage_root = storage_root().into();
info_expect_equal_hash(&header.state_root, &storage_root);
assert!(header.state_root == storage_root, "Storage root must match that calculated.");
info_expect_equal_hash(&storage_root, &header.state_root);
assert!(storage_root == header.state_root, "Storage root must match that calculated.");
}

/// Execute a transaction outside of the block execution function.
Expand Down

0 comments on commit 895b35b

Please sign in to comment.