Skip to content

Commit

Permalink
test + fixes for store_many_headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ametel01 committed Jun 6, 2024
1 parent c6b2841 commit 22ddb44
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 5 additions & 2 deletions starknet/src/L1_headers_store/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub mod L1HeaderStore {
}

fn store_many_state_roots(
ref self: ContractState, start_block: u64, end_block: u64, mut state_roots: Array<u256>
ref self: ContractState, start_block: u64, end_block: u64, state_roots: Array<u256>
) {
self.ownable.assert_only_owner();

Expand All @@ -128,9 +128,12 @@ pub mod L1HeaderStore {
);

let mut start = start_block;
let mut index = 0;

while start <= end_block {
self.store_state_root(start, state_roots.pop_front().unwrap());
self.store_state_root(start, *state_roots.at(index));
start += 1;
index += 1;
};
}

Expand Down
18 changes: 18 additions & 0 deletions starknet/tests/test_l1_header_store.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ fn test_store_state_root() {
assert_eq!(dsp.store.get_state_root(block), state_root);
}

#[test]
fn test_store_many_state_root() {
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;

start_cheat_caller_address(dsp.store.contract_address, OWNER());
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]
fn get_initialized_test() {
assert!(true)
Expand Down

0 comments on commit 22ddb44

Please sign in to comment.