js-stellar-sdk
js-stellar-sdk copied to clipboard
modified the AssembledTransaction and it's tests
Fixes #1059
Description:
-
Corrected
isReadOnly
Method Invocation:-
Issue: Previously, the
isReadOnly
method was incorrectly invoked on an instance ofScSpecFunctionV0
, which does not possess this method. -
Solution: Updated the invocation to use the
Spec
instance (this.spec.isReadOnly(method)
) ensuring proper type safety and functionality.
-
Issue: Previously, the
-
Enhanced
AssembledTransaction
Class:-
Feature Addition: Modified the
sign
method within theAssembledTransaction
class to fail fast if nopublicKey
is provided. -
Improved UX: Instead of using a generic error message or defaulting to a hardcoded
NULL_ACCOUNT
, thesign
method now throws a descriptive error:"Public key not provided. Have you forgotten to set the `publicKey` in AssembledTransactionOptions?"
-
Benefit: This change ensures developers receive clear guidance when they omit the
publicKey
, enhancing the developer experience and preventing unintended transaction behaviors.
-
Feature Addition: Modified the
-
Updated Test Files to Reflect Changes:
-
assembled_transaction_test.js
:- Imported and instantiated the
Spec
class with the contract's specification entries. - Updated the
buildFootprintRestoreTransaction
method to pass theSpec
instance. - Changed account instantiation from
StellarSdk.Account
toxdr.Account
to align with expected types. - Ensured transaction fees are passed as strings to match method signatures.
- Imported and instantiated the
-
test-swap.js
:- Imported and instantiated the
Spec
class with the appropriate contract specifications. - Updated transaction building and signing processes to utilize the
Spec
instance. - Adjusted error assertions to correctly reference the updated error types.
- Ensured consistent account types and fee formatting in transaction methods.
- Imported and instantiated the
-
-
Enhanced
Spec
Class (spec.ts
):- Implemented the
isReadOnly
method to accurately determine if a contract function is read-only based on naming conventions or metadata. - Added comprehensive documentation for better maintainability and clarity.
- Implemented the
-
General Improvements:
- Type Safety: Ensured all method invocations and parameter types align with TypeScript standards, preventing potential runtime errors.
- Descriptive Error Messages: Enhanced error messages to be more actionable, facilitating easier debugging.
- Comprehensive Testing: Updated test cases to cover both read-only and write transaction scenarios, ensuring robust test coverage.
Benefits:
-
Resolved TypeScript Error: Eliminates the
Property 'isReadOnly' does not exist on type 'ScSpecFunctionV0'.ts(2339)
error by correctly invokingisReadOnly
on theSpec
instance. - Improved Developer Experience: Clear and descriptive error messages guide developers to provide necessary configurations, reducing frustration and potential bugs.
- Enhanced Code Quality: Strengthens the codebase through proper type handling, error management, and comprehensive testing.
- Reliable Transaction Handling: Ensures transactions behave as expected, with appropriate checks in place to prevent unintended operations.
Testing:
-
Unit Tests: All existing unit tests pass, and new tests cover the scenarios where
publicKey
is omitted, ensuring thesign
method behaves correctly. -
Integration Tests: Verified that transactions requiring
publicKey
fail gracefully when omitted and succeed when provided. - Error Handling: Confirmed that descriptive errors are thrown, aiding in quicker debugging and issue resolution.