Skip to content

Commit

Permalink
Fix cch e2e test receive btc
Browse files Browse the repository at this point in the history
  • Loading branch information
contrun committed Feb 14, 2025
1 parent 773f0d1 commit 9ab3aaf
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 251 deletions.
52 changes: 52 additions & 0 deletions tests/bruno/e2e/cross-chain-hub/09-create-fiber-invoice.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
meta {
name: 09-create-fiber-invoice
type: http
seq: 9
}

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": "new_invoice",
"params": [
{
"amount": "0x1",
"currency": "Fibd",
"description": "test invoice",
"udt_type_script": {
"args": "0x32e555f3ff8e135cece1351a6a2971518392c1e30375c1e006ad0ce8eac07947",
"code_hash": "0xe1e354d6d643ad42724d40967e334984534e0367405c5ae42a9d7d63d77df419",
"hash_type": "data1"
}
}
]
}
}

assert {
res.status: eq 200
res.body.error: isUndefined
res.body.result.invoice_address: isDefined
res.body.result.invoice.data.payment_hash: isDefined
}

script:post-response {
bru.setVar("FIBER_PAY_REQ", res.body.result.invoice_address);
bru.setVar("PAYMENT_HASH", res.body.result.invoice.data.payment_hash);
}

docs {
Create a fiber invoice to receive money
}
61 changes: 0 additions & 61 deletions tests/bruno/e2e/cross-chain-hub/09-create-receive-btc-order.bru

This file was deleted.

44 changes: 44 additions & 0 deletions tests/bruno/e2e/cross-chain-hub/10-create-receive-btc-order.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
meta {
name: 10-create-receive-btc-order
type: http
seq: 10
}

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": "receive_btc",
"params": [
{
"fiber_pay_req": "{{FIBER_PAY_REQ}}"
}
]
}
}

assert {
res.status: eq 200
res.body.error: isUndefined
res.body.result.btc_pay_req: isDefined
}

script:post-response {
bru.setVar("BTC_PAY_REQ", res.body.result.btc_pay_req);
console.log(res.body.result.btc_pay_req);
}

docs {
CKB user requests a BTC invoice to receive BTC from Bitcoin user.
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
meta {
name: 11-get-receive-btc-order-tlc-id
name: 11-check-receive-btc-order
type: http
seq: 11
}
Expand Down Expand Up @@ -32,32 +32,3 @@ assert {
res.body.error: isUndefined
res.status: eq 200
}

script:pre-request {
if(bru.getVar("iteration") === undefined){
bru.setVar("iteration", 0);
}
}

script:post-response {
const i = bru.getVar("iteration");
const n = bru.getVar("max_iterations");
if (i < n) {
console.log(`Try ${i+1}/${n}`);
}

if (res.body.result.tlc_id !== null) {
bru.setVar("N3N1_TLC_ID1", res.body.result.tlc_id);
console.log(`Node 3 has sent a pending tlc: ${res.body.result.tlc_id}`);
bru.setVar("iteration", 0);
// wait for confirmation
await new Promise(r => setTimeout(r, 500));
} else if (i+1 < n) {
await new Promise(r => setTimeout(r, 10));
bru.setVar("iteration", i + 1);
bru.setNextRequest("11-get-receive-btc-order-tlc-id");
} else {
bru.setVar("iteration", 0);
throw new Error("Node 3 has not sent a pending tlc");
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: 10-pay-btc-invoice
name: 12-pay-btc-invoice
type: http
seq: 10
seq: 12
}

post {
Expand Down

This file was deleted.

66 changes: 66 additions & 0 deletions tests/bruno/e2e/cross-chain-hub/13-get-invoice-status.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
meta {
name: 13-get-invoice-status
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": "get_invoice",
"params": [
{
"payment_hash": "{{PAYMENT_HASH}}"
}
]
}
}

assert {
res.body.error: isUndefined
res.body.result.status: isDefined
}


script:pre-request {
if(bru.getVar("iteration") === undefined){
bru.setVar("iteration", 0);
}
}

vars:post-response {
max_iterations: 20
}

script:post-response {
const i = bru.getVar("iteration");
const n = bru.getVar("max_iterations");
if (i < n) {
console.log(`Try ${i+1}/${n}`);
console.log(res.body)
}

if (res.body.result.status != "Paid") {
console.log("Invoicee is paid");
bru.setVar("iteration", 0);
} else if (i+1 < n) {
await new Promise(r => setTimeout(r, 100));
bru.setVar("iteration", i + 1);
bru.setNextRequest("12-get-invoice-status");
} else {
bru.setVar("iteration", 0);
throw new Error("Bob has not received the payment");
}
}
45 changes: 0 additions & 45 deletions tests/bruno/e2e/cross-chain-hub/13-node1-send-shutdown-channel.bru

This file was deleted.

Loading

0 comments on commit 9ab3aaf

Please sign in to comment.