Skip to content

fix: resolve issues #105, #101, #102, #97 — readContractState, DisputeClient constructor, dead code cleanup - #256

Merged
meshackyaro merged 2 commits into
trustflow-protocol:mainfrom
Rampop01:fix-rampop-issues
Aug 31, 2026
Merged

fix: resolve issues #105, #101, #102, #97 — readContractState, DisputeClient constructor, dead code cleanup#256
meshackyaro merged 2 commits into
trustflow-protocol:mainfrom
Rampop01:fix-rampop-issues

Conversation

@Rampop01

Copy link
Copy Markdown

Summary

This PR resolves four open issues assigned to @Rampop01 across the TrustFlow SDK codebase.


Issue #105 — Fix non-functional readContractState in src/contract/read.ts

Problem: readContractState built a real contract.call() operation but immediately discarded it (the variable was prefixed _operation). Instead, it simulated a hand-faked envelope whose XDR was always the empty string — meaning every call performed the same meaningless simulation regardless of method/args.

Fix:

  • Replaced the fake envelope stub with a proper TransactionBuilder workflow:
    • Uses a dummy Account for simulation (no real account needed for read-only calls).
    • Wraps the contract.call(method, ...args) operation into a real transaction.
    • Passes the built transaction to server.simulateTransaction().
  • Decodes the simulated result using scValToNative() to return usable JS values.
  • Removes the _operation unused-variable warning entirely since the operation is now genuinely consumed.
  • Added a dedicated tests/contract-read.test.ts test suite verifying:
    • A real transaction is built and simulated.
    • Simulation errors throw TrustFlowError.

Files changed: src/contract/read.ts, tests/contract-read.test.ts


Issue #101 — Standardize constructor signatures across DisputeClient, MultiSigEscrowClient, and TrustFlowEscrowClient

Problem: DisputeClient accepted raw (apiUrl: string, token: string) constructor arguments, unlike MultiSigEscrowClient and TrustFlowEscrowClient which both accept a ContractConfig object. This inconsistency made the SDK harder to use and maintain.

Fix:

  • Refactored DisputeClient constructor to accept (config: ContractConfig, options?: DisputeClientOptions).
  • Extracts apiBaseUrl and apiKey from the config object internally.
  • Throws descriptive errors if required config fields (apiBaseUrl, apiKey) are missing.
  • Updated tests/dispute.test.ts to use the new constructor signature.

Files changed: src/escrow/dispute.ts, tests/dispute.test.ts


Issue #102 — Remove or fix src/utils.ts (dead code, duplicate logic, missing dependencies)

Problem: The top-level src/utils.ts was a dead file that imported humanize-duration and moment (neither in package.json), duplicated logic already in src/utils/format.ts, and was never imported by src/index.ts. It caused tsc build failures.

Fix: The file was already removed in a prior merge to main. This PR cleans up the remaining SimpleCache test references in tests/utils.test.ts that pointed to the deleted code and caused test suite failures (TS2304: Cannot find name SimpleCache).

Files changed: tests/utils.test.ts


Issue #97 — Remove dead code in src/utils/validate.ts

Problem: src/utils/validate.ts contained dead/unreachable code paths.

Fix: The file was cleaned up in a prior merge. This PR additionally fixes a residual TS2694 type error in src/contract/simulate.ts where rpc.Api.Transaction no longer exists as an exported member — replaced with a safe as any cast consistent with the SDK's other simulation call sites. Also fixed the ParsedEvent generic default type in src/events.ts from Record<string, unknown> to unknown to resolve index-signature type mismatches.

Files changed: src/contract/simulate.ts, src/events.ts


Verification

  • npx tsc --noEmit passes with zero errors
  • ✅ All 30 test suites pass (210 tests)

Closes #105
Closes #101
Closes #102
Closes #97

…rustflow-protocol#101, trustflow-protocol#97

- Fix non-functional readContractState by building real TransactionBuilder (trustflow-protocol#105)
- Standardize DisputeClient constructor to use ContractConfig (trustflow-protocol#101)
- Remove dead SimpleCache tests referencing deleted utils.ts (trustflow-protocol#102)
- Fix TS2694 type error in simulate.ts (trustflow-protocol#97)
- Add unit test for readContractState
- Fix ParsedEvent generic type in events.ts
@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@Rampop01 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

@meshackyaro
meshackyaro merged commit f6802b0 into trustflow-protocol:main Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment