Skip to content

Commit 17fd6a1

Browse files
committed
feat: allow rpcsnaps with failing cases
1 parent 4341111 commit 17fd6a1

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/tool/subcommands/api_cmd.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ use std::{
3131
};
3232
use test_snapshot::RpcTestSnapshot;
3333

34+
#[derive(Debug, Copy, Clone, PartialEq, ValueEnum)]
35+
pub enum NodeType {
36+
Forest,
37+
Lotus,
38+
}
39+
3440
#[derive(Debug, Subcommand)]
3541
#[allow(clippy::large_enum_variant)]
3642
pub enum ApiCommands {
@@ -130,9 +136,11 @@ pub enum ApiCommands {
130136
/// Folder into which test snapshots are dumped
131137
out_dir: PathBuf,
132138
/// Allow generating snapshot even if Lotus generated a different response. This is useful
133-
/// when the response is not deterministic.
139+
/// when the response is not deterministic or a failing test is expected.
140+
/// If generating a failing test, use `Lotus` as the argument to ensure the test passes
141+
/// only when the response from Forest is fixed and matches the response from Lotus.
134142
#[arg(long)]
135-
allow_response_mismatch: bool,
143+
use_response_from: Option<NodeType>,
136144
},
137145
DumpTests {
138146
#[command(flatten)]
@@ -220,7 +228,7 @@ impl ApiCommands {
220228
db,
221229
chain,
222230
out_dir,
223-
allow_response_mismatch,
231+
use_response_from,
224232
} => {
225233
std::env::set_var("FOREST_TIPSET_CACHE_DISABLED", "1");
226234
if !out_dir.is_dir() {
@@ -239,6 +247,7 @@ impl ApiCommands {
239247
.with_extension("rpcsnap.json");
240248
let test_dump = serde_json::from_reader(std::fs::File::open(&test_dump_file)?)?;
241249
print!("Generating RPC snapshot at {} ...", out_path.display());
250+
let allow_response_mismatch = use_response_from.is_some();
242251
match generate_test_snapshot::run_test_with_dump(
243252
&test_dump,
244253
tracking_db.clone(),
@@ -258,7 +267,10 @@ impl ApiCommands {
258267
chain: chain.clone(),
259268
name: test_dump.request.method_name.to_string(),
260269
params: test_dump.request.params,
261-
response: test_dump.forest_response,
270+
response: match use_response_from {
271+
Some(NodeType::Forest) | None => test_dump.forest_response,
272+
Some(NodeType::Lotus) => test_dump.lotus_response,
273+
},
262274
index,
263275
db,
264276
}

0 commit comments

Comments
 (0)