Skip to content

Commit 504bf1f

Browse files
committed
fix: matching both devnet4 and devnet5 sync fixtures
1 parent c3945ed commit 504bf1f

2 files changed

Lines changed: 43 additions & 16 deletions

File tree

testing/lean-spec-tests/src/sync.rs

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,35 @@ pub fn load_sync_test(path: impl AsRef<Path>) -> anyhow::Result<TestFixture<Sync
1919

2020
/// Run a single sync test case (currently the only operation is `verify_checkpoint`)
2121
pub fn run_sync_test(test_name: &str, test: &SyncTest) -> anyhow::Result<()> {
22-
info!(
23-
"Running sync test: {test_name} (operation={})",
24-
test.operation
25-
);
22+
// devnet4: operation is a plain string, params in output
23+
// devnet5: operation is an object with kind + params
24+
let (operation_kind, num_validators, expected_anchor_slot) =
25+
if let Some(kind) = test.operation.as_str() {
26+
let num_validators = test
27+
.output
28+
.validator_count
29+
.ok_or_else(|| anyhow!("devnet4 format requires output.validatorCount"))?;
30+
let anchor_slot = test
31+
.output
32+
.anchor_slot
33+
.ok_or_else(|| anyhow!("devnet4 format requires output.anchorSlot"))?;
34+
(kind.to_string(), num_validators, anchor_slot)
35+
} else {
36+
let kind = test.operation["kind"]
37+
.as_str()
38+
.ok_or_else(|| anyhow!("Missing operation.kind"))?
39+
.to_string();
40+
let num_validators = test.operation["numValidators"]
41+
.as_u64()
42+
.ok_or_else(|| anyhow!("Missing operation.numValidators"))?;
43+
let anchor_slot = test.operation["anchorSlot"].as_u64().unwrap_or(0);
44+
(kind, num_validators, anchor_slot)
45+
};
46+
47+
info!("Running sync test: {test_name} (operation={operation_kind})");
2648

27-
if test.operation != "verify_checkpoint" {
28-
bail!("Unknown sync operation: {}", test.operation);
49+
if operation_kind != "verify_checkpoint" {
50+
bail!("Unknown sync operation: {operation_kind}");
2951
}
3052

3153
let state_bytes = hex::decode(test.output.state_bytes.trim_start_matches("0x"))
@@ -39,14 +61,12 @@ pub fn run_sync_test(test_name: &str, test: &SyncTest) -> anyhow::Result<()> {
3961
let actually_valid = actual_validator_count > 0;
4062

4163
ensure!(
42-
actual_validator_count == test.output.validator_count,
43-
"validatorCount mismatch: expected {}, got {actual_validator_count}",
44-
test.output.validator_count,
64+
actual_validator_count == num_validators,
65+
"validatorCount mismatch: expected {num_validators}, got {actual_validator_count}",
4566
);
4667
ensure!(
47-
actual_slot == test.output.anchor_slot,
48-
"anchorSlot mismatch: expected {}, got {actual_slot}",
49-
test.output.anchor_slot,
68+
actual_slot == expected_anchor_slot,
69+
"anchorSlot mismatch: expected {expected_anchor_slot}, got {actual_slot}",
5070
);
5171
ensure!(
5272
actually_valid == test.output.valid,

testing/lean-spec-tests/src/types/sync.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ use serde::Deserialize;
44
#[serde(rename_all = "camelCase")]
55
pub struct SyncTest {
66
pub network: String,
7-
pub operation: String,
8-
pub input: SyncInput,
7+
/// devnet4: plain string; devnet5: object with `kind`, `numValidators`, `anchorSlot`
8+
pub operation: serde_json::Value,
9+
/// devnet4 only — params moved into `operation` in devnet5
10+
#[serde(default)]
11+
pub input: Option<SyncInput>,
912
pub output: SyncOutput,
1013
}
1114

@@ -22,6 +25,10 @@ pub struct SyncInput {
2225
pub struct SyncOutput {
2326
pub valid: bool,
2427
pub state_bytes: String,
25-
pub validator_count: u64,
26-
pub anchor_slot: u64,
28+
/// devnet4 only — in devnet5 this lives in `operation`
29+
#[serde(default)]
30+
pub validator_count: Option<u64>,
31+
/// devnet4 only — in devnet5 this lives in `operation`
32+
#[serde(default)]
33+
pub anchor_slot: Option<u64>,
2734
}

0 commit comments

Comments
 (0)