forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add utils to generate instruction_data based on name
Towards #55
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "input_json" | ||
version = "1.0.0" | ||
edition = "2021" | ||
|
||
[[bin]] | ||
name = "generate_input_json" | ||
path = "src/generate_input_json.rs" | ||
|
||
[dependencies] | ||
binascii = "0.1" |
36 changes: 36 additions & 0 deletions
36
external-crates/move/solana/util/src/generate_input_json.rs
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,36 @@ | ||
#[test] | ||
use binascii::{b32encode, b32decode}; | ||
|
||
fn print_as_bytes(data : &str) -> Vec<u8> { | ||
let length = data.len(); | ||
let input = &data[..length].as_bytes(); | ||
input.to_vec() | ||
} | ||
|
||
#[test] | ||
fn test_encode_decode() { | ||
let data : &str = "counter__owner"; | ||
let input = &data[..data.len()].as_bytes(); | ||
let mut output = [0u8; 500]; | ||
let mut dec_out = [0u8; 200]; | ||
let encoded_output = b32encode(&input, &mut output).ok().unwrap(); | ||
let decoded_output = b32decode(&encoded_output, &mut dec_out).ok().unwrap(); | ||
assert_eq!(input, &decoded_output); | ||
} | ||
|
||
#[test] | ||
fn test_print_as_bytes() { | ||
const ENCODED_DATA : [u8; 11] = [104, 101, 108, 108, 111, 95, 95, 109, 97, 105, 110]; | ||
let b = print_as_bytes("hello__main"); | ||
assert_eq!(b.len(), ENCODED_DATA.len()); | ||
assert_eq!(&ENCODED_DATA, &b[..ENCODED_DATA.len()]); | ||
} | ||
|
||
pub fn main() { | ||
let mut b = print_as_bytes("counter__owner"); | ||
let mut blen = b.len().to_le_bytes().to_vec(); | ||
println!("As bytes: {:?}", b.clone()); | ||
println!("len: {:?}", blen.clone()); | ||
blen.append(&mut b); | ||
println!("\"instruction_data\": {:?}", blen); | ||
} |