Skip to content

Commit 669c159

Browse files
starknet_os_flow_tests: create state diff for the committer (#8343)
1 parent 50380c8 commit 669c159

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
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_committer/src/block_committer/input.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ impl ConfigImpl {
9191
}
9292
}
9393

94+
impl Default for ConfigImpl {
95+
fn default() -> Self {
96+
Self { warn_on_trivial_modifications: false, log_level: LevelFilter::INFO }
97+
}
98+
}
99+
94100
#[derive(Debug, Eq, PartialEq)]
95101
pub struct Input<C: Config> {
96102
/// All relevant information for the state diff commitment.

crates/starknet_os_flow_tests/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ license-file.workspace = true
88

99
[dev-dependencies]
1010
blockifier.workspace = true
11+
blockifier_test_utils.workspace = true
12+
starknet_committer.workspace = true
1113

1214
[lints]
1315
workspace = true

crates/starknet_os_flow_tests/src/utils.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ use blockifier::blockifier::transaction_executor::{
77
TransactionExecutorError,
88
};
99
use blockifier::context::BlockContext;
10-
use blockifier::state::cached_state::CachedState;
10+
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::input::{
14+
StarknetStorageKey,
15+
StarknetStorageValue,
16+
StateDiff,
17+
};
18+
use starknet_committer::patricia_merkle_tree::types::CompiledClassHash;
1319

1420
use crate::state_trait::FlowTestState;
1521

@@ -50,3 +56,29 @@ pub(crate) fn execute_transactions<S: FlowTestState>(
5056
let final_state = executor.block_state.unwrap();
5157
ExecutionOutput { execution_outputs, block_summary, final_state }
5258
}
59+
60+
/// Creates a state diff input for the committer based on the execution state diff.
61+
pub(crate) fn create_committer_state_diff(state_diff: CommitmentStateDiff) -> StateDiff {
62+
StateDiff {
63+
address_to_class_hash: state_diff.address_to_class_hash.into_iter().collect(),
64+
address_to_nonce: state_diff.address_to_nonce.into_iter().collect(),
65+
class_hash_to_compiled_class_hash: state_diff
66+
.class_hash_to_compiled_class_hash
67+
.into_iter()
68+
.map(|(k, v)| (k, CompiledClassHash(v.0)))
69+
.collect(),
70+
storage_updates: state_diff
71+
.storage_updates
72+
.into_iter()
73+
.map(|(address, updates)| {
74+
(
75+
address,
76+
updates
77+
.into_iter()
78+
.map(|(k, v)| (StarknetStorageKey(k), StarknetStorageValue(v)))
79+
.collect(),
80+
)
81+
})
82+
.collect(),
83+
}
84+
}

0 commit comments

Comments
 (0)