Skip to content

Commit

Permalink
Merge #420: Add support for running integration tests via cargo test
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sanket1729 committed Jun 2, 2022
2 parents c1bba6f + 139324a commit 56207d5
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 276 deletions.
19 changes: 1 addition & 18 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,4 @@ jobs:
- name: Running cargo
env:
DO_FEATURE_MATRIX: true
run: ./contrib/test.sh

IntTests:
name: Integration tests
runs-on: ubuntu-latest
steps:
- name: Checkout Crate
uses: actions/checkout@v2
- name: Checkout Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Running cargo
env:
BITCOINVERSION: '22.0'
run: ./contrib/test.sh
run: ./contrib/test.sh
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ rand = ["bitcoin/rand"]
bitcoin = "0.28.0"
serde = { version = "1.0", optional = true}

[dev-dependencies]
bitcoind = {version = "0.26.1", features=["22_0"]}
actual-rand = { package = "rand", version = "0.8.4"}
bitcoin = { version = "0.28", features = ["rand"]}

[[example]]
name = "htlc"
required-features = ["compiler"]
Expand Down
13 changes: 0 additions & 13 deletions contrib/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,4 @@ if [ "$DO_DOCS" = true ]; then
RUSTDOCFLAGS="--cfg docsrs" cargo doc --all --features="$FEATURES"
fi

# Run Integration tests if told so
if [ -n "$BITCOINVERSION" ]; then
set -e
cd integration_test
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.
sha256sum --check bitcoin-core-$BITCOINVERSION.sha256sum
export PATH=$PATH:$(pwd)/bitcoin-$BITCOINVERSION/bin
./run.sh
# Cleanups
rm -rf bitcoin-$BITCOINVERSION
exit 0
fi

exit 0
14 changes: 0 additions & 14 deletions integration_test/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion integration_test/bitcoin-core-0.21.0.sha256sum

This file was deleted.

1 change: 0 additions & 1 deletion integration_test/bitcoin-core-22.0.sha256sum

This file was deleted.

34 changes: 0 additions & 34 deletions integration_test/random_ms.txt

This file was deleted.

40 changes: 0 additions & 40 deletions integration_test/run.sh

This file was deleted.

132 changes: 0 additions & 132 deletions integration_test/src/main.rs

This file was deleted.

29 changes: 29 additions & 0 deletions tests/setup/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
extern crate miniscript;

use bitcoind::bitcoincore_rpc::RpcApi;
use bitcoind::BitcoinD;
use miniscript::bitcoin;

pub mod test_util;

// Launch an instance of bitcoind with
pub fn setup() -> BitcoinD {
let exe_path = bitcoind::exe_path().unwrap();
let bitcoind = bitcoind::BitcoinD::new(exe_path).unwrap();
let cl = &bitcoind.client;
// generate to an address by the wallet. And wait for funds to mature
let addr = cl.get_new_address(None, None).unwrap();
let blks = cl.generate_to_address(101, &addr).unwrap();
assert_eq!(blks.len(), 101);

assert_eq!(
cl.get_balance(Some(1) /*min conf*/, None).unwrap(),
bitcoin::Amount::from_sat(100_000_000 * 50)
);
bitcoind
}

#[test]
fn test_setup() {
setup();
}
15 changes: 10 additions & 5 deletions integration_test/src/test_util.rs → tests/setup/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
//! The keys/hashes are automatically translated so that the tests knows how to satisfy things that don't end with !
//!
use bitcoin::hashes::{hex::ToHex, Hash};
use miniscript::descriptor::{SinglePub, SinglePubKey};
use miniscript::{Descriptor, DescriptorPublicKey, Miniscript, ScriptContext, TranslatePk};
use rand::RngCore;
use std::str::FromStr;

use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d};
use actual_rand as rand;
use bitcoin::hashes::hex::ToHex;
use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d, Hash};
use bitcoin::secp256k1;
use miniscript::descriptor::{SinglePub, SinglePubKey};
use miniscript::{Descriptor, DescriptorPublicKey, Miniscript, ScriptContext, TranslatePk};
use rand::RngCore;

#[derive(Clone, Debug)]
pub struct PubData {
Expand Down Expand Up @@ -142,6 +143,8 @@ pub fn random_pk(mut seed: u8) -> bitcoin::PublicKey {
}
}

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

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

0 comments on commit 56207d5

Please sign in to comment.