test(exchange): bring src/api/exchange to 100% offline line coverage - #73
Merged
Conversation
…ine coverage Add a mock-transport harness (recording/failing transports, deterministic local wallets, fixed-nonce single-wallet and multi-sig configs) and 139 offline tests covering every ExchangeClient method path: exact wire payloads for valid params, ValidationError with zero requests for invalid params, multi-sig wrappers (L1 + user-signed, userSetAbstraction payload mappings), options plumbing (vault/expiresAfter/signal/nonceManager, function-valued defaultExpiresAfter), skipValidation, transport and API error passthrough, prepareRequest/submitPrepared wrappers, and the executeUserSignedAction nonce/time-field contract. src/api/exchange: 2624/3124 (84.0%) -> 3175/3175 (100%) DA lines offline.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Tests-only PR — no
src/changes. Bringssrc/api/exchangeto 100% line coverage under the offline CI gate (HL_OFFLINE=1 bun test tests/ --coverage --coverage-reporter=lcov). Previously the method/client bodies were only exercised by the live tests, which are skipped offline.tests/api/exchange/_mockTransport.ts(new): shared offline harness — recording/failing mock transports, deterministic local viem wallets, and prebuilt single-wallet & multi-sig configs with a fixed nonce and signature chain ID, so signed payloads are deterministic and no test touches the network.tests/api/exchange/_client.test.ts(new): 139 offline tests —ExchangeClientmethod path: valid params → exact wire payload (action fields deep-equal, envelope nonce, signature shape); invalid params →ValidationErrorwith zero requests sent.userSetAbstractionpayload-action mappings (disabled/unifiedAccount/portfolioMargin→i/u/p+ theskipValidationpassthrough), and the signature-chain-ID fallback to the leader wallet.vaultAddress/expiresAfteroptions vs config defaults, function-valueddefaultExpiresAfter(sync/async/throwing),AbortSignalpassthrough,nonceManager(receives the wallet address; sync and promise-returning).skipValidationon both L1 and user-signed paths (no default-filling, invalid values posted as-is).ApiRequestError), including the single-status envelope and the getter-flip fallthrough ingetErrorMessage(duck-typed detection is not idempotent).prepareRequest/submitPreparedclient wrappers: capture posts nothing, submission posts the prepared payload byte-for-byte, zero-request callbacks fail the prepare.executeUserSignedActioncontract: EIP-712 types without anonce/timefield are rejected.Coverage
Measured with
HL_OFFLINE=1 bun test tests/ --coverage --coverage-reporter=lcov(DA lines). Denominators shift slightly because Bun's lcov only emits DA entries for some closing lines of a function once the function has executed.src/api/exchange/_methodssrc/api/exchange/client.tssrc/api/exchange/mod.tsPer-file before → after
Verification
bun run check— all steps pass (format, lint, docs, types, ts7, jsdoc, export).HL_OFFLINE=1 bun test tests/— 1159 pass, 0 fail, 236 skip (live-endpoint tests).