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

Feat: add utility function check for ERC-20 token allowance #23

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

GideonBature
Copy link

@GideonBature GideonBature commented Dec 22, 2024

This utility function interacts with the blockchain to call the allowance function which returns the price/value/number of allowance. Also, there are unit tests covering several test-cases.

Please do have a look at it, to run the test cases one will need the token address as well as the rpc provider which the token was deployed on. Thank you!

ref: Connect to an Ethereum Node (ethers_rs docs)

@GideonBature GideonBature marked this pull request as draft December 22, 2024 03:56
@GideonBature GideonBature marked this pull request as ready for review December 22, 2024 07:07
@Abeeujah
Copy link
Collaborator

Hi @GideonBature Great job so far, but a bit of misunderstanding I see... This function is to read allowance for ERC20 tokens deployed on Starknet, not on Ethereum.

@GideonBature
Copy link
Author

Oh... 😅 I see, I misunderstood it then. I will make necessary changes and push again. Thank you for the review!

@GideonBature
Copy link
Author

@Abeeujah Please do check. I have re-implemented it for Starknet Blockchain.

@Abeeujah
Copy link
Collaborator

Hi @GideonBature,

Thank you for your submission, here's a few suggestions:

  1. Environment Variables: To improve security and configuration management, I'd recommend you refactor the code to retrieve the RPC_URL and TOKEN_CONTRACT_ADDRESS values from environment variables. Please also ensure that the .env.sample file is updated to reflect these changes.

  2. Test Coverage: While your test cases address certain scenarios, it's crucial to include a positive or "success" test case to validate the expected behavior of the code under normal conditions. This will provide a more comprehensive assessment of its functionality.

  3. Test Organization: For better code organization and maintainability, I suggest relocating the test cases from their current inline location to the dedicated tests folder. This separation of concerns will improve the overall structure of the project and make it easier to manage and expand the test suite in the future.

@GideonBature
Copy link
Author

Noted, I will do all these. For the tests, I thought about that, but seeing that the issue said unit tests, that was why I put it in same directory with the function. But I will do this. Thank you so much for these reviews. I will implement these and push again.

@GideonBature
Copy link
Author

Please do check if it's okay now, for the TEST_TOKEN, because I will have to convert it to Felt while testing using the felt!(" ") macros, I can't use a variable, the macros only accepts a &str as it needs to know the exact size/length of what it's working with.

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.

2 participants