Skip to content
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
12 changes: 12 additions & 0 deletions .github/workflows/check_lint_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ jobs:
chmod +x bitcoin-patched-bins/bitcoind
chmod +x bitcoin-patched-bins/bitcoin-cli
popd

- name: Download bitcoin unpatched
run: |
pushd ..
wget https://bitcoincore.org/bin/bitcoin-core-30.2/bitcoin-30.2-x86_64-linux-gnu.tar.gz
tar -xf bitcoin-30.2-x86_64-linux-gnu.tar.gz
rm bitcoin-30.2-x86_64-linux-gnu.tar.gz
mv bitcoin-30.2/bin bitcoin-unpatched-bins
rm -r bitcoin-30.2
popd

- name: Download latest bip300301_enforcer
run: |
pushd ..
Expand Down Expand Up @@ -103,6 +114,7 @@ jobs:
run: |
export BIP300301_ENFORCER='../bip300301-enforcer'
export BITCOIND='../bitcoin-patched-bins/bitcoind'
export BITCOIND_UNPATCHED='../bitcoin-unpatched-bins/bitcoind'
export BITCOIN_CLI='../bitcoin-patched-bins/bitcoin-cli'
export ELECTRS='../electrs/target/release/electrs'
export BITNAMES_APP='target/debug/plain_bitnames_app'
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ x25519-dalek = "2.0.0"
[workspace.dependencies.bip300301_enforcer_lib]
default-features = false
git = "https://github.com/LayerTwo-Labs/bip300301_enforcer"
rev = "a8d169ee34aeddf6d354aa52376d847831d7fbb3"
rev = "9c3eb0bdcb5b9a458e6f92cafb8bdbf76a860f74"

[workspace.dependencies.bip300301_enforcer_integration_tests]
default-features = false
git = "https://github.com/LayerTwo-Labs/bip300301_enforcer"
rev = "a8d169ee34aeddf6d354aa52376d847831d7fbb3"
rev = "9c3eb0bdcb5b9a458e6f92cafb8bdbf76a860f74"

