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

Fix integration tests with real fixures #1324

Merged
merged 2 commits into from
Jan 16, 2023
Merged
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
17 changes: 11 additions & 6 deletions fedimint-server/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::ffi::OsString;
use std::net::SocketAddr;
use std::os::unix::prelude::OsStrExt;

@@ -229,6 +230,15 @@ impl ModuleInitRegistry {
Ok(ModuleDecoderRegistry::from_iter(modules))
}

pub fn get_env_vars_map() -> BTreeMap<OsString, OsString> {
std::env::vars_os()
// We currently have no way to enforce that modules are not reading
// global environment variables manually, but to set a good example
// and expectations we filter them here and pass explicitly.
.filter(|(var, _val)| var.as_os_str().as_bytes().starts_with(b"FM_"))
.collect()
}

pub async fn init_all(
&self,
cfg: &ServerConfig,
@@ -237,12 +247,7 @@ impl ModuleInitRegistry {
) -> anyhow::Result<ModuleRegistry<fedimint_api::server::DynServerModule>> {
let mut modules = BTreeMap::new();

let env: BTreeMap<_, _> = std::env::vars_os()
// We currently have no way to enforce that modules are not reading
// global environment variables manually, but to set a good example
// and expectations we filter them here and pass explicitly.
.filter(|(var, _val)| var.as_os_str().as_bytes().starts_with(b"FM_"))
.collect();
let env = ModuleInitRegistry::get_env_vars_map();

for (module_id, module_cfg) in &cfg.consensus.modules {
let kind = module_cfg.kind();
12 changes: 9 additions & 3 deletions integrationtests/tests/fixtures/mod.rs
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ mod real;
mod utils;

const DEFAULT_P2P_PORT: u16 = 8173;
const BASE_PORT_INIT: u16 = DEFAULT_P2P_PORT + 10000;
const BASE_PORT_INIT: u16 = DEFAULT_P2P_PORT + 20000;
static BASE_PORT: AtomicU16 = AtomicU16::new(BASE_PORT_INIT);

// Helper functions for easier test writing
@@ -169,16 +169,21 @@ pub async fn fixtures(num_peers: u16) -> anyhow::Result<Fixtures> {
match env::var("FM_TEST_DISABLE_MOCKS") {
Ok(s) if s == "1" => {
info!("Testing with REAL Bitcoin and Lightning services");
let mut config_task_group = task_group.make_subgroup().await;
let (server_config, client_config) = distributed_config(
"",
&peers,
params,
module_inits.clone(),
max_evil,
&mut task_group,
&mut config_task_group,
)
.await
.expect("distributed config should not be canceled");
config_task_group
.shutdown_join_all()
.await
.expect("Distributed config did not exit cleanly");

let dir = env::var("FM_TEST_DIR").expect("Must have test dir defined for real tests");
let bitcoin_rpc_url =
@@ -1026,6 +1031,7 @@ impl FederationTest {
let mut override_modules = override_modules(cfg.clone(), db.clone()).await;

let mut modules = BTreeMap::new();
let env_vars = ModuleInitRegistry::get_env_vars_map();

for (kind, gen) in module_inits.legacy_init_order_iter() {
let id = cfg.get_module_id_by_kind(kind.clone()).unwrap();
@@ -1038,7 +1044,7 @@ impl FederationTest {
.init(
cfg.get_module_config(id).unwrap(),
db.clone(),
&BTreeMap::new(),
&env_vars,
&mut task_group,
)
.await
2 changes: 2 additions & 0 deletions scripts/setup-tests.sh
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ POLL_INTERVAL=1
bitcoind -regtest -fallbackfee=0.0004 -txindex -server -rpcuser=bitcoin -rpcpassword=bitcoin -datadir=$FM_BTC_DIR &
echo $! >> $FM_PID_FILE

export FM_BITCOIND_RPC="http://bitcoin:bitcoin@127.0.0.1:18443"

until [ "$($FM_BTC_CLIENT getblockchaininfo | jq -e -r '.chain')" == "regtest" ]; do
sleep $POLL_INTERVAL
done