Skip to content

Commit 1236988

Browse files
authored
Merge pull request #5937 from fdefelici/fix/win-test-compilation-fails
fix: make `cargo test testnet` work on windows
2 parents ecf6147 + bbd5236 commit 1236988

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed

stackslib/src/config/chain_data.rs

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ pub mod tests {
722722
}
723723

724724
#[test]
725+
#[cfg(unix)]
725726
fn test_get_unconfirmed_commits() {
726727
use std::os::unix::fs::PermissionsExt;
727728
let shell_code = r#"#!/bin/bash
@@ -808,6 +809,87 @@ EOF
808809
);
809810
}
810811

812+
#[test]
813+
#[cfg(windows)]
814+
fn test_get_unconfirmed_commits() {
815+
let shell_code = r#"@echo off
816+
(
817+
echo [
818+
echo {
819+
echo "txid": "73c318be8cd272a73200b9630089d77a44342d84b2c0d81c937da714152cf402",
820+
echo "burn": 555000,
821+
echo "address": "1FCcoFSKWvNyhjazNvVdLLw8mGkGdcRMux",
822+
echo "input_txid": "ef0dbf0fc4755de5e94843a4da7c1d943571299afb15f32b76bac5d18d8668ce",
823+
echo "input_index": 3,
824+
echo "pox_addrs": [
825+
echo "0014db14133a9dbb1d0e16b60513453e48b6ff2847a9",
826+
echo "a91418c42080a1e87fd02dd3fca94c4513f9ecfe741487"
827+
echo ]
828+
echo }
829+
echo ]
830+
)
831+
"#;
832+
let path = "/tmp/test-get-unconfirmed-commits.bat";
833+
if fs::metadata(path).is_ok() {
834+
fs::remove_file(path).unwrap();
835+
}
836+
{
837+
let mut f = fs::File::create(path).unwrap();
838+
f.write_all(shell_code.as_bytes()).unwrap();
839+
}
840+
841+
let ms = MinerStats {
842+
unconfirmed_commits_helper: path.to_string(),
843+
};
844+
845+
let mut commits = ms.get_unconfirmed_commits(123, &[]).unwrap();
846+
assert_eq!(commits.len(), 1);
847+
let commit = commits.pop().unwrap();
848+
849+
assert_eq!(
850+
commit.txid,
851+
Txid::from_hex("73c318be8cd272a73200b9630089d77a44342d84b2c0d81c937da714152cf402")
852+
.unwrap()
853+
);
854+
assert_eq!(commit.burn_fee, 555000);
855+
assert_eq!(
856+
commit.apparent_sender.0,
857+
"1FCcoFSKWvNyhjazNvVdLLw8mGkGdcRMux".to_string()
858+
);
859+
assert_eq!(
860+
commit.input.0,
861+
Txid::from_hex("ef0dbf0fc4755de5e94843a4da7c1d943571299afb15f32b76bac5d18d8668ce")
862+
.unwrap()
863+
);
864+
assert_eq!(commit.input.1, 3);
865+
assert_eq!(commit.block_height, 123);
866+
867+
assert_eq!(
868+
commit.commit_outs,
869+
vec![
870+
PoxAddress::Addr20(
871+
true,
872+
PoxAddressType20::P2WPKH,
873+
[
874+
219, 20, 19, 58, 157, 187, 29, 14, 22, 182, 5, 19, 69, 62, 72, 182, 255,
875+
40, 71, 169
876+
]
877+
),
878+
PoxAddress::Standard(
879+
StacksAddress::new(
880+
20,
881+
Hash160([
882+
0x18, 0xc4, 0x20, 0x80, 0xa1, 0xe8, 0x7f, 0xd0, 0x2d, 0xd3, 0xfc, 0xa9,
883+
0x4c, 0x45, 0x13, 0xf9, 0xec, 0xfe, 0x74, 0x14
884+
])
885+
)
886+
.unwrap(),
887+
None
888+
)
889+
]
890+
);
891+
}
892+
811893
#[test]
812894
fn test_get_spend_and_win_distribution() {
813895
let active_miners_and_commits = vec![

stackslib/src/net/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2883,9 +2883,10 @@ pub mod test {
28832883
pub fn test_path(config: &TestPeerConfig) -> String {
28842884
let random = thread_rng().gen::<u64>();
28852885
let random_bytes = to_hex(&random.to_be_bytes());
2886+
let cleaned_config_test_name = config.test_name.replace("::", "_");
28862887
format!(
28872888
"/tmp/stacks-node-tests/units-test-peer/{}-{}",
2888-
&config.test_name, random_bytes
2889+
&cleaned_config_test_name, random_bytes
28892890
)
28902891
}
28912892

stackslib/src/net/tests/convergence.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,28 @@ use std::collections::{HashMap, HashSet};
2121
use clarity::vm::types::{QualifiedContractIdentifier, StandardPrincipalData};
2222
use rand::prelude::*;
2323
use rand::thread_rng;
24-
use rlimit;
2524

2625
use crate::core::PEER_VERSION_TESTNET;
2726
use crate::net::db::*;
2827
use crate::net::test::*;
2928
use crate::net::*;
3029
use crate::util_lib::test::*;
3130

31+
#[cfg(unix)]
3232
fn setup_rlimit_nofiles() {
33+
use rlimit;
3334
info!("Attempt to set nofile rlimit to 4096 (required for these tests to run)");
3435
assert!(rlimit::Resource::NOFILE.get().is_ok());
3536
let (slimit, hlimit) = rlimit::getrlimit(rlimit::Resource::NOFILE).unwrap();
3637
rlimit::setrlimit(rlimit::Resource::NOFILE, 4096.max(slimit), hlimit).unwrap();
3738
info!("Successfully set nofile rlimit to 4096");
3839
}
3940

41+
#[cfg(windows)]
42+
fn setup_rlimit_nofiles() {
43+
// rlimit empty stub, since windows hasn't a hard file descriptor limit
44+
}
45+
4046
fn stacker_db_id(i: usize) -> QualifiedContractIdentifier {
4147
QualifiedContractIdentifier::new(
4248
StandardPrincipalData::new(0x01, [i as u8; 20]).unwrap(),

0 commit comments

Comments
 (0)