kkrt-labs / kakarot-ssj

Kakarot zkEVM - rewrite in the latest version of Cairo
https://www.kakarot.org
MIT License
137 stars 83 forks source link

dev: test `emit_events` #952

Closed enitrat closed 1 month ago

enitrat commented 2 months ago

https://github.com/kkrt-labs/kakarot-ssj/blob/fed455472079dd30db36a9bce56328d05ff8ce9c/crates/evm/src/backend/starknet_backend.cairo#L215-L226

Add unit testing for the emit_events function. One single case with N events is sufficient to test multiple cases; e.g (pseudocode):

    #[test]
    fn test_emit_events() {
        let mut state = Default::default();

        // Prepare a variety of events
        let events = array![
            Event { keys: array![], data: array![] }, // Empty event
            Event { keys: array![1.into()], data: array![2, 3] }, // Single key, multiple data
            Event { keys: array![4.into(), 5.into()], data: array![6] }, // Multiple keys, single data
            Event { keys: array![7.into(), 8.into(), 9.into()], data: array![10, 11, 12, 13] } // Multiple keys and data
        ];

        // Add events to state
        for event in events {
          state.add_event(event);
        }

        let mut spy = spy_events();

        // First, test with some events
        emit_events(ref state).expect('emit events failed');

        assert!(state.events.is_empty());

        // Assert each event was emitted correctly by using `assert_emitted`

    }

Reference of how to use assert_emitted in a local testing context

https://github.com/kkrt-labs/kakarot-ssj/blob/fed455472079dd30db36a9bce56328d05ff8ce9c/crates/contracts/tests/test_ownable.cairo#L125-L146

ShantelPeters commented 1 month ago

Please I will like to work on this issue when the OD hack commences @enitrat

onlydustapp[bot] commented 1 month ago

Hi @ShantelPeters! Maintainers during the ODHack # 8.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.

PabloVillaplana commented 1 month ago

I am applying to this issue via OnlyDust platform.

My background and how it can be leveraged

I am a Full Stack developer with 6 years of experience in the industry, I am super excited to be able to contribute to Web 3 projects, this to continue paving my way as an Open Source Contributor. I am from Dojo Coding Community

How I plan on tackling this issue

I have contributed to the Kakarot RPC in the past but not to SSJ and I would like to make my first contribution to this ODHack issue.

DiegoB1911 commented 1 month 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 an active member of Dojo Coding, where I'm expanding my skills in Cairo and Web3 technologies. I have previously worked on an issue involving the creation of unit tests in cairo, so I am familiar with the snforge_std cheatcodes and other necessary functions for testing. I’m eager to learn, contribute, and be part of this project.

How I plan on tackling this issue

To solve this issue, I would:

  1. Follow your proposal: Based on your pseudocode, I will write a unit test with N events to thoroughly test the code.

  2. Verify test coverage: I will ensure that the test works correctly and covers all functionality.

  3. Document my code: Finally, I will document my code for clarity and future reference.

onlydustapp[bot] commented 1 month ago

The maintainer enitrat has assigned DiegoB1911 to this issue via OnlyDust Platform. Good luck!

DiegoB1911 commented 1 month ago

Thank you for assigning me the issue. I will start working on it.