From 37171f347fb24eda79f2aeb1f354948d5b4467f3 Mon Sep 17 00:00:00 2001 From: Egor Dergunov Date: Mon, 10 Jun 2024 22:32:12 +0400 Subject: [PATCH 1/3] add missing tests --- starknet/tests/test_fact_registry.cairo | 39 +++++++++++++++++++++++ starknet/tests/test_l1_header_store.cairo | 14 ++++++++ 2 files changed, 53 insertions(+) diff --git a/starknet/tests/test_fact_registry.cairo b/starknet/tests/test_fact_registry.cairo index e0b81fd..4055bf4 100644 --- a/starknet/tests/test_fact_registry.cairo +++ b/starknet/tests/test_fact_registry.cairo @@ -114,6 +114,20 @@ fn prove_account_test_success_save_all() { assert_eq!(nonce, proof.nonce); } +#[test] +#[should_panic] +fn prove_account_test_fail_state_root_not_found() { + let dsp = setup(); + + let block = proofs::blocks::BLOCK_3(); + + let proof = proofs::account::PROOF_1(); + + dsp + .registry + .prove_account(OptionsSet::All, proof.address, block.number, proof.bytes, proof.data); +} + #[test] fn prove_storage_test_success_with_some_data() { let dsp = setup(); @@ -151,6 +165,31 @@ fn prove_storage_test_success_with_some_data() { ); } +#[test] +#[should_panic] +fn prove_storage_test_fail_state_root_not_found() { + let dsp = setup(); + + let block = proofs::blocks::BLOCK_3(); + + start_cheat_caller_address(dsp.store.contract_address, OWNER()); + dsp.store.store_state_root(block.number, block.state_root); + + let account_proof = proofs::account::PROOF_1(); + + let storage_proof = proofs::storage::PROOF_2(); + + let _ = dsp + .registry + .prove_storage( + block.number, + account_proof.address, + storage_proof.key, + storage_proof.bytes, + storage_proof.data + ); +} + #[test] fn test_get_storage_not_verified() { let dsp = setup(); diff --git a/starknet/tests/test_l1_header_store.cairo b/starknet/tests/test_l1_header_store.cairo index 8a164fd..2f8202b 100644 --- a/starknet/tests/test_l1_header_store.cairo +++ b/starknet/tests/test_l1_header_store.cairo @@ -21,6 +21,20 @@ fn receive_from_l1_success_test() { assert_eq!(dsp.store.get_parent_hash(block.number), parent_hash); } +#[test] +#[should_panic] +fn receive_from_l1_unauthorized_sender() { + let dsp = setup(); + + let block = proofs::blocks::BLOCK_0(); + let parent_hash: u256 = 0xfbacb363819451babc6e7596aa48af6c223e40e8b0ad975e372347df5d60ba0f; + + dsp.store.receive_from_l1(parent_hash, block.number); + + assert_eq!(dsp.store.get_parent_hash(block.number), parent_hash); +} + + #[test] fn test_store_state_root() { let dsp = setup(); From 06dad750fcb82834ed4e19e7893de43be60f5833 Mon Sep 17 00:00:00 2001 From: Egor Dergunov Date: Tue, 11 Jun 2024 13:21:43 +0400 Subject: [PATCH 2/3] add tests for new assertions --- starknet/tests/test_l1_header_store.cairo | 87 ++++++++++++++++++++- starknet/tests/test_l1_messages_proxy.cairo | 25 ++++++ 2 files changed, 109 insertions(+), 3 deletions(-) diff --git a/starknet/tests/test_l1_header_store.cairo b/starknet/tests/test_l1_header_store.cairo index f486131..b507ed5 100644 --- a/starknet/tests/test_l1_header_store.cairo +++ b/starknet/tests/test_l1_header_store.cairo @@ -22,7 +22,7 @@ fn receive_from_l1_success_test() { #[test] #[should_panic] -fn receive_from_l1_unauthorized_sender() { +fn receive_from_l1_fail_unauthorized_sender() { let dsp = setup(); let block = proofs::blocks::BLOCK_0(); @@ -33,9 +33,28 @@ fn receive_from_l1_unauthorized_sender() { assert_eq!(dsp.store.get_parent_hash(block.number), parent_hash); } +#[test] +fn change_l1_messages_origin_success() { + let dsp = setup(); + + let new_origin: starknet::ContractAddress = 'NEW_L1_MESSAGES'.try_into().unwrap(); + start_cheat_caller_address(dsp.store.contract_address, ADMIN()); + dsp.store.change_l1_messages_origin(new_origin); +} + +#[test] +#[should_panic] +fn change_l1_messages_origin_fail_unauthorized_sender() { + let dsp = setup(); + + let new_origin: starknet::ContractAddress = 'NEW_L1_MESSAGES'.try_into().unwrap(); + + dsp.store.change_l1_messages_origin(new_origin); +} + #[test] -fn test_store_state_root() { +fn test_store_state_root_success() { let dsp = setup(); let state_root: u256 = 0x1e7f7; @@ -48,7 +67,33 @@ fn test_store_state_root() { } #[test] -fn test_store_many_state_root() { +#[should_panic] +fn test_store_state_root_fail_call_not_by_owner() { + let dsp = setup(); + + let state_root: u256 = 0x1e7f7; + let block = 19882; + + dsp.store.store_state_root(block, state_root); +} + +#[test] +#[should_panic] +fn test_store_state_root_fail_block_number_is_zero() { + let dsp = setup(); + + let state_root: u256 = 0x1e7f7; + let block = 19882; + + start_cheat_caller_address(dsp.store.contract_address, ADMIN()); + dsp.store.store_state_root(block, state_root); + + start_cheat_caller_address(dsp.store.contract_address, ADMIN()); + dsp.store.store_state_root(block, state_root); +} + +#[test] +fn test_store_many_state_root_success() { let dsp = setup(); let state_roots: Array = array![ @@ -65,3 +110,39 @@ fn test_store_many_state_root() { assert_eq!(dsp.store.get_state_root(10), 0x11e7f7); } +#[test] +#[should_panic] +fn test_store_many_state_root_fail_called_not_by_owner() { + let dsp = setup(); + + let state_roots: Array = array![ + 0x1e7f7, 0x3e497, 0x4e7f7, 0x5e7f7, 0x6e7f7, 0x7e7f7, 0x8e7f7, 0x9e7f7, 0x10e7f7, 0x11e7f7 + ]; + let start_block = 1; + let end_block = 10; + + dsp.store.store_many_state_roots(start_block, end_block, state_roots); + + assert_eq!(dsp.store.get_state_root(1), 0x1e7f7); + assert_eq!(dsp.store.get_state_root(5), 0x6e7f7); + assert_eq!(dsp.store.get_state_root(10), 0x11e7f7); +} + +#[test] +#[should_panic] +fn test_store_many_state_root_fail_invailed_state_root_length() { + let dsp = setup(); + + let state_roots: Array = array![ + 0x1e7f7, 0x3e497, 0x4e7f7, 0x5e7f7, 0x6e7f7, 0x7e7f7, 0x8e7f7, 0x9e7f7, 0x10e7f7, 0x11e7f7 + ]; + let start_block = 1; + let end_block = 9; + + start_cheat_caller_address(dsp.store.contract_address, ADMIN()); + dsp.store.store_many_state_roots(start_block, end_block, state_roots); + + assert_eq!(dsp.store.get_state_root(1), 0x1e7f7); + assert_eq!(dsp.store.get_state_root(5), 0x6e7f7); + assert_eq!(dsp.store.get_state_root(10), 0x11e7f7); +} diff --git a/starknet/tests/test_l1_messages_proxy.cairo b/starknet/tests/test_l1_messages_proxy.cairo index 6aeae67..6d5d41f 100644 --- a/starknet/tests/test_l1_messages_proxy.cairo +++ b/starknet/tests/test_l1_messages_proxy.cairo @@ -49,3 +49,28 @@ fn get_l1_headers_store_address_test() { assert_eq!(dsp.proxy.get_l1_headers_store_address(), dsp.store.contract_address); } + +#[test] +fn change_contract_addresses_success() { + let dsp = setup(); + + let new_l1_headers_store_address: starknet::ContractAddress = 'NEW_L1_HEADER_STORE_ADDRESS' + .try_into() + .unwrap(); + + start_cheat_caller_address(dsp.proxy.contract_address, OWNER()); + dsp.proxy.change_contract_addresses(L1_ORIGIN(), new_l1_headers_store_address); +} + +#[test] +#[should_panic] +fn change_contract_addresses_fail_calle_not_by_owner() { + let dsp = setup(); + + let new_l1_headers_store_address: starknet::ContractAddress = 'NEW_L1_HEADER_STORE_ADDRESS' + .try_into() + .unwrap(); + + dsp.proxy.change_contract_addresses(L1_ORIGIN(), new_l1_headers_store_address); +} + From 9c83c5746e690fa9c6fe5b6f391f5a3389a1b587 Mon Sep 17 00:00:00 2001 From: Egor Dergunov Date: Tue, 11 Jun 2024 19:46:05 +0400 Subject: [PATCH 3/3] add expected fail messages --- starknet/tests/test_fact_registry.cairo | 6 +++--- starknet/tests/test_l1_header_store.cairo | 14 +++++++------- starknet/tests/test_l1_messages_proxy.cairo | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/starknet/tests/test_fact_registry.cairo b/starknet/tests/test_fact_registry.cairo index be239ee..003858c 100644 --- a/starknet/tests/test_fact_registry.cairo +++ b/starknet/tests/test_fact_registry.cairo @@ -115,7 +115,7 @@ fn prove_account_test_success_save_all() { } #[test] -#[should_panic] +#[should_panic(expected: "FactRegistry: block state root not found")] fn prove_account_test_fail_state_root_not_found() { let dsp = setup(); @@ -166,13 +166,13 @@ fn prove_storage_test_success_with_some_data() { } #[test] -#[should_panic] +#[should_panic(expected: "FactRegistry: block state root not found")] fn prove_storage_test_fail_state_root_not_found() { let dsp = setup(); let block = proofs::blocks::BLOCK_3(); - start_cheat_caller_address(dsp.store.contract_address, OWNER()); + start_cheat_caller_address(dsp.store.contract_address, ADMIN()); dsp.store.store_state_root(block.number, block.state_root); let account_proof = proofs::account::PROOF_1(); diff --git a/starknet/tests/test_l1_header_store.cairo b/starknet/tests/test_l1_header_store.cairo index b507ed5..2372cf3 100644 --- a/starknet/tests/test_l1_header_store.cairo +++ b/starknet/tests/test_l1_header_store.cairo @@ -21,7 +21,7 @@ fn receive_from_l1_success_test() { } #[test] -#[should_panic] +#[should_panic(expected: "L1HeaderStore: unauthorized caller")] fn receive_from_l1_fail_unauthorized_sender() { let dsp = setup(); @@ -43,7 +43,7 @@ fn change_l1_messages_origin_success() { } #[test] -#[should_panic] +#[should_panic(expected: 'Caller is not the owner')] fn change_l1_messages_origin_fail_unauthorized_sender() { let dsp = setup(); @@ -67,7 +67,7 @@ fn test_store_state_root_success() { } #[test] -#[should_panic] +#[should_panic(expected: 'Caller is not the owner')] fn test_store_state_root_fail_call_not_by_owner() { let dsp = setup(); @@ -78,8 +78,8 @@ fn test_store_state_root_fail_call_not_by_owner() { } #[test] -#[should_panic] -fn test_store_state_root_fail_block_number_is_zero() { +#[should_panic(expected: "L1HeaderStore: state root already exists")] +fn test_store_state_root_fail_block_number_is_not_zero() { let dsp = setup(); let state_root: u256 = 0x1e7f7; @@ -111,7 +111,7 @@ fn test_store_many_state_root_success() { } #[test] -#[should_panic] +#[should_panic(expected: 'Caller is not the owner')] fn test_store_many_state_root_fail_called_not_by_owner() { let dsp = setup(); @@ -129,7 +129,7 @@ fn test_store_many_state_root_fail_called_not_by_owner() { } #[test] -#[should_panic] +#[should_panic(expected: "L1HeaderStore: invalid state roots length")] fn test_store_many_state_root_fail_invailed_state_root_length() { let dsp = setup(); diff --git a/starknet/tests/test_l1_messages_proxy.cairo b/starknet/tests/test_l1_messages_proxy.cairo index 6d5d41f..1cda7e6 100644 --- a/starknet/tests/test_l1_messages_proxy.cairo +++ b/starknet/tests/test_l1_messages_proxy.cairo @@ -63,7 +63,7 @@ fn change_contract_addresses_success() { } #[test] -#[should_panic] +#[should_panic(expected: 'Caller is not the owner')] fn change_contract_addresses_fail_calle_not_by_owner() { let dsp = setup();