Skip to content

Commit 5633475

Browse files
committed
Merge commit 'refs/pull/347/head' of github.com:bitcoindevkit/bdk
2 parents 9f04a9d + ea8488b commit 5633475

File tree

17 files changed

+1174
-1203
lines changed

17 files changed

+1174
-1203
lines changed

.github/workflows/cont_integration.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,27 @@ jobs:
7373
- name: Test
7474
run: cargo test --features test-md-docs --no-default-features -- doctest::ReadmeDoctests
7575

76-
test-electrum:
77-
name: Test electrum
76+
test-blockchains:
77+
name: Test ${{ matrix.blockchain.name }}
7878
runs-on: ubuntu-16.04
79-
container: bitcoindevkit/electrs:0.2.0
79+
strategy:
80+
matrix:
81+
blockchain:
82+
- name: electrum
83+
container: bitcoindevkit/electrs
84+
start: /root/electrs --network regtest --jsonrpc-import
85+
- name: esplora
86+
container: bitcoindevkit/esplora
87+
start: /root/electrs --network regtest -vvv --cookie admin:passw --jsonrpc-import --electrum-rpc-addr=0.0.0.0:60401 --http-addr 0.0.0.0:3002
88+
container: ${{ matrix.blockchain.container }}
8089
env:
8190
BDK_RPC_AUTH: USER_PASS
8291
BDK_RPC_USER: admin
8392
BDK_RPC_PASS: passw
8493
BDK_RPC_URL: 127.0.0.1:18443
8594
BDK_RPC_WALLET: bdk-test
8695
BDK_ELECTRUM_URL: tcp://127.0.0.1:60401
96+
BDK_ESPLORA_URL: http://127.0.0.1:3002
8797
steps:
8898
- name: Checkout
8999
uses: actions/checkout@v2
@@ -95,6 +105,8 @@ jobs:
95105
~/.cargo/git
96106
target
97107
key: ${{ runner.os }}-cargo-${{ github.job }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
108+
- name: get pkg-config # running eslpora tests seems to need this
109+
run: apt update && apt install -y --fix-missing pkg-config libssl-dev
98110
- name: Install rustup
99111
run: curl https://sh.rustup.rs -sSf | sh -s -- -y
100112
- name: Set default toolchain
@@ -105,8 +117,10 @@ jobs:
105117
run: $HOME/.cargo/bin/rustup update
106118
- name: Start core
107119
run: ./ci/start-core.sh
120+
- name: start ${{ matrix.blockchain.name }}
121+
run: nohup ${{ matrix.blockchain.start }} & sleep 5
108122
- name: Test
109-
run: $HOME/.cargo/bin/cargo test --features test-electrum --no-default-features
123+
run: $HOME/.cargo/bin/cargo test --features ${{ matrix.blockchain.name }},test-blockchains --no-default-features ${{ matrix.blockchain.name }}::bdk_blockchain_tests
110124

111125
check-wasm:
112126
name: Check WASM

Cargo.toml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ socks = { version = "0.3", optional = true }
3232
lazy_static = { version = "1.4", optional = true }
3333
tiny-bip39 = { version = "^0.8", optional = true }
3434

35+
# Needed by bdk_blockchain_tests macro
36+
bitcoincore-rpc = { version = "0.13", optional = true }
37+
serial_test = { version = "0.4", optional = true }
38+
3539
# Platform-specific dependencies
3640
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
3741
tokio = { version = "1", features = ["rt"] }
@@ -54,18 +58,15 @@ all-keys = ["keys-bip39"]
5458
keys-bip39 = ["tiny-bip39"]
5559

5660
# Debug/Test features
57-
debug-proc-macros = ["bdk-macros/debug", "bdk-testutils-macros/debug"]
58-
test-electrum = ["electrum"]
61+
test-blockchains = ["bitcoincore-rpc", "electrum-client"]
5962
test-md-docs = ["electrum"]
6063

6164
[dev-dependencies]
62-
bdk-testutils = "0.4"
63-
bdk-testutils-macros = "0.6"
64-
serial_test = "0.4"
6565
lazy_static = "1.4"
6666
env_logger = "0.7"
6767
base64 = "^0.11"
6868
clap = "2.33"
69+
serial_test = "0.4"
6970

7071
[[example]]
7172
name = "address_validator"
@@ -79,10 +80,7 @@ path = "examples/compiler.rs"
7980
required-features = ["compiler"]
8081

8182
[workspace]
82-
members = ["macros", "testutils", "testutils-macros"]
83-
84-
# Generate docs with nightly to add the "features required" badge
85-
# https://stackoverflow.com/questions/61417452/how-to-get-a-feature-requirement-tag-in-the-documentation-generated-by-cargo-do
83+
members = ["macros"]
8684
[package.metadata.docs.rs]
8785
features = ["compiler", "electrum", "esplora", "compact_filters", "key-value-db", "all-keys"]
8886
# defines the configuration attribute `docsrs`

ci/start-core.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,3 @@ done
1111
echo "Generating 150 bitcoin blocks."
1212
ADDR=$(/root/bitcoin-cli -regtest -rpcuser=$BDK_RPC_USER -rpcpassword=$BDK_RPC_PASS -rpcwallet=$BDK_RPC_WALLET getnewaddress)
1313
/root/bitcoin-cli -regtest -rpcuser=$BDK_RPC_USER -rpcpassword=$BDK_RPC_PASS generatetoaddress 150 $ADDR
14-
15-
echo "Starting electrs node."
16-
nohup /root/electrs --network regtest --jsonrpc-import &
17-
sleep 5

run_blockchain_tests.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/sh
2+
3+
usage() {
4+
cat <<'EOF'
5+
Script for running the bdk blockchain tests for a specific blockchain by starting up the backend in docker.
6+
7+
Usage: ./run_blockchain_tests.sh [esplora|electrum] [test name].
8+
9+
EOF
10+
}
11+
12+
eprintln(){
13+
echo "$@" >&2
14+
}
15+
16+
cleanup() {
17+
if test "$id"; then
18+
eprintln "cleaning up $blockchain docker container $id";
19+
docker rm -fv "$id" > /dev/null;
20+
fi
21+
trap - EXIT INT
22+
}
23+
24+
# Makes sure we clean up the container at the end or if ^C
25+
trap 'rc=$?; cleanup; exit $rc' EXIT INT
26+
27+
blockchain="$1"
28+
test_name="$2"
29+
30+
case "$blockchain" in
31+
electrum)
32+
eprintln "starting electrs docker container"
33+
id="$(docker run -d -p 127.0.0.1:18443-18444:18443-18444/tcp -p 127.0.0.1:60401:60401/tcp bitcoindevkit/electrs)"
34+
;;
35+
esplora)
36+
eprintln "starting esplora docker container"
37+
id="$(docker run -d -p 127.0.0.1:18443-18444:18443-18444/tcp -p 127.0.0.1:60401:60401/tcp -p 127.0.0.1:3002:3002/tcp bitcoindevkit/esplora)"
38+
export BDK_ESPLORA_URL=http://127.0.0.1:3002
39+
;;
40+
*)
41+
usage;
42+
exit 1;
43+
;;
44+
esac
45+
46+
# taken from https://github.com/bitcoindevkit/bitcoin-regtest-box
47+
export BDK_RPC_AUTH=USER_PASS
48+
export BDK_RPC_USER=admin
49+
export BDK_RPC_PASS=passw
50+
export BDK_RPC_URL=127.0.0.1:18443
51+
export BDK_RPC_WALLET=bdk-test
52+
export BDK_ELECTRUM_URL=tcp://127.0.0.1:60401
53+
54+
cli(){
55+
docker exec -it "$id" /root/bitcoin-cli -regtest -rpcuser=admin -rpcpassword=passw $@
56+
}
57+
58+
eprintln "running getwalletinfo until bitcoind seems to be alive"
59+
while ! cli getwalletinfo >/dev/null; do sleep 1; done
60+
61+
# sleep again for good measure!
62+
sleep 1;
63+
64+
cargo test --features "test-blockchains,$blockchain" --no-default-features "$blockchain::bdk_blockchain_tests::$test_name"

