Skip to content

Commit

Permalink
Merge pull request #44 from rustaceanrob/ci-09-06
Browse files Browse the repository at this point in the history
ci: add CI job
  • Loading branch information
rustaceanrob authored Sep 6, 2024
2 parents bfb2112 + 2e8eba7 commit 1f5d5a3
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 18 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build & Test

on:
push:
branches:
- master
pull_request:

jobs:
build:
strategy:
matrix:
platform: [ubuntu-latest, windows-latest]
toolchain: [1.63.0, stable]
include:
- toolchain: 1.63.0
msrv: true
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v3
- name: Update Toolchain
run: |
rustup default ${{ matrix.toolchain }}
rustup component add --toolchain ${{ matrix.toolchain }} rustfmt
rustup component add --toolchain ${{ matrix.toolchain }} clippy
rustup update ${{ matrix.toolchain }}
- name: Pin dependencies
if: matrix.msrv
run: cargo update -p allocator-api2 --precise "0.2.9" --verbose
- name: Lint all targets
run: cargo clippy --all-targets
- name: Format
run: cargo fmt -- --check
- name: Build with defeault features
run: cargo build --verbose
- name: Check release build on Rust ${{ matrix.toolchain }}
run: cargo check --release --verbose --color always
- name: Test
run: cargo test --verbose
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ debug/
target/
Cargo.lock
.DS_Store
.vscode/

