Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into katana/Messaging-Intr…
Browse files Browse the repository at this point in the history
…egation-Testing
  • Loading branch information
fabrobles92 committed May 29, 2024
2 parents d51cb51 + 328004d commit e1766f9
Show file tree
Hide file tree
Showing 100 changed files with 4,837 additions and 1,096 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ env:

jobs:
test:
runs-on: ubuntu-latest-16-cores
runs-on: ubuntu-latest-32-cores
container:
image: ghcr.io/dojoengine/dojo-dev:v0.7.0-alpha.4
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- run: |
cargo build -r --bin katana
KATANA_RUNNER_BIN=$(pwd)/target/release/katana cargo llvm-cov nextest --no-report --all-features --workspace --exclude katana --build-jobs 10
KATANA_RUNNER_BIN=$(pwd)/target/release/katana cargo llvm-cov nextest --no-report --all-features --workspace --exclude katana --build-jobs 20
cargo llvm-cov nextest --no-report -p katana
# TODO(kariy): uncomment this line when `sir` feature support Cairo 2.6.3
# cargo llvm-cov nextest --no-report -p katana --no-default-features --features sir
Expand Down
81 changes: 28 additions & 53 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ edition = "2021"
license = "Apache-2.0"
license-file = "LICENSE"
repository = "https://github.com/dojoengine/dojo/"
version = "0.7.0-alpha.4"
version = "0.7.0-alpha.5"

[profile.performance]
codegen-units = 1
Expand All @@ -68,6 +68,9 @@ dojo-test-utils = { path = "crates/dojo-test-utils" }
dojo-types = { path = "crates/dojo-types" }
dojo-world = { path = "crates/dojo-world" }

# dojo-world
topological-sort = "0.2"

# katana
katana-cairo = { path = "crates/katana/cairo" }
katana-codecs = { path = "crates/katana/storage/codecs" }
Expand Down Expand Up @@ -107,28 +110,28 @@ async-trait = "0.1.77"
auto_impl = "1.2.0"
base64 = "0.21.2"
bytes = "1.6"
cairo-lang-compiler = "=2.6.3"
cairo-lang-debug = "=2.6.3"
cairo-lang-defs = "=2.6.3"
cairo-lang-diagnostics = "=2.6.3"
cairo-lang-filesystem = "=2.6.3"
cairo-lang-formatter = "=2.6.3"
cairo-lang-language-server = "=2.6.3"
cairo-lang-lowering = "=2.6.3"
cairo-lang-parser = "=2.6.3"
cairo-lang-plugins = { version = "=2.6.3", features = [ "testing" ] }
cairo-lang-project = "=2.6.3"
cairo-lang-semantic = { version = "=2.6.3", features = [ "testing" ] }
cairo-lang-sierra = "=2.6.3"
cairo-lang-sierra-generator = "=2.6.3"
cairo-lang-sierra-to-casm = "=2.6.3"
cairo-lang-starknet = "=2.6.3"
cairo-lang-starknet-classes = "=2.6.3"
cairo-lang-syntax = "=2.6.3"
cairo-lang-test-plugin = "=2.6.3"
cairo-lang-test-runner = "=2.6.3"
cairo-lang-test-utils = "=2.6.3"
cairo-lang-utils = "=2.6.3"
cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-debug = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-diagnostics = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-lowering = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-parser = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-plugins = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632", features = [ "testing" ] }
cairo-lang-project = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632", features = [ "testing" ] }
cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-sierra-generator = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-starknet-classes = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-syntax = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-test-utils = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", rev = "d9984ef58e2f704909e271f2f01327f520ded632" }
cairo-proof-parser = { git = "https://github.com/cartridge-gg/cairo-proof-parser", tag = "v0.3.0" }
cairo-vm = "0.9.2"
camino = { version = "1.1.2", features = [ "serde1" ] }
Expand Down Expand Up @@ -162,8 +165,8 @@ regex = "1.10.3"
reqwest = { version = "0.12", features = [ "blocking", "rustls-tls" ], default-features = false }
rpassword = "7.2.0"
salsa = "0.16.1"
scarb = { git = "https://github.com/software-mansion/scarb", rev = "e813dbab8f0ec606b5846827ad65951ef8bd6b92" }
scarb-ui = { git = "https://github.com/software-mansion/scarb", rev = "e813dbab8f0ec606b5846827ad65951ef8bd6b92" }
scarb = { git = "https://github.com/software-mansion/scarb", rev = "f1aa7b09507a84d209d83b2fa80472c82605cc43" }
scarb-ui = { git = "https://github.com/software-mansion/scarb", rev = "f1aa7b09507a84d209d83b2fa80472c82605cc43" }
semver = "1.0.5"
serde = { version = "1.0", features = [ "derive" ] }
serde_json = { version = "1.0", features = [ "arbitrary_precision" ] }
Expand Down Expand Up @@ -224,31 +227,3 @@ alloy-rpc-types = { git = "https://github.com/alloy-rs/alloy", rev = "4655f8e437
alloy-signer = { git = "https://github.com/alloy-rs/alloy", rev = "4655f8e4372ecc0b056e83abbc60c3912902ee64" }
alloy-signer-wallet = { git = "https://github.com/alloy-rs/alloy", rev = "4655f8e4372ecc0b056e83abbc60c3912902ee64" }
alloy-transport = { git = "https://github.com/alloy-rs/alloy", rev = "4655f8e4372ecc0b056e83abbc60c3912902ee64" }

cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-debug = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-diagnostics = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-lowering = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-parser = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-plugins = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-project = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-sierra-generator = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-starknet-classes = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-syntax = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-test-utils = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }

