Move ECDSA message hash methods to its own MessageHashUtils library (#4430)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com> Co-authored-by: Francisco <fg@frang.io>
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
require('@openzeppelin/test-helpers');
|
||||
const { expectRevertCustomError } = require('../../helpers/customError');
|
||||
const { toEthSignedMessageHash, toDataWithIntendedValidatorHash } = require('../../helpers/sign');
|
||||
const { toEthSignedMessageHash } = require('../../helpers/sign');
|
||||
|
||||
const { expect } = require('chai');
|
||||
|
||||
@ -9,7 +9,6 @@ const ECDSA = artifacts.require('$ECDSA');
|
||||
const TEST_MESSAGE = web3.utils.sha3('OpenZeppelin');
|
||||
const WRONG_MESSAGE = web3.utils.sha3('Nope');
|
||||
const NON_HASH_MESSAGE = '0x' + Buffer.from('abcd').toString('hex');
|
||||
const RANDOM_ADDRESS = web3.utils.toChecksumAddress(web3.utils.randomHex(20));
|
||||
|
||||
function to2098Format(signature) {
|
||||
const long = web3.utils.hexToBytes(signature);
|
||||
@ -243,26 +242,4 @@ contract('ECDSA', function (accounts) {
|
||||
expect(() => to2098Format(highSSignature)).to.throw("invalid signature 's' value");
|
||||
});
|
||||
});
|
||||
|
||||
context('toEthSignedMessageHash', function () {
|
||||
it('prefixes bytes32 data correctly', async function () {
|
||||
expect(await this.ecdsa.methods['$toEthSignedMessageHash(bytes32)'](TEST_MESSAGE)).to.equal(
|
||||
toEthSignedMessageHash(TEST_MESSAGE),
|
||||
);
|
||||
});
|
||||
|
||||
it('prefixes dynamic length data correctly', async function () {
|
||||
expect(await this.ecdsa.methods['$toEthSignedMessageHash(bytes)'](NON_HASH_MESSAGE)).to.equal(
|
||||
toEthSignedMessageHash(NON_HASH_MESSAGE),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
context('toDataWithIntendedValidatorHash', function () {
|
||||
it('returns the hash correctly', async function () {
|
||||
expect(
|
||||
await this.ecdsa.methods['$toDataWithIntendedValidatorHash(address,bytes)'](RANDOM_ADDRESS, NON_HASH_MESSAGE),
|
||||
).to.equal(toDataWithIntendedValidatorHash(RANDOM_ADDRESS, NON_HASH_MESSAGE));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user