Skip to content

Commit

Permalink
test: fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qd-qd committed Aug 24, 2022
1 parent 243d7ff commit 9e7a89e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
3 changes: 2 additions & 1 deletion packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const provider = new ethers.providers.JsonRpcProvider(options.provider, {
let resolveName: null | string;
try {
resolveName = await provider.resolveName(name);
} catch {
} catch (e) {
console.log(e);
console.log("the subdomain doesn't exist on the layer2");
return;
}
Expand Down
11 changes: 5 additions & 6 deletions packages/gateway/test/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const VALID_ETH_ADDRESS = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8";

const resolve = (signature: string, args: string[] | ethers.BigNumber[]) => {
switch (signature) {
case 'addr(bytes32)': {
const [nodehash] = args;
return nodehash === VALID_NODE_HASH ? VALID_ETH_ADDRESS : constants.AddressZero;
}

case 'contenthash(bytes32)': {
const [nodehash] = args;
return nodehash !== VALID_NODE_HASH
Expand Down Expand Up @@ -74,12 +79,6 @@ class MockedProvider extends providers.JsonRpcProvider {
})
}

// 'addr(bytes32,uint256)'
resolveName(name: string): Promise<string | null> {
if (name === this.VALID_NODE) return Promise.resolve(VALID_ETH_ADDRESS);
return Promise.resolve(ethers.constants.AddressZero);
}

getResolver(name: string): Promise<ethers.providers.Resolver | null> {
const fakeResolver = { address: ethers.constants.AddressZero } as ethers.providers.Resolver;
if (name === this.VALID_NODE) return Promise.resolve(fakeResolver);
Expand Down
15 changes: 5 additions & 10 deletions packages/gateway/test/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,13 @@ describe('makeServer', () => {
});

test('resolves nonexistent subdomain', async () => {
const response = await makeCall('addr(bytes32)', 'test.mydao.eth');
expect(response).toStrictEqual({
status: 200,
result: Resolver.encodeFunctionResult('addr(bytes32)', [ethers.constants.AddressZero]),
});
return makeCall('addr(bytes32)', 'test.mydao.eth').catch(e =>
expect(e).toEqual(new Error("No resolver attached to this name")));
});

test('resolves random name', async () => {
const response = await makeCall('addr(bytes32)', 'foo.eth');
expect(response).toStrictEqual({
status: 200,
result: Resolver.encodeFunctionResult('addr(bytes32)', [ethers.constants.AddressZero]),
});
return makeCall('addr(bytes32)', 'test.mydao.eth').catch(e =>
expect(e).toEqual(new Error("No resolver attached to this name")));
});
});

Expand Down Expand Up @@ -202,5 +196,6 @@ describe('makeServer', () => {
return makeCall('contenthash(bytes32)', 'foo.eth').catch(e =>
expect(e).toEqual(new Error("No resolver attached to this name")));
});

});
});

0 comments on commit 9e7a89e

Please sign in to comment.