Skip to content

Commit

Permalink
chore: Remove superfluous pub modifiers in test code
Browse files Browse the repository at this point in the history
  • Loading branch information
luckysori committed Dec 14, 2023
1 parent 9a1ba48 commit e1c56f7
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 66 deletions.
6 changes: 3 additions & 3 deletions coordinator/src/collaborative_revert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,19 +485,19 @@ fn estimate_subchannel_reserved_tx_fees(
}

#[cfg(test)]
pub mod tests {
mod tests {
use super::*;

#[test]
pub fn estimate_subchannel_reserved_tx_fees_test() {
fn estimate_subchannel_reserved_tx_fees_test() {
let total_fee =
estimate_subchannel_reserved_tx_fees(200_000, 65_450, 85_673, 1_000, 18_690, 18_690)
.unwrap();
assert_eq!(total_fee, 9_497);
}

#[test]
pub fn estimate_subchannel_reserved_tx_fees_cannot_overflow() {
fn estimate_subchannel_reserved_tx_fees_cannot_overflow() {
assert!(estimate_subchannel_reserved_tx_fees(
200_000, 84_140, 104_363, 1_000, 18_690, 18_690,
)
Expand Down
2 changes: 1 addition & 1 deletion coordinator/src/node/rollover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl From<Rollover> for ContractInput {
}

#[cfg(test)]
pub mod tests {
mod tests {
use super::*;
use bitcoin::secp256k1;
use bitcoin::secp256k1::ecdsa::Signature;
Expand Down
8 changes: 4 additions & 4 deletions coordinator/src/orderbook/trading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,15 +423,15 @@ impl From<&TradeParams> for TraderMatchParams {
}

#[cfg(test)]
pub mod tests {
mod tests {
use super::*;
use rust_decimal_macros::dec;
use std::str::FromStr;
use time::Duration;
use trade::ContractSymbol;

#[test]
pub fn when_short_then_sort_desc() {
fn when_short_then_sort_desc() {
let order1 = dummy_long_order(
dec!(20_000),
Uuid::new_v4(),
Expand Down Expand Up @@ -460,7 +460,7 @@ pub mod tests {
}

#[test]
pub fn when_long_then_sort_asc() {
fn when_long_then_sort_asc() {
let order1 = dummy_long_order(
dec!(20_000),
Uuid::new_v4(),
Expand Down Expand Up @@ -489,7 +489,7 @@ pub mod tests {
}

#[test]
pub fn when_all_same_price_sort_by_id() {
fn when_all_same_price_sort_by_id() {
let order1 = dummy_long_order(
dec!(20_000),
Uuid::new_v4(),
Expand Down
25 changes: 6 additions & 19 deletions coordinator/src/position/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ impl std::fmt::Debug for Position {
}

#[cfg(test)]
pub mod tests {
mod tests {
use super::*;
use rust_decimal_macros::dec;
use std::str::FromStr;
Expand Down Expand Up @@ -801,7 +801,7 @@ pub mod tests {
}

impl Position {
pub(crate) fn dummy() -> Self {
fn dummy() -> Self {
Position {
id: 0,
contract_symbol: ContractSymbol::BtcUsd,
Expand All @@ -827,37 +827,24 @@ pub mod tests {
}
}

pub(crate) fn with_quantity(mut self, quantity: f32) -> Self {
fn with_quantity(mut self, quantity: f32) -> Self {
self.quantity = quantity;
self
}

pub(crate) fn with_average_entry_price(mut self, average_entry_price: f32) -> Self {
fn with_average_entry_price(mut self, average_entry_price: f32) -> Self {
self.average_entry_price = average_entry_price;
self
}

pub(crate) fn with_leverage(mut self, leverage: f32) -> Self {
fn with_leverage(mut self, leverage: f32) -> Self {
self.trader_leverage = leverage;
self
}

pub(crate) fn with_direction(mut self, direction: Direction) -> Self {
fn with_direction(mut self, direction: Direction) -> Self {
self.direction = direction;
self
}
}
}

#[derive(Clone, Debug)]
pub struct CollaborativeRevert {
pub channel_id: ChannelId,
pub trader_pubkey: PublicKey,
pub price: f32,
pub coordinator_address: Address,
pub coordinator_amount_sats: Amount,
pub trader_amount_sats: Amount,
pub timestamp: OffsetDateTime,
pub txid: Txid,
pub vout: u32,
}
2 changes: 1 addition & 1 deletion crates/ln-dlc-node/src/ldk_node_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ where
}

#[cfg(test)]
pub mod tests {
mod tests {
use super::*;
use crate::channel::Channel;
use crate::fee_rate_estimator::EstimateFeeRate;
Expand Down
2 changes: 1 addition & 1 deletion crates/ln-dlc-node/src/ln/coordinator_event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ mod tests {
use std::str::FromStr;

#[test]
pub fn test_calculate_channel_value() {
fn test_calculate_channel_value() {
let dummy_pub_key = PublicKey::from_str(
"02bd998ebd176715fe92b7467cf6b1df8023950a4dd911db4c94dfc89cc9f5a655",
)
Expand Down
37 changes: 19 additions & 18 deletions crates/payout_curve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ mod tests {
const PRINT_CSV: bool = false;

#[test]
pub fn calculate_lower_range_payout_points_when_offerer_long_then_gets_zero() {
fn calculate_lower_range_payout_points_when_offerer_long_then_gets_zero() {
// setup
// we take 2 BTC so that all tests have nice numbers
let total_collateral = Amount::ONE_BTC.to_sat() * 2;
Expand Down Expand Up @@ -336,8 +336,9 @@ mod tests {
wtr.flush().unwrap();
}
}

#[test]
pub fn calculate_lower_range_payout_points_when_offerer_long_then_gets_zero_plus_fee() {
fn calculate_lower_range_payout_points_when_offerer_long_then_gets_zero_plus_fee() {
// setup
// we take 2 BTC so that all tests have nice numbers
let total_collateral = Amount::ONE_BTC.to_sat() * 2;
Expand Down Expand Up @@ -373,7 +374,7 @@ mod tests {
}

#[test]
pub fn calculate_lower_range_payout_points_when_offer_short_then_gets_all() {
fn calculate_lower_range_payout_points_when_offer_short_then_gets_all() {
// setup
// we take 2 BTC so that all tests have nice numbers
let total_collateral = Amount::ONE_BTC.to_sat() * 2;
Expand Down Expand Up @@ -409,7 +410,7 @@ mod tests {
}

#[test]
pub fn snapshot_test_mid_range_offerer() {
fn snapshot_test_mid_range_offerer() {
// setup
let long_leverage = 2.0;
let short_leverage = 2.0;
Expand Down Expand Up @@ -535,7 +536,7 @@ mod tests {
}

#[test]
pub fn ensure_all_bounds_smaller_or_equal_max_btc_price() {
fn ensure_all_bounds_smaller_or_equal_max_btc_price() {
// setup
let long_leverage = 2.0;
let short_leverage = 1.0;
Expand Down Expand Up @@ -592,7 +593,7 @@ mod tests {
}

#[test]
pub fn calculate_upper_range_payout_points_when_offer_short_then_gets_zero() {
fn calculate_upper_range_payout_points_when_offer_short_then_gets_zero() {
// setup
// we take 2 BTC so that all tests have nice numbers
let total_collateral = Amount::ONE_BTC.to_sat() * 2;
Expand Down Expand Up @@ -627,7 +628,7 @@ mod tests {
}

#[test]
pub fn calculate_upper_range_payout_points_when_offer_long_then_gets_everything() {
fn calculate_upper_range_payout_points_when_offer_long_then_gets_everything() {
// setup
// we take 2 BTC so that all tests have nice numbers
let total_collateral = Amount::ONE_BTC.to_sat() * 2;
Expand Down Expand Up @@ -663,7 +664,7 @@ mod tests {
}

#[test]
pub fn upper_range_price_always_below_max_btc_price() {
fn upper_range_price_always_below_max_btc_price() {
// setup
let total_collateral = Amount::ONE_BTC.to_sat() * 2;
let last_payout = PayoutPoint {
Expand Down Expand Up @@ -703,20 +704,20 @@ mod tests {

#[derive(Serialize, Deserialize)]
struct PayoutCouple {
pub lower_event_outcome: u64,
pub lower_outcome_payout: u64,
pub lower_extra_precision: u16,
pub upper_event_outcome: u64,
pub upper_outcome_payout: u64,
pub upper_extra_precision: u16,
lower_event_outcome: u64,
lower_outcome_payout: u64,
lower_extra_precision: u16,
upper_event_outcome: u64,
upper_outcome_payout: u64,
upper_extra_precision: u16,
}

#[derive(Serialize, Deserialize, Debug)]
struct ShouldPayout {
pub start: u64,
pub payout_offer: u64,
pub payout_accept: u64,
pub fee: u64,
start: u64,
payout_offer: u64,
payout_accept: u64,
fee: u64,
}

//******* Proptests *******//
Expand Down
2 changes: 1 addition & 1 deletion crates/trade/src/cfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub fn calculate_pnl(
}

#[cfg(test)]
pub mod tests {
mod tests {
use super::*;

#[test]
Expand Down
4 changes: 2 additions & 2 deletions crates/trade/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ impl fmt::Display for ContractSymbol {
}

#[cfg(test)]
pub mod tests {
mod tests {
use crate::ContractSymbol;
use std::str::FromStr;

#[test]
pub fn contract_symbol_from_str() {
fn contract_symbol_from_str() {
assert_eq!(
ContractSymbol::from_str("btcusd").unwrap(),
ContractSymbol::BtcUsd
Expand Down
14 changes: 7 additions & 7 deletions mobile/native/src/db/custom_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl FromSql<Text, Sqlite> for ChannelState {
}

#[cfg(test)]
pub mod tests {
mod tests {
use crate::db::custom_types::tests::customstruct::id;
use crate::db::models::ContractSymbol;
use crate::db::models::Direction;
Expand All @@ -302,12 +302,12 @@ pub mod tests {

#[derive(Insertable, Queryable, Identifiable, Debug, PartialEq, Clone)]
#[diesel(table_name = customstruct)]
pub struct SampleStruct {
pub id: String,
pub order_type: OrderType,
pub order_state: OrderState,
pub contract_symbol: ContractSymbol,
pub direction: Direction,
struct SampleStruct {
id: String,
order_type: OrderType,
order_state: OrderState,
contract_symbol: ContractSymbol,
direction: Direction,
}

diesel::table! {
Expand Down
12 changes: 6 additions & 6 deletions mobile/native/src/db/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ pub mod test {
use time::Time;

#[test]
pub fn order_round_trip() {
fn order_round_trip() {
let mut connection = SqliteConnection::establish(":memory:").unwrap();
connection.run_pending_migrations(MIGRATIONS).unwrap();

Expand Down Expand Up @@ -1560,7 +1560,7 @@ pub mod test {
}

#[test]
pub fn given_several_orders_when_fetching_orders_for_ui_only_relevant_orders_are_loaded() {
fn given_several_orders_when_fetching_orders_for_ui_only_relevant_orders_are_loaded() {
let mut connection = SqliteConnection::establish(":memory:").unwrap();
connection.run_pending_migrations(MIGRATIONS).unwrap();

Expand Down Expand Up @@ -1652,7 +1652,7 @@ pub mod test {
}

#[test]
pub fn payment_round_trip() {
fn payment_round_trip() {
let mut connection = SqliteConnection::establish(":memory:").unwrap();
connection.run_pending_migrations(MIGRATIONS).unwrap();

Expand Down Expand Up @@ -1764,7 +1764,7 @@ pub mod test {
}

#[test]
pub fn spendable_output_round_trip() {
fn spendable_output_round_trip() {
let mut connection = SqliteConnection::establish(":memory:").unwrap();
connection.run_pending_migrations(MIGRATIONS).unwrap();

Expand Down Expand Up @@ -1837,7 +1837,7 @@ pub mod test {
}

#[test]
pub fn channel_round_trip() {
fn channel_round_trip() {
let mut connection = SqliteConnection::establish(":memory:").unwrap();
connection.run_pending_migrations(MIGRATIONS).unwrap();

Expand Down Expand Up @@ -1899,7 +1899,7 @@ pub mod test {
}

#[test]
pub fn transaction_round_trip() {
fn transaction_round_trip() {
let mut connection = SqliteConnection::establish(":memory:").unwrap();
connection.run_pending_migrations(MIGRATIONS).unwrap();

Expand Down
6 changes: 3 additions & 3 deletions mobile/native/src/ln_dlc/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ impl node::Storage for NodeStorage {
}

#[cfg(test)]
pub mod tests {
mod tests {
use crate::ln_dlc::node::is_expired;
use bitcoin::secp256k1::schnorr::Signature;
use bitcoin::secp256k1::PublicKey;
Expand Down Expand Up @@ -596,7 +596,7 @@ pub mod tests {
use time::OffsetDateTime;

#[test]
pub fn contract_with_maturity_in_past_is_expired() {
fn contract_with_maturity_in_past_is_expired() {
// setup
let expired_timestamp =
(OffsetDateTime::now_utc() - Duration::seconds(10)).unix_timestamp() as u32;
Expand All @@ -611,7 +611,7 @@ pub mod tests {
assert!(is_expired)
}
#[test]
pub fn contract_with_maturity_in_future_is_valid() {
fn contract_with_maturity_in_future_is_valid() {
// setup
let expired_timestamp =
(OffsetDateTime::now_utc() + Duration::minutes(1)).unix_timestamp() as u32;
Expand Down

0 comments on commit e1c56f7

Please sign in to comment.