Repository navigation
test(web): cover listing-contract paid/free gate and legacy-sol flow - #243
Merged
Merged
Conversation
This branch was successfully deployed
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.
Summary
Add missing test coverage for
web/lib/listingContract.ts— the helper that decides whether a skill is served as paid or free and which checkout flow applies.The paid/free decision (
normalizeUsdcMicros) and the flow resolver (getSkillPaymentFlow) sit directly on the money path: they determine whether a download is gated or freely served, so a regression here would silently flip paid content to free (or vice versa). Onmain, only two "paid" branches ofgetSkillPaymentFlowwere tested andnormalizeUsdcMicros, thelegacy-solbranch, andrequiresPurchasehad no coverage at all.What's now covered
normalizeUsdcMicros— the digit-string gate that produces a canonical price string ornull:bigint-shaped values) and trims surrounding whitespacenull/undefined/empty, and zero amounts ("0","000"," 0 ",0)"-5"," -5 ","-0"), fractional ("1.5","1.0","100.00"), scientific notation ("1e3","1E3")"1_000","abc","12abc","0x10") and boolean values that can arrive via JSON request bodiesNumber.MAX_SAFE_INTEGER-ish magnitudes)getSkillPaymentFlow— newly adds the "paid-looking-but-invalid" fallbacks: a linked listing with a zero/invalid price (fractions, negatives) falls through tofreerather than being gated as paid; thelegacy-solbranch is onlylegacy-solwhenallowLegacySolis true and the lamports amount is positive (zero and disallowed cases returnfree); unpriced skills returnfree.requiresPurchase—freeis not purchase-required; every other flow is.Why this is safe / reviewable
web/__tests__/lib/listingContract.test.ts. No production code, no schema, no protocol/money behavior changed — coverage pins the existing (correct) behavior so future changes can't regress the paid/free gate.as unknown as numbercasts because the declared parameter type excludes them, but runtime JSON bodies can carry them and the gate must reject them.What I verified
npx vitest run __tests__/lib/listingContract.test.ts→ 14 tests passed.npm run typecheck --workspace @agentvouch/web→ clean.npm run format:check→ "All matched files use Prettier code style".npm run lint --workspace @agentvouch/web→ clean.npm run test --workspace @agentvouch/web→ 152 files / 1322 tests passed.npm run test(full repo, includes CLI workspace) → 13 files / 77 tests passed.Web build skipped on purpose — this is a test-only change with no production code touched. Per the repo convention the web build is the real build/typecheck gate, but no build input changed here.
What I did NOT verify
forge test(nocontracts/changes) and no Anchor IDL sync (no program/interface changes).