Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoints and types refactor for evm #787

Merged
merged 43 commits into from
Nov 9, 2022

Conversation

ErnoW
Copy link
Member

@ErnoW ErnoW commented Nov 1, 2022


name: 'Pull request'
about: A new pull request

New Pull Request

Checklist

  • I am not disclosing a vulnerability.
  • My code is conform the code style
  • I have made corresponding changes to the documentation
  • I have updated Typescript definitions when needed

Issue Description

Related issue: #FILL_THIS_OUT

Solution Description

@changeset-bot
Copy link

changeset-bot bot commented Nov 1, 2022

⚠️ No Changeset found

Latest commit: d6e1b49

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Nov 3, 2022

Test coverage

Title Lines Statements Branches Functions
api-utils Coverage: 56%
56.34% (262/465) 43.85% (50/114) 57.73% (56/97)
auth Coverage: 100%
100% (143/143) 90.9% (20/22) 100% (42/42)
evm-api Coverage: 92%
92.72% (51/55) 66.66% (4/6) 81.25% (13/16)
common-evm-utils Coverage: 64%
65.02% (939/1444) 20.19% (123/609) 35.89% (201/560)
sol-api Coverage: 100%
100% (20/20) 66.66% (4/6) 100% (6/6)
common-sol-utils Coverage: 75%
74.86% (134/179) 63.15% (12/19) 65.67% (44/67)
common-streams-utils Coverage: 95%
95.6% (674/705) 97.93% (190/194) 100% (244/244)
streams Coverage: 82%
82.72% (388/469) 64% (64/100) 73.6% (92/125)

@sogunshola sogunshola marked this pull request as ready for review November 7, 2022 09:37
Copy link
Collaborator

@b4rtaz b4rtaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sogunshola *Request & *Response types should have same prefix as OperationId (same uppercase lowercase letters). You may run the yarn gen:client command for the @moralisweb3/client-evm-api and the @moralisweb3/client-sol-api packages and check that, the generated clients have correct references.


// Exports

export type GetContractNfTsRequest = Camelize<Omit<RequestParams, 'chain' | 'address'>> & {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetContract >> NfTs << Request -> NFTs


// Exports

export type GetNftContractMetadataRequest = Camelize<Omit<RequestParams, 'chain' | 'address'>> & {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetNftContractMetadataRequest -> GetNFTContractMetadataRequest

function getRequestUrlParams(request: GetPairReservesRequest, core: Core) {
return {
chain: EvmChainResolver.resolve(request.chain, core).apiHex,
pairAddress: EvmAddress.create(request.pairAddress, core).lowercase,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be pair_address as we have in openapi?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see some renaming to camelcase across getRequestUrlParams functions. But as I understand params inside should be equal to query+path?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! The getRequestUrlParams should return names using by the API (especially search parameters, url parameters depend on the urlPathPattern property).

Copy link
Contributor

@Y0moo Y0moo Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we simply can declare in all getRequestUrlParams functions the returned type RequestParams:

function getRequestUrlParams(request: GetPairAddressRequest, core: Core) : RequestParams { }

Nope, ignore my message above. There may be needed some type overwritings. For example in openapi we have block with number type, but in SDK it's a string

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make a type Record<keyof RequestParams, string | undefined>, but I don't like this approach since it makes code more complicated. I guess it'd be better to put this check to the tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a small problem here.

public prepareUrl(baseUrl: string, request: Request) {
    const urlParams = this.operation.getRequestUrlParams(request, this.core);

    let urlPath = this.operation.urlPathPattern;

    for (const paramName of this.operation.urlPathParamNames) {
      const paramValue = urlParams[paramName as string];
      if (!paramValue) {
        throw new Error(`Param ${paramName as string} is required`);
      }
      urlPath = urlPath.replace(`{${paramName as string}}`, paramValue as string);
    }
    const url = `${baseUrl}${urlPath}`;

    const urlSearchParams: Record<string, string | string[]> = {};
    Object.keys(urlParams)
      .filter((paramName) => !this.operation.urlPathParamNames.includes(paramName as keyof Request))
      .forEach((paramName) => {
        const paramValue = urlParams[paramName];
        if (paramValue) {
          urlSearchParams[paramName] = paramValue;
        }
      });

    return { url, urlSearchParams };
  }

in this logic, the urlPathParamNames is (keyof Request)[] which has been camelized so the paramName searched for in the urlParams has to be camelCased as well hence the change to camel case. this is not the case for the search parameters because this logic does not make use of urlSearchParamNames. To change this to snake case, we have to change the expected type for urlPathParamNames.
@b4rtaz @Y0moo

Comment on lines 23 to 25
ignoreBodyCheckOperationNames.forEach((name) => {
operation.bodyParamNames?.splice(operation.bodyParamNames.indexOf(name as never), 1);
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is too complicated. You can simplify this:

 const ignoreBodyCheckOperationNames = ['getContractEvents', 'uploadFolder'];
// ...

if (!ignoreBodyCheckOperationNames.includes(operation.name)) {
        expect(bodyParamNames?.sort().join(',')).toBe(openApiBodyParamNames?.sort().join(','));
}

Copy link
Collaborator

@b4rtaz b4rtaz Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want skip operations, not parameter names.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

@sogunshola sogunshola merged commit 475fc70 into beta Nov 9, 2022
@sogunshola sogunshola deleted the endpoints-and-types-refactor-for-evm branch November 9, 2022 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants