From 233e8f6f668169c37545526c1fdd36644373a707 Mon Sep 17 00:00:00 2001 From: tesseract <146037313+DoTheBestToGetTheBest@users.noreply.github.com> Date: Wed, 14 Feb 2024 13:25:51 -0800 Subject: [PATCH] Update state.rs --- crates/rpc-types/src/eth/state.rs | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/crates/rpc-types/src/eth/state.rs b/crates/rpc-types/src/eth/state.rs index dc93393229b..5b818b03ba2 100644 --- a/crates/rpc-types/src/eth/state.rs +++ b/crates/rpc-types/src/eth/state.rs @@ -36,6 +36,44 @@ mod tests { use super::*; use alloy_primitives::address; + #[test] + #[should_panic(expected = "invalid type")] + fn test_invalid_json_structure() { + let invalid_json = r#"{ + "0x1234567890123456789012345678901234567890": { + "balance": true + } + }"#; + + let _: StateOverride = serde_json::from_str(invalid_json).unwrap(); + } + + #[test] + fn test_large_values_in_override() { + let large_values_json = r#"{ + "0x1234567890123456789012345678901234567890": { + "balance": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "nonce": "0xffffffffffffffff" + } + }"#; + + let state_override: StateOverride = serde_json::from_str(large_values_json).unwrap(); + let acc = + state_override.get(&address!("1234567890123456789012345678901234567890")).unwrap(); + assert_eq!(acc.balance, Some(U256::MAX)); + assert_eq!(acc.nonce, Some(U64::MAX)); + } + + #[test] + fn test_default_account_override() { + let acc_override = AccountOverride::default(); + assert!(acc_override.balance.is_none()); + assert!(acc_override.nonce.is_none()); + assert!(acc_override.code.is_none()); + assert!(acc_override.state.is_none()); + assert!(acc_override.state_diff.is_none()); + } + #[test] fn test_state_override() { let s = r#"{