-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
198 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@moralisweb3/common-evm-utils': patch | ||
'@moralisweb3/evm-api': patch | ||
--- | ||
|
||
Added `resolveENSDomain` method to the EvmApi module. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './resolveAddressOperation'; | ||
export * from './resolveDomainOperation'; | ||
export * from './resolveENSDomainOperation'; |
24 changes: 24 additions & 0 deletions
24
packages/common/evmUtils/src/operations/resolve/resolveENSDomainOperation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import MoralisCore from '@moralisweb3/common-core'; | ||
import { resolveENSDomainOperation, ResolveENSDomainJSONRequest } from './resolveENSDomainOperation'; | ||
|
||
describe('resolveENSDomainOperation', () => { | ||
let core: MoralisCore; | ||
|
||
beforeAll(() => { | ||
core = MoralisCore.create(); | ||
}); | ||
|
||
it('serializeRequest() serializes correctly and deserializeRequest() deserializes correctly', () => { | ||
const request: Required<ResolveENSDomainJSONRequest> = { | ||
domain: 'nick.eth', | ||
}; | ||
|
||
const serializedRequest = resolveENSDomainOperation.serializeRequest(request, core); | ||
|
||
expect(serializedRequest.domain).toBe(request.domain); | ||
|
||
const deserializedRequest = resolveENSDomainOperation.deserializeRequest(serializedRequest, core); | ||
|
||
expect(deserializedRequest.domain).toBe(request.domain); | ||
}); | ||
}); |
71 changes: 71 additions & 0 deletions
71
packages/common/evmUtils/src/operations/resolve/resolveENSDomainOperation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import Core, { Camelize, Operation, ResponseAdapter } from '@moralisweb3/common-core'; | ||
import { EvmAddress } from '../../dataTypes'; | ||
|
||
import { operations } from '../openapi'; | ||
|
||
type OperationId = 'resolveENSDomain'; | ||
|
||
type PathParams = operations[OperationId]['parameters']['path']; | ||
type RequestParams = PathParams; | ||
|
||
type SuccessResponse = operations[OperationId]['responses']['200']['content']['application/json']; | ||
|
||
// Exports | ||
|
||
export interface ResolveENSDomainRequest extends Camelize<RequestParams> {} | ||
|
||
export type ResolveENSDomainJSONRequest = ReturnType<typeof serializeRequest>; | ||
|
||
export type ResolveENSDomainJSONResponse = SuccessResponse; | ||
|
||
export type ResolveENSDomainResponse = ReturnType<typeof deserializeResponse>; | ||
|
||
export interface ResolveENSDomainResponseAdapter | ||
extends ResponseAdapter<ResolveENSDomainResponse, ResolveENSDomainJSONResponse> {} | ||
|
||
/** Resolve a specific ENS domain to its address. */ | ||
export const resolveENSDomainOperation: Operation< | ||
ResolveENSDomainRequest, | ||
ResolveENSDomainJSONRequest, | ||
ResolveENSDomainResponse, | ||
ResolveENSDomainJSONResponse | ||
> = { | ||
method: 'GET', | ||
name: 'resolveENSDomain', | ||
id: 'resolveENSDomain', | ||
groupName: 'resolve', | ||
isNullable: true, | ||
urlPathPattern: '/resolve/ens/{domain}', | ||
urlPathParamNames: ['domain'], | ||
|
||
getRequestUrlParams, | ||
serializeRequest, | ||
deserializeRequest, | ||
deserializeResponse, | ||
}; | ||
|
||
// Methods | ||
|
||
function getRequestUrlParams(request: ResolveENSDomainRequest) { | ||
return { | ||
domain: request.domain, | ||
}; | ||
} | ||
|
||
function serializeRequest(request: ResolveENSDomainRequest) { | ||
return { | ||
domain: request.domain, | ||
}; | ||
} | ||
|
||
function deserializeRequest(jsonRequest: ResolveENSDomainJSONRequest): ResolveENSDomainRequest { | ||
return { | ||
domain: jsonRequest.domain, | ||
}; | ||
} | ||
|
||
function deserializeResponse(jsonResponse: ResolveENSDomainJSONResponse, _: ResolveENSDomainRequest, core: Core) { | ||
return { | ||
address: EvmAddress.create(jsonResponse.address, core), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/evmApi/integration/mocks/endpoints/resolveENSDomain.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { MockScenarios } from '@moralisweb3/test-utils'; | ||
import { createErrorResponse } from '../response/errorResponse'; | ||
|
||
export const mockResolveENSDomain = MockScenarios.create( | ||
{ | ||
name: 'mockResolveENSDomain', | ||
method: 'get', | ||
url: '/resolve/ens/:domain', | ||
getParams: ({ req }) => ({ | ||
domain: req.params.domain, | ||
}), | ||
}, | ||
[ | ||
{ | ||
condition: { | ||
domain: 'nick.eth', | ||
}, | ||
response: { | ||
address: '0xb8c2C29ee19D8307cb7255e1Cd9CbDE883A267d5', | ||
}, | ||
}, | ||
{ | ||
condition: { | ||
domain: 'unknown.eth', | ||
}, | ||
responseStatus: 404, | ||
response: createErrorResponse('null'), | ||
}, | ||
], | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { EvmApi } from '../../src/EvmApi'; | ||
import { cleanEvmApi, setupEvmApi } from '../setup'; | ||
|
||
describe('resolveENSDomain', () => { | ||
let evmApi: EvmApi; | ||
|
||
beforeAll(() => { | ||
evmApi = setupEvmApi(); | ||
}); | ||
|
||
afterAll(() => { | ||
cleanEvmApi(); | ||
}); | ||
|
||
it('returns an address', async () => { | ||
const result = await evmApi.resolve.resolveENSDomain({ | ||
domain: 'nick.eth', | ||
}); | ||
|
||
expect(result?.result.address.checksum).toEqual('0xb8c2C29ee19D8307cb7255e1Cd9CbDE883A267d5'); | ||
}); | ||
|
||
it('returns null when API returns HTTP 404', async () => { | ||
const result = await evmApi.resolve.resolveENSDomain({ | ||
domain: 'unknown.eth', | ||
}); | ||
|
||
expect(result).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8caf913
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test coverage