@@ -152,9 +152,7 @@ impl<N: Network> ToBytes for Block<N> {
152152#[ cfg( test) ]
153153mod tests {
154154 use super :: * ;
155- use console:: network:: MainnetV0 ;
156-
157- type CurrentNetwork = MainnetV0 ;
155+ use console:: network:: { MainnetV0 , TestnetV0 } ;
158156
159157 #[ test]
160158 fn test_bytes ( ) -> Result < ( ) > {
@@ -170,28 +168,58 @@ mod tests {
170168 }
171169
172170 #[ test]
173- fn test_genesis_bytes ( ) -> Result < ( ) > {
171+ fn test_genesis_bytes_mainnet_unchecked ( ) -> Result < ( ) > {
174172 // Load the genesis block.
175- let genesis_block = Block :: < CurrentNetwork > :: read_le ( CurrentNetwork :: genesis_bytes ( ) ) . unwrap ( ) ;
173+ let genesis_block = Block :: < MainnetV0 > :: read_le_unchecked ( MainnetV0 :: genesis_bytes ( ) ) . unwrap ( ) ;
176174
177175 // Check the byte representation.
178176 let expected_bytes = genesis_block. to_bytes_le ( ) ?;
179- assert_eq ! ( genesis_block, Block :: read_le( & expected_bytes[ ..] ) ?) ;
180177 assert_eq ! ( genesis_block, Block :: read_le_unchecked( & expected_bytes[ ..] ) ?) ;
181178
182179 Ok ( ( ) )
183180 }
184181
185182 #[ test]
186- fn test_bincode ( ) -> Result < ( ) > {
183+ fn test_genesis_bytes_testnet_unchecked ( ) -> Result < ( ) > {
187184 // Load the genesis block.
188- let genesis_block = Block :: < CurrentNetwork > :: read_le ( CurrentNetwork :: genesis_bytes ( ) ) . unwrap ( ) ;
185+ let genesis_block = Block :: < TestnetV0 > :: read_le_unchecked ( TestnetV0 :: genesis_bytes ( ) ) . unwrap ( ) ;
189186
190- let bincode_data = bincode:: serialize ( & genesis_block) ?;
191- let block = bincode:: deserialize ( & bincode_data) ?;
187+ // Check the byte representation.
188+ let expected_bytes = genesis_block. to_bytes_le ( ) ?;
189+ assert_eq ! ( genesis_block, Block :: read_le_unchecked( & expected_bytes[ ..] ) ?) ;
192190
193- assert_eq ! ( genesis_block, block) ;
191+ Ok ( ( ) )
192+ }
193+
194+ #[ test]
195+ fn test_genesis_bytes_mainnet ( ) -> Result < ( ) > {
196+ // Load the genesis block.
197+ let genesis_block = Block :: < MainnetV0 > :: read_le ( MainnetV0 :: genesis_bytes ( ) ) . unwrap ( ) ;
198+
199+ // Check the byte representation.
200+ let expected_bytes = genesis_block. to_bytes_le ( ) ?;
201+ assert_eq ! ( genesis_block, Block :: read_le( & expected_bytes[ ..] ) ?) ;
202+ assert_eq ! ( genesis_block, Block :: read_le_unchecked( & expected_bytes[ ..] ) ?) ;
194203
195204 Ok ( ( ) )
196205 }
206+
207+ // When `test_targets` is enabled, the gensis bytes do not match the expected coinbase target.
208+ // (except for Mainnet which ignores this feature)
209+ #[ cfg( not( feature = "test_targets" ) ) ]
210+ mod production {
211+ use super :: * ;
212+ #[ test]
213+ fn test_genesis_bytes_testnet ( ) -> Result < ( ) > {
214+ // Load the genesis block.
215+ let genesis_block = Block :: < TestnetV0 > :: read_le ( TestnetV0 :: genesis_bytes ( ) ) . unwrap ( ) ;
216+
217+ // Check the byte representation.
218+ let expected_bytes = genesis_block. to_bytes_le ( ) ?;
219+ assert_eq ! ( genesis_block, Block :: read_le( & expected_bytes[ ..] ) ?) ;
220+ assert_eq ! ( genesis_block, Block :: read_le_unchecked( & expected_bytes[ ..] ) ?) ;
221+
222+ Ok ( ( ) )
223+ }
224+ }
197225}
0 commit comments