Skip to content

feat(functional-tests): add OL mock deposit+withdrawal test (STR-2020)#1377

Open
voidash wants to merge 11 commits intomainfrom
STR-2020-mock-withdrawal-tx-functional-test
Open

feat(functional-tests): add OL mock deposit+withdrawal test (STR-2020)#1377
voidash wants to merge 11 commits intomainfrom
STR-2020-mock-withdrawal-tx-functional-test

Conversation

@voidash
Copy link
Contributor

@voidash voidash commented Feb 18, 2026

Description

Add an end-to-end functional test that verifies deposit and withdrawal flows through the OL without a real EE, using the debug subprotocol to inject mock deposits via Bitcoin transactions.

What this PR does

Rust changes:

  • Add debug-asm feature flag that conditionally switches ASM worker from StrataAsmSpec to DebugAsmSpec, enabling the debug subprotocol (ID 255)
  • Add create-mock-deposit CLI command to strata-test-cli — builds a Bitcoin tx with SPS-50 tagged OP_RETURN that injects DepositIntentLogData via the debug subprotocol's MockAsmLog mechanism
  • Add build-snark-withdrawal CLI command — constructs RpcOLTransaction JSON with SSZ-encoded SnarkAccountUpdate containing a withdrawal OutputMessage

Python test framework changes:

  • Add OLIsolatedEnvConfig — starts Bitcoin + Strata (OL only, no EE) with configurable genesis snark accounts
  • Add common/test_cli.py — subprocess wrapper for strata-test-cli commands
  • Add EpochSealingConfig support (slots_per_epoch=5 for fast terminal blocks in tests)
  • Fetch real GenesisL1View from bitcoind (target, timestamps) instead of hardcoded values

Test flow (test_mock_withdrawal):

  1. Start bitcoind (regtest) + strata sequencer with a genesis snark account
  2. Inject 20 BTC deposit via create-mock-deposit (debug subprotocol)
  3. Mine Bitcoin blocks, wait for OL terminal block to process L1 manifest
  4. Assert balance == 20 BTC
  5. Submit 1 BTC withdrawal via build-snark-withdrawal + strata_submitTransaction
  6. Assert balance == 19 BTC

Type of Change

  • New feature/Enhancement (non-breaking change which adds functionality or enhances an existing one)
  • New or updated tests

Notes to Reviewers

The debug-asm feature is only enabled during functional tests (run_tests.sh passes -F debug-asm). Production builds are unaffected.

The two new strata-test-cli commands replace previous Python encoding utilities (SSZ, strata-codec) with authoritative Rust implementations, eliminating encoding parity bugs.

Is this PR addressing any specification, design doc or external reference document?

  • Yes

STR-2020

Checklist

  • I have performed a self-review of my code.
  • I have commented my code where necessary.
  • I have updated the documentation if needed.
  • My changes do not introduce new warnings.
  • I have added (where necessary) tests that prove my changes are effective or that my feature works.
  • New and existing tests pass with my changes.
  • I have disclosed my use of AI in the body of this PR.

AI Assistance Notice

AI was used to assist with code review, test hardening fixes, and writing this PR description.

Related Issues

STR-2020

@voidash voidash marked this pull request as ready for review February 24, 2026 08:17
@voidash voidash requested review from a team as code owners February 24, 2026 08:17
@voidash voidash changed the title Str 2020 mock withdrawal tx functional test feat(functional-tests): add OL mock deposit+withdrawal test (STR-2020) Feb 24, 2026
@voidash voidash force-pushed the STR-2020-mock-withdrawal-tx-functional-test branch from 0e9d30d to 3384e39 Compare February 24, 2026 08:55
@github-actions
Copy link
Contributor

github-actions bot commented Feb 24, 2026

Commit: ce401ff

SP1 Execution Results

program cycles success
EVM EE STF 1,320,889
Checkpoint 5,226
Checkpoint New 883,619

delbonis
delbonis previously approved these changes Feb 24, 2026
Copy link
Contributor

@bewakes bewakes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work on tests and utils!
A small concern on the requirement of new ol_isolated environment.

@irnb irnb self-requested a review March 3, 2026 07:17
strata.wait_for_additional_blocks(2, rpc, timeout_per_block=15)

# Step 8: Verify final balance
final_balance = get_account_balance(rpc, account_id_hex)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test should be failing.

Ref:
#1383 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the test passes because the mock intentionally bypasses bridge-v1 because of Debug subprotocol but i agree the type ID mismatch between DepositLog and DepositIntentLogData needs to be resolved. and I think that's a separate issue from the test itself.

