Skip to content

test(wallet-core): Cover the credit-asset signing path in sign_payment (asset code/issuer validation and envelope shape) #42

Description

@Emmyt24

Description

Every existing test in crates/wallet-core/src/signer.rs for sign_payment uses asset: None (native XLM). The Some((code, issuer)) branch — which validates the issuer via is_valid_account and builds the asset via Asset::new_credit — has no direct coverage at all, including its two distinct error paths (invalid issuer, invalid asset code rejected by stellar-base).

Requirements and Context

  • Cover the happy path: signing a payment with a valid 4-char and a valid 12-char asset code against a valid issuer produces a valid envelope with the correct Asset XDR variant (CreditAlphanum4 vs CreditAlphanum12).
  • Cover WalletError::InvalidAddress when the issuer string fails is_valid_account.
  • Cover the case where Asset::new_credit itself rejects the code (e.g. empty string, code longer than 12 chars, non-ASCII) and confirm it maps to WalletError::InvalidAddress, matching the existing .map_err(|_| WalletError::InvalidAddress) in signer.rs.

Suggested Execution

Branch: test/wallet-core/sign-payment-credit-asset

Implement Changes

  • Add test cases to the existing #[cfg(test)] mod tests block in crates/wallet-core/src/signer.rs, reusing sealed_vector_seed and DEST already defined there.
  • Use a valid vector-derived issuer address (e.g. DEST) for the credit-asset tests.

Test and Commit

  • signs_credit_asset_payment_alphanum4 — 3-4 char code, asserts the envelope's operation carries a CreditAlphanum4 asset.
  • signs_credit_asset_payment_alphanum12 — 5-12 char code, asserts CreditAlphanum12.
  • rejects_credit_asset_with_invalid_issuer — malformed issuer string -> WalletError::InvalidAddress.
  • rejects_credit_asset_with_invalid_code — empty or oversized code -> WalletError::InvalidAddress.
  • Run cargo test -p octo-wallet-core locally before committing.

Example Commit Message

test(wallet-core): cover the credit-asset branch of sign_payment

sign_payment's non-native asset path (issuer validation, asset-code length
class, and error mapping) had zero direct test coverage; only native XLM was
exercised. Adds happy-path and error-path cases for both alphanum4 and
alphanum12 codes.

Guidelines

  • Do not change sign_payment's behavior — this issue is test-only.
  • Assert on the XDR operation's asset variant, not just that signing succeeded, so a future regression in asset-kind selection is caught.
  • Reference this issue with Closes #<issue-number> in the PR description.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions