Skip to content

Commit 2b5a272

Browse files
committed
test: vesting tests
1 parent b2fceb7 commit 2b5a272

7 files changed

Lines changed: 527 additions & 11 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ docs/
1212

1313
# Dotenv file
1414
.env
15+
16+
# Test coverage
17+
lcov.info

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// TODO: Уточнить, что не подходит для реализации вестинга ребейз токенов
2+
13
## Foundry
24

35
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**

src/tokenDistribution/MetaTokenDistributor.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ contract MetaTokenDistributor is IMetaTokenDistributor {
4343
}
4444

4545
function startVesting(VestingType vestingType) external returns (address vesting) {
46+
// TODO: механизм, который позволит создавать вестинг для каждого типа единожды
4647
if (block.timestamp < _vestingStartTime) {
4748
revert VestingStartTimeHasNotArrived();
4849
}
4950

51+
// TODO: Может быть клонировано с Clones.cloneWithImmutableArgs
5052
vesting = Clones.clone(_vestingImpl);
5153

5254
// TODO: Можно две функции объединить
@@ -58,6 +60,7 @@ contract MetaTokenDistributor is IMetaTokenDistributor {
5860
(uint256 vestingAmount,,,,) = _vestingParams.getVestingParams(vestingType);
5961

6062
_META.safeTransfer(address(vesting), vestingAmount);
63+
6164
IVesting(vesting).initialize(_META, schedule, beneficiaries);
6265

6366
emit VestingStarted(vesting);

src/tokenDistribution/vesting/Vesting.sol

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.s
77
import {IVesting} from "./interfaces/IVesting.sol";
88
import {Schedule, Period, Beneficiary} from "../utils/Common.sol";
99

10-
// TODO: Проверить отчет на предмет замечаний
11-
1210
/**
1311
* @title Vesting contract of the base token
1412
* @dev Each new vesting instance is created through a factory using the Minimal Clones pattern.
@@ -64,13 +62,8 @@ contract Vesting is IVesting, Initializable {
6462
* @dev The claimed amount will be store in _released mapping
6563
*/
6664
function claim() external {
67-
Schedule memory schedule = _schedule;
68-
69-
if (block.timestamp < schedule.startTime) {
70-
revert VestingHasNotStarted();
71-
}
72-
7365
uint256 unlockedAmount = availableToClaim(msg.sender);
66+
7467
if (unlockedAmount > 0) {
7568
_released[msg.sender] += unlockedAmount;
7669
_baseToken.safeTransfer(msg.sender, unlockedAmount);
@@ -98,6 +91,9 @@ contract Vesting is IVesting, Initializable {
9891

9992
/// @notice Returns the total amount of locked tokens
10093
function totalLocked() external view returns (uint256) {
94+
// TODO: заменить на
95+
// uint256 initialTotalLocked = _initialTotalLocked;
96+
// return initialTotalLocked - _computeUnlocked(initialTotalLocked);
10197
return _initialTotalLocked - totalUnlocked();
10298
}
10399

@@ -108,6 +104,9 @@ contract Vesting is IVesting, Initializable {
108104

109105
/// @notice Returns the amount of locked tokens for a specific account
110106
function lockedOf(address account) external view returns (uint256) {
107+
// TODO: заменить на
108+
// uint256 initialLocked = _initialLocked[account];
109+
// return initialLocked - _computeUnlocked(initialLocked);
111110
return _initialLocked[account] - unlockedOf(account);
112111
}
113112

@@ -191,6 +190,7 @@ contract Vesting is IVesting, Initializable {
191190
}
192191

193192
_initialLocked[beneficiary.account] = beneficiary.amount;
193+
// TODO: переделать на чтение из memory и последующая запись в storage
194194
_initialTotalLocked += beneficiary.amount;
195195
}
196196

@@ -207,6 +207,7 @@ contract Vesting is IVesting, Initializable {
207207
* @return unlockedAmount The total amount of unlocked tokens
208208
*/
209209
function _computeUnlocked(uint256 initialLockedAmount) private view returns (uint256 unlockedAmount) {
210+
// TODO: добавить _schedule в memory
210211
if (block.timestamp < _schedule.startTime) {
211212
return 0;
212213
}

src/tokenDistribution/vesting/interfaces/IVesting.sol

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ interface IVesting {
3333
/// @dev Each new end period time must be greater then prev
3434
error IncorrectPeriodTime();
3535

36-
/// @dev Not available if vesting has not been started
37-
error VestingHasNotStarted();
38-
3936
/// @dev Emitted when vesting schedule params has been initialized
4037
event ScheduleInitialized(Schedule schedule);
4138

test/MetaToken.t.sol

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,15 @@ contract MetaTokenTest is Test {
2828

2929
assertEq(META.balanceOf(distributor), expectedTotalSupply);
3030
}
31+
32+
function test_transfer() external {
33+
address recipient = makeAddr("recipient");
34+
uint256 totalSupply = META.totalSupply();
35+
36+
vm.prank(distributor);
37+
META.transfer(recipient, totalSupply);
38+
39+
assertEq(META.balanceOf(recipient), META.totalSupply());
40+
assertEq(META.balanceOf(distributor), 0);
41+
}
3142
}

0 commit comments

Comments
 (0)