diff --git a/applications/minotari_merge_mining_proxy/src/block_template_protocol.rs b/applications/minotari_merge_mining_proxy/src/block_template_protocol.rs index ed6fc12446..5ffff16c9f 100644 --- a/applications/minotari_merge_mining_proxy/src/block_template_protocol.rs +++ b/applications/minotari_merge_mining_proxy/src/block_template_protocol.rs @@ -63,7 +63,7 @@ impl<'a> BlockTemplateProtocol<'a> { consensus_manager: ConsensusManager, wallet_payment_address: TariAddress, ) -> Result, MmProxyError> { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager()?; Ok(Self { config, base_node_client, diff --git a/applications/minotari_miner/src/run_miner.rs b/applications/minotari_miner/src/run_miner.rs index 9f678c9b89..d986276ef9 100644 --- a/applications/minotari_miner/src/run_miner.rs +++ b/applications/minotari_miner/src/run_miner.rs @@ -84,7 +84,12 @@ pub async fn start_miner(cli: Cli) -> Result<(), ExitError> { config.set_base_path(cli.common.get_base_path()); debug!(target: LOG_TARGET_FILE, "{:?}", config); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().map_err(|err| { + ExitError::new( + ExitCode::KeyManagerServiceError, + "'wallet_payment_address' ".to_owned() + &err.to_string(), + ) + })?; let wallet_payment_address = wallet_payment_address(config.wallet_payment_address.clone(), config.network) .map_err(|err| { ExitError::new( diff --git a/applications/minotari_node/src/grpc/base_node_grpc_server.rs b/applications/minotari_node/src/grpc/base_node_grpc_server.rs index 74484f5652..e102404b08 100644 --- a/applications/minotari_node/src/grpc/base_node_grpc_server.rs +++ b/applications/minotari_node/src/grpc/base_node_grpc_server.rs @@ -827,7 +827,12 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer { prev_coinbase_value = u128::from(coinbase.value); } - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().map_err(|e| { + obscure_error_if_true( + report_error_flag, + Status::internal(format!("Key manager error: '{}'", e)), + ) + })?; let height = new_template.header.height; // The script key is not used in the Diffie-Hellmann protocol, so we assign default. let script_key_id = TariKeyId::default(); @@ -1022,7 +1027,9 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer { Status::invalid_argument("Malformed coinbase amounts".to_string()), )); } - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().map_err(|s| { + obscure_error_if_true(report_error_flag, Status::internal(format!("Key manager error: {}", s))) + })?; let height = block_template.header.height; // The script key is not used in the Diffie-Hellmann protocol, so we assign default. let script_key_id = TariKeyId::default(); diff --git a/base_layer/core/benches/mempool.rs b/base_layer/core/benches/mempool.rs index 7bf8393368..511e8f1905 100644 --- a/base_layer/core/benches/mempool.rs +++ b/base_layer/core/benches/mempool.rs @@ -54,7 +54,7 @@ mod benches { num_outputs: usize, features: OutputFeatures, ) -> std::io::Result>> { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let mut txs = Vec::new(); for _ in 0..num_txs { let (tx, _, _) = diff --git a/base_layer/core/src/blocks/faucets/mod.rs b/base_layer/core/src/blocks/faucets/mod.rs index bb9164ca95..05d463172d 100644 --- a/base_layer/core/src/blocks/faucets/mod.rs +++ b/base_layer/core/src/blocks/faucets/mod.rs @@ -72,7 +72,7 @@ mod test { ) -> (Vec, TransactionKernel) { let mut list_of_spend_keys = Vec::new(); let mut total_script_key = PublicKey::default(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); for address in &addresses { list_of_spend_keys.push(address.public_spend_key().clone()); total_script_key = total_script_key + address.public_spend_key(); diff --git a/base_layer/core/src/chain_storage/tests/blockchain_database.rs b/base_layer/core/src/chain_storage/tests/blockchain_database.rs index dd18656bc6..26ce2024c7 100644 --- a/base_layer/core/src/chain_storage/tests/blockchain_database.rs +++ b/base_layer/core/src/chain_storage/tests/blockchain_database.rs @@ -127,7 +127,7 @@ mod fetch_blocks { #[tokio::test] async fn it_returns_all() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); add_many_chained_blocks(4, &db, &key_manager).await; let blocks = db.fetch_blocks(.., true).unwrap(); assert_eq!(blocks.len(), 5); @@ -139,7 +139,7 @@ mod fetch_blocks { #[tokio::test] async fn it_returns_one() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (new_blocks, _) = add_many_chained_blocks(1, &db, &key_manager).await; let blocks = db.fetch_blocks(1..=1, true).unwrap(); assert_eq!(blocks.len(), 1); @@ -149,7 +149,7 @@ mod fetch_blocks { #[tokio::test] async fn it_returns_nothing_if_asking_for_blocks_out_of_range() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); add_many_chained_blocks(1, &db, &key_manager).await; let blocks = db.fetch_blocks(2.., true).unwrap(); assert!(blocks.is_empty()); @@ -158,7 +158,7 @@ mod fetch_blocks { #[tokio::test] async fn it_returns_blocks_between_bounds_exclusive() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); add_many_chained_blocks(5, &db, &key_manager).await; let blocks = db.fetch_blocks(3..5, true).unwrap(); assert_eq!(blocks.len(), 2); @@ -169,7 +169,7 @@ mod fetch_blocks { #[tokio::test] async fn it_returns_blocks_between_bounds_inclusive() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); add_many_chained_blocks(5, &db, &key_manager).await; let blocks = db.fetch_blocks(3..=5, true).unwrap(); assert_eq!(blocks.len(), 3); @@ -181,7 +181,7 @@ mod fetch_blocks { #[tokio::test] async fn it_returns_blocks_to_the_tip() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); add_many_chained_blocks(5, &db, &key_manager).await; let blocks = db.fetch_blocks(3.., true).unwrap(); assert_eq!(blocks.len(), 3); @@ -193,7 +193,7 @@ mod fetch_blocks { #[tokio::test] async fn it_returns_blocks_from_genesis() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); add_many_chained_blocks(5, &db, &key_manager).await; let blocks = db.fetch_blocks(..=3, true).unwrap(); assert_eq!(blocks.len(), 4); @@ -224,7 +224,7 @@ mod fetch_headers { #[tokio::test] async fn it_returns_all() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); add_many_chained_blocks(4, &db, &key_manager).await; let headers = db.fetch_headers(..).unwrap(); assert_eq!(headers.len(), 5); @@ -236,7 +236,7 @@ mod fetch_headers { #[tokio::test] async fn it_returns_nothing_if_asking_for_blocks_out_of_range() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); add_many_chained_blocks(1, &db, &key_manager).await; let headers = db.fetch_headers(2..).unwrap(); assert!(headers.is_empty()); @@ -245,7 +245,7 @@ mod fetch_headers { #[tokio::test] async fn it_returns_blocks_between_bounds_exclusive() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); add_many_chained_blocks(5, &db, &key_manager).await; let headers = db.fetch_headers(3..5).unwrap(); assert_eq!(headers.len(), 2); @@ -256,7 +256,7 @@ mod fetch_headers { #[tokio::test] async fn it_returns_blocks_between_bounds_inclusive() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); add_many_chained_blocks(5, &db, &key_manager).await; let headers = db.fetch_headers(3..=5).unwrap(); assert_eq!(headers.len(), 3); @@ -267,7 +267,7 @@ mod fetch_headers { #[tokio::test] async fn it_returns_blocks_to_the_tip() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); add_many_chained_blocks(5, &db, &key_manager).await; let headers = db.fetch_headers(3..).unwrap(); assert_eq!(headers.len(), 3); @@ -279,7 +279,7 @@ mod fetch_headers { #[tokio::test] async fn it_returns_blocks_from_genesis() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); add_many_chained_blocks(5, &db, &key_manager).await; let headers = db.fetch_headers(..=3).unwrap(); assert_eq!(headers.len(), 4); @@ -307,7 +307,7 @@ mod find_headers_after_hash { async fn it_returns_from_genesis() { let db = setup(); let genesis_hash = db.fetch_block(0, true).unwrap().block().hash(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); add_many_chained_blocks(1, &db, &key_manager).await; let hashes = vec![genesis_hash]; let (index, headers) = db.find_headers_after_hash(hashes, 1).unwrap().unwrap(); @@ -318,7 +318,7 @@ mod find_headers_after_hash { #[tokio::test] async fn it_returns_the_first_headers_found() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); add_many_chained_blocks(5, &db, &key_manager).await; let hashes = (1..=3) .rev() @@ -334,7 +334,7 @@ mod find_headers_after_hash { async fn fnit_ignores_unknown_hashes() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); add_many_chained_blocks(5, &db, &key_manager).await; let hashes = (2..=4) .map(|i| db.fetch_block(i, true).unwrap().block().hash()) @@ -362,7 +362,7 @@ mod fetch_block_hashes_from_header_tip { #[tokio::test] async fn it_returns_empty_set_for_big_offset() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); add_many_chained_blocks(5, &db, &key_manager).await; let hashes = db.fetch_block_hashes_from_header_tip(3, 6).unwrap(); assert!(hashes.is_empty()); @@ -371,7 +371,7 @@ mod fetch_block_hashes_from_header_tip { #[tokio::test] async fn it_returns_n_hashes_from_tip() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (blocks, _) = add_many_chained_blocks(5, &db, &key_manager).await; let hashes = db.fetch_block_hashes_from_header_tip(3, 1).unwrap(); assert_eq!(hashes.len(), 3); @@ -383,7 +383,7 @@ mod fetch_block_hashes_from_header_tip { #[tokio::test] async fn it_returns_hashes_without_overlapping() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (blocks, _) = add_many_chained_blocks(3, &db, &key_manager).await; let hashes = db.fetch_block_hashes_from_header_tip(2, 0).unwrap(); assert_eq!(hashes[0], blocks[2].hash()); @@ -396,7 +396,7 @@ mod fetch_block_hashes_from_header_tip { async fn it_returns_all_hashes_from_tip() { let db = setup(); let genesis = db.fetch_tip_header().unwrap(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (blocks, _) = add_many_chained_blocks(5, &db, &key_manager).await; let hashes = db.fetch_block_hashes_from_header_tip(10, 0).unwrap(); assert_eq!(hashes.len(), 6); @@ -424,7 +424,7 @@ mod fetch_total_size_stats { async fn it_measures_the_number_of_entries() { let db = setup(); let genesis_output_count = db.fetch_header(0).unwrap().unwrap().output_smt_size; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let _block_and_outputs = add_many_chained_blocks(2, &db, &key_manager).await; let stats = db.fetch_total_size_stats().unwrap(); assert_eq!( @@ -481,7 +481,7 @@ mod fetch_header_containing_kernel_mmr { async fn it_returns_corresponding_header() { let db = setup(); let genesis = db.fetch_block(0, true).unwrap(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (blocks, outputs) = add_many_chained_blocks(1, &db, &key_manager).await; let num_genesis_kernels = genesis.block().body.kernels().len() as u64; @@ -531,7 +531,7 @@ mod clear_all_pending_headers { async fn it_clears_no_headers() { let db = setup(); assert_eq!(db.clear_all_pending_headers().unwrap(), 0); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let _block_and_outputs = add_many_chained_blocks(2, &db, &key_manager).await; db.clear_all_pending_headers().unwrap(); let last_header = db.fetch_last_header().unwrap(); @@ -541,7 +541,7 @@ mod clear_all_pending_headers { #[tokio::test] async fn it_clears_headers_after_tip() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let _blocks_and_outputs = add_many_chained_blocks(2, &db, &key_manager).await; let prev_block = db.fetch_block(2, true).unwrap(); let mut prev_accum = prev_block.accumulated_data().clone(); @@ -601,7 +601,7 @@ mod validator_node_merkle_root { #[tokio::test] async fn it_has_the_correct_genesis_merkle_root() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let vn_mmr = ValidatorNodeBMT::create(Vec::new()); let db = setup(); let (blocks, _outputs) = add_many_chained_blocks(1, &db, &key_manager).await; @@ -611,7 +611,7 @@ mod validator_node_merkle_root { #[tokio::test] async fn it_has_the_correct_merkle_root_for_current_vn_set() { let db = setup(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (blocks, outputs) = add_many_chained_blocks(1, &db, &key_manager).await; let (sk, public_key) = PublicKey::random_keypair(&mut OsRng); diff --git a/base_layer/core/src/covenants/covenant.rs b/base_layer/core/src/covenants/covenant.rs index b9fc7ebf12..e010780f9d 100644 --- a/base_layer/core/src/covenants/covenant.rs +++ b/base_layer/core/src/covenants/covenant.rs @@ -194,7 +194,7 @@ mod test { #[tokio::test] async fn it_succeeds_when_empty() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let outputs = create_outputs(10, UtxoTestParams::default(), &key_manager).await; let input = create_input(&key_manager).await; let covenant = covenant!(); @@ -204,7 +204,7 @@ mod test { #[tokio::test] async fn it_executes_the_covenant() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let mut outputs = create_outputs(10, UtxoTestParams::default(), &key_manager).await; outputs[4].features.maturity = 42; outputs[5].features.maturity = 42; @@ -221,7 +221,7 @@ mod test { #[tokio::test] async fn test_borsh_de_serialization() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let mut outputs = create_outputs(10, UtxoTestParams::default(), &key_manager).await; outputs[4].features.maturity = 42; outputs[5].features.maturity = 42; diff --git a/base_layer/core/src/covenants/fields.rs b/base_layer/core/src/covenants/fields.rs index 12e80b172d..84ec22028a 100644 --- a/base_layer/core/src/covenants/fields.rs +++ b/base_layer/core/src/covenants/fields.rs @@ -401,7 +401,7 @@ mod test { #[tokio::test] async fn it_returns_true_if_eq() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let side_chain_features = make_sample_sidechain_feature(); let output = create_outputs( 1, @@ -444,7 +444,7 @@ mod test { #[tokio::test] async fn it_returns_false_if_not_eq() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let side_chain_features = make_sample_sidechain_feature(); let output = create_outputs( 1, @@ -495,7 +495,7 @@ mod test { #[tokio::test] async fn it_returns_true_if_eq_input() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let output = create_outputs( 1, UtxoTestParams { @@ -572,7 +572,7 @@ mod test { #[tokio::test] async fn it_constructs_challenge_using_consensus_encoding() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let features = OutputFeatures { maturity: 42, output_type: OutputType::Coinbase, @@ -620,7 +620,7 @@ mod test { #[tokio::test] async fn it_retrieves_the_value_as_ref() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let features = OutputFeatures { maturity: 42, range_proof_type: RangeProofType::RevealedValue, diff --git a/base_layer/core/src/covenants/filters/absolute_height.rs b/base_layer/core/src/covenants/filters/absolute_height.rs index a01cfd3955..14a2b6be04 100644 --- a/base_layer/core/src/covenants/filters/absolute_height.rs +++ b/base_layer/core/src/covenants/filters/absolute_height.rs @@ -72,7 +72,7 @@ mod test { #[tokio::test] async fn it_filters_all_out_if_height_not_reached() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let covenant = covenant!(absolute_height(@uint(100))); let input = create_input(&key_manager).await; let (mut context, outputs) = setup_filter_test(&covenant, &input, 42, |_| {}, &key_manager).await; @@ -85,7 +85,7 @@ mod test { #[tokio::test] async fn it_filters_all_in_if_height_reached() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let covenant = covenant!(absolute_height(@uint(100))); let input = create_input(&key_manager).await; let (mut context, outputs) = setup_filter_test(&covenant, &input, 100, |_| {}, &key_manager).await; @@ -98,7 +98,7 @@ mod test { #[tokio::test] async fn it_filters_all_in_if_height_exceeded() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let covenant = covenant!(absolute_height(@uint(42))); let input = create_input(&key_manager).await; let (mut context, outputs) = setup_filter_test(&covenant, &input, 100, |_| {}, &key_manager).await; diff --git a/base_layer/core/src/covenants/filters/and.rs b/base_layer/core/src/covenants/filters/and.rs index 857ae2a5b0..846cc8f56d 100644 --- a/base_layer/core/src/covenants/filters/and.rs +++ b/base_layer/core/src/covenants/filters/and.rs @@ -53,7 +53,7 @@ mod test { #[tokio::test] async fn it_filters_outputset_using_intersection() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let script = script!(CheckHeight(101)); let covenant = covenant!(and(field_eq(@field::features_maturity, @uint(42),), field_eq(@field::script, @script(script.clone())))); let input = create_input(&key_manager).await; diff --git a/base_layer/core/src/covenants/filters/field_eq.rs b/base_layer/core/src/covenants/filters/field_eq.rs index 51e512e177..7824d4bc31 100644 --- a/base_layer/core/src/covenants/filters/field_eq.rs +++ b/base_layer/core/src/covenants/filters/field_eq.rs @@ -90,7 +90,7 @@ mod test { #[tokio::test] async fn it_filters_uint() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let covenant = covenant!(field_eq(@field::features_maturity, @uint(42))); let input = create_input(&key_manager).await; let mut context = create_context(&covenant, &input, 0); @@ -108,7 +108,7 @@ mod test { #[tokio::test] async fn it_filters_sender_offset_public_key() { let pk = PublicKey::from_hex("5615a327e1d19da34e5aa8bbd2ecc97addf29b158844b885bfc4efa0dab17052").unwrap(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let covenant = covenant!(field_eq( @field::sender_offset_public_key, @public_key(pk.clone()) @@ -128,7 +128,7 @@ mod test { #[tokio::test] async fn it_filters_commitment() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let commitment = Commitment::from_hex("7ca31ba517d8b563609ed6707fedde5a2be64ac1d67b254cb5348bc2f680557f").unwrap(); let covenant = covenant!(field_eq( @@ -151,7 +151,7 @@ mod test { #[tokio::test] async fn it_filters_tari_script() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let script = script!(CheckHeight(100)); let covenant = covenant!(field_eq( @field::script, @@ -173,7 +173,7 @@ mod test { #[tokio::test] async fn it_filters_covenant() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let next_cov = covenant!(and(identity(), or(field_eq(@field::features_maturity, @uint(42))))); let covenant = covenant!(field_eq(@field::covenant, @covenant(next_cov.clone()))); let input = create_input(&key_manager).await; @@ -192,7 +192,7 @@ mod test { #[tokio::test] async fn it_filters_output_type() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let covenant = covenant!(field_eq(@field::features_output_type, @output_type(Coinbase))); let input = create_input(&key_manager).await; let mut context = create_context(&covenant, &input, 0); @@ -210,7 +210,7 @@ mod test { #[tokio::test] async fn it_errors_if_field_has_an_incorrect_type() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let covenant = covenant!(field_eq(@field::features, @uint(42))); let input = create_input(&key_manager).await; let mut context = create_context(&covenant, &input, 0); diff --git a/base_layer/core/src/covenants/filters/fields_hashed_eq.rs b/base_layer/core/src/covenants/filters/fields_hashed_eq.rs index c9c1fe40d7..d7502ac141 100644 --- a/base_layer/core/src/covenants/filters/fields_hashed_eq.rs +++ b/base_layer/core/src/covenants/filters/fields_hashed_eq.rs @@ -62,7 +62,7 @@ mod test { #[tokio::test] async fn it_filters_outputs_with_fields_that_hash_to_given_hash() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let features = OutputFeatures { maturity: 42, sidechain_feature: Some(make_sample_sidechain_feature()), diff --git a/base_layer/core/src/covenants/filters/fields_preserved.rs b/base_layer/core/src/covenants/filters/fields_preserved.rs index 06caf4881f..2d7dc6c92b 100644 --- a/base_layer/core/src/covenants/filters/fields_preserved.rs +++ b/base_layer/core/src/covenants/filters/fields_preserved.rs @@ -50,7 +50,7 @@ mod test { #[tokio::test] async fn it_filters_outputs_that_match_input_fields() { let covenant = covenant!(fields_preserved(@fields(@field::features_maturity, @field::features_output_type))); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let mut input = create_input(&key_manager).await; input.set_maturity(42).unwrap(); input.features_mut().unwrap().output_type = OutputType::ValidatorNodeRegistration; diff --git a/base_layer/core/src/covenants/filters/identity.rs b/base_layer/core/src/covenants/filters/identity.rs index 88d1e5c03d..13f85394ee 100644 --- a/base_layer/core/src/covenants/filters/identity.rs +++ b/base_layer/core/src/covenants/filters/identity.rs @@ -44,7 +44,7 @@ mod tests { #[tokio::test] async fn it_returns_the_outputset_unchanged() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let covenant = covenant!(identity()); let input = create_input(&key_manager).await; let (mut context, outputs) = setup_filter_test(&covenant, &input, 0, |_| {}, &key_manager).await; diff --git a/base_layer/core/src/covenants/filters/not.rs b/base_layer/core/src/covenants/filters/not.rs index 811b18854e..9f1d5017d5 100644 --- a/base_layer/core/src/covenants/filters/not.rs +++ b/base_layer/core/src/covenants/filters/not.rs @@ -50,7 +50,7 @@ mod test { #[tokio::test] async fn it_filters_compliment_of_filter() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let script = script!(CheckHeight(100)); let covenant = covenant!(not(or(field_eq(@field::features_maturity, @uint(42),), field_eq(@field::script, @script(script.clone()))))); let input = create_input(&key_manager).await; diff --git a/base_layer/core/src/covenants/filters/or.rs b/base_layer/core/src/covenants/filters/or.rs index 6401ce4bc3..6849b2c0b0 100644 --- a/base_layer/core/src/covenants/filters/or.rs +++ b/base_layer/core/src/covenants/filters/or.rs @@ -56,7 +56,7 @@ mod test { #[tokio::test] async fn it_filters_outputset_using_union() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let script = script!(CheckHeight(100)); let covenant = covenant!(or(field_eq(@field::features_maturity, @uint(42),), field_eq(@field::script, @script(script.clone())))); let input = create_input(&key_manager).await; diff --git a/base_layer/core/src/covenants/filters/output_hash_eq.rs b/base_layer/core/src/covenants/filters/output_hash_eq.rs index 82c02117b3..0a4f5542f9 100644 --- a/base_layer/core/src/covenants/filters/output_hash_eq.rs +++ b/base_layer/core/src/covenants/filters/output_hash_eq.rs @@ -52,7 +52,7 @@ mod test { #[tokio::test] async fn it_filters_output_with_specific_hash() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let output = create_outputs(1, Default::default(), &key_manager).await.remove(0); let output_hash = output.hash(); let mut hash = [0u8; 32]; diff --git a/base_layer/core/src/covenants/filters/xor.rs b/base_layer/core/src/covenants/filters/xor.rs index 5ffa78c50f..75d6ffc467 100644 --- a/base_layer/core/src/covenants/filters/xor.rs +++ b/base_layer/core/src/covenants/filters/xor.rs @@ -58,7 +58,7 @@ mod test { #[tokio::test] async fn it_filters_outputset_using_symmetric_difference() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let script = script!(CheckHeight(100)); let covenant = covenant!(and(field_eq(@field::features_maturity, @uint(42),), field_eq(@field::script, @script(script.clone())))); let input = create_input(&key_manager).await; diff --git a/base_layer/core/src/mempool/priority/prioritized_transaction.rs b/base_layer/core/src/mempool/priority/prioritized_transaction.rs index e3fb1664eb..f32501b004 100644 --- a/base_layer/core/src/mempool/priority/prioritized_transaction.rs +++ b/base_layer/core/src/mempool/priority/prioritized_transaction.rs @@ -144,7 +144,7 @@ mod tests { #[tokio::test] async fn fee_increases_priority() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let weighting = TransactionWeight::latest(); let epoch = u64::MAX / 2; let tx = create_tx_with_fee(2 * uT, &key_manager).await; @@ -158,7 +158,7 @@ mod tests { #[tokio::test] async fn age_increases_priority() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let weighting = TransactionWeight::latest(); let epoch = u64::MAX / 2; let tx = create_tx_with_fee(2 * uT, &key_manager).await; diff --git a/base_layer/core/src/mempool/reorg_pool/reorg_pool.rs b/base_layer/core/src/mempool/reorg_pool/reorg_pool.rs index b3b11e94c6..eab697378c 100644 --- a/base_layer/core/src/mempool/reorg_pool/reorg_pool.rs +++ b/base_layer/core/src/mempool/reorg_pool/reorg_pool.rs @@ -349,7 +349,7 @@ mod test { #[tokio::test] async fn test_insert_expire_by_height() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let tx1 = Arc::new( tx!(MicroMinotari(100_000), fee: MicroMinotari(100), lock: 4000, inputs: 2, outputs: 1, &key_manager) .expect("Failed to get tx") @@ -409,7 +409,7 @@ mod test { #[tokio::test] async fn test_remove_all() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let tx1 = Arc::new( tx!(MicroMinotari(100_000), fee: MicroMinotari(100), lock: 4000, inputs: 2, outputs: 1, &key_manager) .expect("Failed to get tx") @@ -446,7 +446,7 @@ mod test { #[tokio::test] async fn remove_scan_for_and_remove_reorged_txs() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let network = Network::LocalNet; let consensus = ConsensusManagerBuilder::new(network).build().unwrap(); let tx1 = Arc::new( diff --git a/base_layer/core/src/mempool/sync_protocol/test.rs b/base_layer/core/src/mempool/sync_protocol/test.rs index 47b4719a86..b075649e36 100644 --- a/base_layer/core/src/mempool/sync_protocol/test.rs +++ b/base_layer/core/src/mempool/sync_protocol/test.rs @@ -61,7 +61,7 @@ use crate::{ }; pub async fn create_transactions(n: usize) -> Vec { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let mut transactions = Vec::new(); for _i in 0..n { let (transaction, _, _) = create_tx(5000 * uT, 3 * uT, 1, 2, 1, 3, Default::default(), &key_manager) diff --git a/base_layer/core/src/mempool/unconfirmed_pool/unconfirmed_pool.rs b/base_layer/core/src/mempool/unconfirmed_pool/unconfirmed_pool.rs index bb7edfce04..3876b3456c 100644 --- a/base_layer/core/src/mempool/unconfirmed_pool/unconfirmed_pool.rs +++ b/base_layer/core/src/mempool/unconfirmed_pool/unconfirmed_pool.rs @@ -882,7 +882,7 @@ mod test { #[tokio::test] async fn test_find_duplicate_input() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let tx1 = Arc::new( tx!(MicroMinotari(5000), fee: MicroMinotari(50), inputs: 2, outputs: 1, &key_manager) .expect("Failed to get tx") @@ -911,7 +911,7 @@ mod test { #[tokio::test] async fn test_insert_and_retrieve_highest_priority_txs() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let tx1 = Arc::new( tx!(MicroMinotari(5_000), fee: MicroMinotari(5), inputs: 2, outputs: 1, &key_manager) .expect("Failed to get tx") @@ -974,7 +974,7 @@ mod test { #[tokio::test] async fn test_double_spend_inputs() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (tx1, _, _) = tx!(MicroMinotari(5_000), fee: MicroMinotari(10), inputs: 1, outputs: 1, &key_manager) .expect("Failed to get tx"); const INPUT_AMOUNT: MicroMinotari = MicroMinotari(5_000); @@ -1061,7 +1061,7 @@ mod test { #[tokio::test] async fn test_remove_reorg_txs() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let network = Network::LocalNet; let consensus = ConsensusManagerBuilder::new(network).build().unwrap(); let tx1 = Arc::new( @@ -1133,7 +1133,7 @@ mod test { #[tokio::test] async fn test_discard_double_spend_txs() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let consensus = create_consensus_rules(); let tx1 = Arc::new( tx!(MicroMinotari(5_000), fee: MicroMinotari(5), inputs:2, outputs:1, &key_manager) @@ -1208,7 +1208,7 @@ mod test { #[tokio::test] async fn test_multiple_transactions_with_same_outputs_in_mempool() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (tx1, _, _) = tx!(MicroMinotari(150_000), fee: MicroMinotari(50), inputs:5, outputs:5, &key_manager) .expect("Failed to get tx"); let (tx2, _, _) = tx!(MicroMinotari(250_000), fee: MicroMinotari(50), inputs:5, outputs:5, &key_manager) @@ -1311,7 +1311,7 @@ mod test { #[tokio::test] async fn it_compiles_correct_stats_for_single_block() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (tx1, _, _) = tx!(MicroMinotari(150_000), fee: MicroMinotari(5), inputs:5, outputs:1, &key_manager) .expect("Failed to get tx"); let (tx2, _, _) = tx!(MicroMinotari(250_000), fee: MicroMinotari(5), inputs:5, outputs:5, &key_manager) @@ -1341,7 +1341,7 @@ mod test { #[tokio::test] async fn it_compiles_correct_stats_for_multiple_blocks() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let expected_stats = [ FeePerGramStat { order: 0, diff --git a/base_layer/core/src/test_helpers/blockchain.rs b/base_layer/core/src/test_helpers/blockchain.rs index a347982bf0..91bbb03219 100644 --- a/base_layer/core/src/test_helpers/blockchain.rs +++ b/base_layer/core/src/test_helpers/blockchain.rs @@ -437,7 +437,7 @@ pub async fn create_chained_blocks>( let mut block_hashes = HashMap::new(); block_hashes.insert("GB".to_string(), genesis_block); let rules = ConsensusManager::builder(Network::LocalNet).build().unwrap(); - let km = create_memory_db_key_manager(); + let km = create_memory_db_key_manager().unwrap(); let blocks: BlockSpecs = blocks.into(); let mut block_names = Vec::with_capacity(blocks.len()); let (script_key_id, wallet_payment_address) = default_coinbase_entities(&km).await; @@ -550,7 +550,7 @@ impl TestBlockchain { .try_into_chain_block() .map(Arc::new) .unwrap(); - let km = create_memory_db_key_manager(); + let km = create_memory_db_key_manager().unwrap(); let (script_key_id, wallet_payment_address) = default_coinbase_entities(&km).await; let mut blockchain = Self { db, diff --git a/base_layer/core/src/transactions/coinbase_builder.rs b/base_layer/core/src/transactions/coinbase_builder.rs index 1948a4df14..9a3600b194 100644 --- a/base_layer/core/src/transactions/coinbase_builder.rs +++ b/base_layer/core/src/transactions/coinbase_builder.rs @@ -528,7 +528,7 @@ mod test { ) { let network = Network::LocalNet; let rules = ConsensusManagerBuilder::new(network).build().unwrap(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let factories = CryptoFactories::default(); (CoinbaseBuilder::new(key_manager.clone()), rules, factories, key_manager) } diff --git a/base_layer/core/src/transactions/key_manager/memory_db_key_manager.rs b/base_layer/core/src/transactions/key_manager/memory_db_key_manager.rs index 6bfd384d10..1518dfb546 100644 --- a/base_layer/core/src/transactions/key_manager/memory_db_key_manager.rs +++ b/base_layer/core/src/transactions/key_manager/memory_db_key_manager.rs @@ -28,8 +28,12 @@ use tari_common_sqlite::connection::{DbConnection, DbConnectionUrl}; use tari_common_types::wallet_types::WalletType; use tari_key_manager::{ cipher_seed::CipherSeed, - key_manager_service::storage::{database::KeyManagerDatabase, sqlite_db::KeyManagerSqliteDatabase}, + key_manager_service::{ + storage::{database::KeyManagerDatabase, sqlite_db::KeyManagerSqliteDatabase}, + KeyManagerServiceError, + }, }; +use zeroize::Zeroizing; use crate::transactions::{key_manager::TransactionKeyManagerWrapper, CryptoFactories}; @@ -42,25 +46,25 @@ fn random_string(len: usize) -> String { .collect() } -pub fn create_memory_db_key_manager_with_range_proof_size(size: usize) -> MemoryDbKeyManager { - let connection = DbConnection::connect_url(&DbConnectionUrl::MemoryShared(random_string(8))).unwrap(); +pub fn create_memory_db_key_manager_with_range_proof_size( + size: usize, +) -> Result { + let connection = DbConnection::connect_url(&DbConnectionUrl::MemoryShared(random_string(8)))?; let cipher = CipherSeed::new(); - let mut key = [0u8; size_of::()]; - OsRng.fill_bytes(&mut key); - let key_ga = Key::from_slice(&key); + let mut key = Zeroizing::new([0u8; size_of::()]); + OsRng.fill_bytes(key.as_mut()); + let key_ga = Key::from_slice(key.as_ref()); let db_cipher = XChaCha20Poly1305::new(key_ga); let factory = CryptoFactories::new(size); - TransactionKeyManagerWrapper::>::new( cipher, KeyManagerDatabase::new(KeyManagerSqliteDatabase::init(connection, db_cipher)), factory, WalletType::default(), ) - .unwrap() } -pub fn create_memory_db_key_manager() -> MemoryDbKeyManager { +pub fn create_memory_db_key_manager() -> Result { create_memory_db_key_manager_with_range_proof_size(64) } diff --git a/base_layer/core/src/transactions/test_helpers.rs b/base_layer/core/src/transactions/test_helpers.rs index 610233dbeb..4dbe8b10f6 100644 --- a/base_layer/core/src/transactions/test_helpers.rs +++ b/base_layer/core/src/transactions/test_helpers.rs @@ -334,7 +334,7 @@ pub async fn create_coinbase_wallet_output( range_proof_type: RangeProofType, ) -> WalletOutput { let rules = create_consensus_manager(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let constants = rules.consensus_constants(height); test_params .create_output( diff --git a/base_layer/core/src/transactions/transaction_components/test.rs b/base_layer/core/src/transactions/transaction_components/test.rs index 48edf69cfd..b4bd6271a9 100644 --- a/base_layer/core/src/transactions/transaction_components/test.rs +++ b/base_layer/core/src/transactions/transaction_components/test.rs @@ -59,7 +59,7 @@ use crate::{ #[tokio::test] async fn input_and_output_and_wallet_output_hash_match() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let test_params = TestParams::new(&key_manager).await; let i = test_params @@ -83,7 +83,7 @@ fn test_smt_hashes() { #[tokio::test] async fn key_manager_input() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let test_params = TestParams::new(&key_manager).await; let i = test_params @@ -108,7 +108,7 @@ async fn key_manager_input() { #[tokio::test] async fn range_proof_verification() { let factories = CryptoFactories::new(32); - let key_manager = create_memory_db_key_manager_with_range_proof_size(32); + let key_manager = create_memory_db_key_manager_with_range_proof_size(32).unwrap(); // Directly test the tx_output verification let test_params_1 = TestParams::new(&key_manager).await; let test_params_2 = TestParams::new(&key_manager).await; @@ -168,7 +168,7 @@ async fn range_proof_verification() { #[tokio::test] async fn range_proof_verification_batch() { let factories = CryptoFactories::new(64); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let wallet_output1 = TestParams::new(&key_manager) .await .create_output( @@ -259,7 +259,7 @@ async fn range_proof_verification_batch() { #[tokio::test] async fn sender_signature_verification() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let test_params = TestParams::new(&key_manager).await; let wallet_output = test_params .create_output(Default::default(), &key_manager) @@ -420,7 +420,7 @@ fn check_timelocks() { #[tokio::test] async fn test_validate_internal_consistency() { let features = OutputFeatures { ..Default::default() }; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (tx, _, _) = test_helpers::create_tx(5000.into(), 3.into(), 1, 2, 1, 4, features, &key_manager) .await .expect("Failed to create tx"); @@ -433,7 +433,7 @@ async fn test_validate_internal_consistency() { #[tokio::test] #[allow(clippy::identity_op)] async fn check_cut_through() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (tx, _, outputs) = test_helpers::create_tx(50000000.into(), 3.into(), 1, 2, 1, 2, Default::default(), &key_manager) .await @@ -490,7 +490,7 @@ async fn check_cut_through() { #[tokio::test] async fn check_duplicate_inputs_outputs() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (tx, _, _outputs) = test_helpers::create_tx(50000000.into(), 3.into(), 1, 2, 1, 2, Default::default(), &key_manager) .await @@ -513,7 +513,7 @@ async fn check_duplicate_inputs_outputs() { #[tokio::test] async fn inputs_not_malleable() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (inputs, outputs) = test_helpers::create_wallet_outputs( 5000.into(), 1, @@ -548,7 +548,7 @@ async fn inputs_not_malleable() { #[tokio::test] async fn test_output_recover_openings() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let test_params = TestParams::new(&key_manager).await; let v = MicroMinotari::from(42); @@ -621,7 +621,7 @@ mod validate_internal_consistency { //---------------------------------- Case1 - PASS --------------------------------------------// let covenant = covenant!(fields_preserved(@fields( @field::covenant))); let features = OutputFeatures { ..Default::default() }; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); test_case( &UtxoTestParams { features: features.clone(), diff --git a/base_layer/core/src/transactions/transaction_components/transaction_output.rs b/base_layer/core/src/transactions/transaction_components/transaction_output.rs index 74fe70228c..9099603da9 100644 --- a/base_layer/core/src/transactions/transaction_components/transaction_output.rs +++ b/base_layer/core/src/transactions/transaction_components/transaction_output.rs @@ -584,7 +584,7 @@ mod test { #[tokio::test] async fn it_builds_correctly() { let factories = CryptoFactories::default(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let test_params = TestParams::new(&key_manager).await; let value = MicroMinotari(10); @@ -608,7 +608,7 @@ mod test { #[tokio::test] async fn it_does_not_verify_incorrect_minimum_value() { let factories = CryptoFactories::default(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let test_params = TestParams::new(&key_manager).await; let value = MicroMinotari(10); @@ -628,7 +628,7 @@ mod test { #[tokio::test] async fn it_does_batch_verify_correct_minimum_values() { let factories = CryptoFactories::default(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let test_params = TestParams::new(&key_manager).await; let outputs = [ @@ -666,7 +666,7 @@ mod test { #[tokio::test] async fn it_does_batch_verify_with_mixed_range_proof_types() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let factories = CryptoFactories::default(); let test_params = TestParams::new(&key_manager).await; @@ -714,7 +714,7 @@ mod test { #[tokio::test] async fn invalid_revealed_value_proofs_are_blocked() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let test_params = TestParams::new(&key_manager).await; assert!(create_output( &test_params, @@ -745,7 +745,7 @@ mod test { #[tokio::test] async fn revealed_value_proofs_only_succeed_with_valid_metadata_signatures() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let test_params = TestParams::new(&key_manager).await; let mut output = create_output( &test_params, @@ -772,7 +772,7 @@ mod test { #[tokio::test] async fn it_does_not_batch_verify_incorrect_minimum_values() { let factories = CryptoFactories::default(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let test_params = TestParams::new(&key_manager).await; let outputs = [ diff --git a/base_layer/core/src/transactions/transaction_components/wallet_output_builder.rs b/base_layer/core/src/transactions/transaction_components/wallet_output_builder.rs index be15c61fc8..316b903585 100644 --- a/base_layer/core/src/transactions/transaction_components/wallet_output_builder.rs +++ b/base_layer/core/src/transactions/transaction_components/wallet_output_builder.rs @@ -320,7 +320,7 @@ mod test { #[tokio::test] async fn test_try_build() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (spending_key_id, _, script_key_id, _) = key_manager.get_next_spend_and_script_key_ids().await.unwrap(); let value = MicroMinotari(100); let kmob = WalletOutputBuilder::new(value, spending_key_id.clone()); @@ -362,7 +362,7 @@ mod test { #[tokio::test] async fn test_partial_metadata_signatures() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (spending_key_id, _, script_key_id, _) = key_manager.get_next_spend_and_script_key_ids().await.unwrap(); let value = MicroMinotari(100); let kmob = WalletOutputBuilder::new(value, spending_key_id.clone()); diff --git a/base_layer/core/src/transactions/transaction_protocol/recipient.rs b/base_layer/core/src/transactions/transaction_protocol/recipient.rs index 87bd5d9182..fd72a961fa 100644 --- a/base_layer/core/src/transactions/transaction_protocol/recipient.rs +++ b/base_layer/core/src/transactions/transaction_protocol/recipient.rs @@ -199,7 +199,7 @@ mod test { #[tokio::test] async fn single_round_recipient() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let factories = CryptoFactories::default(); let sender_test_params = TestParams::new(&key_manager).await; let m = TransactionMetadata::new(MicroMinotari(125), 0); diff --git a/base_layer/core/src/transactions/transaction_protocol/sender.rs b/base_layer/core/src/transactions/transaction_protocol/sender.rs index 3ef7222f7a..04b58100ee 100644 --- a/base_layer/core/src/transactions/transaction_protocol/sender.rs +++ b/base_layer/core/src/transactions/transaction_protocol/sender.rs @@ -894,7 +894,7 @@ mod test { #[tokio::test] async fn test_errors() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let stp = SenderTransactionProtocol { state: SenderState::Failed(TransactionProtocolError::InvalidStateError), }; @@ -939,7 +939,7 @@ mod test { #[tokio::test] async fn test_metadata_signature_finalize() { // Defaults - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); // Sender data let (ephemeral_pubkey_id, ephemeral_pubkey) = key_manager @@ -1028,7 +1028,7 @@ mod test { #[tokio::test] async fn zero_recipients() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let p1 = TestParams::new(&key_manager).await; let p2 = TestParams::new(&key_manager).await; let input = create_test_input(MicroMinotari(1200), 0, &key_manager, vec![]).await; @@ -1090,7 +1090,7 @@ mod test { let rules = create_consensus_rules(); let factories = CryptoFactories::default(); // Alice's parameters - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let a_change_key = TestParams::new(&key_manager).await; // Bob's parameters let bob_key = TestParams::new(&key_manager).await; @@ -1196,7 +1196,7 @@ mod test { #[tokio::test] async fn single_recipient_with_change() { let rules = create_consensus_rules(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let factories = CryptoFactories::default(); // Alice's parameters let alice_key = TestParams::new(&key_manager).await; @@ -1310,7 +1310,7 @@ mod test { #[tokio::test] async fn single_recipient_multiple_inputs_with_change() { let rules = create_consensus_rules(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let factories = CryptoFactories::default(); // Bob's parameters let bob_key = TestParams::new(&key_manager).await; @@ -1420,7 +1420,7 @@ mod test { #[tokio::test] async fn disallow_fee_larger_than_amount() { // Alice's parameters - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (utxo_amount, fee_per_gram, amount) = (MicroMinotari(2500), MicroMinotari(10), MicroMinotari(500)); let input = create_test_input(utxo_amount, 0, &key_manager, vec![]).await; let script = script!(Nop); @@ -1458,7 +1458,7 @@ mod test { #[tokio::test] async fn allow_fee_larger_than_amount() { // Alice's parameters - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (utxo_amount, fee_per_gram, amount) = (MicroMinotari(2500), MicroMinotari(10), MicroMinotari(500)); let input = create_test_input(utxo_amount, 0, &key_manager, vec![]).await; let script = script!(Nop); @@ -1497,8 +1497,8 @@ mod test { #[tokio::test] async fn single_recipient_with_rewindable_change_and_receiver_outputs_bulletproofs() { // Alice's parameters - let key_manager_alice = create_memory_db_key_manager(); - let key_manager_bob = create_memory_db_key_manager(); + let key_manager_alice = create_memory_db_key_manager().unwrap(); + let key_manager_bob = create_memory_db_key_manager().unwrap(); // Bob's parameters let bob_test_params = TestParams::new(&key_manager_bob).await; let alice_value = MicroMinotari(25000); diff --git a/base_layer/core/src/transactions/transaction_protocol/single_receiver.rs b/base_layer/core/src/transactions/transaction_protocol/single_receiver.rs index 8d43e8ac53..efa55134d8 100644 --- a/base_layer/core/src/transactions/transaction_protocol/single_receiver.rs +++ b/base_layer/core/src/transactions/transaction_protocol/single_receiver.rs @@ -174,7 +174,7 @@ mod test { #[tokio::test] async fn zero_amount_fails() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let test_params = TestParams::new(&key_manager).await; let consensus_constants = create_consensus_constants(0); let info = SingleRoundSenderData::default(); @@ -207,7 +207,7 @@ mod test { #[tokio::test] async fn invalid_version_fails() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let test_params = TestParams::new(&key_manager).await; let consensus_constants = create_consensus_constants(0); @@ -254,7 +254,7 @@ mod test { tari_key_manager::key_manager_service::storage::sqlite_db::KeyManagerSqliteDatabase< tari_common_sqlite::connection::DbConnection, >, - > = create_memory_db_key_manager(); + > = create_memory_db_key_manager().unwrap(); let consensus_constants = create_consensus_constants(0); let m = TransactionMetadata::new(MicroMinotari(100), 0); let test_params = TestParams::new(&key_manager).await; diff --git a/base_layer/core/src/transactions/transaction_protocol/transaction_initializer.rs b/base_layer/core/src/transactions/transaction_protocol/transaction_initializer.rs index 332f560da3..32f259d5eb 100644 --- a/base_layer/core/src/transactions/transaction_protocol/transaction_initializer.rs +++ b/base_layer/core/src/transactions/transaction_protocol/transaction_initializer.rs @@ -606,7 +606,7 @@ mod test { #[tokio::test] async fn no_receivers() -> std::io::Result<()> { // Create some inputs - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let p = TestParams::new(&key_manager).await; // Start the builder let builder = SenderTransactionInitializer::new(&create_consensus_constants(0), key_manager.clone()); @@ -683,7 +683,7 @@ mod test { #[tokio::test] async fn no_change_or_receivers() { // Create some inputs - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let p = TestParams::new(&key_manager).await; let input = create_test_input(MicroMinotari(5000), 0, &key_manager, vec![]).await; let constants = create_consensus_constants(0); @@ -734,7 +734,7 @@ mod test { #[allow(clippy::identity_op)] async fn change_edge_case() { // Create some inputs - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let p = TestParams::new(&key_manager).await; let constants = create_consensus_constants(0); let weighting = constants.transaction_weight_params(); @@ -789,7 +789,7 @@ mod test { #[tokio::test] async fn too_many_inputs() { // Create some inputs - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let p = TestParams::new(&key_manager).await; let output = create_wallet_output_with_data( @@ -821,7 +821,7 @@ mod test { #[tokio::test] async fn fee_too_low() { // Create some inputs - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let p = TestParams::new(&key_manager).await; let tx_fee = p.fee().calculate( MicroMinotari(1), @@ -866,7 +866,7 @@ mod test { #[tokio::test] async fn not_enough_funds() { // Create some inputs - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let p = TestParams::new(&key_manager).await; let input = create_test_input(MicroMinotari(400), 0, &key_manager, vec![]).await; let script = script!(Nop); @@ -918,7 +918,7 @@ mod test { #[tokio::test] async fn single_recipient() { // Create some inputs - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let p = TestParams::new(&key_manager).await; let input1 = create_test_input(MicroMinotari(2000), 0, &key_manager, vec![]).await; let input2 = create_test_input(MicroMinotari(3000), 0, &key_manager, vec![]).await; diff --git a/base_layer/core/src/validation/aggregate_body/aggregate_body_internal_validator.rs b/base_layer/core/src/validation/aggregate_body/aggregate_body_internal_validator.rs index 92d1a086c9..b5e84ad8fd 100644 --- a/base_layer/core/src/validation/aggregate_body/aggregate_body_internal_validator.rs +++ b/base_layer/core/src/validation/aggregate_body/aggregate_body_internal_validator.rs @@ -515,7 +515,7 @@ mod test { let mut kernel1 = test_helpers::create_test_kernel(0.into(), 0, KernelFeatures::create_burn()); let mut kernel2 = test_helpers::create_test_kernel(0.into(), 0, KernelFeatures::create_burn()); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (output1, _, _) = test_helpers::create_utxo( 100.into(), &key_manager, @@ -577,7 +577,7 @@ mod test { // Sort the kernels, we'll check that the outputs fail the sorting check kernels.sort(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let mut outputs = futures::stream::unfold((), |_| async { let (o, _, _) = test_helpers::create_utxo( 100.into(), diff --git a/base_layer/core/src/validation/helpers.rs b/base_layer/core/src/validation/helpers.rs index 555740e268..160706defe 100644 --- a/base_layer/core/src/validation/helpers.rs +++ b/base_layer/core/src/validation/helpers.rs @@ -573,10 +573,10 @@ mod test { #[tokio::test] async fn it_succeeds_for_valid_coinbase() { let height = 1; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let test_params = TestParams::new(&key_manager).await; let rules = test_helpers::create_consensus_manager(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let coinbase = block_on(test_helpers::create_coinbase_wallet_output( &test_params, height, @@ -597,7 +597,7 @@ mod test { #[tokio::test] async fn it_returns_error_for_invalid_coinbase_maturity() { let height = 1; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let test_params = TestParams::new(&key_manager).await; let rules = test_helpers::create_consensus_manager(); let mut coinbase = @@ -621,7 +621,7 @@ mod test { #[tokio::test] async fn it_returns_error_for_invalid_coinbase_reward() { let height = 1; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let test_params = TestParams::new(&key_manager).await; let rules = test_helpers::create_consensus_manager(); let mut coinbase = test_helpers::create_coinbase_wallet_output( diff --git a/base_layer/core/src/validation/test.rs b/base_layer/core/src/validation/test.rs index b4a1748d3f..a2e7e39c7c 100644 --- a/base_layer/core/src/validation/test.rs +++ b/base_layer/core/src/validation/test.rs @@ -173,7 +173,7 @@ async fn chain_balance_validation() { let consensus_manager = ConsensusManagerBuilder::new(Network::Esmeralda).build().unwrap(); let genesis = consensus_manager.get_genesis_block(); let faucet_value = 5000 * uT; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (faucet_utxo, faucet_key_id, _) = create_utxo( faucet_value, &key_manager, @@ -356,7 +356,7 @@ async fn chain_balance_validation_burned() { let consensus_manager = ConsensusManagerBuilder::new(Network::Esmeralda).build().unwrap(); let genesis = consensus_manager.get_genesis_block(); let faucet_value = 5000 * uT; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (faucet_utxo, faucet_key_id, _) = create_utxo( faucet_value, &key_manager, @@ -514,7 +514,7 @@ mod transaction_validator { #[tokio::test] async fn it_rejects_coinbase_outputs() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let consensus_manager = ConsensusManagerBuilder::new(Network::LocalNet).build().unwrap(); let db = create_store_with_consensus(consensus_manager.clone()); let factories = CryptoFactories::default(); @@ -536,7 +536,7 @@ mod transaction_validator { #[tokio::test] async fn coinbase_extra_must_be_empty() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let consensus_manager = ConsensusManagerBuilder::new(Network::LocalNet).build().unwrap(); let db = create_store_with_consensus(consensus_manager.clone()); let factories = CryptoFactories::default(); diff --git a/base_layer/core/tests/helpers/sample_blockchains.rs b/base_layer/core/tests/helpers/sample_blockchains.rs index 0270c7d600..14badc5953 100644 --- a/base_layer/core/tests/helpers/sample_blockchains.rs +++ b/base_layer/core/tests/helpers/sample_blockchains.rs @@ -190,7 +190,7 @@ pub async fn create_new_blockchain( ConsensusManager, MemoryDbKeyManager, ) { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let consensus_constants = consensus_constants(network).build(); let (block0, output) = create_genesis_block(&consensus_constants, &key_manager).await; let consensus_manager = ConsensusManagerBuilder::new(network) @@ -219,7 +219,7 @@ pub async fn create_new_blockchain_with_constants( ConsensusManager, MemoryDbKeyManager, ) { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (block0, output) = create_genesis_block(&constants, &key_manager).await; let consensus_manager = ConsensusManagerBuilder::new(network) .add_consensus_constants(constants) @@ -248,7 +248,7 @@ pub async fn create_new_blockchain_lmdb( ConsensusManager, MemoryDbKeyManager, ) { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let consensus_constants = consensus_constants(network).build(); let (block0, output) = create_genesis_block(&consensus_constants, &key_manager).await; let consensus_manager = ConsensusManagerBuilder::new(network) diff --git a/base_layer/core/tests/helpers/sync.rs b/base_layer/core/tests/helpers/sync.rs index 8dace2f6d9..40099ce612 100644 --- a/base_layer/core/tests/helpers/sync.rs +++ b/base_layer/core/tests/helpers/sync.rs @@ -154,7 +154,7 @@ pub async fn create_network_with_multiple_nodes( } let network = Network::LocalNet; let temp_dir = tempdir().unwrap(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let consensus_constants = sample_blockchains::consensus_constants(network).build(); let (initial_block, coinbase_wallet_output) = create_genesis_block(&consensus_constants, &key_manager).await; let consensus_manager = ConsensusManagerBuilder::new(network) diff --git a/base_layer/core/tests/tests/base_node_rpc.rs b/base_layer/core/tests/tests/base_node_rpc.rs index bc8f0c39fb..b78ae3014b 100644 --- a/base_layer/core/tests/tests/base_node_rpc.rs +++ b/base_layer/core/tests/tests/base_node_rpc.rs @@ -85,7 +85,7 @@ async fn setup() -> ( let consensus_constants = ConsensusConstantsBuilder::new(Network::LocalNet) .with_coinbase_lockheight(1) .build(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let temp_dir = tempdir().unwrap(); let (block0, utxo0) = create_genesis_block_with_coinbase_value(100_000_000.into(), &consensus_constants, &key_manager).await; diff --git a/base_layer/core/tests/tests/block_validation.rs b/base_layer/core/tests/tests/block_validation.rs index c0e4d50c44..4fd6bb516e 100644 --- a/base_layer/core/tests/tests/block_validation.rs +++ b/base_layer/core/tests/tests/block_validation.rs @@ -102,7 +102,7 @@ async fn test_monero_blocks() { let seed1 = "9f02e032f9b15d2aded991e0f68cc3c3427270b568b782e55fbd269ead0bad97"; let seed2 = "9f02e032f9b15d2aded991e0f68cc3c3427270b568b782e55fbd269ead0bad98"; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let network = Network::Esmeralda; let cc = ConsensusConstantsBuilder::new(network) .with_max_randomx_seed_height(1) @@ -339,7 +339,7 @@ async fn inputs_are_not_malleable() { #[allow(clippy::too_many_lines)] async fn test_orphan_validator() { let factories = CryptoFactories::default(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let network = Network::Igor; let consensus_constants = ConsensusConstantsBuilder::new(network) .with_max_block_transaction_weight(325) @@ -489,7 +489,7 @@ async fn test_orphan_body_validation() { .clear_proof_of_work() .add_proof_of_work(PowAlgorithm::Sha3x, sha3x_constants) .build(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (genesis, outputs) = create_genesis_block_with_utxos(&[T, T, T], &consensus_constants, &key_manager).await; let network = Network::LocalNet; let rules = ConsensusManager::builder(network) @@ -700,7 +700,7 @@ OutputFeatures::default()), #[allow(clippy::too_many_lines)] async fn test_header_validation() { let factories = CryptoFactories::default(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let network = Network::Igor; // we dont want localnet's 1 difficulty or the full mined difficulty of weather wax but we want some. let sha3x_constants = PowAlgorithmConstants { @@ -827,7 +827,7 @@ async fn test_block_sync_body_validator() { let consensus_constants = ConsensusConstantsBuilder::new(network) .with_max_block_transaction_weight(400) .build(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (genesis, outputs) = create_genesis_block_with_utxos(&[T, T, T], &consensus_constants, &key_manager).await; let network = Network::LocalNet; let rules = ConsensusManager::builder(network) @@ -1100,7 +1100,7 @@ async fn add_block_with_large_block() { let factories = CryptoFactories::default(); let network = Network::LocalNet; let consensus_constants = ConsensusConstantsBuilder::new(network).build(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (genesis, outputs) = create_genesis_block_with_utxos( &[ 5 * T, @@ -1179,7 +1179,7 @@ async fn add_block_with_large_many_output_block() { let consensus_constants = ConsensusConstantsBuilder::new(network) .with_max_block_transaction_weight(127_795) .build(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (genesis, outputs) = create_genesis_block_with_utxos(&[501 * T], &consensus_constants, &key_manager).await; let network = Network::LocalNet; let rules = ConsensusManager::builder(network) diff --git a/base_layer/core/tests/tests/mempool.rs b/base_layer/core/tests/tests/mempool.rs index 9feb7c180f..d49b7bcab1 100644 --- a/base_layer/core/tests/tests/mempool.rs +++ b/base_layer/core/tests/tests/mempool.rs @@ -1045,7 +1045,7 @@ async fn receive_and_propagate_transaction() { let consensus_constants = crate::helpers::sample_blockchains::consensus_constants(network) .with_coinbase_lockheight(100) .build(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (block0, utxo) = create_genesis_block(&consensus_constants, &key_manager).await; let consensus_manager = ConsensusManager::builder(network) .add_consensus_constants(consensus_constants) @@ -1711,7 +1711,7 @@ async fn block_event_and_reorg_event_handling() { // When block B2A is submitted, then both nodes have TX2A and TX3A in their reorg pools // When block B2B is submitted with TX2B, TX3B, then TX2A, TX3A are discarded (Not Stored) let network = Network::LocalNet; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let consensus_constants = ConsensusConstantsBuilder::new(Network::LocalNet) .with_coinbase_lockheight(1) .build(); diff --git a/base_layer/core/tests/tests/node_comms_interface.rs b/base_layer/core/tests/tests/node_comms_interface.rs index 74aa97d98a..c235f81aa8 100644 --- a/base_layer/core/tests/tests/node_comms_interface.rs +++ b/base_layer/core/tests/tests/node_comms_interface.rs @@ -206,7 +206,7 @@ async fn inbound_fetch_utxos() { let utxo_1 = block0.body.outputs()[0].clone(); let hash_1 = utxo_1.hash(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (utxo_2, _, _) = create_utxo( MicroMinotari(10_000), &key_manager, @@ -367,7 +367,7 @@ async fn initialize_sender_transaction_protocol_for_overflow_test( #[tokio::test] async fn test_sender_transaction_protocol_for_overflow() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let script = script!(Nop); let amount = MicroMinotari(u64::MAX); // This is the adversary's attack! let output_features = OutputFeatures::default(); @@ -439,7 +439,7 @@ async fn test_sender_transaction_protocol_for_overflow() { async fn inbound_fetch_blocks_before_horizon_height() { let consensus_manager = ConsensusManager::builder(Network::LocalNet).build().unwrap(); let block0 = consensus_manager.get_genesis_block(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let validators = Validators::new( MockValidator::new(true), MockValidator::new(true), diff --git a/base_layer/core/tests/tests/node_service.rs b/base_layer/core/tests/tests/node_service.rs index cc36517d53..8f3abcf78e 100644 --- a/base_layer/core/tests/tests/node_service.rs +++ b/base_layer/core/tests/tests/node_service.rs @@ -73,7 +73,7 @@ use crate::{ #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn propagate_and_forward_many_valid_blocks() { let temp_dir = tempdir().unwrap(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); // Alice will propagate a number of block hashes to bob, bob will receive it, request the full block, verify and // then propagate the hash to carol and dan. Dan and Carol will also try to propagate the block hashes to each // other, but the block should not be re-requested. These duplicate blocks will be discarded and wont be @@ -233,7 +233,7 @@ async fn propagate_and_forward_invalid_block_hash() { let bob_node_identity = random_node_identity(); let carol_node_identity = random_node_identity(); let network = Network::LocalNet; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let consensus_constants = crate::helpers::sample_blockchains::consensus_constants(network).build(); let (block0, genesis_coinbase) = create_genesis_block(&consensus_constants, &key_manager).await; let rules = ConsensusManager::builder(network) @@ -363,7 +363,7 @@ async fn propagate_and_forward_invalid_block() { let bob_node_identity = random_node_identity(); let carol_node_identity = random_node_identity(); let dan_node_identity = random_node_identity(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let network = Network::LocalNet; let consensus_constants = crate::helpers::sample_blockchains::consensus_constants(network).build(); let (block0, _) = create_genesis_block(&consensus_constants, &key_manager).await; @@ -512,7 +512,7 @@ async fn propagate_and_forward_invalid_block() { async fn local_get_metadata() { let temp_dir = tempdir().unwrap(); let network = Network::LocalNet; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (mut node, consensus_manager) = BaseNodeBuilder::new(network.into()) .start(temp_dir.path().to_str().unwrap(), BlockchainDatabaseConfig::default()) .await; @@ -536,7 +536,7 @@ async fn local_get_metadata() { async fn local_get_new_block_template_and_get_new_block() { let temp_dir = tempdir().unwrap(); let network = Network::LocalNet; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let consensus_constants = NetworkConsensus::from(network).create_consensus_constants(); let (block0, outputs) = create_genesis_block_with_utxos(&[T, T], &consensus_constants[0], &key_manager).await; let rules = ConsensusManager::builder(network) @@ -579,7 +579,7 @@ async fn local_get_new_block_with_zero_conf() { let factories = CryptoFactories::default(); let temp_dir = tempdir().unwrap(); let network = Network::LocalNet; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let consensus_constants = NetworkConsensus::from(network).create_consensus_constants(); let (block0, outputs) = create_genesis_block_with_utxos(&[T, T], &consensus_constants[0], &key_manager).await; let rules = ConsensusManagerBuilder::new(network) @@ -665,7 +665,7 @@ async fn local_get_new_block_with_combined_transaction() { let factories = CryptoFactories::default(); let temp_dir = tempdir().unwrap(); let network = Network::LocalNet; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let consensus_constants = NetworkConsensus::from(network).create_consensus_constants(); let (block0, outputs) = create_genesis_block_with_utxos(&[T, T], &consensus_constants[0], &key_manager).await; let rules = ConsensusManagerBuilder::new(network) @@ -745,7 +745,7 @@ async fn local_get_new_block_with_combined_transaction() { async fn local_submit_block() { let temp_dir = tempdir().unwrap(); let network = Network::LocalNet; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let (mut node, consensus_manager) = BaseNodeBuilder::new(network.into()) .start(temp_dir.path().to_str().unwrap(), BlockchainDatabaseConfig::default()) .await; diff --git a/base_layer/core/tests/tests/node_state_machine.rs b/base_layer/core/tests/tests/node_state_machine.rs index 8c673b02f4..44cce2048a 100644 --- a/base_layer/core/tests/tests/node_state_machine.rs +++ b/base_layer/core/tests/tests/node_state_machine.rs @@ -70,7 +70,7 @@ use crate::helpers::{ async fn test_listening_lagging() { let network = Network::LocalNet; let temp_dir = tempdir().unwrap(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let consensus_constants = crate::helpers::sample_blockchains::consensus_constants(network).build(); let (prev_block, _) = create_genesis_block(&consensus_constants, &key_manager).await; let consensus_manager = ConsensusManagerBuilder::new(network) @@ -154,7 +154,7 @@ async fn test_listening_lagging() { async fn test_listening_initial_fallen_behind() { let network = Network::LocalNet; let temp_dir = tempdir().unwrap(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let consensus_constants = crate::helpers::sample_blockchains::consensus_constants(network).build(); let (gen_block, _) = create_genesis_block(&consensus_constants, &key_manager).await; let consensus_manager = ConsensusManagerBuilder::new(network) diff --git a/base_layer/key_manager/src/key_manager_service/error.rs b/base_layer/key_manager/src/key_manager_service/error.rs index 1b1e547f1f..43c3196e80 100644 --- a/base_layer/key_manager/src/key_manager_service/error.rs +++ b/base_layer/key_manager/src/key_manager_service/error.rs @@ -21,7 +21,7 @@ // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. use diesel::result::Error as DieselError; -use tari_common_sqlite::error::SqliteStorageError; +use tari_common_sqlite::error::{SqliteStorageError, StorageError}; use tari_crypto::errors::RangeProofError; use tari_utilities::{hex::HexError, ByteArrayError}; @@ -55,6 +55,8 @@ pub enum KeyManagerServiceError { LedgerPrivateKeyInaccessible, #[error("The Ledger view key cannot be accessed or read")] LedgerViewKeyInaccessible, + #[error("Tari Key Manager storage error: `{0}`")] + StorageError(#[from] StorageError), } impl From for KeyManagerServiceError { diff --git a/base_layer/tari_mining_helper_ffi/src/error.rs b/base_layer/tari_mining_helper_ffi/src/error.rs index a897160201..81a80f2f21 100644 --- a/base_layer/tari_mining_helper_ffi/src/error.rs +++ b/base_layer/tari_mining_helper_ffi/src/error.rs @@ -44,6 +44,8 @@ pub enum InterfaceError { InvalidAddress(String), #[error("An invalid network was passed in: `{0}`")] InvalidNetwork(String), + #[error("KeyManager encountered an error: `{0}`")] + KeyManager(String), } /// This struct is meant to hold an error for use by Miningcore. The error has an integer code and string @@ -98,6 +100,10 @@ impl From for MiningHelperError { code: 10, message: format!("{:?}", v), }, + InterfaceError::KeyManager(_) => Self { + code: 11, + message: format!("{:?}", v), + }, } } } diff --git a/base_layer/tari_mining_helper_ffi/src/lib.rs b/base_layer/tari_mining_helper_ffi/src/lib.rs index f24a824f80..71b227ad8e 100644 --- a/base_layer/tari_mining_helper_ffi/src/lib.rs +++ b/base_layer/tari_mining_helper_ffi/src/lib.rs @@ -343,7 +343,14 @@ pub unsafe extern "C" fn inject_coinbase( return; }, }; - let key_manager = create_memory_db_key_manager(); + let key_manager = match create_memory_db_key_manager() { + Ok(v) => v, + Err(e) => { + error = MiningHelperError::from(InterfaceError::KeyManager(e.to_string())).code; + ptr::swap(error_out, &mut error as *mut c_int); + return; + }, + }; let consensus_manager = match ConsensusManager::builder(network).build() { Ok(v) => v, diff --git a/base_layer/wallet/src/output_manager_service/storage/sqlite_db/mod.rs b/base_layer/wallet/src/output_manager_service/storage/sqlite_db/mod.rs index eaa987158d..0cf8498398 100644 --- a/base_layer/wallet/src/output_manager_service/storage/sqlite_db/mod.rs +++ b/base_layer/wallet/src/output_manager_service/storage/sqlite_db/mod.rs @@ -1498,7 +1498,7 @@ mod test { let mut outputs_spent = Vec::new(); let mut outputs_unspent = Vec::new(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); for _i in 0..2 { let (_, uo) = make_input(MicroMinotari::from(100 + OsRng.next_u64() % 1000), &key_manager).await; let uo = DbWalletOutput::from_wallet_output(uo, &key_manager, None, OutputSource::Standard, None, None) diff --git a/base_layer/wallet/src/transaction_service/storage/sqlite_db.rs b/base_layer/wallet/src/transaction_service/storage/sqlite_db.rs index 3b11f18c84..1924fac728 100644 --- a/base_layer/wallet/src/transaction_service/storage/sqlite_db.rs +++ b/base_layer/wallet/src/transaction_service/storage/sqlite_db.rs @@ -2249,7 +2249,7 @@ mod test { #[tokio::test] #[allow(clippy::too_many_lines)] async fn test_crud() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let consensus_constants = create_consensus_constants(0); let db_name = format!("{}.sqlite3", string(8).as_str()); let temp_dir = tempdir().unwrap(); diff --git a/base_layer/wallet/tests/other/mod.rs b/base_layer/wallet/tests/other/mod.rs index 1641e92098..91456421cf 100644 --- a/base_layer/wallet/tests/other/mod.rs +++ b/base_layer/wallet/tests/other/mod.rs @@ -283,7 +283,7 @@ async fn test_wallet() { let mut alice_event_stream = alice_wallet.transaction_service.get_event_stream(); let value = MicroMinotari::from(1000); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap() let (_utxo, uo1) = make_non_recoverable_input(&mut OsRng, MicroMinotari(2500), &OutputFeatures::default(), &key_manager).await; alice_wallet.output_manager_service.add_output(uo1, None).await.unwrap(); @@ -589,7 +589,7 @@ async fn test_store_and_forward_send_tx() { .unwrap(); let value = MicroMinotari::from(1000); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap() let (_utxo, uo1) = make_non_recoverable_input(&mut OsRng, MicroMinotari(2500), &OutputFeatures::default(), &key_manager).await; alice_wallet.output_manager_service.add_output(uo1, None).await.unwrap(); @@ -733,7 +733,7 @@ async fn test_import_utxo() { let input = inputs!(claim); let temp_features = OutputFeatures::create_coinbase(50, None, RangeProofType::BulletProofPlus); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap() let p = TestParams::new(&key_manager); let utxo = create_wallet_output_with_data(script.clone(), temp_features, &p, 20000 * uT, &key_manager).await.unwrap(); let output = utxo.to_transaction_output(&key_manager).unwrap(); diff --git a/base_layer/wallet/tests/output_manager_service_tests/service.rs b/base_layer/wallet/tests/output_manager_service_tests/service.rs index 0074054774..7bc4d4796c 100644 --- a/base_layer/wallet/tests/output_manager_service_tests/service.rs +++ b/base_layer/wallet/tests/output_manager_service_tests/service.rs @@ -159,7 +159,7 @@ async fn setup_output_manager_service( wallet_connectivity_mock.set_base_node_wallet_rpc_client(connect_rpc_client(&mut connection).await); } - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let output_manager_service = OutputManagerService::new( OutputManagerServiceConfig { ..Default::default() }, @@ -226,7 +226,7 @@ pub async fn setup_oms_with_bn_state( mock_base_node_service.set_base_node_state(height); task::spawn(mock_base_node_service.run()); let connectivity = create_wallet_connectivity_mock(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let output_manager_service = OutputManagerService::new( OutputManagerServiceConfig { ..Default::default() }, oms_request_receiver, @@ -1933,7 +1933,7 @@ async fn test_txo_revalidation() { .set_base_node_wallet_rpc_client(connect_rpc_client(&mut connection).await); let output1_value = 1_000_000; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let output1 = create_wallet_output_with_data( script!(Nop), OutputFeatures::default(), @@ -2218,7 +2218,7 @@ async fn scan_for_recovery_test() { let mut non_recoverable_wallet_outputs = Vec::new(); // we need to create a new key_manager to make the outputs non recoverable - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); for i in 1..=NUM_NON_RECOVERABLE { let uo = make_input( &mut OsRng, @@ -2273,7 +2273,7 @@ async fn recovered_output_key_not_in_keychain() { let backend = OutputManagerSqliteDatabase::new(connection.clone()); let mut oms = setup_output_manager_service(backend.clone(), true).await; // we need to create a new key manager here as we dont want the input be recoverable from oms key chain - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let uo = make_input( &mut OsRng, MicroMinotari::from(1000u64), diff --git a/base_layer/wallet/tests/output_manager_service_tests/storage.rs b/base_layer/wallet/tests/output_manager_service_tests/storage.rs index 86653749cf..8ad7a356a4 100644 --- a/base_layer/wallet/tests/output_manager_service_tests/storage.rs +++ b/base_layer/wallet/tests/output_manager_service_tests/storage.rs @@ -54,7 +54,7 @@ pub async fn test_db_backend(backend: T) { // Add some unspent outputs let mut unspent_outputs = Vec::new(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let mut unspent = Vec::with_capacity(5); for i in 0..5 { let uo = make_input( @@ -387,7 +387,7 @@ pub async fn test_raw_custom_queries_regression() { // Add some unspent outputs let mut unspent_outputs = Vec::new(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let mut unspent = Vec::with_capacity(5); for i in 0..5 { let uo = make_input( @@ -572,7 +572,7 @@ pub async fn test_short_term_encumberance() { let db = OutputManagerDatabase::new(backend); let mut unspent_outputs = Vec::new(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); for i in 0..5 { let kmo = make_input( &mut OsRng, @@ -633,7 +633,7 @@ pub async fn test_no_duplicate_outputs() { let db = OutputManagerDatabase::new(backend); // create an output - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let uo = make_input( &mut OsRng, MicroMinotari::from(1000), @@ -681,7 +681,7 @@ pub async fn test_mark_as_unmined() { let db = OutputManagerDatabase::new(backend); // create an output - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let uo = make_input( &mut OsRng, MicroMinotari::from(1000), diff --git a/base_layer/wallet/tests/transaction_service_tests/service.rs b/base_layer/wallet/tests/transaction_service_tests/service.rs index d238f9db23..ed55d1720b 100644 --- a/base_layer/wallet/tests/transaction_service_tests/service.rs +++ b/base_layer/wallet/tests/transaction_service_tests/service.rs @@ -381,7 +381,7 @@ async fn setup_transaction_service_no_comms( let ts_service_db = TransactionServiceSqliteDatabase::new(db_connection.clone(), cipher.clone()); let ts_db = TransactionDatabase::new(ts_service_db.clone()); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let oms_db = OutputManagerDatabase::new(OutputManagerSqliteDatabase::new(db_connection)); let output_manager_service = OutputManagerService::new( OutputManagerServiceConfig::default(), @@ -2590,7 +2590,7 @@ async fn test_accepting_unknown_tx_id_and_malformed_reply() { #[tokio::test] async fn finalize_tx_with_incorrect_pubkey() { let factories = CryptoFactories::default(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let temp_dir = tempdir().unwrap(); let path_string = temp_dir.path().to_str().unwrap().to_string(); @@ -2718,7 +2718,7 @@ async fn finalize_tx_with_incorrect_pubkey() { #[tokio::test] async fn finalize_tx_with_missing_output() { let factories = CryptoFactories::default(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let temp_dir = tempdir().unwrap(); let path_string = temp_dir.path().to_str().unwrap().to_string(); @@ -3399,7 +3399,7 @@ async fn test_transaction_cancellation() { .remove(&tx_id) .is_none()); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let input = create_wallet_output_with_data( script!(Nop), OutputFeatures::default(), @@ -3411,7 +3411,7 @@ async fn test_transaction_cancellation() { .unwrap(); let constants = create_consensus_constants(0); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let mut builder = SenderTransactionProtocol::builder(constants, key_manager.clone()); let amount = MicroMinotari::from(10_000); let change = TestParams::new(&key_manager).await; @@ -4268,7 +4268,7 @@ async fn test_restarting_transaction_protocols() { .await; let constants = create_consensus_constants(0); let fee_calc = Fee::new(*constants.transaction_weight_params()); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let mut builder = SenderTransactionProtocol::builder(constants.clone(), key_manager.clone()); let fee = fee_calc.calculate(MicroMinotari(4), 1, 1, 1, 0); let change = TestParams::new(&key_manager).await; @@ -4693,7 +4693,7 @@ async fn test_resend_on_startup() { NodeIdentity::random(&mut OsRng, get_next_memory_address(), PeerFeatures::COMMUNICATION_NODE); // First we will check the Send Tranasction message - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let input = create_wallet_output_with_data( script!(Nop), OutputFeatures::default(), @@ -4704,7 +4704,7 @@ async fn test_resend_on_startup() { .await .unwrap(); let constants = create_consensus_constants(0); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let mut builder = SenderTransactionProtocol::builder(constants.clone(), key_manager.clone()); let amount = MicroMinotari::from(10_000); let change = TestParams::new(&key_manager).await; @@ -5221,7 +5221,7 @@ async fn test_transaction_timeout_cancellation() { // Now to test if the timeout has elapsed during downtime and that it is honoured on startup // First we will check the Send Transction message - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let input = create_wallet_output_with_data( script!(Nop), OutputFeatures::default(), @@ -5232,7 +5232,7 @@ async fn test_transaction_timeout_cancellation() { .await .unwrap(); let constants = create_consensus_constants(0); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let mut builder = SenderTransactionProtocol::builder(constants, key_manager.clone()); let amount = MicroMinotari::from(10_000); let change = TestParams::new(&key_manager).await; diff --git a/base_layer/wallet/tests/transaction_service_tests/storage.rs b/base_layer/wallet/tests/transaction_service_tests/storage.rs index 7d9d12a915..40344e3294 100644 --- a/base_layer/wallet/tests/transaction_service_tests/storage.rs +++ b/base_layer/wallet/tests/transaction_service_tests/storage.rs @@ -79,7 +79,7 @@ use tempfile::tempdir; pub async fn test_db_backend(backend: T) { let mut db = TransactionDatabase::new(backend); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let input = create_wallet_output_with_data( script!(Nop), OutputFeatures::default(), @@ -90,7 +90,7 @@ pub async fn test_db_backend(backend: T) { .await .unwrap(); let constants = create_consensus_constants(0); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let mut builder = SenderTransactionProtocol::builder(constants.clone(), key_manager.clone()); let amount = MicroMinotari::from(10_000); builder diff --git a/base_layer/wallet/tests/transaction_service_tests/transaction_protocols.rs b/base_layer/wallet/tests/transaction_service_tests/transaction_protocols.rs index b4a62c75e1..c9332e9a8e 100644 --- a/base_layer/wallet/tests/transaction_service_tests/transaction_protocols.rs +++ b/base_layer/wallet/tests/transaction_service_tests/transaction_protocols.rs @@ -147,7 +147,7 @@ pub async fn setup() -> ( let (oms_event_publisher, _) = broadcast::channel(200); let output_manager_service_handle = OutputManagerHandle::new(oms_request_sender, oms_event_publisher); - let core_key_manager_service_handle = create_memory_db_key_manager(); + let core_key_manager_service_handle = create_memory_db_key_manager().unwrap(); let (outbound_message_requester, mock_outbound_service) = create_outbound_service_mock(100); let outbound_mock_state = mock_outbound_service.get_state(); @@ -207,7 +207,7 @@ pub async fn add_transaction_to_database( status: Option, db: TransactionDatabase, ) { - let key_manager_handle = create_memory_db_key_manager(); + let key_manager_handle = create_memory_db_key_manager().unwrap(); let uo0 = make_input(&mut OsRng, 10 * amount, &OutputFeatures::default(), &key_manager_handle).await; let (txs1, _uou1) = schema_to_transaction( &[txn_schema!(from: vec![uo0.clone()], to: vec![amount])], diff --git a/base_layer/wallet/tests/utxo_scanner/mod.rs b/base_layer/wallet/tests/utxo_scanner/mod.rs index 2afdd10e82..a8aff63a25 100644 --- a/base_layer/wallet/tests/utxo_scanner/mod.rs +++ b/base_layer/wallet/tests/utxo_scanner/mod.rs @@ -294,7 +294,7 @@ async fn generate_block_headers_and_utxos( #[tokio::test] async fn test_utxo_scanner_recovery() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let mut test_interface = setup(key_manager.clone(), UtxoScannerMode::Recovery, None, None, None).await; let cipher_seed = CipherSeed::new(); @@ -385,7 +385,7 @@ async fn test_utxo_scanner_recovery() { #[tokio::test] #[allow(clippy::too_many_lines)] async fn test_utxo_scanner_recovery_with_restart() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let mut test_interface = setup(key_manager.clone(), UtxoScannerMode::Recovery, None, None, None).await; let cipher_seed = CipherSeed::new(); @@ -562,7 +562,7 @@ async fn test_utxo_scanner_recovery_with_restart() { #[tokio::test] #[allow(clippy::too_many_lines)] async fn test_utxo_scanner_recovery_with_restart_and_reorg() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let mut test_interface = setup(key_manager.clone(), UtxoScannerMode::Recovery, None, None, None).await; let cipher_seed = CipherSeed::new(); @@ -642,7 +642,7 @@ async fn test_utxo_scanner_recovery_with_restart_and_reorg() { .filter(|u| u.height <= 4) .collect::>(); - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let TestBlockData { block_headers: new_block_headers, wallet_outputs: new_wallet_outputs, @@ -740,7 +740,7 @@ async fn test_utxo_scanner_recovery_with_restart_and_reorg() { #[tokio::test] #[allow(clippy::too_many_lines)] async fn test_utxo_scanner_scanned_block_cache_clearing() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let mut test_interface = setup(key_manager.clone(), UtxoScannerMode::Recovery, None, None, None).await; for h in 0u64..800u64 { @@ -863,7 +863,7 @@ async fn test_utxo_scanner_scanned_block_cache_clearing() { #[tokio::test] #[allow(clippy::too_many_lines)] async fn test_utxo_scanner_one_sided_payments() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let mut test_interface = setup( key_manager.clone(), UtxoScannerMode::Scanning, @@ -1081,7 +1081,7 @@ async fn test_utxo_scanner_one_sided_payments() { #[tokio::test] async fn test_birthday_timestamp_over_chain() { - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let test_interface = setup(key_manager, UtxoScannerMode::Recovery, None, None, None).await; let cipher_seed = CipherSeed::new(); @@ -1092,7 +1092,7 @@ async fn test_birthday_timestamp_over_chain() { const NUM_BLOCKS: u64 = 10; const BIRTHDAY_OFFSET: u64 = 5; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let TestBlockData { block_headers, utxos_by_block, diff --git a/base_layer/wallet_ffi/src/lib.rs b/base_layer/wallet_ffi/src/lib.rs index fceedba2ad..dddc3fb27f 100644 --- a/base_layer/wallet_ffi/src/lib.rs +++ b/base_layer/wallet_ffi/src/lib.rs @@ -11432,7 +11432,7 @@ mod test { let mut error = 0; let error_ptr = &mut error as *mut c_int; // Test the consistent features case - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let utxo_1 = runtime .block_on(create_wallet_output_with_data( script!(Nop), @@ -11809,7 +11809,7 @@ mod test { let mut error = 0; let error_ptr = &mut error as *mut c_int; - let key_manager = create_memory_db_key_manager(); + let key_manager = create_memory_db_key_manager().unwrap(); let utxo_1 = runtime .block_on(create_wallet_output_with_data( script!(Nop), diff --git a/integration_tests/src/world.rs b/integration_tests/src/world.rs index 3f9caae9d8..854722c966 100644 --- a/integration_tests/src/world.rs +++ b/integration_tests/src/world.rs @@ -138,7 +138,7 @@ impl Default for TariWorld { errors: Default::default(), last_imported_tx_ids: vec![], last_merge_miner_response: Default::default(), - key_manager: create_memory_db_key_manager(), + key_manager: create_memory_db_key_manager().unwrap(), wallet_private_key, default_payment_address, consensus_manager: ConsensusManager::builder(Network::LocalNet).build().unwrap(),