If OL should match on DEPOSIT_LOG_TYPE_ID and process DepositLog, then we can rewrite this test to match the canonical type we end up choosing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh no! yeah we should resolve this, maybe in this PR? both sides should use the same basic type instead of having two separate defs of it

@voidash voidash requested a review from a team as a code owner March 3, 2026 08:53
@voidash voidash force-pushed the STR-2020-mock-withdrawal-tx-functional-test branch 2 times, most recently from 27da6c9 to bee19e7 Compare March 3, 2026 12:33
@codecov
Copy link

codecov bot commented Mar 3, 2026

Codecov Report

❌ Patch coverage is 64.41718% with 116 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.97%. Comparing base (41587e9) to head (1f6423d).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
bin/strata-test-cli/src/mock_ee/deposit.rs 55.04% 49 Missing ⚠️
.../strata-test-cli/src/cmd/build_snark_withdrawal.rs 0.00% 36 Missing ⚠️
bin/strata-test-cli/src/cmd/create_mock_deposit.rs 0.00% 23 Missing ⚠️
crates/asm/spec-debug/src/lib.rs 0.00% 4 Missing ⚠️
bin/strata-test-cli/src/main.rs 0.00% 2 Missing ⚠️
crates/consensus-logic/src/sync_manager.rs 0.00% 2 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (41587e9) and HEAD (1f6423d). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (41587e9) HEAD (1f6423d)
functional 1 0
@@             Coverage Diff             @@
##             main    #1377       +/-   ##
===========================================
- Coverage   75.24%   64.97%   -10.27%     
===========================================
  Files         800      802        +2     
  Lines       74882    75055      +173     
===========================================
- Hits        56342    48769     -7573     
- Misses      18540    26286     +7746     
Flag Coverage Δ
functional ?
unit 64.97% <64.41%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
bin/strata-test-cli/src/cmd/args.rs 0.00% <ø> (ø)
bin/strata-test-cli/src/mock_ee/withdrawal.rs 100.00% <100.00%> (ø)
crates/asm/manifest-types/src/payloads.rs 76.92% <ø> (-15.29%) ⬇️
crates/asm/worker/src/builder.rs 93.02% <100.00%> (+1.84%) ⬆️
crates/asm/worker/src/service.rs 79.79% <100.00%> (-6.07%) ⬇️
crates/asm/worker/src/state.rs 76.16% <100.00%> (-1.41%) ⬇️
crates/ol/stf/src/manifest_processing.rs 75.58% <100.00%> (-13.45%) ⬇️
bin/strata-test-cli/src/main.rs 0.00% <0.00%> (-43.75%) ⬇️
crates/consensus-logic/src/sync_manager.rs 0.00% <0.00%> (-36.42%) ⬇️
crates/asm/spec-debug/src/lib.rs 0.00% <0.00%> (ø)
... and 3 more

... and 240 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@voidash voidash requested review from bewakes and irnb March 3, 2026 13:06
Copy link
Contributor

@delbonis delbonis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests look pretty good, happy to see this coming together. Eventually I'd like to see us be able to remove Reth from our test setup here. Just one main note.

strata.wait_for_additional_blocks(2, rpc, timeout_per_block=15)

# Step 8: Verify final balance
final_balance = get_account_balance(rpc, account_id_hex)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh no! yeah we should resolve this, maybe in this PR? both sides should use the same basic type instead of having two separate defs of it

bewakes
bewakes previously approved these changes Mar 10, 2026
Copy link
Contributor

@bewakes bewakes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a rebase though

@voidash voidash force-pushed the STR-2020-mock-withdrawal-tx-functional-test branch 2 times, most recently from b496762 to 111eb91 Compare March 12, 2026 05:28
@voidash voidash requested a review from bewakes March 17, 2026 09:51
voidash added 2 commits March 17, 2026 17:43
Add a `debug-asm` feature that conditionally switches the ASM worker
from `StrataAsmSpec` to `DebugAsmSpec`, enabling the debug subprotocol
(ID 255) which can inject arbitrary ASM logs via Bitcoin transactions.

- Add `DebugAsmSpec::from_params()` constructor mirroring StrataAsmSpec
- Add conditional compilation in asm-worker state.rs via cfg(feature)
- Propagate feature from bin/strata through strata-asm-worker

This is needed for functional tests that inject deposits via the
MockAsmLog mechanism without a real EE.
…awal

Add two new commands for testing the OL without a real EE:

create-mock-deposit: Builds a Bitcoin tx that injects a
DepositIntentLogData (type 100) into the ASM via the debug
subprotocol's MockAsmLog mechanism. Broadcasts via bitcoind RPC.

