Skip to content

Commit

Permalink
Merge remote-tracking branch 'dojo/main' into fix/sozo-models
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Aug 30, 2024
2 parents 92d27f5 + fea03f4 commit 297a9b9
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 31 deletions.
8 changes: 5 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ ENV TABLEGEN_170_PREFIX=/usr/lib/llvm-17

# To allow independent workflow of the container, the rust-toolchain is explicitely given.
RUN echo "1.80.0" > rust_toolchain_version
# Make sure to sync the nightly version with the scripts in ./scripts
RUN echo "nightly-2024-08-28" > nightly_rust_toolchain_version

# Install cargo-binstall
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
Expand All @@ -36,8 +38,8 @@ RUN rustup toolchain install $(cat rust_toolchain_version) && \
rustup component add clippy && \
rustup component add rustfmt

RUN rustup toolchain install nightly && \
rustup component add rustfmt clippy --toolchain nightly
RUN rustup toolchain install $(cat nightly_rust_toolchain_version) && \
rustup component add rustfmt clippy --toolchain $(cat nightly_rust_toolchain_version)

RUN rustup target add x86_64-pc-windows-msvc && \
rustup target add wasm32-unknown-unknown
Expand All @@ -60,7 +62,7 @@ RUN if [ "$TARGETPLATFORM" = "linux/arm64" ] ; then \
rm -r hurl-4.1.0-x86_64-unknown-linux-gnu && \
rm hurl.tar.gz && \
rustup component add llvm-tools-preview --toolchain $(cat rust_toolchain_version)-x86_64-unknown-linux-gnu && \
rustup target add x86_64-fortanix-unknown-sgx --toolchain nightly; \
rustup target add x86_64-fortanix-unknown-sgx --toolchain $(cat nightly_rust_toolchain_version); \
fi

