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

feat(katana): rollup and dev chain spec #2957

Merged
merged 18 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions bin/katana/src/cli/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
use anyhow::{Context, Result};
use clap::Args;
use inquire::{Confirm, CustomType, Select};
use katana_chain_spec::{SettlementLayer, DEV_UNALLOCATED};
use katana_chain_spec::rollup::FeeContract;
use katana_chain_spec::{rollup, SettlementLayer};
use katana_primitives::chain::ChainId;
use katana_primitives::genesis::allocation::DevAllocationsGenerator;
use katana_primitives::genesis::constant::DEFAULT_PREFUNDED_ACCOUNT_BALANCE;
use katana_primitives::genesis::Genesis;
use katana_primitives::{ContractAddress, Felt};
use katana_primitives::{ContractAddress, Felt, U256};
use lazy_static::lazy_static;
use starknet::accounts::{ExecutionEncoding, SingleOwnerAccount};
use starknet::core::types::{BlockId, BlockTag};
Expand Down Expand Up @@ -40,12 +42,13 @@
core_contract: input.settlement_contract,
};

let mut chain_spec = DEV_UNALLOCATED.clone();
chain_spec.genesis = GENESIS.clone();
chain_spec.id = ChainId::parse(&input.id)?;
chain_spec.settlement = Some(settlement);
let id = ChainId::parse(&input.id)?;
let genesis = GENESIS.clone();
// At the moment, the fee token is limited to a predefined token.
let fee_contract = FeeContract::default();

Check warning on line 48 in bin/katana/src/cli/init/mod.rs

View check run for this annotation

Codecov / codecov/patch

bin/katana/src/cli/init/mod.rs#L45-L48

Added lines #L45 - L48 were not covered by tests

katana_chain_spec::file::write(&chain_spec).context("failed to write chain spec file")?;
let chain_spec = rollup::ChainSpec { id, genesis, settlement, fee_contract };
rollup::file::write(&chain_spec).context("failed to write chain spec file")?;

Check warning on line 51 in bin/katana/src/cli/init/mod.rs

View check run for this annotation

Codecov / codecov/patch

bin/katana/src/cli/init/mod.rs#L50-L51

Added lines #L50 - L51 were not covered by tests

Ok(())
}
Expand Down Expand Up @@ -181,7 +184,7 @@
lazy_static! {
static ref GENESIS: Genesis = {
// master account
let accounts = DevAllocationsGenerator::new(1).generate();
let accounts = DevAllocationsGenerator::new(1).with_balance(U256::from(DEFAULT_PREFUNDED_ACCOUNT_BALANCE)).generate();
let mut genesis = Genesis::default();
genesis.extend_allocations(accounts.into_iter().map(|(k, v)| (k, v.into())));
genesis
Expand Down
9 changes: 5 additions & 4 deletions crates/dojo/test-utils/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
let url =
Url::parse(&format!("http://{}", handle.rpc.addr())).expect("Failed to parse URL");

let account = handle.node.backend.chain_spec.genesis.accounts().next().unwrap();
let account = handle.node.backend.chain_spec.genesis().accounts().next().unwrap();
let account = TestAccount {
private_key: Felt::from_bytes_be(&account.1.private_key().unwrap().to_bytes_be()),
account_address: Felt::from_bytes_be(&account.0.to_bytes_be()),
Expand Down Expand Up @@ -81,7 +81,7 @@
index: usize,
) -> SingleOwnerAccount<JsonRpcClient<HttpTransport>, LocalWallet> {
let accounts: Vec<_> =
self.handle.node.backend.chain_spec.genesis.accounts().collect::<_>();
self.handle.node.backend.chain_spec.genesis().accounts().collect::<_>();

Check warning on line 84 in crates/dojo/test-utils/src/sequencer.rs

View check run for this annotation

Codecov / codecov/patch

crates/dojo/test-utils/src/sequencer.rs#L84

Added line #L84 was not covered by tests

let account = accounts[index];
let private_key = Felt::from_bytes_be(&account.1.private_key().unwrap().to_bytes_be());
Expand Down Expand Up @@ -115,7 +115,8 @@

pub fn get_default_test_config(sequencing: SequencingConfig) -> Config {
let dev = DevConfig { fee: false, account_validation: true, fixed_gas_prices: None };
let mut chain = ChainSpec { id: ChainId::SEPOLIA, ..Default::default() };
let mut chain =
katana_chain_spec::dev::ChainSpec { id: ChainId::SEPOLIA, ..Default::default() };
chain.genesis.sequencer_address = *DEFAULT_SEQUENCER_ADDRESS;

let rpc = RpcConfig {
Expand All @@ -128,5 +129,5 @@
max_proof_keys: Some(100),
};

Config { sequencing, rpc, dev, chain: chain.into(), ..Default::default() }
Config { sequencing, rpc, dev, chain: ChainSpec::Dev(chain).into(), ..Default::default() }
}
8 changes: 6 additions & 2 deletions crates/katana/chain-spec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ katana-primitives.workspace = true

alloy-primitives.workspace = true
anyhow.workspace = true
dirs = "6.0.0"
lazy_static.workspace = true
num-traits.workspace = true
serde.workspace = true
serde_json.workspace = true
starknet.workspace = true
thiserror.workspace = true
url.workspace = true
dirs = "6.0.0"
toml.workspace = true
url.workspace = true

[dev-dependencies]
katana-executor.workspace = true
katana-provider = { workspace = true, features = ["test-utils"] }
rstest.workspace = true
similar-asserts.workspace = true
tempfile.workspace = true

Expand Down
Loading
Loading