Skip to content

Commit

Permalink
exists Alias function added + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
steffenkux committed Jan 10, 2024
1 parent ed3e01b commit ace7ab0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/toplevel-alias/contracts/TopLevelAliasRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ contract TopLevelAliasRegistry is Ownable {
aliases[_name] = _alias;
emit AliasSet(_name, _alias);
}

/**
* @dev Checks if an alias exists for the given name.
* @param _name The name to check for an alias.
* @return bool True if an alias exists for the name, false otherwise.
*/
function existsAlias(string memory _name) public view returns (bool) {
return bytes(aliases[_name]).length > 0;
}
}


15 changes: 15 additions & 0 deletions packages/toplevel-alias/test/TopLevelAliasRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ describe('TopLevelAliasRegistry', function () {
});
});

describe('existsAlias Function', function () {
it('Should return true for an existing alias', async function () {
const name = '.alice';
const alias = '.alice.eth';
await topLevelAliasRegistry.connect(owner).setAlias(name, alias);
expect(await topLevelAliasRegistry.existsAlias(name)).to.be.true;
});

it('Should return false for a non-existing alias', async function () {
const nonExistentName = '.bob';
expect(await topLevelAliasRegistry.existsAlias(nonExistentName)).to
.be.false;
});
});

describe('TopLevelAliasRegistry Gas Usage', function () {
it('should measure gas used by setAlias function', async function () {
const tx = await topLevelAliasRegistry
Expand Down

0 comments on commit ace7ab0

Please sign in to comment.