Skip to content

Commit

Permalink
adjusts vesting contracts & test suite to oz5 & solidity 8.24
Browse files Browse the repository at this point in the history
Signed-off-by: stadolf <stadolf@gmail.com>
  • Loading branch information
elmariachi111 committed Feb 24, 2024
1 parent 0e37f21 commit 7b862e4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 38 deletions.
43 changes: 22 additions & 21 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
TokenVestingMerkleTest:testCanOnlyClaimOnce() (gas: 308286)
TokenVestingMerkleTest:testCannotClaimWithoutTokens() (gas: 94109)
TokenVestingMerkleTest:testProofMustBeValid() (gas: 41172)
TokenVestingMerkleTest:testcanClaimSchedule() (gas: 305416)
TokenVestingTest:testCanOnlyBeRevokedIfRevokable() (gas: 306345)
TokenVestingTest:testCannotClaimMoreThanAvailable() (gas: 568697)
TokenVestingTest:testClaimAvailableTokens() (gas: 568743)
TokenVestingTest:testComputationMultipleForSchedules() (gas: 474575)
TokenVestingTest:testFuzzCreateAndRelease(uint256,uint256) (runs: 256, μ: 2439562, ~: 2442361)
TokenVestingTest:testGradualTokenVesting() (gas: 393032)
TokenVestingTest:testNativeTokenDecimals() (gas: 665021)
TokenVestingTest:testNonOwnerCannotCreateSchedule() (gas: 52168)
TokenVestingTest:testNonOwnerCannotRevokeSchedule() (gas: 308653)
TokenVestingTest:testNonTransferability() (gas: 312611)
TokenVestingTest:testRevokeScheduleReleasesVestedTokens() (gas: 340297)
TokenVestingTest:testScheduleIndexComputation() (gas: 8090)
TokenVestingTest:testTextInputParameterChecks() (gas: 76477)
TokenVestingTest:testTokenSupply() (gas: 12771)
TokenVestingTest:testVirtualTokenMeta() (gas: 15447)
TokenVestingTest:testVirtualTokenTotalSupplyAndBalance() (gas: 325425)
TokenVestingTest:testWrongToken() (gas: 119043)
TokenVestingMerkleTest:testCanOnlyClaimOnce() (gas: 308308)
TokenVestingMerkleTest:testCannotClaimWithoutTokens() (gas: 94202)
TokenVestingMerkleTest:testProofMustBeValid() (gas: 41195)
TokenVestingMerkleTest:testcanClaimSchedule() (gas: 305318)
TokenVestingTest:testCanOnlyBeRevokedIfRevokable() (gas: 308729)
TokenVestingTest:testCannotClaimMoreThanAvailable() (gas: 571392)
TokenVestingTest:testClaimAvailableTokens() (gas: 571393)
TokenVestingTest:testComputationMultipleForSchedules() (gas: 475186)
TokenVestingTest:testFuzzCreateAndRelease(uint256,uint256) (runs: 256, μ: 2517777, ~: 2518710)
TokenVestingTest:testGradualTokenVesting() (gas: 400975)
TokenVestingTest:testNativeTokenDecimals() (gas: 604228)
TokenVestingTest:testNonOwnerCannotRevokeSchedule() (gas: 311502)
TokenVestingTest:testNonTransferability() (gas: 316473)
TokenVestingTest:testOnlySchedulerRoleCanCreateSchedule() (gas: 53899)
TokenVestingTest:testRevokeScheduleReleasesVestedTokens() (gas: 342847)
TokenVestingTest:testScheduleIndexComputation() (gas: 8111)
TokenVestingTest:testTextInputParameterChecks() (gas: 77401)
TokenVestingTest:testTokenSupply() (gas: 12749)
TokenVestingTest:testVestingWithCliff() (gas: 314706)
TokenVestingTest:testVirtualTokenMeta() (gas: 15513)
TokenVestingTest:testVirtualTokenTotalSupplyAndBalance() (gas: 328198)
TokenVestingTest:testWrongToken() (gas: 119132)
8 changes: 4 additions & 4 deletions contracts/TokenVesting.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// contracts/TokenVesting.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.18;
pragma solidity 0.8.24;

import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol";

import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { Pausable } from "@openzeppelin/contracts/security/Pausable.sol";
import { Pausable } from "@openzeppelin/contracts/utils/Pausable.sol";

/// @title TokenVesting - On-Chain vesting scheme enabled by smart contracts.
/// The TokenVesting contract can release its token balance gradually like a
Expand Down Expand Up @@ -133,7 +133,7 @@ contract TokenVesting is IERC20Metadata, Ownable, ReentrancyGuard, Pausable, Acc
* @param _name name of the virtual token
* @param _symbol symbol of the virtual token
*/
constructor(IERC20Metadata token_, string memory _name, string memory _symbol) {
constructor(IERC20Metadata token_, string memory _name, string memory _symbol) Ownable(msg.sender) {
nativeToken = token_;
if (nativeToken.decimals() != 18) revert DecimalsError();
name = _name;
Expand Down
2 changes: 1 addition & 1 deletion contracts/TokenVestingMerkle.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// contracts/TokenVestingMerkle.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.18;
pragma solidity 0.8.24;

import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { TokenVesting } from "./TokenVesting.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/Token.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// contracts/Token.sol
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.18;
pragma solidity 0.8.24;

import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

Expand Down
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ src = 'contracts'
out = 'out'
libs = ['lib']
test = 'test'
solc_version = "0.8.18"
solc_version = "0.8.24"
gas_reports = ["TokenVesting", "TokenVestingMerkle"]

[fmt]
Expand Down
15 changes: 5 additions & 10 deletions test/TokenVesting.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ pragma solidity ^0.8.18;
import "forge-std/Test.sol";
import { console } from "forge-std/console.sol";
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

import {IAccessControl} from '@openzeppelin/contracts/access/IAccessControl.sol';
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { Token } from "../contracts/test/Token.sol";
import { TokenVesting } from "../contracts/TokenVesting.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
Expand Down Expand Up @@ -181,7 +182,7 @@ contract TokenVestingTest is Test {
bytes32 vestingScheduleId = tokenVesting.computeVestingScheduleIdForAddressAndIndex(alice, 0);

vm.startPrank(bob);
vm.expectRevert("Ownable: caller is not the owner");
vm.expectRevert(abi.encodeWithSelector(Ownable.OwnableUnauthorizedAccount.selector, bob));
tokenVesting.revoke(vestingScheduleId);
vm.stopPrank();
}
Expand Down Expand Up @@ -209,15 +210,9 @@ contract TokenVestingTest is Test {
token.transfer(address(tokenVesting), 100 ether);
vm.stopPrank();
vm.startPrank(alice);

bytes memory expectedError = abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(alice),
" is missing role ",
Strings.toHexString(uint256(tokenVesting.ROLE_CREATE_SCHEDULE()))
vm.expectRevert(
abi.encodeWithSelector(IAccessControl.AccessControlUnauthorizedAccount.selector, alice, tokenVesting.ROLE_CREATE_SCHEDULE())
);

vm.expectRevert(expectedError);
tokenVesting.createVestingSchedule(alice, baseTime, 0, duration, 1, true, 100 ether);
vm.stopPrank();
}
Expand Down

0 comments on commit 7b862e4

Please sign in to comment.