StarknetByExample icon indicating copy to clipboard operation
StarknetByExample copied to clipboard

feat: add tests

Open julio4 opened this issue 1 year ago • 35 comments

Most of the current listings do not have tests. Adding tests would ensure that we have not left any logic errors that could confuse readers later on.

We need to add atleast simple integration tests for all contracts. Unit tests can be added for more complex contracts.

  • Integration tests are tests that deploy the contract and interact with it's provided interface. They should be placed on a separate file/module tests.cairo.

  • Unit tests do not have to deploy the contract and use the interface. Unit tests can use mocked implementation or state to test only one specific feature. They should be placed on the same file as the example (and hidden in the book using ANCHOR).

You do not have to add tests to all missing listings at once.

See this as a reference.

Please open a PR per example.

julio4 avatar Aug 28 '23 08:08 julio4

I will be working on this

ebbieaden avatar Aug 28 '23 21:08 ebbieaden

@ebbieaden is working on storing_arrays, simple_vault and upgradeable_contract.

julio4 avatar Aug 29 '23 08:08 julio4

hi @julio4 can I add more test?

petersdt avatar May 22 '24 20:05 petersdt

hi @julio4 can i jump on this ?

NueloSE avatar May 22 '24 20:05 NueloSE

hi @julio4 I will love to work on this

CollinsC1O avatar May 23 '24 01:05 CollinsC1O

@petersdt @NueloSE @CollinsC1O Thank you for your interest. Currently, all chapter0 examples are tested. You can pick any listings without tests and list it here to be assigned to it. You can take a look at #179 #181 #182 as examples.

julio4 avatar May 23 '24 02:05 julio4

Hey @julio4 can i work on components_dependencies

No-bodyq avatar May 23 '24 10:05 No-bodyq

i can work on this

the-first-elder avatar May 24 '24 11:05 the-first-elder

i can work on this

You need to specify the 1-3 tests you want to work on it. Only complete tests will be accepted!

julio4 avatar May 24 '24 11:05 julio4

@petersdt @NueloSE @CollinsC1O Thank you for your interest. Currently, all chapter0 examples are tested. You can pick any listings without tests and list it here to be assigned to it. You can take a look at #179 #181 #182 as examples.

@julio4 can i work on components

NueloSE avatar May 24 '24 12:05 NueloSE

@julio4 can i work on smart Vault

petersdt avatar May 24 '24 13:05 petersdt

i can work on this

You need to specify the 1-3 tests you want to work on it. Only complete tests will be accepted!

i can work on switchable and token

the-first-elder avatar May 24 '24 13:05 the-first-elder

@NueloSE , @petersdt OK! @the-first-elder ok for token. Switchable is part of components assigned to @NueloSE currently.

julio4 avatar May 26 '24 08:05 julio4

Hi @julio4 I will love to work on cairo_cheatsheet

CollinsC1O avatar May 26 '24 15:05 CollinsC1O

Hi @julio4 I would like to work on simple_vault.cairo kindly assign it to me.

LamsyA avatar May 27 '24 14:05 LamsyA

I can work on upgradeable contracts

the-first-elder avatar May 27 '24 19:05 the-first-elder

@julio4 I've gone through the upgradable contract and I can work on it. Please can you kindly assign it to me. Thank you

Timilehin-bello avatar May 28 '24 01:05 Timilehin-bello

Hi @julio4 I will love to work on cairo_cheatsheet

Exceptionally, we will not add tests for the cairo cheatsheet section

julio4 avatar May 28 '24 08:05 julio4

@julio4 I've gone through the upgradable contract and I can work on it. Please can you kindly assign it to me. Thank you

Ok! @the-first-elder, let's finish token tests and you can work on another one just after!

julio4 avatar May 28 '24 08:05 julio4

@julio4 I've gone through the upgradable contract and I can work on it. Please can you kindly assign it to me. Thank you

@julio4 I don't know if it's fine for me to work on it since @the-first-elder is working on something else.

As I mention in my previous message here, I've gone through the upgradable contract and I know I can work on it. Please can you kindly assign it to me. I will make sure to complete the task on time. Thank you

Timilehin-bello avatar May 28 '24 11:05 Timilehin-bello

