Skip to content

Commit 919d9c0

Browse files
gnd: trim verbose inline comments in test module
1 parent ed71d34 commit 919d9c0

8 files changed

Lines changed: 91 additions & 217 deletions

File tree

gnd/src/commands/test/assertion.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,10 @@ async fn run_single_assertion(
7777
}
7878
}
7979

80-
/// Reorder `actual` arrays to align with `expected`'s element ordering.
80+
/// Reorder `actual` arrays to match `expected`'s element order for cleaner diffs.
8181
///
82-
/// When a test fails, the raw diff can be misleading if array elements appear
83-
/// in a different order — every line shows as changed even if only one field
84-
/// differs. This function reorders `actual` so that elements are paired with
85-
/// their closest match in `expected`, producing a diff that highlights only
86-
/// real value differences.
82+
/// Without this, out-of-order elements show every field as changed even when
83+
/// only one field differs.
8784
pub(super) fn align_for_diff(
8885
expected: &serde_json::Value,
8986
actual: &serde_json::Value,
@@ -132,12 +129,8 @@ pub(super) fn align_for_diff(
132129
}
133130
}
134131

135-
/// Score how similar two JSON values are for use in [`align_for_diff`].
136-
///
137-
/// For objects, counts the number of fields whose values are equal in both.
138-
/// A matching `"id"` field is weighted heavily (+100) since it is the
139-
/// strongest signal that two objects represent the same entity.
140-
/// For all other value types, returns 1 if equal, 0 otherwise.
132+
/// Score JSON similarity for [`align_for_diff`].
133+
/// Objects: matching `"id"` = 100, other equal fields = 1. Non-objects: 0 or 1.
141134
fn json_similarity(a: &serde_json::Value, b: &serde_json::Value) -> usize {
142135
match (a, b) {
143136
(serde_json::Value::Object(a_obj), serde_json::Value::Object(b_obj)) => {
@@ -162,13 +155,9 @@ fn json_similarity(a: &serde_json::Value, b: &serde_json::Value) -> usize {
162155
}
163156
}
164157

165-
/// Compare two JSON values for equality (ignoring key ordering in objects).
158+
/// Compare JSON values for equality, ignoring object key ordering.
166159
///
167-
/// Also handles string-vs-number coercion: GraphQL returns `BigInt` and
168-
/// `BigDecimal` fields as JSON strings (e.g., `"1000000000000000000"`),
169-
/// but test authors may write them as JSON numbers. This function treats
170-
/// `String("123")` and `Number(123)` as equal when they represent the
171-
/// same value.
160+
/// Coerces string/number: `"123"` == `123` to handle GraphQL `BigInt`/`BigDecimal`.
172161
fn json_equal(a: &serde_json::Value, b: &serde_json::Value) -> bool {
173162
match (a, b) {
174163
(serde_json::Value::Null, serde_json::Value::Null) => true,

gnd/src/commands/test/block_stream.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,15 @@ impl BlockStreamBuilder<Chain> for StaticStreamBuilder {
6363
}
6464
}
6565

66-
/// A `Stream` that synchronously yields pre-defined blocks one at a time.
67-
///
68-
/// Each `poll_next` call returns the next block immediately (no async waiting).
69-
/// When all blocks have been emitted, returns `None` to signal stream completion,
70-
/// which tells the indexer that sync is done.
66+
/// A `Stream` that yields pre-defined blocks synchronously.
67+
/// Returns `None` when all blocks are emitted, signaling sync completion.
7168
struct StaticStream {
7269
blocks: Vec<BlockWithTriggers<Chain>>,
7370
current_idx: usize,
7471
}
7572

7673
impl StaticStream {
77-
/// Create a new stream, optionally skipping past already-processed blocks.
78-
///
79-
/// `skip_to`: If `Some(i)`, start from block `i+1` (block `i` was already processed).
80-
/// If `None`, start from the beginning.
74+
/// `skip_to`: if `Some(i)`, start from block `i+1` (block `i` already processed).
8175
fn new(blocks: Vec<BlockWithTriggers<Chain>>, skip_to: Option<usize>) -> Self {
8276
Self {
8377
blocks,

gnd/src/commands/test/eth_calls.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
//! Pre-populates the eth_call cache with mock responses for `gnd test`.
1+
//! Populates the eth_call cache with mock responses for `gnd test`.
22
//!
3-
//! Function signatures use graph-node's convention: `name(inputs):(outputs)`
4-
//! e.g. `"balanceOf(address):(uint256)"`, `"getReserves():(uint112,uint112,uint32)"`.
5-
//! Call data is encoded using the same path as production graph-node, so cache
6-
//! IDs match exactly what the runtime generates.
3+
//! Signatures use graph-node's `name(inputs):(outputs)` convention.
4+
//! Encoding matches production graph-node so cache IDs align with the runtime.
75
86
use super::schema::{MockEthCall, TestFile};
97
use super::trigger::json_to_sol_value;
@@ -92,16 +90,8 @@ fn encode_return_value(function_sig: &str, returns: &[serde_json::Value]) -> Res
9290
.map_err(|e| anyhow!("Failed to encode return value: {}", e))
9391
}
9492

95-
/// Convert a graph-node style function signature to alloy's expected format.
96-
///
97-
/// Graph-node uses `name(inputs):(outputs)` while alloy expects
98-
/// `name(inputs) returns (outputs)`.
99-
///
100-
/// Examples:
101-
/// - `"balanceOf(address):(uint256)"` → `"balanceOf(address) returns (uint256)"`
102-
/// - `"name():(string)"` → `"name() returns (string)"`
103-
/// - `"transfer(address,uint256)"` → `"transfer(address,uint256)"` (no change)
104-
/// - `"balanceOf(address) returns (uint256)"` → unchanged (already alloy format)
93+
/// Convert graph-node `name(inputs):(outputs)` to alloy `name(inputs) returns (outputs)`.
94+
/// Passes through signatures already in alloy format or without outputs.
10595
fn to_alloy_signature(sig: &str) -> String {
10696
// If it already contains "returns", assume alloy format.
10797
if sig.contains(" returns ") {

gnd/src/commands/test/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ pub async fn run_test(opt: TestOpt) -> Result<()> {
112112
return matchstick::run(&opt).await;
113113
}
114114

115-
// Build the subgraph first so the WASM and schema are available in build/.
116-
// This mirrors what a user would do manually before running tests.
115+
// Build the subgraph first (WASM and schema must be available in build/).
117116
if !opt.skip_build {
118117
step(Step::Generate, "Building subgraph");
119118
let build_opt = crate::commands::BuildOpt {

gnd/src/commands/test/noop.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
//! Noop/stub trait implementations for the mock `Chain`.
1+
//! Noop trait implementations for the mock `Chain`.
22
//!
3-
//! These types satisfy the trait bounds required by the `Chain` constructor
4-
//! but are never called during normal test execution because:
5-
//! - Triggers are provided directly via `StaticStreamBuilder` (no scanning needed)
6-
//! - The real `EthereumRuntimeAdapterBuilder` is used for host functions
7-
//! (ethereum.call, ethereum.getBalance, ethereum.hasCode), backed by the call cache
3+
//! Satisfy `Chain` constructor bounds but are never called:
4+
//! - Triggers come from `StaticStreamBuilder` (no scanning)
5+
//! - Host functions use `EthereumRuntimeAdapterBuilder` with the eth_call cache
86
97
use async_trait::async_trait;
108
use graph::blockchain::block_stream::{BlockRefetcher, BlockWithTriggers, FirehoseCursor};

0 commit comments

Comments
 (0)