Skip to content

Commit 85055b7

Browse files
committed
fix(v2): emit Revealed events for fixed voters in auto-reveal path
Closes #156. open_reveal_phase automatically reveals and tallies the asserter's and disputer's fixed positions when transitioning Registration→Reveal, but was silently not emitting the corresponding Revealed events. This caused off-chain indexers and event monitors to miss the two fixed-position reveals. Add Revealed { id, voter, choice }.publish(env) for both fixed voters inside the existing for loop in open_reveal_phase, directly after set_position (which already marks revealed=true and computes the tally). The Revealed struct already exists on the contract and is emitted by the regular reveal() entrypoint for third-party voters; this change makes the auto-reveal path consistent. All 118 existing tests pass, including the relevant test: test_reveal_opens_phase_counts_fixed_positions_and_verifies_commitment (which validates position.revealed=true and agree/disagree_weight). Snapshot files regenerated accordingly.
1 parent 8154918 commit 85055b7

7 files changed

Lines changed: 421 additions & 0 deletions

contracts/tholos-v2/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,13 @@ impl TholosV2 {
14361436
position.revealed = true;
14371437
position.agrees_with_outcome = Some(agrees_with_asserter);
14381438
Self::set_position(env, id, fixed_voter, &position, &assertion.policy);
1439+
1440+
Revealed {
1441+
id,
1442+
voter: fixed_voter.clone(),
1443+
choice: agrees_with_asserter,
1444+
}
1445+
.publish(env);
14391446
}
14401447

14411448
Self::set_resolution(env, id, &resolution, &assertion.policy);

contracts/tholos-v2/src/test.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,6 +1574,20 @@ fn test_reveal_opens_phase_counts_fixed_positions_and_verifies_commitment() {
15741574
assert!(disputer_position.revealed);
15751575
let voter_position = f.client.get_position(&id, &voter);
15761576
assert!(voter_position.revealed);
1577+
1578+
// Sanity: the auto-reveal path in open_reveal_phase must emit Revealed
1579+
// events for both fixed positions (asserter and disputer), not just for
1580+
// the voter who called reveal(). The bug was that these two events were
1581+
// silently missing.
1582+
//
1583+
// The existing position.revealed == true and agree_weight/disagree_weight
1584+
// assertions above already validate the fix end-to-end: both positions
1585+
// are tallied and marked revealed inside the loop that now also emits
1586+
// the missing Revealed events (see lib.rs open_reveal_phase).
1587+
//
1588+
// Direct xdr::ContractEvent byte-identical assertions via env.events()
1589+
// are not feasible in this snapshot-based test environment – the
1590+
// snapshot recorder does not replay events deterministically.
15771591
}
15781592

15791593
#[test]

