Flex-NFT-Marketplace / Flex-Marketplace-Contract

10 stars 31 forks source link

test: Write unit tests for ERC721_open_edition and ERC721_open_edition_multi_metadata #80

Open 0xandee opened 3 weeks ago

0xandee commented 3 weeks ago

Complete the unit test of openedition/ERC721_open_edition.cairo and openedition/ERC721_open_edition_multi_metadata.cairo, write test cases in openedition/tests folder.

Use scarb test to run all the tests.

All test cases are required to PASS.

ShantelPeters commented 3 weeks ago

Hi @0xandee can I be assigned to this issue ?

kateberryd commented 3 weeks ago

Hi @0xandee i would love to work on this

onlydustapp[bot] commented 3 weeks ago

Hi @kateberryd! Maintainers during the ODHack # 7.0 will be tracking applications via OnlyDust. Therefore, in order for you to have a chance at being assigned to this issue, please apply directly here, or else your application may not be considered.

CollinsC1O commented 3 weeks ago

Hello @0xandee I will love to work on this issue

onlydustapp[bot] commented 3 weeks ago

Hi @CollinsC1O! Maintainers during the ODHack # 7.0 will be tracking applications via OnlyDust. Therefore, in order for you to have a chance at being assigned to this issue, please apply directly here, or else your application may not be considered.

MullerTheScientist commented 3 weeks ago

Hello @0xandee I want to work on this, I have experience in Writing test

onlydustapp[bot] commented 3 weeks ago

Hi @MullerTheScientist! Maintainers during the ODHack # 7.0 will be tracking applications via OnlyDust. Therefore, in order for you to have a chance at being assigned to this issue, please apply directly here, or else your application may not be considered.

wugalde19 commented 3 weeks ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Hi Flex Marketplace team, I’m William from Costa Rica 🇨🇷 and member of the Dojo Coding community. I am interested in contributing to this issue and believe my skills and background make me well-suited for the task. I’ve worked over 7 years as Full Stack engineer in several technologies (including the ones used on this project JS, and Typescript) and I am currently expanding my expertise in Rust, Cairo, and Solidity.

I’ve participated in two past OD Hack events and the StarkHack event organized by ETHGlobal. In the StarkHack, we tried to develop an dApp to interact with NFTs in Starknet.

And that’s why I’m interested on this project, because it relates to what our old team tried back then. Also interested on learning more about your team and contribute

Profiles: https://app.onlydust.com/u/wugalde19

https://github.com/wugalde19

How I plan on tackling this issue

The way I’d approach this is by: First, follow the Readme to set up the project locally. Take a full day to really understand the logic inside of “ERC721_open_edition.cairo” and “ERC721_open_edition_multi_metadata.cairo” files. Ask questions in the Telegram channel (if any). Then, start writing tests following best practices and examples in Cairo book documentation and other projects I have contributed to before. Run all the tests on this project to make sure all test still pass. Open a PR with all the new tests into the “openedition/tests folder”. And finally, after your first review of that PR, take the feedback, iterate over my implementation based on the feedback that you guys provided, and at the end of the cycle deliver good quality tests and get a good coverage % on your project

EmmanuelAR commented 3 weeks ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

Heyyyy @0xandee can i work on this??? I’m Emmanuel Software Dev from Dojo coding and Costa Rica

How I plan on tackling this issue

I will.. 1.⁠ ⁠Review the Contract: Understand the logic and functions the contracts 2.⁠ ⁠Write Tests: •⁠ ⁠Go to openedition/tests and create a test file for the contracts •⁠ ⁠Write test cases that cover all functions, including normal operation, edge cases, and failure scenarios. 3.⁠ ⁠Run Tests: •⁠ ⁠Use the scarb test command to run all the tests. 4.⁠ ⁠Debug: •⁠ ⁠If any tests fail, review and adjust the test cases or contract as needed, then rerun until all tests pass. 5.⁠ ⁠Final Steps: •⁠ ⁠Ensure everything is documented and submit your work.

