Skip to content

Commit

Permalink
(NameRegistry): short names should always be padded to 12 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminbollen committed May 2, 2024
1 parent b818894 commit 76fc410
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/names/NameRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ contract NameRegistry is Base58Converter, INameRegistry, INameRegistryErrors, IC
string memory base58FullAddress = _toBase58(uint256(uint160(_avatar)));
return string(abi.encodePacked(DEFAULT_CIRCLES_NAME_PREFIX, base58FullAddress));
}
string memory base58ShortName = _toBase58(uint256(shortName));
string memory base58ShortName = _toBase58WithPadding(uint256(shortName));
return string(abi.encodePacked(DEFAULT_CIRCLES_NAME_PREFIX, base58ShortName));
}

Expand Down
4 changes: 4 additions & 0 deletions test/names/MockNameRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ contract MockNameRegistry is NameRegistry {
function toBase58WithPadding(uint256 _data) external pure returns (string memory) {
return _toBase58WithPadding(_data);
}

function storeShortName(address _avatar, uint72 _shortName) external {
_storeShortName(_avatar, _shortName, 0);
}
}
10 changes: 10 additions & 0 deletions test/names/NameRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ contract NamesTest is Test, HumanRegistration, Base58Decode {
assertEq(shortName, "Rings-uNJGyf6sN6vY");
}

function testShortNameWithPadding() public {
// 42 converts to "j" in base58
assertEq(mockNameRegistry.toBase58(42), "j");

// but as a short name it shold be padded to 12 characters
mockNameRegistry.storeShortName(addresses[0], 42);
string memory shortName = mockNameRegistry.getShortOrLongName(addresses[0]);
assertEq(shortName, "Rings-11111111111j");
}

function testBase58Conversion() public {
assertEq(mockNameRegistry.toBase58(0), "1");
assertEq(mockNameRegistry.toBase58(mockNameRegistry.MAX_SHORT_NAME()), "zzzzzzzzzzzz");
Expand Down

0 comments on commit 76fc410

Please sign in to comment.