Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/eclair-integration.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
name: CI Checks - Eclair Integration Tests

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check-eclair:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Start bitcoind, electrs, and Eclair
run: docker compose -f docker-compose-eclair.yml up -d

- name: Wait for Eclair to be ready
run: |
for i in $(seq 1 30); do
if curl -s -u :eclairpw -X POST http://127.0.0.1:8080/getinfo > /dev/null 2>&1; then
echo "Eclair is ready"
break
fi
echo "Waiting for Eclair... ($i)"
sleep 5
done

- name: Run Eclair integration tests
run: RUSTFLAGS="--cfg eclair_test" cargo test --test integration_tests_eclair -- --exact --show-output
1 change: 1 addition & 0 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,6 +121,7 @@ check-cfg = [
"cfg(ldk_bench)",
"cfg(tokio_unstable)",
"cfg(cln_test)",
"cfg(eclair_test)",
"cfg(lnd_test)",
"cfg(cycle_tests)",
]
Expand Down
84 changes: 84 additions & 0 deletions docker-compose-eclair.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
services:
bitcoin:
image: blockstream/bitcoind:27.2
platform: linux/amd64
command:
[
"bitcoind",
"-printtoconsole",
"-regtest=1",
"-rpcallowip=0.0.0.0/0",
"-rpcbind=0.0.0.0",
"-rpcuser=user",
"-rpcpassword=pass",
"-fallbackfee=0.00001",
"-zmqpubrawblock=tcp://0.0.0.0:28332",
"-zmqpubrawtx=tcp://0.0.0.0:28333"
]
ports:
- "18443:18443" # Regtest RPC port
- "18444:18444" # Regtest P2P port
- "28332:28332" # ZMQ block port
- "28333:28333" # ZMQ tx port
networks:
- bitcoin-electrs
healthcheck:
test: ["CMD", "bitcoin-cli", "-regtest", "-rpcuser=user", "-rpcpassword=pass", "getblockchaininfo"]
interval: 5s
timeout: 10s
retries: 5

electrs:
image: mempool/electrs:v3.2.0
platform: linux/amd64
depends_on:
bitcoin:
condition: service_healthy
command:
[
"-vvvv",
"--timestamp",
"--jsonrpc-import",
"--cookie=user:pass",
"--network=regtest",
"--daemon-rpc-addr=bitcoin:18443",
"--http-addr=0.0.0.0:3002",
"--electrum-rpc-addr=0.0.0.0:50001"
]
ports:
- "3002:3002"
- "50001:50001"
networks:
- bitcoin-electrs

eclair:
image: acinq/eclair:latest
depends_on:
bitcoin:
condition: service_healthy
environment:
- |
JAVA_OPTS=
-Xmx512m
-Declair.chain=regtest
-Declair.server.port=9736
-Declair.api.enabled=true
-Declair.api.binding-ip=0.0.0.0
-Declair.api.port=8080
-Declair.api.password=eclairpw
-Declair.bitcoind.host=bitcoin
-Declair.bitcoind.rpc-port=18443
-Declair.bitcoind.rpc-user=user
-Declair.bitcoind.rpc-password=pass
-Declair.bitcoind.zmqblock=tcp://bitcoin:28332
-Declair.bitcoind.zmqtx=tcp://bitcoin:28333
-Declair.printToConsole
ports:
- "8080:8080" # API
- "9736:9736" # P2P
networks:
- bitcoin-electrs

networks:
bitcoin-electrs:
driver: bridge
2 changes: 1 addition & 1 deletion tests/common/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

#![cfg(any(test, cln_test, lnd_test, vss_test))]
#![cfg(any(test, cln_test, eclair_test, lnd_test, vss_test))]
#![allow(dead_code)]

pub(crate) mod logging;
Expand Down
259 changes: 259 additions & 0 deletions tests/integration_tests_eclair.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
// This file is Copyright its original authors, visible in version control history.
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

#![cfg(eclair_test)]

mod common;

use std::str::FromStr;

use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use electrsd::corepc_client::client_sync::Auth;
use electrsd::corepc_node::Client as BitcoindClient;
use electrum_client::Client as ElectrumClient;
use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::bitcoin::Amount;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::{Builder, Event};
use lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription, Description};

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_eclair() {
// Setup bitcoind / electrs clients
let bitcoind_client = BitcoindClient::new_with_auth(
"http://127.0.0.1:18443",
Auth::UserPass("user".to_string(), "pass".to_string()),
)
.unwrap();
let electrs_client = ElectrumClient::new("tcp://127.0.0.1:50001").unwrap();

// Give electrs a kick.
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 1).await;

// Setup LDK Node
let config = common::random_config(true);
let mut builder = Builder::from_config(config.node_config);
builder.set_chain_source_esplora("http://127.0.0.1:3002".to_string(), None);

let node = builder.build(config.node_entropy).unwrap();
node.start().unwrap();

// Premine some funds and distribute
let address = node.onchain_payment().new_address().unwrap();
let premine_amount = Amount::from_sat(5_000_000);
common::premine_and_distribute_funds(
&bitcoind_client,
&electrs_client,
vec![address],
premine_amount,
)
.await;

// Setup Eclair
let eclair = TestEclairClient::new("http://127.0.0.1:8080", "eclairpw");

// Wait for Eclair to be synced
let eclair_info = {
loop {
match eclair.get_info().await {
Ok(info) => {
let block_height =
info["blockHeight"].as_u64().expect("blockHeight should be a number");
if block_height > 0 {
break info;
}
},
Err(e) => {
println!("Waiting for Eclair to be ready: {}", e);
},
}
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
}
};

let eclair_node_id =
PublicKey::from_str(eclair_info["nodeId"].as_str().unwrap()).expect("valid nodeId");
let eclair_address: SocketAddress = "127.0.0.1:9736".parse().unwrap();

node.sync_wallets().unwrap();

// Open the channel
let funding_amount_sat = 1_000_000;

node.open_channel(eclair_node_id, eclair_address, funding_amount_sat, Some(500_000_000), None)
.unwrap();

let funding_txo = common::expect_channel_pending_event!(node, eclair_node_id);
common::wait_for_tx(&electrs_client, funding_txo.txid).await;
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
let user_channel_id = common::expect_channel_ready_event!(node, eclair_node_id);

// Send a payment to Eclair (LDK -> Eclair)
let eclair_invoice_str = eclair
.create_invoice(100_000_000, "test-ldk-to-eclair")
.await
.expect("Failed to create Eclair invoice");
let parsed_invoice = Bolt11Invoice::from_str(&eclair_invoice_str).unwrap();

node.bolt11_payment().send(&parsed_invoice, None).unwrap();
common::expect_event!(node, PaymentSuccessful);

// Verify Eclair received the payment
let received_info = eclair
.get_received_info(&eclair_invoice_str)
.await
.expect("Failed to get received info from Eclair");
let status = received_info["status"]["type"].as_str().unwrap_or("unknown");
assert_eq!(status, "received", "Eclair payment should be in received state");

// Send a payment to LDK (Eclair -> LDK)
let amount_msat = 9_000_000;
let invoice_description =
Bolt11InvoiceDescription::Direct(Description::new("eclairTest".to_string()).unwrap());
let ldk_invoice =
node.bolt11_payment().receive(amount_msat, &invoice_description, 3600).unwrap();
eclair.pay_invoice(&ldk_invoice.to_string()).await.expect("Eclair failed to pay invoice");
common::expect_event!(node, PaymentReceived);

// Splice in (soft-fail: splice interop between LDK and Eclair may not yet be compatible)
let eclair_channels = eclair.list_channels().await.expect("Failed to list Eclair channels");
if let Some(channel) = eclair_channels.as_array().and_then(|arr| arr.first()) {
let channel_id = channel["channelId"].as_str().unwrap_or("");
if !channel_id.is_empty() {
match eclair.splice_in(channel_id, 500_000).await {
Ok(_) => {
println!("Splice in succeeded, mining blocks to confirm...");
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
},
Err(e) => {
println!(
"Splice in not yet supported in LDK<->Eclair interop, skipping: {}",
e
);
},
}

// Splice out (soft-fail)
let addr = node.onchain_payment().new_address().unwrap();
match eclair.splice_out(channel_id, 200_000, &addr.to_string()).await {
Ok(_) => {
println!("Splice out succeeded, mining blocks to confirm...");
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
},
Err(e) => {
println!(
"Splice out not yet supported in LDK<->Eclair interop, skipping: {}",
e
);
},
}
}
}

// Close the channel
node.close_channel(&user_channel_id, eclair_node_id).unwrap();
common::expect_event!(node, ChannelClosed);
node.stop().unwrap();
}

struct TestEclairClient {
base_url: String,
auth_header: String,
}

