diff --git a/src/ckb/channel.rs b/src/ckb/channel.rs index 1615a037..47cdbb89 100644 --- a/src/ckb/channel.rs +++ b/src/ckb/channel.rs @@ -645,6 +645,10 @@ impl ChannelActor { ) -> ProcessingChannelResult { debug!("Handling shutdown command: {:?}", &command); let flags = match state.state { + ChannelState::Closed => { + debug!("Channel already closed, ignoring shutdown command"); + return Ok(()); + } ChannelState::ChannelReady() => { debug!("Handling shutdown command in ChannelReady state"); ShuttingDownFlags::empty() @@ -652,9 +656,10 @@ impl ChannelActor { ChannelState::ShuttingDown(flags) => flags, _ => { debug!("Handling shutdown command in state {:?}", &state.state); - return Err(ProcessingChannelError::InvalidState( - "Trying to send shutdown message while in invalid state".to_string(), - )); + return Err(ProcessingChannelError::InvalidState(format!( + "Trying to send shutdown message while in invalid state {:?}", + &state.state + ))); } }; diff --git a/tests/bruno/e2e/3-nodes-transfer/22-node2-send-shutdown-channel-1.bru b/tests/bruno/e2e/3-nodes-transfer/22-node2-send-shutdown-channel-1.bru index 022658c3..976927e7 100644 --- a/tests/bruno/e2e/3-nodes-transfer/22-node2-send-shutdown-channel-1.bru +++ b/tests/bruno/e2e/3-nodes-transfer/22-node2-send-shutdown-channel-1.bru @@ -35,15 +35,11 @@ body:json { } assert { - res.body.error: isDefined - res.body.result: isUndefined + res.body.error: isUndefined + res.body.result: isNull } script:post-response { // Sleep for sometime to make sure current operation finishes before next request starts. - // will get error message since channel is closed in previous step await new Promise(r => setTimeout(r, 100)); - if (!(res.body.error.message === "Messaging failed because channel is closed")) { - throw new Error("Assertion failed: error message is not right"); - } } diff --git a/tests/bruno/e2e/3-nodes-transfer/24-node3-send-shutdown-channel-2.bru b/tests/bruno/e2e/3-nodes-transfer/24-node3-send-shutdown-channel-2.bru index f0d3d0bd..4431e746 100644 --- a/tests/bruno/e2e/3-nodes-transfer/24-node3-send-shutdown-channel-2.bru +++ b/tests/bruno/e2e/3-nodes-transfer/24-node3-send-shutdown-channel-2.bru @@ -35,15 +35,6 @@ body:json { } assert { - res.body.error: isDefined - res.body.result: isUndefined -} - -script:post-response { - // Sleep for sometime to make sure current operation finishes before next request starts. - // will get error message since channel is closed in previous step - await new Promise(r => setTimeout(r, 100)); - if (!(res.body.error.message === "Messaging failed because channel is closed")) { - throw new Error("Assertion failed: error message is not right"); - } -} + res.body.error: isUndefined + res.body.result: isNull +} \ No newline at end of file diff --git a/tests/bruno/e2e/udt/12-node2-send-shutdown-channel-error.bru b/tests/bruno/e2e/udt/12-node2-send-shutdown-channel-error.bru index 9470f5b2..729b7c5f 100644 --- a/tests/bruno/e2e/udt/12-node2-send-shutdown-channel-error.bru +++ b/tests/bruno/e2e/udt/12-node2-send-shutdown-channel-error.bru @@ -35,15 +35,6 @@ body:json { } assert { - res.body.error: isDefined - res.body.result: isUndefined -} - -script:post-response { - // Sleep for sometime to make sure current operation finishes before next request starts. - // will get error message since channel is closed in previous step - await new Promise(r => setTimeout(r, 100)); - if (!(res.body.error.message === "Messaging failed because channel is closed")) { - throw new Error("Assertion failed: error message is not right"); - } -} + res.body.error: isUndefined + res.body.result: isNull +} \ No newline at end of file