Release v5.3 cherrypick #2 (#5526)

Signed-off-by: Hadrien Croubois <hadrien.croubois@gmail.com>
Co-authored-by: Ernesto García <ernestognw@gmail.com>
Co-authored-by: Arr00 <13561405+arr00@users.noreply.github.com>
Co-authored-by: Voronor <129545215+voronor@users.noreply.github.com>
Co-authored-by: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com>
Co-authored-by: Michalis Kargakis <kargakis@protonmail.com>
This commit is contained in:
Hadrien Croubois
2025-03-03 15:51:41 +01:00
committed by GitHub
parent 77a459e987
commit 887697148d
34 changed files with 1641 additions and 262 deletions

View File

@ -19,14 +19,16 @@ describe('MessageHashUtils', function () {
const message = ethers.randomBytes(32);
const expectedHash = ethers.hashMessage(message);
expect(await this.mock.getFunction('$toEthSignedMessageHash(bytes32)')(message)).to.equal(expectedHash);
await expect(this.mock.getFunction('$toEthSignedMessageHash(bytes32)')(message)).to.eventually.equal(
expectedHash,
);
});
it('prefixes dynamic length data correctly', async function () {
const message = ethers.randomBytes(128);
const expectedHash = ethers.hashMessage(message);
expect(await this.mock.getFunction('$toEthSignedMessageHash(bytes)')(message)).to.equal(expectedHash);
await expect(this.mock.getFunction('$toEthSignedMessageHash(bytes)')(message)).to.eventually.equal(expectedHash);
});
it('version match for bytes32', async function () {
@ -39,7 +41,20 @@ describe('MessageHashUtils', function () {
});
describe('toDataWithIntendedValidatorHash', function () {
it('returns the digest correctly', async function () {
it('returns the digest of `bytes32 messageHash` correctly', async function () {
const verifier = ethers.Wallet.createRandom().address;
const message = ethers.randomBytes(32);
const expectedHash = ethers.solidityPackedKeccak256(
['string', 'address', 'bytes32'],
['\x19\x00', verifier, message],
);
await expect(
this.mock.getFunction('$toDataWithIntendedValidatorHash(address,bytes32)')(verifier, message),
).to.eventually.equal(expectedHash);
});
it('returns the digest of `bytes memory message` correctly', async function () {
const verifier = ethers.Wallet.createRandom().address;
const message = ethers.randomBytes(128);
const expectedHash = ethers.solidityPackedKeccak256(
@ -47,7 +62,21 @@ describe('MessageHashUtils', function () {
['\x19\x00', verifier, message],
);
expect(await this.mock.$toDataWithIntendedValidatorHash(verifier, message)).to.equal(expectedHash);
await expect(
this.mock.getFunction('$toDataWithIntendedValidatorHash(address,bytes)')(verifier, message),
).to.eventually.equal(expectedHash);
});
it('version match for bytes32', async function () {
const verifier = ethers.Wallet.createRandom().address;
const message = ethers.randomBytes(32);
const fixed = await this.mock.getFunction('$toDataWithIntendedValidatorHash(address,bytes)')(verifier, message);
const dynamic = await this.mock.getFunction('$toDataWithIntendedValidatorHash(address,bytes32)')(
verifier,
message,
);
expect(fixed).to.equal(dynamic);
});
});
@ -62,7 +91,7 @@ describe('MessageHashUtils', function () {
const structhash = ethers.randomBytes(32);
const expectedHash = hashTypedData(domain, structhash);
expect(await this.mock.$toTypedDataHash(domainSeparator(domain), structhash)).to.equal(expectedHash);
await expect(this.mock.$toTypedDataHash(domainSeparator(domain), structhash)).to.eventually.equal(expectedHash);
});
});
});