Skip to content

Commit

Permalink
additional null asssert
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Jan 7, 2024
1 parent 79a6b4b commit c68a889
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ensRegistry.ts
Expand Up @@ -109,7 +109,7 @@ function _handleNewOwner(event: NewOwnerEvent, isMigrated: boolean): void {
if (domain.name == null) {
// Get label and node names
let label = ens.nameByHash(event.params.label.toHexString());
if (label != null && checkValidLabel(label)) {
if (checkValidLabel(label)) {
domain.labelName = label;
} else {
label = "[" + event.params.label.toHexString().slice(2) + "]";
Expand Down
2 changes: 1 addition & 1 deletion src/ethRegistrar.ts
Expand Up @@ -55,7 +55,7 @@ export function handleNameRegistered(event: NameRegisteredEvent): void {
domain.expiryDate = event.params.expires.plus(GRACE_PERIOD_SECONDS);

let labelName = ens.nameByHash(label.toHexString());
if (labelName != null && checkValidLabel(labelName)) {
if (checkValidLabel(labelName)) {
domain.labelName = labelName;
domain.name = labelName! + ".eth";
registration.labelName = labelName;
Expand Down
7 changes: 6 additions & 1 deletion src/utils.ts
Expand Up @@ -68,7 +68,12 @@ export function createOrLoadDomain(node: string): Domain {
return domain;
}

export function checkValidLabel(name: string): boolean {
export function checkValidLabel(name: string | null): boolean {
if (name == null) {
return false;
}
// for compiler
name = name!;
for (let i = 0; i < name.length; i++) {
let c = name.charCodeAt(i);
if (c === 0) {
Expand Down
2 changes: 1 addition & 1 deletion tests/.latest.json
@@ -1,4 +1,4 @@
{
"version": "0.6.0",
"timestamp": 1702332546798
"timestamp": 1704668302285
}
39 changes: 39 additions & 0 deletions tests/ensRegistrar.test.ts
Expand Up @@ -248,3 +248,42 @@ test("does not assign label name to label that uses unnormalised label notation"

checkNullLabelName(labelhash, labelhashAsInt, label);
});

test("does assign normal label", () => {
const labelhash =
"0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658";
const labelhashAsInt =
"70622639689279718371527342103894932928233838121221666359043189029713682937432";
const label = "test";

const newNewOwnerEvent = createNewOwnerEvent(
ETH_NAMEHASH,
labelhash,
DEFAULT_OWNER
);
handleNewOwner(newNewOwnerEvent);

let newRegistrationEvent = createNameRegisteredEvent(
labelhashAsInt,
DEFAULT_OWNER,
"1610000000"
);
handleNameRegistered(newRegistrationEvent);

let fetchedRegistration = Registration.load(labelhash)!;

fetchedRegistration.labelName = "eth";
fetchedRegistration.save();

const nameRegisteredByControllerEvent = createNameRegisteredByControllerEvent(
label,
labelhash,
DEFAULT_OWNER,
"1610000000"
);
handleNameRegisteredByController(nameRegisteredByControllerEvent);

fetchedRegistration = Registration.load(labelhash)!;

assert.assertTrue(fetchedRegistration.labelName == label);
});

0 comments on commit c68a889

Please sign in to comment.