-
Notifications
You must be signed in to change notification settings - Fork 34
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
chore(blockifier): create unit tests for contract_class_manager #2768
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
9098814
to
b9b2fa2
Compare
003b9ad
to
d6c6713
Compare
0adfb8c
to
e39a328
Compare
e39a328
to
19dab86
Compare
f4dc017
to
d8e38ab
Compare
19dab86
to
87a8788
Compare
aa7f26a
to
5733e03
Compare
87a8788
to
b7e2924
Compare
a34a9e5
to
445cd55
Compare
There was a problem hiding this 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"))]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 3 files at r16, 1 of 4 files at r30, all commit messages.
Reviewable status: all files reviewed, 10 unresolved discussions (waiting on @avi-starkware, @avivg-starkware, and @meship-starkware)
crates/blockifier/src/state/global_cache.rs
line 33 at r3 (raw file):
Previously, avivg-starkware wrote…
Done
Why only for tests?
crates/blockifier/src/state/contract_class_manager_test.rs
line 74 at r30 (raw file):
ContractClassManagerConfig { cairo_native_run_config: native_config, ..Default::default() }; ContractClassManager::start(config) }
Suggestion:
impl ContractClassManager {
fn create_for testing(native_config: CairoNativeRunConfig) -> Self {
let config =
ContractClassManagerConfig { cairo_native_run_config: native_config, ..Default::default() };
ContractClassManager::start(config)
}
}
crates/blockifier/src/state/contract_class_manager_test.rs
line 85 at r30 (raw file):
let manager = create_test_manager(native_config); assert_eq!(manager.cairo_native_run_config, native_config);
Why is it needed?
Code quote:
assert_eq!(manager.cairo_native_run_config, native_config);
crates/blockifier/src/state/contract_class_manager_test.rs
line 115 at r30 (raw file):
#[should_panic(expected = "Compilation request channel is closed.")] fn test_send_compilation_request_channel_disconnected() { let native_config = CairoNativeRunConfig { run_cairo_native: true, ..Default::default() };
I know that it's the default value but it's maybe better to be explicit.
Suggestion:
// We use the channel to send native compilation requests.
let native_config = CairoNativeRunConfig { run_cairo_native: true, wait_on_native_compilation: false, channel_size:1 };
crates/blockifier/src/state/contract_class_manager_test.rs
line 155 at r30 (raw file):
let native_config = CairoNativeRunConfig { run_cairo_native: true, wait_on_native_compilation: true,
No?
Suggestion:
wait_on_native_compilation: false,
crates/blockifier/src/state/contract_class_manager_test.rs
line 162 at r30 (raw file):
let second_request = create_test_request(); // Fill the channel (it can only hold 1 message)
Where can I see it? Where do you set the channel size to 1? Isn't it 0?
Code quote:
// Fill the channel (it can only hold 1 message)
crates/blockifier/src/state/contract_class_manager_test.rs
line 164 at r30 (raw file):
// Fill the channel (it can only hold 1 message) manager.send_compilation_request(request); // Should log an error without panicking
Can we see the error?
Code quote:
// Should log an error without panicking
crates/blockifier/src/state/contract_class_manager_test.rs
line 180 at r30 (raw file):
manager.send_compilation_request(request); }
Consider testing a happy flow of send_compilation_request
with no wait on native and make sure the channel size was increased by 1.
crates/blockifier/src/test_utils/contracts.rs
line 211 at r30 (raw file):
let raw_sierra = self.get_raw_sierra(); serde_json::from_str(&raw_sierra).unwrap() }
Why was it added? Where do you use it?
Code quote:
pub fn get_contract_class(&self) -> CairoLangContractClass {
let raw_sierra = self.get_raw_sierra();
serde_json::from_str(&raw_sierra).unwrap()
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 13 files at r29.
Reviewable status: all files reviewed, 11 unresolved discussions (waiting on @avi-starkware, @avivg-starkware, and @meship-starkware)
crates/blockifier/src/state/contract_class_manager_test.rs
line 197 at r30 (raw file):
let compiler_config = SierraCompilationConfig::default(); let compiler = Arc::new(CommandLineCompiler::new(compiler_config)); process_compilation_request(manager.contract_caches.clone(), compiler.clone(), request.clone());
Suggestion:
let manager = create_test_manager(native_config);
let (request, _native) = request_w_native;
process_compilation_request(manager.contract_caches.clone(), manager.compiler.clone(), request.clone());
crates/blockifier/src/state/contract_class_manager_test.rs
line 207 at r30 (raw file):
#[rstest] fn test_run_compilation_worker() {
What exactly do we test here? How is it different from testingprocess_compilation_request
?
Code quote:
fn test_run_compilation_worker() {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 13 unresolved discussions (waiting on @avi-starkware, @avivg-starkware, and @meship-starkware)
crates/blockifier/src/state/contract_class_manager_test.rs
line 50 at r30 (raw file):
fn create_test_request() -> CompilationRequest { // Question (AvivG): are we interested in testing other contracts?
No
Code quote:
// Question (AvivG): are we interested in testing other contracts?
crates/blockifier/src/state/contract_class_manager_test.rs
line 53 at r30 (raw file):
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Native)); create_test_request_from_contract(test_contract) }
I think that it makes more sense to create the request using the casm.
Then you don't need the get_casm
method.
As for the native:
You don't actually need it. You don't need to check here if the casm is the one that matches the native, you can simply test that you get some native contract.
WDYT?
Code quote:
fn create_test_request() -> CompilationRequest {
// Question (AvivG): are we interested in testing other contracts?
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Native));
create_test_request_from_contract(test_contract)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 14 files at r27, 9 of 13 files at r29, 3 of 4 files at r30.
Reviewable status: all files reviewed, 14 unresolved discussions (waiting on @avi-starkware, @avivg-starkware, and @meship-starkware)
crates/blockifier/src/state/contract_class_manager.rs
line 217 at r30 (raw file):
"Contract class with hash {} is already compiled to native. Skipping compilation.", class_hash );
Consider removing it.
Code quote:
log::debug!(
"Contract class with hash {} is already compiled to native. Skipping compilation.",
class_hash
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#3335 - PR that adds log testing to this PR
Reviewable status: all files reviewed, 14 unresolved discussions (waiting on @avi-starkware, @avivg-starkware, and @noaov1)
crates/blockifier/src/state/contract_class_manager.rs
line 217 at r30 (raw file):
Previously, noaov1 (Noa Oved) wrote…
Consider removing it.
Maybe adding it under the test config is a good indication for one of the logger tests. I can do this on my PR, which tests the logs.
crates/blockifier/src/state/contract_class_manager_test.rs
line 155 at r30 (raw file):
Previously, noaov1 (Noa Oved) wrote…
No?
Also fixed in the next PR, actually aviv you can delete this test as this test only has meaning in the log test PR
crates/blockifier/src/state/contract_class_manager_test.rs
line 162 at r30 (raw file):
Previously, noaov1 (Noa Oved) wrote…
Where can I see it? Where do you set the channel size to 1? Isn't it 0?
It will be fixed in the next PR. My splitting was not perfect
crates/blockifier/src/state/contract_class_manager_test.rs
line 164 at r30 (raw file):
Previously, noaov1 (Noa Oved) wrote…
Can we see the error?
yes next PR
crates/blockifier/src/state/contract_class_manager_test.rs
line 180 at r30 (raw file):
Previously, noaov1 (Noa Oved) wrote…
Consider testing a happy flow of
send_compilation_request
with no wait on native and make sure the channel size was increased by 1.
I added a log, but that might be better
Previously, noaov1 (Noa Oved) wrote…
How can you create a request with the casm and not the sierra? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 14 unresolved discussions (waiting on @avi-starkware, @avivg-starkware, and @meship-starkware)
crates/blockifier/src/state/contract_class_manager_test.rs
line 53 at r30 (raw file):
Previously, avi-starkware (Avi Cohen) wrote…
How can you create a request with the casm and not the sierra?
The request is a request to compile sierra to native
You can get the sierra when using casm as the RunnableCairo1
. I meant use:
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 14 unresolved discussions (waiting on @avi-starkware, @avivg-starkware, and @meship-starkware)
crates/blockifier/src/state/contract_class_manager_test.rs
line 53 at r30 (raw file):
Previously, noaov1 (Noa Oved) wrote…
You can get the sierra when using casm as the
RunnableCairo1
. I meant use:
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm));
I want to avoid using the new method get_casm
.
2d1c8d7
to
c4d606e
Compare
ce8f9a1
to
641f66e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 3 of 16 files reviewed, 12 unresolved discussions (waiting on @avi-starkware, @meship-starkware, and @noaov1)
crates/blockifier/src/state/contract_class_manager.rs
line 217 at r30 (raw file):
Previously, meship-starkware (Meshi Peled) wrote…
Maybe adding it under the test config is a good indication for one of the logger tests. I can do this on my PR, which tests the logs.
Removing- @meship-starkware - make sure to add in the following PR #3335
crates/blockifier/src/state/contract_class_manager_test.rs
line 50 at r30 (raw file):
Previously, noaov1 (Noa Oved) wrote…
No
Done.
crates/blockifier/src/state/contract_class_manager_test.rs
line 53 at r30 (raw file):
Previously, noaov1 (Noa Oved) wrote…
I want to avoid using the new method
get_casm
.
Done, see my change (2 options - above)
crates/blockifier/src/state/contract_class_manager_test.rs
line 85 at r30 (raw file):
Previously, noaov1 (Noa Oved) wrote…
Why is it needed?
A simple check to ensure the configurations saved to the manager were not changed by func 'start'.
crates/blockifier/src/state/contract_class_manager_test.rs
line 115 at r30 (raw file):
Previously, noaov1 (Noa Oved) wrote…
I know that it's the default value but it's maybe better to be explicit.
Done
crates/blockifier/src/state/contract_class_manager_test.rs
line 155 at r30 (raw file):
Previously, meship-starkware (Meshi Peled) wrote…
Also fixed in the next PR, actually aviv you can delete this test as this test only has meaning in the log test PR
Deleted this test- will be in pr #3335
crates/blockifier/src/state/contract_class_manager_test.rs
line 162 at r30 (raw file):
Previously, meship-starkware (Meshi Peled) wrote…
It will be fixed in the next PR. My splitting was not perfect
Deleted this test- will be added in pr #3335
crates/blockifier/src/state/contract_class_manager_test.rs
line 164 at r30 (raw file):
Previously, meship-starkware (Meshi Peled) wrote…
yes next PR
Deleted this test- will be added in pr #3335
crates/blockifier/src/state/contract_class_manager_test.rs
line 180 at r30 (raw file):
Previously, meship-starkware (Meshi Peled) wrote…
I added a log, but that might be better
Deleted this test- will be in pr #3335
@meship-starkware, are you addressing Noa's request in the following PR, or should I?
crates/blockifier/src/state/contract_class_manager_test.rs
line 207 at r30 (raw file):
Previously, noaov1 (Noa Oved) wrote…
What exactly do we test here? How is it different from testing
process_compilation_request
?
test_run_compilation_worker()
ensures that the loop in run_compilation_worker()
stops after the channel is closed and there are no more pending requests. do you think it's unnecessary?
crates/blockifier/src/state/global_cache.rs
line 33 at r3 (raw file):
Previously, noaov1 (Noa Oved) wrote…
Why only for tests?
I assumed @meship-starkware 's intention was not to add unnecessary attributes if there's no use for them - and as I only use it for tests - enough for me. This was my motivation for following the request. @meship-starkware @noaov1 WDYT?
crates/blockifier/src/test_utils/contracts.rs
line 211 at r30 (raw file):
Previously, noaov1 (Noa Oved) wrote…
Why was it added? Where do you use it?
Reverting.
crates/blockifier/src/state/contract_class_manager_test.rs
line 74 at r30 (raw file):
ContractClassManagerConfig { cairo_native_run_config: native_config, ..Default::default() }; ContractClassManager::start(config) }
Done
crates/blockifier/src/state/contract_class_manager_test.rs
line 197 at r30 (raw file):
let compiler_config = SierraCompilationConfig::default(); let compiler = Arc::new(CommandLineCompiler::new(compiler_config)); process_compilation_request(manager.contract_caches.clone(), compiler.clone(), request.clone());
Deleted this test- will be added in pr #3335 + copied this comment appropriately
crates/blockifier/src/state/contract_class_manager_test.rs
line 51 at r31 (raw file):
// Generate Casm, no need to match the native. let contract_class: ContractClass =
2 suggestions for avoiding the use of fn get_casm - preference? @noaov1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 12 of 13 files at r31, all commit messages.
Reviewable status: 15 of 16 files reviewed, 12 unresolved discussions (waiting on @avi-starkware, @avivg-starkware, and @noaov1)
crates/blockifier/src/state/contract_class_manager_test.rs
line 51 at r31 (raw file):
Previously, avivg-starkware wrote…
2 suggestions for avoiding the use of fn get_casm - preference? @noaov1
I would prefer that the test contract would be casm and that the function that would return the runnable class will create a new native contract class
crates/blockifier/src/state/contract_class_manager_test.rs
line 37 at r31 (raw file):
ContractClassManager::start(config) } }
Move this to the contract class manager file see
pub fn create_for_testing(run_cairo_native: bool, wait_on_native_compilation: bool) -> Self { |
Code quote:
impl ContractClassManager {
fn create_for_testing(native_config: CairoNativeRunConfig) -> Self {
let config = ContractClassManagerConfig {
cairo_native_run_config: native_config,
..Default::default()
};
ContractClassManager::start(config)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 13 files at r31.
Reviewable status: all files reviewed, 12 unresolved discussions (waiting on @avivg-starkware and @noaov1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 12 unresolved discussions (waiting on @avivg-starkware and @noaov1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 13 files at r31, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @avivg-starkware)
crates/blockifier/src/state/contract_class_manager_test.rs
line 114 at r3 (raw file):
Previously, avivg-starkware wrote…
@meship-starkware I see that in the following PR #3335 you rewrote the deleted func: test_send_compilation_request_channel_full()
for clarity, I'm returning the func here, could you delete it in the PR #3335 where it's rewritten ?
Summerizing the above:
process_compilation_request
- tested in Meshi's PR (no need to distinguish between the different values of wait_on_native
.
send_compilation_request
-tested in Meshi's PR (need to distinguish between the different values of wait_on_native
.
Please correct me if I'm wrong.
crates/blockifier/src/state/contract_class_manager_test.rs
line 207 at r30 (raw file):
Previously, avivg-starkware wrote…
test_run_compilation_worker()
ensures that the loop inrun_compilation_worker()
stops after the channel is closed and there are no more pending requests. do you think it's unnecessary?
How exactly do you test it? Simply by checking that the test was finished?
crates/blockifier/src/state/global_cache.rs
line 33 at r3 (raw file):
Previously, avivg-starkware wrote…
I assumed @meship-starkware 's intention was not to add unnecessary attributes if there's no use for them - and as I only use it for tests - enough for me. This was my motivation for following the request. @meship-starkware @noaov1 WDYT?
I see. As this is not a heavy trai, it can be derived either way. But I'm fine with this as well :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @avivg-starkware)
crates/blockifier/src/state/contract_class_manager_test.rs
line 114 at r3 (raw file):
Previously, noaov1 (Noa Oved) wrote…
Summerizing the above:
process_compilation_request
- tested in Meshi's PR (no need to distinguish between the different values ofwait_on_native
.
send_compilation_request
-tested in Meshi's PR (need to distinguish between the different values ofwait_on_native
.
Please correct me if I'm wrong.
.
11e9113
to
2c5dfd0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 2 of 17 files reviewed, 4 unresolved discussions (waiting on @avi-starkware, @meship-starkware, and @noaov1)
crates/blockifier/src/state/contract_class_manager_test.rs
line 114 at r3 (raw file):
Previously, noaov1 (Noa Oved) wrote…
.
👍
crates/blockifier/src/state/contract_class_manager_test.rs
line 207 at r30 (raw file):
Previously, noaov1 (Noa Oved) wrote…
How exactly do you test it? Simply by checking that the test was finished?
test removed
crates/blockifier/src/state/contract_class_manager_test.rs
line 37 at r31 (raw file):
Previously, meship-starkware (Meshi Peled) wrote…
Move this to the contract class manager file see
pub fn create_for_testing(run_cairo_native: bool, wait_on_native_compilation: bool) -> Self {
moved to "struct_impls.rs"
crates/blockifier/src/state/contract_class_manager_test.rs
line 51 at r31 (raw file):
Previously, meship-starkware (Meshi Peled) wrote…
I would prefer that the test contract would be casm and that the function that would return the runnable class will create a new native contract class
Done
2c5dfd0
to
3ca8ea2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 7 files at r32, 12 of 12 files at r33, all commit messages.
Reviewable status: 13 of 17 files reviewed, 1 unresolved discussion (waiting on @meship-starkware)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 7 files at r32, 12 of 12 files at r33, all commit messages.
Reviewable status: 13 of 17 files reviewed, all discussions resolved (waiting on @noaov1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 4 of 7 files at r32.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @avivg-starkware)
No description provided.