mod common;
use wickra_proof_core::{canonicalize, prove, ProofSpec};
#[test]
fn proof_spec_json_round_trips() {
let spec = common::sample_spec();
let json = serde_json::to_string(&spec).unwrap();
let back = ProofSpec::from_json(&json).unwrap();
assert_eq!(spec, back);
}
#[test]
fn proof_spec_toml_round_trips() {
let toml = r#"
dataset_ref = "test/TEST/1h"
[strategy]
symbol = "TEST"
timeframe = "1h"
[strategy.indicators.ema_fast]
type = "Ema"
params = [3]
[strategy.indicators.ema_slow]
type = "Ema"
params = [8]
[strategy.entry]
cross_above = ["ema_fast", "ema_slow"]
[strategy.exit]
cross_below = ["ema_fast", "ema_slow"]
[strategy.sizing]
type = "fixed_fraction"
fraction = 0.95
[strategy.costs]
taker_bps = 5
[strategy.costs.slippage]
type = "fixed_bps"
bps = 2
[strategy.risk]
trailing_stop_pct = 5.0
"#;
let spec = ProofSpec::from_toml(toml).unwrap();
assert_eq!(spec.dataset_ref, "test/TEST/1h");
assert!(spec.strategy.is_object());
prove(&spec, &common::sample_data()).unwrap();
}
#[test]
fn proof_json_round_trips() {
let proof = prove(&common::sample_spec(), &common::sample_data()).unwrap();
let json = serde_json::to_string(&proof).unwrap();
let back: wickra_proof_core::Proof = serde_json::from_str(&json).unwrap();
assert_eq!(proof.report_hash, back.report_hash);
assert_eq!(proof.inputs_hash, back.inputs_hash);
assert_eq!(proof.engine_version, back.engine_version);
assert_eq!(
canonicalize(&proof.report).unwrap(),
canonicalize(&back.report).unwrap()
);
}
#[test]
fn strategy_must_be_an_object() {
assert!(ProofSpec::from_json(r#"{"strategy": 42, "dataset_ref": "x"}"#).is_err());
assert!(ProofSpec::from_json(r#"{"strategy": [1,2], "dataset_ref": "x"}"#).is_err());
}
#[test]
fn missing_field_is_rejected() {
assert!(ProofSpec::from_json(r#"{"strategy": {}}"#).is_err());
}