Skip to content

Commit

Permalink
repair offchain resolver test
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexNi245 committed Aug 30, 2023
1 parent 8ca037b commit 7476759
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/offchain-resolver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"yaml": "^2.1.3"
},
"scripts": {
"docker:up": "docker-compose up -d",
"docker:up": "docker compose up -d",
"test": "yarn docker:up && yarn prisma:migrate && yarn mocha --require ts-node/register --extension .test.ts --recursive ./src",
"start": "yarn prisma:migrate && yarn ts-node --transpile-only ./src/index.ts",
"build": "yarn prisma generate --schema=./src/persistance/schema.prisma && yarn tsc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export function getResolverInterface() {
return new ethers.utils.Interface([
// eslint-disable-next-line max-len
'function resolveWithContext(bytes calldata name,bytes calldata data,bytes calldata context) external view returns (bytes memory result)',
'function resolve(bytes calldata name, bytes calldata data) external view returns(bytes)',
//Text
'function text(bytes32 node, string calldata key) external view returns (string memory)',
//Address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ export async function handleCcipRequest(
switch (signature) {
case 'text(bytes32,string)':
req.app.locals.logger.info('Reading text(bytes32,string)');
return ethers.utils.defaultAbiCoder.encode(
['string'],
[await handleText(req.app.locals.db, request)],
);
const profile = await handleText(req.app.locals.db, request);
//If the profile is null, return without encoding. The gateway returns 404 if the response is null
if (!profile) {
return null;
}
return ethers.utils.defaultAbiCoder.encode(['string'], [profile]);
case 'addr(bytes32)':
req.app.locals.logger.info('Reading addr(bytes32))');
return await handleAddr(req.app.locals.db, request);
Expand Down
15 changes: 5 additions & 10 deletions packages/offchain-resolver/src/http/profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ describe('Profile', () => {
};

app.locals.config.spamProtection = true;

process.env.REACT_APP_ADDR_ENS_SUBDOMAIN = '.beta-addr.dm3.eth';
});

afterEach(async () => {
Expand All @@ -80,10 +82,7 @@ describe('Profile', () => {
.post(`/name`)
.send({
alias: 'foo.dm3.eth',
name:
SENDER_ADDRESS +
'.' +
globalConfig.ADDR_ENS_SUBDOMAIN(),
name: SENDER_ADDRESS + globalConfig.ADDR_ENS_SUBDOMAIN(),
signature: await app.locals.forTests.wallet.signMessage(
'alias: foo.dm3.eth',
),
Expand Down Expand Up @@ -116,7 +115,6 @@ describe('Profile', () => {
alias: 'foo.dm3.eth',
name:
offChainProfile1.signer +
'.' +
globalConfig.ADDR_ENS_SUBDOMAIN(),
signature: await sign(
offChainProfile1.privateSigningKey,
Expand Down Expand Up @@ -152,7 +150,6 @@ describe('Profile', () => {
alias: 'foo.dm3.eth',
name:
offChainProfile.signer +
'.' +
globalConfig.ADDR_ENS_SUBDOMAIN(),
signature: await sign(
offChainProfile.privateSigningKey,
Expand Down Expand Up @@ -192,7 +189,6 @@ describe('Profile', () => {
alias: 'foo.dm3.eth',
name:
offChainProfile1.signer +
'.' +
globalConfig.ADDR_ENS_SUBDOMAIN(),
signature: await sign(
offChainProfile1.privateSigningKey,
Expand Down Expand Up @@ -229,7 +225,6 @@ describe('Profile', () => {
alias: 'foo.dm3.eth',
name:
offChainProfile1.signer +
'.' +
globalConfig.ADDR_ENS_SUBDOMAIN(),
signature: await sign(
offChainProfile1.privateSigningKey,
Expand Down Expand Up @@ -369,7 +364,7 @@ describe('Profile', () => {
.post(`/name`)
.send({
alias: 'foo.dm3.eth',
name: signer + '.' + globalConfig.ADDR_ENS_SUBDOMAIN(),
name: signer + globalConfig.ADDR_ENS_SUBDOMAIN(),
signature: await sign(
privateSigningKey,
'alias: foo.dm3.eth',
Expand Down Expand Up @@ -428,7 +423,7 @@ describe('Profile', () => {
.post(`/name`)
.send({
alias: 'foo.dm3.eth',
name: signer + '.' + globalConfig.ADDR_ENS_SUBDOMAIN(),
name: signer + globalConfig.ADDR_ENS_SUBDOMAIN(),
signature: await sign(
privateSigningKey,
'alias: foo.dm3.eth',
Expand Down
2 changes: 1 addition & 1 deletion packages/offchain-resolver/src/http/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export function profile(web3Provider: ethers.providers.BaseProvider) {
});
}

const name = `${address}.${globalConfig.ADDR_ENS_SUBDOMAIN()}`;
const name = `${address}${globalConfig.ADDR_ENS_SUBDOMAIN()}`;

const profileExists =
!!(await req.app.locals.db.getProfileContainer(name));
Expand Down
19 changes: 15 additions & 4 deletions packages/offchain-resolver/src/http/resolverEndpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ describe('Resolver Endpoint', () => {
// eslint-disable-next-line no-console
warn: (msg: string) => console.log(msg),
};

process.env.REACT_APP_ADDR_ENS_SUBDOMAIN = '.beta-addr.dm3.eth';
});

afterEach(async () => {
Expand Down Expand Up @@ -98,7 +100,6 @@ describe('Resolver Endpoint', () => {
const { body, status } = await request(ccipApp)
.get(`/${ethers.constants.AddressZero}/${outerCall}`)
.send();

expect(status).to.equal(200);
expect(body.response).to.equal(
'0x25A643B6e52864d0eD816F1E43c0CF49C83B8292',
Expand Down Expand Up @@ -134,7 +135,12 @@ describe('Resolver Endpoint', () => {
.send();

expect(status).to.equal(200);
expect(body.response).to.equal('test');

const [decoded] = ethers.utils.defaultAbiCoder.decode(
['string'],
body.response,
);
expect(decoded).to.equal('test');
});
});

Expand Down Expand Up @@ -162,7 +168,7 @@ describe('Resolver Endpoint', () => {
.post(`/name`)
.send({
alias: 'foo.dm3.eth',
name: signer + '.' + globalConfig.ADDR_ENS_SUBDOMAIN(),
name: signer + globalConfig.ADDR_ENS_SUBDOMAIN(),
signature: await sign(
privateSigningKey,
'alias: foo.dm3.eth',
Expand All @@ -186,8 +192,13 @@ describe('Resolver Endpoint', () => {
.get(`/${ethers.constants.AddressZero}/${outerCall}`)
.send();

const [decoded] = ethers.utils.defaultAbiCoder.decode(
['string'],
body.response,
);

expect(status).to.equal(200);
expect(body.response).to.equal(
expect(decoded).to.equal(
'data:application/json,' +
stringify({
profile,
Expand Down
2 changes: 1 addition & 1 deletion packages/offchain-resolver/src/http/resolverEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function resolverEndpoint() {

res.status(404).send({ message: 'Record not found' });
} else {
res.send(response);
res.status(200).send({ response });
}
} catch (e) {
req.app.locals.logger.warn((e as Error).message);
Expand Down

0 comments on commit 7476759

Please sign in to comment.