feat: complete test script of mev shield#3196
feat: complete test script of mev shield#3196codomposer wants to merge 1 commit intoopentensor:SDKv10from
Conversation
|
@basfroman Could you please take a look at this PR when you are free? |
I don't see any test power or load in these tests. If you generate tests with AI, please first try to understand the essence of the tests we write. If you're writing a UNIT test for the submit_encrypted_extrinsic function, your ultimate goal is to verify that the following internal calls were made, with what parameters (if any) and how many times (depending on the parameters of the main call):
In negative scenarios, it's worth checking what types of errors were raised. And verification as: assert result.success is True
assert result.data["commitment"] == MOCK_COMMITMENT
assert result.data["ciphertext"] == MOCK_CIPHERTEXT
assert result.data["ml_kem_768_public_key"] == b"x" * ML_KEM_768_KEY_SIZE
assert result.data["payload_core"] == MOCK_PAYLOAD_CORE
assert result.data["signed_extrinsic_hash"] == MOCK_EXTRINSIC_HASH_HEXdoesn't provide any benefit for unit testing. Take this test, for example. There's no assignment to real data at all. Everything is checked through mocks. But we know exactly which arguments are used in the internal calls. Also, we don't write tests for just one implementation (synchronous or asynchronous). If you have both, you need to implement tests for both. You've only implemented tests for the async one. |
Hey @codomposer , pls take a look this pr with tests. This is how I expect to see the coverage. Now the coverage is 100% for sync and async extrinsic modules. |
SDKv10 already has 100% coverage for mev extrinsic modules. Pls take a look the PR from my prev comment. Current logic in this PR is redundant. |
Description of the Change
This PR adds comprehensive unit tests for the async MEV Shield extrinsics module (
bittensor/core/extrinsics/asyncex/mev_shield.py).New test file:
tests/unit_tests/extrinsics/asyncex/test_mev_shield.pyTests implemented:
test_submit_encrypted_extrinsic_success- Verifies successful encryption and submission with commitment and ciphertext generationtest_submit_encrypted_extrinsic_sign_with_hotkey- Verifies correct signer selection when using hotkeytest_wait_for_extrinsic_by_hash_success- Verifies successful extrinsic discovery in subsequent blockstest_wait_for_extrinsic_by_hash_decryption_failure- Verifies markDecryptionFailed event detectiontest_wait_for_extrinsic_by_hash_timeout- Verifies None return when extrinsic not found within timeouttest_submit_encrypted_extrinsic_invalid_signer- Verifies AttributeError raised for invalid sign_with parameterAlternate Designs
N/A - This is a test implementation following existing pytest patterns in the codebase.
Possible Drawbacks
None - This PR only adds tests without modifying production code.
Verification Process
python -m pytest tests/unit_tests/extrinsics/asyncex/test_mev_shield.py -v- All 6 tests pass@pytest.mark.asyncioandAsyncMockRelease Notes
N/A - Test-only changes, not user-facing.
Branch Acknowledgement
[x] I am acknowledging that I am opening this branch against
SDKv10Contribution by Gittensor, learn more at https://gittensor.io/