diff --git a/test/utils/cryptography/ECDSA.test.js b/test/utils/cryptography/ECDSA.test.js index 9062b6913f9..1afcb7f13bd 100644 --- a/test/utils/cryptography/ECDSA.test.js +++ b/test/utils/cryptography/ECDSA.test.js @@ -15,6 +15,8 @@ contract('ECDSA', function (accounts) { this.ecdsa = await ECDSAMock.new(); }); + + context('recover with invalid signature', function () { it('with short signature', async function () { await expectRevert(this.ecdsa.recover(TEST_MESSAGE, '0x1234'), 'ECDSA: invalid signature length'); @@ -30,6 +32,36 @@ contract('ECDSA', function (accounts) { }); context('recover with valid signature', function () { + context('using web3.eth.sign', function () { + context('with correct signature', function () { + it('returns signer address', async function () { + // Create the signature + const signature = fixSignature(await web3.eth.sign(TEST_MESSAGE, other)); + + // Recover the signer address from the generated message and signature. + expect(await this.ecdsa.recover( + toEthSignedMessageHash(TEST_MESSAGE), + signature, + )).to.equal(other); + }); + }); + + context('with wrong message', function () { + it('returns a different address', async function () { + const signature = fixSignature(await web3.eth.sign(TEST_MESSAGE, other)); + expect(await this.ecdsa.recover(WRONG_MESSAGE, signature)).to.not.equal(other); + }); + }); + + context('with invalid signature', function () { + it('reverts', async function () { + // eslint-disable-next-line max-len + const signature = '0x332ce75a821c982f9127538858900d87d3ec1f9f737338ad67cad133fa48feff48e6fa0c18abc62e42820f05943e47af3e9fbe306ce74d64094bdf1691ee53e01c'; + await expectRevert(this.ecdsa.recover(TEST_MESSAGE, signature), 'ECDSA: invalid signature'); + }); + }); + }); + context('with v0 signature', function () { // Signature generated outside ganache with method web3.eth.sign(signer, message) const signer = '0x2cc1166f6212628A0deEf2B33BEFB2187D35b86c'; @@ -104,36 +136,6 @@ contract('ECDSA', function (accounts) { await expectRevert(this.ecdsa.recover(message, highSSignature), 'ECDSA: invalid signature \'s\' value'); }); }); - - context('using web3.eth.sign', function () { - context('with correct signature', function () { - it('returns signer address', async function () { - // Create the signature - const signature = fixSignature(await web3.eth.sign(TEST_MESSAGE, other)); - - // Recover the signer address from the generated message and signature. - expect(await this.ecdsa.recover( - toEthSignedMessageHash(TEST_MESSAGE), - signature, - )).to.equal(other); - }); - }); - - context('with wrong message', function () { - it('returns a different address', async function () { - const signature = fixSignature(await web3.eth.sign(TEST_MESSAGE, other)); - expect(await this.ecdsa.recover(WRONG_MESSAGE, signature)).to.not.equal(other); - }); - }); - - context('with invalid signature', function () { - it('reverts', async function () { - // eslint-disable-next-line max-len - const signature = '0x332ce75a821c982f9127538858900d87d3ec1f9f737338ad67cad133fa48feff48e6fa0c18abc62e42820f05943e47af3e9fbe306ce74d64094bdf1691ee53e01c'; - await expectRevert(this.ecdsa.recover(TEST_MESSAGE, signature), 'ECDSA: invalid signature'); - }); - }); - }); }); context('toEthSignedMessage', function () {