impl TestEclairClient {
fn new(base_url: &str, password: &str) -> Self {
let credentials = format!(":{}", password);
let auth_header = format!("Basic {}", BASE64_STANDARD.encode(credentials.as_bytes()));
TestEclairClient { base_url: base_url.to_string(), auth_header }
}

async fn eclair_post(
&self, endpoint: &str, params: &[(&str, &str)],
) -> Result<serde_json::Value, String> {
let url = format!("{}/{}", self.base_url, endpoint);
let body = params.iter().map(|(k, v)| format!("{}={}", k, v)).collect::<Vec<_>>().join("&");

let request = bitreq::post(&url)
.with_header("Authorization", &self.auth_header)
.with_header("Content-Type", "application/x-www-form-urlencoded")
.with_body(body.as_bytes())
.with_timeout(30);

let response = request
.send_async()
.await
.map_err(|e| format!("HTTP request to {} failed: {}", endpoint, e))?;

if response.status_code != 200 {
let body_str = response.as_str().unwrap_or("(non-utf8 body)");
return Err(format!(
"Eclair {} returned HTTP {}: {}",
endpoint, response.status_code, body_str
));
}

let body_str = response
.as_str()
.map_err(|e| format!("Failed to read response body from {}: {}", endpoint, e))?;

serde_json::from_str(body_str)
.map_err(|e| format!("Failed to parse JSON from {}: {}", endpoint, e))
}

async fn get_info(&self) -> Result<serde_json::Value, String> {
self.eclair_post("getinfo", &[]).await
}

async fn create_invoice(&self, amount_msat: u64, description: &str) -> Result<String, String> {
let amount_str = amount_msat.to_string();
let result = self
.eclair_post(
"createinvoice",
&[("amountMsat", &amount_str), ("description", description)],
)
.await?;
result["serialized"]
.as_str()
.map(|s| s.to_string())
.ok_or_else(|| "Missing 'serialized' field in createinvoice response".to_string())
}

async fn pay_invoice(&self, invoice: &str) -> Result<serde_json::Value, String> {
self.eclair_post("payinvoice", &[("invoice", invoice), ("blocking", "true")]).await
}

async fn get_received_info(&self, invoice: &str) -> Result<serde_json::Value, String> {
self.eclair_post("getreceivedinfo", &[("invoice", invoice)]).await
}

async fn list_channels(&self) -> Result<serde_json::Value, String> {
self.eclair_post("channels", &[]).await
}

async fn splice_in(
&self, channel_id: &str, amount_sat: u64,
) -> Result<serde_json::Value, String> {
let amount_str = amount_sat.to_string();
self.eclair_post("splicein", &[("channelId", channel_id), ("amountIn", &amount_str)]).await
}

async fn splice_out(
&self, channel_id: &str, amount_sat: u64, address: &str,
) -> Result<serde_json::Value, String> {
let amount_str = amount_sat.to_string();
self.eclair_post(
"spliceout",
&[("channelId", channel_id), ("amountOut", &amount_str), ("address", address)],
)
.await
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/eclair-integration.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
name: CI Checks - Eclair Integration Tests

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check-eclair:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Start bitcoind, electrs, and Eclair
run: docker compose -f docker-compose-eclair.yml up -d

- name: Wait for Eclair to be ready
run: |
for i in $(seq 1 30); do
if curl -s -u :eclairpw -X POST http://127.0.0.1:8080/getinfo > /dev/null 2>&1; then
echo "Eclair is ready"
break
fi
echo "Waiting for Eclair... ($i)"
sleep 5
done

- name: Run Eclair integration tests
run: RUSTFLAGS="--cfg eclair_test" cargo test --test integration_tests_eclair -- --exact --show-output
1 change: 1 addition & 0 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,6 +121,7 @@ check-cfg = [
"cfg(ldk_bench)",
"cfg(tokio_unstable)",
"cfg(cln_test)",
"cfg(eclair_test)",
"cfg(lnd_test)",
"cfg(cycle_tests)",
]
Expand Down
84 changes: 84 additions & 0 deletions docker-compose-eclair.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
services:
bitcoin:
image: blockstream/bitcoind:27.2
platform: linux/amd64
command:
[
"bitcoind",
"-printtoconsole",
"-regtest=1",
"-rpcallowip=0.0.0.0/0",
"-rpcbind=0.0.0.0",
"-rpcuser=user",
"-rpcpassword=pass",
"-fallbackfee=0.00001",
"-zmqpubrawblock=tcp://0.0.0.0:28332",
"-zmqpubrawtx=tcp://0.0.0.0:28333"
]
ports:
- "18443:18443" # Regtest RPC port
- "18444:18444" # Regtest P2P port
- "28332:28332" # ZMQ block port
- "28333:28333" # ZMQ tx port
networks:
- bitcoin-electrs
healthcheck:
test: ["CMD", "bitcoin-cli", "-regtest", "-rpcuser=user", "-rpcpassword=pass", "getblockchaininfo"]
interval: 5s
timeout: 10s
retries: 5

electrs:
image: mempool/electrs:v3.2.0
platform: linux/amd64
depends_on:
bitcoin:
condition: service_healthy
command:
[
"-vvvv",
"--timestamp",
"--jsonrpc-import",
"--cookie=user:pass",
"--network=regtest",
"--daemon-rpc-addr=bitcoin:18443",
"--http-addr=0.0.0.0:3002",
"--electrum-rpc-addr=0.0.0.0:50001"
]
ports:
- "3002:3002"
- "50001:50001"
networks:
- bitcoin-electrs

eclair:
image: acinq/eclair:latest
depends_on:
bitcoin:
condition: service_healthy
environment:
- |
JAVA_OPTS=
-Xmx512m
-Declair.chain=regtest
-Declair.server.port=9736
-Declair.api.enabled=true
-Declair.api.binding-ip=0.0.0.0
-Declair.api.port=8080
-Declair.api.password=eclairpw
-Declair.bitcoind.host=bitcoin
-Declair.bitcoind.rpc-port=18443
-Declair.bitcoind.rpc-user=user
-Declair.bitcoind.rpc-password=pass
-Declair.bitcoind.zmqblock=tcp://bitcoin:28332
-Declair.bitcoind.zmqtx=tcp://bitcoin:28333
-Declair.printToConsole
ports:
- "8080:8080" # API
- "9736:9736" # P2P
networks:
- bitcoin-electrs

networks:
bitcoin-electrs:
driver: bridge
2 changes: 1 addition & 1 deletion tests/common/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

#![cfg(any(test, cln_test, lnd_test, vss_test))]
#![cfg(any(test, cln_test, eclair_test, lnd_test, vss_test))]
#![allow(dead_code)]

pub(crate) mod logging;
Expand Down
259 changes: 259 additions & 0 deletions tests/integration_tests_eclair.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
// This file is Copyright its original authors, visible in version control history.
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

#![cfg(eclair_test)]

mod common;

use std::str::FromStr;

use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use electrsd::corepc_client::client_sync::Auth;
use electrsd::corepc_node::Client as BitcoindClient;
use electrum_client::Client as ElectrumClient;
use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::bitcoin::Amount;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::{Builder, Event};
use lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription, Description};

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_eclair() {
// Setup bitcoind / electrs clients
let bitcoind_client = BitcoindClient::new_with_auth(
"http://127.0.0.1:18443",
Auth::UserPass("user".to_string(), "pass".to_string()),
)
.unwrap();
let electrs_client = ElectrumClient::new("tcp://127.0.0.1:50001").unwrap();

// Give electrs a kick.
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 1).await;

// Setup LDK Node
let config = common::random_config(true);
let mut builder = Builder::from_config(config.node_config);
builder.set_chain_source_esplora("http://127.0.0.1:3002".to_string(), None);

let node = builder.build(config.node_entropy).unwrap();
node.start().unwrap();

// Premine some funds and distribute
let address = node.onchain_payment().new_address().unwrap();
let premine_amount = Amount::from_sat(5_000_000);
common::premine_and_distribute_funds(
&bitcoind_client,
&electrs_client,
vec![address],
premine_amount,
)
.await;

// Setup Eclair
let eclair = TestEclairClient::new("http://127.0.0.1:8080", "eclairpw");

// Wait for Eclair to be synced
let eclair_info = {
loop {
match eclair.get_info().await {
Ok(info) => {
let block_height =
info["blockHeight"].as_u64().expect("blockHeight should be a number");
if block_height > 0 {
break info;
}
},
Err(e) => {
println!("Waiting for Eclair to be ready: {}", e);
},
}
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
}
};

let eclair_node_id =
PublicKey::from_str(eclair_info["nodeId"].as_str().unwrap()).expect("valid nodeId");
let eclair_address: SocketAddress = "127.0.0.1:9736".parse().unwrap();

node.sync_wallets().unwrap();

// Open the channel
let funding_amount_sat = 1_000_000;

node.open_channel(eclair_node_id, eclair_address, funding_amount_sat, Some(500_000_000), None)
.unwrap();

let funding_txo = common::expect_channel_pending_event!(node, eclair_node_id);
common::wait_for_tx(&electrs_client, funding_txo.txid).await;
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
let user_channel_id = common::expect_channel_ready_event!(node, eclair_node_id);

// Send a payment to Eclair (LDK -> Eclair)
let eclair_invoice_str = eclair
.create_invoice(100_000_000, "test-ldk-to-eclair")
.await
.expect("Failed to create Eclair invoice");
let parsed_invoice = Bolt11Invoice::from_str(&eclair_invoice_str).unwrap();

node.bolt11_payment().send(&parsed_invoice, None).unwrap();
common::expect_event!(node, PaymentSuccessful);

// Verify Eclair received the payment
let received_info = eclair
.get_received_info(&eclair_invoice_str)
.await
.expect("Failed to get received info from Eclair");
let status = received_info["status"]["type"].as_str().unwrap_or("unknown");
assert_eq!(status, "received", "Eclair payment should be in received state");

// Send a payment to LDK (Eclair -> LDK)
let amount_msat = 9_000_000;
let invoice_description =
Bolt11InvoiceDescription::Direct(Description::new("eclairTest".to_string()).unwrap());
let ldk_invoice =
node.bolt11_payment().receive(amount_msat, &invoice_description, 3600).unwrap();
eclair.pay_invoice(&ldk_invoice.to_string()).await.expect("Eclair failed to pay invoice");
common::expect_event!(node, PaymentReceived);

// Splice in (soft-fail: splice interop between LDK and Eclair may not yet be compatible)
let eclair_channels = eclair.list_channels().await.expect("Failed to list Eclair channels");
if let Some(channel) = eclair_channels.as_array().and_then(|arr| arr.first()) {
let channel_id = channel["channelId"].as_str().unwrap_or("");
if !channel_id.is_empty() {
match eclair.splice_in(channel_id, 500_000).await {
Ok(_) => {
println!("Splice in succeeded, mining blocks to confirm...");
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
},
Err(e) => {
println!(
"Splice in not yet supported in LDK<->Eclair interop, skipping: {}",
e
);
},
}

// Splice out (soft-fail)
let addr = node.onchain_payment().new_address().unwrap();
match eclair.splice_out(channel_id, 200_000, &addr.to_string()).await {
Ok(_) => {
println!("Splice out succeeded, mining blocks to confirm...");
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
},
Err(e) => {
println!(
"Splice out not yet supported in LDK<->Eclair interop, skipping: {}",
e
);
},
}
}
}

// Close the channel
node.close_channel(&user_channel_id, eclair_node_id).unwrap();
common::expect_event!(node, ChannelClosed);
node.stop().unwrap();
}

struct TestEclairClient {
base_url: String,
auth_header: String,
}