src/blockchain/electrum.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ use crate::FeeRate;
4545
/// See the [`blockchain::electrum`](crate::blockchain::electrum) module for a usage example.
4646
pub struct ElectrumBlockchain(Client);
4747

48-
#[cfg(test)]
49-
#[cfg(feature = "test-electrum")]
50-
#[bdk_blockchain_tests(crate)]
51-
fn local_electrs() -> ElectrumBlockchain {
52-
ElectrumBlockchain::from(Client::new(&testutils::get_electrum_url()).unwrap())
53-
}
54-
5548
impl std::convert::From<Client> for ElectrumBlockchain {
5649
fn from(client: Client) -> Self {
5750
ElectrumBlockchain(client)
@@ -175,3 +168,10 @@ impl ConfigurableBlockchain for ElectrumBlockchain {
175168
)?))
176169
}
177170
}
171+
172+
#[cfg(feature = "test-blockchains")]
173+
crate::bdk_blockchain_tests! {
174+
fn test_instance() -> ElectrumBlockchain {
175+
ElectrumBlockchain::from(Client::new(&testutils::blockchain_tests::get_electrum_url()).unwrap())
176+
}
177+
}

src/blockchain/esplora.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,10 @@ impl_error!(reqwest::Error, Reqwest, EsploraError);
414414
impl_error!(std::num::ParseIntError, Parsing, EsploraError);
415415
impl_error!(consensus::encode::Error, BitcoinEncoding, EsploraError);
416416
impl_error!(bitcoin::hashes::hex::Error, Hex, EsploraError);
417+
418+
#[cfg(feature = "test-blockchains")]
419+
crate::bdk_blockchain_tests! {
420+
fn test_instance() -> EsploraBlockchain {
421+
EsploraBlockchain::new(std::env::var("BDK_ESPLORA_URL").unwrap_or("127.0.0.1:3002".into()).as_str(), None)
422+
}
423+
}

