Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: replace blocking_write with write #552

Merged
merged 5 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 29 additions & 32 deletions crates/core/src/test_utils/bin/dump-katana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,40 @@ async fn main() {
})
.await;

tokio::task::spawn_blocking(move || {
// Get a serializable state for the sequencer
let sequencer = test_context.sequencer();
let dump_state = sequencer
.sequencer
.backend
.state
.blocking_write()
.dump_state()
.expect("Failed to call dump_state on Katana state");
// Get a serializable state for the sequencer
let sequencer = test_context.sequencer();
let dump_state = sequencer
.sequencer
Eikix marked this conversation as resolved.
Show resolved Hide resolved
.backend
.state
.write()
.await
.dump_state()
.expect("Failed to call dump_state on Katana state");

let state = serde_json::to_string(&dump_state).expect("Failed to serialize state");
let state = serde_json::to_string(&dump_state).expect("Failed to serialize state");

// Dump the state
std::fs::create_dir_all(".katana/").expect("Failed to create Kakata dump dir");
std::fs::write(".katana/dump.json", state).expect("Failed to write dump to .katana/dump.json");
// Dump the state
std::fs::create_dir_all(".katana/").expect("Failed to create Kakata dump dir");
std::fs::write(".katana/dump.json", state).expect("Failed to write dump to .katana/dump.json");

let deployer_account = DeployerAccount {
address: test_context.client().deployer_account().address(),
private_key: *STARKNET_DEPLOYER_ACCOUNT_PRIVATE_KEY,
};
let deployer_account = DeployerAccount {
Eikix marked this conversation as resolved.
Show resolved Hide resolved
address: test_context.client().deployer_account().address(),
private_key: *STARKNET_DEPLOYER_ACCOUNT_PRIVATE_KEY,
};

// Store contracts information
let mut contracts = HashMap::new();
contracts.insert("Kakarot", serde_json::to_value(test_context.kakarot()).unwrap());
contracts.insert("ERC20", serde_json::to_value(test_context.evm_contract("ERC20")).unwrap());
contracts.insert("Counter", serde_json::to_value(test_context.evm_contract("Counter")).unwrap());
contracts.insert("PlainOpcodes", serde_json::to_value(test_context.evm_contract("PlainOpcodes")).unwrap());
contracts.insert("DeployerAccount", serde_json::to_value(deployer_account).unwrap());
// Store contracts information
let mut contracts = HashMap::new();
contracts.insert("Kakarot", serde_json::to_value(test_context.kakarot()).unwrap());
contracts.insert("ERC20", serde_json::to_value(test_context.evm_contract("ERC20")).unwrap());
contracts.insert("Counter", serde_json::to_value(test_context.evm_contract("Counter")).unwrap());
contracts.insert("PlainOpcodes", serde_json::to_value(test_context.evm_contract("PlainOpcodes")).unwrap());
contracts.insert("DeployerAccount", serde_json::to_value(deployer_account).unwrap());

// Dump the contracts information
let contracts = serde_json::to_string(&contracts).expect("Failed to serialize contract addresses");
std::fs::write(".katana/contracts.json", contracts)
.expect("Failed to write contracts informations to .katana/contracts.json");
})
.await
.expect("Failed to dump state");
// Dump the contracts information
let contracts = serde_json::to_string(&contracts).expect("Failed to serialize contract addresses");
Eikix marked this conversation as resolved.
Show resolved Hide resolved
std::fs::write(".katana/contracts.json", contracts)
.expect("Failed to write contracts informations to .katana/contracts.json");

// Get the sha of the kakarot submodule
let repo = Repository::open(".").unwrap();
Expand Down
7 changes: 5 additions & 2 deletions crates/hive-utils/src/madara/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,12 @@ mod tests {

// Create an atomic reference to the test environment to avoid dropping it
let env = Arc::clone(&test_environment);

// It is not possible to block the async test task, so we need to spawn a blocking task
let handle = tokio::runtime::Handle::current();
tokio::task::spawn_blocking(move || {
Eikix marked this conversation as resolved.
Show resolved Hide resolved
// Get lock on the Starknet sequencer
let mut starknet = env.sequencer().sequencer.backend.state.blocking_write();
let mut starknet = handle.block_on(async { env.sequencer().sequencer.backend.state.write().await });
let mut counter_storage = HashMap::new();

// Set the counter bytecode length into the contract
Expand Down Expand Up @@ -402,9 +404,10 @@ mod tests {
// Create an atomic reference to the test environment to avoid dropping it
let env = Arc::clone(&test_environment);
// It is not possible to block the async test task, so we need to spawn a blocking task
let handle = tokio::runtime::Handle::current();
Eikix marked this conversation as resolved.
Show resolved Hide resolved
tokio::task::spawn_blocking(move || {
// Get lock on the Starknet sequencer
let mut starknet = env.sequencer().sequencer.backend.state.blocking_write();
let mut starknet = handle.block_on(async { env.sequencer().sequencer.backend.state.write().await });
let mut storage = HashMap::new();

// Prepare the record to be inserted into the storage
Expand Down
Loading