-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add UTF-8 encoding validity check, limit dst20 token name length * fmt cpp * Add longer string test * Fix rust lint * Disable clippy on ffi * Specify exact clippy warn * Init vec with reserved namespace size * Fix throw error on max byte size check * Add genesis block token name tests * Remove unnecessary substr op * Fix createtoken rpc token name max length * Initial dev to port utf8 check on rust side * Fixes to use vec * Fix rust ffi for creating dst20 tokens * Rust lint * Fmt cpp * Revert token validation pipeline * Add unit test for rust UTF-8 encoding validity test * Fix rust lint * Switch to 31 limit * Fix dst20 test * Remove clippy ignore * Fix merge error * Expose rust str utf8 check with ffi * Fix rust lint * Remove import * Remove import * Add next upgrade fork height on tests * Disable lint checks on dst20 migration tokens * Fix rust lint --------- Co-authored-by: Jouzo <[email protected]>
- Loading branch information
Showing
46 changed files
with
432 additions
and
54 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,55 @@ | ||
#[cfg(test)] | ||
use std::str; | ||
|
||
#[test] | ||
fn check_for_valid_utf8_strings() { | ||
let test1 = "abcdefghijklmnopqrstuvwxyz1234567890~_= ^+%]{}"; | ||
let test2 = "abcdeàèéìòù"; | ||
let test3 = "😁 Beaming Face With Smiling Eyes"; | ||
let test4 = "Slightly Smiling Face 🙂"; | ||
let test5 = "🤣🤣🤣 Rolling on the Floor Laughing"; | ||
let test6 = "🤩🤩🤩 Star-🤩Struck 🤩🤩"; | ||
let test7 = "Left till here away at to whom past. Feelings laughing at no wondered repeated provided finished. \ | ||
It acceptance thoroughly my advantages everything as. Are projecting inquietude affronting preference saw who. \ | ||
Marry of am do avoid ample as. Old disposal followed she ignorant desirous two has. Called played entire roused \ | ||
though for one too. He into walk roof made tall cold he. Feelings way likewise addition wandered contempt bed \ | ||
indulged."; | ||
|
||
let test1_bytes = test1.as_bytes(); | ||
let test2_bytes = test2.as_bytes(); | ||
let test3_bytes = test3.as_bytes(); | ||
let test4_bytes = test4.as_bytes(); | ||
let test5_bytes = test5.as_bytes(); | ||
let test6_bytes = test6.as_bytes(); | ||
let test7_bytes = test7.as_bytes(); | ||
|
||
assert_eq!(str::from_utf8(test1_bytes), Ok(test1)); | ||
assert_eq!(str::from_utf8(test2_bytes), Ok(test2)); | ||
assert_eq!(str::from_utf8(test3_bytes), Ok(test3)); | ||
assert_eq!(str::from_utf8(test4_bytes), Ok(test4)); | ||
assert_eq!(str::from_utf8(test5_bytes), Ok(test5)); | ||
assert_eq!(str::from_utf8(test6_bytes), Ok(test6)); | ||
assert_eq!(str::from_utf8(test7_bytes), Ok(test7)); | ||
} | ||
|
||
#[test] | ||
fn check_for_invalid_utf8_strings() { | ||
let smiling_face = "😁".as_bytes(); | ||
let laughing_face = "🤣".as_bytes(); | ||
let star_struck_face = "🤩".as_bytes(); | ||
|
||
let mut test1 = smiling_face[0..1].to_vec(); | ||
test1.extend_from_slice(" Beaming Face With Smiling Eyes".as_bytes()); | ||
|
||
let mut test2 = laughing_face[0..3].to_vec(); | ||
test2.extend_from_slice(&laughing_face[0..2]); | ||
test2.extend_from_slice(&laughing_face[0..1]); | ||
test2.extend_from_slice(" Rolling on the Floor Laughing".as_bytes()); | ||
|
||
let mut test3 = star_struck_face[0..1].to_vec(); | ||
test3.extend_from_slice("🤩🤩 Star-🤩Struck 🤩🤩".as_bytes()); | ||
|
||
assert!(str::from_utf8(test1.as_slice()).is_err()); | ||
assert!(str::from_utf8(test2.as_slice()).is_err()); | ||
assert!(str::from_utf8(test3.as_slice()).is_err()); | ||
} |
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,13 @@ | ||
use std::str; | ||
|
||
use ain_evm::Result; | ||
use ain_macros::ffi_fallible; | ||
|
||
use crate::{ffi, prelude::*}; | ||
|
||
/// Validates a slice of bytes is valid UTF-8 and converts the bytes to a rust string slice. | ||
#[ffi_fallible] | ||
pub fn rs_try_from_utf8(string: &'static [u8]) -> Result<String> { | ||
let string = str::from_utf8(string).map_err(|_| "Error interpreting bytes, invalid UTF-8")?; | ||
Ok(string.to_string()) | ||
} |
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
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
Oops, something went wrong.