-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathquery.integration.test.ts
More file actions
144 lines (125 loc) · 3.99 KB
/
query.integration.test.ts
File metadata and controls
144 lines (125 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { type Address, labelhash } from "viem";
import { describe, expect, it } from "vitest";
import { DatasourceNames } from "@ensnode/datasources";
import {
type DomainId,
getCanonicalId,
getDatasourceContract,
getENSv2RootRegistryId,
type InterpretedLabel,
makeENSv2DomainId,
type Name,
} from "@ensnode/ensnode-sdk";
import { DEVNET_NAMES } from "@/test/integration/devnet-names";
import {
type PaginatedDomainResult,
QueryDomainsPaginated,
} from "@/test/integration/domain-pagination-queries";
import { gql } from "@/test/integration/ensnode-graphql-api-client";
import {
flattenConnection,
type GraphQLConnection,
type PaginatedGraphQLConnection,
request,
} from "@/test/integration/graphql-utils";
import { testDomainPagination } from "@/test/integration/test-domain-pagination";
const namespace = "ens-test-env";
const V2_ROOT_REGISTRY = getDatasourceContract(
namespace,
DatasourceNames.ENSv2Root,
"RootRegistry",
);
const V2_ETH_CANONICAL_ID = getCanonicalId(labelhash("eth"));
const V2_ETH_DOMAIN_ID = makeENSv2DomainId(V2_ROOT_REGISTRY, V2_ETH_CANONICAL_ID);
describe("Query.root", () => {
it("returns the root registry", async () => {
await expect(request(gql`{ root { id } }`)).resolves.toMatchObject({
root: {
id: getENSv2RootRegistryId(namespace),
},
});
});
});
describe("Query.domains", () => {
type QueryDomainsResult = {
domains: GraphQLConnection<{
__typename: "ENSv1Domain" | "ENSv2Domain";
id: DomainId;
name: Name;
label: { interpreted: InterpretedLabel };
owner: { address: Address };
}>;
};
const QueryDomains = gql`
query QueryDomains($name: String!, $canonical: Boolean, $order: DomainsOrderInput) {
domains(where: { name: $name, canonical: $canonical }, order: $order) {
edges {
node {
__typename
id
name
label {
interpreted
}
owner {
address
}
}
}
}
}
`;
it("requires the name filter", async () => {
await expect(request(gql`{ domains { edges { node { id }} } }`)).rejects.toThrow(
'argument "where" of type "DomainsWhereInput!" is required, but it was not provided',
);
});
it("sees .eth domain", async () => {
const result = await request<QueryDomainsResult>(QueryDomains, { name: "eth" });
const domains = flattenConnection(result.domains);
// there's at least a v2 'eth' domain
expect(domains.length).toBeGreaterThanOrEqual(1);
const v1EthDomain = domains.find((d) => d.__typename === "ENSv1Domain" && d.name === "eth");
const v2EthDomain = domains.find((d) => d.__typename === "ENSv2Domain" && d.name === "eth");
// TODO: the v1 eth label should surely exist but i don't see it in devnet at the moment?
expect(v1EthDomain).toBeUndefined();
// expect(v1EthDomain).toMatchObject({
// id: V1_ETH_DOMAIN_ID,
// name: "eth",
// label: { interpreted: "eth" },
// });
expect(v2EthDomain).toMatchObject({
id: V2_ETH_DOMAIN_ID,
name: "eth",
label: { interpreted: "eth" },
});
});
});
describe("Query.domain", () => {
const DomainByName = gql`
query DomainByName($name: Name!) {
domain(by: { name: $name }) {
name
}
}
`;
it.each(DEVNET_NAMES)("resolves $name", async ({ name, canonical }) => {
await expect(request(DomainByName, { name })).resolves.toMatchObject({
domain: { name: canonical },
});
});
it("returns null for a nonexistent name", async () => {
await expect(
request(DomainByName, { name: "this-name-definitely-does-not-exist-xyz123.eth" }),
).resolves.toMatchObject({ domain: null });
});
});
describe("Query.domains pagination", () => {
testDomainPagination(async (variables) => {
const result = await request<{ domains: PaginatedGraphQLConnection<PaginatedDomainResult> }>(
QueryDomainsPaginated,
variables,
);
return result.domains;
});
});