Skip to content

Commit c844791

Browse files
authored
Merge pull request #87 from ensdomains/fix/expiry-date-check
fix: ensure consistent expiry date on domain entity
2 parents 17294f5 + 9211255 commit c844791

File tree

7 files changed

+194
-67
lines changed

7 files changed

+194
-67
lines changed

src/ethRegistrar.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { BigInt, ByteArray, Bytes, crypto, ens } from "@graphprotocol/graph-ts";
33

44
import {
5-
byteArrayFromHex,
65
checkValidLabel,
76
concat,
87
createEventID,
@@ -36,7 +35,7 @@ import {
3635

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

39-
var rootNode: ByteArray = byteArrayFromHex(ETH_NODE);
38+
var rootNode: ByteArray = ByteArray.fromHexString(ETH_NODE);
4039

4140
export function handleNameRegistered(event: NameRegisteredEvent): void {
4241
let account = new Account(event.params.owner.toHex());

src/nameWrapper.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,7 @@ function makeWrappedTransfer(
193193
to: string
194194
): void {
195195
const _to = createOrLoadAccount(to);
196-
const namehash =
197-
"0x" +
198-
node
199-
.toHex()
200-
.slice(2)
201-
.padStart(64, "0");
196+
const namehash = "0x" + node.toHex().slice(2).padStart(64, "0");
202197
const domain = createOrLoadDomain(namehash);
203198
let wrappedDomain = WrappedDomain.load(namehash);
204199
// new registrations emit the Transfer` event before the NameWrapped event
@@ -242,9 +237,7 @@ export function handleTransferBatch(event: TransferBatchEvent): void {
242237
makeWrappedTransfer(
243238
blockNumber,
244239
transactionID,
245-
createEventID(event)
246-
.concat("-")
247-
.concat(i.toString()),
240+
createEventID(event).concat("-").concat(i.toString()),
248241
ids[i],
249242
to.toHex()
250243
);

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function createEventID(event: ethereum.Event): string {
1010
}
1111

1212
export const ETH_NODE =
13-
"93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae";
13+
"0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae";
1414
export const ROOT_NODE =
1515
"0x0000000000000000000000000000000000000000000000000000000000000000";
1616
export const EMPTY_ADDRESS = "0x0000000000000000000000000000000000000000";

tests/.latest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"version": "0.6.0",
3-
"timestamp": 1704668302285
3+
"timestamp": 1707952879651
44
}

tests/ensRegistrar.test.ts

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,10 @@ import {
1111
handleNameRegisteredByController,
1212
} from "../src/ethRegistrar";
1313
import { NameRegistered } from "../src/types/BaseRegistrar/BaseRegistrar";
14-
import { NewOwner } from "../src/types/ENSRegistry/EnsRegistry";
1514
import { NameRegistered as NameRegisteredByController } from "../src/types/EthRegistrarController/EthRegistrarController";
1615
import { Registration } from "../src/types/schema";
17-
18-
const ETH_NAMEHASH =
19-
"0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae";
20-
21-
const DEFAULT_OWNER = "0x89205A3A3b2A69De6Dbf7f01ED13B2108B2c43e7";
16+
import { ETH_NODE } from "../src/utils";
17+
import { createNewOwnerEvent, DEFAULT_OWNER, setEthOwner } from "./testUtils";
2218

2319
const createNameRegisteredByControllerEvent = (
2420
name: string,
@@ -73,42 +69,6 @@ const createNameRegisteredByControllerEvent = (
7369
return nameRegisteredByControllerEvent;
7470
};
7571

76-
const createNewOwnerEvent = (
77-
node: string,
78-
label: string,
79-
owner: string
80-
): NewOwner => {
81-
let mockEvent = newMockEvent();
82-
let newNewOwnerEvent = new NewOwner(
83-
mockEvent.address,
84-
mockEvent.logIndex,
85-
mockEvent.transactionLogIndex,
86-
mockEvent.logType,
87-
mockEvent.block,
88-
mockEvent.transaction,
89-
mockEvent.parameters,
90-
mockEvent.receipt
91-
);
92-
93-
newNewOwnerEvent.parameters = new Array();
94-
let nodeParam = new ethereum.EventParam(
95-
"node",
96-
ethereum.Value.fromBytes(Bytes.fromHexString(node))
97-
);
98-
let labelParam = new ethereum.EventParam(
99-
"label",
100-
ethereum.Value.fromBytes(Bytes.fromHexString(label))
101-
);
102-
let ownerParam = new ethereum.EventParam(
103-
"owner",
104-
ethereum.Value.fromAddress(Address.fromString(owner))
105-
);
106-
newNewOwnerEvent.parameters.push(nodeParam);
107-
newNewOwnerEvent.parameters.push(labelParam);
108-
newNewOwnerEvent.parameters.push(ownerParam);
109-
return newNewOwnerEvent;
110-
};
111-
11272
const createNameRegisteredEvent = (
11373
id: string,
11474
owner: string,
@@ -145,16 +105,7 @@ const createNameRegisteredEvent = (
145105
};
146106

147107
beforeAll(() => {
148-
const ethLabelhash =
149-
"0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0";
150-
const emptyNode =
151-
"0x0000000000000000000000000000000000000000000000000000000000000000";
152-
const newNewOwnerEvent = createNewOwnerEvent(
153-
emptyNode,
154-
ethLabelhash,
155-
DEFAULT_OWNER
156-
);
157-
handleNewOwner(newNewOwnerEvent);
108+
setEthOwner();
158109
});
159110

160111
const checkNullLabelName = (
@@ -163,7 +114,7 @@ const checkNullLabelName = (
163114
label: string
164115
): void => {
165116
const newNewOwnerEvent = createNewOwnerEvent(
166-
ETH_NAMEHASH,
117+
ETH_NODE,
167118
labelhash,
168119
DEFAULT_OWNER
169120
);
@@ -257,7 +208,7 @@ test("does assign normal label", () => {
257208
const label = "test";
258209

259210
const newNewOwnerEvent = createNewOwnerEvent(
260-
ETH_NAMEHASH,
211+
ETH_NODE,
261212
labelhash,
262213
DEFAULT_OWNER
263214
);

tests/nameWrapper.test.ts

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import { Address, BigInt, Bytes, ethereum } from "@graphprotocol/graph-ts";
2+
import {
3+
assert,
4+
beforeAll,
5+
describe,
6+
newMockEvent,
7+
test,
8+
} from "matchstick-as/assembly/index";
9+
import { handleNameUnwrapped } from "../src/nameWrapper";
10+
import { NameUnwrapped } from "../src/types/NameWrapper/NameWrapper";
11+
import { Domain, WrappedDomain } from "../src/types/schema";
12+
import { ETH_NODE } from "../src/utils";
13+
import { DEFAULT_OWNER, setEthOwner } from "./testUtils";
14+
15+
beforeAll(() => {
16+
setEthOwner();
17+
});
18+
19+
const NAME_WRAPPER_ADDRESS = "0xD4416b13d2b3a9aBae7AcD5D6C2BbDBE25686401";
20+
// test.eth
21+
const testEthNamehash =
22+
"0xeb4f647bea6caa36333c816d7b46fdcb05f9466ecacc140ea8c66faf15b3d9f1";
23+
24+
const createNameUnwrappedEvent = (
25+
node: string,
26+
owner: string
27+
): NameUnwrapped => {
28+
let mockEvent = newMockEvent();
29+
let newNameUnwrappedEvent = new NameUnwrapped(
30+
mockEvent.address,
31+
mockEvent.logIndex,
32+
mockEvent.transactionLogIndex,
33+
mockEvent.logType,
34+
mockEvent.block,
35+
mockEvent.transaction,
36+
mockEvent.parameters,
37+
mockEvent.receipt
38+
);
39+
newNameUnwrappedEvent.parameters = new Array();
40+
let nodeParam = new ethereum.EventParam(
41+
"node",
42+
ethereum.Value.fromBytes(Bytes.fromHexString(node))
43+
);
44+
let ownerParam = new ethereum.EventParam(
45+
"owner",
46+
ethereum.Value.fromAddress(Address.fromString(owner))
47+
);
48+
newNameUnwrappedEvent.parameters.push(nodeParam);
49+
newNameUnwrappedEvent.parameters.push(ownerParam);
50+
return newNameUnwrappedEvent;
51+
};
52+
53+
describe("handleNameUnwrapped", () => {
54+
test("does not set expiryDate to null if name is .eth", () => {
55+
// test
56+
const labelhash =
57+
"0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658";
58+
59+
let domain = new Domain(testEthNamehash);
60+
domain.name = "test.eth";
61+
domain.labelName = "test";
62+
domain.labelhash = Bytes.fromHexString(labelhash);
63+
domain.parent = ETH_NODE;
64+
domain.subdomainCount = 0;
65+
domain.isMigrated = true;
66+
domain.createdAt = BigInt.fromI32(0);
67+
domain.owner = NAME_WRAPPER_ADDRESS;
68+
domain.registrant = NAME_WRAPPER_ADDRESS;
69+
domain.wrappedOwner = DEFAULT_OWNER;
70+
domain.expiryDate = BigInt.fromI32(123456789);
71+
domain.save();
72+
73+
const wrappedDomain = new WrappedDomain(testEthNamehash);
74+
wrappedDomain.domain = testEthNamehash;
75+
wrappedDomain.expiryDate = BigInt.fromI32(123456789);
76+
wrappedDomain.fuses = 0;
77+
wrappedDomain.owner = DEFAULT_OWNER;
78+
wrappedDomain.name = "test.eth";
79+
wrappedDomain.save();
80+
81+
const nameUnwrappedEvent = createNameUnwrappedEvent(
82+
testEthNamehash,
83+
DEFAULT_OWNER
84+
);
85+
86+
handleNameUnwrapped(nameUnwrappedEvent);
87+
88+
assert.fieldEquals("Domain", testEthNamehash, "expiryDate", "123456789");
89+
});
90+
test("sets expiryDate to null if name is not .eth", () => {
91+
// cool.test.eth
92+
const subNamehash =
93+
"0x85c47d906feeeed4795f21773ab20983af35e85837d2de39549f650c8fb50c0f";
94+
// cool
95+
const labelhash =
96+
"0x678c189fde5058554d934d6af17e41750fa2a94b61371c5ea958a7595e146324";
97+
98+
let domain = new Domain(subNamehash);
99+
domain.name = "cool.test.eth";
100+
domain.labelName = "cool";
101+
domain.labelhash = Bytes.fromHexString(labelhash);
102+
domain.parent = testEthNamehash;
103+
domain.subdomainCount = 0;
104+
domain.isMigrated = true;
105+
domain.createdAt = BigInt.fromI32(0);
106+
domain.owner = NAME_WRAPPER_ADDRESS;
107+
domain.registrant = NAME_WRAPPER_ADDRESS;
108+
domain.wrappedOwner = DEFAULT_OWNER;
109+
domain.expiryDate = BigInt.fromI32(123456789);
110+
domain.save();
111+
112+
const wrappedDomain = new WrappedDomain(subNamehash);
113+
wrappedDomain.domain = subNamehash;
114+
wrappedDomain.expiryDate = BigInt.fromI32(123456789);
115+
wrappedDomain.fuses = 0;
116+
wrappedDomain.owner = DEFAULT_OWNER;
117+
wrappedDomain.name = "test.eth";
118+
wrappedDomain.save();
119+
120+
const nameUnwrappedEvent = createNameUnwrappedEvent(
121+
subNamehash,
122+
DEFAULT_OWNER
123+
);
124+
125+
handleNameUnwrapped(nameUnwrappedEvent);
126+
127+
assert.fieldEquals("Domain", subNamehash, "expiryDate", "null");
128+
});
129+
});

tests/testUtils.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Address, Bytes, ethereum } from "@graphprotocol/graph-ts";
2+
import { newMockEvent } from "matchstick-as/assembly/index";
3+
import { handleNewOwner } from "../src/ensRegistry";
4+
import { NewOwner } from "../src/types/ENSRegistry/EnsRegistry";
5+
6+
export const DEFAULT_OWNER = "0x89205A3A3b2A69De6Dbf7f01ED13B2108B2c43e7";
7+
8+
export const createNewOwnerEvent = (
9+
node: string,
10+
label: string,
11+
owner: string
12+
): NewOwner => {
13+
let mockEvent = newMockEvent();
14+
let newNewOwnerEvent = new NewOwner(
15+
mockEvent.address,
16+
mockEvent.logIndex,
17+
mockEvent.transactionLogIndex,
18+
mockEvent.logType,
19+
mockEvent.block,
20+
mockEvent.transaction,
21+
mockEvent.parameters,
22+
mockEvent.receipt
23+
);
24+
25+
newNewOwnerEvent.parameters = new Array();
26+
let nodeParam = new ethereum.EventParam(
27+
"node",
28+
ethereum.Value.fromBytes(Bytes.fromHexString(node))
29+
);
30+
let labelParam = new ethereum.EventParam(
31+
"label",
32+
ethereum.Value.fromBytes(Bytes.fromHexString(label))
33+
);
34+
let ownerParam = new ethereum.EventParam(
35+
"owner",
36+
ethereum.Value.fromAddress(Address.fromString(owner))
37+
);
38+
newNewOwnerEvent.parameters.push(nodeParam);
39+
newNewOwnerEvent.parameters.push(labelParam);
40+
newNewOwnerEvent.parameters.push(ownerParam);
41+
return newNewOwnerEvent;
42+
};
43+
44+
export const setEthOwner = (): void => {
45+
const ethLabelhash =
46+
"0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0";
47+
const emptyNode =
48+
"0x0000000000000000000000000000000000000000000000000000000000000000";
49+
const newNewOwnerEvent = createNewOwnerEvent(
50+
emptyNode,
51+
ethLabelhash,
52+
DEFAULT_OWNER
53+
);
54+
handleNewOwner(newNewOwnerEvent);
55+
};

0 commit comments

Comments
 (0)