Skip to content

Commit f122261

Browse files
committed
Mock cardano-cli now read epoch from file
1 parent a8fdf56 commit f122261

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

mithril-test-lab/mithril-end-to-end/script/mock-cardano-cli

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ main () {
2020
done
2121

2222
case $command_to_run in
23-
stake-snapshot) cat $STAKE_DISTRIBUTION_FILE ;;
24-
chain-tip) cat <<EOF
23+
stake-snapshot) cat $MOCK_STAKE_DISTRIBUTION_FILE ;;
24+
chain-tip) epoch=$(cat $MOCK_EPOCH_FILE)
25+
26+
cat <<EOF
2527
{
2628
"era": "Babbage",
2729
"syncProgress": "100.00",
2830
"hash": "f6d1b8c328697c7a4a8e7f718c79510acbcd411ff4ca19401ded13534d45a38d",
29-
"epoch": 1,
31+
"epoch": $epoch,
3032
"slot": 0,
3133
"block": 0
3234
}

mithril-test-lab/mithril-end-to-end/src/bin/load-aggregator/main.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
use std::{fs::File, path::PathBuf, sync::Arc, time::Duration};
1+
use std::{
2+
fs::File,
3+
io::Write,
4+
path::{Path, PathBuf},
5+
sync::Arc,
6+
time::Duration,
7+
};
28

39
use anyhow::Context;
410
use clap::Parser;
@@ -87,6 +93,24 @@ pub async fn wait_for_http_response(url: &str, timeout: Duration, message: &str)
8793
}
8894
}
8995

96+
pub fn write_stake_distribution(
97+
mock_stake_distribution_file_path: &Path,
98+
signers_fixture: &MithrilFixture,
99+
) {
100+
let mock_stake_distribution_file = File::create(mock_stake_distribution_file_path).unwrap();
101+
serde_json::to_writer(
102+
&mock_stake_distribution_file,
103+
&signers_fixture.cardano_cli_stake_distribution(),
104+
)
105+
.expect("Writing the stake distribution into a file for the mock cardano cli failed");
106+
}
107+
108+
pub fn write_epoch(mock_epoch_file_path: &Path, epoch: Epoch) {
109+
let mock_epoch_file = File::create(mock_epoch_file_path).unwrap();
110+
write!(&mock_epoch_file, "{}", *epoch)
111+
.expect("Writing the epoch into a file for the mock cardano cli failed");
112+
}
113+
90114
#[derive(Debug, Parser)]
91115
#[command(author, version, about, long_about = None)]
92116
pub struct MainOpts {
@@ -205,6 +229,7 @@ async fn main() -> StdResult<()> {
205229
let _logger = init_logger(&opts);
206230
let args = AggregatorParameters::new(&opts)?;
207231
let mock_stake_distribution_file_path = args.work_dir.join("stake_distribution.json");
232+
let mock_epoch_file_path = args.work_dir.join("epoch.txt");
208233
info!(">> Starting stress test with options: {opts:?}");
209234

210235
info!(">> Creation of the Signer Key Registrations payloads");
@@ -222,15 +247,12 @@ async fn main() -> StdResult<()> {
222247
)
223248
.unwrap();
224249

225-
let mock_stake_distribution_file = File::create(&mock_stake_distribution_file_path).unwrap();
226-
serde_json::to_writer(
227-
&mock_stake_distribution_file,
228-
&signers_fixture.cardano_cli_stake_distribution(),
229-
)
230-
.expect("Writing the stake distribution into a file for the mock cardano cli failed");
250+
write_epoch(&mock_epoch_file_path, Epoch(26));
251+
write_stake_distribution(&mock_stake_distribution_file_path, &signers_fixture);
231252

232253
aggregator.change_run_interval(Duration::from_secs(6));
233-
aggregator.set_mock_cardano_cli_stake_distribution_file(&mock_stake_distribution_file_path);
254+
aggregator
255+
.set_mock_cardano_cli_file_path(&mock_stake_distribution_file_path, &mock_epoch_file_path);
234256
aggregator.set_protocol_parameters(&ProtocolParameters::default());
235257
aggregator.serve().unwrap();
236258

mithril-test-lab/mithril-end-to-end/src/mithril/aggregator.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,17 @@ impl Aggregator {
124124
);
125125
}
126126

127-
pub fn set_mock_cardano_cli_stake_distribution_file(&mut self, file_path: &Path) {
127+
pub fn set_mock_cardano_cli_file_path(
128+
&mut self,
129+
stake_distribution_file: &Path,
130+
epoch_file_path: &Path,
131+
) {
132+
self.command.set_env_var(
133+
"MOCK_STAKE_DISTRIBUTION_FILE",
134+
stake_distribution_file.to_str().unwrap(),
135+
);
128136
self.command
129-
.set_env_var("STAKE_DISTRIBUTION_FILE", file_path.to_str().unwrap())
137+
.set_env_var("MOCK_EPOCH_FILE", epoch_file_path.to_str().unwrap());
130138
}
131139

132140
/// Change the run interval of the aggregator state machine (default: 400ms)

0 commit comments

Comments
 (0)