Skip to content

Commit 938a92b

Browse files
committed
Merge branch 'master' into feat/eip1363-v5.x
2 parents 341a687 + 88211e8 commit 938a92b

30 files changed

+2001
-2414
lines changed

test/governance/Governor.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ const ethSigUtil = require('eth-sig-util');
44
const Wallet = require('ethereumjs-wallet').default;
55

66
const Enums = require('../helpers/enums');
7-
const {
8-
getDomain,
9-
domainType,
10-
types: { Ballot },
11-
} = require('../helpers/eip712');
7+
const { getDomain, domainType, Ballot } = require('../helpers/eip712');
128
const { GovernorHelper, proposalStatesToBitMap } = require('../helpers/governance');
139
const { clockFromReceipt } = require('../helpers/time');
1410
const { expectRevertCustomError } = require('../helpers/customError');

test/governance/extensions/GovernorWithParams.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ const ethSigUtil = require('eth-sig-util');
44
const Wallet = require('ethereumjs-wallet').default;
55

66
const Enums = require('../../helpers/enums');
7-
const {
8-
getDomain,
9-
domainType,
10-
types: { ExtendedBallot },
11-
} = require('../../helpers/eip712');
7+
const { getDomain, domainType, ExtendedBallot } = require('../../helpers/eip712');
128
const { GovernorHelper } = require('../../helpers/governance');
139
const { expectRevertCustomError } = require('../../helpers/customError');
1410

test/governance/utils/Votes.behavior.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ const ethSigUtil = require('eth-sig-util');
77
const Wallet = require('ethereumjs-wallet').default;
88

99
const { shouldBehaveLikeERC6372 } = require('./ERC6372.behavior');
10-
const {
11-
getDomain,
12-
domainType,
13-
types: { Delegation },
14-
} = require('../../helpers/eip712');
10+
const { getDomain, domainType, Delegation } = require('../../helpers/eip712');
1511
const { clockFromReceipt } = require('../../helpers/time');
1612
const { expectRevertCustomError } = require('../../helpers/customError');
1713

test/helpers/eip712-types.js

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,52 @@
1-
module.exports = {
2-
EIP712Domain: [
3-
{ name: 'name', type: 'string' },
4-
{ name: 'version', type: 'string' },
5-
{ name: 'chainId', type: 'uint256' },
6-
{ name: 'verifyingContract', type: 'address' },
7-
{ name: 'salt', type: 'bytes32' },
8-
],
9-
Permit: [
10-
{ name: 'owner', type: 'address' },
11-
{ name: 'spender', type: 'address' },
12-
{ name: 'value', type: 'uint256' },
13-
{ name: 'nonce', type: 'uint256' },
14-
{ name: 'deadline', type: 'uint256' },
15-
],
16-
Ballot: [
17-
{ name: 'proposalId', type: 'uint256' },
18-
{ name: 'support', type: 'uint8' },
19-
{ name: 'voter', type: 'address' },
20-
{ name: 'nonce', type: 'uint256' },
21-
],
22-
ExtendedBallot: [
23-
{ name: 'proposalId', type: 'uint256' },
24-
{ name: 'support', type: 'uint8' },
25-
{ name: 'voter', type: 'address' },
26-
{ name: 'nonce', type: 'uint256' },
27-
{ name: 'reason', type: 'string' },
28-
{ name: 'params', type: 'bytes' },
29-
],
30-
Delegation: [
31-
{ name: 'delegatee', type: 'address' },
32-
{ name: 'nonce', type: 'uint256' },
33-
{ name: 'expiry', type: 'uint256' },
34-
],
35-
ForwardRequest: [
36-
{ name: 'from', type: 'address' },
37-
{ name: 'to', type: 'address' },
38-
{ name: 'value', type: 'uint256' },
39-
{ name: 'gas', type: 'uint256' },
40-
{ name: 'nonce', type: 'uint256' },
41-
{ name: 'deadline', type: 'uint48' },
42-
{ name: 'data', type: 'bytes' },
43-
],
44-
};
1+
const { mapValues } = require('./iterate');
2+
3+
const formatType = schema => Object.entries(schema).map(([name, type]) => ({ name, type }));
4+
5+
module.exports = mapValues(
6+
{
7+
EIP712Domain: {
8+
name: 'string',
9+
version: 'string',
10+
chainId: 'uint256',
11+
verifyingContract: 'address',
12+
salt: 'bytes32',
13+
},
14+
Permit: {
15+
owner: 'address',
16+
spender: 'address',
17+
value: 'uint256',
18+
nonce: 'uint256',
19+
deadline: 'uint256',
20+
},
21+
Ballot: {
22+
proposalId: 'uint256',
23+
support: 'uint8',
24+
voter: 'address',
25+
nonce: 'uint256',
26+
},
27+
ExtendedBallot: {
28+
proposalId: 'uint256',
29+
support: 'uint8',
30+
voter: 'address',
31+
nonce: 'uint256',
32+
reason: 'string',
33+
params: 'bytes',
34+
},
35+
Delegation: {
36+
delegatee: 'address',
37+
nonce: 'uint256',
38+
expiry: 'uint256',
39+
},
40+
ForwardRequest: {
41+
from: 'address',
42+
to: 'address',
43+
value: 'uint256',
44+
gas: 'uint256',
45+
nonce: 'uint256',
46+
deadline: 'uint48',
47+
data: 'bytes',
48+
},
49+
},
50+
formatType,
51+
);
52+
module.exports.formatType = formatType;