# database
data/
Expand Down
6 changes: 3 additions & 3 deletions examples/signet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ async fn main() -> anyhow::Result<()> {

let desc = "tr([7d94197e/86'/1'/0']tpubDCyQVJj8KzjiQsFjmb3KwECVXPvMwvAxxZGCP9XmWSopmjW3bCV3wD7TgxrUhiGSueDS1MU5X1Vb1YjYcp8jitXc5fXfdC1z68hDDEyKRNr/0/*)";
let change_desc = "tr([7d94197e/86'/1'/0']tpubDCyQVJj8KzjiQsFjmb3KwECVXPvMwvAxxZGCP9XmWSopmjW3bCV3wD7TgxrUhiGSueDS1MU5X1Vb1YjYcp8jitXc5fXfdC1z68hDDEyKRNr/1/*)";
let (descriptor, _) = Descriptor::parse_descriptor(&secp, &desc)?;
let (change_descriptor, _) = Descriptor::parse_descriptor(&secp, &change_desc)?;
let (descriptor, _) = Descriptor::parse_descriptor(&secp, desc)?;
let (change_descriptor, _) = Descriptor::parse_descriptor(&secp, change_desc)?;

let g = genesis_block(Network::Signet).block_hash();
let (mut chain, _) = LocalChain::from_genesis_hash(g);
Expand Down Expand Up @@ -81,7 +81,7 @@ async fn main() -> anyhow::Result<()> {
.index
.reveal_to_target_multi(&update.last_active_indices);
indexed_tx_graph_changeset.merge(index_changeset.into());
let _ = graph.apply_changeset(indexed_tx_graph_changeset);
graph.apply_changeset(indexed_tx_graph_changeset);
}

// Shutdown
Expand Down
2 changes: 1 addition & 1 deletion examples/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn main() -> anyhow::Result<()> {
let change_desc = "tr([7d94197e/86'/1'/0']tpubDCyQVJj8KzjiQsFjmb3KwECVXPvMwvAxxZGCP9XmWSopmjW3bCV3wD7TgxrUhiGSueDS1MU5X1Vb1YjYcp8jitXc5fXfdC1z68hDDEyKRNr/1/*)";

let peers = PEERS
.into_iter()
.iter()
.map(|ip| {
let mut peer = TrustedPeer::from_ip(*ip);
peer.set_services(ServiceFlags::P2P_V2);
Expand Down
2 changes: 1 addition & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//!
//! The node has a number of configurations. Notably, the height of in the blockchain to start a wallet recovery
//! and the nodes on the peer-to-peer network are both configurable.
//!
//!
//! ```no_run
//! # const RECEIVE: &str = "tr([7d94197e/86'/1'/0']tpubDCyQVJj8KzjiQsFjmb3KwECVXPvMwvAxxZGCP9XmWSopmjW3bCV3wD7TgxrUhiGSueDS1MU5X1Vb1YjYcp8jitXc5fXfdC1z68hDDEyKRNr/0/*)";
//! # const CHANGE: &str = "tr([7d94197e/86'/1'/0']tpubDCyQVJj8KzjiQsFjmb3KwECVXPvMwvAxxZGCP9XmWSopmjW3bCV3wD7TgxrUhiGSueDS1MU5X1Vb1YjYcp8jitXc5fXfdC1z68hDDEyKRNr/1/*)";
Expand Down
26 changes: 13 additions & 13 deletions tests/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ fn testenv() -> anyhow::Result<TestEnv> {
})
}

fn wait_for_height(env: &TestEnv, height: u32) -> anyhow::Result<()> {
async fn wait_for_height(env: &TestEnv, height: u32) -> anyhow::Result<()> {
while env.rpc_client().get_block_count()? < height as u64 {
let _ = time::sleep(Duration::from_millis(256));
time::sleep(Duration::from_millis(256)).await;
}
Ok(())
}
Expand All @@ -43,12 +43,12 @@ fn init_node(
wallet: &bdk_wallet::Wallet,
) -> anyhow::Result<(bdk_kyoto::Node, bdk_kyoto::Client<KeychainKind>)> {
let peer = env.bitcoind.params.p2p_socket.unwrap();
let ip: IpAddr = peer.ip().clone().into();
let ip: IpAddr = (*peer.ip()).into();
let port = peer.port();
let mut peer = TrustedPeer::from_ip(ip);
peer.port = Some(port);
let path = tempfile::tempdir()?.path().join("kyoto-data");
Ok(LightClientBuilder::new(&wallet)
Ok(LightClientBuilder::new(wallet)
.peers(vec![peer])
.data_dir(path)
.connections(1)
Expand Down Expand Up @@ -76,13 +76,13 @@ async fn update_returns_blockchain_data() -> anyhow::Result<()> {

// mine blocks
let _hashes = env.mine_blocks(100, Some(miner.clone()))?;
wait_for_height(&env, 101)?;
wait_for_height(&env, 101).await?;

// send tx
let amt = Amount::from_btc(0.21)?;
let txid = env.send(&addr, amt)?;
let hashes = env.mine_blocks(1, Some(miner))?;
wait_for_height(&env, 102)?;
wait_for_height(&env, 102).await?;

// run node
task::spawn(async move { node.run().await });
Expand All @@ -95,8 +95,8 @@ async fn update_returns_blockchain_data() -> anyhow::Result<()> {
last_active_indices,
} = res;
// graph tx and anchor
let tx = tx_update.txs.iter().next().unwrap();
let (anchor, anchor_txid) = tx_update.anchors.first().unwrap().clone();
let tx = tx_update.txs.first().unwrap();
let (anchor, anchor_txid) = *tx_update.anchors.first().unwrap();
assert_eq!(anchor_txid, txid);
assert_eq!(anchor.block_id.height, 102);
assert_eq!(anchor.block_id.hash, hashes[0]);
Expand Down Expand Up @@ -133,33 +133,33 @@ async fn update_handles_reorg() -> anyhow::Result<()> {
.get_new_address(None, None)?
.assume_checked();
let _hashes = env.mine_blocks(100, Some(miner.clone()))?;
wait_for_height(&env, 101)?;
wait_for_height(&env, 101).await?;

// send tx
let amt = Amount::from_btc(0.21)?;
let txid = env.send(&addr, amt)?;
let hashes = env.mine_blocks(1, Some(miner.clone()))?;
let blockhash = hashes[0];
wait_for_height(&env, 102)?;
wait_for_height(&env, 102).await?;

task::spawn(async move { node.run().await });

// get update
let logger = PrintLogger::new();
let res = client.update(&logger).await.expect("should have update");
let (anchor, anchor_txid) = res.tx_update.anchors.first().unwrap().clone();
let (anchor, anchor_txid) = *res.tx_update.anchors.first().unwrap();
assert_eq!(anchor.block_id.hash, blockhash);
assert_eq!(anchor_txid, txid);

// reorg
let hashes = env.reorg(1)?; // 102
let new_blockhash = hashes[0];
_ = env.mine_blocks(1, Some(miner))?; // 103
wait_for_height(&env, 103)?;
wait_for_height(&env, 103).await?;

// expect tx to confirm at same height but different blockhash
let res = client.update(&logger).await.expect("should have update");
let (anchor, anchor_txid) = res.tx_update.anchors.first().unwrap().clone();
let (anchor, anchor_txid) = *res.tx_update.anchors.first().unwrap();
assert_eq!(anchor_txid, txid);
assert_eq!(anchor.block_id.height, 102);
assert_ne!(anchor.block_id.hash, blockhash);
Expand Down

0 comments on commit 1f5d5a3

Please sign in to comment.