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

Add Nft Api Compute Rarity #148

Merged

Conversation

xeno097
Copy link
Contributor

@xeno097 xeno097 commented Oct 16, 2022

Changelog

  • Adds the computeRarity method in the nft namespace.
  • Adds the NftAttributeRarity type to represent the result of the computeRarity endpoint.
  • Fixes a typo in the OwnedBaseNftsResponse type doc.
  • Adds unit and integration tests for the computeRarity method.

Extra

I was considering wrapping the computeRarity endpoint result in an object with the following structure {attributes: NftAttributeRarity[] } and exposing that in the public API but then decided to keep the same format as the endpoint response. Also, I'll gladly accept suggestions for the NftAttributeRarity type name if you have a better name for this use case.
The other endpoints listed in #140 will be added in another pr.

@thebrianchen thebrianchen self-requested a review October 17, 2022 23:47
Copy link
Member

@thebrianchen thebrianchen left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on -- we really appreciate it! Also thanks for catching some typos :)

Left a few nits and comments, but this is really good 🔥

value: string;

/** The type of NFT attribute. */
trait_type: string;
Copy link
Member

Choose a reason for hiding this comment

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

Please rename to traitType in order to be consistent with JS style.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On it 👌🏼

/** The type of NFT attribute. */
trait_type: string;

/** The NFT's attribute frequency in the current collection. */
Copy link
Member

Choose a reason for hiding this comment

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

Please update comment to:
A number from 0 to 1 representing the prevalence of this value for this trait type in the current collection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okis, much better

const response = await alchemy.nft.computeRarity(contractAddress, tokenId);

expect(response).toBeDefined();
expect(response.length).toBeGreaterThan(0);
Copy link
Member

Choose a reason for hiding this comment

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

Please update the test to check that each field in the response type is present in the first element of the array.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the suggestion!

'contractAddress',
contractAddress
);
expect(mock.history.get[0].params).toHaveProperty('tokenId', tokenId);
Copy link
Member

Choose a reason for hiding this comment

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

Once you update trait_type to traitType, can you also add a test to check that the method converts the field properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, no problem.

Copy link
Member

@thebrianchen thebrianchen left a comment

Choose a reason for hiding this comment

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

Thanks for the clean PR and fast turnaround times! Left one last request, but will merge this in after that 🚀

@@ -1204,6 +1209,54 @@ describe('NFT module', () => {
});
});

describe('computeRarity()', () => {
const contractAddress = '0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d';
const tokenId = '7495';
Copy link
Member

Choose a reason for hiding this comment

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

one more request: can you use a numerical value for tokenId here to check that the logic to convert Bignumberish input to a string is properly executed? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ready 👌🏼

@xeno097
Copy link
Contributor Author

xeno097 commented Oct 18, 2022

Thanks for the clean PR and fast turnaround times! Left one last request, but will merge this in after that rocket

🔥

…g call works correctly in computeRarity tests
@thebrianchen thebrianchen merged commit 4bf4949 into alchemyplatform:main Oct 18, 2022
@xeno097 xeno097 deleted the xeno097/nft-api-compute-rarity branch October 18, 2022 20:37
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.

None yet

2 participants