From 6c7026604a1c3afa8730e9b4679435ecb95b44fc Mon Sep 17 00:00:00 2001 From: jwinterm Date: Sun, 26 Jul 2026 08:18:43 -0400 Subject: [PATCH] Contracts: clear the warnings introduced by this PR - Remove unused imports in api_impl::owner, backend, contract::utils, v5_bin and the contract tests. - Remove unused test bindings, and document the shared slate test fixtures module. - Drop the commented-out assertion block in the mwixnet contract test, along with the height bookkeeping and import that only it used. --- controller/tests/contract_early_proofs_rsr.rs | 4 +- .../tests/contract_self_spend_cancel.rs | 4 +- controller/tests/contract_srs_mwmixnet.rs | 53 +------------------ controller/tests/self_send_cancel.rs | 2 +- libwallet/src/api_impl/owner.rs | 5 +- libwallet/src/backend.rs | 1 - libwallet/src/contract/utils.rs | 1 - libwallet/src/slate_versions/mod.rs | 3 +- libwallet/src/slate_versions/v5_bin.rs | 1 - src/cmd/wallet_args.rs | 2 +- 10 files changed, 11 insertions(+), 65 deletions(-) diff --git a/controller/tests/contract_early_proofs_rsr.rs b/controller/tests/contract_early_proofs_rsr.rs index 439195d..28a1938 100644 --- a/controller/tests/contract_early_proofs_rsr.rs +++ b/controller/tests/contract_early_proofs_rsr.rs @@ -27,7 +27,7 @@ use grin_wallet_libwallet as libwallet; use impls::test_framework::{self}; use libwallet::contract::my_fee_contribution; use libwallet::contract::types::{ContractNewArgsAPI, ContractSetupArgsAPI}; -use libwallet::{Slate, SlateState, Slatepack, Slatepacker, SlatepackerArgs, TxLogEntryType}; +use libwallet::{Slate, SlateState, Slatepacker, SlatepackerArgs, TxLogEntryType}; use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; @@ -55,7 +55,7 @@ fn contract_early_proofs_rsr_test_impl(test_dir: &'static str) -> Result<(), lib send_wallet.clone(), send_mask, PathBuf::from(test_dir), - |api, m| { + |api, _m| { sender_address = Some(api.get_slatepack_address(send_mask, 0)?.pub_key); Ok(()) }, diff --git a/controller/tests/contract_self_spend_cancel.rs b/controller/tests/contract_self_spend_cancel.rs index 47515b0..5f732f3 100644 --- a/controller/tests/contract_self_spend_cancel.rs +++ b/controller/tests/contract_self_spend_cancel.rs @@ -19,8 +19,6 @@ extern crate log; use grin_wallet_libwallet as libwallet; -use impls::test_framework::{self}; -use libwallet::contract::my_fee_contribution; use libwallet::contract::types::{ContractNewArgsAPI, ContractSetupArgsAPI}; use libwallet::{Slate, SlateState, TxLogEntryType}; use std::sync::atomic::Ordering; @@ -35,7 +33,7 @@ use std::path::PathBuf; /// contract self-spend flow fn contract_self_spend_cancel_impl(test_dir: &'static str) -> Result<(), libwallet::Error> { // create a single wallet and mine 4 blocks - let (wallets, chain, stopper, mut bh) = + let (wallets, _chain, stopper, _bh) = create_wallets(vec![vec![("default", 4)]], test_dir).unwrap(); let send_wallet = wallets[0].0.clone(); let send_mask = wallets[0].1.as_ref(); diff --git a/controller/tests/contract_srs_mwmixnet.rs b/controller/tests/contract_srs_mwmixnet.rs index 4b3962e..1f8c5cb 100644 --- a/controller/tests/contract_srs_mwmixnet.rs +++ b/controller/tests/contract_srs_mwmixnet.rs @@ -21,10 +21,9 @@ use grin_util::{secp::SecretKey, static_secp_instance}; use grin_wallet_libwallet as libwallet; use impls::test_framework::{self}; -use libwallet::contract::my_fee_contribution; use libwallet::contract::types::{ContractNewArgsAPI, ContractSetupArgsAPI}; use libwallet::mwixnet::MixnetReqCreationParams; -use libwallet::{Slate, SlateState, TxLogEntryType}; +use libwallet::{Slate, SlateState}; use std::sync::atomic::Ordering; use std::thread; use std::time::Duration; @@ -37,7 +36,7 @@ use std::path::PathBuf; /// contract SRS flow - just creating an mwixnet tx at the moment fn contract_srs_mwixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet::Error> { // create two wallets and mine 4 blocks in each (we want both to have balance to get a payjoin) - let (wallets, chain, stopper, mut bh) = + let (wallets, chain, stopper, _bh) = create_wallets(vec![vec![("default", 4)], vec![("default", 4)]], test_dir).unwrap(); let send_wallet = wallets[0].0.clone(); let send_mask = wallets[0].1.as_ref(); @@ -107,11 +106,9 @@ fn contract_srs_mwixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet: Ok(()) }, )?; - bh += 1; let _ = test_framework::award_blocks_to_wallet(&chain, send_wallet.clone(), send_mask, 3, false); - bh += 3; // Recipient wallet sends outputs to mwixnet wallet::controller::owner_single_use( @@ -158,52 +155,6 @@ fn contract_srs_mwixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet: }, )?; - bh += 1; - - /* - let _ = - test_framework::award_blocks_to_wallet(&chain, send_wallet.clone(), send_mask, 3, false); - bh += 3; - - // Assert changes in receive wallet - wallet::controller::owner_single_use(recv_wallet.clone(), recv_mask, PathBuf::from(test_dir), |api, m| { - let (_, wallet_info) = api.retrieve_summary_info(m, true, 1)?; - let (refreshed, txs) = api.retrieve_txs(m, true, None, None, None)?; - assert_eq!(wallet_info.last_confirmed_height, bh); - assert!(refreshed); - assert_eq!(txs.len(), 5); // 4 mined and 1 received - let tx_log = txs[4].clone(); - assert_eq!(tx_log.tx_type, TxLogEntryType::TxReceived); - assert_eq!(tx_log.amount_credited, 5_000_000_000); - assert_eq!(tx_log.amount_debited, 0); - assert_eq!(tx_log.num_inputs, 1); - assert_eq!(tx_log.num_outputs, 1); - let expected_fees_paid = Some(my_fee_contribution(1, 1, 1, 2)?); - assert_eq!(tx_log.fee, expected_fees_paid); - assert_eq!( - wallet_info.amount_currently_spendable, - 4 * 60_000_000_000 + 5_000_000_000 - expected_fees_paid.unwrap().fee() // we expect the balance of 4 mined blocks + 5 Grin - fees paid - ); - Ok(()) - })?; - - // Assert changes in send wallet - wallet::controller::owner_single_use(send_wallet.clone(), send_mask, PathBuf::from(test_dir), |api, m| { - let (_, wallet_info) = api.retrieve_summary_info(m, true, 1)?; - let (refreshed, txs) = api.retrieve_txs(m, true, None, None, None)?; - assert_eq!(wallet_info.last_confirmed_height, bh); - assert!(refreshed); - assert_eq!(txs.len() as u64, bh - 4 + 1); // send wallet didn't mine 4 blocks and made 1 tx - let tx_log = txs[txs.len() - 5].clone(); // TODO: why -5 and not -4? - assert_eq!(tx_log.tx_type, TxLogEntryType::TxSent); - assert_eq!(tx_log.amount_credited, 0); - assert_eq!(tx_log.amount_debited, 5_000_000_000); - assert_eq!(tx_log.num_inputs, 1); - assert_eq!(tx_log.num_outputs, 1); - assert_eq!(tx_log.fee, Some(my_fee_contribution(1, 1, 1, 2)?)); - Ok(()) - })?;*/ - // let logging finish stopper.store(false, Ordering::Relaxed); thread::sleep(Duration::from_millis(200)); diff --git a/controller/tests/self_send_cancel.rs b/controller/tests/self_send_cancel.rs index fbb83cf..492ecf5 100644 --- a/controller/tests/self_send_cancel.rs +++ b/controller/tests/self_send_cancel.rs @@ -109,7 +109,7 @@ fn self_send_cancel_test_impl(test_dir: &'static str) -> Result<(), libwallet::E wallet1.clone(), mask1, PathBuf::from(test_dir), - |api, m| { + |api, _m| { let query = RetrieveTxQueryArgs { include_outstanding_only: Some(true), exclude_cancelled: Some(true), diff --git a/libwallet/src/api_impl/owner.rs b/libwallet/src/api_impl/owner.rs index a5f6144..7e90d8d 100644 --- a/libwallet/src/api_impl/owner.rs +++ b/libwallet/src/api_impl/owner.rs @@ -24,10 +24,9 @@ use crate::grin_core::core::{FeeFields, Output, OutputFeatures, Transaction}; use crate::grin_core::libtx::proof; use crate::grin_keychain::ViewKey; use crate::grin_util::secp::key::SecretKey; -use crate::grin_util::secp::pedersen; use crate::grin_util::secp::pedersen::Commitment; -use crate::grin_util::{static_secp_instance, Mutex, ToHex}; -use crate::util::{OnionV3Address, OnionV3AddressError}; +use crate::grin_util::{Mutex, ToHex}; +use crate::util::OnionV3Address; use crate::api_impl::owner_updater::StatusMessage; use crate::contract::types::{ContractNewArgsAPI, ContractRevokeArgsAPI, ContractSetupArgsAPI}; diff --git a/libwallet/src/backend.rs b/libwallet/src/backend.rs index 82c11b1..5833563 100644 --- a/libwallet/src/backend.rs +++ b/libwallet/src/backend.rs @@ -17,7 +17,6 @@ use std::fs; use std::fs::File; use std::io::{Read, Write}; use std::path::Path; -use uuid::Uuid; use crate::blake2::blake2b::{Blake2b, Blake2bResult}; diff --git a/libwallet/src/contract/utils.rs b/libwallet/src/contract/utils.rs index cd08b73..c0077ec 100644 --- a/libwallet/src/contract/utils.rs +++ b/libwallet/src/contract/utils.rs @@ -25,7 +25,6 @@ use crate::types::{Context, NodeClient, StoredProofInfo, TxLogEntryType}; use crate::util::OnionV3Address; use crate::{address, Error, OutputData, OutputStatus, TxLogEntry}; use grin_core::core::FeeFields; -use grin_util::file::delete; use uuid::Uuid; /// Creates an initial TxLogEntry without input/output or kernel information diff --git a/libwallet/src/slate_versions/mod.rs b/libwallet/src/slate_versions/mod.rs index 466516d..bde521d 100644 --- a/libwallet/src/slate_versions/mod.rs +++ b/libwallet/src/slate_versions/mod.rs @@ -142,6 +142,7 @@ impl VersionedCoinbase { } } } +/// Shared slate fixtures, used by the version conversion tests #[cfg(test)] pub mod tests { use crate::grin_core::core::transaction::OutputFeatures; @@ -161,7 +162,7 @@ pub mod tests { use grin_keychain::{ExtKeychain, Keychain, SwitchCommitmentType}; use std::convert::TryInto; - // Populate a test internal slate with all fields to test conversions + /// Populate a test internal slate with all fields to test conversions pub fn populate_test_slate() -> Result { let keychain = ExtKeychain::from_random_seed(true).unwrap(); let switch = SwitchCommitmentType::Regular; diff --git a/libwallet/src/slate_versions/v5_bin.rs b/libwallet/src/slate_versions/v5_bin.rs index f1af734..98c3f7b 100644 --- a/libwallet/src/slate_versions/v5_bin.rs +++ b/libwallet/src/slate_versions/v5_bin.rs @@ -25,7 +25,6 @@ use chrono::{DateTime, NaiveDateTime, Utc}; use ed25519_dalek::Signature as DalekSignature; use ed25519_dalek::VerifyingKey as DalekPublicKey; use std::convert::{TryFrom, TryInto}; -use std::f64::consts::E; use crate::slate_versions::v5::{ CommitsV5, KernelFeaturesArgsV5, ParticipantDataV5, PaymentInfoV5, PaymentMemoV5, SlateStateV5, diff --git a/src/cmd/wallet_args.rs b/src/cmd/wallet_args.rs index 1f3b196..a65b24f 100644 --- a/src/cmd/wallet_args.rs +++ b/src/cmd/wallet_args.rs @@ -1489,7 +1489,7 @@ where let broadcast_tx = !sign_args.is_present("no-broadcast"); command::contract_sign(owner_api, km, setup_args, broadcast_tx) } - ("view", Some(view_args)) => { + ("view", Some(_view_args)) => { Err(Error::ArgumentError(String::from("Not implemented")).into()) } ("revoke", Some(revoke_args)) => {