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

chore(blockifier): create unit tests for contract_class_manager #2768

Open
wants to merge 1 commit into
base: avivg/blockifier/add_casm_func_in_test_utils
Choose a base branch
from

Conversation

avivg-starkware
Copy link
Contributor

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor Author

avivg-starkware commented Dec 18, 2024

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@avivg-starkware avivg-starkware marked this pull request as ready for review December 18, 2024 15:26
@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/test_contract_class_manager branch from 9098814 to b9b2fa2 Compare December 18, 2024 15:30
@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/test_contract_class_manager branch 9 times, most recently from 003b9ad to d6c6713 Compare December 24, 2024 15:12
@avivg-starkware avivg-starkware changed the base branch from main to avivg/blockifier/add_channel_size_to_contact_manager_config December 24, 2024 15:12
@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/add_channel_size_to_contact_manager_config branch from 0adfb8c to e39a328 Compare December 25, 2024 13:02
@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/add_channel_size_to_contact_manager_config branch from e39a328 to 19dab86 Compare December 26, 2024 10:10
@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/test_contract_class_manager branch 2 times, most recently from f4dc017 to d8e38ab Compare December 26, 2024 10:17
@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/add_channel_size_to_contact_manager_config branch from 19dab86 to 87a8788 Compare December 26, 2024 10:18
@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/test_contract_class_manager branch 2 times, most recently from aa7f26a to 5733e03 Compare December 26, 2024 10:27
@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/add_channel_size_to_contact_manager_config branch from 87a8788 to b7e2924 Compare December 26, 2024 15:44
@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/test_contract_class_manager branch 2 times, most recently from a34a9e5 to 445cd55 Compare December 29, 2024 12:35
@avivg-starkware avivg-starkware changed the base branch from avivg/blockifier/add_channel_size_to_contact_manager_config to main-v0.13.4 December 29, 2024 12:35
Copy link
Collaborator

@noaov1 noaov1 left a comment

Choose a reason for hiding this comment

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

Reviewed 7 of 7 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @avi-starkware and @avivg-starkware)


crates/blockifier/src/test_utils/contracts.rs line 183 at r3 (raw file):

    }

    pub fn get_casm(&self) -> CompiledClassV1 {

Consider sharing code withget_class.

Code quote:

pub fn get_casm(&self) -> CompiledClassV1 {

crates/blockifier/src/state/contract_class_manager_test.rs line 19 at r3 (raw file):

    let mut contract_class = test_contract.get_contract_class();
    // Truncate the sierra program to trigger an error.
    contract_class.sierra_program = contract_class.sierra_program[..100].to_vec();

Nice :)
Is there a way to cause a compilation error by "damaging" the SierraContractClass object?

Code quote:

    // Truncate the sierra program to trigger an error.
    contract_class.sierra_program = contract_class.sierra_program[..100].to_vec();

crates/blockifier/src/state/contract_class_manager_test.rs line 77 at r3 (raw file):

        "Sender should be able to send a request successfully"
    );
}

Consider unifying these tests with test_cases.
You can also check: no compiler when cairo-native is off.

Code quote:

#[test]
fn test_sender_with_native_compilation_disabled() {
    let config = ContractClassManagerConfig { run_cairo_native: false, ..Default::default() };
    let manager = ContractClassManager::start(config);
    assert!(manager.sender.is_none(), "Sender should be None when native compilation is disabled");
}

#[test]
fn test_sender_with_native_compilation_enabled() {
    let config = ContractClassManagerConfig { run_cairo_native: true, ..Default::default() };
    let manager = ContractClassManager::start(config);
    assert!(manager.sender.is_some());

    assert!(
        manager.sender.as_ref().unwrap().try_send(create_test_request()).is_ok(),
        "Sender should be able to send a request successfully"
    );
}

crates/blockifier/src/state/contract_class_manager_test.rs line 80 at r3 (raw file):

#[test]
fn test_send_request_channel_disconnected() {

Can you please explain this test?

Code quote:

fn test_send_request_channel_disconnected() 

crates/blockifier/src/state/contract_class_manager_test.rs line 108 at r3 (raw file):

    let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
        manager.send_compilation_request(second_request);
    }));

Why is the catch_unwind needed?

Code quote:

    let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
        manager.send_compilation_request(second_request);
    }));

crates/blockifier/src/state/contract_class_manager_test.rs line 114 at r3 (raw file):

