Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dash-spv-ffi/FFI_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ dash_spv_ffi_config_get_network(config: *const FFIClientConfig,) -> FFINetwork
```

**Description:**
Gets the network type from the configuration # Safety - `config` must be a valid pointer to an FFIClientConfig or null - If null, returns FFINetwork::Dash as default
Gets the network type from the configuration # Safety - `config` must be a valid pointer to an FFIClientConfig or null - If null, returns FFINetwork::Mainnet as default

**Safety:**
- `config` must be a valid pointer to an FFIClientConfig or null - If null, returns FFINetwork::Dash as default
- `config` must be a valid pointer to an FFIClientConfig or null - If null, returns FFINetwork::Mainnet as default

**Module:** `config`

Expand Down
2 changes: 1 addition & 1 deletion dash-spv-ffi/dash_spv_ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ int32_t dash_spv_ffi_config_set_masternode_sync_enabled(struct FFIClientConfig *
*
* # Safety
* - `config` must be a valid pointer to an FFIClientConfig or null
* - If null, returns FFINetwork::Dash as default
* - If null, returns FFINetwork::Mainnet as default
*/
FFINetwork dash_spv_ffi_config_get_network(const struct FFIClientConfig *config) ;

Expand Down
2 changes: 1 addition & 1 deletion dash-spv-ffi/include/dash_spv_ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ int32_t dash_spv_ffi_config_set_masternode_sync_enabled(struct FFIClientConfig *
*
* # Safety
* - `config` must be a valid pointer to an FFIClientConfig or null
* - If null, returns FFINetwork::Dash as default
* - If null, returns FFINetwork::Mainnet as default
*/
FFINetwork dash_spv_ffi_config_get_network(const struct FFIClientConfig *config) ;

Expand Down
4 changes: 2 additions & 2 deletions dash-spv-ffi/src/bin/ffi_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ fn main() {

// Map network
let network = match matches.get_one::<String>("network").map(|s| s.as_str()) {
Some("mainnet") => FFINetwork::Dash,
Some("mainnet") => FFINetwork::Mainnet,
Some("testnet") => FFINetwork::Testnet,
Some("regtest") => FFINetwork::Regtest,
_ => FFINetwork::Dash,
_ => FFINetwork::Mainnet,
};

unsafe {
Expand Down
6 changes: 3 additions & 3 deletions dash-spv-ffi/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub unsafe extern "C" fn dash_spv_ffi_config_add_peer(

let cfg = unsafe { &mut *((*config).inner as *mut ClientConfig) };
let default_port = match cfg.network {
dashcore::Network::Dash => 9999,
dashcore::Network::Mainnet => 9999,
dashcore::Network::Testnet => 19999,
dashcore::Network::Regtest => 19899,
dashcore::Network::Devnet => 29999,
Expand Down Expand Up @@ -232,13 +232,13 @@ pub unsafe extern "C" fn dash_spv_ffi_config_set_masternode_sync_enabled(
///
/// # Safety
/// - `config` must be a valid pointer to an FFIClientConfig or null
/// - If null, returns FFINetwork::Dash as default
/// - If null, returns FFINetwork::Mainnet as default
#[no_mangle]
pub unsafe extern "C" fn dash_spv_ffi_config_get_network(
config: *const FFIClientConfig,
) -> FFINetwork {
if config.is_null() {
return FFINetwork::Dash;
return FFINetwork::Mainnet;
}

let config = unsafe { &*((*config).inner as *const ClientConfig) };
Expand Down
6 changes: 3 additions & 3 deletions dash-spv-ffi/src/platform_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ pub unsafe extern "C" fn ffi_dash_spv_get_platform_activation_height(

// Platform activation heights per network
let height = match network {
dashcore::Network::Dash => 1_888_888, // Mainnet (placeholder - needs verification)
dashcore::Network::Mainnet => 1_888_888, // Mainnet (placeholder - needs verification)
dashcore::Network::Testnet => 1_289_520, // Testnet confirmed height
dashcore::Network::Devnet => 1, // Devnet starts immediately
_ => 0, // Unknown network
dashcore::Network::Devnet => 1, // Devnet starts immediately
_ => 0, // Unknown network
};

// Set the output value
Expand Down
2 changes: 1 addition & 1 deletion dash-spv-ffi/tests/test_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod tests {
assert!(!config.is_null());

let network = dash_spv_ffi_config_get_network(config);
assert_eq!(network as i32, FFINetwork::Dash as i32);
assert_eq!(network as i32, FFINetwork::Mainnet as i32);

dash_spv_ffi_config_destroy(config);
}
Expand Down
4 changes: 2 additions & 2 deletions dash-spv-ffi/tests/test_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ mod tests {

#[test]
fn test_ffi_network_conversion() {
assert_eq!(dashcore::Network::Dash, FFINetwork::Dash.into());
assert_eq!(dashcore::Network::Mainnet, FFINetwork::Mainnet.into());
assert_eq!(dashcore::Network::Testnet, FFINetwork::Testnet.into());
assert_eq!(dashcore::Network::Regtest, FFINetwork::Regtest.into());
assert_eq!(dashcore::Network::Devnet, FFINetwork::Devnet.into());

assert_eq!(FFINetwork::Dash, dashcore::Network::Dash.into());
assert_eq!(FFINetwork::Mainnet, dashcore::Network::Mainnet.into());
assert_eq!(FFINetwork::Testnet, dashcore::Network::Testnet.into());
assert_eq!(FFINetwork::Regtest, dashcore::Network::Regtest.into());
assert_eq!(FFINetwork::Devnet, dashcore::Network::Devnet.into());
Expand Down
4 changes: 2 additions & 2 deletions dash-spv-ffi/tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ mod tests {
#[test]
fn test_network_names() {
unsafe {
let name = ffi_network_get_name(FFINetwork::Dash);
let name = ffi_network_get_name(FFINetwork::Mainnet);
assert!(!name.is_null());
let name_str = CStr::from_ptr(name).to_str().unwrap();
assert_eq!(name_str, "dash");
assert_eq!(name_str, "mainnet");

let name = ffi_network_get_name(FFINetwork::Testnet);
assert!(!name.is_null());
Expand Down
4 changes: 2 additions & 2 deletions dash-spv-ffi/tests/unit/test_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod tests {
unsafe {
// Test creating config with each valid network
let networks =
[FFINetwork::Dash, FFINetwork::Testnet, FFINetwork::Regtest, FFINetwork::Devnet];
[FFINetwork::Mainnet, FFINetwork::Testnet, FFINetwork::Regtest, FFINetwork::Devnet];
for net in networks {
let config = dash_spv_ffi_config_new(net);
assert!(!config.is_null());
Expand Down Expand Up @@ -218,7 +218,7 @@ mod tests {

// Test getters with null
let net = dash_spv_ffi_config_get_network(std::ptr::null());
assert_eq!(net as i32, FFINetwork::Dash as i32); // Returns default
assert_eq!(net as i32, FFINetwork::Mainnet as i32); // Returns default

// Test destroy with null (should be safe)
dash_spv_ffi_config_destroy(std::ptr::null_mut());
Expand Down
2 changes: 1 addition & 1 deletion dash-spv-ffi/tests/unit/test_error_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ mod tests {
// Use a valid enum value to avoid UB in Rust tests. If invalid raw inputs
// need to be tested, do so from a C test or add a raw-int FFI entrypoint.
unsafe {
let config = dash_spv_ffi_config_new(FFINetwork::Dash);
let config = dash_spv_ffi_config_new(FFINetwork::Mainnet);
assert!(!config.is_null());
dash_spv_ffi_config_destroy(config);
}
Expand Down
2 changes: 1 addition & 1 deletion dash-spv-ffi/tests/unit/test_type_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ mod tests {
fn test_network_conversions() {
// Test all network conversions
let networks = [
(FFINetwork::Dash, dashcore::Network::Dash),
(FFINetwork::Mainnet, dashcore::Network::Mainnet),
(FFINetwork::Testnet, dashcore::Network::Testnet),
(FFINetwork::Regtest, dashcore::Network::Regtest),
(FFINetwork::Devnet, dashcore::Network::Devnet),
Expand Down
2 changes: 1 addition & 1 deletion dash-spv/src/chain/chain_work.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ mod tests {

#[test]
fn test_chain_work_from_header() {
let genesis = genesis_block(Network::Dash).header;
let genesis = genesis_block(Network::Mainnet).header;
let work = ChainWork::from_header(&genesis);
assert!(!work.is_zero());
}
Expand Down
6 changes: 3 additions & 3 deletions dash-spv/src/client/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub struct ClientConfig {
impl Default for ClientConfig {
fn default() -> Self {
Self {
network: Network::Dash,
network: Network::Mainnet,
peers: vec![],
restrict_to_configured_peers: false,
storage_path: PathBuf::from("./dash-spv-storage"),
Expand Down Expand Up @@ -110,7 +110,7 @@ impl ClientConfig {

/// Create a configuration for mainnet.
pub fn mainnet() -> Self {
Self::new(Network::Dash)
Self::new(Network::Mainnet)
}

/// Create a configuration for testnet.
Expand Down Expand Up @@ -221,7 +221,7 @@ impl ClientConfig {
/// Explicit peers can still be added via add_peer() or configuration.
fn default_peers_for_network(network: Network) -> Vec<SocketAddr> {
match network {
Network::Dash | Network::Testnet => {
Network::Mainnet | Network::Testnet => {
// Return empty to trigger immediate DNS discovery
// DNS seeds will be used: dnsseed.dash.org (mainnet), testnet-seed.dashdot.io (testnet)
vec![]
Expand Down
4 changes: 2 additions & 2 deletions dash-spv/src/client/config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod tests {
fn test_default_config() {
let config = ClientConfig::default();

assert_eq!(config.network, Network::Dash);
assert_eq!(config.network, Network::Mainnet);
assert!(config.peers.is_empty());
assert_eq!(config.validation_mode, ValidationMode::Full);
assert!(config.enable_filters);
Expand All @@ -30,7 +30,7 @@ mod tests {
#[test]
fn test_network_specific_configs() {
let mainnet = ClientConfig::mainnet();
assert_eq!(mainnet.network, Network::Dash);
assert_eq!(mainnet.network, Network::Mainnet);
assert!(mainnet.peers.is_empty()); // Should use DNS discovery

let testnet = ClientConfig::testnet();
Expand Down
4 changes: 2 additions & 2 deletions dash-spv/src/client/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<W: WalletInterface, N: NetworkManager, S: StorageManager> DashSpvClient<W,
> = Managers::default();

let checkpoints = match config.network {
dashcore::Network::Dash => mainnet_checkpoints(),
dashcore::Network::Mainnet => mainnet_checkpoints(),
dashcore::Network::Testnet => testnet_checkpoints(),
_ => Vec::new(),
};
Expand Down Expand Up @@ -262,7 +262,7 @@ impl<W: WalletInterface, N: NetworkManager, S: StorageManager> DashSpvClient<W,
if let Some(start_height) = config.start_from_height {
// Get checkpoints for this network
let checkpoints = match config.network {
dashcore::Network::Dash => crate::chain::checkpoints::mainnet_checkpoints(),
dashcore::Network::Mainnet => crate::chain::checkpoints::mainnet_checkpoints(),
dashcore::Network::Testnet => crate::chain::checkpoints::testnet_checkpoints(),
_ => vec![],
};
Expand Down
2 changes: 1 addition & 1 deletion dash-spv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error>> {
// Parse network
let network_str = matches.get_one::<String>("network").ok_or("Missing network argument")?;
let network = match network_str.as_str() {
"mainnet" => Network::Dash,
"mainnet" => Network::Mainnet,
"testnet" => Network::Testnet,
"regtest" => Network::Regtest,
n => return Err(format!("Invalid network: {}", n).into()),
Expand Down
16 changes: 8 additions & 8 deletions dash-spv/src/mempool_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ mod tests {
2, // Small limit for testing
mempool_state.clone(),
HashSet::new(),
Network::Dash,
Network::Mainnet,
);

// Should fetch any transaction when under limit
Expand Down Expand Up @@ -246,7 +246,7 @@ mod tests {

#[tokio::test]
async fn test_is_transaction_relevant_with_address() {
let network = Network::Dash;
let network = Network::Mainnet;

let addr1 = Address::dummy(network, 0);
let addr2 = Address::dummy(network, 1);
Expand All @@ -273,7 +273,7 @@ mod tests {

#[tokio::test]
async fn test_is_transaction_relevant_with_script() {
let network = Network::Dash;
let network = Network::Mainnet;

let addr1 = Address::dummy(network, 0);
let addr2 = Address::dummy(network, 1);
Expand All @@ -300,7 +300,7 @@ mod tests {

#[tokio::test]
async fn test_is_transaction_relevant_with_outpoint() {
let network = Network::Dash;
let network = Network::Mainnet;

let addr1 = Address::dummy(network, 0);

Expand Down Expand Up @@ -346,7 +346,7 @@ mod tests {
3, // Very small limit
mempool_state.clone(),
HashSet::new(),
Network::Dash,
Network::Mainnet,
);

// Should not be at capacity initially
Expand Down Expand Up @@ -391,7 +391,7 @@ mod tests {
1000,
mempool_state.clone(),
HashSet::new(),
Network::Dash,
Network::Mainnet,
);

// Add some transactions with different ages
Expand Down Expand Up @@ -458,7 +458,7 @@ mod tests {
1000,
mempool_state,
HashSet::new(),
Network::Dash,
Network::Mainnet,
);

// BloomFilter strategy should always return true (actual filtering is done by network layer)
Expand All @@ -470,7 +470,7 @@ mod tests {

#[tokio::test]
async fn test_address_with_earliest_height() {
let network = Network::Dash;
let network = Network::Mainnet;
let addr1 = Address::dummy(network, 0);
let addr2 = Address::dummy(network, 1);

Expand Down
4 changes: 2 additions & 2 deletions dash-spv/src/network/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl DnsDiscovery {
/// Discover peers for the given network
pub async fn discover_peers(&self, network: Network) -> Vec<SocketAddr> {
let (seeds, port) = match network {
Network::Dash => (MAINNET_DNS_SEEDS, 9999),
Network::Mainnet => (MAINNET_DNS_SEEDS, 9999),
Network::Testnet => (TESTNET_DNS_SEEDS, 19999),
_ => {
log::debug!("No DNS seeds for {:?} network", network);
Expand Down Expand Up @@ -84,7 +84,7 @@ mod tests {
#[ignore] // Requires network access
async fn test_dns_discovery_mainnet() {
let discovery = DnsDiscovery::new().await.expect("Failed to create DNS discovery for test");
let peers = discovery.discover_peers(Network::Dash).await;
let peers = discovery.discover_peers(Network::Mainnet).await;

// Print discovered peers for debugging
println!("Discovered {} mainnet peers:", peers.len());
Expand Down
2 changes: 1 addition & 1 deletion dash-spv/src/network/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod peer_tests {
fn test_peer_creation() {
let addr = "127.0.0.1:9999".parse().unwrap();
let timeout = Duration::from_secs(30);
let peer = Peer::new(addr, timeout, Network::Dash);
let peer = Peer::new(addr, timeout, Network::Mainnet);

assert!(!peer.is_connected());
assert_eq!(peer.address(), addr);
Expand Down
2 changes: 1 addition & 1 deletion dash-spv/src/test_utils/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,6 @@ impl NetworkManager for MockNetworkManager {
impl Peer {
pub fn dummy() -> Self {
let addr: SocketAddr = "127.0.0.1:9999".parse().unwrap();
Peer::new(addr, Duration::from_secs(10), Network::Dash)
Peer::new(addr, Duration::from_secs(10), Network::Mainnet)
}
}
2 changes: 1 addition & 1 deletion dash-spv/src/validation/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ mod tests {
fn test_genesis_blocks() {
let validator = BlockHeaderValidator::new();

for network in [Network::Dash, Network::Testnet, Network::Regtest] {
for network in [Network::Mainnet, Network::Testnet, Network::Regtest] {
let genesis = HashedBlockHeader::from(genesis_block(network).header);
assert!(
validator.validate(&[genesis]).is_ok(),
Expand Down
11 changes: 6 additions & 5 deletions dash-spv/tests/handshake_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ async fn test_handshake_with_mainnet_peer() {
let _ = env_logger::builder().filter_level(log::LevelFilter::Debug).is_test(true).try_init();

let peer_addr: SocketAddr = "127.0.0.1:9999".parse().expect("Valid peer address");
let result = Peer::connect(peer_addr, 10, Network::Dash).await;
let result = Peer::connect(peer_addr, 10, Network::Mainnet).await;

match result {
Ok(mut connection) => {
let mut handshake_manager = HandshakeManager::new(
Network::Dash,
Network::Mainnet,
MempoolStrategy::BloomFilter,
Some("handshake_test".parse().unwrap()),
);
Expand Down Expand Up @@ -54,7 +54,7 @@ async fn test_handshake_timeout() {
// This IP range is reserved for documentation and will never respond.
let peer_addr: SocketAddr = "192.0.2.1:9999".parse().expect("Valid peer address");
let start = std::time::Instant::now();
let result = Peer::connect(peer_addr, 2, Network::Dash).await;
let result = Peer::connect(peer_addr, 2, Network::Mainnet).await;
let elapsed = start.elapsed();

assert!(result.is_err(), "Connection should fail for unreachable peer");
Expand All @@ -73,7 +73,8 @@ async fn test_handshake_timeout() {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_network_manager_creation() {
let temp_dir = tempfile::TempDir::new().expect("Failed to create temporary directory");
let config = ClientConfig::new(Network::Dash).with_storage_path(temp_dir.path().to_path_buf());
let config =
ClientConfig::new(Network::Mainnet).with_storage_path(temp_dir.path().to_path_buf());
let network = PeerNetworkManager::new(&config).await;

assert!(network.is_ok(), "Network manager creation should succeed");
Expand All @@ -86,7 +87,7 @@ async fn test_network_manager_creation() {
#[tokio::test]
async fn test_multiple_connect_disconnect_cycles() {
let peer_addr: SocketAddr = "127.0.0.1:9999".parse().expect("Valid peer address");
let mut connection = Peer::new(peer_addr, Duration::from_secs(10), Network::Dash);
let mut connection = Peer::new(peer_addr, Duration::from_secs(10), Network::Mainnet);

// Try multiple connect/disconnect cycles
for i in 1..=3 {
Expand Down
Loading
Loading