Skip to content

Commit 743b2ba

Browse files
starknet_os_flow_tests: commit state diff
1 parent 2762524 commit 743b2ba

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/starknet_os_flow_tests/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ license-file.workspace = true
1010
blockifier.workspace = true
1111
blockifier_test_utils.workspace = true
1212
starknet_committer.workspace = true
13+
starknet_patricia.workspace = true
14+
starknet_patricia_storage = { workspace = true, features = ["testing"] }
1315
[lints]
1416
workspace = true

crates/starknet_os_flow_tests/src/utils.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ use blockifier::context::BlockContext;
1010
use blockifier::state::cached_state::{CachedState, CommitmentStateDiff};
1111
use blockifier::test_utils::maybe_dummy_block_hash_and_number;
1212
use blockifier::transaction::transaction_execution::Transaction;
13+
use starknet_committer::block_committer::commit::commit_block;
1314
use starknet_committer::block_committer::input::{
15+
ConfigImpl,
16+
Input,
1417
StarknetStorageKey,
1518
StarknetStorageValue,
1619
StateDiff,
1720
};
1821
use starknet_committer::patricia_merkle_tree::types::CompiledClassHash;
22+
use starknet_patricia::hash::hash_trait::HashOutput;
23+
use starknet_patricia_storage::map_storage::MapStorage;
1924

2025
use crate::state_trait::FlowTestState;
2126

@@ -79,3 +84,24 @@ pub(crate) fn create_committer_state_diff(state_diff: CommitmentStateDiff) -> St
7984
.collect(),
8085
}
8186
}
87+
88+
/// Commits the state diff, saves the new facts and returns the computed roots.
89+
async fn commit_state_diff(
90+
facts: &mut MapStorage,
91+
contracts_trie_root_hash: HashOutput,
92+
classes_trie_root_hash: HashOutput,
93+
state_diff: StateDiff,
94+
) -> (HashOutput, HashOutput) {
95+
let config = ConfigImpl::default();
96+
// TODO(Nimrod): Remove the clone once commit takes reference to the storage.
97+
let input = Input {
98+
storage: facts.storage.clone(),
99+
state_diff,
100+
contracts_trie_root_hash,
101+
classes_trie_root_hash,
102+
config,
103+
};
104+
let filled_forest = commit_block(input).await.expect("Failed to commit the given block.");
105+
filled_forest.write_to_storage(facts);
106+
(filled_forest.get_contract_root_hash(), filled_forest.get_compiled_class_root_hash())
107+
}

0 commit comments

Comments
 (0)