From a726d56b834c60e1e3c5a129942691089bf6beb2 Mon Sep 17 00:00:00 2001 From: ZacLou Date: Thu, 3 Sep 2026 08:22:37 +0800 Subject: [PATCH] fix(v2): emit Revealed events for fixed asserter/disputer positions in open_reveal_phase Closes #156 When open_reveal_phase auto-reveals the asserter and disputer fixed positions, publish a Revealed event for each so off-chain indexers can observe the revealed choice without requiring an explicit reveal() call. Adds a test assertion that exactly three Revealed events are emitted: asserter, disputer, and the external voter that called reveal(). --- contracts/tholos-v2/src/lib.rs | 7 +++++++ contracts/tholos-v2/src/test.rs | 21 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/contracts/tholos-v2/src/lib.rs b/contracts/tholos-v2/src/lib.rs index 9f2fccc..b9524fd 100644 --- a/contracts/tholos-v2/src/lib.rs +++ b/contracts/tholos-v2/src/lib.rs @@ -1354,6 +1354,13 @@ impl TholosV2 { position.revealed = true; position.agrees_with_outcome = Some(agrees_with_asserter); Self::set_position(env, id, fixed_voter, &position, &assertion.policy); + + Revealed { + id, + voter: fixed_voter.clone(), + choice: agrees_with_asserter, + } + .publish(env); } Self::set_resolution(env, id, &resolution, &assertion.policy); diff --git a/contracts/tholos-v2/src/test.rs b/contracts/tholos-v2/src/test.rs index 776ecd5..6b2b090 100644 --- a/contracts/tholos-v2/src/test.rs +++ b/contracts/tholos-v2/src/test.rs @@ -2,7 +2,8 @@ use super::*; use soroban_sdk::testutils::storage::Persistent as _; -use soroban_sdk::testutils::{Address as _, Ledger}; +use soroban_sdk::testutils::{Address as _, Events, Ledger}; +use soroban_sdk::xdr; const DEFAULT_BOND: i128 = 100; const DEFAULT_CHALLENGE_WINDOW: u64 = 3600; @@ -1444,6 +1445,24 @@ fn test_reveal_opens_phase_counts_fixed_positions_and_verifies_commitment() { f.advance_past_registration_deadline(id); f.client.reveal(&voter, &id, &true, &s); + // Auto-reveal of the asserter and disputer fixed positions must each emit + // a Revealed event, in addition to the explicit Revealed event from the + // external voter's reveal() call. + let contract_events = f.env.events().all(); + let all_events = contract_events.events(); + let mut revealed_count: u32 = 0; + for event in all_events.iter() { + let xdr::ContractEventBody::V0(event_data) = &event.body; + if event_data.topics.len() == 2 { + if let xdr::ScVal::Symbol(topic0) = &event_data.topics[0] { + if topic0.to_utf8_string().unwrap_or_default() == "revealed" { + revealed_count += 1; + } + } + } + } + assert_eq!(revealed_count, 3, "expected asserter, disputer, and voter Revealed events"); + let assertion = f.client.get_assertion(&id); assert_eq!(assertion.phase, PhaseV2::Reveal);