Skip to content

Commit

Permalink
Close both channels in cch e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
contrun authored and doitian committed Jul 5, 2024
1 parent bb0ed2c commit 1cdea9b
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/bruno/e2e/cross-chain-hub/13-node1-send-shutdown-channel.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
meta {
name: 13-node1-send-shutdown-channel
type: http
seq: 13
}

post {
url: {{NODE1_RPC_URL}}
body: json
auth: none
}

headers {
Content-Type: application/json
Accept: application/json
}

body:json {
{
"id": "42",
"jsonrpc": "2.0",
"method": "shutdown_channel",
"params": [
{
"channel_id": "{{N1N3_CHANNEL_ID}}",
"close_script": {
"code_hash": "0x2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a",
"hash_type": "data",
"args": "0x0101010101010101010101010101010101010101"
},
"fee_rate": "0x3FC"
}
]
}
}

assert {
res.body.error: isUndefined
res.body.result: isNull
}

script:post-response {
// Sleep for sometime to make sure current operation finishes before next request starts.
await new Promise(r => setTimeout(r, 100));
}
40 changes: 40 additions & 0 deletions tests/bruno/e2e/cross-chain-hub/14-node3-send-shutdown-channel.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
meta {
name: 14-node3-send-shutdown-channel
type: http
seq: 14
}

post {
url: {{NODE1_RPC_URL}}
body: json
auth: none
}

headers {
Content-Type: application/json
Accept: application/json
}

body:json {
{
"id": "42",
"jsonrpc": "2.0",
"method": "shutdown_channel",
"params": [
{
"channel_id": "{{N1N3_CHANNEL_ID}}",
"close_script": {
"code_hash": "0x2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a",
"hash_type": "data",
"args": "0x0303030303030303030303030303030303030303"
},
"fee_rate": "0x3FC"
}
]
}
}

script:post-response {
// Sleep for sometime to make sure current operation finishes before next request starts.
await new Promise(r => setTimeout(r, 100));
}
35 changes: 35 additions & 0 deletions tests/bruno/e2e/cross-chain-hub/15-node3-list-channel.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
meta {
name: 15-node3-list-channel
type: http
seq: 15
}

post {
url: {{NODE3_RPC_URL}}
body: json
auth: none
}

headers {
Content-Type: application/json
Accept: application/json
}

body:json {
{
"id": "42",
"jsonrpc": "2.0",
"method": "list_channels",
"params": [
{
"peer_id": "{{NODE1_PEERID}}"
}
]
}
}

assert {
res.body.error: isUndefined
res.body.result.channels: isDefined
res.body.result.channels.map(channel => channel.channel_id): notContains {{N1N3_CHANNEL_ID}}
}
20 changes: 20 additions & 0 deletions tests/bruno/e2e/cross-chain-hub/16-node1-list-ln-channel.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
meta {
name: 16-node1-list-ln-channel
type: http
seq: 16
}

get {
url: {{LND_BOB_RPC_URL}}/v1/channels
body: json
auth: none
}

assert {
res.body.channels: length 1
}

script:post-response {
console.log("list ln channel result: ", res.body);
bru.setVar("LN_CHANNEL_ID", res.body.channels[0].channel_point.replace(":", "/"));
}
33 changes: 33 additions & 0 deletions tests/bruno/e2e/cross-chain-hub/17-node1-close-ln-channel.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
meta {
name: 17-node1-close-ln-channel
type: http
seq: 17
}

delete {
url: {{LND_BOB_RPC_URL}}/v1/channels/{{LN_CHANNEL_ID}}
body: json
auth: none
}

script:pre-request {
const axios = require('axios');

const url = bru.getEnvVar("LND_BOB_RPC_URL") + "/v1/channels/" + bru.getVar("LN_CHANNEL_ID");
console.log(url);

const resp = await axios({
method: 'DELETE',
url: url,
responseType: 'stream'
});
resp.data.destroy();
}

assert {
res.status: eq 500
}

docs {
This is a server-streaming RPC which will block Bruno. The workaround is sending the request in the pre-script so the Bruno request will return 500 because the channel is already closed.
}
19 changes: 19 additions & 0 deletions tests/bruno/e2e/cross-chain-hub/18-node1-list-ln-channel.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
meta {
name: 18-node1-list-ln-channel
type: http
seq: 18
}

get {
url: {{LND_BOB_RPC_URL}}/v1/channels
body: json
auth: none
}

assert {
res.body.channels: length 0
}

script:post-response {
console.log("list channel result: ", res.body);
}

0 comments on commit 1cdea9b

Please sign in to comment.