Skip to content

Commit bcb94a8

Browse files
committed
changed "." prefix requirement
1 parent dc392a9 commit bcb94a8

File tree

3 files changed

+38
-40
lines changed

3 files changed

+38
-40
lines changed

packages/toplevel-alias/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The top-level alias registry is a `dm3` protocol extension to provide a decentra
1212

1313
- **Alias Management:** Allows setting of aliases for given names with specific format rules.
1414
- **Ownership Control:** Utilizes OpenZeppelin's `Ownable` contract to restrict certain functionalities to the contract owner.
15-
- **Format Validation:** Enforces aliases to start with a dot, be at least a certain length, and follow a specific pattern.
15+
- **Format Validation:** Enforces aliases must not start with a dot, be at least a certain length, and follow a specific pattern.
1616

1717
## Contract Functions
1818

@@ -21,8 +21,8 @@ The top-level alias registry is a `dm3` protocol extension to provide a decentra
2121
- **Description:** Sets an alias for a given name (= top-level).
2222
- **Access:** Restricted to the contract owner.
2323
- **Parameters:**
24-
- `_name`: The name (top-level domain) to map the alias to. Must not be empty and start with ".".
25-
- `_alias`: The alias to be set for the given name. Must start with a dot and follow the format rules.
24+
- `_name`: The name (top-level domain) to map the alias to. Must not be empty and not start with ".".
25+
- `_alias`: The alias to be set for the given name. Must not start with a dot and follow the format rules.
2626

2727
### Other Functions
2828

@@ -31,7 +31,7 @@ The top-level alias registry is a `dm3` protocol extension to provide a decentra
3131

3232
## Format Rules for Aliases
3333

34-
- The alias must start with a dot (e.g., `.example`).
34+
- The alias must not start with a dot (e.g., `example` and not `.example`).
3535
- It must have at least three characters before the dot and at least two characters after the dot.
3636
- The total length of the alias must be within the predefined maximum limit.
3737

@@ -52,7 +52,7 @@ The contract comes with a suite of tests to verify its functionalities. To run t
5252
5353
## Contributing
5454
55-
Contributions to the `TopLevelAliasRegistry` sub project of the `dm3` project are welcome. Please ensure that any major changes are discussed via issues before submitting a pull request.
55+
Contributions to the `TopLevelAliasRegistry` sub-project of the `dm3` project are welcome. Please ensure that any major changes are discussed via issues before submitting a pull request.
5656
5757
## License
5858

