Skip to content

Commit 56207d5

Browse files
committed
Merge #420: Add support for running integration tests via cargo test
139324a Remove integration test code (sanket1729) 90b5f10 Remove warnings (sanket1729) 967b95e Add support for running integration tests via cargo test (sanket1729) Pull request description: There are still some annoying warnings present for unused functions when they are used. rust-lang/rust#46379 Later commits will remove the hacky integration test setup. Running `cargo test` now should also run integration tests Our testing infrastructure now takes a long time to build because we have more than 100 dependencies (transitive). But all of these are dev dependencies, so our library isn't getting bloated. Fixes #361 ACKs for top commit: apoelstra: ACK 139324a Tree-SHA512: debf68fd0ac98cffa9c8c89964d6d1c45ee542fe17eb2fdab6295357efc06eb43a0412e6ed5d0fd7264a987989984eebb0c5b3bbf7169ecb780d31dce887cb0b
2 parents c1bba6f + 139324a commit 56207d5

File tree

13 files changed

+143
-276
lines changed

13 files changed

+143
-276
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,4 @@ jobs:
6969
- name: Running cargo
7070
env:
7171
DO_FEATURE_MATRIX: true
72-
run: ./contrib/test.sh
73-
74-
IntTests:
75-
name: Integration tests
76-
runs-on: ubuntu-latest
77-
steps:
78-
- name: Checkout Crate
79-
uses: actions/checkout@v2
80-
- name: Checkout Toolchain
81-
uses: actions-rs/toolchain@v1
82-
with:
83-
profile: minimal
84-
toolchain: stable
85-
override: true
86-
- name: Running cargo
87-
env:
88-
BITCOINVERSION: '22.0'
89-
run: ./contrib/test.sh
72+
run: ./contrib/test.sh

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ rand = ["bitcoin/rand"]
2222
bitcoin = "0.28.0"
2323
serde = { version = "1.0", optional = true}
2424

25+
[dev-dependencies]
26+
bitcoind = {version = "0.26.1", features=["22_0"]}
27+
actual-rand = { package = "rand", version = "0.8.4"}
28+
bitcoin = { version = "0.28", features = ["rand"]}
29+
2530
[[example]]
2631
name = "htlc"
2732
required-features = ["compiler"]

contrib/test.sh

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,4 @@ if [ "$DO_DOCS" = true ]; then
6666
RUSTDOCFLAGS="--cfg docsrs" cargo doc --all --features="$FEATURES"
6767
fi
6868

69-
# Run Integration tests if told so
70-
if [ -n "$BITCOINVERSION" ]; then
71-
set -e
72-
cd integration_test
73-
curl https://bitcoincore.org/bin/bitcoin-core-$BITCOINVERSION/bitcoin-$BITCOINVERSION-x86_64-linux-gnu.tar.gz | tar xvzf - bitcoin-$BITCOINVERSION/bin/bitcoind # will abort if the check fails.
74-
sha256sum --check bitcoin-core-$BITCOINVERSION.sha256sum
75-
export PATH=$PATH:$(pwd)/bitcoin-$BITCOINVERSION/bin
76-
./run.sh
77-
# Cleanups
78-
rm -rf bitcoin-$BITCOINVERSION
79-
exit 0
80-
fi
81-
8269
exit 0

integration_test/Cargo.toml

Lines changed: 0 additions & 14 deletions
This file was deleted.

integration_test/bitcoin-core-0.21.0.sha256sum

Lines changed: 0 additions & 1 deletion
This file was deleted.

integration_test/bitcoin-core-22.0.sha256sum

Lines changed: 0 additions & 1 deletion
This file was deleted.

integration_test/random_ms.txt

Lines changed: 0 additions & 34 deletions
This file was deleted.

integration_test/run.sh

Lines changed: 0 additions & 40 deletions
This file was deleted.

integration_test/src/main.rs

Lines changed: 0 additions & 132 deletions
This file was deleted.

tests/setup/mod.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
extern crate miniscript;
2+
3+
use bitcoind::bitcoincore_rpc::RpcApi;
4+
use bitcoind::BitcoinD;
5+
use miniscript::bitcoin;
6+
7+
pub mod test_util;
8+
9+
// Launch an instance of bitcoind with
10+
pub fn setup() -> BitcoinD {
11+
let exe_path = bitcoind::exe_path().unwrap();
12+
let bitcoind = bitcoind::BitcoinD::new(exe_path).unwrap();
13+
let cl = &bitcoind.client;
14+
// generate to an address by the wallet. And wait for funds to mature
15+
let addr = cl.get_new_address(None, None).unwrap();
16+
let blks = cl.generate_to_address(101, &addr).unwrap();
17+
assert_eq!(blks.len(), 101);
18+
19+
assert_eq!(
20+
cl.get_balance(Some(1) /*min conf*/, None).unwrap(),
21+
bitcoin::Amount::from_sat(100_000_000 * 50)
22+
);
23+
bitcoind
24+
}
25+
26+
#[test]
27+
fn test_setup() {
28+
setup();
29+
}

integration_test/src/test_util.rs renamed to tests/setup/test_util.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
//! The keys/hashes are automatically translated so that the tests knows how to satisfy things that don't end with !
1818
//!
1919
20-
use bitcoin::hashes::{hex::ToHex, Hash};
21-
use miniscript::descriptor::{SinglePub, SinglePubKey};
22-
use miniscript::{Descriptor, DescriptorPublicKey, Miniscript, ScriptContext, TranslatePk};
23-
use rand::RngCore;
2420
use std::str::FromStr;
2521

26-
use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d};
22+
use actual_rand as rand;
23+
use bitcoin::hashes::hex::ToHex;
24+
use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d, Hash};
2725
use bitcoin::secp256k1;
26+
use miniscript::descriptor::{SinglePub, SinglePubKey};
27+
use miniscript::{Descriptor, DescriptorPublicKey, Miniscript, ScriptContext, TranslatePk};
28+
use rand::RngCore;
2829

2930
#[derive(Clone, Debug)]
3031
pub struct PubData {
@@ -142,6 +143,8 @@ pub fn random_pk(mut seed: u8) -> bitcoin::PublicKey {
142143
}
143144
}
144145

146+
#[allow(dead_code)]
147+
// https://github.com/rust-lang/rust/issues/46379. The code is pub fn and integration test, but still shows warnings
145148
/// Parse an insane miniscript into a miniscript with the format described above at file header
146149
pub fn parse_insane_ms<Ctx: ScriptContext>(
147150
ms: &str,
@@ -213,6 +216,8 @@ pub fn parse_insane_ms<Ctx: ScriptContext>(
213216
ms
214217
}
215218

219+
#[allow(dead_code)]
220+
// https://github.com/rust-lang/rust/issues/46379. The code is pub fn and integration test, but still shows warnings
216221
pub fn parse_test_desc(desc: &str, pubdata: &PubData) -> Descriptor<DescriptorPublicKey> {
217222
let desc = subs_hash_frag(desc, pubdata);
218223
let desc =

0 commit comments

Comments
 (0)