Skip to content

Commit

Permalink
address_integration_test: Add initial multi threaded test.
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyhunsen committed Jun 27, 2024
1 parent e115cc7 commit 1e413af
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
39 changes: 39 additions & 0 deletions tests/address.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//! Address related integration tests.
use bitcoin_mock_rpc::{Client, RpcApiWrapper};
use bitcoincore_rpc::{Auth, RpcApi};
use std::thread;

mod common;

#[test]
fn generate_to_address_multi_threaded() {
// Bacause `thread::spawn` moves value to closure, cloning a new is needed. This is good,
// because cloning an rpc struct should have a persistent ledger even though there are more than
// one accessors.
let rpc = Client::new("", Auth::None).unwrap();
let cloned_rpc = rpc.clone();
let address = rpc.get_new_address(None, None).unwrap().assume_checked();
let cloned_address = address.clone();

let initial_balance = rpc.get_balance(None, None).unwrap();

thread::spawn(move || {
cloned_rpc
.generate_to_address(101, &cloned_address)
.unwrap();

assert!(cloned_rpc.get_balance(None, None).unwrap() > initial_balance);
})
.join()
.unwrap();

// Change made in other rpc connection should be available now.
let changed_balance = rpc.get_balance(None, None).unwrap();
assert!(changed_balance > initial_balance);

// Adding new blocks should add more funds.
rpc.generate_to_address(101, &address).unwrap();
assert!(rpc.get_balance(None, None).unwrap() > changed_balance);
assert!(rpc.get_balance(None, None).unwrap() > initial_balance);
}
6 changes: 0 additions & 6 deletions tests/transaction.rs

This file was deleted.

0 comments on commit 1e413af

Please sign in to comment.