Add unit tests across all crates #8

Closed
opened 2026-02-27 14:07:41 +00:00 by mik-tf · 0 comments
Member

Problem

The project currently has zero unit tests. This makes it hard to catch regressions and verify correctness of core logic.

Scope

Add unit tests for the three main crates:

portal-frontend (signing.rs) — 10 tests

  • Mnemonic derivation produces valid SS58 addresses
  • Derivation is deterministic (same mnemonic → same keys)
  • Whitespace trimming on mnemonic input
  • Invalid mnemonic rejection
  • Mnemonic phrase preservation in WalletState
  • Payload signing returns valid hex signature
  • Bad hex payload rejection
  • Public key to SS58 known vector
  • GatewayAccountId default value
  • HeroLedgerAccount default value

portal-shared (lib.rs) — 10 tests

  • Serde round-trip for all shared types (BalanceResponse, TransferPrepareResponse, etc.)
  • Default values for optional fields
  • Optional memo field omission
  • TwinResponse with null relay
  • NodeResponse defaults

portal-backend (api.rs) — 13 tests

  • Memo validation (valid hex, too short, too long, non-hex, empty)
  • TFT-to-planck conversion (zero, one, fractional, large amounts)
  • SS58 address parsing (valid/invalid)
  • API error response structure

Verification

All 33 tests pass with make test (cargo test --all).

## Problem The project currently has zero unit tests. This makes it hard to catch regressions and verify correctness of core logic. ## Scope Add unit tests for the three main crates: ### portal-frontend (signing.rs) — 10 tests - Mnemonic derivation produces valid SS58 addresses - Derivation is deterministic (same mnemonic → same keys) - Whitespace trimming on mnemonic input - Invalid mnemonic rejection - Mnemonic phrase preservation in WalletState - Payload signing returns valid hex signature - Bad hex payload rejection - Public key to SS58 known vector - GatewayAccountId default value - HeroLedgerAccount default value ### portal-shared (lib.rs) — 10 tests - Serde round-trip for all shared types (BalanceResponse, TransferPrepareResponse, etc.) - Default values for optional fields - Optional memo field omission - TwinResponse with null relay - NodeResponse defaults ### portal-backend (api.rs) — 13 tests - Memo validation (valid hex, too short, too long, non-hex, empty) - TFT-to-planck conversion (zero, one, fractional, large amounts) - SS58 address parsing (valid/invalid) - API error response structure ## Verification All 33 tests pass with `make test` (cargo test --all).
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mycelium/www_migrate_mycelium#8
No description provided.