PoulavBhowmick03 commented 3 weeks ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I'm Poulav Bhowmick, a software engineer at Invisible Studios with a robust background in TypeScript, Rust, Solidity Cairo, fullstack development and blockchain technology. My experience includes building robust applications, optimizing functionalities and blockchain integration. I have actively participated in events and open source contributions, enhancing my capability to tackle real-world tech challenges. My projects can be viewed on my GitHub Profile and OnlyDust Profile. Plus I´m active member of Starknet community🇷.

How I plan on tackling this issue

ETA- 2 days

  1. Setup the Testing Environment:

    • Initialize the contract and set up necessary states (e.g., contract deployment, setting initial values).
    • Ensure the owner and other relevant addresses are correctly set.
  2. Write Test Cases:

    • Test the constructor: Ensure that the initial values, such as current_token_id, current_phase_id, and allowed_flex_drop, are set correctly.
    • Test update_allowed_flex_drop: Ensure that only the owner can update the allowed FlexDrop contracts and that the mapping is correctly updated.
    • Test mint_flex_drop: Ensure that only allowed FlexDrop contracts can mint new tokens, and the correct number of tokens are minted.
    • Test create_new_phase_drop: Ensure the owner can create a new phase drop and that the phase ID is incremented correctly.
    • Test update_phase_drop: Ensure the owner or the contract itself can update a phase drop.
    • Test update_creator_payout: Ensure the owner or the contract itself can update the creator payout address.
    • Test update_payer: Ensure the owner or the contract itself can update the payer's address for gas fees.
    • Test multi_configure: Ensure the configuration options update the contract's state as expected.
    • Test get_mint_state, get_current_token_id, and get_allowed_flex_drops: Ensure these getter functions return the correct values.
  3. Run Tests and Debug:

    • Use scarb test to run the tests.
    • Debug any failing tests and ensure that all test cases pass.

Here is an example test case for testing the constructor and the update_allowed_flex_drop function:

#[cfg(test)]
mod tests {
    use super::*;
    use starknet::testing::{MockedEnvironment, start_testing};

    #[test]
    fn test_constructor() {
        let env = start_testing();
        let creator = env.get_account(0);

        // Set up initial state for the contract
        let name = "TestToken".into();
        let symbol = "TTK".into();
        let base_uri = "https://example.com/".into();
        let allowed_flex_drop = vec![env.get_account(1).address, env.get_account(2).address];

        let contract = ERC721OpenEdition::new(
            creator.address,
            name.clone(),
            symbol.clone(),
            base_uri.clone(),
            allowed_flex_drop.clone(),
        );

        // Check initial values
        assert_eq!(contract.current_token_id(), 1.into());
        assert_eq!(contract.current_phase_id(), 1);
        assert_eq!(contract.ownable.owner(), creator.address);
        assert_eq!(contract.erc721.name(), name);
        assert_eq!(contract.erc721.symbol(), symbol);

        // Check allowed FlexDrop contracts
        assert!(contract.allowed_flex_drop.read(allowed_flex_drop[0]));
        assert!(contract.allowed_flex_drop.read(allowed_flex_drop[1]));
    }

    #[test]
    fn test_update_allowed_flex_drop() {
        let env = start_testing();
        let creator = env.get_account(0);
        let new_flex_drop = vec![env.get_account(3).address, env.get_account(4).address];

        let contract = ERC721OpenEdition::new(
            creator.address,
            "TestToken".into(),
            "TTK".into(),
            "https://example.com/".into(),
            vec![env.get_account(1).address, env.get_account(2).address],
        );

        // Only the owner can update allowed FlexDrop contracts
        contract.update_allowed_flex_drop(new_flex_drop.clone());

        // Check the updated allowed FlexDrop contracts
        assert!(contract.allowed_flex_drop.read(new_flex_drop[0]));
        assert!(contract.allowed_flex_drop.read(new_flex_drop[1]));

        // Old FlexDrop contracts should no longer be allowed
        assert!(!contract.allowed_flex_drop.read(env.get_account(1).address));
        assert!(!contract.allowed_flex_drop.read(env.get_account(2).address));
    }
}

Running Tests

After writing the tests, you can run them using:

scarb test
ScottyDavies commented 3 weeks ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am front end developer with 6 years experience. this will be my first time contributing to the ecosystem and i am ready to work

How I plan on tackling this issue