impl TestEclairClient {
fn new(base_url: &str, password: &str) -> Self {
let credentials = format!(":{}", password);
let auth_header = format!("Basic {}", BASE64_STANDARD.encode(credentials.as_bytes()));
TestEclairClient { base_url: base_url.to_string(), auth_header }
}

async fn eclair_post(
&self, endpoint: &str, params: &[(&str, &str)],
) -> Result<serde_json::Value, String> {
let url = format!("{}/{}", self.base_url, endpoint);
let body = params.iter().map(|(k, v)| format!("{}={}", k, v)).collect::<Vec<_>>().join("&");

let request = bitreq::post(&url)
.with_header("Authorization", &self.auth_header)
.with_header("Content-Type", "application/x-www-form-urlencoded")
.with_body(body.as_bytes())
.with_timeout(30);

let response = request
.send_async()
.await
.map_err(|e| format!("HTTP request to {} failed: {}", endpoint, e))?;

if response.status_code != 200 {
let body_str = response.as_str().unwrap_or("(non-utf8 body)");
return Err(format!(
"Eclair {} returned HTTP {}: {}",
endpoint, response.status_code, body_str
));
}

let body_str = response
.as_str()
.map_err(|e| format!("Failed to read response body from {}: {}", endpoint, e))?;

serde_json::from_str(body_str)
.map_err(|e| format!("Failed to parse JSON from {}: {}", endpoint, e))
}

async fn get_info(&self) -> Result<serde_json::Value, String> {
self.eclair_post("getinfo", &[]).await
}

async fn create_invoice(&self, amount_msat: u64, description: &str) -> Result<String, String> {
let amount_str = amount_msat.to_string();
let result = self
.eclair_post(
"createinvoice",
&[("amountMsat", &amount_str), ("description", description)],
)
.await?;
result["serialized"]
.as_str()
.map(|s| s.to_string())
.ok_or_else(|| "Missing 'serialized' field in createinvoice response".to_string())
}

async fn pay_invoice(&self, invoice: &str) -> Result<serde_json::Value, String> {
self.eclair_post("payinvoice", &[("invoice", invoice), ("blocking", "true")]).await
}

async fn get_received_info(&self, invoice: &str) -> Result<serde_json::Value, String> {
self.eclair_post("getreceivedinfo", &[("invoice", invoice)]).await
}

async fn list_channels(&self) -> Result<serde_json::Value, String> {
self.eclair_post("channels", &[]).await
}

async fn splice_in(
&self, channel_id: &str, amount_sat: u64,
) -> Result<serde_json::Value, String> {
let amount_str = amount_sat.to_string();
self.eclair_post("splicein", &[("channelId", channel_id), ("amountIn", &amount_str)]).await
}

async fn splice_out(
&self, channel_id: &str, amount_sat: u64, address: &str,
) -> Result<serde_json::Value, String> {
let amount_str = amount_sat.to_string();
self.eclair_post(
"spliceout",
&[("channelId", channel_id), ("amountOut", &amount_str), ("address", address)],
)
.await
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/eclair-integration.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
name: CI Checks - Eclair Integration Tests

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check-eclair:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Start bitcoind, electrs, and Eclair
run: docker compose -f docker-compose-eclair.yml up -d

- name: Wait for Eclair to be ready
run: |
for i in $(seq 1 30); do
if curl -s -u :eclairpw -X POST http://127.0.0.1:8080/getinfo > /dev/null 2>&1; then
echo "Eclair is ready"
break
fi
echo "Waiting for Eclair... ($i)"
sleep 5
done

- name: Run Eclair integration tests
run: RUSTFLAGS="--cfg eclair_test" cargo test --test integration_tests_eclair -- --exact --show-output
1 change: 1 addition & 0 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,6 +121,7 @@ check-cfg = [
"cfg(ldk_bench)",
"cfg(tokio_unstable)",
"cfg(cln_test)",
"cfg(eclair_test)",
"cfg(lnd_test)",
"cfg(cycle_tests)",
]
Expand Down
84 changes: 84 additions & 0 deletions docker-compose-eclair.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
services:
bitcoin:
image: blockstream/bitcoind:27.2
platform: linux/amd64
command:
[
"bitcoind",
"-printtoconsole",
"-regtest=1",
"-rpcallowip=0.0.0.0/0",
"-rpcbind=0.0.0.0",
"-rpcuser=user",
"-rpcpassword=pass",
"-fallbackfee=0.00001",
"-zmqpubrawblock=tcp://0.0.0.0:28332",
"-zmqpubrawtx=tcp://0.0.0.0:28333"
]
ports:
- "18443:18443" # Regtest RPC port
- "18444:18444" # Regtest P2P port
- "28332:28332" # ZMQ block port
- "28333:28333" # ZMQ tx port
networks:
- bitcoin-electrs
healthcheck:
test: ["CMD", "bitcoin-cli", "-regtest", "-rpcuser=user", "-rpcpassword=pass", "getblockchaininfo"]
interval: 5s
timeout: 10s
retries: 5

electrs:
image: mempool/electrs:v3.2.0
platform: linux/amd64
depends_on:
bitcoin:
condition: service_healthy
command:
[
"-vvvv",
"--timestamp",
"--jsonrpc-import",
"--cookie=user:pass",
"--network=regtest",
"--daemon-rpc-addr=bitcoin:18443",
"--http-addr=0.0.0.0:3002",
"--electrum-rpc-addr=0.0.0.0:50001"
]
ports:
- "3002:3002"
- "50001:50001"
networks:
- bitcoin-electrs

eclair:
image: acinq/eclair:latest
depends_on:
bitcoin:
condition: service_healthy
environment:
- |
JAVA_OPTS=
-Xmx512m
-Declair.chain=regtest
-Declair.server.port=9736
-Declair.api.enabled=true
-Declair.api.binding-ip=0.0.0.0
-Declair.api.port=8080
-Declair.api.password=eclairpw
-Declair.bitcoind.host=bitcoin
-Declair.bitcoind.rpc-port=18443
-Declair.bitcoind.rpc-user=user
-Declair.bitcoind.rpc-password=pass
-Declair.bitcoind.zmqblock=tcp://bitcoin:28332
-Declair.bitcoind.zmqtx=tcp://bitcoin:28333
-Declair.printToConsole
ports:
- "8080:8080" # API
- "9736:9736" # P2P
networks:
- bitcoin-electrs

networks:
bitcoin-electrs:
driver: bridge
2 changes: 1 addition & 1 deletion tests/common/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

#![cfg(any(test, cln_test, lnd_test, vss_test))]
#![cfg(any(test, cln_test, eclair_test, lnd_test, vss_test))]
#![allow(dead_code)]

pub(crate) mod logging;
Expand Down
259 changes: 259 additions & 0 deletions tests/integration_tests_eclair.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
// This file is Copyright its original authors, visible in version control history.
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

#![cfg(eclair_test)]

mod common;

use std::str::FromStr;

use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use electrsd::corepc_client::client_sync::Auth;
use electrsd::corepc_node::Client as BitcoindClient;
use electrum_client::Client as ElectrumClient;
use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::bitcoin::Amount;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::{Builder, Event};
use lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription, Description};

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_eclair() {
// Setup bitcoind / electrs clients
let bitcoind_client = BitcoindClient::new_with_auth(
"http://127.0.0.1:18443",
Auth::UserPass("user".to_string(), "pass".to_string()),
)
.unwrap();
let electrs_client = ElectrumClient::new("tcp://127.0.0.1:50001").unwrap();

// Give electrs a kick.
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 1).await;

// Setup LDK Node
let config = common::random_config(true);
let mut builder = Builder::from_config(config.node_config);
builder.set_chain_source_esplora("http://127.0.0.1:3002".to_string(), None);

let node = builder.build(config.node_entropy).unwrap();
node.start().unwrap();

// Premine some funds and distribute
let address = node.onchain_payment().new_address().unwrap();
let premine_amount = Amount::from_sat(5_000_000);
common::premine_and_distribute_funds(
&bitcoind_client,
&electrs_client,
vec![address],
premine_amount,
)
.await;

// Setup Eclair
let eclair = TestEclairClient::new("http://127.0.0.1:8080", "eclairpw");

// Wait for Eclair to be synced
let eclair_info = {
loop {
match eclair.get_info().await {
Ok(info) => {
let block_height =
info["blockHeight"].as_u64().expect("blockHeight should be a number");
if block_height > 0 {
break info;
}
},
Err(e) => {
println!("Waiting for Eclair to be ready: {}", e);
},
}
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
}
};

let eclair_node_id =
PublicKey::from_str(eclair_info["nodeId"].as_str().unwrap()).expect("valid nodeId");
let eclair_address: SocketAddress = "127.0.0.1:9736".parse().unwrap();

node.sync_wallets().unwrap();

// Open the channel
let funding_amount_sat = 1_000_000;

node.open_channel(eclair_node_id, eclair_address, funding_amount_sat, Some(500_000_000), None)
.unwrap();

let funding_txo = common::expect_channel_pending_event!(node, eclair_node_id);
common::wait_for_tx(&electrs_client, funding_txo.txid).await;
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
let user_channel_id = common::expect_channel_ready_event!(node, eclair_node_id);

// Send a payment to Eclair (LDK -> Eclair)
let eclair_invoice_str = eclair
.create_invoice(100_000_000, "test-ldk-to-eclair")
.await
.expect("Failed to create Eclair invoice");
let parsed_invoice = Bolt11Invoice::from_str(&eclair_invoice_str).unwrap();

node.bolt11_payment().send(&parsed_invoice, None).unwrap();
common::expect_event!(node, PaymentSuccessful);

// Verify Eclair received the payment
let received_info = eclair
.get_received_info(&eclair_invoice_str)
.await
.expect("Failed to get received info from Eclair");
let status = received_info["status"]["type"].as_str().unwrap_or("unknown");
assert_eq!(status, "received", "Eclair payment should be in received state");

// Send a payment to LDK (Eclair -> LDK)
let amount_msat = 9_000_000;
let invoice_description =
Bolt11InvoiceDescription::Direct(Description::new("eclairTest".to_string()).unwrap());
let ldk_invoice =
node.bolt11_payment().receive(amount_msat, &invoice_description, 3600).unwrap();
eclair.pay_invoice(&ldk_invoice.to_string()).await.expect("Eclair failed to pay invoice");
common::expect_event!(node, PaymentReceived);

// Splice in (soft-fail: splice interop between LDK and Eclair may not yet be compatible)
let eclair_channels = eclair.list_channels().await.expect("Failed to list Eclair channels");
if let Some(channel) = eclair_channels.as_array().and_then(|arr| arr.first()) {
let channel_id = channel["channelId"].as_str().unwrap_or("");
if !channel_id.is_empty() {
match eclair.splice_in(channel_id, 500_000).await {
Ok(_) => {
println!("Splice in succeeded, mining blocks to confirm...");
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
},
Err(e) => {
println!(
"Splice in not yet supported in LDK<->Eclair interop, skipping: {}",
e
);
},
}

// Splice out (soft-fail)
let addr = node.onchain_payment().new_address().unwrap();
match eclair.splice_out(channel_id, 200_000, &addr.to_string()).await {
Ok(_) => {
println!("Splice out succeeded, mining blocks to confirm...");
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
},
Err(e) => {
println!(
"Splice out not yet supported in LDK<->Eclair interop, skipping: {}",
e
);
},
}
}
}

// Close the channel
node.close_channel(&user_channel_id, eclair_node_id).unwrap();
common::expect_event!(node, ChannelClosed);
node.stop().unwrap();
}

struct TestEclairClient {
base_url: String,
auth_header: String,
}

