-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add invoice get rpc and check expire
- Loading branch information
1 parent
856a2ad
commit 5ccb247
Showing
9 changed files
with
224 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
tests/bruno/e2e/router-pay/22-node3-gen-expiring-invoice.bru
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
meta { | ||
name: generate a invoice which will expiring in short time | ||
type: http | ||
seq: 22 | ||
} | ||
|
||
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": "new_invoice", | ||
"params": [ | ||
{ | ||
"amount": "0x613", | ||
"currency": "Fibb", | ||
"description": "test invoice generated by node3", | ||
"expiry": "0x2", | ||
"final_cltv": "0x28", | ||
"payment_preimage": "{{payment_preimage}}" | ||
} | ||
] | ||
} | ||
} | ||
|
||
assert { | ||
res.body.error: isUndefined | ||
res.body.result: isDefined | ||
} | ||
|
||
script:pre-request { | ||
// generate random preimage | ||
function generateRandomPreimage() { | ||
let hash = '0x'; | ||
for (let i = 0; i < 64; i++) { | ||
hash += Math.floor(Math.random() * 16).toString(16); | ||
} | ||
return hash; | ||
} | ||
const payment_preimage = generateRandomPreimage(); | ||
bru.setVar("payment_preimage", payment_preimage); | ||
let hash_algorithm = bru.getEnvVar("HASH_ALGORITHM"); | ||
if (hash_algorithm !== null) { | ||
let body = req.getBody(); | ||
body.params[0].hash_algorithm = hash_algorithm; | ||
req.setBody(body); | ||
} | ||
} | ||
|
||
script:post-response { | ||
// Sleep for sometime to make sure current operation finishes before next request starts. | ||
await new Promise(r => setTimeout(r, 3000)); | ||
console.log("generated result: ", res.body.result); | ||
bru.setVar("encoded_invoice", res.body.result.invoice_address); | ||
} |
48 changes: 48 additions & 0 deletions
48
tests/bruno/e2e/router-pay/23-node1-send-payment-will-fail.bru
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
meta { | ||
name: Node1 send payment with router | ||
type: http | ||
seq: 23 | ||
} | ||
|
||
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": "send_payment", | ||
"params": [ | ||
{ | ||
"invoice": "{{encoded_invoice}}" | ||
} | ||
] | ||
} | ||
} | ||
|
||
assert { | ||
res.body.error: isDefined | ||
} | ||
|
||
|
||
script:pre-request { | ||
// sleep for a while | ||
await new Promise(r => setTimeout(r, 1000)); | ||
} | ||
|
||
|
||
script:post-response { | ||
// Sleep for sometime to make sure current operation finishes before next request starts. | ||
await new Promise(r => setTimeout(r, 100)); | ||
if (!(res.body.error.message.includes("invoice is expired"))) { | ||
throw new Error("Assertion failed: error message is not right"); | ||
} | ||
} |