build-snark-withdrawal: Constructs a complete RpcOLTransaction JSON
blob containing an SSZ-encoded SnarkAccountUpdate with a withdrawal
OutputMessage. Pure computation, no network calls.

These replace the previous Python encoding utilities (SSZ, strata-codec,
msg-fmt) with authoritative Rust implementations, eliminating encoding
parity bugs.
voidash added 8 commits March 17, 2026 17:43
…a-test-cli

Add end-to-end test that deposits funds into a snark account via the
debug subprotocol and withdraws them, all without a real EE.

Test flow: inject deposit via Bitcoin tx (MockAsmLog), wait for terminal
block to process L1 manifest, verify balance, submit withdrawal via
RPC, verify balance deduction.

- Add common/test_cli.py wrapper for strata-test-cli subprocess calls
- Add EpochSealingConfig (slots_per_epoch=5 for fast terminal blocks)
- Fetch real GenesisL1View from bitcoind (target, timestamps)
- Pre-fund BDK wallet in ol_isolated env setup
- Query balance via getChainStatus + getBlocksSummaries
- Use account serial 128 (first user serial; 0-127 are system-reserved)
- Add subprocess timeout (60s) to strata-test-cli wrapper to prevent
  test hangs if the CLI binary stalls
- Improve subprocess error handling in OLIsolatedEnvConfig with
  descriptive error messages for BDK address retrieval failures
- Mine 8 blocks instead of 6 for deposit maturation to provide safety
  margin above l1_follow_distance=6
- Remove unused OL_ISOLATED_DEFAULT instance
…onfig

Address review feedback:
- Remove separate OLIsolatedEnvConfig; add genesis_accounts,
  epoch_sealing, and fund_test_cli_wallet params to StrataEnvConfig
- Derive block wait count from slots_per_epoch instead of hardcoding 10
- Store slots_per_epoch in strata service props for test access
Run cargo fmt and minimal workspace lockfile update (not full
regeneration) to avoid pulling incompatible dependency versions.
The OL STF was matching on DepositIntentLogData (TY=100), a placeholder
type that bridge-v1 never emits. Bridge-v1 emits DepositLog (TY=1),
meaning real deposits would be silently ignored by the new OL STF.

Unify on DepositLog (TY=1) as the canonical deposit log type:
- OL STF now decodes DepositDescriptor from DepositLog payloads
- Mock deposit tooling (strata-test-cli) emits DepositLog
- Remove DepositIntentLogData and DEPOSIT_INTENT_ASM_LOG_TYPE_ID
- Remove unused strata-asm-manifest-types dep from ol-stf Cargo.toml
- Add selected_operator param to WithdrawalMsgData::new call
…-switched

Move the ASM spec selection out of the worker crate into the caller.
AsmWorkerServiceState, AsmWorkerService, and AsmWorkerBuilder are now
generic over S: AsmSpec, and the caller constructs and passes in the
concrete spec.

The debug-asm feature flag moves from strata-asm-worker to
strata-consensus-logic, where the spec is constructed. The worker crate
no longer depends on either spec implementation crate.
- Add GenesisAccountData and OLParams dataclasses to params.py
- Export them from common.config.__init__
- Wire OLParams into strata factory: write custom ol-params.json
  when provided instead of always generating via datatool
- Fix type mismatch: pass genesis_l1.blk.height (int) to factory
  instead of GenesisL1View object
- Refactor let-chains syntax in deposit_withdrawal.rs (requires
  Rust edition 2024, not available in project toolchain)
- Run cargo fmt on deposit.rs, service.rs, deposit_withdrawal.rs
- Run ruff format on params.py, test_mock_withdrawal.py
@voidash voidash force-pushed the STR-2020-mock-withdrawal-tx-functional-test branch from 1cef449 to ac13022 Compare March 17, 2026 12:01
- Add `from err` to re-raise in except block (ruff B904)
- Remove unused `asdict` import (ruff F401)
- Update dbtool tests: epoch_slots=4 -> epoch_sealing=EpochSealingConfig.new_fixed_slot(4)
  to match StrataEnvConfig API change
@voidash voidash force-pushed the STR-2020-mock-withdrawal-tx-functional-test branch from ac13022 to 1f6423d Compare March 17, 2026 12:26
Copy link
Member

@storopoli storopoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 1f6423d

@storopoli storopoli requested a review from delbonis March 17, 2026 18:47
Copy link
Contributor

@bewakes bewakes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The func tests are failing. The rest LGTM.

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.

5 participants