Repository navigation
Feat(test)/unity test framework - #276
Conversation
Relax assertion in ECDSASignatures.cs: p1363Offset check changed from > 0 to >= 0 to allow a zero offset when packing P-256 P1363 signature components. Prevents erroneous assertion failures when a valid zero offset is used.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughAdds a large set of Unity edit-mode tests (cryptography, JSON‑RPC, Mobile Wallet Adapter client/session), supporting assembly and metadata, a test mock, and a one-line change relaxing an assertion in ECDSA signature packing and a corrected decryption error message. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@Tests/EditMode/Crypto/MobileWalletAdapterSessionTests.cs`:
- Line 99: The test DecryptSessionPayload_* is asserting the wrong log message —
it expects an encrypt-related error ("Cannot encrypt, no session key has been
established") in a decrypt test; update the LogAssert.Expect call in the test
method (the assertion on the log message) to assert the corresponding decrypt
message (e.g., "Cannot decrypt, no session key has been established") or
otherwise match the actual error produced by the DecryptSessionPayload method so
the test validates the correct behavior.
In `@Tests/EditMode/EditMode.asmdef`:
- Line 13: Update the Tests/EditMode assembly definition by setting the
"allowUnsafeCode" property to false (change the "allowUnsafeCode" entry
currently true in EditMode.asmdef) so the assembly disables unsafe code; ensure
the JSON key remains present and set to false to maintain tighter security
defaults.
In `@Tests/EditMode/Mocks/MockMessageSender.cs`:
- Around line 15-25: The mock currently stores and returns references to
caller-provided byte[] buffers which can be mutated later; update
MockMessageSender to defensive-copy buffers: in Send(byte[] message) create and
store a new byte[] copy into SentMessages (rather than the original reference),
and change the LastMessage getter to return a copy of the stored buffer (or
null) so callers cannot mutate internal state; reference the Send method, the
SentMessages collection, and the LastMessage property when making these changes.
In `@Tests/EditMode/MwaClient/MobileWalletAdapterClientTests.cs`:
- Line 53: Change the request-construction tests in
MobileWalletAdapterClientTests from void to async Task and await the
asynchronous calls instead of discarding them; specifically update each test
that currently does `_ = _client.Authorize(...)` (and other similar `_ =
_client.*` calls at the listed locations) to `await _client.Authorize(...)`,
adjust the test method signatures to `async Task` so exceptions surface and the
Task is awaited, and apply this change consistently across all instances
referenced (lines for the Authorize call and the other similar calls in the same
test class).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: ed9d59b4-718f-478f-a2c8-bd2bc21d45e0
📒 Files selected for processing (19)
Runtime/codebase/SolanaMobileStack/Crypto/ECDSASignatures.csTests.metaTests/EditMode.metaTests/EditMode/Crypto.metaTests/EditMode/Crypto/EcdsaSignaturesTests.csTests/EditMode/Crypto/EcdsaSignaturesTests.cs.metaTests/EditMode/Crypto/MobileWalletAdapterSessionTests.csTests/EditMode/Crypto/MobileWalletAdapterSessionTests.cs.metaTests/EditMode/EditMode.asmdefTests/EditMode/EditMode.asmdef.metaTests/EditMode/JsonRpc.metaTests/EditMode/JsonRpc/ResponseModelTests.csTests/EditMode/JsonRpc/ResponseModelTests.cs.metaTests/EditMode/Mocks.metaTests/EditMode/Mocks/MockMessageSender.csTests/EditMode/Mocks/MockMessageSender.cs.metaTests/EditMode/MwaClient.metaTests/EditMode/MwaClient/MobileWalletAdapterClientTests.csTests/EditMode/MwaClient/MobileWalletAdapterClientTests.cs.meta
fix decrypt error string, defensive copy in mock, disable unsafe code in test assembly
Problem
The Solana Unity SDK did not have any automated test infrastructure before this PR.
That meant core Mobile Wallet Adapter logic had no repeatable regression coverage, including crypto helpers, session state behavior, JSON-RPC request construction, and response model convenience properties. It also made it harder to validate changes requested during recent MWA work without relying entirely on manual testing.
Solution
This PR adds the first Unity Test Framework scaffold to the SDK and introduces 31 EditMode unit tests across 4 test classes.
The new tests focus on logic that can be exercised in pure EditMode without requiring Android runtime dependencies:
EcdsaSignaturescrypto helpersMobileWalletAdapterSessionMobileWalletAdapterClientJSON-RPC request buildingResponse<T>computed propertiesA
MockMessageSendertest double was added forIMessageSenderso request payloads can be asserted without a real transport.This PR is intentionally scoped to the parts of the MWA stack that are already testable in Editor.
SolanaMobileWalletAdapterlifecycle and reconnect flows are not included yet because they currently depend on constructor behavior that throws on non-Android platforms.Before & After Screenshots
Insert screenshots of example code output
BEFORE:
N/A. No automated tests existed in the SDK before this PR.
AFTER:

Other changes (e.g. bug fixes, small refactors)
Tests/structure for Unity Test Framework coverageDeploy Notes
This PR primarily adds test infrastructure and EditMode unit coverage. It does not introduce new package dependencies or deployment steps.
New scripts:
Tests/EditMode/Crypto/EcdsaSignaturesTests.cs: EditMode coverage for DER/P1363 conversion and P-256 key encode/decodeTests/EditMode/Crypto/MobileWalletAdapterSessionTests.cs: EditMode coverage for session token and pre-ECDH error pathsTests/EditMode/JsonRpc/ResponseModelTests.cs: EditMode coverage forResponse<T>success/failure propertiesTests/EditMode/MwaClient/MobileWalletAdapterClientTests.cs: EditMode coverage for JSON-RPC request buildingTests/EditMode/Mocks/MockMessageSender.cs: Test double forIMessageSenderNew dependencies:
Summary by CodeRabbit
Tests
Bug Fixes
Chores