test: MultiStateHub foundry migration beginning

This commit is contained in:
vicnaum
2022-11-01 19:50:21 +01:00
parent 67dd991267
commit fea5a42ee7
2 changed files with 127 additions and 7 deletions

View File

@@ -55,14 +55,14 @@ Scenarios
Multi-State Hub
Common
Negatives
[ ] User should fail to set the state on the hub
[ ] User should fail to set the emergency admin
[ ] Governance should set user as emergency admin, user should fail to set protocol state to Unpaused
[ ] Governance should set user as emergency admin, user should fail to set protocol state to PublishingPaused or Paused from Paused
[X] User should fail to set the state on the hub
[X] User should fail to set the emergency admin
[X] Governance should set user as emergency admin, user should fail to set protocol state to Unpaused
[X] Governance should set user as emergency admin, user should fail to set protocol state to PublishingPaused or Paused from Paused
Scenarios
[ ] Governance should set user as emergency admin, user sets protocol state but fails to set emergency admin, governance sets emergency admin to the zero address, user fails to set protocol state
[ ] Governance should set the protocol state, fetched protocol state should be accurate
[ ] Governance should set user as emergency admin, user should set protocol state to PublishingPaused, then Paused, then fail to set it to PublishingPaused
[X] Governance should set user as emergency admin, user sets protocol state but fails to set emergency admin, governance sets emergency admin to the zero address, user fails to set protocol state
[X] Governance should set the protocol state, fetched protocol state should be accurate
[X] Governance should set user as emergency admin, user should set protocol state to PublishingPaused, then Paused, then fail to set it to PublishingPaused
Paused State
Scenarios
[ ] User should create a profile, governance should pause the hub, transferring the profile should fail

View File

@@ -0,0 +1,120 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import './base/BaseTest.t.sol';
contract MultiStateHubTest is BaseTest {
// Negatives
function testCannotSetStateAsRegularUser() public {
vm.expectRevert(Errors.NotGovernanceOrEmergencyAdmin.selector);
_setState(DataTypes.ProtocolState.Paused);
vm.expectRevert(Errors.NotGovernanceOrEmergencyAdmin.selector);
_setState(DataTypes.ProtocolState.PublishingPaused);
vm.expectRevert(Errors.NotGovernanceOrEmergencyAdmin.selector);
_setState(DataTypes.ProtocolState.Unpaused);
}
function testCannotSetEmergencyAdminAsRegularUser() public {
vm.expectRevert(Errors.NotGovernance.selector);
_setEmergencyAdmin(address(this));
}
function testCannotUnpauseAsEmergencyAdmin() public {
vm.prank(governance);
_setEmergencyAdmin(address(this));
vm.expectRevert(Errors.EmergencyAdminCanOnlyPauseFurther.selector);
_setState(DataTypes.ProtocolState.Unpaused);
}
function testCannotSetLowerStateAsEmergencyAdmin() public {
vm.prank(governance);
_setEmergencyAdmin(address(this));
_setState(DataTypes.ProtocolState.Paused);
vm.expectRevert(Errors.EmergencyAdminCanOnlyPauseFurther.selector);
_setState(DataTypes.ProtocolState.PublishingPaused);
vm.expectRevert(Errors.EmergencyAdminCanOnlyPauseFurther.selector);
_setState(DataTypes.ProtocolState.Paused);
}
function testCannotSetEmergencyAdminAsEmergencyAdmin() public {
vm.prank(governance);
_setEmergencyAdmin(address(this));
vm.expectRevert(Errors.NotGovernance.selector);
_setEmergencyAdmin(address(0));
}
// Scenarios
function testSetProtocolStateAsEmergencyAdmin() public {
vm.prank(governance);
_setEmergencyAdmin(address(this));
DataTypes.ProtocolState[2] memory states = [
DataTypes.ProtocolState.PublishingPaused,
DataTypes.ProtocolState.Paused
];
for (uint256 i = 0; i < states.length; i++) {
DataTypes.ProtocolState newState = states[i];
DataTypes.ProtocolState prevState = _getState();
_setState(newState);
DataTypes.ProtocolState curState = _getState();
assertTrue(newState == curState);
assertTrue(curState != prevState);
}
}
function testSetProtocolStateAsGovernance() public {
vm.startPrank(governance);
DataTypes.ProtocolState[6] memory states = [
DataTypes.ProtocolState.PublishingPaused,
DataTypes.ProtocolState.Paused,
DataTypes.ProtocolState.Unpaused,
DataTypes.ProtocolState.Paused,
DataTypes.ProtocolState.PublishingPaused,
DataTypes.ProtocolState.Unpaused
];
for (uint256 i = 0; i < states.length; i++) {
DataTypes.ProtocolState newState = states[i];
DataTypes.ProtocolState prevState = _getState();
_setState(newState);
DataTypes.ProtocolState curState = _getState();
assertTrue(newState == curState);
assertTrue(curState != prevState);
}
vm.stopPrank();
}
function testGovernanceCanRevokeEmergencyAdmin() public {
vm.prank(governance);
_setEmergencyAdmin(address(this));
_setState(DataTypes.ProtocolState.PublishingPaused);
vm.prank(governance);
_setEmergencyAdmin(address(0));
vm.expectRevert(Errors.NotGovernanceOrEmergencyAdmin.selector);
_setState(DataTypes.ProtocolState.Paused);
}
function _setState(DataTypes.ProtocolState newState) internal {
hub.setState(newState);
}
function _getState() internal view returns (DataTypes.ProtocolState) {
return hub.getState();
}
function _setEmergencyAdmin(address newEmergencyAdmin) internal {
hub.setEmergencyAdmin(newEmergencyAdmin);
}
}