impl TestEclairClient {
fn new(base_url: &str, password: &str) -> Self {
let credentials = format!(":{}", password);
let auth_header = format!("Basic {}", BASE64_STANDARD.encode(credentials.as_bytes()));
TestEclairClient { base_url: base_url.to_string(), auth_header }
}

async fn eclair_post(
&self, endpoint: &str, params: &[(&str, &str)],
) -> Result<serde_json::Value, String> {
let url = format!("{}/{}", self.base_url, endpoint);
let body = params.iter().map(|(k, v)| format!("{}={}", k, v)).collect::<Vec<_>>().join("&");

let request = bitreq::post(&url)
.with_header("Authorization", &self.auth_header)
.with_header("Content-Type", "application/x-www-form-urlencoded")
.with_body(body.as_bytes())
.with_timeout(30);

let response = request
.send_async()
.await
.map_err(|e| format!("HTTP request to {} failed: {}", endpoint, e))?;

if response.status_code != 200 {
let body_str = response.as_str().unwrap_or("(non-utf8 body)");
return Err(format!(
"Eclair {} returned HTTP {}: {}",
endpoint, response.status_code, body_str
));
}

let body_str = response
.as_str()
.map_err(|e| format!("Failed to read response body from {}: {}", endpoint, e))?;

serde_json::from_str(body_str)
.map_err(|e| format!("Failed to parse JSON from {}: {}", endpoint, e))
}

async fn get_info(&self) -> Result<serde_json::Value, String> {
self.eclair_post("getinfo", &[]).await
}

async fn create_invoice(&self, amount_msat: u64, description: &str) -> Result<String, String> {
let amount_str = amount_msat.to_string();
let result = self
.eclair_post(
"createinvoice",
&[("amountMsat", &amount_str), ("description", description)],
)
.await?;
result["serialized"]
.as_str()
.map(|s| s.to_string())
.ok_or_else(|| "Missing 'serialized' field in createinvoice response".to_string())
}

async fn pay_invoice(&self, invoice: &str) -> Result<serde_json::Value, String> {
self.eclair_post("payinvoice", &[("invoice", invoice), ("blocking", "true")]).await
}

async fn get_received_info(&self, invoice: &str) -> Result<serde_json::Value, String> {
self.eclair_post("getreceivedinfo", &[("invoice", invoice)]).await
}

async fn list_channels(&self) -> Result<serde_json::Value, String> {
self.eclair_post("channels", &[]).await
}

async fn splice_in(
&self, channel_id: &str, amount_sat: u64,
) -> Result<serde_json::Value, String> {
let amount_str = amount_sat.to_string();
self.eclair_post("splicein", &[("channelId", channel_id), ("amountIn", &amount_str)]).await
}

async fn splice_out(
&self, channel_id: &str, amount_sat: u64, address: &str,
) -> Result<serde_json::Value, String> {
let amount_str = amount_sat.to_string();
self.eclair_post(
"spliceout",
&[("channelId", channel_id), ("amountOut", &amount_str), ("address", address)],
)
.await
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/eclair-integration.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
name: CI Checks - Eclair Integration Tests

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check-eclair:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Start bitcoind, electrs, and Eclair
run: docker compose -f docker-compose-eclair.yml up -d

- name: Wait for Eclair to be ready
run: |
for i in $(seq 1 30); do
if curl -s -u :eclairpw -X POST http://127.0.0.1:8080/getinfo > /dev/null 2>&1; then
echo "Eclair is ready"
break
fi
echo "Waiting for Eclair... ($i)"
sleep 5
done

- name: Run Eclair integration tests
run: RUSTFLAGS="--cfg eclair_test" cargo test --test integration_tests_eclair -- --exact --show-output
1 change: 1 addition & 0 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,6 +121,7 @@ check-cfg = [
"cfg(ldk_bench)",
"cfg(tokio_unstable)",
"cfg(cln_test)",
"cfg(eclair_test)",
"cfg(lnd_test)",
"cfg(cycle_tests)",
]
Expand Down
84 changes: 84 additions & 0 deletions docker-compose-eclair.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
services:
bitcoin:
image: blockstream/bitcoind:27.2
platform: linux/amd64
command:
[
"bitcoind",
"-printtoconsole",
"-regtest=1",
"-rpcallowip=0.0.0.0/0",
"-rpcbind=0.0.0.0",
"-rpcuser=user",
"-rpcpassword=pass",
"-fallbackfee=0.00001",
"-zmqpubrawblock=tcp://0.0.0.0:28332",
"-zmqpubrawtx=tcp://0.0.0.0:28333"
]
ports:
- "18443:18443" # Regtest RPC port
- "18444:18444" # Regtest P2P port
- "28332:28332" # ZMQ block port
- "28333:28333" # ZMQ tx port
networks:
- bitcoin-electrs
healthcheck:
test: ["CMD", "bitcoin-cli", "-regtest", "-rpcuser=user", "-rpcpassword=pass", "getblockchaininfo"]
interval: 5s
timeout: 10s
retries: 5

electrs:
image: mempool/electrs:v3.2.0
platform: linux/amd64
depends_on:
bitcoin:
condition: service_healthy
command:
[
"-vvvv",
"--timestamp",
"--jsonrpc-import",
"--cookie=user:pass",
"--network=regtest",
"--daemon-rpc-addr=bitcoin:18443",
"--http-addr=0.0.0.0:3002",
"--electrum-rpc-addr=0.0.0.0:50001"
]
ports:
- "3002:3002"
- "50001:50001"
networks:
- bitcoin-electrs

eclair:
image: acinq/eclair:latest
depends_on:
bitcoin:
condition: service_healthy
environment:
- |
JAVA_OPTS=
-Xmx512m
-Declair.chain=regtest
-Declair.server.port=9736
-Declair.api.enabled=true
-Declair.api.binding-ip=0.0.0.0
-Declair.api.port=8080
-Declair.api.password=eclairpw
-Declair.bitcoind.host=bitcoin
-Declair.bitcoind.rpc-port=18443
-Declair.bitcoind.rpc-user=user
-Declair.bitcoind.rpc-password=pass
-Declair.bitcoind.zmqblock=tcp://bitcoin:28332
-Declair.bitcoind.zmqtx=tcp://bitcoin:28333
-Declair.printToConsole
ports:
- "8080:8080" # API
- "9736:9736" # P2P
networks:
- bitcoin-electrs

networks:
bitcoin-electrs:
driver: bridge
2 changes: 1 addition & 1 deletion tests/common/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

#![cfg(any(test, cln_test, lnd_test, vss_test))]
#![cfg(any(test, cln_test, eclair_test, lnd_test, vss_test))]
#![allow(dead_code)]

pub(crate) mod logging;
Expand Down
259 changes: 259 additions & 0 deletions tests/integration_tests_eclair.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
// This file is Copyright its original authors, visible in version control history.
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

#![cfg(eclair_test)]

mod common;

use std::str::FromStr;

use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use electrsd::corepc_client::client_sync::Auth;
use electrsd::corepc_node::Client as BitcoindClient;
use electrum_client::Client as ElectrumClient;
use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::bitcoin::Amount;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::{Builder, Event};
use lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription, Description};

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_eclair() {
// Setup bitcoind / electrs clients
let bitcoind_client = BitcoindClient::new_with_auth(
"http://127.0.0.1:18443",
Auth::UserPass("user".to_string(), "pass".to_string()),
)
.unwrap();
let electrs_client = ElectrumClient::new("tcp://127.0.0.1:50001").unwrap();

// Give electrs a kick.
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 1).await;

// Setup LDK Node
let config = common::random_config(true);
let mut builder = Builder::from_config(config.node_config);
builder.set_chain_source_esplora("http://127.0.0.1:3002".to_string(), None);

let node = builder.build(config.node_entropy).unwrap();
node.start().unwrap();

// Premine some funds and distribute
let address = node.onchain_payment().new_address().unwrap();
let premine_amount = Amount::from_sat(5_000_000);
common::premine_and_distribute_funds(
&bitcoind_client,
&electrs_client,
vec![address],
premine_amount,
)
.await;

// Setup Eclair
let eclair = TestEclairClient::new("http://127.0.0.1:8080", "eclairpw");

// Wait for Eclair to be synced
let eclair_info = {
loop {
match eclair.get_info().await {
Ok(info) => {
let block_height =
info["blockHeight"].as_u64().expect("blockHeight should be a number");
if block_height > 0 {
break info;
}
},
Err(e) => {
println!("Waiting for Eclair to be ready: {}", e);
},
}
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
}
};

let eclair_node_id =
PublicKey::from_str(eclair_info["nodeId"].as_str().unwrap()).expect("valid nodeId");
let eclair_address: SocketAddress = "127.0.0.1:9736".parse().unwrap();

node.sync_wallets().unwrap();

// Open the channel
let funding_amount_sat = 1_000_000;

node.open_channel(eclair_node_id, eclair_address, funding_amount_sat, Some(500_000_000), None)
.unwrap();

let funding_txo = common::expect_channel_pending_event!(node, eclair_node_id);
common::wait_for_tx(&electrs_client, funding_txo.txid).await;
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
let user_channel_id = common::expect_channel_ready_event!(node, eclair_node_id);

// Send a payment to Eclair (LDK -> Eclair)
let eclair_invoice_str = eclair
.create_invoice(100_000_000, "test-ldk-to-eclair")
.await
.expect("Failed to create Eclair invoice");
let parsed_invoice = Bolt11Invoice::from_str(&eclair_invoice_str).unwrap();

node.bolt11_payment().send(&parsed_invoice, None).unwrap();
common::expect_event!(node, PaymentSuccessful);

// Verify Eclair received the payment
let received_info = eclair
.get_received_info(&eclair_invoice_str)
.await
.expect("Failed to get received info from Eclair");
let status = received_info["status"]["type"].as_str().unwrap_or("unknown");
assert_eq!(status, "received", "Eclair payment should be in received state");

// Send a payment to LDK (Eclair -> LDK)
let amount_msat = 9_000_000;
let invoice_description =
Bolt11InvoiceDescription::Direct(Description::new("eclairTest".to_string()).unwrap());
let ldk_invoice =
node.bolt11_payment().receive(amount_msat, &invoice_description, 3600).unwrap();
eclair.pay_invoice(&ldk_invoice.to_string()).await.expect("Eclair failed to pay invoice");
common::expect_event!(node, PaymentReceived);

// Splice in (soft-fail: splice interop between LDK and Eclair may not yet be compatible)
let eclair_channels = eclair.list_channels().await.expect("Failed to list Eclair channels");
if let Some(channel) = eclair_channels.as_array().and_then(|arr| arr.first()) {
let channel_id = channel["channelId"].as_str().unwrap_or("");
if !channel_id.is_empty() {
match eclair.splice_in(channel_id, 500_000).await {
Ok(_) => {
println!("Splice in succeeded, mining blocks to confirm...");
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
},
Err(e) => {
println!(
"Splice in not yet supported in LDK<->Eclair interop, skipping: {}",
e
);
},
}

// Splice out (soft-fail)
let addr = node.onchain_payment().new_address().unwrap();
match eclair.splice_out(channel_id, 200_000, &addr.to_string()).await {
Ok(_) => {
println!("Splice out succeeded, mining blocks to confirm...");
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
},
Err(e) => {
println!(
"Splice out not yet supported in LDK<->Eclair interop, skipping: {}",
e
);
},
}
}
}

// Close the channel
node.close_channel(&user_channel_id, eclair_node_id).unwrap();
common::expect_event!(node, ChannelClosed);
node.stop().unwrap();
}

struct TestEclairClient {
base_url: String,
auth_header: String,
}

