Skip to content

Commit

Permalink
add tests for new assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
sqrlfirst committed Jun 11, 2024
1 parent 55eb08f commit 06dad75
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 3 deletions.
87 changes: 84 additions & 3 deletions starknet/tests/test_l1_header_store.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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<u256> = array![
Expand All @@ -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<u256> = 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<u256> = 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);
}
25 changes: 25 additions & 0 deletions starknet/tests/test_l1_messages_proxy.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 06dad75

Please sign in to comment.