Skip to content

Commit

Permalink
Merge pull request #80 from ensdomains/fix/resolver-null-set
Browse files Browse the repository at this point in the history
fix: set resolver on domain to null if 0x0
  • Loading branch information
TateB committed Jul 28, 2023
2 parents 707985b + 0df56f6 commit 5c048fb
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -25,7 +25,7 @@
"@graphprotocol/graph-cli": "^0.51.2",
"@graphprotocol/graph-ts": "^0.31.0",
"assemblyscript": "^0.19.0",
"matchstick-as": "^0.5.0",
"matchstick-as": "^0.5.2",
"typescript": "^4.9.4"
}
}
10 changes: 8 additions & 2 deletions src/ensRegistry.ts
@@ -1,7 +1,13 @@
// Import types and APIs from graph-ts
import { BigInt, crypto, ens } from "@graphprotocol/graph-ts";

import { concat, createEventID, EMPTY_ADDRESS, ROOT_NODE } from "./utils";
import {
concat,
createEventID,
EMPTY_ADDRESS,
EMPTY_ADDRESS_BYTEARRAY,
ROOT_NODE,
} from "./utils";

// Import event types from the registry contract ABI
import {
Expand Down Expand Up @@ -165,7 +171,7 @@ export function handleNewResolver(event: NewResolverEvent): void {

// if resolver is set to 0x0, set id to null
// we don't want to create a resolver entity for 0x0
if (event.params.resolver.toHexString() === EMPTY_ADDRESS) {
if (event.params.resolver.equals(EMPTY_ADDRESS_BYTEARRAY)) {
id = null;
} else {
id = event.params.resolver
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Expand Up @@ -14,6 +14,7 @@ export const ETH_NODE =
export const ROOT_NODE =
"0x0000000000000000000000000000000000000000000000000000000000000000";
export const EMPTY_ADDRESS = "0x0000000000000000000000000000000000000000";
export const EMPTY_ADDRESS_BYTEARRAY = new ByteArray(20);

// Helper for concatenating two byte arrays
export function concat(a: ByteArray, b: ByteArray): ByteArray {
Expand Down
2 changes: 1 addition & 1 deletion tests/.latest.json
@@ -1,4 +1,4 @@
{
"version": "0.5.4",
"timestamp": 1689639506312
"timestamp": 1689736116460
}
130 changes: 130 additions & 0 deletions tests/ensRegistry.test.ts
@@ -0,0 +1,130 @@
import { Address, Bytes, ethereum } from "@graphprotocol/graph-ts";
import {
assert,
beforeAll,
newMockEvent,
test,
} from "matchstick-as/assembly/index";
import { handleNewOwner, handleNewResolver } from "../src/ensRegistry";
import { NewOwner, NewResolver } from "../src/types/ENSRegistry/EnsRegistry";
import { Domain } from "../src/types/schema";

const ETH_NAMEHASH =
"0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae";

const DEFAULT_OWNER = "0x89205A3A3b2A69De6Dbf7f01ED13B2108B2c43e7";

const DEFAULT_RESOLVER = "0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41";

const EMPTY_ADDRESS = "0x0000000000000000000000000000000000000000";

const createNewOwnerEvent = (
node: string,
label: string,
owner: string
): NewOwner => {
let mockEvent = newMockEvent();
let newNewOwnerEvent = new NewOwner(
mockEvent.address,
mockEvent.logIndex,
mockEvent.transactionLogIndex,
mockEvent.logType,
mockEvent.block,
mockEvent.transaction,
mockEvent.parameters,
mockEvent.receipt
);

newNewOwnerEvent.parameters = new Array();
let nodeParam = new ethereum.EventParam(
"node",
ethereum.Value.fromBytes(Bytes.fromHexString(node))
);
let labelParam = new ethereum.EventParam(
"label",
ethereum.Value.fromBytes(Bytes.fromHexString(label))
);
let ownerParam = new ethereum.EventParam(
"owner",
ethereum.Value.fromAddress(Address.fromString(owner))
);
newNewOwnerEvent.parameters.push(nodeParam);
newNewOwnerEvent.parameters.push(labelParam);
newNewOwnerEvent.parameters.push(ownerParam);
return newNewOwnerEvent;
};

const createNewResolverEvent = (
node: string,
resolver: string
): NewResolver => {
let mockEvent = newMockEvent();
let newResolverEvent = new NewResolver(
mockEvent.address,
mockEvent.logIndex,
mockEvent.transactionLogIndex,
mockEvent.logType,
mockEvent.block,
mockEvent.transaction,
mockEvent.parameters,
mockEvent.receipt
);

newResolverEvent.parameters = new Array();
let nodeParam = new ethereum.EventParam(
"node",
ethereum.Value.fromFixedBytes(Bytes.fromHexString(node))
);
let resolverParam = new ethereum.EventParam(
"resolver",
ethereum.Value.fromAddress(Address.fromString(resolver))
);
newResolverEvent.parameters.push(nodeParam);
newResolverEvent.parameters.push(resolverParam);

return newResolverEvent;
};

beforeAll(() => {
const ethLabelhash =
"0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0";
const emptyNode =
"0x0000000000000000000000000000000000000000000000000000000000000000";
const newNewOwnerEvent = createNewOwnerEvent(
emptyNode,
ethLabelhash,
DEFAULT_OWNER
);
handleNewOwner(newNewOwnerEvent);
});

test("sets 0x0 resolver to null", () => {
// something.eth
const labelhash =
"0x68371d7e884c168ae2022c82bd837d51837718a7f7dfb7aa3f753074a35e1d87";
const namehash =
"0x7857c9824139b8a8c3cb04712b41558b4878c55fa9c1e5390e910ee3220c3cce";
const newNewOwnerEvent = createNewOwnerEvent(
ETH_NAMEHASH,
labelhash,
DEFAULT_OWNER
);
handleNewOwner(newNewOwnerEvent);

const newNewResolverEvent = createNewResolverEvent(
namehash,
DEFAULT_RESOLVER
);
handleNewResolver(newNewResolverEvent);

let fetchedDomain = Domain.load(namehash)!;

assert.assertNotNull(fetchedDomain.resolver);

const emptyResolverEvent = createNewResolverEvent(namehash, EMPTY_ADDRESS);
handleNewResolver(emptyResolverEvent);

fetchedDomain = Domain.load(namehash)!;

assert.assertNull(fetchedDomain.resolver);
});
19 changes: 5 additions & 14 deletions yarn.lock
Expand Up @@ -259,13 +259,6 @@
which "2.0.2"
yaml "1.10.2"

"@graphprotocol/graph-ts@^0.27.0":
version "0.27.0"
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.27.0.tgz#948fe1716f6082964a01a63a19bcbf9ac44e06ff"
integrity sha512-r1SPDIZVQiGMxcY8rhFSM0y7d/xAbQf5vHMWUf59js1KgoyWpM6P3tczZqmQd7JTmeyNsDGIPzd9FeaxllsU4w==
dependencies:
assemblyscript "0.19.10"

"@graphprotocol/graph-ts@^0.31.0":
version "0.31.0"
resolved "https://registry.yarnpkg.com/@graphprotocol/graph-ts/-/graph-ts-0.31.0.tgz#730668c0369828b31bef81e8d9bc66b9b48e3480"
Expand Down Expand Up @@ -786,7 +779,7 @@ assemblyscript@0.19.10:
binaryen "101.0.0-nightly.20210723"
long "^4.0.0"

assemblyscript@0.19.23, assemblyscript@^0.19.0, assemblyscript@^0.19.20:
assemblyscript@0.19.23, assemblyscript@^0.19.0:
version "0.19.23"
resolved "https://registry.yarnpkg.com/assemblyscript/-/assemblyscript-0.19.23.tgz#16ece69f7f302161e2e736a0f6a474e6db72134c"
integrity sha512-fwOQNZVTMga5KRsfY80g7cpOl4PsFQczMwHzdtgoqLXaYhkhavufKb0sB0l3T1DUxpAufA0KNhlbpuuhZUwxMA==
Expand Down Expand Up @@ -2712,13 +2705,11 @@ make-error@^1.1.1:
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==

matchstick-as@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/matchstick-as/-/matchstick-as-0.5.0.tgz#cdafc1ef49d670b9cbe98e933bc2a5cb7c450aeb"
integrity sha512-4K619YDH+so129qt4RB4JCNxaFwJJYLXPc7drpG+/mIj86Cfzg6FKs/bA91cnajmS1CLHdhHl9vt6Kd6Oqvfkg==
matchstick-as@^0.5.2:
version "0.5.2"
resolved "https://registry.yarnpkg.com/matchstick-as/-/matchstick-as-0.5.2.tgz#6a6dde02d1d939c32458bd67bac688891a07a34c"
integrity sha512-fb1OVphDKEvJY06Ue02Eh1CNncuW95vp6b8tNAP7UIqplICSLoU/zgN6U7ge7R0upsoO78C7CRi4EyK/7Jxz7g==
dependencies:
"@graphprotocol/graph-ts" "^0.27.0"
assemblyscript "^0.19.20"
wabt "1.0.24"

md5.js@^1.3.4:
Expand Down

1 comment on commit 5c048fb

@1mikola
Copy link

@1mikola 1mikola commented on 5c048fb Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.