impl TestEclairClient {
fn new(base_url: &str, password: &str) -> Self {
let credentials = format!(":{}", password);
let auth_header = format!("Basic {}", BASE64_STANDARD.encode(credentials.as_bytes()));
TestEclairClient { base_url: base_url.to_string(), auth_header }
}

async fn eclair_post(
&self, endpoint: &str, params: &[(&str, &str)],
) -> Result<serde_json::Value, String> {
let url = format!("{}/{}", self.base_url, endpoint);
let body = params.iter().map(|(k, v)| format!("{}={}", k, v)).collect::<Vec<_>>().join("&");

let request = bitreq::post(&url)
.with_header("Authorization", &self.auth_header)
.with_header("Content-Type", "application/x-www-form-urlencoded")
.with_body(body.as_bytes())
.with_timeout(30);

let response = request
.send_async()
.await
.map_err(|e| format!("HTTP request to {} failed: {}", endpoint, e))?;

if response.status_code != 200 {
let body_str = response.as_str().unwrap_or("(non-utf8 body)");
return Err(format!(
"Eclair {} returned HTTP {}: {}",
endpoint, response.status_code, body_str
));
}

let body_str = response
.as_str()
.map_err(|e| format!("Failed to read response body from {}: {}", endpoint, e))?;

serde_json::from_str(body_str)
.map_err(|e| format!("Failed to parse JSON from {}: {}", endpoint, e))
}

async fn get_info(&self) -> Result<serde_json::Value, String> {
self.eclair_post("getinfo", &[]).await
}

async fn create_invoice(&self, amount_msat: u64, description: &str) -> Result<String, String> {
let amount_str = amount_msat.to_string();
let result = self
.eclair_post(
"createinvoice",
&[("amountMsat", &amount_str), ("description", description)],
)
.await?;
result["serialized"]
.as_str()
.map(|s| s.to_string())
.ok_or_else(|| "Missing 'serialized' field in createinvoice response".to_string())
}

async fn pay_invoice(&self, invoice: &str) -> Result<serde_json::Value, String> {
self.eclair_post("payinvoice", &[("invoice", invoice), ("blocking", "true")]).await
}

async fn get_received_info(&self, invoice: &str) -> Result<serde_json::Value, String> {
self.eclair_post("getreceivedinfo", &[("invoice", invoice)]).await
}

async fn list_channels(&self) -> Result<serde_json::Value, String> {
self.eclair_post("channels", &[]).await
}

async fn splice_in(
&self, channel_id: &str, amount_sat: u64,
) -> Result<serde_json::Value, String> {
let amount_str = amount_sat.to_string();
self.eclair_post("splicein", &[("channelId", channel_id), ("amountIn", &amount_str)]).await
}

async fn splice_out(
&self, channel_id: &str, amount_sat: u64, address: &str,
) -> Result<serde_json::Value, String> {
let amount_str = amount_sat.to_string();
self.eclair_post(
"spliceout",
&[("channelId", channel_id), ("amountOut", &amount_str), ("address", address)],
)
.await
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/eclair-integration.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
name: CI Checks - Eclair Integration Tests

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check-eclair:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Start bitcoind, electrs, and Eclair
run: docker compose -f docker-compose-eclair.yml up -d

- name: Wait for Eclair to be ready
run: |
for i in $(seq 1 30); do
if curl -s -u :eclairpw -X POST http://127.0.0.1:8080/getinfo > /dev/null 2>&1; then
echo "Eclair is ready"
break
fi
echo "Waiting for Eclair... ($i)"
sleep 5
done

- name: Run Eclair integration tests
run: RUSTFLAGS="--cfg eclair_test" cargo test --test integration_tests_eclair -- --exact --show-output
1 change: 1 addition & 0 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,6 +121,7 @@ check-cfg = [
"cfg(ldk_bench)",
"cfg(tokio_unstable)",
"cfg(cln_test)",
"cfg(eclair_test)",
"cfg(lnd_test)",
"cfg(cycle_tests)",
]
Expand Down
84 changes: 84 additions & 0 deletions docker-compose-eclair.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
services:
bitcoin:
image: blockstream/bitcoind:27.2
platform: linux/amd64
command:
[
"bitcoind",
"-printtoconsole",
"-regtest=1",
"-rpcallowip=0.0.0.0/0",
"-rpcbind=0.0.0.0",
"-rpcuser=user",
"-rpcpassword=pass",
"-fallbackfee=0.00001",
"-zmqpubrawblock=tcp://0.0.0.0:28332",
"-zmqpubrawtx=tcp://0.0.0.0:28333"
]
ports:
- "18443:18443" # Regtest RPC port
- "18444:18444" # Regtest P2P port
- "28332:28332" # ZMQ block port
- "28333:28333" # ZMQ tx port
networks:
- bitcoin-electrs
healthcheck:
test: ["CMD", "bitcoin-cli", "-regtest", "-rpcuser=user", "-rpcpassword=pass", "getblockchaininfo"]
interval: 5s
timeout: 10s
retries: 5

electrs:
image: mempool/electrs:v3.2.0
platform: linux/amd64
depends_on:
bitcoin:
condition: service_healthy
command:
[
"-vvvv",
"--timestamp",
"--jsonrpc-import",
"--cookie=user:pass",
"--network=regtest",
"--daemon-rpc-addr=bitcoin:18443",
"--http-addr=0.0.0.0:3002",
"--electrum-rpc-addr=0.0.0.0:50001"
]
ports:
- "3002:3002"
- "50001:50001"
networks:
- bitcoin-electrs

eclair:
image: acinq/eclair:latest
depends_on:
bitcoin:
condition: service_healthy
environment:
- |
JAVA_OPTS=
-Xmx512m
-Declair.chain=regtest
-Declair.server.port=9736
-Declair.api.enabled=true
-Declair.api.binding-ip=0.0.0.0
-Declair.api.port=8080
-Declair.api.password=eclairpw
-Declair.bitcoind.host=bitcoin
-Declair.bitcoind.rpc-port=18443
-Declair.bitcoind.rpc-user=user
-Declair.bitcoind.rpc-password=pass
-Declair.bitcoind.zmqblock=tcp://bitcoin:28332
-Declair.bitcoind.zmqtx=tcp://bitcoin:28333
-Declair.printToConsole
ports:
- "8080:8080" # API
- "9736:9736" # P2P
networks:
- bitcoin-electrs

networks:
bitcoin-electrs:
driver: bridge
2 changes: 1 addition & 1 deletion tests/common/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

#![cfg(any(test, cln_test, lnd_test, vss_test))]
#![cfg(any(test, cln_test, eclair_test, lnd_test, vss_test))]
#![allow(dead_code)]

pub(crate) mod logging;
Expand Down
259 changes: 259 additions & 0 deletions tests/integration_tests_eclair.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
// This file is Copyright its original authors, visible in version control history.
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

#![cfg(eclair_test)]

mod common;

use std::str::FromStr;

use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use electrsd::corepc_client::client_sync::Auth;
use electrsd::corepc_node::Client as BitcoindClient;
use electrum_client::Client as ElectrumClient;
use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::bitcoin::Amount;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::{Builder, Event};
use lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription, Description};

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_eclair() {
// Setup bitcoind / electrs clients
let bitcoind_client = BitcoindClient::new_with_auth(
"http://127.0.0.1:18443",
Auth::UserPass("user".to_string(), "pass".to_string()),
)
.unwrap();
let electrs_client = ElectrumClient::new("tcp://127.0.0.1:50001").unwrap();

// Give electrs a kick.
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 1).await;

// Setup LDK Node
let config = common::random_config(true);
let mut builder = Builder::from_config(config.node_config);
builder.set_chain_source_esplora("http://127.0.0.1:3002".to_string(), None);

let node = builder.build(config.node_entropy).unwrap();
node.start().unwrap();

// Premine some funds and distribute
let address = node.onchain_payment().new_address().unwrap();
let premine_amount = Amount::from_sat(5_000_000);
common::premine_and_distribute_funds(
&bitcoind_client,
&electrs_client,
vec![address],
premine_amount,
)
.await;

// Setup Eclair
let eclair = TestEclairClient::new("http://127.0.0.1:8080", "eclairpw");

// Wait for Eclair to be synced
let eclair_info = {
loop {
match eclair.get_info().await {
Ok(info) => {
let block_height =
info["blockHeight"].as_u64().expect("blockHeight should be a number");
if block_height > 0 {
break info;
}
},
Err(e) => {
println!("Waiting for Eclair to be ready: {}", e);
},
}
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
}
};

let eclair_node_id =
PublicKey::from_str(eclair_info["nodeId"].as_str().unwrap()).expect("valid nodeId");
let eclair_address: SocketAddress = "127.0.0.1:9736".parse().unwrap();

node.sync_wallets().unwrap();

// Open the channel
let funding_amount_sat = 1_000_000;

node.open_channel(eclair_node_id, eclair_address, funding_amount_sat, Some(500_000_000), None)
.unwrap();

let funding_txo = common::expect_channel_pending_event!(node, eclair_node_id);
common::wait_for_tx(&electrs_client, funding_txo.txid).await;
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
let user_channel_id = common::expect_channel_ready_event!(node, eclair_node_id);

// Send a payment to Eclair (LDK -> Eclair)
let eclair_invoice_str = eclair
.create_invoice(100_000_000, "test-ldk-to-eclair")
.await
.expect("Failed to create Eclair invoice");
let parsed_invoice = Bolt11Invoice::from_str(&eclair_invoice_str).unwrap();

node.bolt11_payment().send(&parsed_invoice, None).unwrap();
common::expect_event!(node, PaymentSuccessful);

// Verify Eclair received the payment
let received_info = eclair
.get_received_info(&eclair_invoice_str)
.await
.expect("Failed to get received info from Eclair");
let status = received_info["status"]["type"].as_str().unwrap_or("unknown");
assert_eq!(status, "received", "Eclair payment should be in received state");

// Send a payment to LDK (Eclair -> LDK)
let amount_msat = 9_000_000;
let invoice_description =
Bolt11InvoiceDescription::Direct(Description::new("eclairTest".to_string()).unwrap());
let ldk_invoice =
node.bolt11_payment().receive(amount_msat, &invoice_description, 3600).unwrap();
eclair.pay_invoice(&ldk_invoice.to_string()).await.expect("Eclair failed to pay invoice");
common::expect_event!(node, PaymentReceived);

// Splice in (soft-fail: splice interop between LDK and Eclair may not yet be compatible)
let eclair_channels = eclair.list_channels().await.expect("Failed to list Eclair channels");
if let Some(channel) = eclair_channels.as_array().and_then(|arr| arr.first()) {
let channel_id = channel["channelId"].as_str().unwrap_or("");
if !channel_id.is_empty() {
match eclair.splice_in(channel_id, 500_000).await {
Ok(_) => {
println!("Splice in succeeded, mining blocks to confirm...");
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
},
Err(e) => {
println!(
"Splice in not yet supported in LDK<->Eclair interop, skipping: {}",
e
);
},
}

// Splice out (soft-fail)
let addr = node.onchain_payment().new_address().unwrap();
match eclair.splice_out(channel_id, 200_000, &addr.to_string()).await {
Ok(_) => {
println!("Splice out succeeded, mining blocks to confirm...");
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
},
Err(e) => {
println!(
"Splice out not yet supported in LDK<->Eclair interop, skipping: {}",
e
);
},
}
}
}

// Close the channel
node.close_channel(&user_channel_id, eclair_node_id).unwrap();
common::expect_event!(node, ChannelClosed);
node.stop().unwrap();
}

struct TestEclairClient {
base_url: String,
auth_header: String,
}

