Skip to content

Commit

Permalink
fix: ensure consistent expiry date on domain entity
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Feb 15, 2024
1 parent 17294f5 commit 9211255
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 67 deletions.
3 changes: 1 addition & 2 deletions src/ethRegistrar.ts
Expand Up @@ -2,7 +2,6 @@
import { BigInt, ByteArray, Bytes, crypto, ens } from "@graphprotocol/graph-ts";

import {
byteArrayFromHex,
checkValidLabel,
concat,
createEventID,
Expand Down Expand Up @@ -36,7 +35,7 @@ import {

const GRACE_PERIOD_SECONDS = BigInt.fromI32(7776000); // 90 days

var rootNode: ByteArray = byteArrayFromHex(ETH_NODE);
var rootNode: ByteArray = ByteArray.fromHexString(ETH_NODE);

export function handleNameRegistered(event: NameRegisteredEvent): void {
let account = new Account(event.params.owner.toHex());
Expand Down
11 changes: 2 additions & 9 deletions src/nameWrapper.ts
Expand Up @@ -193,12 +193,7 @@ function makeWrappedTransfer(
to: string
): void {
const _to = createOrLoadAccount(to);
const namehash =
"0x" +
node
.toHex()
.slice(2)
.padStart(64, "0");
const namehash = "0x" + node.toHex().slice(2).padStart(64, "0");
const domain = createOrLoadDomain(namehash);
let wrappedDomain = WrappedDomain.load(namehash);
// new registrations emit the Transfer` event before the NameWrapped event
Expand Down Expand Up @@ -242,9 +237,7 @@ export function handleTransferBatch(event: TransferBatchEvent): void {
makeWrappedTransfer(
blockNumber,
transactionID,
createEventID(event)
.concat("-")
.concat(i.toString()),
createEventID(event).concat("-").concat(i.toString()),
ids[i],
to.toHex()
);
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Expand Up @@ -10,7 +10,7 @@ export function createEventID(event: ethereum.Event): string {
}

export const ETH_NODE =
"93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae";
"0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae";
export const ROOT_NODE =
"0x0000000000000000000000000000000000000000000000000000000000000000";
export const EMPTY_ADDRESS = "0x0000000000000000000000000000000000000000";
Expand Down
2 changes: 1 addition & 1 deletion tests/.latest.json
@@ -1,4 +1,4 @@
{
"version": "0.6.0",
"timestamp": 1704668302285
"timestamp": 1707952879651
}
59 changes: 5 additions & 54 deletions tests/ensRegistrar.test.ts
Expand Up @@ -11,14 +11,10 @@ import {
handleNameRegisteredByController,
} from "../src/ethRegistrar";
import { NameRegistered } from "../src/types/BaseRegistrar/BaseRegistrar";
import { NewOwner } from "../src/types/ENSRegistry/EnsRegistry";
import { NameRegistered as NameRegisteredByController } from "../src/types/EthRegistrarController/EthRegistrarController";
import { Registration } from "../src/types/schema";

const ETH_NAMEHASH =
"0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae";

const DEFAULT_OWNER = "0x89205A3A3b2A69De6Dbf7f01ED13B2108B2c43e7";
import { ETH_NODE } from "../src/utils";
import { createNewOwnerEvent, DEFAULT_OWNER, setEthOwner } from "./testUtils";

const createNameRegisteredByControllerEvent = (
name: string,
Expand Down Expand Up @@ -73,42 +69,6 @@ const createNameRegisteredByControllerEvent = (
return nameRegisteredByControllerEvent;
};

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 createNameRegisteredEvent = (
id: string,
owner: string,
Expand Down Expand Up @@ -145,16 +105,7 @@ const createNameRegisteredEvent = (
};

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

const checkNullLabelName = (
Expand All @@ -163,7 +114,7 @@ const checkNullLabelName = (
label: string
): void => {
const newNewOwnerEvent = createNewOwnerEvent(
ETH_NAMEHASH,
ETH_NODE,
labelhash,
DEFAULT_OWNER
);
Expand Down Expand Up @@ -257,7 +208,7 @@ test("does assign normal label", () => {
const label = "test";

const newNewOwnerEvent = createNewOwnerEvent(
ETH_NAMEHASH,
ETH_NODE,
labelhash,
DEFAULT_OWNER
);
Expand Down
129 changes: 129 additions & 0 deletions tests/nameWrapper.test.ts
@@ -0,0 +1,129 @@
import { Address, BigInt, Bytes, ethereum } from "@graphprotocol/graph-ts";
import {
assert,
beforeAll,
describe,
newMockEvent,
test,
} from "matchstick-as/assembly/index";
import { handleNameUnwrapped } from "../src/nameWrapper";
import { NameUnwrapped } from "../src/types/NameWrapper/NameWrapper";
import { Domain, WrappedDomain } from "../src/types/schema";
import { ETH_NODE } from "../src/utils";
import { DEFAULT_OWNER, setEthOwner } from "./testUtils";

beforeAll(() => {
setEthOwner();
});

const NAME_WRAPPER_ADDRESS = "0xD4416b13d2b3a9aBae7AcD5D6C2BbDBE25686401";
// test.eth
const testEthNamehash =
"0xeb4f647bea6caa36333c816d7b46fdcb05f9466ecacc140ea8c66faf15b3d9f1";

const createNameUnwrappedEvent = (
node: string,
owner: string
): NameUnwrapped => {
let mockEvent = newMockEvent();
let newNameUnwrappedEvent = new NameUnwrapped(
mockEvent.address,
mockEvent.logIndex,
mockEvent.transactionLogIndex,
mockEvent.logType,
mockEvent.block,
mockEvent.transaction,
mockEvent.parameters,
mockEvent.receipt
);
newNameUnwrappedEvent.parameters = new Array();
let nodeParam = new ethereum.EventParam(
"node",
ethereum.Value.fromBytes(Bytes.fromHexString(node))
);
let ownerParam = new ethereum.EventParam(
"owner",
ethereum.Value.fromAddress(Address.fromString(owner))
);
newNameUnwrappedEvent.parameters.push(nodeParam);
newNameUnwrappedEvent.parameters.push(ownerParam);
return newNameUnwrappedEvent;
};

describe("handleNameUnwrapped", () => {
test("does not set expiryDate to null if name is .eth", () => {
// test
const labelhash =
"0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658";

let domain = new Domain(testEthNamehash);
domain.name = "test.eth";
domain.labelName = "test";
domain.labelhash = Bytes.fromHexString(labelhash);
domain.parent = ETH_NODE;
domain.subdomainCount = 0;
domain.isMigrated = true;
domain.createdAt = BigInt.fromI32(0);
domain.owner = NAME_WRAPPER_ADDRESS;
domain.registrant = NAME_WRAPPER_ADDRESS;
domain.wrappedOwner = DEFAULT_OWNER;
domain.expiryDate = BigInt.fromI32(123456789);
domain.save();

const wrappedDomain = new WrappedDomain(testEthNamehash);
wrappedDomain.domain = testEthNamehash;
wrappedDomain.expiryDate = BigInt.fromI32(123456789);
wrappedDomain.fuses = 0;
wrappedDomain.owner = DEFAULT_OWNER;
wrappedDomain.name = "test.eth";
wrappedDomain.save();

const nameUnwrappedEvent = createNameUnwrappedEvent(
testEthNamehash,
DEFAULT_OWNER
);

handleNameUnwrapped(nameUnwrappedEvent);

assert.fieldEquals("Domain", testEthNamehash, "expiryDate", "123456789");
});
test("sets expiryDate to null if name is not .eth", () => {
// cool.test.eth
const subNamehash =
"0x85c47d906feeeed4795f21773ab20983af35e85837d2de39549f650c8fb50c0f";
// cool
const labelhash =
"0x678c189fde5058554d934d6af17e41750fa2a94b61371c5ea958a7595e146324";

let domain = new Domain(subNamehash);
domain.name = "cool.test.eth";
domain.labelName = "cool";
domain.labelhash = Bytes.fromHexString(labelhash);
domain.parent = testEthNamehash;
domain.subdomainCount = 0;
domain.isMigrated = true;
domain.createdAt = BigInt.fromI32(0);
domain.owner = NAME_WRAPPER_ADDRESS;
domain.registrant = NAME_WRAPPER_ADDRESS;
domain.wrappedOwner = DEFAULT_OWNER;
domain.expiryDate = BigInt.fromI32(123456789);
domain.save();

const wrappedDomain = new WrappedDomain(subNamehash);
wrappedDomain.domain = subNamehash;
wrappedDomain.expiryDate = BigInt.fromI32(123456789);
wrappedDomain.fuses = 0;
wrappedDomain.owner = DEFAULT_OWNER;
wrappedDomain.name = "test.eth";
wrappedDomain.save();

const nameUnwrappedEvent = createNameUnwrappedEvent(
subNamehash,
DEFAULT_OWNER
);

handleNameUnwrapped(nameUnwrappedEvent);

assert.fieldEquals("Domain", subNamehash, "expiryDate", "null");
});
});
55 changes: 55 additions & 0 deletions tests/testUtils.ts
@@ -0,0 +1,55 @@
import { Address, Bytes, ethereum } from "@graphprotocol/graph-ts";
import { newMockEvent } from "matchstick-as/assembly/index";
import { handleNewOwner } from "../src/ensRegistry";
import { NewOwner } from "../src/types/ENSRegistry/EnsRegistry";

export const DEFAULT_OWNER = "0x89205A3A3b2A69De6Dbf7f01ED13B2108B2c43e7";

export 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;
};

export const setEthOwner = (): void => {
const ethLabelhash =
"0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0";
const emptyNode =
"0x0000000000000000000000000000000000000000000000000000000000000000";
const newNewOwnerEvent = createNewOwnerEvent(
emptyNode,
ethLabelhash,
DEFAULT_OWNER
);
handleNewOwner(newNewOwnerEvent);
};

0 comments on commit 9211255

Please sign in to comment.