@@ -471,3 +471,149 @@ impl Drop for FlushJsonBlockCacheDB {
471471 trace ! ( target: "fork::cache" , "flushed cache" ) ;
472472 }
473473}
474+
475+ #[ cfg( test) ]
476+ mod tests {
477+ use super :: * ;
478+
479+ #[ test]
480+ fn can_deserialize_cache ( ) {
481+ let s = r#"{
482+ "meta": {
483+ "cfg_env": {
484+ "chain_id": 1337,
485+ "perf_analyse_created_bytecodes": "Analyse",
486+ "limit_contract_code_size": 18446744073709551615,
487+ "memory_limit": 4294967295,
488+ "disable_block_gas_limit": false,
489+ "disable_eip3607": false,
490+ "disable_base_fee": false
491+ },
492+ "block_env": {
493+ "number": "0xed3ddf",
494+ "coinbase": "0x0000000000000000000000000000000000000000",
495+ "timestamp": "0x6324bc3f",
496+ "difficulty": "0x0",
497+ "basefee": "0x2e5fda223",
498+ "gas_limit": "0x1c9c380",
499+ "prevrandao": "0x0000000000000000000000000000000000000000000000000000000000000000"
500+ },
501+ "hosts": [
502+ "eth-mainnet.alchemyapi.io"
503+ ]
504+ },
505+ "accounts": {
506+ "0xb8ffc3cd6e7cf5a098a1c92f48009765b24088dc": {
507+ "balance": "0x0",
508+ "nonce": 10,
509+ "code_hash": "0x3ac64c95eedf82e5d821696a12daac0e1b22c8ee18a9fd688b00cfaf14550aad",
510+ "code": {
511+ "LegacyAnalyzed": {
512+ "bytecode": "0x00",
513+ "original_len": 0,
514+ "jump_table": {
515+ "order": "bitvec::order::Lsb0",
516+ "head": {
517+ "width": 8,
518+ "index": 0
519+ },
520+ "bits": 1,
521+ "data": [0]
522+ }
523+ }
524+ }
525+ }
526+ },
527+ "storage": {
528+ "0xa354f35829ae975e850e23e9615b11da1b3dc4de": {
529+ "0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e564": "0x5553444320795661756c74000000000000000000000000000000000000000000",
530+ "0x10": "0x37fd60ff8346",
531+ "0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563": "0xb",
532+ "0x6": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
533+ "0x5": "0x36ff5b93162e",
534+ "0x14": "0x29d635a8e000",
535+ "0x11": "0x63224c73",
536+ "0x2": "0x6"
537+ }
538+ },
539+ "block_hashes": {
540+ "0xed3deb": "0xbf7be3174b261ea3c377b6aba4a1e05d5fae7eee7aab5691087c20cf353e9877",
541+ "0xed3de9": "0xba1c3648e0aee193e7d00dffe4e9a5e420016b4880455641085a4731c1d32eef",
542+ "0xed3de8": "0x61d1491c03a9295fb13395cca18b17b4fa5c64c6b8e56ee9cc0a70c3f6cf9855",
543+ "0xed3de7": "0xb54560b5baeccd18350d56a3bee4035432294dc9d2b7e02f157813e1dee3a0be",
544+ "0xed3dea": "0x816f124480b9661e1631c6ec9ee39350bda79f0cbfc911f925838d88e3d02e4b"
545+ }
546+ }"# ;
547+
548+ let cache: JsonBlockCacheData = serde_json:: from_str ( s) . unwrap ( ) ;
549+ assert_eq ! ( cache. data. accounts. read( ) . len( ) , 1 ) ;
550+ assert_eq ! ( cache. data. storage. read( ) . len( ) , 1 ) ;
551+ assert_eq ! ( cache. data. block_hashes. read( ) . len( ) , 5 ) ;
552+
553+ let _s = serde_json:: to_string ( & cache) . unwrap ( ) ;
554+ }
555+
556+ #[ test]
557+ fn can_deserialize_cache_post_4844 ( ) {
558+ let s = r#"{
559+ "meta": {
560+ "cfg_env": {
561+ "chain_id": 1,
562+ "kzg_settings": "Default",
563+ "perf_analyse_created_bytecodes": "Analyse",
564+ "limit_contract_code_size": 18446744073709551615,
565+ "memory_limit": 134217728,
566+ "disable_block_gas_limit": false,
567+ "disable_eip3607": true,
568+ "disable_base_fee": false,
569+ "optimism": false
570+ },
571+ "block_env": {
572+ "number": "0x11c99bc",
573+ "coinbase": "0x4838b106fce9647bdf1e7877bf73ce8b0bad5f97",
574+ "timestamp": "0x65627003",
575+ "gas_limit": "0x1c9c380",
576+ "basefee": "0x64288ff1f",
577+ "difficulty": "0xc6b1a299886016dea3865689f8393b9bf4d8f4fe8c0ad25f0058b3569297c057",
578+ "prevrandao": "0xc6b1a299886016dea3865689f8393b9bf4d8f4fe8c0ad25f0058b3569297c057",
579+ "blob_excess_gas_and_price": {
580+ "excess_blob_gas": 0,
581+ "blob_gasprice": 1
582+ }
583+ },
584+ "hosts": [
585+ "eth-mainnet.alchemyapi.io"
586+ ]
587+ },
588+ "accounts": {
589+ "0x4838b106fce9647bdf1e7877bf73ce8b0bad5f97": {
590+ "balance": "0x8e0c373cfcdfd0eb",
591+ "nonce": 128912,
592+ "code_hash": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
593+ "code": {
594+ "LegacyAnalyzed": {
595+ "bytecode": "0x00",
596+ "original_len": 0,
597+ "jump_table": {
598+ "order": "bitvec::order::Lsb0",
599+ "head": {
600+ "width": 8,
601+ "index": 0
602+ },
603+ "bits": 1,
604+ "data": [0]
605+ }
606+ }
607+ }
608+ }
609+ },
610+ "storage": {},
611+ "block_hashes": {}
612+ }"# ;
613+
614+ let cache: JsonBlockCacheData = serde_json:: from_str ( s) . unwrap ( ) ;
615+ assert_eq ! ( cache. data. accounts. read( ) . len( ) , 1 ) ;
616+
617+ let _s = serde_json:: to_string ( & cache) . unwrap ( ) ;
618+ }
619+ }
0 commit comments