impl TestEclairClient {
fn new(base_url: &str, password: &str) -> Self {
let credentials = format!(":{}", password);
let auth_header = format!("Basic {}", BASE64_STANDARD.encode(credentials.as_bytes()));
TestEclairClient { base_url: base_url.to_string(), auth_header }
}

async fn eclair_post(
&self, endpoint: &str, params: &[(&str, &str)],
) -> Result<serde_json::Value, String> {
let url = format!("{}/{}", self.base_url, endpoint);
let body = params.iter().map(|(k, v)| format!("{}={}", k, v)).collect::<Vec<_>>().join("&");

let request = bitreq::post(&url)
.with_header("Authorization", &self.auth_header)
.with_header("Content-Type", "application/x-www-form-urlencoded")
.with_body(body.as_bytes())
.with_timeout(30);

let response = request
.send_async()
.await
.map_err(|e| format!("HTTP request to {} failed: {}", endpoint, e))?;

if response.status_code != 200 {
let body_str = response.as_str().unwrap_or("(non-utf8 body)");
return Err(format!(
"Eclair {} returned HTTP {}: {}",
endpoint, response.status_code, body_str
));
}

let body_str = response
.as_str()
.map_err(|e| format!("Failed to read response body from {}: {}", endpoint, e))?;

serde_json::from_str(body_str)
.map_err(|e| format!("Failed to parse JSON from {}: {}", endpoint, e))
}

async fn get_info(&self) -> Result<serde_json::Value, String> {
self.eclair_post("getinfo", &[]).await
}

async fn create_invoice(&self, amount_msat: u64, description: &str) -> Result<String, String> {
let amount_str = amount_msat.to_string();
let result = self
.eclair_post(
"createinvoice",
&[("amountMsat", &amount_str), ("description", description)],
)
.await?;
result["serialized"]
.as_str()
.map(|s| s.to_string())
.ok_or_else(|| "Missing 'serialized' field in createinvoice response".to_string())
}

async fn pay_invoice(&self, invoice: &str) -> Result<serde_json::Value, String> {
self.eclair_post("payinvoice", &[("invoice", invoice), ("blocking", "true")]).await
}

async fn get_received_info(&self, invoice: &str) -> Result<serde_json::Value, String> {
self.eclair_post("getreceivedinfo", &[("invoice", invoice)]).await
}

async fn list_channels(&self) -> Result<serde_json::Value, String> {
self.eclair_post("channels", &[]).await
}

async fn splice_in(
&self, channel_id: &str, amount_sat: u64,
) -> Result<serde_json::Value, String> {
let amount_str = amount_sat.to_string();
self.eclair_post("splicein", &[("channelId", channel_id), ("amountIn", &amount_str)]).await
}

async fn splice_out(
&self, channel_id: &str, amount_sat: u64, address: &str,
) -> Result<serde_json::Value, String> {
let amount_str = amount_sat.to_string();
self.eclair_post(
"spliceout",
&[("channelId", channel_id), ("amountOut", &amount_str), ("address", address)],
)
.await
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/eclair-integration.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
name: CI Checks - Eclair Integration Tests

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check-eclair:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Start bitcoind, electrs, and Eclair
run: docker compose -f docker-compose-eclair.yml up -d

- name: Wait for Eclair to be ready
run: |
for i in $(seq 1 30); do
if curl -s -u :eclairpw -X POST http://127.0.0.1:8080/getinfo > /dev/null 2>&1; then
echo "Eclair is ready"
break
fi
echo "Waiting for Eclair... ($i)"
sleep 5
done

- name: Run Eclair integration tests
run: RUSTFLAGS="--cfg eclair_test" cargo test --test integration_tests_eclair -- --exact --show-output
1 change: 1 addition & 0 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,6 +121,7 @@ check-cfg = [
"cfg(ldk_bench)",
"cfg(tokio_unstable)",
"cfg(cln_test)",
"cfg(eclair_test)",
"cfg(lnd_test)",
"cfg(cycle_tests)",
]
Expand Down
84 changes: 84 additions & 0 deletions docker-compose-eclair.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
services:
bitcoin:
image: blockstream/bitcoind:27.2
platform: linux/amd64
command:
[
"bitcoind",
"-printtoconsole",
"-regtest=1",
"-rpcallowip=0.0.0.0/0",
"-rpcbind=0.0.0.0",
"-rpcuser=user",
"-rpcpassword=pass",
"-fallbackfee=0.00001",
"-zmqpubrawblock=tcp://0.0.0.0:28332",
"-zmqpubrawtx=tcp://0.0.0.0:28333"
]
ports:
- "18443:18443" # Regtest RPC port
- "18444:18444" # Regtest P2P port
- "28332:28332" # ZMQ block port
- "28333:28333" # ZMQ tx port
networks:
- bitcoin-electrs
healthcheck:
test: ["CMD", "bitcoin-cli", "-regtest", "-rpcuser=user", "-rpcpassword=pass", "getblockchaininfo"]
interval: 5s
timeout: 10s
retries: 5

electrs:
image: mempool/electrs:v3.2.0
platform: linux/amd64
depends_on:
bitcoin:
condition: service_healthy
command:
[
"-vvvv",
"--timestamp",
"--jsonrpc-import",
"--cookie=user:pass",
"--network=regtest",
"--daemon-rpc-addr=bitcoin:18443",
"--http-addr=0.0.0.0:3002",
"--electrum-rpc-addr=0.0.0.0:50001"
]
ports:
- "3002:3002"
- "50001:50001"
networks:
- bitcoin-electrs

eclair:
image: acinq/eclair:latest
depends_on:
bitcoin:
condition: service_healthy
environment:
- |
JAVA_OPTS=
-Xmx512m
-Declair.chain=regtest
-Declair.server.port=9736
-Declair.api.enabled=true
-Declair.api.binding-ip=0.0.0.0
-Declair.api.port=8080
-Declair.api.password=eclairpw
-Declair.bitcoind.host=bitcoin
-Declair.bitcoind.rpc-port=18443
-Declair.bitcoind.rpc-user=user
-Declair.bitcoind.rpc-password=pass
-Declair.bitcoind.zmqblock=tcp://bitcoin:28332
-Declair.bitcoind.zmqtx=tcp://bitcoin:28333
-Declair.printToConsole
ports:
- "8080:8080" # API
- "9736:9736" # P2P
networks:
- bitcoin-electrs

networks:
bitcoin-electrs:
driver: bridge
2 changes: 1 addition & 1 deletion tests/common/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

#![cfg(any(test, cln_test, lnd_test, vss_test))]
#![cfg(any(test, cln_test, eclair_test, lnd_test, vss_test))]
#![allow(dead_code)]

pub(crate) mod logging;
Expand Down
259 changes: 259 additions & 0 deletions tests/integration_tests_eclair.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
// This file is Copyright its original authors, visible in version control history.
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

#![cfg(eclair_test)]

mod common;

use std::str::FromStr;

use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use electrsd::corepc_client::client_sync::Auth;
use electrsd::corepc_node::Client as BitcoindClient;
use electrum_client::Client as ElectrumClient;
use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::bitcoin::Amount;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::{Builder, Event};
use lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription, Description};

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_eclair() {
// Setup bitcoind / electrs clients
let bitcoind_client = BitcoindClient::new_with_auth(
"http://127.0.0.1:18443",
Auth::UserPass("user".to_string(), "pass".to_string()),
)
.unwrap();
let electrs_client = ElectrumClient::new("tcp://127.0.0.1:50001").unwrap();

// Give electrs a kick.
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 1).await;

// Setup LDK Node
let config = common::random_config(true);
let mut builder = Builder::from_config(config.node_config);
builder.set_chain_source_esplora("http://127.0.0.1:3002".to_string(), None);

let node = builder.build(config.node_entropy).unwrap();
node.start().unwrap();

// Premine some funds and distribute
let address = node.onchain_payment().new_address().unwrap();
let premine_amount = Amount::from_sat(5_000_000);
common::premine_and_distribute_funds(
&bitcoind_client,
&electrs_client,
vec![address],
premine_amount,
)
.await;

// Setup Eclair
let eclair = TestEclairClient::new("http://127.0.0.1:8080", "eclairpw");

// Wait for Eclair to be synced
let eclair_info = {
loop {
match eclair.get_info().await {
Ok(info) => {
let block_height =
info["blockHeight"].as_u64().expect("blockHeight should be a number");
if block_height > 0 {
break info;
}
},
Err(e) => {
println!("Waiting for Eclair to be ready: {}", e);
},
}
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
}
};

let eclair_node_id =
PublicKey::from_str(eclair_info["nodeId"].as_str().unwrap()).expect("valid nodeId");
let eclair_address: SocketAddress = "127.0.0.1:9736".parse().unwrap();

node.sync_wallets().unwrap();

// Open the channel
let funding_amount_sat = 1_000_000;

node.open_channel(eclair_node_id, eclair_address, funding_amount_sat, Some(500_000_000), None)
.unwrap();

let funding_txo = common::expect_channel_pending_event!(node, eclair_node_id);
common::wait_for_tx(&electrs_client, funding_txo.txid).await;
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
let user_channel_id = common::expect_channel_ready_event!(node, eclair_node_id);

// Send a payment to Eclair (LDK -> Eclair)
let eclair_invoice_str = eclair
.create_invoice(100_000_000, "test-ldk-to-eclair")
.await
.expect("Failed to create Eclair invoice");
let parsed_invoice = Bolt11Invoice::from_str(&eclair_invoice_str).unwrap();

node.bolt11_payment().send(&parsed_invoice, None).unwrap();
common::expect_event!(node, PaymentSuccessful);

// Verify Eclair received the payment
let received_info = eclair
.get_received_info(&eclair_invoice_str)
.await
.expect("Failed to get received info from Eclair");
let status = received_info["status"]["type"].as_str().unwrap_or("unknown");
assert_eq!(status, "received", "Eclair payment should be in received state");

// Send a payment to LDK (Eclair -> LDK)
let amount_msat = 9_000_000;
let invoice_description =
Bolt11InvoiceDescription::Direct(Description::new("eclairTest".to_string()).unwrap());
let ldk_invoice =
node.bolt11_payment().receive(amount_msat, &invoice_description, 3600).unwrap();
eclair.pay_invoice(&ldk_invoice.to_string()).await.expect("Eclair failed to pay invoice");
common::expect_event!(node, PaymentReceived);

// Splice in (soft-fail: splice interop between LDK and Eclair may not yet be compatible)
let eclair_channels = eclair.list_channels().await.expect("Failed to list Eclair channels");
if let Some(channel) = eclair_channels.as_array().and_then(|arr| arr.first()) {
let channel_id = channel["channelId"].as_str().unwrap_or("");
if !channel_id.is_empty() {
match eclair.splice_in(channel_id, 500_000).await {
Ok(_) => {
println!("Splice in succeeded, mining blocks to confirm...");
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
},
Err(e) => {
println!(
"Splice in not yet supported in LDK<->Eclair interop, skipping: {}",
e
);
},
}

// Splice out (soft-fail)
let addr = node.onchain_payment().new_address().unwrap();
match eclair.splice_out(channel_id, 200_000, &addr.to_string()).await {
Ok(_) => {
println!("Splice out succeeded, mining blocks to confirm...");
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
},
Err(e) => {
println!(
"Splice out not yet supported in LDK<->Eclair interop, skipping: {}",
e
);
},
}
}
}

// Close the channel
node.close_channel(&user_channel_id, eclair_node_id).unwrap();
common::expect_event!(node, ChannelClosed);
node.stop().unwrap();
}

struct TestEclairClient {
base_url: String,
auth_header: String,
}

