Skip to content

Fix: 3 issues (#929, #930, #931) - #1019

Merged
Austinaminu2 merged 2 commits into
FlowwStar:mainfrom
popsman01:simple/929-930-931
Oct 17, 2026
Merged

Austinaminu2 merged 2 commits into
FlowwStar:mainfrom
popsman01:simple/929-930-931

Conversation

@popsman01

Copy link
Copy Markdown
Contributor

Closes #929
Closes #930
Closes #931

Issues

#929 Test create-stream ScVal builders

Description

Building the ScVal arguments for create_stream currently has no test coverage (0 calls in the Vitest coverage report).

Location

lib/contract.ts (buildCreateStreamInputScVal, buildCreateStreamParamsScVal, ~lines 437–470)

Task

Add tests under __tests__/ (Vitest + Testing Library; only __tests__/** is collected). Cover at least:

  • field names/order match the contract
  • amounts and times encode as i128/u64
  • metadata optional

Acceptance criteria

  • Tests live under __tests__/ and pass with npm test
  • Listed cases are covered
  • No production code changes needed (unless a bug is found — then note it in the PR)

Good for contributors because

Self-contained test task with clear inputs/outputs; a great way to learn the codebase.

#930 Test getTokenMetadata

Description

Fetching token metadata currently has no test coverage (0 calls in the Vitest coverage report).

Location

lib/contract.ts (getTokenMetadata, ~line 736)

Task

Add tests under __tests__/ (Vitest + Testing Library; only __tests__/** is collected). Cover at least:

  • mock-mode path
  • successful lookup
  • failure returns a sensible error

Acceptance criteria

  • Tests live under __tests__/ and pass with npm test
  • Listed cases are covered
  • No production code changes needed (unless a bug is found — then note it in the PR)

Good for contributors because

Self-contained test task with clear inputs/outputs; a great way to learn the codebase.

#931 Test downloadCSV and downloadJSON

Description

The file download helpers currently has no test coverage (0 calls in the Vitest coverage report).

Location

lib/export.ts (lines ~86–106)

Task

Add tests under __tests__/ (Vitest + Testing Library; only __tests__/** is collected). Cover at least:

  • create a Blob with the right MIME type
  • trigger a download with the given filename
  • revoke the object URL (mock URL.createObjectURL)

Acceptance criteria

  • Tests live under __tests__/ and pass with npm test
  • Listed cases are covered
  • No production code changes needed (unless a bug is found — then note it in the PR)

Good for contributors because

Self-contained test task with clear inputs/outputs; a great way to learn the codebase.

Summary

All three issues are test-only; no production changes are expected. buildCreateStreamInputScVal and buildCreateStreamParamsScVal are module-private, so they must be exercised through estimateCreateStreamFee and createStream in live mode (stub a non-empty NEXT_PUBLIC_STREAM_CONTRACT_ID_TESTNET and mock getServer). Use @stellar/stellar-sdk's xdr.ScVal type tags (scvI128, scvU64, scvAddress, scvSymbol) to assert encodings, and include bigint values above Number.MAX_SAFE_INTEGER to catch precision loss. For getTokenMetadata, confirm whether the implementation returns a fallback token or throws on failure and assert accordingly. For export helpers, mock URL.createObjectURL/revokeObjectURL and anchor click; spy on Blob to check MIME types. Only tests/** is collected by Vitest, so all new tests must live there.

Changes

  • Add tests for the create_stream ScVal builders (buildCreateStreamInputScVal and buildCreateStreamParamsScVal in lib/contract.ts). Since these are module-private, exercise them through the public paths that use them: estimateCreateStreamFee (live mode) and createStream (live mode). Mock @/lib/stellar's getServer to return a fake server whose getAccount/getLatestLedger/simulateTransaction are vi.fn()s, and stub NEXT_PUBLIC_STREAM_CONTRACT_ID_TESTNET to a valid contract StrKey so mock mode is off. Capture the xdr.ScVal args passed to the contract call (via the TransactionBuilder operation or by inspecting the simulated transaction) and assert: (1) the params map has exactly the contract field names in the expected order (cliff_amount, cliff_time, end_time, recipient, start_time, token, total_amount for buildCreateStreamParamsScVal; recipient, token, total_amount, start_time, end_time, cliff_time, cliff_amount for buildCreateStreamInputScVal), (2) total_amount and cliff_amount are encoded as i128 (ScVal type tag scvI128) with the exact bigint values including values above Number.MAX_SAFE_INTEGER, (3) start_time/end_time/cliff_time are encoded as u64 (scvU64) with the exact bigint values, (4) recipient and token are address ScVals matching the input, and (5) metadata is optional — verify the builders produce no metadata entry when none is supplied and that a supplied metadata value is handled as expected (note in the PR if the builders currently drop metadata, since the CreateStreamInput type may not carry it). Run npm test; only change lib/contract.ts if a genuine bug is found and document it in the PR. (tests/lib/contract-scval.test.ts)
  • Add tests for getTokenMetadata in lib/contract.ts. Mock @/lib/stellar's getServer to return a fake server with getAccount and simulateTransaction vi.fn()s, and control mock mode via NEXT_PUBLIC_STREAM_CONTRACT_ID_TESTNET (empty string = mock mode). Cover: (1) mock-mode path — with no contract ID configured, getTokenMetadata returns the expected metadata without any network calls (assert getServer/simulateTransaction not called); (2) successful lookup — with a contract ID configured, simulateTransaction resolves to a success response whose retval is a token-metadata ScVal (e.g. nativeToScVal({ name, symbol, decimals })), and assert the returned TokenInfo maps name/symbol/decimals correctly; (3) failure — simulateTransaction resolves to a simulation error (or rejects), and assert getTokenMetadata returns/propagates a sensible error (e.g. rejects with a message containing 'Simulation failed' or returns a fallback UNK token, matching the implementation). Use vi.stubEnv in beforeEach and vi.unstubAllEnvs/vi.clearAllMocks in afterEach. Run npm test; only change lib/contract.ts if a genuine bug is found and note it in the PR. (tests/lib/contract.test.ts)
  • Add tests for downloadCSV and downloadJSON in lib/export.ts. In a new describe block, mock URL.createObjectURL and URL.revokeObjectURL with vi.fn() (returning a fake object URL string), and spy on document.createElement('a') / HTMLAnchorElement.prototype.click so no real navigation happens. Spy on the global Blob constructor (or inspect the Blob passed to createObjectURL) to assert: (1) downloadCSV creates a Blob with type 'text/csv;charset=utf-8;' containing the CSV string, and downloadJSON creates a Blob with type 'application/json;charset=utf-8;' containing the pretty-printed JSON; (2) the anchor's download attribute is set to the given filename and click() is called; (3) URL.revokeObjectURL is called with the URL returned by createObjectURL. Restore mocks in afterEach. Run npm test; only change lib/export.ts if a genuine bug is found and note it in the PR. (tests/lib/export.test.ts)

Co-authored-by: Simple Agent <agent@simple.dev>
@drips-wave

drips-wave Bot commented Oct 17, 2026

Copy link
Copy Markdown

@popsman01 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Austinaminu2
Austinaminu2 merged commit c51fb29 into FlowwStar:main Oct 17, 2026
2 of 7 checks passed
@grantfox-oss grantfox-oss Bot mentioned this pull request Oct 17, 2026
3 tasks

This branch had an error being deployed

1 failed deployment
staging — e75b1b91 Deployed Oct 17, 2026 by Austinaminu2 via deploy-staging #341
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.

Test downloadCSV and downloadJSON Test getTokenMetadata Test create-stream ScVal builders

2 participants