-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't allow invalid chars in Symbol objects. (#765)
Co-authored-by: Graydon Hoare <graydon@pobox.com>
- Loading branch information
Showing
4 changed files
with
76 additions
and
6 deletions.
There are no files selected for viewing
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
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,50 @@ | ||
use crate::{Host, HostError}; | ||
use soroban_env_common::{Symbol, TryFromVal}; | ||
|
||
#[test] | ||
fn invalid_chars() -> Result<(), HostError> { | ||
let host = Host::default(); | ||
|
||
let s = "#"; | ||
let s = Symbol::try_from_val(&host, &s); | ||
|
||
assert!(s.is_err()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn overlong() -> Result<(), HostError> { | ||
let host = Host::default(); | ||
|
||
let s = "123456789012345678901234567890___"; | ||
let s = Symbol::try_from_val(&host, &s); | ||
|
||
assert!(s.is_err()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn max_len() -> Result<(), HostError> { | ||
let host = Host::default(); | ||
|
||
let s = "123456789012345678901234567890__"; | ||
let s = Symbol::try_from_val(&host, &s); | ||
|
||
assert!(s.is_ok()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn zero_len() -> Result<(), HostError> { | ||
let host = Host::default(); | ||
|
||
let s = ""; | ||
let s = Symbol::try_from_val(&host, &s); | ||
|
||
assert!(s.is_ok()); | ||
|
||
Ok(()) | ||
} |