Skip to content

Commit 1f1e8ab

Browse files
committed
test: more coverage
1 parent a7b63b1 commit 1f1e8ab

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed

src/contracts/vault/v1.1/VaultVotes.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ contract VaultVotes is VaultTokenized {
2626

2727
function _migrate(uint64 oldVersion, uint64, /* newVersion */ bytes memory data) internal virtual override {
2828
if (oldVersion != 3) {
29-
revert IVaultVotes.ImproperMigration();
29+
revert IVaultVotes.InvalidOrigin();
3030
}
3131

3232
if (data.length > 0) {

src/interfaces/vault/v1.1/IVaultVotes.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity ^0.8.0;
44
import {IERC5805} from "@openzeppelin/contracts/interfaces/IERC5805.sol";
55

66
interface IVaultVotes is IERC5805 {
7-
error ImproperMigration();
7+
error InvalidOrigin();
88
error InvalidData();
99
error SafeSupplyExceeded();
1010
}

test/mocks/Token.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@ contract Token is ERC20 {
99
) ERC20(name_, "") {
1010
_mint(msg.sender, 1_000_000 * 10 ** decimals());
1111
}
12+
13+
function mint(address to, uint256 amount) external {
14+
_mint(to, amount);
15+
}
1216
}

test/vault/v1.1/VaultVotes.t.sol

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {MetadataService} from "../../../src/contracts/service/MetadataService.so
1212
import {NetworkMiddlewareService} from "../../../src/contracts/service/NetworkMiddlewareService.sol";
1313
import {OptInService} from "../../../src/contracts/service/OptInService.sol";
1414

15+
import {IVault as IVaultV1} from "../../../src/interfaces/vault/IVault.sol";
1516
import {Vault as VaultV1} from "../../../src/contracts/vault/Vault.sol";
1617
import {VaultTokenized as VaultTokenizedV1} from "../../../src/contracts/vault/VaultTokenized.sol";
1718
import {VaultVotesImplementation} from "../../../src/contracts/vault/v1.1/VaultVotesImplementation.sol";
@@ -25,6 +26,7 @@ import {OperatorSpecificDelegator} from "../../../src/contracts/delegator/Operat
2526
import {OperatorNetworkSpecificDelegator} from "../../../src/contracts/delegator/OperatorNetworkSpecificDelegator.sol";
2627
import {Slasher} from "../../../src/contracts/slasher/Slasher.sol";
2728
import {VetoSlasher} from "../../../src/contracts/slasher/VetoSlasher.sol";
29+
import {VotesUpgradeable} from "@openzeppelin/contracts-upgradeable/governance/utils/VotesUpgradeable.sol";
2830

2931
import {IVault} from "../../../src/interfaces/vault/v1.1/IVault.sol";
3032
import {IVaultTokenized} from "../../../src/interfaces/vault/v1.1/IVaultTokenized.sol";
@@ -1562,6 +1564,26 @@ contract VaultVotesTest is Test {
15621564
assertGt(gasSpent, gasLeft - gasleft());
15631565
}
15641566

1567+
function test_DepositRevertSafeSupplyExceeded(
1568+
uint256 amount1
1569+
) public {
1570+
amount1 = bound(amount1, uint256(type(uint208).max) + 1, type(uint224).max);
1571+
1572+
uint256 blockTimestamp = vm.getBlockTimestamp();
1573+
blockTimestamp = blockTimestamp + 1_720_700_948;
1574+
vm.warp(blockTimestamp);
1575+
1576+
uint48 epochDuration = 1;
1577+
vault = _getVault(epochDuration);
1578+
1579+
collateral.mint(alice, amount1);
1580+
vm.startPrank(alice);
1581+
collateral.approve(address(vault), amount1);
1582+
vm.expectRevert(IVaultVotes.SafeSupplyExceeded.selector);
1583+
vault.deposit(alice, amount1);
1584+
vm.stopPrank();
1585+
}
1586+
15651587
function test_DepositTwiceFeeOnTransferCollateral(uint256 amount1, uint256 amount2) public {
15661588
amount1 = bound(amount1, 2, 100 * 10 ** 18);
15671589
amount2 = bound(amount2, 2, 100 * 10 ** 18);
@@ -3584,6 +3606,8 @@ contract VaultVotesTest is Test {
35843606
assertEq(vault.getVotes(alice), 0);
35853607
assertEq(vault.getPastVotes(alice, blockTimestamp - 1), 0);
35863608
assertEq(vault.getPastTotalSupply(blockTimestamp - 1), 0);
3609+
vm.expectRevert();
3610+
vault.getPastTotalSupply(blockTimestamp + 1);
35873611
assertEq(vault.delegates(alice), address(0));
35883612

35893613
vm.startPrank(alice);
@@ -3876,6 +3900,58 @@ contract VaultVotesTest is Test {
38763900
vm.stopPrank();
38773901
}
38783902

3903+
function test_MigrateInvalidOrigin() public {
3904+
uint256 blockTimestamp = vm.getBlockTimestamp();
3905+
blockTimestamp = blockTimestamp + 1_720_700_948;
3906+
vm.warp(blockTimestamp);
3907+
3908+
address[] memory networkLimitSetRoleHolders = new address[](1);
3909+
networkLimitSetRoleHolders[0] = alice;
3910+
address[] memory operatorNetworkSharesSetRoleHolders = new address[](1);
3911+
operatorNetworkSharesSetRoleHolders[0] = alice;
3912+
(address vault_,,) = vaultConfigurator.create(
3913+
IVaultConfigurator.InitParams({
3914+
version: 1,
3915+
owner: alice,
3916+
vaultParams: abi.encode(
3917+
IVaultV1.InitParams({
3918+
collateral: address(collateral),
3919+
burner: address(0xdEaD),
3920+
epochDuration: 7 days,
3921+
depositWhitelist: false,
3922+
isDepositLimit: false,
3923+
depositLimit: 0,
3924+
defaultAdminRoleHolder: alice,
3925+
depositWhitelistSetRoleHolder: alice,
3926+
depositorWhitelistRoleHolder: alice,
3927+
isDepositLimitSetRoleHolder: alice,
3928+
depositLimitSetRoleHolder: alice
3929+
})
3930+
),
3931+
delegatorIndex: 0,
3932+
delegatorParams: abi.encode(
3933+
INetworkRestakeDelegator.InitParams({
3934+
baseParams: IBaseDelegator.BaseParams({
3935+
defaultAdminRoleHolder: alice,
3936+
hook: address(0),
3937+
hookSetRoleHolder: alice
3938+
}),
3939+
networkLimitSetRoleHolders: networkLimitSetRoleHolders,
3940+
operatorNetworkSharesSetRoleHolders: operatorNetworkSharesSetRoleHolders
3941+
})
3942+
),
3943+
withSlasher: false,
3944+
slasherIndex: 0,
3945+
slasherParams: abi.encode(ISlasher.InitParams({baseParams: IBaseSlasher.BaseParams({isBurnerHook: false})}))
3946+
})
3947+
);
3948+
3949+
vm.startPrank(alice);
3950+
vm.expectRevert(IVaultVotes.InvalidOrigin.selector);
3951+
vaultFactory.migrate(vault_, 4, new bytes(0));
3952+
vm.stopPrank();
3953+
}
3954+
38793955
function _getVault(
38803956
uint48 epochDuration
38813957
) internal returns (VaultVotesImplementation) {

0 commit comments

Comments
 (0)