impl TestEclairClient {
fn new(base_url: &str, password: &str) -> Self {
let credentials = format!(":{}", password);
let auth_header = format!("Basic {}", BASE64_STANDARD.encode(credentials.as_bytes()));
TestEclairClient { base_url: base_url.to_string(), auth_header }
}

async fn eclair_post(
&self, endpoint: &str, params: &[(&str, &str)],
) -> Result<serde_json::Value, String> {
let url = format!("{}/{}", self.base_url, endpoint);
let body = params.iter().map(|(k, v)| format!("{}={}", k, v)).collect::<Vec<_>>().join("&");

let request = bitreq::post(&url)
.with_header("Authorization", &self.auth_header)
.with_header("Content-Type", "application/x-www-form-urlencoded")
.with_body(body.as_bytes())
.with_timeout(30);

let response = request
.send_async()
.await
.map_err(|e| format!("HTTP request to {} failed: {}", endpoint, e))?;

if response.status_code != 200 {
let body_str = response.as_str().unwrap_or("(non-utf8 body)");
return Err(format!(
"Eclair {} returned HTTP {}: {}",
endpoint, response.status_code, body_str
));
}

let body_str = response
.as_str()
.map_err(|e| format!("Failed to read response body from {}: {}", endpoint, e))?;

serde_json::from_str(body_str)
.map_err(|e| format!("Failed to parse JSON from {}: {}", endpoint, e))
}

async fn get_info(&self) -> Result<serde_json::Value, String> {
self.eclair_post("getinfo", &[]).await
}

async fn create_invoice(&self, amount_msat: u64, description: &str) -> Result<String, String> {
let amount_str = amount_msat.to_string();
let result = self
.eclair_post(
"createinvoice",
&[("amountMsat", &amount_str), ("description", description)],
)
.await?;
result["serialized"]
.as_str()
.map(|s| s.to_string())
.ok_or_else(|| "Missing 'serialized' field in createinvoice response".to_string())
}

async fn pay_invoice(&self, invoice: &str) -> Result<serde_json::Value, String> {
self.eclair_post("payinvoice", &[("invoice", invoice), ("blocking", "true")]).await
}

async fn get_received_info(&self, invoice: &str) -> Result<serde_json::Value, String> {
self.eclair_post("getreceivedinfo", &[("invoice", invoice)]).await
}

async fn list_channels(&self) -> Result<serde_json::Value, String> {
self.eclair_post("channels", &[]).await
}

async fn splice_in(
&self, channel_id: &str, amount_sat: u64,
) -> Result<serde_json::Value, String> {
let amount_str = amount_sat.to_string();
self.eclair_post("splicein", &[("channelId", channel_id), ("amountIn", &amount_str)]).await
}

async fn splice_out(
&self, channel_id: &str, amount_sat: u64, address: &str,
) -> Result<serde_json::Value, String> {
let amount_str = amount_sat.to_string();
self.eclair_post(
"spliceout",
&[("channelId", channel_id), ("amountOut", &amount_str), ("address", address)],
)
.await
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/eclair-integration.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
name: CI Checks - Eclair Integration Tests

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check-eclair:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Start bitcoind, electrs, and Eclair
run: docker compose -f docker-compose-eclair.yml up -d

- name: Wait for Eclair to be ready
run: |
for i in $(seq 1 30); do
if curl -s -u :eclairpw -X POST http://127.0.0.1:8080/getinfo > /dev/null 2>&1; then
echo "Eclair is ready"
break
fi
echo "Waiting for Eclair... ($i)"
sleep 5
done

- name: Run Eclair integration tests
run: RUSTFLAGS="--cfg eclair_test" cargo test --test integration_tests_eclair -- --exact --show-output
1 change: 1 addition & 0 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,6 +121,7 @@ check-cfg = [
"cfg(ldk_bench)",
"cfg(tokio_unstable)",
"cfg(cln_test)",
"cfg(eclair_test)",
"cfg(lnd_test)",
"cfg(cycle_tests)",
]
Expand Down
84 changes: 84 additions & 0 deletions docker-compose-eclair.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
services:
bitcoin:
image: blockstream/bitcoind:27.2
platform: linux/amd64
command:
[
"bitcoind",
"-printtoconsole",
"-regtest=1",
"-rpcallowip=0.0.0.0/0",
"-rpcbind=0.0.0.0",
"-rpcuser=user",
"-rpcpassword=pass",
"-fallbackfee=0.00001",
"-zmqpubrawblock=tcp://0.0.0.0:28332",
"-zmqpubrawtx=tcp://0.0.0.0:28333"
]
ports:
- "18443:18443" # Regtest RPC port
- "18444:18444" # Regtest P2P port
- "28332:28332" # ZMQ block port
- "28333:28333" # ZMQ tx port
networks:
- bitcoin-electrs
healthcheck:
test: ["CMD", "bitcoin-cli", "-regtest", "-rpcuser=user", "-rpcpassword=pass", "getblockchaininfo"]
interval: 5s
timeout: 10s
retries: 5

electrs:
image: mempool/electrs:v3.2.0
platform: linux/amd64
depends_on:
bitcoin:
condition: service_healthy
command:
[
"-vvvv",
"--timestamp",
"--jsonrpc-import",
"--cookie=user:pass",
"--network=regtest",
"--daemon-rpc-addr=bitcoin:18443",
"--http-addr=0.0.0.0:3002",
"--electrum-rpc-addr=0.0.0.0:50001"
]
ports:
- "3002:3002"
- "50001:50001"
networks:
- bitcoin-electrs

eclair:
image: acinq/eclair:latest
depends_on:
bitcoin:
condition: service_healthy
environment:
- |
JAVA_OPTS=
-Xmx512m
-Declair.chain=regtest
-Declair.server.port=9736
-Declair.api.enabled=true
-Declair.api.binding-ip=0.0.0.0
-Declair.api.port=8080
-Declair.api.password=eclairpw
-Declair.bitcoind.host=bitcoin
-Declair.bitcoind.rpc-port=18443
-Declair.bitcoind.rpc-user=user
-Declair.bitcoind.rpc-password=pass
-Declair.bitcoind.zmqblock=tcp://bitcoin:28332
-Declair.bitcoind.zmqtx=tcp://bitcoin:28333
-Declair.printToConsole
ports:
- "8080:8080" # API
- "9736:9736" # P2P
networks:
- bitcoin-electrs

networks:
bitcoin-electrs:
driver: bridge
2 changes: 1 addition & 1 deletion tests/common/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

#![cfg(any(test, cln_test, lnd_test, vss_test))]
#![cfg(any(test, cln_test, eclair_test, lnd_test, vss_test))]
#![allow(dead_code)]

pub(crate) mod logging;
Expand Down
259 changes: 259 additions & 0 deletions tests/integration_tests_eclair.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
// This file is Copyright its original authors, visible in version control history.
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

#![cfg(eclair_test)]

mod common;

use std::str::FromStr;

use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use electrsd::corepc_client::client_sync::Auth;
use electrsd::corepc_node::Client as BitcoindClient;
use electrum_client::Client as ElectrumClient;
use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::bitcoin::Amount;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::{Builder, Event};
use lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription, Description};

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_eclair() {
// Setup bitcoind / electrs clients
let bitcoind_client = BitcoindClient::new_with_auth(
"http://127.0.0.1:18443",
Auth::UserPass("user".to_string(), "pass".to_string()),
)
.unwrap();
let electrs_client = ElectrumClient::new("tcp://127.0.0.1:50001").unwrap();

// Give electrs a kick.
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 1).await;

// Setup LDK Node
let config = common::random_config(true);
let mut builder = Builder::from_config(config.node_config);
builder.set_chain_source_esplora("http://127.0.0.1:3002".to_string(), None);

let node = builder.build(config.node_entropy).unwrap();
node.start().unwrap();

// Premine some funds and distribute
let address = node.onchain_payment().new_address().unwrap();
let premine_amount = Amount::from_sat(5_000_000);
common::premine_and_distribute_funds(
&bitcoind_client,
&electrs_client,
vec![address],
premine_amount,
)
.await;

// Setup Eclair
let eclair = TestEclairClient::new("http://127.0.0.1:8080", "eclairpw");

// Wait for Eclair to be synced
let eclair_info = {
loop {
match eclair.get_info().await {
Ok(info) => {
let block_height =
info["blockHeight"].as_u64().expect("blockHeight should be a number");
if block_height > 0 {
break info;
}
},
Err(e) => {
println!("Waiting for Eclair to be ready: {}", e);
},
}
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
}
};

let eclair_node_id =
PublicKey::from_str(eclair_info["nodeId"].as_str().unwrap()).expect("valid nodeId");
let eclair_address: SocketAddress = "127.0.0.1:9736".parse().unwrap();

node.sync_wallets().unwrap();

// Open the channel
let funding_amount_sat = 1_000_000;

node.open_channel(eclair_node_id, eclair_address, funding_amount_sat, Some(500_000_000), None)
.unwrap();

let funding_txo = common::expect_channel_pending_event!(node, eclair_node_id);
common::wait_for_tx(&electrs_client, funding_txo.txid).await;
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
let user_channel_id = common::expect_channel_ready_event!(node, eclair_node_id);

// Send a payment to Eclair (LDK -> Eclair)
let eclair_invoice_str = eclair
.create_invoice(100_000_000, "test-ldk-to-eclair")
.await
.expect("Failed to create Eclair invoice");
let parsed_invoice = Bolt11Invoice::from_str(&eclair_invoice_str).unwrap();

node.bolt11_payment().send(&parsed_invoice, None).unwrap();
common::expect_event!(node, PaymentSuccessful);

// Verify Eclair received the payment
let received_info = eclair
.get_received_info(&eclair_invoice_str)
.await
.expect("Failed to get received info from Eclair");
let status = received_info["status"]["type"].as_str().unwrap_or("unknown");
assert_eq!(status, "received", "Eclair payment should be in received state");

// Send a payment to LDK (Eclair -> LDK)
let amount_msat = 9_000_000;
let invoice_description =
Bolt11InvoiceDescription::Direct(Description::new("eclairTest".to_string()).unwrap());
let ldk_invoice =
node.bolt11_payment().receive(amount_msat, &invoice_description, 3600).unwrap();
eclair.pay_invoice(&ldk_invoice.to_string()).await.expect("Eclair failed to pay invoice");
common::expect_event!(node, PaymentReceived);

// Splice in (soft-fail: splice interop between LDK and Eclair may not yet be compatible)
let eclair_channels = eclair.list_channels().await.expect("Failed to list Eclair channels");
if let Some(channel) = eclair_channels.as_array().and_then(|arr| arr.first()) {
let channel_id = channel["channelId"].as_str().unwrap_or("");
if !channel_id.is_empty() {
match eclair.splice_in(channel_id, 500_000).await {
Ok(_) => {
println!("Splice in succeeded, mining blocks to confirm...");
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
},
Err(e) => {
println!(
"Splice in not yet supported in LDK<->Eclair interop, skipping: {}",
e
);
},
}

// Splice out (soft-fail)
let addr = node.onchain_payment().new_address().unwrap();
match eclair.splice_out(channel_id, 200_000, &addr.to_string()).await {
Ok(_) => {
println!("Splice out succeeded, mining blocks to confirm...");
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
},
Err(e) => {
println!(
"Splice out not yet supported in LDK<->Eclair interop, skipping: {}",
e
);
},
}
}
}

// Close the channel
node.close_channel(&user_channel_id, eclair_node_id).unwrap();
common::expect_event!(node, ChannelClosed);
node.stop().unwrap();
}

struct TestEclairClient {
base_url: String,
auth_header: String,
}

impl TestEclairClient {
fn new(base_url: &str, password: &str) -> Self {
let credentials = format!(":{}", password);
let auth_header = format!("Basic {}", BASE64_STANDARD.encode(credentials.as_bytes()));
TestEclairClient { base_url: base_url.to_string(), auth_header }
}

async fn eclair_post(
&self, endpoint: &str, params: &[(&str, &str)],
) -> Result<serde_json::Value, String> {
let url = format!("{}/{}", self.base_url, endpoint);
let body = params.iter().map(|(k, v)| format!("{}={}", k, v)).collect::<Vec<_>>().join("&");

let request = bitreq::post(&url)
.with_header("Authorization", &self.auth_header)
.with_header("Content-Type", "application/x-www-form-urlencoded")
.with_body(body.as_bytes())
.with_timeout(30);

let response = request
.send_async()
.await
.map_err(|e| format!("HTTP request to {} failed: {}", endpoint, e))?;

if response.status_code != 200 {
let body_str = response.as_str().unwrap_or("(non-utf8 body)");
return Err(format!(
"Eclair {} returned HTTP {}: {}",
endpoint, response.status_code, body_str
));
}

let body_str = response
.as_str()
.map_err(|e| format!("Failed to read response body from {}: {}", endpoint, e))?;

serde_json::from_str(body_str)
.map_err(|e| format!("Failed to parse JSON from {}: {}", endpoint, e))
}

async fn get_info(&self) -> Result<serde_json::Value, String> {
self.eclair_post("getinfo", &[]).await
}

async fn create_invoice(&self, amount_msat: u64, description: &str) -> Result<String, String> {
let amount_str = amount_msat.to_string();
let result = self
.eclair_post(
"createinvoice",
&[("amountMsat", &amount_str), ("description", description)],
)
.await?;
result["serialized"]
.as_str()
.map(|s| s.to_string())
.ok_or_else(|| "Missing 'serialized' field in createinvoice response".to_string())
}

async fn pay_invoice(&self, invoice: &str) -> Result<serde_json::Value, String> {
self.eclair_post("payinvoice", &[("invoice", invoice), ("blocking", "true")]).await
}

async fn get_received_info(&self, invoice: &str) -> Result<serde_json::Value, String> {
self.eclair_post("getreceivedinfo", &[("invoice", invoice)]).await
}

async fn list_channels(&self) -> Result<serde_json::Value, String> {
self.eclair_post("channels", &[]).await
}

async fn splice_in(
&self, channel_id: &str, amount_sat: u64,
) -> Result<serde_json::Value, String> {
let amount_str = amount_sat.to_string();
self.eclair_post("splicein", &[("channelId", channel_id), ("amountIn", &amount_str)]).await
}

async fn splice_out(
&self, channel_id: &str, amount_sat: u64, address: &str,
) -> Result<serde_json::Value, String> {
let amount_str = amount_sat.to_string();
self.eclair_post(
"spliceout",
&[("channelId", channel_id), ("amountOut", &amount_str), ("address", address)],
)
.await
}
}
Loading
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/eclair-integration.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
name: CI Checks - Eclair Integration Tests

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check-eclair:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Start bitcoind, electrs, and Eclair
run: docker compose -f docker-compose-eclair.yml up -d

