Skip to content

Commit

Permalink
test factorisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx authored Jan 12, 2023
1 parent a0bda75 commit 4ccf3d9
Showing 1 changed file with 42 additions and 82 deletions.
124 changes: 42 additions & 82 deletions test/utils/cryptography/SignatureChecker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,88 +40,48 @@ contract('SignatureChecker (ERC1271)', function (accounts) {
});

context('ERC1271 wallet', function () {
context('when testing isValidERC1271SignatureNow', function () {
it('with matching signer and signature', async function () {
expect(
await this.signaturechecker.$isValidERC1271SignatureNow(
this.wallet.address,
toEthSignedMessageHash(TEST_MESSAGE),
this.signature,
),
).to.equal(true);
for (const signature of ['isValidERC1271SignatureNow', 'isValidSignatureNow']) {
context(signature, function () {
it('with matching signer and signature', async function () {
expect(
await this.signaturechecker[`$${signature}`](
this.wallet.address,
toEthSignedMessageHash(TEST_MESSAGE),
this.signature,
),
).to.equal(true);
});

it('with invalid signer', async function () {
expect(
await this.signaturechecker[`$${signature}`](
this.signaturechecker.address,
toEthSignedMessageHash(TEST_MESSAGE),
this.signature,
),
).to.equal(false);
});

it('with invalid signature', async function () {
expect(
await this.signaturechecker[`$${signature}`](
this.wallet.address,
toEthSignedMessageHash(WRONG_MESSAGE),
this.signature,
),
).to.equal(false);
});

it('with malicious wallet', async function () {
expect(
await this.signaturechecker[`$${signature}`](
this.malicious.address,
toEthSignedMessageHash(TEST_MESSAGE),
this.signature,
),
).to.equal(false);
});
});

it('with invalid signer', async function () {
expect(
await this.signaturechecker.$isValidERC1271SignatureNow(
this.signaturechecker.address,
toEthSignedMessageHash(TEST_MESSAGE),
this.signature,
),
).to.equal(false);
});

it('with invalid signature', async function () {
expect(
await this.signaturechecker.$isValidERC1271SignatureNow(
this.wallet.address,
toEthSignedMessageHash(WRONG_MESSAGE),
this.signature,
),
).to.equal(false);
});

it('with malicious wallet', async function () {
expect(
await this.signaturechecker.$isValidERC1271SignatureNow(
this.malicious.address,
toEthSignedMessageHash(TEST_MESSAGE),
this.signature,
),
).to.equal(false);
});
});

context('when testing isValidSignatureNow', function () {
it('with matching signer and signature', async function () {
expect(
await this.signaturechecker.$isValidSignatureNow(
this.wallet.address,
toEthSignedMessageHash(TEST_MESSAGE),
this.signature,
),
).to.equal(true);
});

it('with invalid signer', async function () {
expect(
await this.signaturechecker.$isValidSignatureNow(
this.signaturechecker.address,
toEthSignedMessageHash(TEST_MESSAGE),
this.signature,
),
).to.equal(false);
});

it('with invalid signature', async function () {
expect(
await this.signaturechecker.$isValidSignatureNow(
this.wallet.address,
toEthSignedMessageHash(WRONG_MESSAGE),
this.signature,
),
).to.equal(false);
});

it('with malicious wallet', async function () {
expect(
await this.signaturechecker.$isValidSignatureNow(
this.malicious.address,
toEthSignedMessageHash(TEST_MESSAGE),
this.signature,
),
).to.equal(false);
});
});
}
});
});

0 comments on commit 4ccf3d9

Please sign in to comment.