Skip to content

Comments

test: run comprehensive test coverage for transaction provider#39

Merged
phertyameen merged 2 commits intobridgelet-org:mainfrom
KingFRANKHOOD:main
Jan 30, 2026
Merged

test: run comprehensive test coverage for transaction provider#39
phertyameen merged 2 commits intobridgelet-org:mainfrom
KingFRANKHOOD:main

Conversation

@KingFRANKHOOD
Copy link
Contributor

Comprehensive Test Coverage for TransactionProvider - Closes #31

The TransactionProvider is a critical security component in the Bridgelet SDK that handles actual Stellar blockchain transactions including sweep operations and account merges. This provider directly interfaces with the Stellar Horizon API and manages cryptographic operations, transaction building, signing, and submission

Initial Problem

The existing tests for TransactionProvider have several critical deficiencies:

  • Incomplete Mock Architecture: The Stellar SDK mocking is shallow and doesn't properly simulate the actual behavior of the SDK's builder pattern or error responses
  • Missing Edge Cases: Critical failure scenarios are not tested (network timeouts, insufficient balance, invalid signatures, etc.)
  • Insufficient Transaction Lifecycle Testing: The full transaction flow from building to signing to submission is not properly validated
  • Asset Parsing Gaps: While basic parsing is tested, complex asset scenarios and error handling are incomplete
  • Error Response Validation: Horizon API error responses with extras field are not properly tested
  • Account Balance Verification: The getAccountBalance method is completely untested
  • Network Configuration: Tests don't validate behavior differences between testnet and mainnet
  • Transaction Building Parameters: BASE_FEE, timeout, and network passphrase handling not properly validated

IMPLEMENTATIONS

  • All existing tests continue to pass
  • Code coverage for TransactionProvider reaches minimum 90%
  • All critical failure scenarios documented above are tested
  • Mock architecture properly simulates Stellar SDK behavior
  • Tests use proper TypeScript typing throughout
  • Each test has clear documentation of what scenario it validates
  • Tests follow NestJS and Jest best practices
  • All async operations properly handled
  • Error messages are validated, not just error types
  • Tests validate both positive and negative scenarios for each method

Extra confirmations

  • Horizon error codes: handle at least tx_bad_seq, tx_insufficient_balance, tx_failed, tx_duplicate, op_no_destination; optionally include tx_bad_auth, tx_too_late, tx_internal_error, op_underfunded for production hardening.
  • Transaction simulation: yes, test separately at the ContractProvider level
  • Signing validation without chain: assert transaction.sign is called with the correct keypair and that builder order is enforced; optionally validate signature count via SDK transaction object mock.
  • Invalid ConfigService URLs: expect constructor to throw (via getOrThrow) or provider calls to surface InternalServerErrorException with the original error message.
  • Fee edge cases: yes; verify BASE_FEE usage, insufficient fee errors (tx_insufficient_balance), and ensure fee is passed to TransactionBuilder for both sweep and merge.

@KingFRANKHOOD
Copy link
Contributor Author

Hi @phertyameen, I changed a few things in only the package.json so that Jest can run the tests without crashing. It tells Jest to treat .ts test files like normal CommonJS and to resolve local “.js” imports to their .ts files. Apart from that, only the transaction provider file was handled

@phertyameen
Copy link
Contributor

Hi @phertyameen, I changed a few things in only the package.json so that Jest can run the tests without crashing. It tells Jest to treat .ts test files like normal CommonJS and to resolve local “.js” imports to their .ts files. Apart from that, only the transaction provider file was handled

Nice of you to inform me. Thats great

@phertyameen phertyameen merged commit 0e4aa15 into bridgelet-org:main Jan 30, 2026
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.

Comprehensive Test Coverage for TransactionProvider - Critical Security & Transaction Flow Validation

2 participants