Include EIP-5267 discovery in EIP-712 (#3969)
Co-authored-by: Francisco <frangio.1@gmail.com> Co-authored-by: Francisco <fg@frang.io>
This commit is contained in:
@ -11,7 +11,7 @@ const Wallet = require('ethereumjs-wallet').default;
|
||||
const ERC20Votes = artifacts.require('$ERC20Votes');
|
||||
|
||||
const { batchInBlock } = require('../../../helpers/txpool');
|
||||
const { EIP712Domain, domainSeparator } = require('../../../helpers/eip712');
|
||||
const { getDomain, domainType, domainSeparator } = require('../../../helpers/eip712');
|
||||
const { getChainId } = require('../../../helpers/chainid');
|
||||
|
||||
const Delegation = [
|
||||
@ -38,9 +38,7 @@ contract('ERC20Votes', function (accounts) {
|
||||
});
|
||||
|
||||
it('domain separator', async function () {
|
||||
expect(await this.token.DOMAIN_SEPARATOR()).to.equal(
|
||||
await domainSeparator({ name, version, chainId: this.chainId, verifyingContract: this.token.address }),
|
||||
);
|
||||
expect(await this.token.DOMAIN_SEPARATOR()).to.equal(await getDomain(this.token).then(domainSeparator));
|
||||
});
|
||||
|
||||
it('minting restriction', async function () {
|
||||
@ -107,30 +105,26 @@ contract('ERC20Votes', function (accounts) {
|
||||
const delegatorAddress = web3.utils.toChecksumAddress(delegator.getAddressString());
|
||||
const nonce = 0;
|
||||
|
||||
const buildData = (chainId, verifyingContract, message) => ({
|
||||
data: {
|
||||
const buildData = (contract, message) =>
|
||||
getDomain(contract).then(domain => ({
|
||||
primaryType: 'Delegation',
|
||||
types: { EIP712Domain, Delegation },
|
||||
domain: { name, version, chainId, verifyingContract },
|
||||
types: { EIP712Domain: domainType(domain), Delegation },
|
||||
domain,
|
||||
message,
|
||||
},
|
||||
});
|
||||
}));
|
||||
|
||||
beforeEach(async function () {
|
||||
await this.token.$_mint(delegatorAddress, supply);
|
||||
});
|
||||
|
||||
it('accept signed delegation', async function () {
|
||||
const { v, r, s } = fromRpcSig(
|
||||
ethSigUtil.signTypedMessage(
|
||||
delegator.getPrivateKey(),
|
||||
buildData(this.chainId, this.token.address, {
|
||||
delegatee: delegatorAddress,
|
||||
nonce,
|
||||
expiry: MAX_UINT256,
|
||||
}),
|
||||
),
|
||||
);
|
||||
const { v, r, s } = await buildData(this.token, {
|
||||
delegatee: delegatorAddress,
|
||||
nonce,
|
||||
expiry: MAX_UINT256,
|
||||
})
|
||||
.then(data => ethSigUtil.signTypedMessage(delegator.getPrivateKey(), { data }))
|
||||
.then(fromRpcSig);
|
||||
|
||||
expect(await this.token.delegates(delegatorAddress)).to.be.equal(ZERO_ADDRESS);
|
||||
|
||||
@ -155,16 +149,13 @@ contract('ERC20Votes', function (accounts) {
|
||||
});
|
||||
|
||||
it('rejects reused signature', async function () {
|
||||
const { v, r, s } = fromRpcSig(
|
||||
ethSigUtil.signTypedMessage(
|
||||
delegator.getPrivateKey(),
|
||||
buildData(this.chainId, this.token.address, {
|
||||
delegatee: delegatorAddress,
|
||||
nonce,
|
||||
expiry: MAX_UINT256,
|
||||
}),
|
||||
),
|
||||
);
|
||||
const { v, r, s } = await buildData(this.token, {
|
||||
delegatee: delegatorAddress,
|
||||
nonce,
|
||||
expiry: MAX_UINT256,
|
||||
})
|
||||
.then(data => ethSigUtil.signTypedMessage(delegator.getPrivateKey(), { data }))
|
||||
.then(fromRpcSig);
|
||||
|
||||
await this.token.delegateBySig(delegatorAddress, nonce, MAX_UINT256, v, r, s);
|
||||
|
||||
@ -175,16 +166,13 @@ contract('ERC20Votes', function (accounts) {
|
||||
});
|
||||
|
||||
it('rejects bad delegatee', async function () {
|
||||
const { v, r, s } = fromRpcSig(
|
||||
ethSigUtil.signTypedMessage(
|
||||
delegator.getPrivateKey(),
|
||||
buildData(this.chainId, this.token.address, {
|
||||
delegatee: delegatorAddress,
|
||||
nonce,
|
||||
expiry: MAX_UINT256,
|
||||
}),
|
||||
),
|
||||
);
|
||||
const { v, r, s } = await buildData(this.token, {
|
||||
delegatee: delegatorAddress,
|
||||
nonce,
|
||||
expiry: MAX_UINT256,
|
||||
})
|
||||
.then(data => ethSigUtil.signTypedMessage(delegator.getPrivateKey(), { data }))
|
||||
.then(fromRpcSig);
|
||||
|
||||
const receipt = await this.token.delegateBySig(holderDelegatee, nonce, MAX_UINT256, v, r, s);
|
||||
const { args } = receipt.logs.find(({ event }) => event == 'DelegateChanged');
|
||||
@ -194,16 +182,14 @@ contract('ERC20Votes', function (accounts) {
|
||||
});
|
||||
|
||||
it('rejects bad nonce', async function () {
|
||||
const { v, r, s } = fromRpcSig(
|
||||
ethSigUtil.signTypedMessage(
|
||||
delegator.getPrivateKey(),
|
||||
buildData(this.chainId, this.token.address, {
|
||||
delegatee: delegatorAddress,
|
||||
nonce,
|
||||
expiry: MAX_UINT256,
|
||||
}),
|
||||
),
|
||||
);
|
||||
const { v, r, s } = await buildData(this.token, {
|
||||
delegatee: delegatorAddress,
|
||||
nonce,
|
||||
expiry: MAX_UINT256,
|
||||
})
|
||||
.then(data => ethSigUtil.signTypedMessage(delegator.getPrivateKey(), { data }))
|
||||
.then(fromRpcSig);
|
||||
|
||||
await expectRevert(
|
||||
this.token.delegateBySig(delegatorAddress, nonce + 1, MAX_UINT256, v, r, s),
|
||||
'ERC20Votes: invalid nonce',
|
||||
@ -212,16 +198,14 @@ contract('ERC20Votes', function (accounts) {
|
||||
|
||||
it('rejects expired permit', async function () {
|
||||
const expiry = (await time.latest()) - time.duration.weeks(1);
|
||||
const { v, r, s } = fromRpcSig(
|
||||
ethSigUtil.signTypedMessage(
|
||||
delegator.getPrivateKey(),
|
||||
buildData(this.chainId, this.token.address, {
|
||||
delegatee: delegatorAddress,
|
||||
nonce,
|
||||
expiry,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
const { v, r, s } = await buildData(this.token, {
|
||||
delegatee: delegatorAddress,
|
||||
nonce,
|
||||
expiry,
|
||||
})
|
||||
.then(data => ethSigUtil.signTypedMessage(delegator.getPrivateKey(), { data }))
|
||||
.then(fromRpcSig);
|
||||
|
||||
await expectRevert(
|
||||
this.token.delegateBySig(delegatorAddress, nonce, expiry, v, r, s),
|
||||
|
||||
Reference in New Issue
Block a user