# Runner
cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }
cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo", rev = "290f51f554c978180ca9d91177423305959cbed5" }

13 changes: 0 additions & 13 deletions bin/dojo-language-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@ version.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow.workspace = true
cairo-lang-compiler.workspace = true
cairo-lang-filesystem.workspace = true
cairo-lang-language-server.workspace = true
cairo-lang-plugins.workspace = true
cairo-lang-semantic.workspace = true
cairo-lang-starknet.workspace = true
cairo-lang-test-plugin.workspace = true
cairo-lang-utils.workspace = true
clap.workspace = true
dojo-lang.workspace = true
log.workspace = true
salsa.workspace = true
smol_str.workspace = true
tokio = { version = "1.18.2", features = [ "full", "sync" ] }
tower-lsp = "0.20.0"
8 changes: 8 additions & 0 deletions bin/dojo-language-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
use cairo_lang_language_server::Tricks;
use clap::Parser;
use dojo_lang::plugin::dojo_plugin_suite;

/// Dojo Language Server
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {}

fn main() {
let _args = Args::parse();

let mut tricks = Tricks::default();
tricks.extra_plugin_suites = Some(&|| vec![dojo_plugin_suite()]);
cairo_lang_language_server::start_with_tricks(tricks);
Expand Down
113 changes: 79 additions & 34 deletions bin/sozo/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ use scarb::ops::{CompileOpts, FeaturesOpts, FeaturesSelector};
use sozo_ops::statistics::{get_contract_statistics_for_dir, ContractStatistics};
use tracing::trace;

const BYTECODE_SIZE_LABEL: &str = "Bytecode size [in felts]\n(Sierra, Casm)";
const CONTRACT_CLASS_SIZE_LABEL: &str = "Contract Class size [in bytes]\n(Sierra, Casm)";

const CONTRACT_NAME_LABEL: &str = "Contract";

#[derive(Debug, Args)]
pub struct BuildArgs {
#[arg(long)]
#[arg(help = "Generate Typescript bindings.")]
pub typescript: bool,

// Should we deprecate typescript bindings codegen?
// Disabled due to lack of support in dojo.js
// #[arg(long)]
// #[arg(help = "Generate Typescript bindings.")]
// pub typescript: bool,
#[arg(long)]
#[arg(help = "Generate Typescript bindings.")]
pub typescript_v2: bool,
Expand Down Expand Up @@ -47,9 +53,11 @@ impl BuildArgs {
trace!(?compile_info, "Compiled workspace.");

let mut builtin_plugins = vec![];
if self.typescript {
builtin_plugins.push(BuiltinPlugins::Typescript);
}

// Disable typescript for now. Due to lack of support and maintenance in dojo.js
// if self.typescript {
// builtin_plugins.push(BuiltinPlugins::Typescript);
// }

if self.typescript_v2 {
builtin_plugins.push(BuiltinPlugins::TypeScriptV2);
Expand All @@ -61,14 +69,30 @@ impl BuildArgs {

if self.stats {
let target_dir = &compile_info.target_dir;
let contracts_statistics = get_contract_statistics_for_dir(target_dir)
let contracts_statistics = get_contract_statistics_for_dir(config.ui(), target_dir)
.context("Error getting contracts stats")?;
trace!(
?contracts_statistics,
?target_dir,
"Read contract statistics for target directory."
);

let ui = config.ui();

ui.print(
"Bytecode: It is low-level code that constitutes smart contracts and is \
represented by an array of felts.",
);
ui.print("Bytecode size: It is number of felts in Bytecode.");
ui.print(
"Contract Class: It serve as the fundamental building blocks of smart contracts.",
);
ui.print(
"Contract Class size: It denotes the file size of the minified JSON \
representation of the contract class.",
);
ui.print(" ");

let table = create_stats_table(contracts_statistics);
table.printstd()
}
Expand All @@ -95,26 +119,40 @@ impl BuildArgs {
}
}

fn create_stats_table(contracts_statistics: Vec<ContractStatistics>) -> Table {
fn create_stats_table(mut contracts_statistics: Vec<ContractStatistics>) -> Table {
let mut table = Table::new();
table.set_format(*FORMAT_NO_LINESEP_WITH_TITLE);

// Add table headers
table.set_titles(Row::new(vec![
Cell::new_align("Contract", format::Alignment::CENTER),
Cell::new_align("Bytecode size (felts)", format::Alignment::CENTER),
Cell::new_align("Class size (bytes)", format::Alignment::CENTER),
Cell::new_align(CONTRACT_NAME_LABEL, format::Alignment::CENTER),
Cell::new_align(BYTECODE_SIZE_LABEL, format::Alignment::CENTER),
Cell::new_align(CONTRACT_CLASS_SIZE_LABEL, format::Alignment::CENTER),
]));

// sort contracts in alphabetical order
contracts_statistics.sort_by(|a, b| a.contract_name.cmp(&b.contract_name));

for contract_stats in contracts_statistics {
// Add table rows
let contract_name = contract_stats.contract_name;
let number_felts = contract_stats.number_felts;
let file_size = contract_stats.file_size;

let sierra_bytecode_size = contract_stats.sierra_bytecode_size;
let sierra_contract_class_size = contract_stats.sierra_contract_class_size;

let casm_bytecode_size = contract_stats.casm_bytecode_size;
let casm_contract_class_size = contract_stats.casm_contract_class_size;

table.add_row(Row::new(vec![
Cell::new_align(&contract_name, format::Alignment::LEFT),
Cell::new_align(format!("{}", number_felts).as_str(), format::Alignment::RIGHT),
Cell::new_align(format!("{}", file_size).as_str(), format::Alignment::RIGHT),
Cell::new_align(
format!("{}, {}", sierra_bytecode_size, casm_bytecode_size).as_str(),
format::Alignment::CENTER,
),
Cell::new_align(
format!("{}, {}", sierra_contract_class_size, casm_contract_class_size).as_str(),
format::Alignment::CENTER,
),
]));
}

Expand All @@ -129,7 +167,8 @@ mod tests {
use prettytable::{format, Cell, Row, Table};
use sozo_ops::statistics::ContractStatistics;

use super::{create_stats_table, BuildArgs};
use super::{create_stats_table, BuildArgs, *};
use crate::commands::build::CONTRACT_NAME_LABEL;

// Uncomment once bindings support arrays.
#[test]
Expand All @@ -141,9 +180,9 @@ mod tests {

let build_args = BuildArgs {
bindings_output: "generated".to_string(),
typescript: false,
// typescript: false,
unity: true,
typescript_v2: false,
typescript_v2: true,
stats: true,
};
let result = build_args.run(&config);
Expand All @@ -156,42 +195,48 @@ mod tests {
let contracts_statistics = vec![
ContractStatistics {
contract_name: "Test1".to_string(),
number_felts: 33,
file_size: 33,
sierra_bytecode_size: 33,
sierra_contract_class_size: 33,
casm_bytecode_size: 66,
casm_contract_class_size: 66,
},
ContractStatistics {
contract_name: "Test2".to_string(),
number_felts: 43,
file_size: 24,
sierra_bytecode_size: 43,
sierra_contract_class_size: 24,
casm_bytecode_size: 86,
casm_contract_class_size: 48,
},
ContractStatistics {
contract_name: "Test3".to_string(),
number_felts: 36,
file_size: 12,
sierra_bytecode_size: 36,
sierra_contract_class_size: 12,
casm_bytecode_size: 72,
casm_contract_class_size: 24,
},
];

let mut expected_table = Table::new();
expected_table.set_format(*FORMAT_NO_LINESEP_WITH_TITLE);
expected_table.set_titles(Row::new(vec![
Cell::new_align("Contract", format::Alignment::CENTER),
Cell::new_align("Bytecode size (felts)", format::Alignment::CENTER),
Cell::new_align("Class size (bytes)", format::Alignment::CENTER),
Cell::new_align(CONTRACT_NAME_LABEL, format::Alignment::CENTER),
Cell::new_align(BYTECODE_SIZE_LABEL, format::Alignment::CENTER),
Cell::new_align(CONTRACT_CLASS_SIZE_LABEL, format::Alignment::CENTER),
]));
expected_table.add_row(Row::new(vec![
Cell::new_align("Test1", format::Alignment::LEFT),
Cell::new_align(format!("{}", 33).as_str(), format::Alignment::RIGHT),
Cell::new_align(format!("{}", 33).as_str(), format::Alignment::RIGHT),
Cell::new_align(format!("{}, {}", 33, 66).as_str(), format::Alignment::CENTER),
Cell::new_align(format!("{}, {}", 33, 66).as_str(), format::Alignment::CENTER),
]));
expected_table.add_row(Row::new(vec![
Cell::new_align("Test2", format::Alignment::LEFT),
Cell::new_align(format!("{}", 43).as_str(), format::Alignment::RIGHT),
Cell::new_align(format!("{}", 24).as_str(), format::Alignment::RIGHT),
Cell::new_align(format!("{}, {}", 43, 86).as_str(), format::Alignment::CENTER),
Cell::new_align(format!("{}, {}", 24, 48).as_str(), format::Alignment::CENTER),
]));
expected_table.add_row(Row::new(vec![
Cell::new_align("Test3", format::Alignment::LEFT),
Cell::new_align(format!("{}", 36).as_str(), format::Alignment::RIGHT),
Cell::new_align(format!("{}", 12).as_str(), format::Alignment::RIGHT),
Cell::new_align(format!("{}, {}", 36, 72).as_str(), format::Alignment::CENTER),
Cell::new_align(format!("{}, {}", 12, 24).as_str(), format::Alignment::CENTER),
]));

// Act
Expand Down
Loading

0 comments on commit e1766f9

Please sign in to comment.