#[cfg(feature = "zmq")]
use blvm_node::zmq::publisher::{ZmqConfig, ZmqPublisher};
#[cfg(feature = "zmq")]
use blvm_protocol::Block;
#[cfg(feature = "zmq")]
#[test]
fn test_zmq_publisher_creation() {
let config = ZmqConfig {
hashblock: Some("tcp://127.0.0.1:28332".to_string()),
..Default::default()
};
let result = ZmqPublisher::new(&config);
let _ = result;
}
#[cfg(feature = "zmq")]
#[test]
fn test_zmq_publisher_multiple_endpoints() {
let config = ZmqConfig {
hashblock: Some("tcp://127.0.0.1:28332".to_string()),
hashtx: Some("tcp://127.0.0.1:28333".to_string()),
rawblock: Some("tcp://127.0.0.1:28334".to_string()),
..Default::default()
};
let result = ZmqPublisher::new(&config);
let _ = result;
}
#[cfg(feature = "zmq")]
#[test]
fn test_zmq_config_is_enabled() {
let config_empty = ZmqConfig::default();
assert!(!config_empty.is_enabled());
let config_enabled = ZmqConfig {
hashblock: Some("tcp://127.0.0.1:28332".to_string()),
..Default::default()
};
assert!(config_enabled.is_enabled());
}
#[cfg(feature = "zmq")]
#[tokio::test]
async fn test_zmq_publisher_publish_block() {
let config = ZmqConfig {
hashblock: Some("tcp://127.0.0.1:28332".to_string()),
rawblock: Some("tcp://127.0.0.1:28334".to_string()),
..Default::default()
};
if let Ok(publisher) = ZmqPublisher::new(&config) {
let block = Block {
header: blvm_protocol::BlockHeader {
version: 1,
prev_block_hash: [0u8; 32],
merkle_root: [0u8; 32],
timestamp: 1231006505,
bits: 0x1d00ffff,
nonce: 0,
},
transactions: vec![].into_boxed_slice(),
};
let block_hash: blvm_protocol::Hash = [0u8; 32];
let _result = publisher.publish_block(&block, &block_hash).await;
}
}
#[cfg(feature = "zmq")]
#[tokio::test]
async fn test_zmq_publisher_publish_transaction() {
let config = ZmqConfig {
hashtx: Some("tcp://127.0.0.1:28333".to_string()),
rawtx: Some("tcp://127.0.0.1:28335".to_string()),
sequence: Some("tcp://127.0.0.1:28336".to_string()),
..Default::default()
};
if let Ok(publisher) = ZmqPublisher::new(&config) {
let tx = blvm_protocol::Transaction {
version: 1,
inputs: vec![].into(),
outputs: vec![].into(),
lock_time: 0,
};
let tx_hash: blvm_protocol::Hash = [0u8; 32];
let _result = publisher.publish_transaction(&tx, &tx_hash, true).await;
}
}
#[cfg(not(feature = "zmq"))]
#[test]
fn test_zmq_feature_not_enabled() {
assert!(true);
}