diff --git a/script/DeployContracts.s.sol b/script/DeployContracts.s.sol index f18171b..4d32795 100644 --- a/script/DeployContracts.s.sol +++ b/script/DeployContracts.s.sol @@ -129,6 +129,7 @@ contract DeployContracts is Script { govToken.grantRole(govToken.MINTER_ROLE(), address(votingPowerExchange)); // give exchange the burner role of utilityToken utilityToken.grantRole(utilityToken.BURNER_ROLE(), address(votingPowerExchange)); + govToken.grantRole(govToken.VOTING_POWER_EXCHANGE_ROLE(), address(votingPowerExchange)); vm.stopPrank(); return DeploymentResult({ diff --git a/src/VotingPowerExchange.sol b/src/VotingPowerExchange.sol index 935837c..f2c85e4 100644 --- a/src/VotingPowerExchange.sol +++ b/src/VotingPowerExchange.sol @@ -132,7 +132,7 @@ contract VotingPowerExchange is AccessControl, EIP712 { } // burn utilityToken from the `sender` - utilityToken.burnByBurner(msg.sender, burningTokenAmount); + utilityToken.burnByBurner(sender, burningTokenAmount); // update the burned amount of the `sender` govToken.setBurnedAmountOfUtilToken(sender, currentBurnedAmount + burningTokenAmount); diff --git a/test/integration/VotingPowerExchange.t.sol b/test/integration/VotingPowerExchange.t.sol index 171ab34..53ed1cd 100644 --- a/test/integration/VotingPowerExchange.t.sol +++ b/test/integration/VotingPowerExchange.t.sol @@ -398,9 +398,15 @@ contract VotingPwoerExchangeTest is Test { /////// Exchange tests /////// function testExchangeCase1() public { bytes32 nonce = bytes32(0); - bytes memory signature = helper.generateSignatureFromPrivateKey(dc.DEFAULT_ANVIL_KEY2(), 620 * 1e18, nonce, block.timestamp + 3600); + console.log(block.chainid); + console.log("Signer address:", vm.addr(dc.DEFAULT_ANVIL_KEY2())); + console.log("participant2 address:", participant2); + + bytes memory signature = helper.generateSignatureFromPrivateKey(dc.DEFAULT_ANVIL_KEY2(), 1_000 * 1e18, nonce, 3600, address(votingPowerExchange)); + address signer = vm.addr(dc.DEFAULT_ANVIL_KEY2()); vm.startPrank(exchanger); - votingPowerExchange.exchange(participant, 100_000 * 1e18, nonce, block.timestamp + 3600, signature); + votingPowerExchange.exchange(signer, 1_000 * 1e18, nonce, 3600, signature); vm.stopPrank(); + } } diff --git a/test/integration/utils/VotingPowerExchangeTestHelper.t.sol b/test/integration/utils/VotingPowerExchangeTestHelper.t.sol index 967e3e1..73820c4 100644 --- a/test/integration/utils/VotingPowerExchangeTestHelper.t.sol +++ b/test/integration/utils/VotingPowerExchangeTestHelper.t.sol @@ -6,17 +6,19 @@ import {DeployContracts, DeploymentResult} from "script/DeployContracts.s.sol"; import {Test, console} from "forge-std/Test.sol"; import {VotingPowerExchange} from "src/VotingPowerExchange.sol"; +import {MessageHashUtils} from "lib/openzeppelin-contracts/contracts/utils/cryptography/MessageHashUtils.sol"; contract VotingPowerExchangeTestHelper is Test { bytes32 private constant _EXCHANGE_TYPEHASH = keccak256("Exchange(address sender,uint256 amount,bytes32 nonce,uint256 expiration)"); - function generateSignatureFromPrivateKey(uint256 privateKey, uint256 amount, bytes32 nonce, uint256 expiration) + function generateSignatureFromPrivateKey(uint256 privateKey, uint256 amount, bytes32 nonce, uint256 expiration, address exchangeAddr) public view returns (bytes memory) { - address sender = address(uint160(privateKey)); + address sender = vm.addr(privateKey); + console.log("sender", sender); bytes32 structHash = keccak256(abi.encode(_EXCHANGE_TYPEHASH, sender, amount, nonce, expiration)); bytes32 domainSeparator = keccak256( @@ -25,11 +27,11 @@ contract VotingPowerExchangeTestHelper is Test { keccak256(bytes("VotingPowerExchange")), keccak256(bytes("1")), block.chainid, - address(this) + exchangeAddr ) ); - bytes32 hash = keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash)); + bytes32 hash = MessageHashUtils.toTypedDataHash(domainSeparator, structHash); (uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, hash);