From ff9f10c5b319b413574a4bffb00f1811d03dd550 Mon Sep 17 00:00:00 2001 From: Theo Date: Sat, 27 May 2023 17:17:58 +0300 Subject: [PATCH] Get actual account nonce while signing messages to ERC20Permit --- test/ProposalUtils.sol | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/ProposalUtils.sol b/test/ProposalUtils.sol index 9e4f7a0..993d4cd 100644 --- a/test/ProposalUtils.sol +++ b/test/ProposalUtils.sol @@ -4,6 +4,8 @@ pragma experimental ABIEncoderV2; import { Test } from "@forge-std/Test.sol"; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import { ERC20Permit } from "torn-token/contracts/ERC20Permit.sol"; +import { console2 } from "@forge-std/console2.sol"; import { Mock } from "./Mock.sol"; import { Proposal, IGovernance } from "@interfaces/IGovernance.sol"; @@ -53,12 +55,15 @@ contract ProposalUtils is Mock, Parameters, Test { function retrieveAndLockBalance(uint256 privateKey, address voter, uint256 amount) internal { uint256 lockTimestamp = block.timestamp + PROPOSAL_DURATION; + uint256 accountNonce = ERC20Permit(_tokenAddress).nonces(voter); + + console2.log("Account nonce: %s", accountNonce); bytes32 messageHash = keccak256( abi.encodePacked( PERMIT_FUNC_SELECTOR, EIP712_DOMAIN, - keccak256(abi.encode(PERMIT_TYPEHASH, voter, _governanceAddress, amount, 0, lockTimestamp)) + keccak256(abi.encode(PERMIT_TYPEHASH, voter, _governanceAddress, amount, accountNonce, lockTimestamp)) ) );