Skip to content

Commit

Permalink
Added the RIPEMD-160 coverage.
Browse files Browse the repository at this point in the history
Signed-off-by: ebadiere <[email protected]>
  • Loading branch information
ebadiere committed Oct 23, 2023
1 parent 0f41c95 commit 76e4681
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
7 changes: 6 additions & 1 deletion contracts/evm/Precompiles.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ contract Precompiles {
return recoveredAddress == expectedSigner;
}

function computeHash(string memory input) public pure returns (bytes32) {
function computeSha256Hash(string memory input) public pure returns (bytes32) {
return sha256(abi.encodePacked(input));
}

function computeRipemd160Hash(string memory input) public pure returns (bytes20) {
return ripemd160(abi.encodePacked(input));
}

}
17 changes: 12 additions & 5 deletions test/evm/Precompiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,24 @@ describe("@solidityevmequiv1 Precompiles Support", function () {

it("Should return the correct SHA-256 hash", async function () {

// Compute the SHA-256 hash of the string "Hello future!" using JavaScript
const crypto = require('crypto');
const input = "Hello future!";
const hash = crypto.createHash('sha256').update(input).digest('hex');
const expectedHash = "0x" + hash;

// Call the computeHash function from the contract
const result = await precompilesContract.computeHash(input);
const result = await precompilesContract.computeSha256Hash(input);
expect(result).to.equal(expectedHash);
});

it("Should return the correct RIPEMD-160 hash", async function () {

// Assert
const crypto = require('crypto');
const input = "Hello future!";
const hash = crypto.createHash('ripemd160').update(input).digest('hex');
const expectedHash = "0x" + hash;

const result = await precompilesContract.computeRipemd160Hash(input);
expect(result).to.equal(expectedHash);
});
});

});

0 comments on commit 76e4681

Please sign in to comment.