Skip to content

Commit e4adcfc

Browse files
committed
test: channel full cycle with chain source in REST sync
Additionally adds the BlockSource implementation for BitcoindSyncClient
1 parent 822fe46 commit e4adcfc

File tree

4 files changed

+46
-11
lines changed

4 files changed

+46
-11
lines changed

docker-compose.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ services:
1313
"-rpcbind=0.0.0.0",
1414
"-rpcuser=user",
1515
"-rpcpassword=pass",
16-
"-fallbackfee=0.00001"
16+
"-fallbackfee=0.00001",
17+
"-rest"
1718
]
1819
ports:
19-
- "18443:18443" # Regtest RPC port
20+
- "18443:18443" # Regtest REST and RPC port
2021
- "18444:18444" # Regtest P2P port
2122
networks:
2223
- bitcoin-electrs

src/chain/mod.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ impl BlockSource for BitcoindSyncClient {
203203
BitcoindSyncClient::Rpc(rpc_client) => {
204204
Box::pin(async move { rpc_client.get_header(header_hash, height_hint).await })
205205
},
206-
BitcoindSyncClient::Rest(_rest_client) => todo!(),
206+
BitcoindSyncClient::Rest(rest_client) => {
207+
Box::pin(async move { rest_client.get_header(header_hash, height_hint).await })
208+
},
207209
}
208210
}
209211

@@ -214,7 +216,9 @@ impl BlockSource for BitcoindSyncClient {
214216
BitcoindSyncClient::Rpc(rpc_client) => {
215217
Box::pin(async move { rpc_client.get_block(header_hash).await })
216218
},
217-
BitcoindSyncClient::Rest(_rest_client) => todo!(),
219+
BitcoindSyncClient::Rest(rest_client) => {
220+
Box::pin(async move { rest_client.get_block(header_hash).await })
221+
},
218222
}
219223
}
220224

@@ -225,7 +229,9 @@ impl BlockSource for BitcoindSyncClient {
225229
BitcoindSyncClient::Rpc(rpc_client) => {
226230
Box::pin(async move { rpc_client.get_best_block().await })
227231
},
228-
BitcoindSyncClient::Rest(_rest_client) => todo!(),
232+
BitcoindSyncClient::Rest(rest_client) => {
233+
Box::pin(async move { rest_client.get_best_block().await })
234+
},
229235
}
230236
}
231237
}
@@ -349,7 +355,9 @@ impl ChainSource {
349355
endpoint(host, port),
350356
))),
351357
BitcoindSyncClientConfig::Rest { rest_host, rest_port } => {
352-
Arc::new(BitcoindSyncClient::Rest(RestClient::new(endpoint(rest_host, rest_port))))
358+
Arc::new(BitcoindSyncClient::Rest(RestClient::new(
359+
endpoint(rest_host, rest_port).with_path("/rest".to_string()),
360+
)))
353361
},
354362
};
355363

tests/common/mod.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub(crate) mod logging;
1212

1313
use logging::TestLogWriter;
1414

15-
use ldk_node::config::{Config, ElectrumSyncConfig, EsploraSyncConfig};
15+
use ldk_node::config::{BitcoindSyncClientConfig, Config, ElectrumSyncConfig, EsploraSyncConfig};
1616
use ldk_node::io::sqlite_store::SqliteStore;
1717
use ldk_node::payment::{PaymentDirection, PaymentKind, PaymentStatus};
1818
use ldk_node::{
@@ -174,6 +174,7 @@ pub(crate) fn setup_bitcoind_and_electrsd() -> (BitcoinD, ElectrsD) {
174174
);
175175
let mut bitcoind_conf = corepc_node::Conf::default();
176176
bitcoind_conf.network = "regtest";
177+
bitcoind_conf.args.push("-rest");
177178
let bitcoind = BitcoinD::with_conf(bitcoind_exe, &bitcoind_conf).unwrap();
178179

179180
let electrs_exe = env::var("ELECTRS_EXE")
@@ -256,7 +257,8 @@ type TestNode = Node;
256257
pub(crate) enum TestChainSource<'a> {
257258
Esplora(&'a ElectrsD),
258259
Electrum(&'a ElectrsD),
259-
BitcoindRpc(&'a BitcoinD),
260+
BitcoindRpcSync(&'a BitcoinD),
261+
BitcoindRestSync(&'a BitcoinD),
260262
}
261263

262264
#[derive(Clone, Default)]
@@ -317,14 +319,30 @@ pub(crate) fn setup_node(
317319
let sync_config = ElectrumSyncConfig { background_sync_config: None };
318320
builder.set_chain_source_electrum(electrum_url.clone(), Some(sync_config));
319321
},
320-
TestChainSource::BitcoindRpc(bitcoind) => {
322+
TestChainSource::BitcoindRpcSync(bitcoind) => {
321323
let rpc_host = bitcoind.params.rpc_socket.ip().to_string();
322324
let rpc_port = bitcoind.params.rpc_socket.port();
323325
let values = bitcoind.params.get_cookie_values().unwrap().unwrap();
324326
let rpc_user = values.user;
325327
let rpc_password = values.password;
326328
builder.set_chain_source_bitcoind(rpc_host, rpc_port, rpc_user, rpc_password, None);
327329
},
330+
TestChainSource::BitcoindRestSync(bitcoind) => {
331+
let rpc_host = bitcoind.params.rpc_socket.ip().to_string();
332+
let rpc_port = bitcoind.params.rpc_socket.port();
333+
let values = bitcoind.params.get_cookie_values().unwrap().unwrap();
334+
let rpc_user = values.user;
335+
let rpc_password = values.password;
336+
let sync_client_config =
337+
BitcoindSyncClientConfig::Rest { rest_host: rpc_host.clone(), rest_port: rpc_port };
338+
builder.set_chain_source_bitcoind(
339+
rpc_host,
340+
rpc_port,
341+
rpc_user,
342+
rpc_password,
343+
Some(sync_client_config),
344+
);
345+
},
328346
}
329347

330348
match &config.log_writer {

tests/integration_tests_rust.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,17 @@ fn channel_full_cycle_electrum() {
5454
}
5555

5656
#[test]
57-
fn channel_full_cycle_bitcoind() {
57+
fn channel_full_cycle_bitcoind_rpc_sync() {
5858
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
59-
let chain_source = TestChainSource::BitcoindRpc(&bitcoind);
59+
let chain_source = TestChainSource::BitcoindRpcSync(&bitcoind);
60+
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);
61+
do_channel_full_cycle(node_a, node_b, &bitcoind.client, &electrsd.client, false, true, false);
62+
}
63+
64+
#[test]
65+
fn channel_full_cycle_bitcoind_rest_sync() {
66+
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
67+
let chain_source = TestChainSource::BitcoindRestSync(&bitcoind);
6068
let (node_a, node_b) = setup_two_nodes(&chain_source, false, true, false);
6169
do_channel_full_cycle(node_a, node_b, &bitcoind.client, &electrsd.client, false, true, false);
6270
}

0 commit comments

Comments
 (0)