Skip to content

Commit

Permalink
Resolve #405
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed Oct 23, 2023
1 parent c4bdbdd commit 08180cc
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 60 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac

- name: Test Dependencies
uses: ./.github/actions/test-dependencies
- name: Build Dependencies
uses: ./.github/actions/build-dependencies
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -51,8 +51,8 @@ jobs:
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac

- name: Test Dependencies
uses: ./.github/actions/test-dependencies
- name: Build Dependencies
uses: ./.github/actions/build-dependencies
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions processor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ frost = { package = "modular-frost", path = "../crypto/frost", features = ["test

env_logger = "0.10"

dockertest = "0.4"
serai-docker-tests = { path = "../tests/docker" }

[features]
secp256k1 = ["k256", "frost/secp256k1"]
bitcoin = ["dep:secp256k1", "secp256k1", "bitcoin-serai", "serai-client/bitcoin"]
Expand Down
82 changes: 78 additions & 4 deletions processor/src/tests/literal/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
use dockertest::{
PullPolicy, StartPolicy, LogOptions, LogAction, LogPolicy, LogSource, Image,
TestBodySpecification, DockerOperations, DockerTest,
};

#[cfg(feature = "bitcoin")]
mod bitcoin {
use super::*;
use crate::networks::{Network, Bitcoin};

#[test]
Expand All @@ -13,14 +19,47 @@ mod bitcoin {
check::<IsTrue<{ Bitcoin::DUST >= bitcoin_serai::wallet::DUST }>>();
}

async fn bitcoin() -> Bitcoin {
let bitcoin = Bitcoin::new("http://serai:[email protected]:18443".to_string()).await;
fn spawn_bitcoin() -> DockerTest {
serai_docker_tests::build("bitcoin".to_string());

let composition = TestBodySpecification::with_image(
Image::with_repository("serai-dev-bitcoin").pull_policy(PullPolicy::Never),
)
.replace_cmd(vec![
"bitcoind".to_string(),
"-txindex".to_string(),
"-regtest".to_string(),
format!("-rpcuser=serai"),
format!("-rpcpassword=seraidex"),
"-rpcbind=0.0.0.0".to_string(),
"-rpcallowip=0.0.0.0/0".to_string(),
"-rpcport=8332".to_string(),
])
.set_start_policy(StartPolicy::Strict)
.set_log_options(Some(LogOptions {
action: LogAction::Forward,
policy: LogPolicy::OnError,
source: LogSource::Both,
}))
.set_publish_all_ports(true);

let mut test = DockerTest::new().with_network(dockertest::Network::Isolated);
test.provide_container(composition);
test
}

async fn bitcoin(ops: &DockerOperations) -> Bitcoin {
let handle = ops.handle("serai-dev-bitcoin").host_port(8332).unwrap();
// TODO: Replace with a check if the node has booted
tokio::time::sleep(core::time::Duration::from_secs(20)).await;
let bitcoin = Bitcoin::new(format!("http://serai:seraidex@{}:{}", handle.0, handle.1)).await;
bitcoin.fresh_chain().await;
bitcoin
}

test_network!(
Bitcoin,
spawn_bitcoin,
bitcoin,
bitcoin_key_gen,
bitcoin_scanner,
Expand All @@ -33,10 +72,44 @@ mod bitcoin {

#[cfg(feature = "monero")]
mod monero {
use super::*;
use crate::networks::{Network, Monero};

async fn monero() -> Monero {
let monero = Monero::new("http://127.0.0.1:18081".to_string());
fn spawn_monero() -> DockerTest {
serai_docker_tests::build("monero".to_string());

let composition = TestBodySpecification::with_image(
Image::with_repository("serai-dev-monero").pull_policy(PullPolicy::Never),
)
.replace_cmd(vec![
"monerod".to_string(),
"--regtest".to_string(),
"--offline".to_string(),
"--fixed-difficulty=1".to_string(),
"--rpc-bind-ip=0.0.0.0".to_string(),
format!("--rpc-login=serai:seraidex"),
"--rpc-access-control-origins=*".to_string(),
"--confirm-external-bind".to_string(),
"--non-interactive".to_string(),
])
.set_start_policy(StartPolicy::Strict)
.set_log_options(Some(LogOptions {
action: LogAction::Forward,
policy: LogPolicy::OnError,
source: LogSource::Both,
}))
.set_publish_all_ports(true);

let mut test = DockerTest::new().with_network(dockertest::Network::Isolated);
test.provide_container(composition);
test
}

async fn monero(ops: &DockerOperations) -> Monero {
let handle = ops.handle("serai-dev-monero").host_port(18081).unwrap();
// TODO: Replace with a check if the node has booted
tokio::time::sleep(core::time::Duration::from_secs(20)).await;
let monero = Monero::new(format!("http://serai:seraidex@{}:{}", handle.0, handle.1));
while monero.get_latest_block_number().await.unwrap() < 150 {
monero.mine_block().await;
}
Expand All @@ -45,6 +118,7 @@ mod monero {

test_network!(
Monero,
spawn_monero,
monero,
monero_key_gen,
monero_scanner,
Expand Down
84 changes: 32 additions & 52 deletions processor/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,11 @@ lazy_static::lazy_static! {
static ref INIT_LOGGER: () = env_logger::init();
}

#[macro_export]
macro_rules! sequential {
() => {
lazy_static::lazy_static! {
static ref SEQUENTIAL: tokio::sync::Mutex<()> = tokio::sync::Mutex::new(());
}
};
}

#[macro_export]
macro_rules! async_sequential {
($(async fn $name: ident() $body: block)*) => {
$(
#[tokio::test]
async fn $name() {
*$crate::tests::INIT_LOGGER;
let guard = SEQUENTIAL.lock().await;
let local = tokio::task::LocalSet::new();
local.run_until(async move {
if let Err(err) = tokio::task::spawn_local(async move { $body }).await {
drop(guard);
Err(err).unwrap()
}
}).await;
}
)*
}
}

#[macro_export]
macro_rules! test_network {
(
$N: ident,
$docker: ident,
$network: ident,
$key_gen: ident,
$scanner: ident,
Expand All @@ -66,42 +38,50 @@ macro_rules! test_network {
test_addresses,
};

// This doesn't interact with a node and accordingly doesn't need to be run sequentially
// This doesn't interact with a node and accordingly doesn't need to be run
#[tokio::test]
async fn $key_gen() {
test_key_gen::<$N>().await;
}

sequential!();

async_sequential! {
async fn $scanner() {
test_scanner($network().await).await;
}
#[test]
fn $scanner() {
let docker = $docker();
docker.run(|ops| async move {
test_scanner($network(&ops).await).await;
});
}

async_sequential! {
async fn $signer() {
test_signer($network().await).await;
}
#[test]
fn $signer() {
let docker = $docker();
docker.run(|ops| async move {
test_signer($network(&ops).await).await;
});
}

async_sequential! {
async fn $wallet() {
test_wallet($network().await).await;
}
#[test]
fn $wallet() {
let docker = $docker();
docker.run(|ops| async move {
test_wallet($network(&ops).await).await;
});
}

async_sequential! {
async fn $addresses() {
test_addresses($network().await).await;
}
#[test]
fn $addresses() {
let docker = $docker();
docker.run(|ops| async move {
test_addresses($network(&ops).await).await;
});
}

async_sequential! {
async fn $no_deadlock_in_multisig_completed() {
test_no_deadlock_in_multisig_completed($network().await).await;
}
#[test]
fn $no_deadlock_in_multisig_completed() {
let docker = $docker();
docker.run(|ops| async move {
test_no_deadlock_in_multisig_completed($network(&ops).await).await;
});
}
};
}
Expand Down

0 comments on commit 08180cc

Please sign in to comment.