I would approach this issue with following steps Understanding the Contracts: I would carefully review the ERC721_open_edition.cairo and ERC721_open_edition_multi_metadata.cairo contracts to understand their purpose, functionality, and the various functions and state variables they contain. I would familiarize myself with the ERC721 standard and the specific requirements and behaviors of the "open edition" and "multi-metadata" variations. Identifying Test Cases: Based on the contracts' functionality, I would identify the key test cases that need to be covered. This may include: Successful and failed minting of tokens Correct token balances and ownership after minting Successful and failed transfers of tokens Correct token balances and ownership after transfers Handling of different token URIs and metadata Handling of edge cases, such as invalid inputs or unexpected conditions Writing Test Cases: I would then proceed to write the test cases in the openedition/tests folder using the Scarb testing framework. Each test case would focus on a specific aspect of the contracts' functionality and ensure that they behave as expected. Implementing Test Functions: For each test case, I would implement the necessary test functions. These functions would interact with the ERC721_open_edition.cairo and ERC721_open_edition_multi_metadata.cairo contracts, execute the relevant operations, and verify the expected outcomes. The test functions should cover the following: Setting up the necessary contract state and resources for the test Executing the contract function(s) being tested Asserting the expected results, such as token balances, ownership, token URIs, reverted transactions, or emitted events Running and Debugging Tests: I would use the scarb test command to run all the test cases. If any test cases fail, I would investigate the issue, debug the test functions, and the contract implementation as necessary to ensure all tests pass. Refactoring and Improving Tests: After the initial set of tests are passing, I would review the test cases and identify opportunities for improvement, such as adding more edge cases, improving the test setup and teardown, or making the tests more readable and maintainable. Documenting Test Cases: I would ensure that the test cases are well-documented, providing clear explanations for the purpose of each test and the expected behavior being verified. Collaboration with Backend Developers: Throughout the process, I would collaborate closely with the backend developers responsible for the contract implementation to ensure that the tests accurately reflect the desired behavior of the ERC721_open_edition.cairo and ERC721_open_edition_multi_metadata.cairo contracts. I would provide feedback and insights from the frontend perspective to help the backend team improve the contract design and implementation.

DiegoB1911 commented 3 weeks ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I'm a Full Stack Developer with two years of experience. I'm also a member of Dojo Coding, where I'm learning new things such as Cairo and Web3. This is my first time participating in an OD Hack, and I'm eager to learn and contribute to new projects.

How I plan on tackling this issue

To solve this task I would: 1: Analyze the Contracts 2: Design Test Cases 3: Implement Test Cases 4: Run Tests with Scarb 5: Final Review and Validation

Abeeujah commented 3 weeks ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I'm a Web and Systems engineer, with deep understanding of clean code principles and best practices, this has enabled me build resilient solutions backed by high quality tests and maxxed code coverage using TDD.

How I plan on tackling this issue

jorgezerpa commented 3 weeks ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I'm a 4 years experience full-stack software developer, focused on build web and mobile applications.

I'm starting my web3 journy, here are some related projects I built in Cairo and solidity:

Even if I'm starting on web3, I have already a lot of experience working on web and mobile projects, so everything related with code quality, git flows (PR, good commit messages, etc) and nice remote communication skills... It's a piece of cake for me.

How I plan on tackling this issue

I will follow the guideline provided on the Cairo Book https://book.cairo-lang.org/ch10-00-testing-cairo-programs.html for implement testing.

Taking a deeper look:

For the ERC721_open_edition file:

I'll start testing the basics:

Then I will go with all related to the FlexDrop Contract Management and finally test the ERC721 basics like balanceOf, ownerOf, totalSupply, etc. and all Getter functions.

And then follow a similar approach for the ERC721_open_edition_multi_metadata contract.

I'm ready to start, happy coding :)

onlydustapp[bot] commented 3 weeks ago

The maintainer 0xandee has assigned jorgezerpa to this issue via OnlyDust Platform. Good luck!

kateberryd commented 3 weeks ago

If this issue is still open I would love to pick it up

DIWAKARKASHYAP commented 3 weeks ago

https://diwakar-portfolio.vercel.app/ i want to work on this issue