Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for running integration tests via cargo test #420

Merged
merged 3 commits into from
Jun 2, 2022
Merged
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
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"]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since there is rand anyway, can't we use sign_schnorr_with_aux_rand and remove the feature rand so that we don't have both bitcoin and bitcoin-with-rand?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adressing in a follow-up PR.


[[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