Skip to content

Commit 2070cc8

Browse files
committed
Update readme
Signed-off-by: Giuseppe Bertone <giuseppe.bertone@hashgraph.com>
1 parent cdf662e commit 2070cc8

File tree

1 file changed

+31
-47
lines changed

1 file changed

+31
-47
lines changed

README.md

Lines changed: 31 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,12 @@ Messages are auto-detected (format: JSON/CBOR/plain, encryption: RSA/ECIES) and
453453
│ ├── hedera.js # Hedera SDK wrappers, client init, key parsing
454454
│ └── message-box.js # Core message box logic (setup, send, poll)
455455
├── test/
456+
│ ├── config.test.js # Unit tests for config.js (env loading, defaults, validation)
457+
│ ├── format-message.test.js # Unit tests for format-message.js (CBOR codec, parsing)
456458
│ ├── integration.test.js # End-to-end integration test suite (requires .env)
457459
│ ├── setup.js # Jest setup — silences app console output during tests
458460
│ ├── streaming-reporter.js # Custom Jest reporter with real-time per-test output
459-
│ └── unit.test.js # Offline unit tests (no credentials required)
461+
│ └── unit.test.js # formatMessage unit tests (no credentials required)
460462
├── .env # Hedera credentials and config (not committed)
461463
├── .env.example # Example environment file
462464
├── .gitignore # Git ignore rules
@@ -488,7 +490,17 @@ npm run test:coverage # Run all tests and generate
488490

489491
## Testing
490492

491-
The project uses [Jest](https://jestjs.io/) as its test runner. There are two test suites:
493+
The project uses [Jest](https://jestjs.io/) as its test runner. Tests are split into offline unit tests and live integration tests:
494+
495+
### All Tests
496+
497+
Run with:
498+
499+
```bash
500+
npm test
501+
```
502+
503+
Each test name appears immediately when it starts running (with a `` indicator), and updates in-place with the result and elapsed time once it finishes. This is handled by [test/streaming-reporter.js](test/streaming-reporter.js).
492504

493505
### Unit Tests (offline)
494506

@@ -498,13 +510,29 @@ Test pure logic with no network connection or credentials required:
498510
npm run test:unit
499511
```
500512

501-
Covers all four exit paths of `formatMessage` in `src/lib/format-message.js`:
513+
Spans three test files (`unit.test.js`, `config.test.js`, `format-message.test.js`) and covers:
514+
515+
**`unit.test.js`** — four exit paths of `formatMessage`:
502516

503517
- Encrypted message that decrypts successfully
504518
- Encrypted message that cannot be decrypted (wrong key)
505519
- Public key announcement message
506520
- Plain-text / unrecognised content
507521

522+
**`config.test.js`** — config singleton (`src/lib/config.js`):
523+
524+
- `.env` file loading: absent file, read errors, env-var precedence, quote stripping, comment/blank-line handling
525+
- `findProjectRoot()` fallback behaviour
526+
- Default values and case normalisations (network, encryption type, RSA data dir, mirror node URL)
527+
- Required-field validation (throws with a clear message for each missing field)
528+
529+
**`format-message.test.js`** — CBOR codec and message formatting (`src/lib/format-message.js`):
530+
531+
- `encodeCBOR`/`decodeCBOR` roundtrip for all supported types (primitives, integers, floats, strings, buffers, arrays, objects)
532+
- `encodeCBOR` and `decodeCBOR` error cases (unsupported types, malformed input)
533+
- `parseMessageContent` format detection (CBOR, JSON, plain)
534+
- `formatMessage` with CBOR-encoded messages and public-key output branches
535+
508536
### Integration Tests (live Hedera)
509537

510538
End-to-end tests that require a configured `.env` file and HBAR balance:
@@ -526,50 +554,6 @@ Covers:
526554
- Link ownership validation (rejects attempts to link a topic to the wrong account)
527555
- Sending messages to a re-linked message box
528556

529-
### All Tests
530-
531-
Run with:
532-
533-
```bash
534-
npm test
535-
```
536-
537-
Example output:
538-
539-
```text
540-
formatMessage
541-
✓ Encrypted message decrypted successfully (3 ms)
542-
✓ Encrypted message cannot be decrypted (60 ms)
543-
✓ Public key announcement message correctly decoded (17 ms)
544-
✓ Plain text / unrecognised message correctly handled (1 ms)
545-
546-
Test Suites: 1 passed, 1 total
547-
Tests: 4 passed, 4 total
548-
Snapshots: 0 total
549-
Time: 0.234 s
550-
551-
Message Box Integration
552-
✓ Setup Message Box (9757 ms)
553-
✓ Send Message (6520 ms)
554-
✓ Send Message (CBOR) (5816 ms)
555-
✓ Check Messages (187 ms)
556-
✓ Message Box Reuse (Idempotency) (95 ms)
557-
✓ Signature Verification (2532 ms)
558-
✓ Remove Message Box (5519 ms)
559-
✓ Link Message Box (re-attach existing topic) (6562 ms)
560-
✓ Link Message Box (idempotent – already linked) (132 ms)
561-
✓ Link Message Box (rejects wrong account) (122 ms)
562-
✓ Send Message After Re-link (4391 ms)
563-
✓ Remove Message Box (final cleanup) (6430 ms)
564-
565-
Test Suites: 1 passed, 1 total
566-
Tests: 12 passed, 12 total
567-
Snapshots: 0 total
568-
Time: 48.353 s
569-
```
570-
571-
Each test name appears immediately when it starts running (with a `` indicator), and updates in-place with the result and elapsed time once it finishes. This is handled by [test/streaming-reporter.js](test/streaming-reporter.js).
572-
573557
## Configuration Files
574558

575559
### Environment Variables (`.env`)

0 commit comments

Comments
 (0)