test/helpers/eip712.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ function hashTypedData(domain, structHash) {
3838
}
3939

4040
module.exports = {
41-
types,
4241
getDomain,
4342
domainType,
4443
domainSeparator: ethers.TypedDataEncoder.hashDomain,
4544
hashTypedData,
45+
...types,
4646
};

test/helpers/time.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const { time, mineUpTo } = require('@nomicfoundation/hardhat-network-helpers');
2-
3-
const mapObject = (obj, fn) => Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, fn(value)]));
2+
const { mapValues } = require('./iterate');
43

54
module.exports = {
65
clock: {
@@ -22,8 +21,8 @@ module.exports = {
2221

2322
// TODO: deprecate the old version in favor of this one
2423
module.exports.bigint = {
25-
clock: mapObject(module.exports.clock, fn => () => fn().then(BigInt)),
26-
clockFromReceipt: mapObject(module.exports.clockFromReceipt, fn => receipt => fn(receipt).then(BigInt)),
24+
clock: mapValues(module.exports.clock, fn => () => fn().then(BigInt)),
25+
clockFromReceipt: mapValues(module.exports.clockFromReceipt, fn => receipt => fn(receipt).then(BigInt)),
2726
forward: module.exports.forward,
28-
duration: mapObject(module.exports.duration, fn => n => BigInt(fn(n))),
27+
duration: mapValues(module.exports.duration, fn => n => BigInt(fn(n))),
2928
};

test/metatx/ERC2771Context.test.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { expect } = require('chai');
33
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
44

55
const { impersonate } = require('../helpers/account');
6-
const { getDomain } = require('../helpers/eip712');
6+
const { getDomain, ForwardRequest } = require('../helpers/eip712');
77
const { MAX_UINT48 } = require('../helpers/constants');
88

99
const { shouldBehaveLikeRegularContext } = require('../utils/Context.behavior');
@@ -15,17 +15,7 @@ async function fixture() {
1515
const forwarderAsSigner = await impersonate(forwarder.target);
1616
const context = await ethers.deployContract('ERC2771ContextMock', [forwarder]);
1717
const domain = await getDomain(forwarder);
18-
const types = {
19-
ForwardRequest: [
20-
{ name: 'from', type: 'address' },
21-
{ name: 'to', type: 'address' },
22-
{ name: 'value', type: 'uint256' },
23-
{ name: 'gas', type: 'uint256' },
24-
{ name: 'nonce', type: 'uint256' },
25-
{ name: 'deadline', type: 'uint48' },
26-
{ name: 'data', type: 'bytes' },
27-
],
28-
};
18+
const types = { ForwardRequest };
2919

3020
return { sender, other, forwarder, forwarderAsSigner, context, domain, types };
3121
}

test/metatx/ERC2771Forwarder.test.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { ethers } = require('hardhat');
22
const { expect } = require('chai');
33
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
44

5-
const { getDomain } = require('../helpers/eip712');
5+
const { getDomain, ForwardRequest } = require('../helpers/eip712');
66
const { bigint: time } = require('../helpers/time');
77
const { sum } = require('../helpers/math');
88

@@ -12,17 +12,7 @@ async function fixture() {
1212
const forwarder = await ethers.deployContract('ERC2771Forwarder', ['ERC2771Forwarder']);
1313
const receiver = await ethers.deployContract('CallReceiverMockTrustingForwarder', [forwarder]);
1414
const domain = await getDomain(forwarder);
15-
const types = {
16-
ForwardRequest: [
17-
{ name: 'from', type: 'address' },
18-
{ name: 'to', type: 'address' },
19-
{ name: 'value', type: 'uint256' },
20-
{ name: 'gas', type: 'uint256' },
21-
{ name: 'nonce', type: 'uint256' },
22-
{ name: 'deadline', type: 'uint48' },
23-
{ name: 'data', type: 'bytes' },
24-
],
25-
};
15+
const types = { ForwardRequest };
2616

2717
const forgeRequest = async (override = {}, signer = sender) => {
2818
const req = {

test/token/ERC20/extensions/ERC20Burnable.behavior.js

Lines changed: 0 additions & 116 deletions
This file was deleted.

0 commit comments

Comments
 (0)