Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: disable editing moniker #442

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading