Add more test cases for EIP712 (#4212)
This commit is contained in:
@ -111,6 +111,8 @@ abstract contract EIP712 is IERC5267 {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev See {EIP-5267}.
|
* @dev See {EIP-5267}.
|
||||||
|
*
|
||||||
|
* _Available since v4.9._
|
||||||
*/
|
*/
|
||||||
function eip712Domain()
|
function eip712Domain()
|
||||||
public
|
public
|
||||||
|
|||||||
@ -6,13 +6,24 @@ const { getChainId } = require('../../helpers/chainid');
|
|||||||
const { mapValues } = require('../../helpers/map-values');
|
const { mapValues } = require('../../helpers/map-values');
|
||||||
|
|
||||||
const EIP712Verifier = artifacts.require('$EIP712Verifier');
|
const EIP712Verifier = artifacts.require('$EIP712Verifier');
|
||||||
|
const Clones = artifacts.require('$Clones');
|
||||||
|
|
||||||
contract('EIP712', function (accounts) {
|
contract('EIP712', function (accounts) {
|
||||||
const [mailTo] = accounts;
|
const [mailTo] = accounts;
|
||||||
|
|
||||||
const name = 'A Name';
|
const shortName = 'A Name';
|
||||||
const version = '1';
|
const shortVersion = '1';
|
||||||
|
|
||||||
|
const longName = 'A'.repeat(40);
|
||||||
|
const longVersion = 'B'.repeat(40);
|
||||||
|
|
||||||
|
const cases = [
|
||||||
|
['short', shortName, shortVersion],
|
||||||
|
['long', longName, longVersion],
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const [shortOrLong, name, version] of cases) {
|
||||||
|
describe(`with ${shortOrLong} name and version`, function () {
|
||||||
beforeEach('deploying', async function () {
|
beforeEach('deploying', async function () {
|
||||||
this.eip712 = await EIP712Verifier.new(name, version);
|
this.eip712 = await EIP712Verifier.new(name, version);
|
||||||
|
|
||||||
@ -36,6 +47,26 @@ contract('EIP712', function (accounts) {
|
|||||||
const rebuildDomain = await getDomain(this.eip712);
|
const rebuildDomain = await getDomain(this.eip712);
|
||||||
expect(mapValues(rebuildDomain, String)).to.be.deep.equal(mapValues(this.domain, String));
|
expect(mapValues(rebuildDomain, String)).to.be.deep.equal(mapValues(this.domain, String));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (shortOrLong === 'short') {
|
||||||
|
// Long strings are in storage, and the proxy will not be properly initialized unless
|
||||||
|
// the upgradeable contract variant is used and the initializer is invoked.
|
||||||
|
|
||||||
|
it('adjusts when behind proxy', async function () {
|
||||||
|
const factory = await Clones.new();
|
||||||
|
const cloneReceipt = await factory.$clone(this.eip712.address);
|
||||||
|
const cloneAddress = cloneReceipt.logs.find(({ event }) => event === 'return$clone').args.instance;
|
||||||
|
const clone = new EIP712Verifier(cloneAddress);
|
||||||
|
|
||||||
|
const cloneDomain = { ...this.domain, verifyingContract: clone.address };
|
||||||
|
|
||||||
|
const expectedSeparator = await domainSeparator(cloneDomain);
|
||||||
|
expect(await clone.$_domainSeparatorV4()).to.equal(expectedSeparator);
|
||||||
|
|
||||||
|
const reportedDomain = await getDomain(clone);
|
||||||
|
expect(mapValues(reportedDomain, String)).to.be.deep.equal(mapValues(cloneDomain, String));
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('hash digest', async function () {
|
it('hash digest', async function () {
|
||||||
@ -68,3 +99,5 @@ contract('EIP712', function (accounts) {
|
|||||||
await this.eip712.verify(signature, wallet.getAddressString(), message.to, message.contents);
|
await this.eip712.verify(signature, wallet.getAddressString(), message.to, message.contents);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user