Skip to content

Commit

Permalink
Merge pull request #209 from quake/quake/fix-merge-test-error
Browse files Browse the repository at this point in the history
fix: resolve merge test error
  • Loading branch information
quake authored Oct 1, 2024
2 parents 059c0c7 + 3e1aa06 commit 73132b1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 55 deletions.
35 changes: 7 additions & 28 deletions src/fiber/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5618,10 +5618,7 @@ mod tests {

#[tokio::test]
async fn test_open_channel_to_peer() {
let [node_a, mut node_b] = NetworkNode::new_n_interconnected_nodes(2)
.await
.try_into()
.unwrap();
let [node_a, mut node_b] = NetworkNode::new_n_interconnected_nodes().await;

let message = |rpc_reply| {
NetworkActorMessage::Command(NetworkActorCommand::OpenChannel(
Expand Down Expand Up @@ -5662,10 +5659,7 @@ mod tests {
async fn test_open_and_accept_channel() {
use crate::fiber::channel::DEFAULT_CHANNEL_MINIMAL_CKB_AMOUNT;

let [node_a, mut node_b] = NetworkNode::new_n_interconnected_nodes(2)
.await
.try_into()
.unwrap();
let [node_a, mut node_b] = NetworkNode::new_n_interconnected_nodes().await;

let message = |rpc_reply| {
NetworkActorMessage::Command(NetworkActorCommand::OpenChannel(
Expand Down Expand Up @@ -5764,10 +5758,7 @@ mod tests {
}

async fn do_test_channel_commitment_tx_after_add_tlc(algorithm: HashAlgorithm) {
let [mut node_a, mut node_b] = NetworkNode::new_n_interconnected_nodes(2)
.await
.try_into()
.unwrap();
let [mut node_a, mut node_b] = NetworkNode::new_n_interconnected_nodes().await;

let node_a_funding_amount = 100000000000;
let node_b_funidng_amount = 6200000000;
Expand Down Expand Up @@ -5960,10 +5951,7 @@ mod tests {
node_b_funding_amount: u128,
public: bool,
) -> (NetworkNode, NetworkNode, Hash256) {
let [mut node_a, mut node_b] = NetworkNode::new_n_interconnected_nodes(2)
.await
.try_into()
.unwrap();
let [mut node_a, mut node_b] = NetworkNode::new_n_interconnected_nodes().await;

let message = |rpc_reply| {
NetworkActorMessage::Command(NetworkActorCommand::OpenChannel(
Expand Down Expand Up @@ -6302,10 +6290,7 @@ mod tests {
async fn test_revoke_old_commitment_transaction() {
init_tracing();

let [mut node_a, mut node_b] = NetworkNode::new_n_interconnected_nodes(2)
.await
.try_into()
.unwrap();
let [mut node_a, mut node_b] = NetworkNode::new_n_interconnected_nodes().await;

let message = |rpc_reply| {
NetworkActorMessage::Command(NetworkActorCommand::OpenChannel(
Expand Down Expand Up @@ -6480,10 +6465,7 @@ mod tests {

#[tokio::test]
async fn test_create_channel() {
let [mut node_a, mut node_b] = NetworkNode::new_n_interconnected_nodes(2)
.await
.try_into()
.unwrap();
let [mut node_a, mut node_b] = NetworkNode::new_n_interconnected_nodes().await;

let message = |rpc_reply| {
NetworkActorMessage::Command(NetworkActorCommand::OpenChannel(
Expand Down Expand Up @@ -6605,10 +6587,7 @@ mod tests {

#[tokio::test]
async fn test_reestablish_channel() {
let [mut node_a, mut node_b] = NetworkNode::new_n_interconnected_nodes(2)
.await
.try_into()
.unwrap();
let [mut node_a, mut node_b] = NetworkNode::new_n_interconnected_nodes().await;

let message = |rpc_reply| {
NetworkActorMessage::Command(NetworkActorCommand::OpenChannel(
Expand Down
13 changes: 5 additions & 8 deletions src/fiber/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3783,7 +3783,7 @@ mod tests {
async fn test_channel_update_version() {
let (node, channel_info, _priv_key, sk1, _sk2) = create_a_channel().await;

let create_channel_update = |version: u64, key: Privkey| {
let create_channel_update = |version: u64, key: &Privkey| {
let mut channel_update = ChannelUpdate::new_unsigned(
get_chain_hash(),
channel_info.announcement_msg.channel_outpoint.clone(),
Expand All @@ -3808,7 +3808,7 @@ mod tests {
channel_update
};

let channel_update_2 = create_channel_update(2, sk1);
let channel_update_2 = create_channel_update(2, &sk1);
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
let new_channel_info = node
.store
Expand All @@ -3824,7 +3824,7 @@ mod tests {
);

// Old channel update will not replace the new one.
let _channel_update_1 = create_channel_update(1, sk1);
let _channel_update_1 = create_channel_update(1, &sk1);
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
let new_channel_info = node
.store
Expand All @@ -3840,7 +3840,7 @@ mod tests {
);

// New channel update will replace the old one.
let channel_update_3 = create_channel_update(3, sk1);
let channel_update_3 = create_channel_update(3, &sk1);
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
let new_channel_info = node
.store
Expand Down Expand Up @@ -3971,10 +3971,7 @@ mod tests {
async fn test_sync_node_announcement_after_restart() {
init_tracing();

let [mut node1, mut node2] = NetworkNode::new_n_interconnected_nodes(2)
.await
.try_into()
.unwrap();
let [mut node1, mut node2] = NetworkNode::new_n_interconnected_nodes().await;

node1
.expect_event(|c| matches!(c, NetworkServiceEvent::SyncingCompleted))
Expand Down
27 changes: 8 additions & 19 deletions src/fiber/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ pub fn get_fiber_config<P: AsRef<Path>>(base_dir: P, node_name: Option<&str>) ->
}
}

#[derive(Debug)]
pub struct NetworkNode {
/// The base directory of the node, will be deleted after this struct dropped.
pub base_dir: Arc<TempDir>,
Expand Down Expand Up @@ -342,7 +341,6 @@ impl NetworkNode {
pub async fn start(&mut self) {
let config = self.get_node_config();
let new = Self::new_with_config(config).await;
tracing::debug!("New node started: {:?}", &new);
*self = new;
}

Expand All @@ -360,16 +358,19 @@ impl NetworkNode {
self.start().await;
}

pub async fn new_n_interconnected_nodes(n: usize) -> Vec<Self> {
let mut nodes: Vec<NetworkNode> = Vec::with_capacity(n);
for i in 0..n {
pub async fn new_n_interconnected_nodes<const N: usize>() -> [Self; N] {
let mut nodes: Vec<NetworkNode> = Vec::with_capacity(N);
for i in 0..N {
let new = Self::new_with_node_name_opt(Some(format!("Node {i}"))).await;
for node in nodes.iter_mut() {
node.connect_to(&new).await;
}
nodes.push(new);
}
nodes
match nodes.try_into() {
Ok(nodes) => nodes,
Err(_) => unreachable!(),
}
}

// Create n nodes and connect them. The config_gen function
Expand Down Expand Up @@ -459,7 +460,7 @@ impl NetworkNode {
}
}

#[derive(Debug, Clone, Default)]
#[derive(Clone, Default)]
pub struct MemoryStore {
channel_actor_state_map: Arc<RwLock<HashMap<Hash256, ChannelActorState>>>,
channels_map: Arc<RwLock<HashMap<OutPoint, ChannelInfo>>>,
Expand Down Expand Up @@ -673,25 +674,13 @@ impl InvoiceStore for MemoryStore {
mod tests {
use super::NetworkNode;

#[tokio::test]
async fn test_start_network_node() {
println!("starting network node");
let node = NetworkNode::new().await;
println!("network node {:?} started", &node);
}

#[tokio::test]
async fn test_connect_to_other_node() {
let mut node_a = NetworkNode::new().await;
let node_b = NetworkNode::new().await;
node_a.connect_to(&node_b).await;
}

#[tokio::test]
async fn test_create_two_interconnected_nodes() {
let _two_nodes = NetworkNode::new_n_interconnected_nodes(2).await;
}

#[tokio::test]
async fn test_restart_network_node() {
let mut node = NetworkNode::new().await;
Expand Down

0 comments on commit 73132b1

Please sign in to comment.