Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply review suggestions
Co-authored-by: Hadrien Croubois <[email protected]>
Co-authored-by: Francisco <[email protected]>
  • Loading branch information
3 people committed Jul 4, 2023
commit c0fab294626337fe3f54080d0a8c794a528d89fe
48 changes: 27 additions & 21 deletions test/governance/Governor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,24 +196,30 @@ contract('Governor', function (accounts) {
});

describe('vote with signature', function () {
beforeEach(async function () {
this.sign = privateKey => (contract, message) =>
getDomain(contract)
.then(domain => ({
primaryType: 'Ballot',
types: {
EIP712Domain: domainType(domain),
Ballot: [
{ name: 'proposalId', type: 'uint256' },
{ name: 'support', type: 'uint8' },
{ name: 'voter', type: 'address' },
{ name: 'nonce', type: 'uint256' },
],
},
domain,
message,
}))
.then(data => ethSigUtil.signTypedMessage(privateKey, { data }));
const sign = privateKey => async (contract, message) => {
const domain = await getDomain(contract);
return ethSigUtil.signTypedMessage(privateKey, {
data: {
primaryType: 'Ballot',
types: {
EIP712Domain: domainType(domain),
Ballot: [
{ name: 'proposalId', type: 'uint256' },
{ name: 'support', type: 'uint8' },
{ name: 'voter', type: 'address' },
{ name: 'nonce', type: 'uint256' },
],
},
domain,
message,
},
});
};

afterEach('no other votes are cast for proposalId', async function () {
expect(await this.mock.hasVoted(this.proposal.id, owner)).to.be.equal(false);
expect(await this.mock.hasVoted(this.proposal.id, voter1)).to.be.equal(false);
expect(await this.mock.hasVoted(this.proposal.id, voter2)).to.be.equal(false);
});

it('votes with an EOA signature', async function () {
Expand All @@ -232,7 +238,7 @@ contract('Governor', function (accounts) {
support: Enums.VoteType.For,
voter: voterBySigAddress,
nonce,
signature: this.sign(voterBySig.getPrivateKey()),
signature: sign(voterBySig.getPrivateKey()),
}),
'VoteCast',
{
Expand Down Expand Up @@ -266,7 +272,7 @@ contract('Governor', function (accounts) {
support: Enums.VoteType.For,
voter: wallet.address,
nonce,
signature: this.sign(ERC1271WalletOwner.getPrivateKey()),
signature: sign(ERC1271WalletOwner.getPrivateKey()),
}),
'VoteCast',
{
Expand All @@ -282,7 +288,7 @@ contract('Governor', function (accounts) {
expect(await this.mock.nonces(wallet.address)).to.be.bignumber.equal(nonce.addn(1));
});

afterEach(async function () {
afterEach('no other votes are cast', async function () {
expect(await this.mock.hasVoted(this.proposal.id, owner)).to.be.equal(false);
expect(await this.mock.hasVoted(this.proposal.id, voter1)).to.be.equal(false);
expect(await this.mock.hasVoted(this.proposal.id, voter2)).to.be.equal(false);
Expand Down
6 changes: 3 additions & 3 deletions test/governance/extensions/GovernorWithParams.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ contract('GovernorWithParams', function (accounts) {
expect(votes.forVotes).to.be.bignumber.equal(weight);
});

describe.only('voting by signature', function () {
describe('voting by signature', function () {
beforeEach(async function () {
this.voterBySig = Wallet.generate();
this.voterBySig.address = web3.utils.toChecksumAddress(this.voterBySig.getAddressString());
Expand All @@ -143,8 +143,8 @@ contract('GovernorWithParams', function (accounts) {
message,
}));

this.sign = privateKey => (contract, message) =>
this.data(contract, message).then(data => ethSigUtil.signTypedMessage(privateKey, { data }));
this.sign = privateKey => async (contract, message) =>
ethSigUtil.signTypedMessage(privateKey, { data: await this.data(contract, message) });
});

it('suports EOA signatures', async function () {
Expand Down