packages/toplevel-alias/contracts/TopLevelAliasRegistry.sol

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ contract TopLevelAliasRegistry is Ownable {
1414
mapping(string => string) public aliases;
1515

1616
// Maximum allowed length for an alias
17-
uint256 private constant MAX_ALIAS_LENGTH = 100;
17+
uint256 private constant MAX_ALIAS_LENGTH = 50;
1818

1919
// Event emitted when an alias is set
2020
event AliasSet(string indexed _toplevel, string _alias);
@@ -29,25 +29,25 @@ contract TopLevelAliasRegistry is Ownable {
2929
/**
3030
* @dev Sets an alias for a given name, ensuring it meets various criteria including ENS validity.
3131
* Only the owner of the contract can call this function.
32-
* Validates that the name is not empty, the alias length is within limits, and ends with '.eth'.
32+
* Validates that the name is not empty, the alias length is within limits
3333
*
3434
* @param _toplevel The toplevel name to map the alias to. Must not be empty.
35-
* @param _alias The alias to be set for the given name. Must meet the criteria.
35+
* @param _alias The alias to be set for the given toplevel. Must meet the criteria.
3636
*/
3737
function setAlias(string memory _toplevel, string memory _alias) public onlyOwner {
3838
require(bytes(_toplevel).length > 0, "Toplevel cannot be empty");
39-
require(bytes(_alias).length >= 7 && bytes(_alias).length <= MAX_ALIAS_LENGTH, "Alias length is invalid"); //"." + min. 3 chars + "." + "min. 2 chars"
40-
require (bytes(_alias)[0] == '.', "Alias must start with a dot");
41-
require (bytes(_toplevel)[0] == '.', "Toplevel must start with a dot");
39+
require(bytes(_alias).length >= 6 && bytes(_alias).length <= MAX_ALIAS_LENGTH, "Alias length is invalid"); // min. 3 chars + "." + "min. 2 chars"
40+
require (bytes(_alias)[0] != '.', "Alias must not start with a dot");
41+
require (bytes(_toplevel)[0] != '.', "Toplevel must not start with a dot");
4242

4343
aliases[_toplevel] = _alias;
4444
emit AliasSet(_toplevel, _alias);
4545
}
4646

4747
/**
48-
* @dev Checks if an alias exists for the given name.
48+
* @dev Checks if an alias exists for the given toplevel.
4949
* @param _toplevel The toplevel to check for an alias.
50-
* @return bool True if an alias exists for the name, false otherwise.
50+
* @return bool True if an alias exists for the toplevel, false otherwise.
5151
*/
5252
function existsAlias(string memory _toplevel) public view returns (bool) {
5353
return bytes(aliases[_toplevel]).length > 0;

packages/toplevel-alias/test/TopLevelAliasRegistry.test.ts

+25-27
Original file line numberDiff line numberDiff line change
@@ -32,63 +32,61 @@ describe('TopLevelAliasRegistry', function () {
3232
it('Should let the owner set a valid alias and retrieve it', async function () {
3333
await topLevelAliasRegistry
3434
.connect(owner)
35-
.setAlias('.alice', '.alice.eth');
36-
expect(await topLevelAliasRegistry.aliases('.alice')).to.equal(
37-
'.alice.eth',
35+
.setAlias('alice', 'alice.eth');
36+
expect(await topLevelAliasRegistry.aliases('alice')).to.equal(
37+
'alice.eth',
3838
);
3939
});
4040

4141
it('Should let the owner set a valid alias and retrieve it', async function () {
4242
await topLevelAliasRegistry
4343
.connect(owner)
44-
.setAlias('.alice', '.abc.io');
45-
expect(await topLevelAliasRegistry.aliases('.alice')).to.equal(
46-
'.abc.io',
44+
.setAlias('alice', 'abc.io');
45+
expect(await topLevelAliasRegistry.aliases('alice')).to.equal(
46+
'abc.io',
4747
);
4848
});
4949

5050
it('Should let the owner set a valid long alias and retrieve it', async function () {
5151
await topLevelAliasRegistry
5252
.connect(owner)
53-
.setAlias('.test', '.abc.long_name.xyz.eth');
54-
expect(await topLevelAliasRegistry.aliases('.test')).to.equal(
55-
'.abc.long_name.xyz.eth',
53+
.setAlias('test', 'abc.long_name.xyz.eth');
54+
expect(await topLevelAliasRegistry.aliases('test')).to.equal(
55+
'abc.long_name.xyz.eth',
5656
);
5757
});
5858

5959
it('Should prevent setting an alias that is too short or too long', async function () {
6060
await expect(
61-
topLevelAliasRegistry.connect(owner).setAlias('.bob', '.bb.et'),
61+
topLevelAliasRegistry.connect(owner).setAlias('bob', 'bb.et'),
6262
).to.be.revertedWith('Alias length is invalid');
6363

64-
let longAlias = '.b'.repeat(101) + '.eth';
64+
let longAlias = 'b'.repeat(47) + '.eth';
6565
await expect(
66-
topLevelAliasRegistry
67-
.connect(owner)
68-
.setAlias('.bob', longAlias),
66+
topLevelAliasRegistry.connect(owner).setAlias('bob', longAlias),
6967
).to.be.revertedWith('Alias length is invalid');
7068
});
7169

7270
it('Should prevent setting an empty toplevel', async function () {
7371
await expect(
74-
topLevelAliasRegistry.connect(owner).setAlias('', '.valid.eth'),
72+
topLevelAliasRegistry.connect(owner).setAlias('', 'valid.eth'),
7573
).to.be.revertedWith('Toplevel cannot be empty');
7674
});
7775

78-
it('Should revert if the alias does not start with a dot', async function () {
76+
it('Should revert if the alias starts with a dot', async function () {
7977
await expect(
8078
topLevelAliasRegistry
8179
.connect(owner)
82-
.setAlias('.alice', 'alice.eth'),
83-
).to.be.revertedWith('Alias must start with a dot');
80+
.setAlias('alice', '.alice.eth'),
81+
).to.be.revertedWith('Alias must not start with a dot');
8482
});
8583

86-
it('Should revert if the toplevel does not start with a dot', async function () {
84+
it('Should revert if the toplevel starts with a dot', async function () {
8785
await expect(
8886
topLevelAliasRegistry
8987
.connect(owner)
90-
.setAlias('alice', '.alice.eth'),
91-
).to.be.revertedWith('Toplevel must start with a dot');
88+
.setAlias('.alice', 'alice.eth'),
89+
).to.be.revertedWith('Toplevel must not start with a dot');
9290
});
9391
});
9492

@@ -97,17 +95,17 @@ describe('TopLevelAliasRegistry', function () {
9795
await expect(
9896
topLevelAliasRegistry
9997
.connect(owner)
100-
.setAlias('.alice', '.alice.eth'),
98+
.setAlias('alice', 'alice.eth'),
10199
)
102100
.to.emit(topLevelAliasRegistry, 'AliasSet')
103-
.withArgs('.alice', '.alice.eth');
101+
.withArgs('alice', 'alice.eth');
104102
});
105103
});
106104

107105
describe('existsAlias Function', function () {
108106
it('Should return true for an existing alias', async function () {
109-
const toplevel = '.alice';
110-
const alias = '.alice.eth';
107+
const toplevel = 'alice';
108+
const alias = 'alice.eth';
111109
await topLevelAliasRegistry
112110
.connect(owner)
113111
.setAlias(toplevel, alias);
@@ -116,7 +114,7 @@ describe('TopLevelAliasRegistry', function () {
116114
});
117115

118116
it('Should return false for a non-existing alias', async function () {
119-
const nonExistentToplevel = '.bob';
117+
const nonExistentToplevel = 'bob';
120118
expect(await topLevelAliasRegistry.existsAlias(nonExistentToplevel))
121119
.to.be.false;
122120
});
@@ -162,7 +160,7 @@ describe('TopLevelAliasRegistry', function () {
162160
await expect(
163161
topLevelAliasRegistry
164162
.connect(addr1)
165-
.setAlias('.testname', '.testname.eth'),
163+
.setAlias('testname', 'testname.eth'),
166164
).to.be.revertedWithCustomError(
167165
topLevelAliasRegistry,
168166
'OwnableUnauthorizedAccount',

0 commit comments

Comments
 (0)