diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 13c69571e59..afb4f53e538 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -644,8 +644,8 @@ mod tests { use super::*; - fn config_factory() -> Result { - let key_pair = KeyPair::generate()?; + fn config_factory() -> ConfigurationProxy { + let key_pair = KeyPair::generate(); let mut base = ConfigurationProxy { chain_id: Some(ChainId::new("0")), @@ -663,7 +663,7 @@ mod tests { torii.p2p_addr = Some(socket_addr!(127.0.0.1:1337)); torii.api_url = Some(socket_addr!(127.0.0.1:1337)); - Ok(base) + base } #[test] @@ -675,7 +675,7 @@ mod tests { .build(); let config = { - let mut cfg = config_factory()?; + let mut cfg = config_factory(); cfg.genesis.as_mut().unwrap().file = Some(Some("./genesis/gen.json".into())); cfg.kura.as_mut().unwrap().block_store_path = Some("../storage".into()); cfg.snapshot.as_mut().unwrap().dir_path = Some("../snapshots".into()); @@ -729,7 +729,7 @@ mod tests { .build(); let config = { - let mut cfg = config_factory()?; + let mut cfg = config_factory(); cfg.genesis.as_mut().unwrap().file = Some(Some("./genesis.json".into())); cfg }; diff --git a/cli/src/samples.rs b/cli/src/samples.rs index 94d2495b884..0a4c13870b2 100644 --- a/cli/src/samples.rs +++ b/cli/src/samples.rs @@ -53,9 +53,7 @@ pub fn get_config_proxy( ) -> ConfigurationProxy { let chain_id = chain_id.unwrap_or_else(|| ChainId::new("0")); - let (public_key, private_key) = key_pair - .unwrap_or_else(|| KeyPair::generate().expect("Key pair generation failed")) - .into(); + let (public_key, private_key) = key_pair.unwrap_or_else(KeyPair::generate).into(); iroha_logger::info!(%public_key); ConfigurationProxy { chain_id: Some(chain_id), diff --git a/client/benches/torii.rs b/client/benches/torii.rs index f8f51917f1d..dd503e3c396 100644 --- a/client/benches/torii.rs +++ b/client/benches/torii.rs @@ -71,9 +71,7 @@ fn query_requests(criterion: &mut Criterion) { let domain_id: DomainId = "domain".parse().expect("Valid"); let create_domain = Register::domain(Domain::new(domain_id.clone())); let account_id = AccountId::new(domain_id.clone(), "account".parse().expect("Valid")); - let (public_key, _) = KeyPair::generate() - .expect("Failed to generate KeyPair") - .into(); + let (public_key, _) = KeyPair::generate().into(); let create_account = Register::account(Account::new(account_id.clone(), [public_key])); let asset_definition_id = AssetDefinitionId::new(domain_id, "xor".parse().expect("Valid")); let create_asset = @@ -169,9 +167,7 @@ fn instruction_submits(criterion: &mut Criterion) { let domain_id: DomainId = "domain".parse().expect("Valid"); let create_domain: InstructionBox = Register::domain(Domain::new(domain_id.clone())).into(); let account_id = AccountId::new(domain_id.clone(), "account".parse().expect("Valid")); - let (public_key, _) = KeyPair::generate() - .expect("Failed to generate Key-pair.") - .into(); + let (public_key, _) = KeyPair::generate().into(); let create_account = Register::account(Account::new(account_id.clone(), [public_key])).into(); let asset_definition_id = AssetDefinitionId::new(domain_id, "xor".parse().expect("Valid")); let mut client_config = diff --git a/client/benches/tps/utils.rs b/client/benches/tps/utils.rs index bbafb4187c5..3901d11b266 100644 --- a/client/benches/tps/utils.rs +++ b/client/benches/tps/utils.rs @@ -153,8 +153,7 @@ impl MeasurerUnit { /// Submit initial transactions for measurement fn ready(self) -> Result { - let keypair = - iroha_client::crypto::KeyPair::generate().expect("Failed to generate KeyPair."); + let keypair = iroha_client::crypto::KeyPair::generate(); let account_id = account_id(self.name); let asset_id = asset_id(self.name); diff --git a/client/examples/tutorial.rs b/client/examples/tutorial.rs index 40c56a1a3aa..b83a2665ae3 100644 --- a/client/examples/tutorial.rs +++ b/client/examples/tutorial.rs @@ -132,9 +132,7 @@ fn account_registration_test(config: &Configuration) -> Result<(), Error> { // TODO: consider getting a key from white_rabbit // Generate a new public key for a new account - let (public_key, _) = KeyPair::generate() - .expect("Failed to generate KeyPair") - .into(); + let (public_key, _) = KeyPair::generate().into(); // #region register_account_generate // Generate a new account diff --git a/client/src/client.rs b/client/src/client.rs index cdc7b4748e8..3dcbbc44635 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -1604,7 +1604,7 @@ mod tests { #[test] fn txs_same_except_for_nonce_have_different_hashes() { - let (public_key, private_key) = KeyPair::generate().unwrap().into(); + let (public_key, private_key) = KeyPair::generate().into(); let cfg = ConfigurationProxy { chain_id: Some(ChainId::new("0")), diff --git a/client/tests/integration/asset.rs b/client/tests/integration/asset.rs index 2758c751962..31d77cc26ae 100644 --- a/client/tests/integration/asset.rs +++ b/client/tests/integration/asset.rs @@ -261,8 +261,8 @@ fn find_rate_and_make_exchange_isi_should_succeed() { let seller_btc: AssetId = "btc#crypto#seller@company".parse().expect("Valid."); let buyer_eth: AssetId = "eth#crypto#buyer@company".parse().expect("Valid."); - let seller_keypair = KeyPair::generate().expect("Failed to generate seller KeyPair."); - let buyer_keypair = KeyPair::generate().expect("Failed to generate seller KeyPair."); + let seller_keypair = KeyPair::generate(); + let buyer_keypair = KeyPair::generate(); let register_account = |account_id: AccountId, signature: PublicKey| { Register::account(Account::new(account_id, [signature])) diff --git a/client/tests/integration/asset_propagation.rs b/client/tests/integration/asset_propagation.rs index d248d160f86..6047dea994e 100644 --- a/client/tests/integration/asset_propagation.rs +++ b/client/tests/integration/asset_propagation.rs @@ -29,7 +29,7 @@ fn client_add_asset_quantity_to_existing_asset_should_increase_asset_amount_on_a let create_domain: InstructionBox = Register::domain(Domain::new(DomainId::from_str("domain")?)).into(); let account_id = AccountId::from_str("account@domain")?; - let (public_key, _) = KeyPair::generate()?.into(); + let (public_key, _) = KeyPair::generate().into(); let create_account = Register::account(Account::new(account_id.clone(), [public_key])).into(); let asset_definition_id = AssetDefinitionId::from_str("xor#domain")?; let create_asset = diff --git a/client/tests/integration/burn_public_keys.rs b/client/tests/integration/burn_public_keys.rs index 83552134f18..2bd40263a08 100644 --- a/client/tests/integration/burn_public_keys.rs +++ b/client/tests/integration/burn_public_keys.rs @@ -49,7 +49,7 @@ fn public_keys_cannot_be_burned_to_nothing() { let (_rt, _peer, client) = ::new().with_port(10_045).start_with_runtime(); wait_for_genesis_committed(&vec![client.clone()], 0); - let charlie_initial_keypair = KeyPair::generate().unwrap(); + let charlie_initial_keypair = KeyPair::generate(); let register_charlie = Register::account(Account::new( charlie_id.clone(), [charlie_initial_keypair.public_key().clone()], @@ -62,7 +62,7 @@ fn public_keys_cannot_be_burned_to_nothing() { assert_eq!(keys_count, 1); let mint_keys = (0..KEYS_COUNT - 1).map(|_| { - let (public_key, _) = KeyPair::generate().unwrap().into(); + let (public_key, _) = KeyPair::generate().into(); Mint::account_public_key(public_key, charlie_id.clone()) }); diff --git a/client/tests/integration/domain_owner.rs b/client/tests/integration/domain_owner.rs index da184e675b7..f36ce73df85 100644 --- a/client/tests/integration/domain_owner.rs +++ b/client/tests/integration/domain_owner.rs @@ -22,7 +22,7 @@ fn domain_owner_domain_permissions() -> Result<()> { let kingdom = Domain::new(kingdom_id.clone()); test_client.submit_blocking(Register::domain(kingdom))?; - let bob_keypair = KeyPair::generate()?; + let bob_keypair = KeyPair::generate(); let bob = Account::new(bob_id.clone(), [bob_keypair.public_key().clone()]); test_client.submit_blocking(Register::account(bob))?; @@ -93,7 +93,7 @@ fn domain_owner_account_permissions() -> Result<()> { let kingdom = Domain::new(kingdom_id); test_client.submit_blocking(Register::domain(kingdom))?; - let mad_hatter_keypair = KeyPair::generate()?; + let mad_hatter_keypair = KeyPair::generate(); let mad_hatter = Account::new( mad_hatter_id.clone(), [mad_hatter_keypair.public_key().clone()], @@ -101,7 +101,7 @@ fn domain_owner_account_permissions() -> Result<()> { test_client.submit_blocking(Register::account(mad_hatter))?; // check that "alice@wonderland" as owner of domain can burn and mint public keys for accounts in her domain - let mad_hatter_new_keypair = KeyPair::generate()?; + let mad_hatter_new_keypair = KeyPair::generate(); test_client.submit_blocking(Mint::account_public_key( mad_hatter_new_keypair.public_key().clone(), mad_hatter_id.clone(), @@ -157,7 +157,7 @@ fn domain_owner_asset_definition_permissions() -> Result<()> { let kingdom = Domain::new(kingdom_id.clone()); test_client.submit_blocking(Register::domain(kingdom))?; - let bob_keypair = KeyPair::generate()?; + let bob_keypair = KeyPair::generate(); let bob = Account::new(bob_id.clone(), [bob_keypair.public_key().clone()]); test_client.submit_blocking(Register::account(bob))?; @@ -227,7 +227,7 @@ fn domain_owner_asset_permissions() -> Result<()> { let kingdom = Domain::new(kingdom_id.clone()); test_client.submit_blocking(Register::domain(kingdom))?; - let bob_keypair = KeyPair::generate()?; + let bob_keypair = KeyPair::generate(); let bob = Account::new(bob_id.clone(), [bob_keypair.public_key().clone()]); test_client.submit_blocking(Register::account(bob))?; @@ -292,7 +292,7 @@ fn domain_owner_trigger_permissions() -> Result<()> { let kingdom = Domain::new(kingdom_id); test_client.submit_blocking(Register::domain(kingdom))?; - let bob_keypair = KeyPair::generate()?; + let bob_keypair = KeyPair::generate(); let bob = Account::new(bob_id.clone(), [bob_keypair.public_key().clone()]); test_client.submit_blocking(Register::account(bob))?; @@ -353,7 +353,7 @@ fn domain_owner_transfer() -> Result<()> { let kingdom = Domain::new(kingdom_id.clone()); test_client.submit_blocking(Register::domain(kingdom))?; - let bob_keypair = KeyPair::generate()?; + let bob_keypair = KeyPair::generate(); let bob = Account::new(bob_id.clone(), [bob_keypair.public_key().clone()]); test_client.submit_blocking(Register::account(bob))?; diff --git a/client/tests/integration/multiple_blocks_created.rs b/client/tests/integration/multiple_blocks_created.rs index bac51f52cd7..ccc6c3b020e 100644 --- a/client/tests/integration/multiple_blocks_created.rs +++ b/client/tests/integration/multiple_blocks_created.rs @@ -30,7 +30,7 @@ fn long_multiple_blocks_created() -> Result<()> { let create_domain: InstructionBox = Register::domain(Domain::new("domain".parse()?)).into(); let account_id: AccountId = "account@domain".parse()?; - let (public_key, _) = KeyPair::generate()?.into(); + let (public_key, _) = KeyPair::generate().into(); let create_account = Register::account(Account::new(account_id.clone(), [public_key])).into(); let asset_definition_id: AssetDefinitionId = "xor#domain".parse()?; let create_asset = diff --git a/client/tests/integration/multisignature_account.rs b/client/tests/integration/multisignature_account.rs index 6a7650a7a34..be7aa0a224f 100644 --- a/client/tests/integration/multisignature_account.rs +++ b/client/tests/integration/multisignature_account.rs @@ -20,7 +20,7 @@ fn transaction_signed_by_new_signatory_of_account_should_pass() -> Result<()> { let asset_definition_id: AssetDefinitionId = "xor#wonderland".parse().expect("Valid"); let create_asset = Register::asset_definition(AssetDefinition::quantity(asset_definition_id.clone())); - let key_pair = KeyPair::generate()?; + let key_pair = KeyPair::generate(); let add_signatory = Mint::account_public_key(key_pair.public_key().clone(), account_id.clone()); let instructions: [InstructionBox; 2] = [create_asset.into(), add_signatory.into()]; diff --git a/client/tests/integration/multisignature_transaction.rs b/client/tests/integration/multisignature_transaction.rs index 3095a9d9a5e..176e03061bb 100644 --- a/client/tests/integration/multisignature_transaction.rs +++ b/client/tests/integration/multisignature_transaction.rs @@ -28,7 +28,7 @@ fn multisignature_transactions_should_wait_for_all_signatures() -> Result<()> { let alice_id = AccountId::from_str("alice@wonderland")?; let alice_key_pair = get_key_pair(); - let key_pair_2 = KeyPair::generate()?; + let key_pair_2 = KeyPair::generate(); let asset_definition_id = AssetDefinitionId::from_str("camomile#wonderland")?; let create_asset = Register::asset_definition(AssetDefinition::quantity(asset_definition_id.clone())); diff --git a/client/tests/integration/offline_peers.rs b/client/tests/integration/offline_peers.rs index bc14bce0376..7627c6ddfbd 100644 --- a/client/tests/integration/offline_peers.rs +++ b/client/tests/integration/offline_peers.rs @@ -53,7 +53,7 @@ fn register_offline_peer() -> Result<()> { check_status(&peer_clients, 1); let address = socket_addr!(128.0.0.2:8085); - let key_pair = KeyPair::generate().unwrap(); + let key_pair = KeyPair::generate(); let public_key = key_pair.public_key().clone(); let peer_id = PeerId::new(address, public_key); let register_peer = Register::peer(DataModelPeer::new(peer_id)); diff --git a/client/tests/integration/permissions.rs b/client/tests/integration/permissions.rs index c6ccc522f29..5a9bf6881ee 100644 --- a/client/tests/integration/permissions.rs +++ b/client/tests/integration/permissions.rs @@ -75,7 +75,7 @@ fn permissions_disallow_asset_transfer() { let asset_definition_id: AssetDefinitionId = "xor#wonderland".parse().expect("Valid"); let create_asset = Register::asset_definition(AssetDefinition::quantity(asset_definition_id.clone())); - let mouse_keypair = KeyPair::generate().expect("Failed to generate KeyPair."); + let mouse_keypair = KeyPair::generate(); let alice_start_assets = get_assets(&iroha_client, &alice_id); iroha_client @@ -130,7 +130,7 @@ fn permissions_disallow_asset_burn() { let asset_definition_id = AssetDefinitionId::from_str("xor#wonderland").expect("Valid"); let create_asset = Register::asset_definition(AssetDefinition::quantity(asset_definition_id.clone())); - let mouse_keypair = KeyPair::generate().expect("Failed to generate KeyPair."); + let mouse_keypair = KeyPair::generate(); let alice_start_assets = get_assets(&iroha_client, &alice_id); @@ -201,7 +201,7 @@ fn permissions_differ_not_only_by_names() { let alice_id: AccountId = "alice@wonderland".parse().expect("Valid"); let mouse_id: AccountId = "mouse@outfit".parse().expect("Valid"); - let mouse_keypair = KeyPair::generate().expect("Failed to generate KeyPair."); + let mouse_keypair = KeyPair::generate(); // Registering mouse let outfit_domain: DomainId = "outfit".parse().unwrap(); @@ -305,7 +305,7 @@ fn stored_vs_granted_token_payload() -> Result<()> { let create_asset = Register::asset_definition(AssetDefinition::store(asset_definition_id.clone())); let mouse_id: AccountId = "mouse@wonderland".parse().expect("Valid"); - let mouse_keypair = KeyPair::generate().expect("Failed to generate KeyPair."); + let mouse_keypair = KeyPair::generate(); let new_mouse_account = Account::new(mouse_id.clone(), [mouse_keypair.public_key().clone()]); let instructions: [InstructionBox; 2] = [ Register::account(new_mouse_account).into(), diff --git a/client/tests/integration/queries/asset.rs b/client/tests/integration/queries/asset.rs index 6046c8cbf88..d987395f76c 100644 --- a/client/tests/integration/queries/asset.rs +++ b/client/tests/integration/queries/asset.rs @@ -31,10 +31,9 @@ fn find_asset_total_quantity() -> Result<()> { "white_rabbit@looking_glass".parse()?, ]; - let keys = - core::iter::repeat_with(|| KeyPair::generate().expect("Failed to generate `KeyPair`")) - .take(accounts.len() - 1) - .collect::>(); + let keys = core::iter::repeat_with(KeyPair::generate) + .take(accounts.len() - 1) + .collect::>(); // Registering accounts let register_accounts = accounts diff --git a/client/tests/integration/roles.rs b/client/tests/integration/roles.rs index a9102dc718d..f5a3f266f95 100644 --- a/client/tests/integration/roles.rs +++ b/client/tests/integration/roles.rs @@ -55,7 +55,7 @@ fn register_and_grant_role_for_metadata_access() -> Result<()> { let mouse_id = AccountId::from_str("mouse@wonderland")?; // Registering Mouse - let mouse_key_pair = KeyPair::generate()?; + let mouse_key_pair = KeyPair::generate(); let register_mouse = Register::account(Account::new( mouse_id.clone(), [mouse_key_pair.public_key().clone()], diff --git a/client/tests/integration/transfer_asset.rs b/client/tests/integration/transfer_asset.rs index 63953cf6b4a..0de27aad05a 100644 --- a/client/tests/integration/transfer_asset.rs +++ b/client/tests/integration/transfer_asset.rs @@ -179,8 +179,6 @@ fn generate_two_ids() -> (AccountId, AccountId) { } fn create_mouse(mouse_id: AccountId) -> Register { - let (mouse_public_key, _) = KeyPair::generate() - .expect("Failed to generate KeyPair") - .into(); + let (mouse_public_key, _) = KeyPair::generate().into(); Register::account(Account::new(mouse_id, [mouse_public_key])) } diff --git a/client/tests/integration/unregister_peer.rs b/client/tests/integration/unregister_peer.rs index 16f6ad87c10..fb45c9db8c4 100644 --- a/client/tests/integration/unregister_peer.rs +++ b/client/tests/integration/unregister_peer.rs @@ -107,7 +107,7 @@ fn init() -> Result<( .into_set_parameters(); let create_domain = Register::domain(Domain::new("domain".parse()?)); let account_id: AccountId = "account@domain".parse()?; - let (public_key, _) = KeyPair::generate()?.into(); + let (public_key, _) = KeyPair::generate().into(); let create_account = Register::account(Account::new(account_id.clone(), [public_key])); let asset_definition_id: AssetDefinitionId = "xor#domain".parse()?; let create_asset = diff --git a/client/tests/integration/upgrade.rs b/client/tests/integration/upgrade.rs index 42ee2f623de..ec53fdbbe8b 100644 --- a/client/tests/integration/upgrade.rs +++ b/client/tests/integration/upgrade.rs @@ -23,7 +23,7 @@ fn executor_upgrade_should_work() -> Result<()> { client.submit_blocking(register_admin_domain)?; let admin_id: AccountId = "admin@admin".parse()?; - let admin_keypair = KeyPair::generate()?; + let admin_keypair = KeyPair::generate(); let admin_account = Account::new(admin_id.clone(), [admin_keypair.public_key().clone()]); let register_admin_account = Register::account(admin_account); client.submit_blocking(register_admin_account)?; diff --git a/core/benches/blocks/apply_blocks.rs b/core/benches/blocks/apply_blocks.rs index 5a2e48b7e82..8a09d3e886c 100644 --- a/core/benches/blocks/apply_blocks.rs +++ b/core/benches/blocks/apply_blocks.rs @@ -24,7 +24,7 @@ impl WsvApplyBlocks { let accounts_per_domain = 1000; let assets_per_domain = 1000; let account_id: AccountId = "alice@wonderland".parse()?; - let key_pair = KeyPair::generate()?; + let key_pair = KeyPair::generate(); let wsv = build_wsv(rt, &account_id, &key_pair); let nth = 100; diff --git a/core/benches/blocks/validate_blocks.rs b/core/benches/blocks/validate_blocks.rs index 9b59b9f7ed7..80b53e209ce 100644 --- a/core/benches/blocks/validate_blocks.rs +++ b/core/benches/blocks/validate_blocks.rs @@ -27,7 +27,7 @@ impl WsvValidateBlocks { let accounts_per_domain = 1000; let assets_per_domain = 1000; let account_id: AccountId = "alice@wonderland".parse()?; - let key_pair = KeyPair::generate()?; + let key_pair = KeyPair::generate(); let wsv = build_wsv(rt, &account_id, &key_pair); let nth = 100; diff --git a/core/benches/kura.rs b/core/benches/kura.rs index 3c9e9b103e2..9dd90d7b268 100644 --- a/core/benches/kura.rs +++ b/core/benches/kura.rs @@ -26,7 +26,7 @@ async fn measure_block_size_for_n_executors(n_executors: u32) { let xor_id = AssetDefinitionId::from_str("xor#test").expect("tested"); let alice_xor_id = AssetId::new(xor_id, alice_id); let transfer = Transfer::asset_quantity(alice_xor_id, 10_u32, bob_id); - let keypair = KeyPair::generate().expect("Failed to generate KeyPair."); + let keypair = KeyPair::generate(); let tx = TransactionBuilder::new( chain_id.clone(), AccountId::from_str("alice@wonderland").expect("checked"), @@ -53,10 +53,10 @@ async fn measure_block_size_for_n_executors(n_executors: u32) { let topology = Topology::new(UniqueVec::new()); let mut block = BlockBuilder::new(vec![tx], topology, Vec::new()) .chain(0, &mut wsv) - .sign(&KeyPair::generate().unwrap()); + .sign(&KeyPair::generate()); for _ in 1..n_executors { - block = block.sign(&KeyPair::generate().unwrap()); + block = block.sign(&KeyPair::generate()); } let mut block_store = BlockStore::new(dir.path(), LockStatus::Unlocked); block_store.create_files_if_they_do_not_exist().unwrap(); diff --git a/core/benches/validation.rs b/core/benches/validation.rs index 970bc80571c..089d6e29e2a 100644 --- a/core/benches/validation.rs +++ b/core/benches/validation.rs @@ -28,9 +28,7 @@ fn build_test_transaction(keys: &KeyPair, chain_id: ChainId) -> SignedTransactio let domain_id = DomainId::from_str(domain_name).expect("does not panic"); let create_domain: InstructionBox = Register::domain(Domain::new(domain_id)).into(); let account_name = "account"; - let (public_key, _) = KeyPair::generate() - .expect("Failed to generate KeyPair.") - .into(); + let (public_key, _) = KeyPair::generate().into(); let create_account = Register::account(Account::new( AccountId::new( domain_name.parse().expect("Valid"), @@ -97,7 +95,7 @@ fn build_test_and_transient_wsv(keys: KeyPair) -> WorldStateView { fn accept_transaction(criterion: &mut Criterion) { let chain_id = ChainId::new("0"); - let keys = KeyPair::generate().expect("Failed to generate keys"); + let keys = KeyPair::generate(); let transaction = build_test_transaction(&keys, chain_id.clone()); let mut success_count = 0; let mut failures_count = 0; @@ -115,9 +113,9 @@ fn accept_transaction(criterion: &mut Criterion) { fn sign_transaction(criterion: &mut Criterion) { let chain_id = ChainId::new("0"); - let keys = KeyPair::generate().expect("Failed to generate keys"); + let keys = KeyPair::generate(); let transaction = build_test_transaction(&keys, chain_id); - let key_pair = KeyPair::generate().expect("Failed to generate KeyPair."); + let key_pair = KeyPair::generate(); let mut count = 0; let _ = criterion.bench_function("sign", |b| { b.iter_batched( @@ -135,7 +133,7 @@ fn sign_transaction(criterion: &mut Criterion) { fn validate_transaction(criterion: &mut Criterion) { let chain_id = ChainId::new("0"); - let keys = KeyPair::generate().expect("Failed to generate keys"); + let keys = KeyPair::generate(); let transaction = AcceptedTransaction::accept( build_test_transaction(&keys, chain_id.clone()), &chain_id, @@ -161,14 +159,14 @@ fn validate_transaction(criterion: &mut Criterion) { fn sign_blocks(criterion: &mut Criterion) { let chain_id = ChainId::new("0"); - let keys = KeyPair::generate().expect("Failed to generate keys"); + let keys = KeyPair::generate(); let transaction = AcceptedTransaction::accept( build_test_transaction(&keys, chain_id.clone()), &chain_id, &TRANSACTION_LIMITS, ) .expect("Failed to accept transaction."); - let key_pair = KeyPair::generate().expect("Failed to generate KeyPair."); + let key_pair = KeyPair::generate(); let kura = iroha_core::kura::Kura::blank_kura_for_testing(); let query_handle = LiveQueryStore::test().start(); let mut wsv = WorldStateView::new(World::new(), kura, query_handle); diff --git a/core/src/block.rs b/core/src/block.rs index 98dbdb2c931..e87ce6e972d 100644 --- a/core/src/block.rs +++ b/core/src/block.rs @@ -447,7 +447,7 @@ mod valid { commit_topology: UniqueVec::new(), event_recommendations: Vec::new(), })) - .sign(&KeyPair::generate().unwrap()) + .sign(&KeyPair::generate()) } /// Check if block's signatures meet requirements for given topology. @@ -519,11 +519,9 @@ mod valid { #[test] fn signature_verification_ok() { - let key_pairs = core::iter::repeat_with(|| { - KeyPair::generate().expect("Failed to generate key pair") - }) - .take(7) - .collect::>(); + let key_pairs = core::iter::repeat_with(KeyPair::generate) + .take(7) + .collect::>(); let mut key_pairs_iter = key_pairs.iter(); let peers = test_peers![0, 1, 2, 3, 4, 5, 6: key_pairs_iter]; let topology = Topology::new(peers); @@ -541,11 +539,9 @@ mod valid { #[test] fn signature_verification_consensus_not_required_ok() { - let key_pairs = core::iter::repeat_with(|| { - KeyPair::generate().expect("Failed to generate key pair") - }) - .take(1) - .collect::>(); + let key_pairs = core::iter::repeat_with(KeyPair::generate) + .take(1) + .collect::>(); let mut key_pairs_iter = key_pairs.iter(); let peers = test_peers![0,: key_pairs_iter]; let topology = Topology::new(peers); @@ -565,11 +561,9 @@ mod valid { /// Check requirement of having at least $2f + 1$ signatures in $3f + 1$ network #[test] fn signature_verification_not_enough_signatures() { - let key_pairs = core::iter::repeat_with(|| { - KeyPair::generate().expect("Failed to generate key pair") - }) - .take(7) - .collect::>(); + let key_pairs = core::iter::repeat_with(KeyPair::generate) + .take(7) + .collect::>(); let mut key_pairs_iter = key_pairs.iter(); let peers = test_peers![0, 1, 2, 3, 4, 5, 6: key_pairs_iter]; let topology = Topology::new(peers); @@ -593,11 +587,9 @@ mod valid { /// Check requirement of having leader signature #[test] fn signature_verification_miss_proxy_tail_signature() { - let key_pairs = core::iter::repeat_with(|| { - KeyPair::generate().expect("Failed to generate key pair") - }) - .take(7) - .collect::>(); + let key_pairs = core::iter::repeat_with(KeyPair::generate) + .take(7) + .collect::>(); let mut key_pairs_iter = key_pairs.iter(); let peers = test_peers![0, 1, 2, 3, 4, 5, 6: key_pairs_iter]; let topology = Topology::new(peers); @@ -699,7 +691,7 @@ mod tests { // Predefined world state let alice_id = AccountId::from_str("alice@wonderland").expect("Valid"); - let alice_keys = KeyPair::generate().expect("Valid"); + let alice_keys = KeyPair::generate(); let account = Account::new(alice_id.clone(), [alice_keys.public_key().clone()]).build(&alice_id); let domain_id = DomainId::from_str("wonderland").expect("Valid"); @@ -730,7 +722,7 @@ mod tests { .sign(&alice_keys); // The first transaction should be confirmed - assert!(valid_block.0.transactions().nth(0).unwrap().error.is_none()); + assert!(valid_block.0.transactions().next().unwrap().error.is_none()); // The second transaction should be rejected assert!(valid_block.0.transactions().nth(1).unwrap().error.is_some()); @@ -742,7 +734,7 @@ mod tests { // Predefined world state let alice_id = AccountId::from_str("alice@wonderland").expect("Valid"); - let alice_keys = KeyPair::generate().expect("Valid"); + let alice_keys = KeyPair::generate(); let account = Account::new(alice_id.clone(), [alice_keys.public_key().clone()]).build(&alice_id); let domain_id = DomainId::from_str("wonderland").expect("Valid"); @@ -796,7 +788,7 @@ mod tests { .sign(&alice_keys); // The first transaction should fail - assert!(valid_block.0.transactions().nth(0).unwrap().error.is_some()); + assert!(valid_block.0.transactions().next().unwrap().error.is_some()); // The third transaction should succeed assert!(valid_block.0.transactions().nth(2).unwrap().error.is_none()); @@ -808,7 +800,7 @@ mod tests { // Predefined world state let alice_id = AccountId::from_str("alice@wonderland").expect("Valid"); - let alice_keys = KeyPair::generate().expect("Valid"); + let alice_keys = KeyPair::generate(); let account = Account::new(alice_id.clone(), [alice_keys.public_key().clone()]).build(&alice_id); let domain_id = DomainId::from_str("wonderland").expect("Valid"); @@ -853,7 +845,7 @@ mod tests { // The first transaction should be rejected assert!( - valid_block.0.transactions().nth(0).unwrap().error.is_some(), + valid_block.0.transactions().next().unwrap().error.is_some(), "The first transaction should be rejected, as it contains `Fail`." ); diff --git a/core/src/queue.rs b/core/src/queue.rs index 20ec63648e1..53eeb75f4fb 100644 --- a/core/src/queue.rs +++ b/core/src/queue.rs @@ -427,7 +427,7 @@ mod tests { #[test] async fn push_tx() { - let key_pair = KeyPair::generate().unwrap(); + let key_pair = KeyPair::generate(); let kura = Kura::blank_kura_for_testing(); let query_handle = LiveQueryStore::test().start(); let wsv = Arc::new(WorldStateView::new( @@ -453,7 +453,7 @@ mod tests { async fn push_tx_overflow() { let max_txs_in_queue = 10; - let key_pair = KeyPair::generate().unwrap(); + let key_pair = KeyPair::generate(); let kura = Kura::blank_kura_for_testing(); let query_handle = LiveQueryStore::test().start(); let wsv = Arc::new(WorldStateView::new( @@ -491,7 +491,7 @@ mod tests { let chain_id = ChainId::new("0"); let max_txs_in_block = 2; - let key_pairs = [KeyPair::generate().unwrap(), KeyPair::generate().unwrap()]; + let key_pairs = [KeyPair::generate(), KeyPair::generate()]; let kura = Kura::blank_kura_for_testing(); let wsv = { let domain_id = DomainId::from_str("wonderland").expect("Valid"); @@ -573,7 +573,7 @@ mod tests { #[test] async fn get_available_txs() { let max_txs_in_block = 2; - let alice_key = KeyPair::generate().expect("Failed to generate keypair."); + let alice_key = KeyPair::generate(); let kura = Kura::blank_kura_for_testing(); let query_handle = LiveQueryStore::test().start(); let wsv = Arc::new(WorldStateView::new( @@ -601,7 +601,7 @@ mod tests { #[test] async fn push_tx_already_in_blockchain() { - let alice_key = KeyPair::generate().expect("Failed to generate keypair."); + let alice_key = KeyPair::generate(); let kura = Kura::blank_kura_for_testing(); let query_handle = LiveQueryStore::test().start(); let mut wsv = WorldStateView::new( @@ -631,7 +631,7 @@ mod tests { #[test] async fn get_tx_drop_if_in_blockchain() { let max_txs_in_block = 2; - let alice_key = KeyPair::generate().expect("Failed to generate keypair."); + let alice_key = KeyPair::generate(); let kura = Kura::blank_kura_for_testing(); let query_handle = LiveQueryStore::test().start(); let mut wsv = WorldStateView::new( @@ -661,7 +661,7 @@ mod tests { #[test] async fn get_available_txs_with_timeout() { let max_txs_in_block = 6; - let alice_key = KeyPair::generate().expect("Failed to generate keypair."); + let alice_key = KeyPair::generate(); let kura = Kura::blank_kura_for_testing(); let query_handle = LiveQueryStore::test().start(); let wsv = Arc::new(WorldStateView::new( @@ -711,7 +711,7 @@ mod tests { #[test] async fn transactions_available_after_pop() { let max_txs_in_block = 2; - let alice_key = KeyPair::generate().expect("Failed to generate keypair."); + let alice_key = KeyPair::generate(); let kura = Kura::blank_kura_for_testing(); let query_handle = LiveQueryStore::test().start(); let wsv = Arc::new(WorldStateView::new( @@ -751,7 +751,7 @@ mod tests { let chain_id = ChainId::new("0"); let max_txs_in_block = 2; - let alice_key = KeyPair::generate().expect("Failed to generate keypair."); + let alice_key = KeyPair::generate(); let kura = Kura::blank_kura_for_testing(); let query_handle = LiveQueryStore::test().start(); let wsv = Arc::new(WorldStateView::new( @@ -797,7 +797,7 @@ mod tests { #[test] async fn concurrent_stress_test() { let max_txs_in_block = 10; - let alice_key = KeyPair::generate().expect("Failed to generate keypair."); + let alice_key = KeyPair::generate(); let kura = Kura::blank_kura_for_testing(); let query_handle = LiveQueryStore::test().start(); let wsv = WorldStateView::new( @@ -872,7 +872,7 @@ mod tests { let future_threshold_ms = 1000; let alice_id = "alice@wonderland"; - let alice_key = KeyPair::generate().expect("Failed to generate keypair."); + let alice_key = KeyPair::generate(); let kura = Kura::blank_kura_for_testing(); let query_handle = LiveQueryStore::test().start(); let wsv = Arc::new(WorldStateView::new( @@ -922,8 +922,8 @@ mod tests { #[test] async fn queue_throttling() { - let alice_key_pair = KeyPair::generate().unwrap(); - let bob_key_pair = KeyPair::generate().unwrap(); + let alice_key_pair = KeyPair::generate(); + let bob_key_pair = KeyPair::generate(); let kura = Kura::blank_kura_for_testing(); let world = { let domain_id = DomainId::from_str("wonderland").expect("Valid"); diff --git a/core/src/smartcontracts/isi/mod.rs b/core/src/smartcontracts/isi/mod.rs index 6e12ab0649c..ccd65f6d8cb 100644 --- a/core/src/smartcontracts/isi/mod.rs +++ b/core/src/smartcontracts/isi/mod.rs @@ -244,7 +244,7 @@ mod tests { let mut wsv = WorldStateView::new(world, kura.clone(), query_handle); let genesis_account_id = AccountId::from_str("genesis@genesis")?; let account_id = AccountId::from_str("alice@wonderland")?; - let (public_key, _) = KeyPair::generate()?.into(); + let (public_key, _) = KeyPair::generate().into(); let asset_definition_id = AssetDefinitionId::from_str("rose#wonderland")?; Register::domain(Domain::new(DomainId::from_str("wonderland")?)) .execute(&genesis_account_id, &mut wsv)?; @@ -394,9 +394,7 @@ mod tests { let trigger_id = TriggerId::from_str("test_trigger_id")?; // register fake account - let (public_key, _) = KeyPair::generate() - .expect("Failed to generate KeyPair") - .into(); + let (public_key, _) = KeyPair::generate().into(); let register_account = Register::account(Account::new(fake_account_id.clone(), [public_key])); register_account.execute(&account_id, &mut wsv)?; diff --git a/core/src/smartcontracts/isi/query.rs b/core/src/smartcontracts/isi/query.rs index c4afe933047..db2ab543e21 100644 --- a/core/src/smartcontracts/isi/query.rs +++ b/core/src/smartcontracts/isi/query.rs @@ -179,7 +179,7 @@ mod tests { sumeragi::network_topology::Topology, tx::AcceptedTransaction, wsv::World, PeersIds, }; - static ALICE_KEYS: Lazy = Lazy::new(|| KeyPair::generate().unwrap()); + static ALICE_KEYS: Lazy = Lazy::new(KeyPair::generate); static ALICE_ID: Lazy = Lazy::new(|| AccountId::from_str("alice@wonderland").expect("Valid")); diff --git a/core/src/smartcontracts/wasm.rs b/core/src/smartcontracts/wasm.rs index cdc3ebd1d60..b361bc97b04 100644 --- a/core/src/smartcontracts/wasm.rs +++ b/core/src/smartcontracts/wasm.rs @@ -1658,7 +1658,7 @@ mod tests { fn world_with_test_account(authority: &AccountId) -> World { let domain_id = authority.domain_id.clone(); - let (public_key, _) = KeyPair::generate().unwrap().into(); + let (public_key, _) = KeyPair::generate().into(); let account = Account::new(authority.clone(), [public_key]).build(authority); let mut domain = Domain::new(domain_id).build(authority); assert!(domain.add_account(account).is_none()); diff --git a/core/src/sumeragi/main_loop.rs b/core/src/sumeragi/main_loop.rs index 482d1427132..06c8e2c2b97 100644 --- a/core/src/sumeragi/main_loop.rs +++ b/core/src/sumeragi/main_loop.rs @@ -1184,7 +1184,7 @@ mod tests { use crate::{query::store::LiveQueryStore, smartcontracts::Registrable}; /// Used to inject faulty payload for testing - fn payload_mut<'a>(block: &'a mut SignedBlock) -> &'a mut BlockPayload { + fn payload_mut(block: &mut SignedBlock) -> &mut BlockPayload { let SignedBlock::V1(signed) = block; &mut signed.payload } @@ -1192,11 +1192,11 @@ mod tests { fn create_data_for_test( chain_id: &ChainId, topology: &Topology, - leader_key_pair: KeyPair, + leader_key_pair: &KeyPair, ) -> (WorldStateView, Arc, SignedBlock) { // Predefined world state let alice_id: AccountId = "alice@wonderland".parse().expect("Valid"); - let alice_keys = KeyPair::generate().expect("Valid"); + let alice_keys = KeyPair::generate(); let account = Account::new(alice_id.clone(), [alice_keys.public_key().clone()]).build(&alice_id); let domain_id = "wonderland".parse().expect("Valid"); @@ -1225,7 +1225,7 @@ mod tests { // Creating a block of two identical transactions and validating it let block = BlockBuilder::new(vec![tx.clone(), tx], topology.clone(), Vec::new()) .chain(0, &mut wsv) - .sign(&leader_key_pair); + .sign(leader_key_pair); let genesis = block.commit(topology).expect("Block is valid"); wsv.apply(&genesis).expect("Failed to apply block"); @@ -1263,7 +1263,7 @@ mod tests { // Creating a block of two identical transactions and validating it let block = BlockBuilder::new(vec![tx1, tx2], topology.clone(), Vec::new()) .chain(0, &mut wsv.clone()) - .sign(&leader_key_pair); + .sign(leader_key_pair); (wsv, kura, block.into()) } @@ -1273,13 +1273,13 @@ mod tests { async fn block_sync_invalid_block() { let chain_id = ChainId::new("0"); - let leader_key_pair = KeyPair::generate().unwrap(); + let leader_key_pair = KeyPair::generate(); let topology = Topology::new(unique_vec![PeerId::new( "127.0.0.1:8080".parse().unwrap(), leader_key_pair.public_key().clone(), )]); let (finalized_wsv, _, mut block) = - create_data_for_test(&chain_id, &topology, leader_key_pair); + create_data_for_test(&chain_id, &topology, &leader_key_pair); let wsv = finalized_wsv.clone(); // Malform block to make it invalid @@ -1293,13 +1293,13 @@ mod tests { async fn block_sync_invalid_soft_fork_block() { let chain_id = ChainId::new("0"); - let leader_key_pair = KeyPair::generate().unwrap(); + let leader_key_pair = KeyPair::generate(); let topology = Topology::new(unique_vec![PeerId::new( "127.0.0.1:8080".parse().unwrap(), leader_key_pair.public_key().clone(), )]); let (finalized_wsv, kura, mut block) = - create_data_for_test(&chain_id, &topology, leader_key_pair); + create_data_for_test(&chain_id, &topology, &leader_key_pair); let mut wsv = finalized_wsv.clone(); let validated_block = @@ -1325,9 +1325,9 @@ mod tests { let chain_id = ChainId::new("0"); let topology = Topology::new(UniqueVec::new()); - let leader_key_pair = KeyPair::generate().unwrap(); + let leader_key_pair = KeyPair::generate(); let (finalized_wsv, _, mut block) = - create_data_for_test(&chain_id, &topology, leader_key_pair); + create_data_for_test(&chain_id, &topology, &leader_key_pair); let wsv = finalized_wsv.clone(); // Change block height @@ -1351,12 +1351,13 @@ mod tests { async fn block_sync_commit_block() { let chain_id = ChainId::new("0"); - let leader_key_pair = KeyPair::generate().unwrap(); + let leader_key_pair = KeyPair::generate(); let topology = Topology::new(unique_vec![PeerId::new( "127.0.0.1:8080".parse().unwrap(), leader_key_pair.public_key().clone(), )]); - let (finalized_wsv, _, block) = create_data_for_test(&chain_id, &topology, leader_key_pair); + let (finalized_wsv, _, block) = + create_data_for_test(&chain_id, &topology, &leader_key_pair); let wsv = finalized_wsv.clone(); let result = handle_block_sync(&chain_id, block, &wsv, &finalized_wsv); assert!(matches!(result, Ok(BlockSyncOk::CommitBlock(_, _)))) @@ -1366,13 +1367,13 @@ mod tests { async fn block_sync_replace_top_block() { let chain_id = ChainId::new("0"); - let leader_key_pair = KeyPair::generate().unwrap(); + let leader_key_pair = KeyPair::generate(); let topology = Topology::new(unique_vec![PeerId::new( "127.0.0.1:8080".parse().unwrap(), leader_key_pair.public_key().clone(), )]); let (finalized_wsv, kura, mut block) = - create_data_for_test(&chain_id, &topology, leader_key_pair); + create_data_for_test(&chain_id, &topology, &leader_key_pair); let mut wsv = finalized_wsv.clone(); let validated_block = @@ -1394,13 +1395,13 @@ mod tests { async fn block_sync_small_view_change_index() { let chain_id = ChainId::new("0"); - let leader_key_pair = KeyPair::generate().unwrap(); + let leader_key_pair = KeyPair::generate(); let topology = Topology::new(unique_vec![PeerId::new( "127.0.0.1:8080".parse().unwrap(), leader_key_pair.public_key().clone(), )]); let (finalized_wsv, kura, mut block) = - create_data_for_test(&chain_id, &topology, leader_key_pair); + create_data_for_test(&chain_id, &topology, &leader_key_pair); let mut wsv = finalized_wsv.clone(); // Increase block view change index @@ -1436,9 +1437,9 @@ mod tests { let chain_id = ChainId::new("0"); let topology = Topology::new(UniqueVec::new()); - let leader_key_pair = KeyPair::generate().unwrap(); + let leader_key_pair = KeyPair::generate(); let (finalized_wsv, _, mut block) = - create_data_for_test(&chain_id, &topology, leader_key_pair); + create_data_for_test(&chain_id, &topology, &leader_key_pair); let wsv = finalized_wsv.clone(); // Change block height and view change index diff --git a/core/src/sumeragi/network_topology.rs b/core/src/sumeragi/network_topology.rs index cbc2325d1ed..0d2def7260d 100644 --- a/core/src/sumeragi/network_topology.rs +++ b/core/src/sumeragi/network_topology.rs @@ -280,7 +280,7 @@ pub enum Role { #[cfg(test)] macro_rules! test_peers { ($($id:literal),+$(,)?) => {{ - let mut iter = ::core::iter::repeat_with(|| KeyPair::generate().expect("Failed to generate key pair")); + let mut iter = ::core::iter::repeat_with(|| KeyPair::generate()); test_peers![$($id),*: iter] }}; ($($id:literal),+$(,)?: $key_pair_iter:expr) => { @@ -353,10 +353,9 @@ mod tests { #[test] fn filter_by_role() { - let key_pairs = - core::iter::repeat_with(|| KeyPair::generate().expect("Failed to generate key pair")) - .take(7) - .collect::>(); + let key_pairs = core::iter::repeat_with(KeyPair::generate) + .take(7) + .collect::>(); let mut key_pairs_iter = key_pairs.iter(); let peers = test_peers![0, 1, 2, 3, 4, 5, 6: key_pairs_iter]; let topology = Topology::new(peers.clone()); @@ -396,10 +395,9 @@ mod tests { #[test] fn filter_by_role_empty() { - let key_pairs = - core::iter::repeat_with(|| KeyPair::generate().expect("Failed to generate key pair")) - .take(7) - .collect::>(); + let key_pairs = core::iter::repeat_with(KeyPair::generate) + .take(7) + .collect::>(); let peers = UniqueVec::new(); let topology = Topology::new(peers); @@ -428,10 +426,9 @@ mod tests { #[test] fn filter_by_role_1() { - let key_pairs = - core::iter::repeat_with(|| KeyPair::generate().expect("Failed to generate key pair")) - .take(7) - .collect::>(); + let key_pairs = core::iter::repeat_with(KeyPair::generate) + .take(7) + .collect::>(); let mut key_pairs_iter = key_pairs.iter(); let peers = test_peers![0: key_pairs_iter]; let topology = Topology::new(peers.clone()); @@ -462,10 +459,9 @@ mod tests { #[test] fn filter_by_role_2() { - let key_pairs = - core::iter::repeat_with(|| KeyPair::generate().expect("Failed to generate key pair")) - .take(7) - .collect::>(); + let key_pairs = core::iter::repeat_with(KeyPair::generate) + .take(7) + .collect::>(); let mut key_pairs_iter = key_pairs.iter(); let peers = test_peers![0, 1: key_pairs_iter]; let topology = Topology::new(peers.clone()); @@ -497,10 +493,9 @@ mod tests { #[test] fn filter_by_role_3() { - let key_pairs = - core::iter::repeat_with(|| KeyPair::generate().expect("Failed to generate key pair")) - .take(7) - .collect::>(); + let key_pairs = core::iter::repeat_with(KeyPair::generate) + .take(7) + .collect::>(); let mut key_pairs_iter = key_pairs.iter(); let peers = test_peers![0, 1, 2: key_pairs_iter]; let topology = Topology::new(peers.clone()); diff --git a/core/test_network/src/lib.rs b/core/test_network/src/lib.rs index c88f0ba1d55..f283d63c292 100644 --- a/core/test_network/src/lib.rs +++ b/core/test_network/src/lib.rs @@ -483,7 +483,7 @@ impl Peer { /// - `api_address` /// * If keypair generation fails pub fn new() -> Result { - let key_pair = KeyPair::generate()?; + let key_pair = KeyPair::generate(); let p2p_address = local_unique_port()?; let api_address = local_unique_port()?; let id = PeerId::new(p2p_address.clone(), key_pair.public_key().clone()); @@ -775,7 +775,7 @@ impl TestConfiguration for Configuration { ); let env_proxy = ConfigurationProxy::from_std_env().expect("Test env variables should parse properly"); - let (public_key, private_key) = KeyPair::generate().unwrap().into(); + let (public_key, private_key) = KeyPair::generate().into(); sample_proxy.public_key = Some(public_key); sample_proxy.private_key = Some(private_key); sample_proxy.override_with(env_proxy) diff --git a/crypto/src/lib.rs b/crypto/src/lib.rs index 457874d8118..853af121700 100755 --- a/crypto/src/lib.rs +++ b/crypto/src/lib.rs @@ -188,12 +188,12 @@ ffi::ffi_item! { impl KeyPair { /// Generates a pair of Public and Private key with [`Algorithm::default()`] selected as generation algorithm. - /// - /// # Errors - /// Fails if decoding fails #[cfg(feature = "rand")] - pub fn generate() -> Result { - Self::generate_with_configuration(KeyGenConfiguration::from_random()) + pub fn generate() -> Self { + Self::generate_with_configuration( + KeyGenConfiguration::from_random().with_algorithm(Algorithm::Ed25519), + ) + .expect("Ed25519 key generation from random bytes should never fail") } } @@ -227,7 +227,8 @@ impl KeyPair { /// Generates a pair of Public and Private key with the corresponding [`KeyGenConfiguration`]. /// /// # Errors - /// Fails if decoding fails + /// + /// Fails if used [`Secp256k1`](Algorithm::Secp256k1) algorithm with seed less than `32` bytes. pub fn generate_with_configuration(configuration: KeyGenConfiguration) -> Result { let key_gen_option = match (configuration.algorithm, configuration.key_gen_option) { (Algorithm::Secp256k1, KeyGenOption::UseSeed(seed)) if seed.len() < 32 => { diff --git a/crypto/src/signature/mod.rs b/crypto/src/signature/mod.rs index 1317403f8b8..4131f673e50 100644 --- a/crypto/src/signature/mod.rs +++ b/crypto/src/signature/mod.rs @@ -584,7 +584,7 @@ mod tests { #[test] #[cfg(all(feature = "rand", not(feature = "ffi_import")))] fn signatures_of_deduplication_by_public_key() { - let key_pair = KeyPair::generate().expect("Failed to generate keys"); + let key_pair = KeyPair::generate(); let signatures = [ SignatureOf::new(&key_pair, &1), SignatureOf::new(&key_pair, &2), @@ -603,17 +603,16 @@ mod tests { let keys = 5; let signatures_per_key = 10; - let signatures = - core::iter::repeat_with(|| KeyPair::generate().expect("Failed to generate keys")) - .take(keys) - .flat_map(|key| { - core::iter::repeat_with(move || key.clone()) - .zip(0..) - .map(|(key, i)| SignatureOf::new(&key, &i)) - .take(signatures_per_key) - }) - .map(SignatureWrapperOf) - .collect::>(); + let signatures = core::iter::repeat_with(KeyPair::generate) + .take(keys) + .flat_map(|key| { + core::iter::repeat_with(move || key.clone()) + .zip(0..) + .map(|(key, i)| SignatureOf::new(&key, &i)) + .take(signatures_per_key) + }) + .map(SignatureWrapperOf) + .collect::>(); let hash_set: HashSet<_> = signatures.clone().into_iter().collect(); let btree_set: BTreeSet<_> = signatures.into_iter().collect(); diff --git a/data_model/src/account.rs b/data_model/src/account.rs index f472b3152b7..59ad7b0a4d9 100644 --- a/data_model/src/account.rs +++ b/data_model/src/account.rs @@ -336,7 +336,7 @@ mod tests { use crate::{domain::DomainId, name::Name}; fn make_key() -> PublicKey { - KeyPair::generate().unwrap().public_key().clone() + KeyPair::generate().public_key().clone() } fn check_signature_check_condition( diff --git a/data_model/src/predicate.rs b/data_model/src/predicate.rs index a18fc3e7dde..e50157fdaf7 100644 --- a/data_model/src/predicate.rs +++ b/data_model/src/predicate.rs @@ -495,9 +495,7 @@ pub mod string { #[test] fn peer_id() { - let (public_key, _) = iroha_crypto::KeyPair::generate() - .expect("Should not panic") - .into(); + let (public_key, _) = iroha_crypto::KeyPair::generate().into(); let id = IdBox::PeerId(peer::PeerId::new(socket_addr!(127.0.0.1:123), public_key)); assert!(StringPredicate::contains("123").applies(&id)); } @@ -1188,7 +1186,7 @@ pub mod value { assert!(!pred.applies(&Value::String("alice@wonderland".to_owned()))); } { - let key_pair = iroha_crypto::KeyPair::generate().expect("Should not fail"); + let key_pair = iroha_crypto::KeyPair::generate(); let (public_key, _) = key_pair.into(); let pred = ValuePredicate::Display(string::StringPredicate::is("alice@wonderland")); println!("{pred:?}"); diff --git a/genesis/src/lib.rs b/genesis/src/lib.rs index b0d9a1cef9a..c23d7c3b900 100644 --- a/genesis/src/lib.rs +++ b/genesis/src/lib.rs @@ -358,8 +358,8 @@ mod tests { fn load_new_genesis_block() -> Result<()> { let chain_id = ChainId::new("0"); - let genesis_key_pair = KeyPair::generate()?; - let (alice_public_key, _) = KeyPair::generate()?.into(); + let genesis_key_pair = KeyPair::generate(); + let (alice_public_key, _) = KeyPair::generate().into(); let _genesis_block = GenesisNetwork::new( RawGenesisBlockBuilder::default() diff --git a/p2p/tests/integration/p2p.rs b/p2p/tests/integration/p2p.rs index 0b45a35cc70..61acb9ddaa0 100644 --- a/p2p/tests/integration/p2p.rs +++ b/p2p/tests/integration/p2p.rs @@ -46,7 +46,7 @@ async fn network_create() { setup_logger(); info!("Starting network tests..."); let address = socket_addr!(127.0.0.1:12_000); - let key_pair = KeyPair::generate().unwrap(); + let key_pair = KeyPair::generate(); let public_key = key_pair.public_key().clone(); let network = NetworkHandle::start(address.clone(), key_pair) .await @@ -150,9 +150,9 @@ impl TestActor { async fn two_networks() { let delay = Duration::from_millis(300); setup_logger(); - let key_pair1 = KeyPair::generate().unwrap(); + let key_pair1 = KeyPair::generate(); let public_key1 = key_pair1.public_key().clone(); - let key_pair2 = KeyPair::generate().unwrap().clone(); + let key_pair2 = KeyPair::generate().clone(); let public_key2 = key_pair2.public_key().clone(); info!("Starting first network..."); let address1 = socket_addr!(127.0.0.1:12_005); @@ -226,7 +226,7 @@ async fn multiple_networks() { let mut key_pairs = Vec::new(); for i in 0_u16..10_u16 { let address = socket_addr!(127.0.0.1: 12_015 + ( i * 5)); - let key_pair = KeyPair::generate().unwrap(); + let key_pair = KeyPair::generate(); let public_key = key_pair.public_key().clone(); peers.push(PeerId::new(address, public_key)); key_pairs.push(key_pair); diff --git a/tools/kagami/src/genesis.rs b/tools/kagami/src/genesis.rs index c679e4c01b0..b873dd85c4c 100644 --- a/tools/kagami/src/genesis.rs +++ b/tools/kagami/src/genesis.rs @@ -226,7 +226,7 @@ fn generate_synthetic( let mut domain_builder = builder.domain(format!("domain_{domain}").parse()?); for account in 0..accounts_per_domain { - let (public_key, _) = iroha_crypto::KeyPair::generate()?.into(); + let (public_key, _) = iroha_crypto::KeyPair::generate().into(); domain_builder = domain_builder.account(format!("account_{account}").parse()?, public_key); } diff --git a/tools/swarm/src/compose.rs b/tools/swarm/src/compose.rs index edc8b972d46..7fdf3b0997c 100644 --- a/tools/swarm/src/compose.rs +++ b/tools/swarm/src/compose.rs @@ -666,7 +666,7 @@ mod tests { #[test] fn default_config_with_swarm_env_is_exhaustive() { - let keypair = KeyPair::generate().unwrap(); + let keypair = KeyPair::generate(); let env: TestEnv = CompactPeerEnv { chain_id: ChainId::new("00000000-0000-0000-0000-000000000000"), key_pair: keypair.clone(),