src/database/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ macro_rules! doctest_wallet {
511511
() => {{
512512
use $crate::bitcoin::Network;
513513
use $crate::database::MemoryDatabase;
514-
use testutils::testutils;
514+
use $crate::testutils;
515515
let descriptor = "wpkh(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW)";
516516
let descriptors = testutils!(@descriptors (descriptor) (descriptor));
517517

src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,10 @@ pub extern crate sled;
230230

231231
#[allow(unused_imports)]
232232
#[cfg(test)]
233-
#[macro_use]
234-
extern crate testutils;
235-
#[allow(unused_imports)]
236-
#[cfg(test)]
237-
#[macro_use]
238-
extern crate testutils_macros;
239233
#[allow(unused_imports)]
240234
#[cfg(test)]
241235
#[macro_use]
242-
extern crate serial_test;
236+
pub extern crate serial_test;
243237

244238
#[macro_use]
245239
pub(crate) mod error;
@@ -267,3 +261,10 @@ pub use wallet::Wallet;
267261
pub fn version() -> &'static str {
268262
env!("CARGO_PKG_VERSION", "unknown")
269263
}
264+
265+
// We should consider putting this under a feature flag but we need the macro in doctets so we need
266+
// to wait until https://github.com/rust-lang/rust/issues/67295 is fixed.
267+
//
268+
// Stuff in here is too rough to document atm
269+
#[doc(hidden)]
270+
pub mod testutils;

0 commit comments

Comments
 (0)