Skip to content

refactor(ethflow-watcher): port to Host trait + MockHost tests (BLEU-855)#25

Open
brunota20 wants to merge 1 commit into
feat/twap-monitor-host-trait-bleu-854from
feat/ethflow-watcher-host-trait-bleu-855
Open

refactor(ethflow-watcher): port to Host trait + MockHost tests (BLEU-855)#25
brunota20 wants to merge 1 commit into
feat/twap-monitor-host-trait-bleu-854from
feat/ethflow-watcher-host-trait-bleu-855

Conversation

@brunota20

Copy link
Copy Markdown
Collaborator

Summary

Mirror of #24 (twap-monitor / BLEU-854) for the second M2 module. Closes the parallel gap on ethflow-watcher: `submit_placement` and the `submitted:` / `dropped:` / `backoff:` bookkeeping were calling `local_store::*` + `cow_api::submit_order` directly, so the dispatch + idempotency state machine introduced by PR #10 / commit c5e4d7d was not unit-tested.

  • `strategy.rs` (new) - pure logic against `shepherd_sdk::host::Host`. `LogView<'a>` keeps the strategy wit-independent; `on_logs` is the entry point.
  • `lib.rs` (rewritten, 427 -> 157 lines) - wit-bindgen `generate!`, `WitBindgenHost` adapter, `Guest` impl that destructures `types::Event::Logs` into `LogView`s and delegates to `strategy::on_logs`.

Tests

Status Test
Preserved 7 pure tests (decoders, EIP-1271 build, PreSign build, unsupported chain, unknown marker, non-empty app_data)
New (MockHost) `placement_log_submits_order_and_persists_submitted_uid`
New (MockHost) `redelivered_placement_is_skipped_via_submitted_uid_dedup` (PR #10 / commit c5e4d7d regression guard)
New (MockHost) `submit_transient_error_writes_backoff_marker_and_returns`
New (MockHost) `submit_permanent_error_persists_dropped_uid_and_clears_backoff`
New (MockHost) `eip1271_signature_shape_round_trips_through_submit_body` (decodes the JSON body MockCowApi received and asserts `signingScheme=eip1271`, signature blob verbatim, `from` = EthFlow contract)

Total: 12 tests (was 7).

Numbers

`.wasm` (release wasm32-wasip2) 281,518 bytes
Em-dashes added 0

Linear: BLEU-855.

Closes the M2 QA loop opened in the post-M3 audit. With #24 + this PR landed, the four host-trait modules (price-alert, stop-loss, twap-monitor, ethflow-watcher) all share the same `strategy.rs` + `lib.rs` shape - so M4 hardening (BLEU-842 supervisor restart, BLEU-845 poison pill) can MockHost-test the dispatch matrix in isolation.

Test plan

  • `cargo test -p ethflow-watcher` -> 12 passing.
  • `cargo clippy --all-targets --workspace -- -D warnings` clean.
  • `cargo build --target wasm32-wasip2 --release -p ethflow-watcher` clean.
  • `grep -rn '—' modules/ethflow-watcher/` -> 0 matches.

…855)

Same shape as BLEU-854 (twap-monitor / PR #24). Closes the M2-side
gap on ethflow-watcher.

Before: `submit_placement`, `prior_outcome`, `apply_submit_retry`,
and the `submitted:` / `dropped:` / `backoff:` bookkeeping called
`local_store::*` and `cow_api::submit_order` directly, with all the
state-machine bits unverified in unit (only 7 decoder / encoder
tests).

After:

1. `strategy.rs` (new) - pure logic against
   `shepherd_sdk::host::Host`. `LogView<'a>` keeps the strategy wit-
   independent; `on_logs` is the entry point.

2. `lib.rs` (rewritten, 427 -> 157 lines) - wit-bindgen `generate!`,
   `WitBindgenHost` adapter, `Guest` impl that destructures
   `types::Event::Logs` into `LogView`s and delegates to
   `strategy::on_logs`.

3. Tests against `shepherd_sdk_test::MockHost` (5 new) cover the
   dispatch + idempotency matrix:

     - `placement_log_submits_order_and_persists_submitted_uid`
     - `redelivered_placement_is_skipped_via_submitted_uid_dedup`
       (PR #10 / commit c5e4d7d regression guard)
     - `submit_transient_error_writes_backoff_marker_and_returns`
     - `submit_permanent_error_persists_dropped_uid_and_clears_backoff`
     - `eip1271_signature_shape_round_trips_through_submit_body`
       (decodes the JSON body MockCowApi received and asserts
       `signingScheme=eip1271`, signature blob verbatim, `from` =
       EthFlow contract)

4. All 7 original pure tests preserved unchanged. Total: 12 tests
   (was 7).

Numbers:

- `.wasm` 281,518 bytes (release wasm32-wasip2).
- 12 tests passing; clippy clean on host + wasm32-wasip2.
- 0 em-dashes in the module tree.

Stacks on PR #24 (BLEU-854) so reviewers can compare both M2
strategy / lib.rs splits in one stack with the M3 examples.
@linear-code

linear-code Bot commented Jun 17, 2026

Copy link
Copy Markdown

BLEU-855

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant