kona_genesis/superchain/
chains.rs

1//! Contains the `Superchains` type.
2
3use alloc::vec::Vec;
4
5use crate::Superchain;
6
7/// A list of Hydrated Superchain Configs.
8#[derive(Debug, Clone, Default, Eq, PartialEq)]
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
11#[cfg_attr(feature = "serde", serde(deny_unknown_fields))]
12pub struct Superchains {
13    /// A list of superchain configs.
14    pub superchains: Vec<Superchain>,
15}
16
17#[cfg(test)]
18#[cfg(feature = "serde")]
19mod tests {
20    use super::*;
21    use crate::{HardForkConfig, SuperchainConfig, SuperchainL1Info};
22    use alloc::{string::ToString, vec};
23
24    #[test]
25    fn test_deny_unknown_fields_superchains() {
26        let raw: &str = r#"
27        {
28            "superchains": [
29                {
30                    "name": "Mainnet",
31                    "config": {
32                        "name": "Mainnet",
33                        "l1": {
34                            "chainId": 10,
35                            "publicRPC": "https://mainnet.rpc",
36                            "explorer": "https://mainnet.explorer"
37                        },
38                        "hardforks": {
39                            "canyon_time": 1699981200,
40                            "delta_time": 1703203200,
41                            "ecotone_time": 1708534800,
42                            "fjord_time": 1716998400,
43                            "granite_time": 1723478400,
44                            "holocene_time": 1732633200
45                        }
46                    },
47                    "chains": []
48                }
49            ],
50            "unknown_field": "unknown"
51        }
52        "#;
53
54        let err = serde_json::from_str::<Superchains>(raw).unwrap_err();
55        assert_eq!(err.classify(), serde_json::error::Category::Data);
56    }
57
58    #[test]
59    fn test_superchains_serde() {
60        let raw: &str = r#"
61        {
62            "superchains": [
63                {
64                    "name": "Mainnet",
65                    "config": {
66                        "name": "Mainnet",
67                        "l1": {
68                            "chainId": 10,
69                            "publicRPC": "https://mainnet.rpc",
70                            "explorer": "https://mainnet.explorer"
71                        },
72                        "hardforks": {
73                            "canyon_time": 1699981200,
74                            "delta_time": 1703203200,
75                            "ecotone_time": 1708534800,
76                            "fjord_time": 1716998400,
77                            "granite_time": 1723478400,
78                            "holocene_time": 1732633200
79                        }
80                    },
81                    "chains": []
82                }
83            ]
84        }
85        "#;
86
87        let superchains = Superchains {
88            superchains: vec![Superchain {
89                name: "Mainnet".to_string(),
90                config: SuperchainConfig {
91                    name: "Mainnet".to_string(),
92                    l1: SuperchainL1Info {
93                        chain_id: 10,
94                        public_rpc: "https://mainnet.rpc".to_string(),
95                        explorer: "https://mainnet.explorer".to_string(),
96                    },
97                    hardforks: HardForkConfig {
98                        regolith_time: None,
99                        canyon_time: Some(1699981200),
100                        delta_time: Some(1703203200),
101                        ecotone_time: Some(1708534800),
102                        fjord_time: Some(1716998400),
103                        granite_time: Some(1723478400),
104                        holocene_time: Some(1732633200),
105                        pectra_blob_schedule_time: None,
106                        isthmus_time: None,
107                        interop_time: None,
108                    },
109                    protocol_versions_addr: None,
110                    superchain_config_addr: None,
111                    op_contracts_manager_proxy_addr: None,
112                },
113                chains: vec![],
114            }],
115        };
116
117        let deserialized: Superchains = serde_json::from_str(raw).unwrap();
118        assert_eq!(deserialized, superchains);
119    }
120}