use blvm_node::config::PaymentConfig;
use blvm_node::payment::processor::{PaymentError, PaymentProcessor};
#[test]
fn test_p2p_always_available() {
let config = PaymentConfig {
p2p_enabled: true,
http_enabled: false,
..Default::default()
};
let result = PaymentProcessor::new(config);
assert!(
result.is_ok(),
"P2P should always be available without any feature flags"
);
}
#[test]
#[cfg(feature = "bip70-http")]
fn test_http_feature_enabled() {
let config = PaymentConfig {
p2p_enabled: false,
http_enabled: true,
..Default::default()
};
let result = PaymentProcessor::new(config);
assert!(
result.is_ok(),
"HTTP should be available when bip70-http feature is enabled"
);
}
#[test]
#[cfg(not(feature = "bip70-http"))]
fn test_http_feature_disabled() {
let config = PaymentConfig {
p2p_enabled: false,
http_enabled: true,
..Default::default()
};
let result = PaymentProcessor::new(config.clone());
assert!(
result.is_err(),
"HTTP should require bip70-http feature flag when disabled"
);
if let Err(PaymentError::FeatureNotEnabled(_)) = result {
} else {
let result2 = PaymentProcessor::new(config);
assert!(result2.is_err(), "Should still be an error");
}
}
#[test]
#[cfg(feature = "bip70-http")]
fn test_http_endpoints_conditional_compilation() {
use blvm_node::payment::http;
assert!(true, "HTTP handler module is conditionally compiled");
}
#[test]
#[cfg(feature = "bip70-http")]
fn test_payment_module_http_available() {
use blvm_node::payment;
#[cfg(feature = "bip70-http")]
{
use blvm_node::payment::http;
assert!(true, "HTTP payment module is available with feature");
}
}
#[test]
#[cfg(not(feature = "bip70-http"))]
fn test_payment_module_http_not_available() {
let config = PaymentConfig::default();
let result = PaymentProcessor::new(config);
assert!(
result.is_ok(),
"PaymentProcessor should be available without HTTP feature"
);
}
#[test]
#[cfg(all(feature = "bip70-http", feature = "rest-api"))]
fn test_http_with_rest_api_feature() {
let config = PaymentConfig {
p2p_enabled: true,
http_enabled: true,
..Default::default()
};
let result = PaymentProcessor::new(config);
assert!(
result.is_ok(),
"HTTP should work when both bip70-http and rest-api features are enabled"
);
}
#[test]
#[cfg(not(feature = "rest-api"))]
fn test_http_requires_rest_api_feature() {
let config = PaymentConfig {
p2p_enabled: false,
http_enabled: true,
..Default::default()
};
let result = PaymentProcessor::new(config.clone());
assert!(
result.is_err(),
"HTTP should require rest-api feature flag when disabled"
);
if let Err(PaymentError::FeatureNotEnabled(_)) = result {
} else {
let result2 = PaymentProcessor::new(config);
assert!(result2.is_err(), "Should still be an error");
}
}
#[test]
fn test_both_transports_with_features() {
let config = PaymentConfig {
p2p_enabled: true,
http_enabled: true,
..Default::default()
};
#[cfg(all(feature = "bip70-http", feature = "rest-api"))]
{
let result = PaymentProcessor::new(config);
assert!(
result.is_ok(),
"Both transports should work when required features are enabled"
);
}
#[cfg(not(all(feature = "bip70-http", feature = "rest-api")))]
{
let result = PaymentProcessor::new(config);
assert!(
result.is_err(),
"Both transports should fail when required features are not enabled"
);
}
}
#[test]
#[cfg(all(feature = "bip70-http", feature = "rest-api"))]
fn test_rest_api_server_payment_processor_method() {
#[cfg(all(feature = "bip70-http", feature = "rest-api"))]
{
use blvm_node::rpc::rest::server::RestApiServer;
assert!(
true,
"RestApiServer has with_payment_processor method when features enabled"
);
}
}
#[test]
#[cfg(any(not(feature = "bip70-http"), not(feature = "rest-api")))]
fn test_rest_api_server_no_payment_processor_method() {
#[cfg(not(feature = "bip70-http"))]
{
assert!(
true,
"RestApiServer doesn't have with_payment_processor method when feature disabled"
);
}
#[cfg(all(feature = "bip70-http", not(feature = "rest-api")))]
{
assert!(
true,
"RestApiServer module not available when rest-api feature disabled"
);
}
}
#[test]
fn test_p2p_independent_of_features() {
let config = PaymentConfig {
p2p_enabled: true,
http_enabled: false,
..Default::default()
};
let result = PaymentProcessor::new(config);
assert!(
result.is_ok(),
"P2P should work regardless of HTTP feature flags"
);
}
#[test]
#[cfg(feature = "bip70-http")]
fn test_http_handler_functions_exist() {
use blvm_node::payment::http;
assert!(true, "HTTP handler functions exist when feature enabled");
}