Skip to content

Commit

Permalink
add _ to allowed chars
Browse files Browse the repository at this point in the history
  • Loading branch information
LorranSutter committed Sep 4, 2024
1 parent b2780ed commit 4df451e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ typechain-types
# Hardhat files
cache
artifacts
*Old.sol

# OpenZeppelin
.openzeppelin/unknown-*.json
Expand Down
13 changes: 7 additions & 6 deletions contracts/DcnManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,18 @@ contract DcnManager is
if (labelLength < 3) revert InvalidLength();
if (labelLength > 15) revert InvalidLength();

bytes1 bLetter;
bytes1 bChar;
for (uint256 i = 0; i < labelLength; i++) {
bLetter = b[i];
bChar = b[i];

// A-Z
if (bLetter > 0x40 && bLetter < 0x5B) {
if (bChar > 0x40 && bChar < 0x5B) {
// To lowercase
b[i] = bLetter | 0x20;
b[i] = bChar | 0x20;
} else if (
!(bLetter > 0x2F && bLetter < 0x3A) && // 9-0
!(bLetter > 0x60 && bLetter < 0x7B) // a-z
!(bChar > 0x2F && bChar < 0x3A) && // 9-0
!(bChar > 0x60 && bChar < 0x7B) && // a-z
!(bChar == 0x5F) // _
) {
revert InvalidCharacter();
}
Expand Down
12 changes: 12 additions & 0 deletions test/DcnManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ describe('DcnManager', () => {
});

context('State', () => {
it('Should mint a name with all allowed characters', async () => {
const { user1, dcnManager, dcnRegistry } = await loadFixture(setupTldMinted);

await dcnManager
.connect(user1)
.mint(user1.address, C.MOCK_LABELS, C.ONE_YEAR, 0);

const latestBlock = await time.latestBlock();
const newNode = (await dcnRegistry.queryFilter(dcnRegistry.filters.NewNode(), latestBlock))[0].args.node;

expect(newNode).to.be.equal(namehash(C.MOCK_LABELS));
});
it('Should convert uppercase to lowercase', async () => {
const { user1, dcnManager, dcnRegistry } = await loadFixture(setupTldMinted);

Expand Down
8 changes: 4 additions & 4 deletions utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export const DCN_REGISTRY_NFT_BASE_URI = 'https://dimo.zone/dcn/';

export const MOCK_INVALID_TLD = 'invalidtld';
export const MOCK_TLD = 'dimo';
export const MOCK_LABELS = ['label1', 'dimo'];
export const MOCK_LABELS_UPPERCASE = ['LABEL1', 'dimo'];
export const MOCK_LABELS = ['label_1', 'dimo'];
export const MOCK_LABELS_UPPERCASE = ['LABEL_1', 'dimo'];

// Invalid labels
export const MOCK_LABELS_3 = ['label2', 'label1', 'dimo'];
export const MOCK_LABELS_3 = ['label_2', 'label_1', 'dimo'];
export const MOCK_LABELS_SHORT = ['l', 'dimo'];
export const MOCK_LABELS_LONG = ['labelabelabelabelabelabelabel', 'dimo'];
export const MOCK_LABELS_WRONG_CHARS = ['Ln57&%_', 'dimo'];
export const MOCK_LABELS_WRONG_CHARS = ['Ln57&%', 'dimo'];

// Disallowed labels
export const MOCK_DISALLOWED_LABEL_1 = 'disallowed1';
Expand Down

0 comments on commit 4df451e

Please sign in to comment.