- name: Wait for Eclair to be ready
run: |
for i in $(seq 1 30); do
if curl -s -u :eclairpw -X POST http://127.0.0.1:8080/getinfo > /dev/null 2>&1; then
echo "Eclair is ready"
break
fi
echo "Waiting for Eclair... ($i)"
sleep 5
done

- name: Run Eclair integration tests
run: RUSTFLAGS="--cfg eclair_test" cargo test --test integration_tests_eclair -- --exact --show-output
1 change: 1 addition & 0 deletions Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,6 +121,7 @@ check-cfg = [
"cfg(ldk_bench)",
"cfg(tokio_unstable)",
"cfg(cln_test)",
"cfg(eclair_test)",
"cfg(lnd_test)",
"cfg(cycle_tests)",
]
Expand Down
84 changes: 84 additions & 0 deletions docker-compose-eclair.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
services:
bitcoin:
image: blockstream/bitcoind:27.2
platform: linux/amd64
command:
[
"bitcoind",
"-printtoconsole",
"-regtest=1",
"-rpcallowip=0.0.0.0/0",
"-rpcbind=0.0.0.0",
"-rpcuser=user",
"-rpcpassword=pass",
"-fallbackfee=0.00001",
"-zmqpubrawblock=tcp://0.0.0.0:28332",
"-zmqpubrawtx=tcp://0.0.0.0:28333"
]
ports:
- "18443:18443" # Regtest RPC port
- "18444:18444" # Regtest P2P port
- "28332:28332" # ZMQ block port
- "28333:28333" # ZMQ tx port
networks:
- bitcoin-electrs
healthcheck:
test: ["CMD", "bitcoin-cli", "-regtest", "-rpcuser=user", "-rpcpassword=pass", "getblockchaininfo"]
interval: 5s
timeout: 10s
retries: 5

electrs:
image: mempool/electrs:v3.2.0
platform: linux/amd64
depends_on:
bitcoin:
condition: service_healthy
command:
[
"-vvvv",
"--timestamp",
"--jsonrpc-import",
"--cookie=user:pass",
"--network=regtest",
"--daemon-rpc-addr=bitcoin:18443",
"--http-addr=0.0.0.0:3002",
"--electrum-rpc-addr=0.0.0.0:50001"
]
ports:
- "3002:3002"
- "50001:50001"
networks:
- bitcoin-electrs

eclair:
image: acinq/eclair:latest
depends_on:
bitcoin:
condition: service_healthy
environment:
- |
JAVA_OPTS=
-Xmx512m
-Declair.chain=regtest
-Declair.server.port=9736
-Declair.api.enabled=true
-Declair.api.binding-ip=0.0.0.0
-Declair.api.port=8080
-Declair.api.password=eclairpw
-Declair.bitcoind.host=bitcoin
-Declair.bitcoind.rpc-port=18443
-Declair.bitcoind.rpc-user=user
-Declair.bitcoind.rpc-password=pass
-Declair.bitcoind.zmqblock=tcp://bitcoin:28332
-Declair.bitcoind.zmqtx=tcp://bitcoin:28333
-Declair.printToConsole
ports:
- "8080:8080" # API
- "9736:9736" # P2P
networks:
- bitcoin-electrs

networks:
bitcoin-electrs:
driver: bridge
2 changes: 1 addition & 1 deletion tests/common/mod.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

#![cfg(any(test, cln_test, lnd_test, vss_test))]
#![cfg(any(test, cln_test, eclair_test, lnd_test, vss_test))]
#![allow(dead_code)]

pub(crate) mod logging;
Expand Down
259 changes: 259 additions & 0 deletions tests/integration_tests_eclair.rs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
// This file is Copyright its original authors, visible in version control history.
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
// accordance with one or both of these licenses.

#![cfg(eclair_test)]

mod common;

use std::str::FromStr;

use base64::prelude::BASE64_STANDARD;
use base64::Engine;
use electrsd::corepc_client::client_sync::Auth;
use electrsd::corepc_node::Client as BitcoindClient;
use electrum_client::Client as ElectrumClient;
use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::bitcoin::Amount;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::{Builder, Event};
use lightning_invoice::{Bolt11Invoice, Bolt11InvoiceDescription, Description};

#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_eclair() {
// Setup bitcoind / electrs clients
let bitcoind_client = BitcoindClient::new_with_auth(
"http://127.0.0.1:18443",
Auth::UserPass("user".to_string(), "pass".to_string()),
)
.unwrap();
let electrs_client = ElectrumClient::new("tcp://127.0.0.1:50001").unwrap();

// Give electrs a kick.
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 1).await;

// Setup LDK Node
let config = common::random_config(true);
let mut builder = Builder::from_config(config.node_config);
builder.set_chain_source_esplora("http://127.0.0.1:3002".to_string(), None);

let node = builder.build(config.node_entropy).unwrap();
node.start().unwrap();

// Premine some funds and distribute
let address = node.onchain_payment().new_address().unwrap();
let premine_amount = Amount::from_sat(5_000_000);
common::premine_and_distribute_funds(
&bitcoind_client,
&electrs_client,
vec![address],
premine_amount,
)
.await;

// Setup Eclair
let eclair = TestEclairClient::new("http://127.0.0.1:8080", "eclairpw");

// Wait for Eclair to be synced
let eclair_info = {
loop {
match eclair.get_info().await {
Ok(info) => {
let block_height =
info["blockHeight"].as_u64().expect("blockHeight should be a number");
if block_height > 0 {
break info;
}
},
Err(e) => {
println!("Waiting for Eclair to be ready: {}", e);
},
}
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
}
};

let eclair_node_id =
PublicKey::from_str(eclair_info["nodeId"].as_str().unwrap()).expect("valid nodeId");
let eclair_address: SocketAddress = "127.0.0.1:9736".parse().unwrap();

node.sync_wallets().unwrap();

// Open the channel
let funding_amount_sat = 1_000_000;

node.open_channel(eclair_node_id, eclair_address, funding_amount_sat, Some(500_000_000), None)
.unwrap();

let funding_txo = common::expect_channel_pending_event!(node, eclair_node_id);
common::wait_for_tx(&electrs_client, funding_txo.txid).await;
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
let user_channel_id = common::expect_channel_ready_event!(node, eclair_node_id);

// Send a payment to Eclair (LDK -> Eclair)
let eclair_invoice_str = eclair
.create_invoice(100_000_000, "test-ldk-to-eclair")
.await
.expect("Failed to create Eclair invoice");
let parsed_invoice = Bolt11Invoice::from_str(&eclair_invoice_str).unwrap();

node.bolt11_payment().send(&parsed_invoice, None).unwrap();
common::expect_event!(node, PaymentSuccessful);

// Verify Eclair received the payment
let received_info = eclair
.get_received_info(&eclair_invoice_str)
.await
.expect("Failed to get received info from Eclair");
let status = received_info["status"]["type"].as_str().unwrap_or("unknown");
assert_eq!(status, "received", "Eclair payment should be in received state");

// Send a payment to LDK (Eclair -> LDK)
let amount_msat = 9_000_000;
let invoice_description =
Bolt11InvoiceDescription::Direct(Description::new("eclairTest".to_string()).unwrap());
let ldk_invoice =
node.bolt11_payment().receive(amount_msat, &invoice_description, 3600).unwrap();
eclair.pay_invoice(&ldk_invoice.to_string()).await.expect("Eclair failed to pay invoice");
common::expect_event!(node, PaymentReceived);

// Splice in (soft-fail: splice interop between LDK and Eclair may not yet be compatible)
let eclair_channels = eclair.list_channels().await.expect("Failed to list Eclair channels");
if let Some(channel) = eclair_channels.as_array().and_then(|arr| arr.first()) {
let channel_id = channel["channelId"].as_str().unwrap_or("");
if !channel_id.is_empty() {
match eclair.splice_in(channel_id, 500_000).await {
Ok(_) => {
println!("Splice in succeeded, mining blocks to confirm...");
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
},
Err(e) => {
println!(
"Splice in not yet supported in LDK<->Eclair interop, skipping: {}",
e
);
},
}

// Splice out (soft-fail)
let addr = node.onchain_payment().new_address().unwrap();
match eclair.splice_out(channel_id, 200_000, &addr.to_string()).await {
Ok(_) => {
println!("Splice out succeeded, mining blocks to confirm...");
common::generate_blocks_and_wait(&bitcoind_client, &electrs_client, 6).await;
node.sync_wallets().unwrap();
},
Err(e) => {
println!(
"Splice out not yet supported in LDK<->Eclair interop, skipping: {}",
e
);
},
}
}
}

// Close the channel
node.close_channel(&user_channel_id, eclair_node_id).unwrap();
common::expect_event!(node, ChannelClosed);
node.stop().unwrap();
}

struct TestEclairClient {
base_url: String,
auth_header: String,
}

impl TestEclairClient {
fn new(base_url: &str, password: &str) -> Self {
let credentials = format!(":{}", password);
let auth_header = format!("Basic {}", BASE64_STANDARD.encode(credentials.as_bytes()));
TestEclairClient { base_url: base_url.to_string(), auth_header }
}

async fn eclair_post(
&self, endpoint: &str, params: &[(&str, &str)],
) -> Result<serde_json::Value, String> {
let url = format!("{}/{}", self.base_url, endpoint);
let body = params.iter().map(|(k, v)| format!("{}={}", k, v)).collect::<Vec<_>>().join("&");

let request = bitreq::post(&url)
.with_header("Authorization", &self.auth_header)
.with_header("Content-Type", "application/x-www-form-urlencoded")
.with_body(body.as_bytes())
.with_timeout(30);

let response = request
.send_async()
.await
.map_err(|e| format!("HTTP request to {} failed: {}", endpoint, e))?;

if response.status_code != 200 {
let body_str = response.as_str().unwrap_or("(non-utf8 body)");
return Err(format!(
"Eclair {} returned HTTP {}: {}",
endpoint, response.status_code, body_str
));
}

let body_str = response
.as_str()
.map_err(|e| format!("Failed to read response body from {}: {}", endpoint, e))?;

serde_json::from_str(body_str)
.map_err(|e| format!("Failed to parse JSON from {}: {}", endpoint, e))
}

async fn get_info(&self) -> Result<serde_json::Value, String> {
self.eclair_post("getinfo", &[]).await
}

async fn create_invoice(&self, amount_msat: u64, description: &str) -> Result<String, String> {
let amount_str = amount_msat.to_string();
let result = self
.eclair_post(
"createinvoice",
&[("amountMsat", &amount_str), ("description", description)],
)
.await?;
result["serialized"]
.as_str()
.map(|s| s.to_string())
.ok_or_else(|| "Missing 'serialized' field in createinvoice response".to_string())
}

async fn pay_invoice(&self, invoice: &str) -> Result<serde_json::Value, String> {
self.eclair_post("payinvoice", &[("invoice", invoice), ("blocking", "true")]).await
}

async fn get_received_info(&self, invoice: &str) -> Result<serde_json::Value, String> {
self.eclair_post("getreceivedinfo", &[("invoice", invoice)]).await
}

async fn list_channels(&self) -> Result<serde_json::Value, String> {
self.eclair_post("channels", &[]).await
}

async fn splice_in(
&self, channel_id: &str, amount_sat: u64,
) -> Result<serde_json::Value, String> {
let amount_str = amount_sat.to_string();
self.eclair_post("splicein", &[("channelId", channel_id), ("amountIn", &amount_str)]).await
}

async fn splice_out(
&self, channel_id: &str, amount_sat: u64, address: &str,
) -> Result<serde_json::Value, String> {
let amount_str = amount_sat.to_string();
self.eclair_post(
"spliceout",
&[("channelId", channel_id), ("amountOut", &amount_str), ("address", address)],
)
.await
}
}
Loading