MynaWallet / monorepo

16 stars 5 forks source link

Refactor Test Cases for Better Specification Clarity #16

Closed motemotech closed 11 months ago

motemotech commented 11 months ago

Overview

We aim to refactor test case names to better describe what specifications they are testing within the code.

Current Situation

For instance, this test case tells us it's testing for a failure in Rsa verification, but it takes time to understand under what circumstances this error occurs.

 function test_FailRsaVerify() public {
        bytes32 INVALID_SHA256_HASHED = hex"47707cfb91cc6bede5f48cde4f1cea391e0ed78338e9240889b045e8808b32d3";
        uint256 ret = INVALID_SHA256_HASHED.pkcs1Sha256Verify(SIGNATURE, EXPONENT, MODULUS);
        assertTrue(ret == 5, "pkcs1Sha256Verify failed");
    }

Desired State

In this particular case, the test is verifying that an error occurs during validation, when checking if the decrypted signature's message part matches the given message's SHA256 hash. It would be more helpful if the test case name directly reflected this.

 function test_FailRsaVerifyByDigestMismatchBetweenSignatureAndGivenHash() public {
        bytes32 INVALID_SHA256_HASHED = hex"47707cfb91cc6bede5f48cde4f1cea391e0ed78338e9240889b045e8808b32d3";
        uint256 ret = INVALID_SHA256_HASHED.pkcs1Sha256Verify(SIGNATURE, EXPONENT, MODULUS);
        assertTrue(ret == 5, "pkcs1Sha256Verify failed");
    }

Benefits