ARG DOJO_VERSION=stable
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/rust
{
"name": "Rust",
"image": "ghcr.io/dojoengine/dojo-dev:v1.0.0-alpha.8",
"image": "ghcr.io/dojoengine/dojo-dev:e89ac13",
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
bench-katana:
runs-on: ubuntu-latest
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.0-alpha.8
image: ghcr.io/dojoengine/dojo-dev:e89ac13
steps:
- uses: actions/checkout@v3
- run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
needs: ensure-docker
runs-on: ubuntu-latest-32-cores
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.0-alpha.8
image: ghcr.io/dojoengine/dojo-dev:e89ac13
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
Expand All @@ -55,7 +55,7 @@ jobs:
ensure-wasm:
runs-on: ubuntu-latest
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.0-alpha.8
image: ghcr.io/dojoengine/dojo-dev:e89ac13
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
needs: build
runs-on: ubuntu-latest
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.0-alpha.8
image: ghcr.io/dojoengine/dojo-dev:e89ac13
steps:
- uses: actions/download-artifact@v4
with:
Expand All @@ -135,7 +135,7 @@ jobs:
needs: build
runs-on: ubuntu-latest
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.0-alpha.8
image: ghcr.io/dojoengine/dojo-dev:e89ac13
steps:
- uses: actions/download-artifact@v4
with:
Expand All @@ -149,7 +149,7 @@ jobs:
dojo-world-bindings-check:
runs-on: ubuntu-latest
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.0-alpha.8
image: ghcr.io/dojoengine/dojo-dev:e89ac13
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
Expand All @@ -158,7 +158,7 @@ jobs:
clippy:
runs-on: ubuntu-latest-4-cores
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.0-alpha.8
image: ghcr.io/dojoengine/dojo-dev:e89ac13
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
Expand All @@ -167,7 +167,7 @@ jobs:
fmt:
runs-on: ubuntu-latest
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.0-alpha.8
image: ghcr.io/dojoengine/dojo-dev:e89ac13
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
Expand All @@ -176,7 +176,7 @@ jobs:
docs:
runs-on: ubuntu-latest
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.0-alpha.8
image: ghcr.io/dojoengine/dojo-dev:e89ac13
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
contents: write
runs-on: ubuntu-latest
container:
image: ghcr.io/dojoengine/dojo-dev:v1.0.0-alpha.8
image: ghcr.io/dojoengine/dojo-dev:e89ac13
env:
VERSION: ""
steps:
Expand Down
5 changes: 5 additions & 0 deletions bin/sozo/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use scarb_ui::args::{FeaturesSpec, PackagesFilter};
use sozo_ops::statistics::{get_contract_statistics_for_dir, ContractStatistics};
use tracing::trace;

use crate::commands::check_package_dojo_version;
use crate::commands::clean::CleanArgs;

const BYTECODE_SIZE_LABEL: &str = "Bytecode size [in felts]\n(Sierra, Casm)";
Expand Down Expand Up @@ -58,6 +59,10 @@ impl BuildArgs {
ws.members().collect()
};

for p in &packages {
check_package_dojo_version(&ws, p)?;
}

let profile_name =
ws.current_profile().expect("Scarb profile is expected at this point.").to_string();

Expand Down
21 changes: 17 additions & 4 deletions bin/sozo/src/commands/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use clap::Args;
use dojo_world::contracts::naming::ensure_namespace;
use dojo_world::metadata::get_default_namespace_from_ws;
use scarb::core::Config;
use starknet::core::types::Felt;
use tracing::trace;

use super::options::starknet::StarknetOptions;
use super::options::world::WorldOptions;
use crate::commands::calldata_decoder;
use crate::utils;

#[derive(Debug, Args)]
Expand All @@ -22,8 +22,14 @@ pub struct CallArgs {
#[arg(short, long)]
#[arg(value_delimiter = ',')]
#[arg(help = "The calldata to be passed to the entrypoint. Comma separated values e.g., \
0x12345,0x69420.")]
pub calldata: Vec<Felt>,
0x12345,128,u256:9999999999. Sozo supports some prefixes that you can use to \
automatically parse some types. The supported prefixes are:
- u256: A 256-bit unsigned integer.
- sstr: A cairo short string.
- str: A cairo string (ByteArray).
- int: A signed integer.
- no prefix: A cairo felt or any type that fit into one felt.")]
pub calldata: Option<String>,

#[arg(short, long)]
#[arg(help = "The block ID (could be a hash, a number, 'pending' or 'latest')")]
Expand Down Expand Up @@ -57,11 +63,18 @@ impl CallArgs {
.await
.unwrap();

let calldata = if let Some(cd) = self.calldata {
calldata_decoder::decode_calldata(&cd)?
} else {
vec![]
};

sozo_ops::call::call(
&config.ui(),
world_reader,
tag_or_address,
self.entrypoint,
self.calldata,
calldata,
self.block_id,
)
.await
Expand Down
46 changes: 45 additions & 1 deletion bin/sozo/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::fmt;

use anyhow::Result;
use clap::Subcommand;
use scarb::core::Config;
use scarb::core::{Config, Package, Workspace};

pub(crate) mod account;
pub(crate) mod auth;
Expand Down Expand Up @@ -133,3 +133,47 @@ pub fn run(command: Commands, config: &Config) -> Result<()> {
Commands::Completions(args) => args.run(),
}
}

/// Checks if the package has a compatible version of dojo-core.
/// In case of a workspace with multiple packages, each package is individually checked
/// and the workspace manifest path is returned in case of virtual workspace.
pub fn check_package_dojo_version(ws: &Workspace<'_>, package: &Package) -> anyhow::Result<()> {
if let Some(dojo_dep) =
package.manifest.summary.dependencies.iter().find(|dep| dep.name.as_str() == "dojo")
{
let dojo_version = env!("CARGO_PKG_VERSION");
println!("Dojo version: {}", dojo_version);

let dojo_dep_str = dojo_dep.to_string();
println!("Dojo dep: {}", dojo_dep_str);

// Only in case of git dependency with an explicit tag, we check if the tag is the same as
// the current version.
if dojo_dep_str.contains("git+")
&& dojo_dep_str.contains("tag=v")
&& !dojo_dep_str.contains(dojo_version)
{
if let Ok(cp) = ws.current_package() {
let path =
if cp.id == package.id { package.manifest_path() } else { ws.manifest_path() };

anyhow::bail!(
"Found dojo-core version mismatch: expected {}. Please verify your dojo \
dependency in {}",
dojo_version,
path
)
} else {
// Virtual workspace.
anyhow::bail!(
"Found dojo-core version mismatch: expected {}. Please verify your dojo \
dependency in {}",
dojo_version,
ws.manifest_path()
)
}
}
}

Ok(())
}
6 changes: 6 additions & 0 deletions bin/sozo/src/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use scarb::ops::{self, CompileOpts};
use scarb_ui::args::{FeaturesSpec, PackagesFilter};
use tracing::trace;

use super::check_package_dojo_version;

pub(crate) const LOG_TARGET: &str = "sozo::cli::commands::test";

#[derive(Debug, Clone, PartialEq, clap::ValueEnum)]
Expand Down Expand Up @@ -81,6 +83,10 @@ impl TestArgs {
ws.members().collect()
};

for p in &packages {
check_package_dojo_version(&ws, p)?;
}

let resolve = ops::resolve_workspace(&ws)?;

let opts = CompileOpts {
Expand Down
26 changes: 21 additions & 5 deletions crates/sozo/ops/src/call.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use anyhow::{Context, Result};
use anyhow::Result;
use dojo_world::contracts::WorldContractReader;
use scarb_ui::Ui;
use starknet::core::types::{BlockId, BlockTag, Felt, FunctionCall};
use starknet::core::utils::get_selector_from_name;
use starknet::providers::Provider;

use crate::migration::ui::MigrationUi;
use crate::utils::{get_contract_address_from_reader, parse_block_id};

pub async fn call<P: Provider + Sync + Send>(
ui: &Ui,
world_reader: WorldContractReader<P>,
tag_or_address: String,
entrypoint: String,
Expand All @@ -20,7 +23,7 @@ pub async fn call<P: Provider + Sync + Send>(
BlockId::Tag(BlockTag::Pending)
};

let output = world_reader
let res = world_reader
.provider()
.call(
FunctionCall {
Expand All @@ -30,10 +33,23 @@ pub async fn call<P: Provider + Sync + Send>(
},
block_id,
)
.await
.with_context(|| format!("Failed to call {entrypoint}"))?;
.await;

println!("[ {} ]", output.iter().map(|o| format!("0x{:x}", o)).collect::<Vec<_>>().join(" "));
match res {
Ok(output) => {
println!(
"[ {} ]",
output.iter().map(|o| format!("0x{:x}", o)).collect::<Vec<_>>().join(" ")
);
}
Err(e) => {
ui.print_hidden_sub(format!("{:?}", e));
anyhow::bail!(format!(
"Error calling entrypoint `{}` on address: {:#066x}",
entrypoint, contract_address
));
}
}

Ok(())
}
Loading

0 comments on commit 297a9b9

Please sign in to comment.