Skip to content

Commit

Permalink
chore: disable editing moniker (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonberg1997 committed Dec 12, 2023
1 parent 3ca5fa6 commit 5d9b19a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
6 changes: 3 additions & 3 deletions contracts/BC_fusion/StakeHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -354,20 +354,20 @@ contract StakeHub is System, Initializable {
}

/**
* @notice the moniker of the validator will be ignored as it is not editable
* @param description the new description of the validator
*/
function editDescription(Description calldata description)
function editDescription(Description memory description)
external
whenNotPaused
notInBlackList
validatorExist(msg.sender)
{
if (!_checkMoniker(description.moniker)) revert InvalidMoniker();

address operatorAddress = msg.sender;
Validator storage valInfo = _validators[operatorAddress];
if (valInfo.updateTime + BREATH_BLOCK_INTERVAL > block.timestamp) revert UpdateTooFrequently();

description.moniker = valInfo.description.moniker;
valInfo.description = description;
valInfo.updateTime = block.timestamp;

Expand Down
22 changes: 3 additions & 19 deletions test/StakeHub.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,14 @@ contract StakeHubTest is Deployer {
// 4. edit description
vm.warp(block.timestamp + 1 days);
StakeHub.Description memory description = stakeHub.getValidatorDescription(validator);
// invalid moniker
description.moniker = "test";
vm.expectRevert();
stakeHub.editDescription(description);

description.moniker = "T";
vm.expectRevert();
stakeHub.editDescription(description);

description.moniker = "Test;";
vm.expectRevert();
stakeHub.editDescription(description);

description.moniker = "Test ";
vm.expectRevert();
stakeHub.editDescription(description);

// valid moniker
description.moniker = "Test";
description.website = "Test";
vm.expectEmit(true, false, false, true, address(stakeHub));
emit DescriptionEdited(validator);
stakeHub.editDescription(description);
StakeHub.Description memory realDesc = stakeHub.getValidatorDescription(validator);
assertEq(realDesc.moniker, "Test");
assertNotEq(realDesc.moniker, "Test"); // edit moniker is not allowed
assertEq(realDesc.website, "Test");

// 5. edit vote address
vm.warp(block.timestamp + 1 days);
Expand Down

0 comments on commit 5d9b19a

Please sign in to comment.