Skip to content

Commit

Permalink
fix HashValue json break change and test_handshake_message
Browse files Browse the repository at this point in the history
  • Loading branch information
nkysg committed Nov 22, 2024
1 parent 2e05b2b commit 1611db2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ starcoin-chain-service = { path = "chain/service" }
starcoin-cmd = { path = "cmd/starcoin" }
starcoin-config = { path = "config" }
starcoin-consensus = { path = "consensus" }
starcoin-crypto = { git = "https://github.com/starcoinorg/starcoin-crypto", rev = "69ccde1e1ec331588a93346729475d499d52959a" }
starcoin-crypto = { git = "https://github.com/starcoinorg/starcoin-crypto", rev = "a14be64c9cd5889389730c76f00a7f82ad5c99cf" }

starcoin-decrypt = { path = "commons/decrypt" }
starcoin-dev = { path = "vm/dev" }
Expand Down
6 changes: 3 additions & 3 deletions network-p2p/src/service_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,10 @@ fn test_handshake_message() -> Result<()> {
let json_msg = serde_json::to_string(&status).unwrap();
let status1 = serde_json::from_str::<Status>(&json_msg).unwrap();
assert_eq!(status, status1);
// let hex = hex::encode(status.encode().unwrap());
//println!("{}", hex);
// let hex = hex::encode(status.encode().unwrap());
// println!("{}", hex);
//println!("{}", serde_json::to_string(&status).unwrap());
let bin_msg = "0100000001000000020f2f73746172636f696e2f74786e2f31112f73746172636f696e2f626c6f636b2f3100ff20509224b8142926f6c079c66a85ca6db7981734bfe8f9427b3b925574be013f9320509224b8142926f6c079c66a85ca6db7981734bfe8f9427b3b925574be013f93c337446077010000fd23000000000000e6f6e9ec5a878e29350b4356e21d63db0020a57516ba50672afe23869529b2d54b9cb95bf6c2ad0982048c5dc1633e567f5620163305561261490852c28f3c1131e4e8d181bea0e1c8552f1ff9f8fbdd10772720cead8e63f08b297df0e6c0e80a15f824d1a6f08ecb6f88021d6f3dc6c31544af0000fa000000000000000000000000000000000000000000000000000000000000000000000016482019990c2875098a829ac4d6db2c78b77e6102d0837920304a14ebb474190a5007ff50a4f7240000000001012082b85e25967cd4077f4df26a8975ab34ec6eba954e2c38d2b8393c6c42c2963c20a97a39d3aa469d73d24f92dc17e190cf9bebd0c158b671eb4246bed87f5a82f2000000000000000000000000000000000000000000000000000000000356fcbd20a57516ba50672afe23869529b2d54b9cb95bf6c2ad0982048c5dc1633e567f560c20ed2a8ca4a2972761099903410a9dc0c4607eaec944c41d919c27c57418d2aa592021ee454f8510f89866eae45cd5727bee271595e67740ef5aaf80f9fc9d3b84d320527890d7a348f2bfe9801eaad4d98facd340489a37234f405c15ab4e64a0f2eb20d0dacaa8beb77998983313ce06b44385b88c1772992f42a835b2f8477118321b2031b0df1da737424b169c3a43c0bc23794cc65d65d352aeff8a50b0593320a0cb2017dcc4f902c5e237a2c2a3b47b9263b7e67512c026ff76981e9c88955135cd86200686841f7caeb4cd82eb1d51575971c7b189609a87c63970447c45b10361908620abfa4a9ed920176ad2a789d731f26398768732f813351e43a38d4c1aa22ff259206914b1dd9aac5d4721fdb7bd736b1f107e72253050b4effd4bd9952da32eef84202b0be3dc9f9196c5f8b5b9c430083d682720651154b29d1778971273eb9dfbcf20566f2db25b5255647988d164c4e2855b689fe5dcf7b1ba37bfa6a3d86accc50320e5b5f78b0b2e08fc3e3cafa9808346704da2f7b7a572dd84ed947e00003266c4f0ef010000000000d4df03000000000020163305561261490852c28f3c1131e4e8d181bea0e1c8552f1ff9f8fbdd1077270a20ef637a9b977e8969503e4fedb8558b0f294268bbaa6a0b24a824ad3c98edcf1e20a8cf073cfe1b08a5ed94a04dc79f16d125b7d4fb4d7ce02f75f412ded9cf9b7920f89ff07faba4299566955c4b9c31fcba99fc5855a229bed7d6487dafd59f1e70202fd161c1b5d03833eb3efb09e530e689ac67ec7d5748246df4891bb9c3f3111b2055e40a53390e839a588904e16fe656676b0c5a7b3ec70bd8dcc2276e70e7600b20b3918be1fd6460dd30daf058e0e516c7046d242642130547f510335a319a98dd20f0737bc518a99c1a619bd87ba82d95dcd8dd19b0836a7dbed514b603f90e7ea820f48e3dfc240d86a64e9adb9c2d276c6f42119e4aaee7598b13f61e4d77390d112062cb92b81afa80226494d92a2120bdd4e9956c48f44f41b1283a59d9fe32e6df20eb5618d7d5699735477bee792b0e1a1ffa3c892fa31b7515b6948d80e3b424b2fe23000000000000f247000000000000";
let bin_msg = "0100000001000000020f2f73746172636f696e2f74786e2f31112f73746172636f696e2f626c6f636b2f3100ff20509224b8142926f6c079c66a85ca6db7981734bfe8f9427b3b925574be013f9320509224b8142926f6c079c66a85ca6db7981734bfe8f9427b3b925574be013f93c337446077010000fd23000000000000e6f6e9ec5a878e29350b4356e21d63db20a57516ba50672afe23869529b2d54b9cb95bf6c2ad0982048c5dc1633e567f5620163305561261490852c28f3c1131e4e8d181bea0e1c8552f1ff9f8fbdd10772720cead8e63f08b297df0e6c0e80a15f824d1a6f08ecb6f88021d6f3dc6c31544af0000fa000000000000000000000000000000000000000000000000000000000000000000000016482019990c2875098a829ac4d6db2c78b77e6102d0837920304a14ebb474190a5007ff50a4f7240000000001012082b85e25967cd4077f4df26a8975ab34ec6eba954e2c38d2b8393c6c42c2963c202de438b469ca2fc52e2a31535163e1e6a9fa362066e38d0f9531351d59595846000000000000000000000000000000000000000000000000000000000356fcbd20a57516ba50672afe23869529b2d54b9cb95bf6c2ad0982048c5dc1633e567f560c20ed2a8ca4a2972761099903410a9dc0c4607eaec944c41d919c27c57418d2aa592021ee454f8510f89866eae45cd5727bee271595e67740ef5aaf80f9fc9d3b84d320527890d7a348f2bfe9801eaad4d98facd340489a37234f405c15ab4e64a0f2eb20d0dacaa8beb77998983313ce06b44385b88c1772992f42a835b2f8477118321b2031b0df1da737424b169c3a43c0bc23794cc65d65d352aeff8a50b0593320a0cb2017dcc4f902c5e237a2c2a3b47b9263b7e67512c026ff76981e9c88955135cd86200686841f7caeb4cd82eb1d51575971c7b189609a87c63970447c45b10361908620abfa4a9ed920176ad2a789d731f26398768732f813351e43a38d4c1aa22ff259206914b1dd9aac5d4721fdb7bd736b1f107e72253050b4effd4bd9952da32eef84202b0be3dc9f9196c5f8b5b9c430083d682720651154b29d1778971273eb9dfbcf20566f2db25b5255647988d164c4e2855b689fe5dcf7b1ba37bfa6a3d86accc50320e5b5f78b0b2e08fc3e3cafa9808346704da2f7b7a572dd84ed947e00003266c4f0ef010000000000d4df03000000000020163305561261490852c28f3c1131e4e8d181bea0e1c8552f1ff9f8fbdd1077270a20ef637a9b977e8969503e4fedb8558b0f294268bbaa6a0b24a824ad3c98edcf1e20a8cf073cfe1b08a5ed94a04dc79f16d125b7d4fb4d7ce02f75f412ded9cf9b7920f89ff07faba4299566955c4b9c31fcba99fc5855a229bed7d6487dafd59f1e70202fd161c1b5d03833eb3efb09e530e689ac67ec7d5748246df4891bb9c3f3111b2055e40a53390e839a588904e16fe656676b0c5a7b3ec70bd8dcc2276e70e7600b20b3918be1fd6460dd30daf058e0e516c7046d242642130547f510335a319a98dd20f0737bc518a99c1a619bd87ba82d95dcd8dd19b0836a7dbed514b603f90e7ea820f48e3dfc240d86a64e9adb9c2d276c6f42119e4aaee7598b13f61e4d77390d112062cb92b81afa80226494d92a2120bdd4e9956c48f44f41b1283a59d9fe32e6df20eb5618d7d5699735477bee792b0e1a1ffa3c892fa31b7515b6948d80e3b424b2fe23000000000000f247000000000000";
let bytes = hex::decode(bin_msg).unwrap();
let status2 = Status::decode(bytes.as_slice()).unwrap();
assert_eq!(status, status2);
Expand Down
13 changes: 13 additions & 0 deletions vm/types/src/on_chain_resource/block_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,17 @@ mod tests {
let hash1 = bcs::from_bytes::<HashValue>(&bytes).unwrap();
assert_eq!(hash1, hash);
}

#[test]
fn test_hash_value_serialize() {
let hash = HashValue::random();
let json_value = serde_json::to_string(&hash).unwrap();
println!("{}", json_value);
assert_eq!(json_value, format!("\"{}\"", hash.to_string()));

Check warning on line 62 in vm/types/src/on_chain_resource/block_metadata.rs

View workflow job for this annotation

GitHub Actions / build and test

`to_string` applied to a type that implements `Display` in `assert_eq!` args

let de_hash = serde_json::from_slice::<HashValue>(json_value.as_bytes()).unwrap();
let de_hash2: HashValue = serde_json::from_str::<HashValue>(&json_value).unwrap();
assert_eq!(hash, de_hash);
assert_eq!(hash, de_hash2);
}
}

0 comments on commit 1611db2

Please sign in to comment.