[workspace.dependencies.l2l-openapi]
git = "https://github.com/Ash-L2L/l2l-openapi"
Expand Down
2 changes: 1 addition & 1 deletion app/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl RpcServer for RpcServerImpl {
) -> RpcResult<Option<WithdrawalBundle>> {
self.app
.node
.get_pending_withdrawal_bundle()
.try_get_pending_withdrawal_bundle()
.map_err(custom_err)
}

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dotenvy = "0.15.7"
futures = { workspace = true }
jsonrpsee = { workspace = true }
libtest-mimic = "0.8.1"
plain_bitnames = { path = "../lib" }
plain_bitnames = { path = "../lib", features = ["clap"] }
plain_bitnames_app_rpc_api = { path = "../rpc-api" }
reserve-port = "2.0.1"
thiserror = { workspace = true }
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/example.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
BIP300301_ENFORCER='../bip300301_enforcer/target/debug/bip300301_enforcer'
BITCOIND='../bitcoin/build/src/bitcoind'
BITCOIND='../bitcoin-patched/build/src/bitcoind'
BITCOIND_UNPATCHED='../bitcoin/build/src/bitcoind'
BITCOIN_CLI='../bitcoin/build/src/bitcoin-cli'
ELECTRS='../electrs/target/release/electrs'
BITNAMES_APP='target/debug/plain_bitnames_app'
20 changes: 11 additions & 9 deletions integration_tests/ibd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use std::net::SocketAddr;
use bip300301_enforcer_integration_tests::{
integration_test::{activate_sidechain, fund_enforcer, propose_sidechain},
setup::{
Mode, Network, PostSetup as EnforcerPostSetup, Sidechain as _,
setup as setup_enforcer,
Mode, Network, PostSetup as EnforcerPostSetup,
PreSetup as EnforcerPreSetup, SetupOpts as EnforcerSetupOpts,
Sidechain as _,
},
util::{AbortOnDrop, AsyncTrial, TestFailureCollector, TestFileRegistry},
};
Expand All @@ -33,13 +34,14 @@ async fn setup(
bin_paths: BinPaths,
res_tx: mpsc::UnboundedSender<anyhow::Result<()>>,
) -> anyhow::Result<(EnforcerPostSetup, BitNamesNodes)> {
let mut enforcer_post_setup = setup_enforcer(
&bin_paths.others,
Network::Regtest,
Mode::Mempool,
res_tx.clone(),
)
.await?;
let enforcer_pre_setup =
EnforcerPreSetup::new(bin_paths.others, Network::Regtest)?;
let mut enforcer_post_setup = {
let setup_opts: EnforcerSetupOpts = Default::default();
enforcer_pre_setup
.setup(Mode::Mempool, setup_opts, res_tx.clone())
.await?
};
let sidechain_sender = PostSetup::setup(
Init {
bitnames_app: bin_paths.bitnames.clone(),
Expand Down
153 changes: 135 additions & 18 deletions integration_tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
use bip300301_enforcer_integration_tests::{
setup::{Mode, Network},
integration_test as bip300301_enforcer_integration_test,
setup::{
Mode, Network, PostSetup as EnforcerPostSetup,
PreSetup as EnforcerPreSetup, SetupOpts as EnforcerSetupOpts,
Sidechain as _,
},
util::{AsyncTrial, TestFailureCollector, TestFileRegistry},
};
use futures::{FutureExt, future::BoxFuture};
use bip300301_enforcer_lib::bins::CommandExt;
use futures::{FutureExt, channel::mpsc::UnboundedSender, future::BoxFuture};
use plain_bitnames_app_rpc_api::RpcClient as _;

use crate::{
ibd::ibd_trial,
Expand All @@ -12,7 +19,112 @@ use crate::{
util::BinPaths,
};

fn deposit_withdraw_roundtrip(
#[allow(clippy::significant_drop_tightening, reason = "false positive")]
pub async fn deposit_withdraw_roundtrip_task(
post_setup: &mut EnforcerPostSetup,
res_tx: UnboundedSender<anyhow::Result<()>>,
init: Init,
) -> anyhow::Result<PostSetup> {
use bip300301_enforcer_integration_test::{
activate_sidechain, deposit, fund_enforcer, propose_sidechain,
wait_for_wallet_sync, withdraw_succeed,
};
use bitcoin::Amount;

const DEPOSIT_AMOUNT: Amount = Amount::from_sat(21_000_000);
const DEPOSIT_FEE: Amount = Amount::from_sat(1_000_000);
const WITHDRAW_AMOUNT: Amount = Amount::from_sat(18_000_000);
const WITHDRAW_FEE: Amount = Amount::from_sat(1_000_000);

let mut sidechain = PostSetup::setup(init, post_setup, res_tx).await?;
tracing::info!("Setup successfully");
let () = propose_sidechain::<PostSetup>(post_setup).await?;
tracing::info!("Proposed sidechain successfully");
let () = activate_sidechain::<PostSetup>(post_setup).await?;
tracing::info!("Activated sidechain successfully");
let () = fund_enforcer::<PostSetup>(post_setup).await?;
tracing::info!("Funded enforcer successfully");
let deposit_address = sidechain.get_deposit_address().await?;
let () = deposit(
post_setup,
&mut sidechain,
&deposit_address,
DEPOSIT_AMOUNT,
DEPOSIT_FEE,
)
.await?;
tracing::info!("Deposited to sidechain successfully");
// Wait for mempool to catch up before attempting second deposit
tracing::debug!("Waiting for wallet sync...");
let () = wait_for_wallet_sync().await?;
tracing::info!("Attempting second deposit");
let () = deposit(
post_setup,
&mut sidechain,
&deposit_address,
DEPOSIT_AMOUNT,
DEPOSIT_FEE,
)
.await?;
tracing::info!("Deposited to sidechain successfully");
let sidechain_block_count = sidechain.rpc_client.getblockcount().await?;
let target_sidechain_block_height = 5;
tracing::info!(
sidechain_block_count,
target_sidechain_block_height,
"BMMing sidechain blocks..."
);
sidechain
.bmm(
post_setup,
target_sidechain_block_height - sidechain_block_count,
)
.await?;
let () = withdraw_succeed(
post_setup,
&mut sidechain,
WITHDRAW_AMOUNT,
WITHDRAW_FEE,
Amount::ZERO,
)
.await?;
tracing::info!("Withdrawal succeeded");
let mainchain_block_count = post_setup
.bitcoin_cli
.command::<String, _, String, _, _>([], "getblockcount", [])
.run_utf8()
.await?;
let sidechain_block_count = sidechain.rpc_client.getblockcount().await?;
tracing::info!(%mainchain_block_count, sidechain_block_count);
Ok(sidechain)
}

async fn deposit_withdraw_roundtrip(
mut post_setup: EnforcerPostSetup,
init: Init,
res_tx: UnboundedSender<anyhow::Result<()>>,
) -> anyhow::Result<()> {
let sidechain_post_setup =
deposit_withdraw_roundtrip_task(&mut post_setup, res_tx, init).await?;
// check that everything is ok after BMM'ing 3 blocks
let mut block_count_pre =
sidechain_post_setup.rpc_client.getblockcount().await?;
sidechain_post_setup.bmm_single(&mut post_setup).await?;
let mut block_count_post =
sidechain_post_setup.rpc_client.getblockcount().await?;
anyhow::ensure!(block_count_post == block_count_pre + 1);
block_count_pre = block_count_post;
sidechain_post_setup.bmm_single(&mut post_setup).await?;
block_count_post = sidechain_post_setup.rpc_client.getblockcount().await?;
anyhow::ensure!(block_count_post == block_count_pre + 1);
block_count_pre = block_count_post;
sidechain_post_setup.bmm_single(&mut post_setup).await?;
block_count_post = sidechain_post_setup.rpc_client.getblockcount().await?;
anyhow::ensure!(block_count_post == block_count_pre + 1);
Ok(())
}

fn deposit_withdraw_roundtrip_trial(
bin_paths: BinPaths,
file_registry: TestFileRegistry,
failure_collector: TestFailureCollector,
Expand All @@ -21,20 +133,25 @@ fn deposit_withdraw_roundtrip(
"deposit_withdraw_roundtrip",
async move {
let (res_tx, _) = futures::channel::mpsc::unbounded();
let post_setup = bip300301_enforcer_integration_tests::setup::setup(
&bin_paths.others,
Network::Regtest,
Mode::Mempool,
res_tx
).await?;
bip300301_enforcer_integration_tests::integration_test::deposit_withdraw_roundtrip::<PostSetup>(
post_setup,
Init {
bitnames_app: bin_paths.bitnames,
data_dir_suffix: None,
},
).await
}.boxed(),
let pre_setup =
EnforcerPreSetup::new(bin_paths.others, Network::Regtest)?;
let post_setup = {
let setup_opts: EnforcerSetupOpts = Default::default();
pre_setup
.setup(Mode::Mempool, setup_opts, res_tx.clone())
.await?
};
deposit_withdraw_roundtrip(
post_setup,
Init {
bitnames_app: bin_paths.bitnames,
data_dir_suffix: None,
},
res_tx,
)
.await
}
.boxed(),
file_registry,
failure_collector,
)
Expand All @@ -46,7 +163,7 @@ pub fn tests(
failure_collector: TestFailureCollector,
) -> Vec<AsyncTrial<BoxFuture<'static, anyhow::Result<()>>>> {
vec![
deposit_withdraw_roundtrip(
deposit_withdraw_roundtrip_trial(
bin_paths.clone(),
file_registry.clone(),
failure_collector.clone(),
Expand Down
1 change: 1 addition & 0 deletions integration_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fn set_tracing_subscriber(log_level: tracing::Level) -> anyhow::Result<()> {
let targets_filter = {
let default_directives_str = targets_directive_str([
("", saturating_pred_level(log_level)),
("bip300301_enforcer_integration_tests", log_level),
("integration_tests", log_level),
]);
let directives_str =
Expand Down
26 changes: 14 additions & 12 deletions integration_tests/register_bitname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use bip300301_enforcer_integration_tests::{
activate_sidechain, deposit, fund_enforcer, propose_sidechain,
},
setup::{
Mode, Network, PostSetup as EnforcerPostSetup, Sidechain as _,
setup as setup_enforcer,
Mode, Network, PostSetup as EnforcerPostSetup,
PreSetup as EnforcerPreSetup, SetupOpts as EnforcerSetupOpts,
Sidechain as _,
},
util::{AbortOnDrop, AsyncTrial, TestFailureCollector, TestFileRegistry},
};
Expand All @@ -28,24 +29,25 @@ const DEPOSIT_FEE: bitcoin::Amount = bitcoin::Amount::from_sat(1_000_000);

/// Initial setup for the test
async fn setup(
bin_paths: &BinPaths,
bin_paths: BinPaths,
res_tx: mpsc::UnboundedSender<anyhow::Result<()>>,
) -> anyhow::Result<(EnforcerPostSetup, PostSetup)> {
let mut enforcer_post_setup = setup_enforcer(
&bin_paths.others,
Network::Regtest,
Mode::Mempool,
res_tx.clone(),
)
.await?;
let enforcer_pre_setup =
EnforcerPreSetup::new(bin_paths.others, Network::Regtest)?;
let mut enforcer_post_setup = {
let setup_opts: EnforcerSetupOpts = Default::default();
enforcer_pre_setup
.setup(Mode::Mempool, setup_opts, res_tx.clone())
.await?
};
let () = propose_sidechain::<PostSetup>(&mut enforcer_post_setup).await?;
tracing::info!("Proposed sidechain successfully");
let () = activate_sidechain::<PostSetup>(&mut enforcer_post_setup).await?;
tracing::info!("Activated sidechain successfully");
let () = fund_enforcer::<PostSetup>(&mut enforcer_post_setup).await?;
let mut post_setup = PostSetup::setup(
Init {
bitnames_app: bin_paths.bitnames.clone(),
bitnames_app: bin_paths.bitnames,
data_dir_suffix: None,
},
&enforcer_post_setup,
Expand All @@ -72,7 +74,7 @@ async fn register_bitname_task(
res_tx: mpsc::UnboundedSender<anyhow::Result<()>>,
) -> anyhow::Result<()> {
let (mut enforcer_post_setup, post_setup) =
setup(&bin_paths, res_tx.clone()).await?;
setup(bin_paths, res_tx.clone()).await?;
tracing::info!("Reserving BitName");
let _: Txid = post_setup
.rpc_client
Expand Down
13 changes: 7 additions & 6 deletions integration_tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use bip300301_enforcer_integration_tests::{
};
use bip300301_enforcer_lib::types::SidechainNumber;
use futures::{TryFutureExt as _, channel::mpsc, future};
use plain_bitnames::types::{FilledOutput, FilledOutputContent, PointedOutput};
use plain_bitnames::types::{
FilledOutput, FilledOutputContent, Network, PointedOutput,
};
use plain_bitnames_app_rpc_api::RpcClient as _;
use reserve_port::ReservedPort;
use thiserror::Error;
Expand Down Expand Up @@ -169,6 +171,7 @@ impl Sidechain for PostSetup {
.enforcer_serve_grpc
.port(),
net_port: reserved_ports.net.port(),
network: Network::Regtest,
rpc_port: reserved_ports.rpc.port(),
zmq_port: reserved_ports.zmq.port(),
};
Expand Down Expand Up @@ -275,12 +278,10 @@ impl Sidechain for PostSetup {
.latest_failed_withdrawal_bundle_height()
.await?
.unwrap_or(0);
match WITHDRAWAL_BUNDLE_FAILURE_GAP.saturating_sub(
let blocks_to_mine = WITHDRAWAL_BUNDLE_FAILURE_GAP.saturating_sub(
block_height - latest_failed_withdrawal_bundle_height,
) {
0 => WITHDRAWAL_BUNDLE_FAILURE_GAP + 1,
blocks_to_mine => blocks_to_mine,
}
);
std::cmp::max(1, blocks_to_mine)
};
tracing::debug!(
"Mining BitNames blocks until withdrawal bundle is broadcast"
Expand Down
Loading
Loading