@@ -23,18 +23,15 @@ pub struct Superchain {
23
23
#[ derive( Debug , Clone , Default , Hash , Eq , PartialEq ) ]
24
24
#[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
25
25
#[ cfg_attr( any( test, feature = "arbitrary" ) , derive( arbitrary:: Arbitrary ) ) ]
26
+ #[ cfg_attr( feature = "serde" , serde( rename_all = "PascalCase" ) ) ]
26
27
pub struct SuperchainConfig {
27
28
/// Superchain name (e.g. "Mainnet")
28
- #[ cfg_attr( feature = "serde" , serde( rename = "Name" ) ) ]
29
29
pub name : String ,
30
30
/// Superchain L1 anchor information
31
- #[ cfg_attr( feature = "serde" , serde( rename = "L1" ) ) ]
32
31
pub l1 : SuperchainL1Info ,
33
32
/// Optional addresses for the superchain-wide default protocol versions contract.
34
- #[ cfg_attr( feature = "serde" , serde( rename = "ProtocolVersionsAddr" ) ) ]
35
33
pub protocol_versions_addr : Option < Address > ,
36
34
/// Optional address for the superchain-wide default superchain config contract.
37
- #[ cfg_attr( feature = "serde" , serde( rename = "SuperchainConfigAddr" ) ) ]
38
35
pub superchain_config_addr : Option < Address > ,
39
36
/// Hardfork Configuration. These values may be overridden by individual chains.
40
37
#[ cfg_attr( feature = "serde" , serde( flatten) ) ]
@@ -45,6 +42,7 @@ pub struct SuperchainConfig {
45
42
#[ derive( Debug , Clone , Default , Hash , Eq , PartialEq ) ]
46
43
#[ cfg_attr( feature = "serde" , derive( serde:: Serialize , serde:: Deserialize ) ) ]
47
44
#[ cfg_attr( any( test, feature = "arbitrary" ) , derive( arbitrary:: Arbitrary ) ) ]
45
+ #[ cfg_attr( feature = "serde" , serde( rename_all = "PascalCase" ) ) ]
48
46
pub struct SuperchainL1Info {
49
47
/// L1 chain ID
50
48
#[ cfg_attr( feature = "serde" , serde( rename = "ChainID" ) ) ]
@@ -53,7 +51,6 @@ pub struct SuperchainL1Info {
53
51
#[ cfg_attr( feature = "serde" , serde( rename = "PublicRPC" ) ) ]
54
52
pub public_rpc : String ,
55
53
/// L1 chain explorer RPC endpoint
56
- #[ cfg_attr( feature = "serde" , serde( rename = "Explorer" ) ) ]
57
54
pub explorer : String ,
58
55
}
59
56
@@ -74,3 +71,79 @@ pub enum SuperchainLevel {
74
71
#[ default]
75
72
Standard = 1 ,
76
73
}
74
+
75
+ #[ cfg( test) ]
76
+ mod tests {
77
+ use super :: * ;
78
+ use alloy_primitives:: address;
79
+
80
+ fn ref_config ( ) -> SuperchainConfig {
81
+ SuperchainConfig {
82
+ name : "Mainnet" . to_string ( ) ,
83
+ l1 : SuperchainL1Info {
84
+ chain_id : 1 ,
85
+ public_rpc : "https://ethereum-rpc.publicnode.com" . to_string ( ) ,
86
+ explorer : "https://etherscan.io" . to_string ( ) ,
87
+ } ,
88
+ protocol_versions_addr : Some ( address ! ( "8062AbC286f5e7D9428a0Ccb9AbD71e50d93b935" ) ) ,
89
+ superchain_config_addr : Some ( address ! ( "95703e0982140D16f8ebA6d158FccEde42f04a4C" ) ) ,
90
+ hardfork_defaults : HardForkConfiguration :: default ( ) ,
91
+ }
92
+ }
93
+
94
+ #[ test]
95
+ fn test_superchain_l1_info_serde ( ) {
96
+ let l1_str = r#"{
97
+ "ChainID": 1,
98
+ "PublicRPC": "https://ethereum-rpc.publicnode.com",
99
+ "Explorer": "https://etherscan.io"
100
+ }"# ;
101
+ let l1: SuperchainL1Info = serde_json:: from_str ( l1_str) . unwrap ( ) ;
102
+ assert_eq ! (
103
+ l1,
104
+ SuperchainL1Info {
105
+ chain_id: 1 ,
106
+ public_rpc: "https://ethereum-rpc.publicnode.com" . to_string( ) ,
107
+ explorer: "https://etherscan.io" . to_string( ) ,
108
+ }
109
+ ) ;
110
+ }
111
+
112
+ #[ test]
113
+ fn test_superchain_config_serde ( ) {
114
+ let cfg_str = r#"{
115
+ "Name": "Mainnet",
116
+ "L1": {
117
+ "ChainID": 1,
118
+ "PublicRPC": "https://ethereum-rpc.publicnode.com",
119
+ "Explorer": "https://etherscan.io"
120
+ },
121
+ "ProtocolVersionsAddr": "0x8062AbC286f5e7D9428a0Ccb9AbD71e50d93b935",
122
+ "SuperchainConfigAddr": "0x95703e0982140D16f8ebA6d158FccEde42f04a4C"
123
+ }"# ;
124
+ let cfg: SuperchainConfig = serde_json:: from_str ( cfg_str) . unwrap ( ) ;
125
+ assert_eq ! ( cfg, ref_config( ) ) ;
126
+ }
127
+
128
+ #[ test]
129
+ fn test_superchain_serde ( ) {
130
+ let superchain_str = r#"{
131
+ "name": "Mainnet",
132
+ "config": {
133
+ "Name": "Mainnet",
134
+ "L1": {
135
+ "ChainID": 1,
136
+ "PublicRPC": "https://ethereum-rpc.publicnode.com",
137
+ "Explorer": "https://etherscan.io"
138
+ },
139
+ "ProtocolVersionsAddr": "0x8062AbC286f5e7D9428a0Ccb9AbD71e50d93b935",
140
+ "SuperchainConfigAddr": "0x95703e0982140D16f8ebA6d158FccEde42f04a4C"
141
+ },
142
+ "chains": []
143
+ }"# ;
144
+ let superchain: Superchain = serde_json:: from_str ( superchain_str) . unwrap ( ) ;
145
+ assert_eq ! ( superchain. name, "Mainnet" ) ;
146
+ assert_eq ! ( superchain. config, ref_config( ) ) ;
147
+ assert ! ( superchain. chains. is_empty( ) ) ;
148
+ }
149
+ }
0 commit comments