Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/indexer-fixture-coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Returns canonical v2 topics in stable order:
4. `rv_rej` (period `period_id`)
5. `rv_rep` (period `period_id`)
6. `claim` (period `0`)
7. `rg_lim_d` (period `0`)

All fixtures are versioned with `version = 2`.

Expand Down
685 changes: 580 additions & 105 deletions src/lib.rs

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/merkle_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@

#![allow(dead_code)]

use soroban_sdk::{contracterror, xdr::ToXdr, Address, Bytes, BytesN, Env, Vec};
use soroban_sdk::{contracterror, contracttype, xdr::ToXdr, Address, Bytes, BytesN, Env, Vec};

// ── Depth bound ─────────────────────────────────────────────────────────────

Expand Down Expand Up @@ -141,6 +141,8 @@ pub enum MerkleError {
/// Produced by [`canonical_leaves`] and consumed by [`build_merkle_root`].
/// The fields are intentionally `pub` so external code can inspect the ordering.
#[derive(Clone, Debug)]
#[contracttype]
#[derive(Clone)]
pub struct MerkleLeaf {
/// The holder address.
pub holder: Address,
Expand Down
28 changes: 17 additions & 11 deletions src/milestone_signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,9 @@ fn milestone_indexed_v2_topic_emitted_on_report_revenue() {
client.report_revenue(&issuer, &ns, &token, &payout, &1_000i128, &42u64, &false);

// The fixture helper returns canonical v2 topics — verify rv_rep shape
let fixtures = client.get_indexer_fixture_topics(&issuer, &ns, &token, &42u64);
let (v2_fixtures, _) = client.get_indexer_fixture_topics(&issuer, &ns, &token, &42u64);
let mut rv_rep_opt = None;
for f in fixtures.iter() {
for f in v2_fixtures.iter() {
if f.event_type == symbol_short!("rv_rep") {
rv_rep_opt = Some(f);
break;
Expand All @@ -415,20 +415,21 @@ fn milestone_fixture_covers_all_canonical_event_types() {
let token = Address::generate(&env);
let ns = symbol_short!("def");

let fixtures = client.get_indexer_fixture_topics(&issuer, &ns, &token, &1u64);
assert_eq!(fixtures.len(), 6u32);
let (v2_fixtures, _) = client.get_indexer_fixture_topics(&issuer, &ns, &token, &1u64);
assert!(v2_fixtures.len() >= 16, "fixture count must be at least 16 (including rg_lim_d)");

// Check all expected event types are present
// Check all expected event types are present (core 6 + new rg_lim_d)
let expected = [
symbol_short!("offer"),
symbol_short!("rv_init"),
symbol_short!("rv_ovr"),
symbol_short!("rv_rej"),
symbol_short!("rv_rep"),
symbol_short!("claim"),
symbol_short!("rg_lim_d"),
];
for expected_type in expected.iter() {
let found = fixtures.iter().any(|f| f.event_type == *expected_type);
let found = v2_fixtures.iter().any(|f| f.event_type == *expected_type);
assert!(found, "fixture must contain event_type");
}
}
Expand All @@ -443,12 +444,17 @@ fn milestone_non_period_scoped_fixtures_have_zero_period_id() {
let token = Address::generate(&env);
let ns = symbol_short!("def");

let fixtures = client.get_indexer_fixture_topics(&issuer, &ns, &token, &99u64);
for f in fixtures.iter() {
if f.event_type == symbol_short!("offer") || f.event_type == symbol_short!("claim") {
assert_eq!(f.period_id, 0u64, "non-period-scoped event must have period_id = 0");
} else {
let (v2_fixtures, _) = client.get_indexer_fixture_topics(&issuer, &ns, &token, &99u64);
for f in v2_fixtures.iter() {
// Only revenue event types are period-scoped
if f.event_type == symbol_short!("rv_init")
|| f.event_type == symbol_short!("rv_ovr")
|| f.event_type == symbol_short!("rv_rej")
|| f.event_type == symbol_short!("rv_rep")
{
assert_eq!(f.period_id, 99u64, "period-scoped event must carry the requested period_id");
} else {
assert_eq!(f.period_id, 0u64, "non-period-scoped event must have period_id = 0");
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/test_indexer_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ fn fixture_topics_have_stable_order_and_shape() {
let ns = symbol_short!("def");

let (v2_fixtures, v3_fixtures) = client.get_indexer_fixture_topics(&issuer, &ns, &token, &7u64);
assert_eq!(v2_fixtures.len(), 15);
assert_eq!(v3_fixtures.len(), 15);
assert_eq!(v2_fixtures.len(), 16);
assert_eq!(v3_fixtures.len(), 16);

let f0 = v2_fixtures.get(0).unwrap();
assert_eq!(f0.version, 2);
Expand Down Expand Up @@ -91,7 +91,11 @@ fn fixture_topics_have_stable_order_and_shape() {
let f14 = v2_fixtures.get(14).unwrap();
assert_eq!(f14.event_type, symbol_short!("ms_init"));

for i in 0..15 {
let f15 = v2_fixtures.get(15).unwrap();
assert_eq!(f15.event_type, symbol_short!("rg_lim_d"));
assert_eq!(f15.period_id, 0);

for i in 0..16 {
let v3 = v3_fixtures.get(i).unwrap();
assert_eq!(v3.version, 3);
assert_eq!(v3.event_type, v2_fixtures.get(i).unwrap().event_type);
Expand Down
Loading
Loading