Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Hex serde deserialize #1396

Merged
merged 1 commit into from
Sep 4, 2023
Merged

fix: Hex serde deserialize #1396

merged 1 commit into from
Sep 4, 2023

Conversation

yangby-cryptape
Copy link
Collaborator

@yangby-cryptape yangby-cryptape commented Sep 4, 2023

What this PR does / why we need it?

This PR fixes:

running 1 test
test types::primitive::tests::test_hex_serde_deserialize ... FAILED

failures:

failures:
    types::primitive::tests::test_hex_serde_deserialize

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 41 filtered out; finished in 0.00s


--- STDERR:              axon-protocol types::primitive::tests::test_hex_serde_deserialize ---
thread 'types::primitive::tests::test_hex_serde_deserialize' panicked at 'called `Result::unwrap()` on an `Err` value: Error { inner: Error { inner: TomlError { message: "invalid type: string \"0x1234\", expected a borrowed byte array", original: Some("\n            key = \"0x1234\"\n        "), keys: ["key"], span: Some(19..27) } } }', protocol/src/types/primitive.rs:546:58
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

What is the impact of this PR?

No Breaking Change

PR relation:

  • Ref #

Special notes for your reviewer:

Before this PR, the serde_json already works well:

#[test]
fn test_metadata_json_serialize() {
let metadata: Metadata = serde_json::from_slice(
&fs::read("../devtools/genesis-generator/metadata.json").unwrap(),
)
.unwrap();

pub struct Metadata {
pub version: MetadataVersion,
#[cfg_attr(feature = "hex-serialize", serde(serialize_with = "serialize_uint"))]
pub epoch: u64,
pub verifier_list: Vec<ValidatorExtend>,

pub struct ValidatorExtend {
pub bls_pub_key: Hex,
pub pub_key: Hex,

CI Settings

CI Usage

Tip: Check the CI you want to run below, and then comment /run-ci.

CI Switch

  • E2E Tests
  • Web3 Compatible Tests
  • OCT 1-5 And 12-15
  • OCT 6-10
  • OCT 11
  • OCT 16-19
  • v3 Core Tests

CI Description

CI Name Description
Chaos CI Test the liveness and robustness of Axon under terrible network condition
Cargo Clippy Run cargo clippy --all --all-targets --all-features
Coverage Test Get the unit test coverage report
E2E Test Run end-to-end test to check interfaces
Code Format Run cargo +nightly fmt --all -- --check and cargo sort -gwc
Web3 Compatible Test Test the Web3 compatibility of Axon
v3 Core Test Run the compatibility tests provided by Uniswap V3
OCT 1-5 | 6-10 | 11 | 12-15 | 16-19 Run the compatibility tests provided by OpenZeppelin

@yangby-cryptape yangby-cryptape requested a review from a team as a code owner September 4, 2023 07:26
@github-actions github-actions bot added the bugfix label Sep 4, 2023
@yangby-cryptape yangby-cryptape requested review from Flouse, driftluo and KaoImin and removed request for wenyuanhust and Simon-Tl September 4, 2023 07:26
@github-actions
Copy link

github-actions bot commented Sep 4, 2023

The title of this PR does not conform the conventional commits. Please fix it, thx.

@yangby-cryptape yangby-cryptape changed the title fix: Hex serde deserialize fix: Hex serde deserialize Sep 4, 2023
@yangby-cryptape yangby-cryptape changed the title fix: Hex serde deserialize fix: serde deserialize Hex Sep 4, 2023
@yangby-cryptape yangby-cryptape changed the title fix: serde deserialize Hex fix(types): serde deserialize Hex Sep 4, 2023
@yangby-cryptape yangby-cryptape changed the title fix(types): serde deserialize Hex fix: Hex serde deserialize Sep 4, 2023
@yangby-cryptape
Copy link
Collaborator Author

The title of this PR does not conform the conventional commits. Please fix it, thx.

🆘 If anyone know how to pass this check, please fix the PR title, thx.

p.s. Even the CI looks like it is passed, but in the logs of that CI check, you could find that the check is failed.

@blckngm
Copy link
Contributor

blckngm commented Sep 4, 2023

Is this a bug in faster-hex? (It should first de-serialize to String or maybe Cow<str>, not &[u8].)

@yangby-cryptape yangby-cryptape changed the title fix: Hex serde deserialize [HOLD] fix: Hex serde deserialize Sep 4, 2023
@yangby-cryptape
Copy link
Collaborator Author

yangby-cryptape commented Sep 4, 2023

Is this a bug in faster-hex? (It should first de-serialize to String or maybe Cow<str>, not &[u8].)

I checked the following code:

#[serde(transparent)]                                                                                                    
pub struct Hex(#[serde(with = "faster_hex")] Bytes); 

And, it failed, too.

Ref:

I guess:

  • serde_json knows every input fields are strings, it parses every fields from string, no matter with quotes or not.
  • But serde doesn't, it deserialize all basic types directly (eg, u8, bool), no intermediate type (here, it's string).
    • So, you have to tell serde, parse it to a string, before pass to your customized parser.

@yangby-cryptape yangby-cryptape changed the title [HOLD] fix: Hex serde deserialize fix: Hex serde deserialize Sep 4, 2023
@Flouse Flouse requested a review from blckngm September 4, 2023 09:49
@blckngm
Copy link
Contributor

blckngm commented Sep 4, 2023

I guess it's because serde_json supports deserializing borrowed str/[u8], but toml doesn't.

It may fail with serde_json too if there are escapes in the json string.

@KaoImin KaoImin added this pull request to the merge queue Sep 4, 2023
Merged via the queue into main with commit b77f29f Sep 4, 2023
42 of 44 checks passed
@yangby-cryptape yangby-cryptape deleted the yangby/bugfix/hex-deserialize branch September 4, 2023 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants