-
Notifications
You must be signed in to change notification settings - Fork 673
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(runtime): Fix empty method_names bug (#2188)
Fixes: #2183 # Test plan: - Extracted the code into utils crate and added unit tests.
- Loading branch information
Evgeny Kuzyakov
authored
Feb 25, 2020
1 parent
d4a07fa
commit 29cb252
Showing
9 changed files
with
123 additions
and
52 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "near-runtime-fees" | ||
version = "0.4.4" | ||
version = "0.4.5" | ||
authors = ["Near Inc <[email protected]>"] | ||
edition = "2018" | ||
license = "Apache-2.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "near-vm-errors" | ||
version = "0.4.4" | ||
version = "0.4.5" | ||
authors = ["Near Inc <[email protected]>"] | ||
edition = "2018" | ||
license = "Apache-2.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "near-vm-logic" | ||
version = "0.4.4" | ||
version = "0.4.5" | ||
authors = ["Near Inc <[email protected]>"] | ||
edition = "2018" | ||
license = "Apache-2.0" | ||
|
@@ -16,8 +16,8 @@ This crate implements the specification of the interface that Near blockchain ex | |
byteorder = "1.2" | ||
bs58 = "0.3" | ||
serde = { version = "1.0", features = ["derive"] } | ||
near-runtime-fees = { path = "../near-runtime-fees", version = "0.4.4" } | ||
near-vm-errors = { path = "../near-vm-errors", version = "0.4.4" } | ||
near-runtime-fees = { path = "../near-runtime-fees", version = "0.4.5" } | ||
near-vm-errors = { path = "../near-vm-errors", version = "0.4.5" } | ||
|
||
[dev-dependencies] | ||
serde_json = {version= "1.0", features= ["preserve_order"]} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
use near_vm_errors::{HostError, VMLogicError}; | ||
|
||
type Result<T> = ::std::result::Result<T, VMLogicError>; | ||
|
||
/// Uses `,` separator to split `method_names` into a vector of method names. | ||
/// Returns an empty vec if the empty slice is given. | ||
/// Throws `HostError::EmptyMethodName` in case there is an empty method name inside. | ||
pub(crate) fn split_method_names(method_names: &[u8]) -> Result<Vec<Vec<u8>>> { | ||
if method_names.is_empty() { | ||
Ok(vec![]) | ||
} else { | ||
method_names | ||
.split(|c| *c == b',') | ||
.map( | ||
|v| { | ||
if v.is_empty() { | ||
Err(HostError::EmptyMethodName.into()) | ||
} else { | ||
Ok(v.to_vec()) | ||
} | ||
}, | ||
) | ||
.collect::<Result<Vec<_>>>() | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_split_method_names_empty() { | ||
assert_eq!(split_method_names(b""), Ok(vec![])); | ||
} | ||
|
||
#[test] | ||
fn test_split_method_one_name() { | ||
assert_eq!(split_method_names(b"hello"), Ok(vec![b"hello".to_vec()])); | ||
} | ||
|
||
#[test] | ||
fn test_split_method_two_method_names() { | ||
assert_eq!( | ||
split_method_names(b"hello,world"), | ||
Ok(vec![b"hello".to_vec(), b"world".to_vec()]) | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_split_empty_method_name_inside() { | ||
assert_eq!( | ||
split_method_names(b"hello,,world"), | ||
Err(VMLogicError::HostError(HostError::EmptyMethodName)) | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_split_empty_method_name_front() { | ||
assert_eq!( | ||
split_method_names(b",world"), | ||
Err(VMLogicError::HostError(HostError::EmptyMethodName)) | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_split_empty_method_name_back() { | ||
assert_eq!( | ||
split_method_names(b"world,"), | ||
Err(VMLogicError::HostError(HostError::EmptyMethodName)) | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_split_empty_method_name_comma_only() { | ||
assert_eq!( | ||
split_method_names(b","), | ||
Err(VMLogicError::HostError(HostError::EmptyMethodName)) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "near-vm-runner-standalone" | ||
version = "0.4.4" | ||
version = "0.4.5" | ||
authors = ["Near Inc <[email protected]>"] | ||
edition = "2018" | ||
license = "Apache-2.0" | ||
|
@@ -21,6 +21,6 @@ to make sure it has expected behavior once deployed to the blockchain. | |
[dependencies] | ||
serde_json = "1.0" | ||
clap = "2.33.0" | ||
near-vm-logic = { path = "../near-vm-logic", version = "0.4.4"} | ||
near-vm-runner = { path = "../near-vm-runner", version = "0.4.4" } | ||
near-runtime-fees = { path = "../near-runtime-fees", version = "0.4.4" } | ||
near-vm-logic = { path = "../near-vm-logic", version = "0.4.5"} | ||
near-vm-runner = { path = "../near-vm-runner", version = "0.4.5" } | ||
near-runtime-fees = { path = "../near-runtime-fees", version = "0.4.5" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "near-vm-runner" | ||
version = "0.4.4" | ||
version = "0.4.5" | ||
authors = ["Near Inc <[email protected]>"] | ||
edition = "2018" | ||
license = "Apache-2.0" | ||
|
@@ -16,9 +16,9 @@ This crate implements the specification of the interface that Near blockchain ex | |
cached = "0.11.0" | ||
wasmer-runtime = { version = "0.13.1", features = ["default-backend-singlepass"], default-features = false } | ||
wasmer-runtime-core = { version = "0.13.1" } | ||
near-runtime-fees = { path="../near-runtime-fees", version = "0.4.4" } | ||
near-vm-logic = { path="../near-vm-logic", version = "0.4.4", default-features = false, features = []} | ||
near-vm-errors = { path = "../near-vm-errors", version = "0.4.4" } | ||
near-runtime-fees = { path="../near-runtime-fees", version = "0.4.5" } | ||
near-vm-logic = { path="../near-vm-logic", version = "0.4.5", default-features = false, features = []} | ||
near-vm-errors = { path = "../near-vm-errors", version = "0.4.5" } | ||
pwasm-utils = "0.12.0" | ||
parity-wasm = "0.41.0" | ||
wasmparser = "0.44" | ||
|