@@ -197,99 +197,58 @@ fn bump_nonce_to_one(mut account: Account) -> anyhow::Result<Account> {
197197
198198#[ cfg( test) ]
199199mod tests {
200- use miden_protocol:: ZERO ;
200+ use miden_node_store:: genesis:: config:: GenesisConfig ;
201+ use miden_protocol:: crypto:: dsa:: ecdsa_k256_keccak:: SecretKey ;
201202 use miden_protocol:: utils:: Serializable ;
202203
203204 use super :: * ;
204205
205- #[ test]
206- fn default_mode_generates_accounts_with_secret_keys ( ) {
207- let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
206+ /// Parses the generated genesis.toml, builds a genesis block, and asserts the bridge account
207+ /// is included with nonce=1.
208+ async fn assert_valid_genesis_block ( dir : & Path ) {
209+ let bridge_id = AccountFile :: read ( dir. join ( "bridge.mac" ) ) . unwrap ( ) . account . id ( ) ;
210+
211+ let config = GenesisConfig :: read_toml_file ( & dir. join ( "genesis.toml" ) ) . unwrap ( ) ;
212+ let signer = SecretKey :: read_from_bytes ( & [ 0x01 ; 32 ] ) . unwrap ( ) ;
213+ let ( state, _) = config. into_state ( signer) . unwrap ( ) ;
208214
209- run ( dir. path ( ) , None , None ) . expect ( "run should succeed" ) ;
215+ let bridge = state. accounts . iter ( ) . find ( |a| a. id ( ) == bridge_id) . unwrap ( ) ;
216+ assert_eq ! ( bridge. nonce( ) , ONE ) ;
210217
211- // All 4 files should exist.
212- assert ! ( dir. path( ) . join( "bridge_admin.mac" ) . exists( ) ) ;
213- assert ! ( dir. path( ) . join( "ger_manager.mac" ) . exists( ) ) ;
214- assert ! ( dir. path( ) . join( "bridge.mac" ) . exists( ) ) ;
215- assert ! ( dir. path( ) . join( "genesis.toml" ) . exists( ) ) ;
218+ state. into_block ( ) . await . expect ( "genesis block should build" ) ;
219+ }
216220
217- // Bridge account should have nonce=1 (genesis account).
218- let bridge = AccountFile :: read ( dir . path ( ) . join ( "bridge.mac" ) ) . unwrap ( ) ;
219- assert_eq ! ( bridge . account . nonce ( ) , ONE ) ;
220- assert ! ( bridge . auth_secret_keys . is_empty ( ) , "bridge should have no secret keys" ) ;
221+ # [ tokio :: test ]
222+ async fn default_mode_includes_secret_keys ( ) {
223+ let dir = tempfile :: tempdir ( ) . unwrap ( ) ;
224+ run ( dir . path ( ) , None , None ) . unwrap ( ) ;
221225
222- // Bridge admin should have nonce=0 and include a secret key.
223226 let admin = AccountFile :: read ( dir. path ( ) . join ( "bridge_admin.mac" ) ) . unwrap ( ) ;
224- assert_eq ! ( admin. account. nonce( ) , ZERO ) ;
225- assert_eq ! ( admin. auth_secret_keys. len( ) , 1 , "bridge admin should have a secret key" ) ;
227+ assert_eq ! ( admin. auth_secret_keys. len( ) , 1 ) ;
226228
227- // GER manager should have nonce=0 and include a secret key.
228229 let ger = AccountFile :: read ( dir. path ( ) . join ( "ger_manager.mac" ) ) . unwrap ( ) ;
229- assert_eq ! ( ger. account. nonce( ) , ZERO ) ;
230- assert_eq ! ( ger. auth_secret_keys. len( ) , 1 , "GER manager should have a secret key" ) ;
230+ assert_eq ! ( ger. auth_secret_keys. len( ) , 1 ) ;
231+
232+ assert_valid_genesis_block ( dir. path ( ) ) . await ;
231233 }
232234
233- #[ test]
234- fn custom_public_keys_generates_accounts_without_secret_keys ( ) {
235+ #[ tokio :: test]
236+ async fn custom_public_keys_excludes_secret_keys ( ) {
235237 let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
236238
237- // Generate two keypairs and pass their public keys as hex.
238239 let ( admin_pub, _) = generate_falcon_keypair ( ) ;
239240 let ( ger_pub, _) = generate_falcon_keypair ( ) ;
240241 let admin_hex = hex:: encode ( ( & admin_pub) . to_bytes ( ) ) ;
241242 let ger_hex = hex:: encode ( ( & ger_pub) . to_bytes ( ) ) ;
242243
243- run ( dir. path ( ) , Some ( & admin_hex) , Some ( & ger_hex) ) . expect ( "run should succeed" ) ;
244+ run ( dir. path ( ) , Some ( & admin_hex) , Some ( & ger_hex) ) . unwrap ( ) ;
244245
245- // Bridge admin and GER manager should have no secret keys when public keys are provided.
246246 let admin = AccountFile :: read ( dir. path ( ) . join ( "bridge_admin.mac" ) ) . unwrap ( ) ;
247- assert ! (
248- admin. auth_secret_keys. is_empty( ) ,
249- "bridge admin should have no secret keys in custom mode"
250- ) ;
247+ assert ! ( admin. auth_secret_keys. is_empty( ) ) ;
251248
252249 let ger = AccountFile :: read ( dir. path ( ) . join ( "ger_manager.mac" ) ) . unwrap ( ) ;
253- assert ! (
254- ger. auth_secret_keys. is_empty( ) ,
255- "GER manager should have no secret keys in custom mode"
256- ) ;
257-
258- // Bridge should still have nonce=1.
259- let bridge = AccountFile :: read ( dir. path ( ) . join ( "bridge.mac" ) ) . unwrap ( ) ;
260- assert_eq ! ( bridge. account. nonce( ) , ONE ) ;
261- }
262-
263- #[ tokio:: test]
264- async fn genesis_config_produces_valid_genesis_block ( ) {
265- use miden_node_store:: genesis:: config:: GenesisConfig ;
266- use miden_protocol:: crypto:: dsa:: ecdsa_k256_keccak:: SecretKey ;
267-
268- let dir = tempfile:: tempdir ( ) . unwrap ( ) ;
269- run ( dir. path ( ) , None , None ) . expect ( "run should succeed" ) ;
270-
271- // Read the bridge account to know its expected ID.
272- let bridge_file = AccountFile :: read ( dir. path ( ) . join ( "bridge.mac" ) ) . unwrap ( ) ;
273- let expected_bridge_id = bridge_file. account . id ( ) ;
250+ assert ! ( ger. auth_secret_keys. is_empty( ) ) ;
274251
275- // Parse the generated genesis.toml.
276- let config = GenesisConfig :: read_toml_file ( & dir. path ( ) . join ( "genesis.toml" ) )
277- . expect ( "genesis.toml should be parseable" ) ;
278-
279- // Build the genesis state and block.
280- let signer = SecretKey :: read_from_bytes ( & [ 0x01 ; 32 ] ) . unwrap ( ) ;
281- let ( state, _secrets) = config. into_state ( signer) . expect ( "genesis state should build" ) ;
282-
283- // The genesis state should contain the bridge account (+ the default MIDEN faucet).
284- let bridge_in_genesis = state
285- . accounts
286- . iter ( )
287- . find ( |a| a. id ( ) == expected_bridge_id)
288- . expect ( "bridge account should be in genesis state" ) ;
289- assert_eq ! ( bridge_in_genesis. nonce( ) , ONE ) ;
290-
291- // Build the actual genesis block to verify it's valid.
292- let block = state. into_block ( ) . await . expect ( "genesis block should build successfully" ) ;
293- assert_eq ! ( block. inner( ) . header( ) . block_num( ) , miden_protocol:: block:: BlockNumber :: GENESIS ) ;
252+ assert_valid_genesis_block ( dir. path ( ) ) . await ;
294253 }
295254}
0 commit comments