Hi @julio4 I would like to work on simple_vault.cairo kindly assign it to me.

hi @julio4 @LamsyA i have already been assigned smart Vault and am making a PR soon

petersdt avatar May 29 '24 12:05 petersdt

Hey @julio4 is there any tests left I can work on? Maybe Constant Product AMM since OZ#953 has been fixed now. https://github.com/NethermindEth/StarknetByExample/blob/main/listings/applications/constant_product_amm/src/tests.cairo#L41

saimeunt avatar May 30 '24 10:05 saimeunt

Hello @julio4 I have added test to simple_vault contract this is the PR

LamsyA avatar Jun 01 '24 17:06 LamsyA

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hi, I'm Nemesis Alfaro from Costa Rica, i'm a system engineer. I love to learn and practice about different tecnologies. I'm hard-working, constant and curious person This would be my first contribution on the platform, in order to gain more knowledge and improve in the area.

How I plan on tackling this issue

First, i would like carefully read the request and be in contact with you for more infomation. Then i would to further investigate about the options to solve the issue

nemealfaro avatar Jun 28 '24 22:06 nemealfaro

Hi, I'm Nemesis Alfaro from Costa Rica, i'm a system engineer. ...

Thank you for your interest! Please take a look at the contributing guide to get started.

julio4 avatar Jul 01 '24 02:07 julio4

Thank you for the opportunity, I will review it and if I have any questions, I will contact you

nemealfaro avatar Jul 01 '24 06:07 nemealfaro

New missing tests: simple_account

julio4 avatar Jul 01 '24 07:07 julio4

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

My recent focus in Ethereum-Solidity and Starknet-Cairo has significantly deepened my understanding of web3 technologies, positioning me well to contribute to innovative projects in the blockchain space. As an alumnus of Web3Bridge, where I received training in Solidity and Cairo, I have developed a solid foundation in these technologies. I am eager to contribute to open-source projects within the Starknet ecosystem, and I am particularly excited about the opportunity to make meaningful contributions to this project. Given the chance, I am committed to delivering my best work and leveraging my skills to drive success.

How I plan on tackling this issue

To approach the task of adding integration and unit tests to the Starknet by Example collection, we need a structured plan.

First, set up the testing environment by ensuring that all necessary tools and libraries are installed. This includes Cairo, Starknet CLI, and the Starknet testing framework, such as pytest. Organize your repository to accommodate both the contract examples and their respective tests, perhaps by creating separate directories for contracts and tests.

Next, thoroughly review each contract example to understand its functionality. Identify the key features that need testing and determine the main scenarios to be tested, which includes both integration tests and unit tests.

For integration tests, create a tests.cairo file in a dedicated tests directory for each example. Write test cases that deploy the contract and assert successful deployment. Additionally, write tests that interact with the contract's methods to verify the expected outcomes, simulating real-world use cases. An example of such a test involves deploying the contract and calling its methods, then asserting that the responses are as expected.

For unit tests, add them within the same file as the example for more complex contracts. These tests can be hidden in the book using anchors if necessary. Use mocked implementations or states to isolate and test specific features of the contract. An example unit test involves mocking a specific function or state and asserting the expected behavior.

Once the tests are written, create a new branch for each example you're adding tests to. Add and commit the changes with a descriptive message, then push the branch to your repository and open a PR with a clear description of the changes made.

Ensure that each PR undergoes a thorough code review to confirm that the tests are comprehensive and accurate. Make any necessary changes based on feedback received during the review process, and merge the PRs once they are approved.

To maintain quality, set up a CI pipeline, such as GitHub Actions or GitLab CI, to automatically run tests on every push or PR. This ensures that all tests pass before any changes are merged into the main branch.

By following this structured approach, you can systematically add integration and unit tests to the Starknet by Example collection, ensuring each contract is well-tested and reliable.

Ternder001 avatar Jul 20 '24 08:07 Ternder001

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a solidity developer and migrating to being a cairo developer

How I plan on tackling this issue

First find the logic to solving the problem and then one by one implement things by reading the documentation for the language.

Giri-Aayush avatar Jul 27 '24 09:07 Giri-Aayush

heyyyy @julio4 is this still available? any function to test? let me know

EmmanuelAR avatar Aug 12 '24 18:08 EmmanuelAR