#[test]
fn test_run_compilation_worker_success() {

?

Suggestion:

fn test_process_compilation_request_success() {

crates/blockifier/src/state/contract_class_manager.rs line 33 at r3 (raw file):

pub const DEFAULT_COMPILATION_REQUEST_CHANNEL_SIZE: usize = 1000;

#[cfg(all(test, feature = "cairo_native"))]

We will want to test it even when the cairo-native flag is off.

Code quote:

#[cfg(all(test, feature = "cairo_native"))]

@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/test_contract_class_manager branch from 445cd55 to 9547c32 Compare January 1, 2025 08:35
@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/test_contract_class_manager branch 3 times, most recently from cb70f0d to 0935c4f Compare January 2, 2025 10:21
@avivg-starkware
Copy link
Contributor Author

crates/blockifier/src/state/contract_class_manager_test.rs line 19 at r3 (raw file):

Previously, noaov1 (Noa Oved) wrote…

Nice :)
Is there a way to cause a compilation error by "damaging" the SierraContractClass object?

Done

@avivg-starkware
Copy link
Contributor Author

crates/blockifier/src/state/contract_class_manager_test.rs line 77 at r3 (raw file):

Previously, noaov1 (Noa Oved) wrote…

Consider unifying these tests with test_cases.
You can also check: no compiler when cairo-native is off.

Done.

@avivg-starkware
Copy link
Contributor Author

crates/blockifier/src/state/contract_class_manager_test.rs line 80 at r3 (raw file):

Previously, noaov1 (Noa Oved) wrote…

Can you please explain this test?

my intention was to check that panic occurs when trying to send massage with disconnected channel, how does it look now?

@avivg-starkware
Copy link
Contributor Author

crates/blockifier/src/state/contract_class_manager_test.rs line 108 at r3 (raw file):

Previously, noaov1 (Noa Oved) wrote…

Why is the catch_unwind needed?

WDYT? not sure if this test is needed and if so, what best way to handle a check that panic doesn't occur

@avivg-starkware
Copy link
Contributor Author

crates/blockifier/src/state/contract_class_manager_test.rs line 114 at r3 (raw file):

Previously, noaov1 (Noa Oved) wrote…

?

I've changed it to test send_compilation_request and added a separate test for process_compilation_request.
Do you think we need a test for the case wait_on_native = false? using time funcs to ensure enough time elapses for the other thread to finish compiling

@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/test_contract_class_manager branch 2 times, most recently from 03f2692 to ea8f100 Compare January 2, 2025 15:53
Copy link
Contributor

@meship-starkware meship-starkware left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 7 files at r2, 1 of 1 files at r3, 1 of 2 files at r5, all commit messages.
Reviewable status: 6 of 7 files reviewed, 8 unresolved discussions (waiting on @avi-starkware, @avivg-starkware, and @noaov1)


crates/blockifier/src/state/global_cache.rs line 33 at r3 (raw file):

#[cfg(feature = "cairo_native")]
#[derive(Debug, Clone, PartialEq)]

Can you derive the PartialEq only for the test config?

Code quote:

#[derive(Debug, Clone, PartialEq)]

@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/test_contract_class_manager branch 4 times, most recently from 93d79f0 to f0143b5 Compare January 5, 2025 16:50
Copy link
Contributor Author

@avivg-starkware avivg-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 5 of 7 files reviewed, 7 unresolved discussions (waiting on @avi-starkware, @meship-starkware, and @noaov1)


crates/blockifier/src/state/global_cache.rs line 33 at r3 (raw file):

Previously, meship-starkware (Meshi Peled) wrote…

Can you derive the PartialEq only for the test config?

Done

@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/test_contract_class_manager branch 2 times, most recently from 83d1a76 to f2f15ab Compare January 6, 2025 14:53
@avivg-starkware avivg-starkware force-pushed the avivg/blockifier/test_contract_class_manager branch from f2f15ab to 56c5ea5 Compare January 6, 2025 14:59
@avivg-starkware avivg-starkware changed the base branch from main-v0.13.4 to avivg/blockifier/add_casm_func_in_test_utils January 6, 2025 14:59
@avivg-starkware
Copy link
Contributor Author

crates/blockifier/src/test_utils/contracts.rs line 183 at r3 (raw file):

Previously, noaov1 (Noa Oved) wrote…

Consider sharing code withget_class.

handled code sharing in #3138

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.

4 participants