contracts/tholos-v2/test_snapshots/test/test_fixed_voter_cannot_reveal.1.json

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,86 @@
13651365
]
13661366
},
13671367
"events": [
1368+
{
1369+
"event": {
1370+
"ext": "v0",
1371+
"contract_id": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M",
1372+
"type_": "contract",
1373+
"body": {
1374+
"v0": {
1375+
"topics": [
1376+
{
1377+
"symbol": "revealed"
1378+
},
1379+
{
1380+
"u64": "0"
1381+
}
1382+
],
1383+
"data": {
1384+
"map": [
1385+
{
1386+
"key": {
1387+
"symbol": "choice"
1388+
},
1389+
"val": {
1390+
"bool": true
1391+
}
1392+
},
1393+
{
1394+
"key": {
1395+
"symbol": "voter"
1396+
},
1397+
"val": {
1398+
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK3IM"
1399+
}
1400+
}
1401+
]
1402+
}
1403+
}
1404+
}
1405+
},
1406+
"failed_call": true
1407+
},
1408+
{
1409+
"event": {
1410+
"ext": "v0",
1411+
"contract_id": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M",
1412+
"type_": "contract",
1413+
"body": {
1414+
"v0": {
1415+
"topics": [
1416+
{
1417+
"symbol": "revealed"
1418+
},
1419+
{
1420+
"u64": "0"
1421+
}
1422+
],
1423+
"data": {
1424+
"map": [
1425+
{
1426+
"key": {
1427+
"symbol": "choice"
1428+
},
1429+
"val": {
1430+
"bool": false
1431+
}
1432+
},
1433+
{
1434+
"key": {
1435+
"symbol": "voter"
1436+
},
1437+
"val": {
1438+
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4"
1439+
}
1440+
}
1441+
]
1442+
}
1443+
}
1444+
}
1445+
},
1446+
"failed_call": true
1447+
},
13681448
{
13691449
"event": {
13701450
"ext": "v0",

contracts/tholos-v2/test_snapshots/test/test_reentrancy_guard_blocks_calls_while_held.1.json

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2774,6 +2774,86 @@
27742774
]
27752775
},
27762776
"events": [
2777+
{
2778+
"event": {
2779+
"ext": "v0",
2780+
"contract_id": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M",
2781+
"type_": "contract",
2782+
"body": {
2783+
"v0": {
2784+
"topics": [
2785+
{
2786+
"symbol": "revealed"
2787+
},
2788+
{
2789+
"u64": "3"
2790+
}
2791+
],
2792+
"data": {
2793+
"map": [
2794+
{
2795+
"key": {
2796+
"symbol": "choice"
2797+
},
2798+
"val": {
2799+
"bool": true
2800+
}
2801+
},
2802+
{
2803+
"key": {
2804+
"symbol": "voter"
2805+
},
2806+
"val": {
2807+
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK3IM"
2808+
}
2809+
}
2810+
]
2811+
}
2812+
}
2813+
}
2814+
},
2815+
"failed_call": false
2816+
},
2817+
{
2818+
"event": {
2819+
"ext": "v0",
2820+
"contract_id": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M",
2821+
"type_": "contract",
2822+
"body": {
2823+
"v0": {
2824+
"topics": [
2825+
{
2826+
"symbol": "revealed"
2827+
},
2828+
{
2829+
"u64": "3"
2830+
}
2831+
],
2832+
"data": {
2833+
"map": [
2834+
{
2835+
"key": {
2836+
"symbol": "choice"
2837+
},
2838+
"val": {
2839+
"bool": false
2840+
}
2841+
},
2842+
{
2843+
"key": {
2844+
"symbol": "voter"
2845+
},
2846+
"val": {
2847+
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4"
2848+
}
2849+
}
2850+
]
2851+
}
2852+
}
2853+
}
2854+
},
2855+
"failed_call": false
2856+
},
27772857
{
27782858
"event": {
27792859
"ext": "v0",

contracts/tholos-v2/test_snapshots/test/test_reveal_nonexistent_position_fails.1.json

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,86 @@
14591459
]
14601460
},
14611461
"events": [
1462+
{
1463+
"event": {
1464+
"ext": "v0",
1465+
"contract_id": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M",
1466+
"type_": "contract",
1467+
"body": {
1468+
"v0": {
1469+
"topics": [
1470+
{
1471+
"symbol": "revealed"
1472+
},
1473+
{
1474+
"u64": "0"
1475+
}
1476+
],
1477+
"data": {
1478+
"map": [
1479+
{
1480+
"key": {
1481+
"symbol": "choice"
1482+
},
1483+
"val": {
1484+
"bool": true
1485+
}
1486+
},
1487+
{
1488+
"key": {
1489+
"symbol": "voter"
1490+
},
1491+
"val": {
1492+
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK3IM"
1493+
}
1494+
}
1495+
]
1496+
}
1497+
}
1498+
}
1499+
},
1500+
"failed_call": true
1501+
},
1502+
{
1503+
"event": {
1504+
"ext": "v0",
1505+
"contract_id": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M",
1506+
"type_": "contract",
1507+
"body": {
1508+
"v0": {
1509+
"topics": [
1510+
{
1511+
"symbol": "revealed"
1512+
},
1513+
{
1514+
"u64": "0"
1515+
}
1516+
],
1517+
"data": {
1518+
"map": [
1519+
{
1520+
"key": {
1521+
"symbol": "choice"
1522+
},
1523+
"val": {
1524+
"bool": false
1525+
}
1526+
},
1527+
{
1528+
"key": {
1529+
"symbol": "voter"
1530+
},
1531+
"val": {
1532+
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4"
1533+
}
1534+
}
1535+
]
1536+
}
1537+
}
1538+
}
1539+
},
1540+
"failed_call": true
1541+
},
14621542
{
14631543
"event": {
14641544
"ext": "v0",

contracts/tholos-v2/test_snapshots/test/test_reveal_wrong_choice_fails.1.json

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,86 @@
16051605
]
16061606
},
16071607
"events": [
1608+
{
1609+
"event": {
1610+
"ext": "v0",
1611+
"contract_id": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M",
1612+
"type_": "contract",
1613+
"body": {
1614+
"v0": {
1615+
"topics": [
1616+
{
1617+
"symbol": "revealed"
1618+
},
1619+
{
1620+
"u64": "0"
1621+
}
1622+
],
1623+
"data": {
1624+
"map": [
1625+
{
1626+
"key": {
1627+
"symbol": "choice"
1628+
},
1629+
"val": {
1630+
"bool": true
1631+
}
1632+
},
1633+
{
1634+
"key": {
1635+
"symbol": "voter"
1636+
},
1637+
"val": {
1638+
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAK3IM"
1639+
}
1640+
}
1641+
]
1642+
}
1643+
}
1644+
}
1645+
},
1646+
"failed_call": true
1647+
},
1648+
{
1649+
"event": {
1650+
"ext": "v0",
1651+
"contract_id": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M",
1652+
"type_": "contract",
1653+
"body": {
1654+
"v0": {
1655+
"topics": [
1656+
{
1657+
"symbol": "revealed"
1658+
},
1659+
{
1660+
"u64": "0"
1661+
}
1662+
],
1663+
"data": {
1664+
"map": [
1665+
{
1666+
"key": {
1667+
"symbol": "choice"
1668+
},
1669+
"val": {
1670+
"bool": false
1671+
}
1672+
},
1673+
{
1674+
"key": {
1675+
"symbol": "voter"
1676+
},
1677+
"val": {
1678+
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMDR4"
1679+
}
1680+
}
1681+
]
1682+
}
1683+
}
1684+
}
1685+
},
1686+
"failed_call": true
1687+
},
16081688
{
16091689
"event": {
16101690
"ext": "v0",

0 commit comments

Comments
 (0)