diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cfaa6ee1c2..79e972e988 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -114,7 +114,7 @@ jobs: - uses: actions/checkout@v3 - uses: software-mansion/setup-scarb@v1 with: - scarb-version: "2.8.4" + scarb-version: "2.9.2" - run: | scarb --manifest-path examples/spawn-and-move/Scarb.toml fmt --check scarb --manifest-path examples/simple/Scarb.toml fmt --check @@ -127,6 +127,9 @@ jobs: container: image: ghcr.io/dojoengine/dojo-dev:v1.0.11 steps: + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: "2.9.2" - uses: actions/download-artifact@v4 with: name: dojo-bins @@ -143,6 +146,9 @@ jobs: container: image: ghcr.io/dojoengine/dojo-dev:v1.0.11 steps: + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: "2.9.2" - uses: actions/download-artifact@v4 with: name: dojo-bins diff --git a/.tool-versions b/.tool-versions index dee4ebacd4..e9c2ad7f1d 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -scarb 2.8.4 +scarb 2.9.2 starknet-foundry 0.30.0 diff --git a/Cargo.lock b/Cargo.lock index 5c50920e88..7e0b1adc3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2001,7 +2001,7 @@ dependencies = [ "bitflags 2.6.0", "cexpr", "clang-sys", - "itertools 0.11.0", + "itertools 0.12.1", "lazy_static", "lazycell", "log", @@ -2122,8 +2122,8 @@ dependencies = [ [[package]] name = "blockifier" -version = "0.8.0-rc.3" -source = "git+https://github.com/dojoengine/sequencer?tag=v0.8.0-rc3.2#d6951f24fc2082c7aa89cdbc063648915b131d74" +version = "0.0.0" +source = "git+https://github.com/dojoengine/sequencer?rev=802c5dc#802c5dc1b3ca231d96b65ffcada349f4b5ab0e3b" dependencies = [ "anyhow", "ark-ec", @@ -2134,31 +2134,32 @@ dependencies = [ "cairo-lang-casm", "cairo-lang-runner", "cairo-lang-starknet-classes", - "cairo-lang-utils", "cairo-vm 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "derive_more 0.99.18", "indexmap 2.5.0", - "itertools 0.10.5", + "itertools 0.12.1", "keccak", "log", "num-bigint", "num-integer", "num-rational", "num-traits 0.2.19", - "once_cell", + "papyrus_config", "paste", "phf", "rand 0.8.5", "rstest 0.17.0", + "semver 1.0.23", "serde", "serde_json", "sha2 0.10.8", - "sha3", "starknet-types-core", "starknet_api", "strum 0.25.0", "strum_macros 0.25.3", + "tempfile", "thiserror 1.0.63", + "toml 0.8.19", ] [[package]] @@ -2214,7 +2215,7 @@ dependencies = [ "slotmap", "smallvec", "starknet-types-core", - "thiserror 2.0.7", + "thiserror 2.0.11", ] [[package]] @@ -2469,32 +2470,6 @@ dependencies = [ "url", ] -[[package]] -name = "cainome" -version = "0.4.6" -source = "git+https://github.com/cartridge-gg/cainome?rev=5c2616c273faca7700d2ba565503fcefb5b9d720#5c2616c273faca7700d2ba565503fcefb5b9d720" -dependencies = [ - "anyhow", - "async-trait", - "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?rev=5c2616c273faca7700d2ba565503fcefb5b9d720)", - "cainome-cairo-serde-derive 0.1.0 (git+https://github.com/cartridge-gg/cainome?rev=5c2616c273faca7700d2ba565503fcefb5b9d720)", - "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?rev=5c2616c273faca7700d2ba565503fcefb5b9d720)", - "cainome-rs 0.1.0 (git+https://github.com/cartridge-gg/cainome?rev=5c2616c273faca7700d2ba565503fcefb5b9d720)", - "cainome-rs-macro 0.1.0 (git+https://github.com/cartridge-gg/cainome?rev=5c2616c273faca7700d2ba565503fcefb5b9d720)", - "camino", - "clap", - "clap_complete", - "convert_case 0.6.0", - "serde", - "serde_json", - "starknet 0.12.0", - "starknet-types-core", - "thiserror 1.0.63", - "tracing", - "tracing-subscriber", - "url", -] - [[package]] name = "cainome" version = "0.4.11" @@ -2503,7 +2478,7 @@ dependencies = [ "anyhow", "async-trait", "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.11)", - "cainome-cairo-serde-derive 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.11)", + "cainome-cairo-serde-derive", "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.11)", "cainome-rs 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.11)", "cainome-rs-macro 0.1.0 (git+https://github.com/cartridge-gg/cainome?tag=v0.4.11)", @@ -2543,16 +2518,6 @@ dependencies = [ "thiserror 1.0.63", ] -[[package]] -name = "cainome-cairo-serde" -version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?rev=5c2616c273faca7700d2ba565503fcefb5b9d720#5c2616c273faca7700d2ba565503fcefb5b9d720" -dependencies = [ - "serde", - "starknet 0.12.0", - "thiserror 1.0.63", -] - [[package]] name = "cainome-cairo-serde-derive" version = "0.1.0" @@ -2564,17 +2529,6 @@ dependencies = [ "unzip-n", ] -[[package]] -name = "cainome-cairo-serde-derive" -version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?rev=5c2616c273faca7700d2ba565503fcefb5b9d720#5c2616c273faca7700d2ba565503fcefb5b9d720" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.90", - "unzip-n", -] - [[package]] name = "cainome-parser" version = "0.1.0" @@ -2601,19 +2555,6 @@ dependencies = [ "thiserror 1.0.63", ] -[[package]] -name = "cainome-parser" -version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?rev=5c2616c273faca7700d2ba565503fcefb5b9d720#5c2616c273faca7700d2ba565503fcefb5b9d720" -dependencies = [ - "convert_case 0.6.0", - "quote", - "serde_json", - "starknet 0.12.0", - "syn 2.0.90", - "thiserror 1.0.63", -] - [[package]] name = "cainome-rs" version = "0.1.0" @@ -2650,24 +2591,6 @@ dependencies = [ "thiserror 1.0.63", ] -[[package]] -name = "cainome-rs" -version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?rev=5c2616c273faca7700d2ba565503fcefb5b9d720#5c2616c273faca7700d2ba565503fcefb5b9d720" -dependencies = [ - "anyhow", - "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?rev=5c2616c273faca7700d2ba565503fcefb5b9d720)", - "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?rev=5c2616c273faca7700d2ba565503fcefb5b9d720)", - "camino", - "prettyplease", - "proc-macro2", - "quote", - "serde_json", - "starknet 0.12.0", - "syn 2.0.90", - "thiserror 1.0.63", -] - [[package]] name = "cainome-rs-macro" version = "0.1.0" @@ -2704,32 +2627,14 @@ dependencies = [ "thiserror 1.0.63", ] -[[package]] -name = "cainome-rs-macro" -version = "0.1.0" -source = "git+https://github.com/cartridge-gg/cainome?rev=5c2616c273faca7700d2ba565503fcefb5b9d720#5c2616c273faca7700d2ba565503fcefb5b9d720" -dependencies = [ - "anyhow", - "cainome-cairo-serde 0.1.0 (git+https://github.com/cartridge-gg/cainome?rev=5c2616c273faca7700d2ba565503fcefb5b9d720)", - "cainome-parser 0.1.0 (git+https://github.com/cartridge-gg/cainome?rev=5c2616c273faca7700d2ba565503fcefb5b9d720)", - "cainome-rs 0.1.0 (git+https://github.com/cartridge-gg/cainome?rev=5c2616c273faca7700d2ba565503fcefb5b9d720)", - "proc-macro-error", - "proc-macro2", - "quote", - "serde_json", - "starknet 0.12.0", - "syn 2.0.90", - "thiserror 1.0.63", -] - [[package]] name = "cairo-lang-casm" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd4d6659539ace9649c8e8a7434e51b0c50a7a700111d0a2b967dde220ddff49" +checksum = "3929a38c1d586e35e19dbdf7798b146fba3627b308417a6d373fea8939535b6b" dependencies = [ "cairo-lang-utils", - "indoc 2.0.5", + "indoc", "num-bigint", "num-traits 0.2.19", "parity-scale-codec", @@ -2738,9 +2643,9 @@ dependencies = [ [[package]] name = "cairo-lang-compiler" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2016966ed29f3a44487fd1bbdb05320fb6ea8ec46201c04c6b222ccb5264e0a" +checksum = "0bed098f0c3666b3ad3a93aef6293f91fc1119bef660ce994105f6d1bc2802cf" dependencies = [ "anyhow", "cairo-lang-defs", @@ -2754,7 +2659,7 @@ dependencies = [ "cairo-lang-sierra-generator", "cairo-lang-syntax", "cairo-lang-utils", - "indoc 2.0.5", + "indoc", "rayon", "rust-analyzer-salsa", "semver 1.0.23", @@ -2764,18 +2669,18 @@ dependencies = [ [[package]] name = "cairo-lang-debug" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50c804649297ca417206435ee3e8041d2100cc31ebf4a95bc4b92ed02dc63469" +checksum = "d7763505dcfe15f36899074c27185bf7e3494875f63fd06350c6e3ed8d1f91d5" dependencies = [ "cairo-lang-utils", ] [[package]] name = "cairo-lang-defs" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8fbda467ac36f73bb1879e1f741898fc719d6f9239a01cc422e6a023281319b" +checksum = "b4d29dc5a3cafe94ea4397d41b00cd54a9dffbe9bc3a3092a9ea617ea737bc6e" dependencies = [ "cairo-lang-debug", "cairo-lang-diagnostics", @@ -2790,9 +2695,9 @@ dependencies = [ [[package]] name = "cairo-lang-diagnostics" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c843ef4715e3d21de5388d02206db2506e2d2ec0e80e2629e0ae9900a08b8674" +checksum = "761d20ca9c3a3eb7025b2488aa6e0e5dc23c5d551dd95e83a989b5e87687f523" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -2802,24 +2707,30 @@ dependencies = [ [[package]] name = "cairo-lang-doc" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a932262ab491cf248283ccbe6d584a76fd55fc85ae0c7879b2ad687c512a115" +checksum = "835b357a22fccbfecdeeee4c4566d94e0b329cedcf91c0aad1c535e966dd867b" dependencies = [ + "cairo-lang-debug", "cairo-lang-defs", + "cairo-lang-diagnostics", + "cairo-lang-filesystem", "cairo-lang-formatter", "cairo-lang-parser", + "cairo-lang-semantic", "cairo-lang-syntax", "cairo-lang-utils", "itertools 0.12.1", + "pulldown-cmark", "rust-analyzer-salsa", + "smol_str", ] [[package]] name = "cairo-lang-eq-solver" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33a416c5871960fb4823160ebef2abc51e0c1b86fef1e97a1ebb2e5f3c3795d3" +checksum = "d778ec864e92c82293370a512195715b12775b05981e14065d85eb5dd3dd96b6" dependencies = [ "cairo-lang-utils", "good_lp", @@ -2827,9 +2738,9 @@ dependencies = [ [[package]] name = "cairo-lang-filesystem" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47189e0cb84b21defd201af4cf24a94c6b0d09f48706cf659c9ffa0def8a7a43" +checksum = "d9dc486c554e2df3be8e84c47e30fe55b59d2349b680fbe992bfba801ef93ff5" dependencies = [ "cairo-lang-debug", "cairo-lang-utils", @@ -2838,13 +2749,14 @@ dependencies = [ "semver 1.0.23", "serde", "smol_str", + "toml 0.8.19", ] [[package]] name = "cairo-lang-formatter" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6409ff1f4a93ce7c0968d9d857d2a8c03657617a827159d33f978110b718b31d" +checksum = "675d281a3c9aa365055ce6e201d5dd91534dfccfd2929a41b7397f665c80293c" dependencies = [ "anyhow", "cairo-lang-diagnostics", @@ -2857,15 +2769,14 @@ dependencies = [ "itertools 0.12.1", "rust-analyzer-salsa", "serde", - "smol_str", "thiserror 1.0.63", ] [[package]] name = "cairo-lang-language-server" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5dad8906d9d4b3876e6b2061f9ddd499f0514368e3e7e0aeaea70e80c3608a" +checksum = "f6164634b4b3a07f8ab575435e053931c37bf0609121e52ca6026f000f542ed8" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -2875,6 +2786,7 @@ dependencies = [ "cairo-lang-filesystem", "cairo-lang-formatter", "cairo-lang-lowering", + "cairo-lang-macro", "cairo-lang-parser", "cairo-lang-project", "cairo-lang-semantic", @@ -2882,17 +2794,25 @@ dependencies = [ "cairo-lang-syntax", "cairo-lang-test-plugin", "cairo-lang-utils", + "convert_case 0.6.0", + "crossbeam", + "governor", "indent", - "indoc 2.0.5", + "indoc", "itertools 0.12.1", + "jod-thread", + "libc", + "lsp-server", + "lsp-types", "rust-analyzer-salsa", - "scarb-metadata 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hash 1.1.0", + "scarb-metadata 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "scarb-proc-macro-server-types 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "scarb-stable-hash 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde", "serde_json", "smol_str", "tempfile", - "tokio", - "tower-lsp", "tracing", "tracing-chrome", "tracing-subscriber", @@ -2900,9 +2820,9 @@ dependencies = [ [[package]] name = "cairo-lang-lowering" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e224e006c82ef21bd9e243390992de2be25ae6fbbdaa8544067b3f0c31977f1" +checksum = "d880470c94f94fac08c2150bc0ce4af930b6760956a56966e47612de376d57ec" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -2917,6 +2837,7 @@ dependencies = [ "itertools 0.12.1", "log", "num-bigint", + "num-integer", "num-traits 0.2.19", "rust-analyzer-salsa", "smol_str", @@ -2924,12 +2845,14 @@ dependencies = [ [[package]] name = "cairo-lang-macro" -version = "0.1.0" -source = "git+https://github.com/dojoengine/scarb?rev=7eac49b3e61236ce466e712225d9c989f9db1ef3#7eac49b3e61236ce466e712225d9c989f9db1ef3" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dda77fe9404e438edaa80c9acaf0d72260aa883ba433812d0a745f5a72f31881" dependencies = [ "cairo-lang-macro-attributes", "cairo-lang-macro-stable", "linkme", + "serde", ] [[package]] @@ -2951,9 +2874,9 @@ checksum = "c49906d6b1c215e5814be7c5c65ecf2328898b335bee8c2409ec07cfb5530daf" [[package]] name = "cairo-lang-parser" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb260ba349c2b699639e56f9b64deb969ff01179a0253087e2c8ceec7e32157" +checksum = "37e2b488f659432c8b866bf540e54ab3696a24ac0f366faac33b860c5313e78c" dependencies = [ "cairo-lang-diagnostics", "cairo-lang-filesystem", @@ -2971,9 +2894,9 @@ dependencies = [ [[package]] name = "cairo-lang-plugins" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05a2e500dc8ddea4d25a866d8a839158b0e4c41a6c023f21911e2da252bd91b3" +checksum = "13cf34fd39a1efb997455fa38dbdb6bef489a125a2d17d77ebfea1ee580559f3" dependencies = [ "cairo-lang-defs", "cairo-lang-diagnostics", @@ -2982,17 +2905,23 @@ dependencies = [ "cairo-lang-syntax", "cairo-lang-utils", "indent", - "indoc 2.0.5", + "indoc", "itertools 0.12.1", "rust-analyzer-salsa", "smol_str", ] +[[package]] +name = "cairo-lang-primitive-token" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "123ac0ecadf31bacae77436d72b88fa9caef2b8e92c89ce63a125ae911a12fae" + [[package]] name = "cairo-lang-proc-macros" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d72f17373740f242d6995e896b9195c2cedff7e8b14e496afdd16b405039d1fb" +checksum = "b3c4a161868276ce022c44ac500afbfa0d7d8371106feb40dfca34ea7be97503" dependencies = [ "cairo-lang-debug", "quote", @@ -3001,34 +2930,50 @@ dependencies = [ [[package]] name = "cairo-lang-project" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13294f08d2013fcd6e815e7235935680963dec3390e5baf454f33da866fc44b6" +checksum = "fde3cc9777fff4daacbfd839a6fcefa29abd660068de47f72ac6d5883fa93ccd" dependencies = [ "cairo-lang-filesystem", "cairo-lang-utils", "serde", - "smol_str", "thiserror 1.0.63", "toml 0.8.19", ] +[[package]] +name = "cairo-lang-runnable-utils" +version = "2.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872d846834c8fdc886a7dc591c1f6ddd969d25d2c88dd65452931c63dfca7acc" +dependencies = [ + "cairo-lang-casm", + "cairo-lang-sierra", + "cairo-lang-sierra-ap-change", + "cairo-lang-sierra-gas", + "cairo-lang-sierra-to-casm", + "cairo-lang-sierra-type-size", + "cairo-lang-utils", + "cairo-vm 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "itertools 0.12.1", + "thiserror 1.0.63", +] + [[package]] name = "cairo-lang-runner" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c5b9e6a21d92255b92f64c60658b4224dd7d290cde8beea783fadc10fbfcd8c" +checksum = "f9121164a61b0a8fcadefc8b21240e372bf04e6648ea31d09f9e85701e60877a" dependencies = [ "ark-ff 0.4.2", "ark-secp256k1", "ark-secp256r1", "cairo-lang-casm", "cairo-lang-lowering", + "cairo-lang-runnable-utils", "cairo-lang-sierra", - "cairo-lang-sierra-ap-change", "cairo-lang-sierra-generator", "cairo-lang-sierra-to-casm", - "cairo-lang-sierra-type-size", "cairo-lang-starknet", "cairo-lang-utils", "cairo-vm 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3046,9 +2991,9 @@ dependencies = [ [[package]] name = "cairo-lang-semantic" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6936215bca75c23e71873998420a3d46c322507a09917ce676c8d39f8c1bd6fe" +checksum = "8af1f92ba601fd61a994c44d0c80d711fbb3d64b2b5a1e72905fc6f581b1fadd" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -3061,20 +3006,21 @@ dependencies = [ "cairo-lang-test-utils", "cairo-lang-utils", "id-arena", - "indoc 2.0.5", + "indoc", "itertools 0.12.1", "num-bigint", "num-traits 0.2.19", "rust-analyzer-salsa", + "sha3", "smol_str", "toml 0.8.19", ] [[package]] name = "cairo-lang-sierra" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "424f55450494e959c1ae26c52a71075767a90f76e3ecca6e81056dd7517e8ba0" +checksum = "075c6457642ada82b32cf657d871a8545ae7a9d61c78dd5588a794c8c905abdc" dependencies = [ "anyhow", "cairo-lang-utils", @@ -3099,9 +3045,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-ap-change" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053dd520e0b9d1c1078d93ea69045f6f334c3d41b4b75db183ab33e32cfd8570" +checksum = "b69172fe8354b1dd564bba318ccb5233aa78f70d57145b8c92a0b1cf009fa0fc" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -3115,9 +3061,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-gas" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a73227867377efc62ebb893cddaa88df3940bf2be5dbdc2f0b00f9edf69288e" +checksum = "42b571b73d9b02103f780aeee05dbf9a71d68d8a16341a04aa1dd581d0db3ad6" dependencies = [ "cairo-lang-eq-solver", "cairo-lang-sierra", @@ -3131,9 +3077,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-generator" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3752cacd475ea089d9a536357804150e693a124e703fcc33a55566d568094b3" +checksum = "1d3857cd98a0cb35b32cc962e70c04e6ddfcd8bf61106ac37b6cf453ec76b878" dependencies = [ "cairo-lang-debug", "cairo-lang-defs", @@ -3155,9 +3101,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-to-casm" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7162fb3c93960dfc6d8005b65064e518e3f1ed6102e8981b42ea41879c331184" +checksum = "add264b156dfb01f18292282a6037070c078acca3bccde05787da1e1c997b78c" dependencies = [ "assert_matches", "cairo-lang-casm", @@ -3166,7 +3112,7 @@ dependencies = [ "cairo-lang-sierra-gas", "cairo-lang-sierra-type-size", "cairo-lang-utils", - "indoc 2.0.5", + "indoc", "itertools 0.12.1", "num-bigint", "num-traits 0.2.19", @@ -3176,9 +3122,9 @@ dependencies = [ [[package]] name = "cairo-lang-sierra-type-size" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a51b80c117e2b05a6d300f2e2247892cc99e42e950e79f6085e6ed6cbcb44d12" +checksum = "7bda5388ef862bc26388e999ac7ad62dd8ab3064720c3483b81fd761b051e627" dependencies = [ "cairo-lang-sierra", "cairo-lang-utils", @@ -3186,9 +3132,9 @@ dependencies = [ [[package]] name = "cairo-lang-starknet" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aafaabc43f78dfa2f45d935993ba21c05c164bbb3bf277d348847a51e5939a9f" +checksum = "32d5ed4aa48fe739f643a8c503c14aec0858c31dc73ba4e6a335b77ca7438807" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -3205,7 +3151,7 @@ dependencies = [ "cairo-lang-utils", "const_format", "indent", - "indoc 2.0.5", + "indoc", "itertools 0.12.1", "serde", "serde_json", @@ -3216,9 +3162,9 @@ dependencies = [ [[package]] name = "cairo-lang-starknet-classes" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "832fd9072ddf4204ca6d227c0238929349f10146bd066a98025d51ac15d27fad" +checksum = "fe691200b431e51e3d6cfa84f256a3dd2e8405f44d182843fbe124f803d085ff" dependencies = [ "cairo-lang-casm", "cairo-lang-sierra", @@ -3239,12 +3185,13 @@ dependencies = [ [[package]] name = "cairo-lang-syntax" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cebe67c0d68f9acf8709d170c1308ca57a778d22f70da38a57f74ae250eee28a" +checksum = "0a38f1431f22a9487b9b0dd7aef098c9605fe6b8677e0f620547aa69195f7fb5" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", + "cairo-lang-primitive-token", "cairo-lang-utils", "num-bigint", "num-traits 0.2.19", @@ -3255,9 +3202,9 @@ dependencies = [ [[package]] name = "cairo-lang-syntax-codegen" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31cef5b4347626e61bad8f070495cd35d637a5cb6744c34d20dd382c7431aff8" +checksum = "fd7990586c9bb37eaa875ffeb218bdecf96f87881d03263ebf84fcd46514ca9f" dependencies = [ "genco", "xshell", @@ -3265,9 +3212,9 @@ dependencies = [ [[package]] name = "cairo-lang-test-plugin" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d5f036132e07b7829cb1d61b1ecc02789a70c7d16b2733722a2aca992492bc3" +checksum = "5432fb1e290bed1c961a6bd778b3b553480b364524e7dbc343495b79b452131b" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -3282,7 +3229,7 @@ dependencies = [ "cairo-lang-starknet-classes", "cairo-lang-syntax", "cairo-lang-utils", - "indoc 2.0.5", + "indoc", "itertools 0.12.1", "num-bigint", "num-traits 0.2.19", @@ -3292,9 +3239,9 @@ dependencies = [ [[package]] name = "cairo-lang-test-runner" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3effbddf1d0cebab9c91ca46d9792ed441095e1eb75a53785a15e5f378f9c52e" +checksum = "64db55a6df93c900c9f7d620292c9fca4d43b6e3e180442085a896d218a84e43" dependencies = [ "anyhow", "cairo-lang-compiler", @@ -3315,9 +3262,9 @@ dependencies = [ [[package]] name = "cairo-lang-test-utils" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "060c61ac4a3ae0428771244ff8db903105f127392b7d725d919fe3fb1ec4132f" +checksum = "f2b76c55a742da177540d2a0eb39fa50d011998d0ccfdeae8b48ea0e2d7f077f" dependencies = [ "cairo-lang-formatter", "cairo-lang-utils", @@ -3328,9 +3275,9 @@ dependencies = [ [[package]] name = "cairo-lang-utils" -version = "2.8.4" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bfc6372538143afad658c853a35bdc9f5210c5cb54e0c8f04ab78e268139466" +checksum = "ff5d7609abc99c15de7d7f90b8441b27e2bd52e930a3014c95a9b620e5d3211a" dependencies = [ "env_logger", "hashbrown 0.14.5", @@ -4188,7 +4135,7 @@ dependencies = [ [[package]] name = "create-output-dir" version = "1.0.0" -source = "git+https://github.com/dojoengine/scarb?rev=7eac49b3e61236ce466e712225d9c989f9db1ef3#7eac49b3e61236ce466e712225d9c989f9db1ef3" +source = "git+https://github.com/dojoengine/scarb?rev=72b5db6b009fda6a83e2740d2a10b529b02d792c#72b5db6b009fda6a83e2740d2a10b529b02d792c" dependencies = [ "anyhow", "core-foundation 0.10.0", @@ -4232,6 +4179,19 @@ dependencies = [ "itertools 0.10.5", ] +[[package]] +name = "crossbeam" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1137cd7e7fc0fb5d3c5a8678be38ec56e819125d8d7907411fe24ccb943faca8" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils", +] + [[package]] name = "crossbeam-channel" version = "0.5.13" @@ -4542,19 +4502,20 @@ dependencies = [ [[package]] name = "deno_task_shell" -version = "0.18.0" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec1b0c646a53492068b6675af74cecbef486e670be2c0cdd06e7e636d167e50f" +checksum = "e2da21d6f1061632e50ee585afa570bcad080b7a42fe7baedf447007c49f848e" dependencies = [ "anyhow", "futures", "glob", "monch", + "nix 0.29.0", "os_pipe", "path-dedot", - "thiserror 1.0.63", + "thiserror 2.0.11", "tokio", - "tokio-util", + "windows-sys 0.59.0", ] [[package]] @@ -4869,40 +4830,24 @@ version = "1.0.11" [[package]] name = "dojo-lang" -version = "1.0.0-rc.2" -source = "git+https://github.com/dojoengine/dojo?rev=6725a8f20af56213fa7382aa1e158817f3ee623c#6725a8f20af56213fa7382aa1e158817f3ee623c" +version = "1.0.9" +source = "git+https://github.com/dojoengine/dojo?rev=c04cdc63774929fb3bb8d7167e22683d7c9bc72f#c04cdc63774929fb3bb8d7167e22683d7c9bc72f" dependencies = [ "anyhow", - "cairo-lang-compiler", "cairo-lang-defs", "cairo-lang-diagnostics", "cairo-lang-filesystem", "cairo-lang-plugins", - "cairo-lang-project", "cairo-lang-semantic", - "cairo-lang-sierra-generator", - "cairo-lang-starknet", - "cairo-lang-starknet-classes", "cairo-lang-syntax", - "cairo-lang-test-plugin", "cairo-lang-utils", - "camino", - "convert_case 0.6.0", - "dojo-types 1.0.0-rc.2", - "indoc 1.0.9", + "dojo-types 1.0.9", "itertools 0.12.1", - "regex", - "semver 1.0.23", "serde", - "serde_json", - "serde_with 3.11.0", "smol_str", "starknet 0.12.0", "starknet-crypto 0.7.2", - "tempfile", - "toml 0.8.19", "tracing", - "url", ] [[package]] @@ -4976,13 +4921,14 @@ dependencies = [ [[package]] name = "dojo-types" -version = "1.0.0-rc.2" -source = "git+https://github.com/dojoengine/dojo?rev=6725a8f20af56213fa7382aa1e158817f3ee623c#6725a8f20af56213fa7382aa1e158817f3ee623c" +version = "1.0.9" +source = "git+https://github.com/dojoengine/dojo?rev=c04cdc63774929fb3bb8d7167e22683d7c9bc72f#c04cdc63774929fb3bb8d7167e22683d7c9bc72f" dependencies = [ "anyhow", - "cainome 0.4.6", + "cainome 0.4.11", "crypto-bigint", "hex", + "indexmap 2.5.0", "itertools 0.12.1", "num-traits 0.2.19", "regex", @@ -5259,6 +5205,12 @@ dependencies = [ "regex", ] +[[package]] +name = "env_home" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f84e12ccf0a7ddc17a6c41c93326024c42920d7ee630d04950e6926645c0fe" + [[package]] name = "env_logger" version = "0.11.5" @@ -5521,11 +5473,12 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" [[package]] name = "flate2" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253" +checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" dependencies = [ "crc32fast", + "libz-sys", "miniz_oxide 0.8.0", ] @@ -5646,9 +5599,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -5656,9 +5609,9 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" @@ -5685,9 +5638,9 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-lite" @@ -5719,9 +5672,9 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", @@ -5741,15 +5694,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-ticker" @@ -5774,9 +5727,9 @@ dependencies = [ [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-channel", "futures-core", @@ -5847,6 +5800,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + [[package]] name = "getrandom" version = "0.2.15" @@ -6820,6 +6782,25 @@ dependencies = [ "minilp", ] +[[package]] +name = "governor" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0746aa765db78b521451ef74221663b57ba595bf83f75d0ce23cc09447c8139f" +dependencies = [ + "cfg-if", + "futures-sink", + "futures-timer", + "futures-util", + "no-std-compat", + "nonzero_ext", + "parking_lot 0.12.3", + "portable-atomic", + "quanta", + "smallvec", + "spinning_top", +] + [[package]] name = "graphql-introspection-query" version = "0.2.0" @@ -7494,6 +7475,17 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "idna" version = "0.3.0" @@ -7553,6 +7545,12 @@ dependencies = [ "windows 0.51.1", ] +[[package]] +name = "if_chain" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb56e1aa765b4b4f3aadfab769793b7087bb03a4ea4920644a6d238e2df5b9ed" + [[package]] name = "igd-next" version = "0.14.3" @@ -7741,12 +7739,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "indoc" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306" - [[package]] name = "indoc" version = "2.0.5" @@ -7771,6 +7763,15 @@ dependencies = [ "str_stack", ] +[[package]] +name = "infra_utils" +version = "0.0.0" +source = "git+https://github.com/dojoengine/sequencer?rev=802c5dc#802c5dc1b3ca231d96b65ffcada349f4b5ab0e3b" +dependencies = [ + "tokio", + "tracing", +] + [[package]] name = "inotify" version = "0.10.2" @@ -8107,6 +8108,12 @@ dependencies = [ "libc", ] +[[package]] +name = "jod-thread" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b23360e99b8717f20aaa4598f5a6541efbe30630039fbc7706cf954a87947ae" + [[package]] name = "jpeg-decoder" version = "0.3.1" @@ -9124,9 +9131,9 @@ dependencies = [ [[package]] name = "libloading" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", "windows-targets 0.52.6", @@ -9673,6 +9680,17 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "libz-sys" +version = "1.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df9b68e50e6e0b26f672573834882eb57759f6db9b3be2ea3c35c91188bb4eaa" +dependencies = [ + "cc", + "pkg-config", + "vcpkg", +] + [[package]] name = "linked-hash-map" version = "0.5.6" @@ -9757,11 +9775,24 @@ dependencies = [ "linked-hash-map", ] +[[package]] +name = "lsp-server" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9462c4dc73e17f971ec1f171d44bfffb72e65a130117233388a0ebc7ec5656f9" +dependencies = [ + "crossbeam-channel", + "log", + "serde", + "serde_derive", + "serde_json", +] + [[package]] name = "lsp-types" -version = "0.94.1" +version = "0.95.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c66bfd44a06ae10647fe3f8214762e9369fd4248df1350924b4ef9e770a85ea1" +checksum = "158c1911354ef73e8fe42da6b10c0484cb65c7f1007f28022e847706c1ab6984" dependencies = [ "bitflags 1.3.2", "serde", @@ -9803,6 +9834,12 @@ dependencies = [ "regex-automata 0.1.10", ] +[[package]] +name = "matches" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" + [[package]] name = "matchit" version = "0.7.3" @@ -10348,6 +10385,12 @@ dependencies = [ "sha2 0.10.8", ] +[[package]] +name = "no-std-compat" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b93853da6d84c2e3c7d730d6473e8817692dd89be387eb01b94d7f108ecb5b8c" + [[package]] name = "nohash-hasher" version = "0.2.0" @@ -10364,6 +10407,12 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nonzero_ext" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38bf9645c8b145698bb0b18a4637dcacbc421ea49bef2317e4fd8065a387cf21" + [[package]] name = "noop_proc_macro" version = "0.3.0" @@ -10808,6 +10857,21 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "papyrus_config" +version = "0.0.0" +source = "git+https://github.com/dojoengine/sequencer?rev=802c5dc#802c5dc1b3ca231d96b65ffcada349f4b5ab0e3b" +dependencies = [ + "clap", + "infra_utils", + "itertools 0.12.1", + "serde", + "serde_json", + "strum_macros 0.25.3", + "thiserror 1.0.63", + "validator", +] + [[package]] name = "parity-scale-codec" version = "3.6.12" @@ -11595,8 +11659,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22505a5c94da8e3b7c2996394d1c933236c4d743e81a410bcca4e6989fc066a4" dependencies = [ "bytes", - "heck 0.4.1", - "itertools 0.11.0", + "heck 0.5.0", + "itertools 0.12.1", "log", "multimap", "once_cell", @@ -11616,7 +11680,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c1318b19085f08681016926435853bbf7858f9c082d0999b80550ff5d9abe15" dependencies = [ "bytes", - "heck 0.4.1", + "heck 0.5.0", "itertools 0.13.0", "log", "multimap", @@ -11637,7 +11701,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" dependencies = [ "anyhow", - "itertools 0.11.0", + "itertools 0.12.1", "proc-macro2", "quote", "syn 2.0.90", @@ -11732,6 +11796,25 @@ dependencies = [ "psl-types", ] +[[package]] +name = "pulldown-cmark" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f86ba2052aebccc42cbbb3ed234b8b13ce76f75c3551a303cb2bcffcff12bb14" +dependencies = [ + "bitflags 2.6.0", + "getopts", + "memchr", + "pulldown-cmark-escape", + "unicase", +] + +[[package]] +name = "pulldown-cmark-escape" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d8adb5ddab6f8e3f491ac63566a7d5002cc7ed73901f72057943fa71ae1ae" + [[package]] name = "qoi" version = "0.4.1" @@ -12063,9 +12146,9 @@ dependencies = [ [[package]] name = "redb" -version = "2.1.3" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4760ad04a88ef77075ba86ba9ea79b919e6bab29c1764c5747237cd6eaedcaa" +checksum = "ea0a72cd7140de9fc3e318823b883abf819c20d478ec89ce880466dc2ef263c6" dependencies = [ "libc", ] @@ -13037,8 +13120,8 @@ dependencies = [ [[package]] name = "scarb" -version = "2.8.4" -source = "git+https://github.com/dojoengine/scarb?rev=7eac49b3e61236ce466e712225d9c989f9db1ef3#7eac49b3e61236ce466e712225d9c989f9db1ef3" +version = "2.9.2" +source = "git+https://github.com/dojoengine/scarb?rev=72b5db6b009fda6a83e2740d2a10b529b02d792c#72b5db6b009fda6a83e2740d2a10b529b02d792c" dependencies = [ "anyhow", "async-trait", @@ -13060,16 +13143,19 @@ dependencies = [ "cairo-lang-test-plugin", "cairo-lang-utils", "camino", + "cargo_metadata", "clap", "convert_case 0.6.0", "create-output-dir", + "crossbeam-channel", "data-encoding", "deno_task_shell", "derive_builder", "dialoguer", "directories", - "dojo-lang 1.0.0-rc.2", + "dojo-lang 1.0.9", "dunce", + "flate2", "fs4", "fs_extra", "futures", @@ -13078,7 +13164,7 @@ dependencies = [ "glob", "ignore", "include_dir", - "indoc 2.0.5", + "indoc", "itertools 0.12.1", "libloading", "once_cell", @@ -13088,8 +13174,9 @@ dependencies = [ "redb", "reqwest 0.11.27", "scarb-build-metadata", - "scarb-metadata 1.12.0 (git+https://github.com/dojoengine/scarb?rev=7eac49b3e61236ce466e712225d9c989f9db1ef3)", - "scarb-stable-hash 1.0.0 (git+https://github.com/dojoengine/scarb?rev=7eac49b3e61236ce466e712225d9c989f9db1ef3)", + "scarb-metadata 1.13.0 (git+https://github.com/dojoengine/scarb?rev=72b5db6b009fda6a83e2740d2a10b529b02d792c)", + "scarb-proc-macro-server-types 0.1.0 (git+https://github.com/dojoengine/scarb?rev=72b5db6b009fda6a83e2740d2a10b529b02d792c)", + "scarb-stable-hash 1.0.0 (git+https://github.com/dojoengine/scarb?rev=72b5db6b009fda6a83e2740d2a10b529b02d792c)", "scarb-ui", "semver 1.0.23", "serde", @@ -13101,7 +13188,7 @@ dependencies = [ "smallvec", "smol_str", "tar", - "thiserror 1.0.63", + "thiserror 2.0.11", "tokio", "toml 0.8.19", "toml_edit", @@ -13110,7 +13197,7 @@ dependencies = [ "typed-builder", "url", "walkdir", - "which 5.0.0", + "which 7.0.1", "windows-sys 0.59.0", "zip", "zstd 0.13.2", @@ -13118,17 +13205,17 @@ dependencies = [ [[package]] name = "scarb-build-metadata" -version = "2.8.4" -source = "git+https://github.com/dojoengine/scarb?rev=7eac49b3e61236ce466e712225d9c989f9db1ef3#7eac49b3e61236ce466e712225d9c989f9db1ef3" +version = "2.9.2" +source = "git+https://github.com/dojoengine/scarb?rev=72b5db6b009fda6a83e2740d2a10b529b02d792c#72b5db6b009fda6a83e2740d2a10b529b02d792c" dependencies = [ "cargo_metadata", ] [[package]] name = "scarb-metadata" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "170ebce1774a85568646ba4096827f898306665187eebd9282fee313e316518d" +checksum = "1a8b71f63999dbb6d269fbc6fd61310016ab3a160fb13e52a6511a2b904359f0" dependencies = [ "camino", "semver 1.0.23", @@ -13139,15 +13226,36 @@ dependencies = [ [[package]] name = "scarb-metadata" -version = "1.12.0" -source = "git+https://github.com/dojoengine/scarb?rev=7eac49b3e61236ce466e712225d9c989f9db1ef3#7eac49b3e61236ce466e712225d9c989f9db1ef3" +version = "1.13.0" +source = "git+https://github.com/dojoengine/scarb?rev=72b5db6b009fda6a83e2740d2a10b529b02d792c#72b5db6b009fda6a83e2740d2a10b529b02d792c" dependencies = [ "camino", "derive_builder", "semver 1.0.23", "serde", "serde_json", - "thiserror 1.0.63", + "thiserror 2.0.11", +] + +[[package]] +name = "scarb-proc-macro-server-types" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cb73a7fb2681885d05a1d918f95b179c034fb5d5a57adfbb718f36946fe5ade" +dependencies = [ + "cairo-lang-macro", + "serde", + "serde_json", +] + +[[package]] +name = "scarb-proc-macro-server-types" +version = "0.1.0" +source = "git+https://github.com/dojoengine/scarb?rev=72b5db6b009fda6a83e2740d2a10b529b02d792c#72b5db6b009fda6a83e2740d2a10b529b02d792c" +dependencies = [ + "cairo-lang-macro", + "serde", + "serde_json", ] [[package]] @@ -13163,7 +13271,7 @@ dependencies = [ [[package]] name = "scarb-stable-hash" version = "1.0.0" -source = "git+https://github.com/dojoengine/scarb?rev=7eac49b3e61236ce466e712225d9c989f9db1ef3#7eac49b3e61236ce466e712225d9c989f9db1ef3" +source = "git+https://github.com/dojoengine/scarb?rev=72b5db6b009fda6a83e2740d2a10b529b02d792c#72b5db6b009fda6a83e2740d2a10b529b02d792c" dependencies = [ "data-encoding", "xxhash-rust", @@ -13172,14 +13280,14 @@ dependencies = [ [[package]] name = "scarb-ui" version = "0.1.5" -source = "git+https://github.com/dojoengine/scarb?rev=7eac49b3e61236ce466e712225d9c989f9db1ef3#7eac49b3e61236ce466e712225d9c989f9db1ef3" +source = "git+https://github.com/dojoengine/scarb?rev=72b5db6b009fda6a83e2740d2a10b529b02d792c#72b5db6b009fda6a83e2740d2a10b529b02d792c" dependencies = [ "anyhow", "camino", "clap", "console", "indicatif", - "scarb-metadata 1.12.0 (git+https://github.com/dojoengine/scarb?rev=7eac49b3e61236ce466e712225d9c989f9db1ef3)", + "scarb-metadata 1.13.0 (git+https://github.com/dojoengine/scarb?rev=72b5db6b009fda6a83e2740d2a10b529b02d792c)", "serde", "serde_json", "tracing-core", @@ -13368,9 +13476,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.210" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] @@ -13438,9 +13546,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", @@ -13950,29 +14058,24 @@ dependencies = [ "anyhow", "async-trait", "cainome 0.4.11", - "cairo-lang-compiler", - "cairo-lang-filesystem", - "cairo-lang-project", - "cairo-lang-starknet", + "cairo-lang-sierra", "cairo-lang-test-plugin", "cairo-lang-test-runner", - "cairo-lang-utils", "camino", "clap", "clap-verbosity-flag", "colored", "dojo-bindgen", - "dojo-lang 1.0.11", "dojo-test-utils", "dojo-types 1.0.11", "dojo-utils", "dojo-world", - "itertools 0.12.1", "katana-rpc-api", "katana-runner", "notify", "reqwest 0.11.27", "scarb", + "scarb-metadata 1.13.0 (git+https://github.com/dojoengine/scarb?rev=72b5db6b009fda6a83e2740d2a10b529b02d792c)", "scarb-ui", "semver 1.0.23", "serde", @@ -14082,6 +14185,15 @@ dependencies = [ "lock_api", ] +[[package]] +name = "spinning_top" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96d2d1d716fb500937168cc09353ffdc7a012be8475ac7308e1bdf0e3923300" +dependencies = [ + "lock_api", +] + [[package]] name = "spinoff" version = "0.8.0" @@ -14464,26 +14576,6 @@ dependencies = [ "starknet-types-core", ] -[[package]] -name = "starknet-crypto" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3f2175b0b3fc24ff2ec6dc07f5a720498994effca7e78b11a6e1c1bd02cad52" -dependencies = [ - "crypto-bigint", - "hex", - "hmac", - "num-bigint", - "num-integer", - "num-traits 0.2.19", - "rfc6979", - "sha2 0.10.8", - "starknet-crypto-codegen", - "starknet-curve 0.3.0", - "starknet-ff", - "zeroize", -] - [[package]] name = "starknet-crypto" version = "0.6.2" @@ -14534,15 +14626,6 @@ dependencies = [ "syn 2.0.90", ] -[[package]] -name = "starknet-curve" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "252610baff59e4c4332ce3569f7469c5d3f9b415a2240d698fb238b2b4fc0942" -dependencies = [ - "starknet-ff", -] - [[package]] name = "starknet-curve" version = "0.4.2" @@ -14680,24 +14763,27 @@ dependencies = [ [[package]] name = "starknet_api" -version = "0.13.0-rc.1" -source = "git+https://github.com/dojoengine/sequencer?tag=v0.8.0-rc3.2#d6951f24fc2082c7aa89cdbc063648915b131d74" +version = "0.0.0" +source = "git+https://github.com/dojoengine/sequencer?rev=802c5dc#802c5dc1b3ca231d96b65ffcada349f4b5ab0e3b" dependencies = [ "bitvec", + "cairo-lang-runner", "cairo-lang-starknet-classes", "derive_more 0.99.18", "hex", "indexmap 2.5.0", "itertools 0.12.1", - "once_cell", + "num-bigint", + "pretty_assertions", "primitive-types", + "semver 1.0.23", "serde", "serde_json", "sha3", - "starknet-crypto 0.5.2", + "starknet-crypto 0.7.2", "starknet-types-core", - "strum 0.24.1", - "strum_macros 0.24.3", + "strum 0.25.0", + "strum_macros 0.25.3", "thiserror 1.0.63", ] @@ -14755,12 +14841,6 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" -[[package]] -name = "strum" -version = "0.24.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" - [[package]] name = "strum" version = "0.25.0" @@ -14776,19 +14856,6 @@ dependencies = [ "strum_macros 0.26.4", ] -[[package]] -name = "strum_macros" -version = "0.24.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" -dependencies = [ - "heck 0.4.1", - "proc-macro2", - "quote", - "rustversion", - "syn 1.0.109", -] - [[package]] name = "strum_macros" version = "0.25.3" @@ -15137,11 +15204,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.7" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93605438cbd668185516ab499d589afb7ee1859ea3d5fc8f6b0755e1c7443767" +checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" dependencies = [ - "thiserror-impl 2.0.7", + "thiserror-impl 2.0.11", ] [[package]] @@ -15157,9 +15224,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.7" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d8749b4531af2117677a5fcd12b1348a3fe2b81e36e61ffeac5c4aa3273e36" +checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" dependencies = [ "proc-macro2", "quote", @@ -16066,40 +16133,6 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" -[[package]] -name = "tower-lsp" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4ba052b54a6627628d9b3c34c176e7eda8359b7da9acd497b9f20998d118508" -dependencies = [ - "async-trait", - "auto_impl", - "bytes", - "dashmap 5.5.3", - "futures", - "httparse", - "lsp-types", - "memchr", - "serde", - "serde_json", - "tokio", - "tokio-util", - "tower 0.4.13", - "tower-lsp-macros", - "tracing", -] - -[[package]] -name = "tower-lsp-macros" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84fd902d4e0b9a4b27f2f440108dc034e1758628a9b702f8ec61ad66355422fa" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.90", -] - [[package]] name = "tower-service" version = "0.3.3" @@ -16587,6 +16620,45 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "validator" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d6937c33ec6039d8071bcf72933146b5bbe378d645d8fa59bdadabfc2a249" +dependencies = [ + "idna 0.2.3", + "lazy_static", + "regex", + "serde", + "serde_derive", + "serde_json", + "url", + "validator_derive", + "validator_types", +] + +[[package]] +name = "validator_derive" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4286b4497f270f59276a89ae0ad109d5f8f18c69b613e3fb22b61201aadb0c4d" +dependencies = [ + "if_chain", + "lazy_static", + "proc-macro-error", + "proc-macro2", + "quote", + "regex", + "syn 1.0.109", + "validator_types", +] + +[[package]] +name = "validator_types" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad9680608df133af2c1ddd5eaf1ddce91d60d61b6bc51494ef326458365a470a" + [[package]] name = "valuable" version = "0.1.0" @@ -17224,15 +17296,14 @@ dependencies = [ [[package]] name = "which" -version = "5.0.0" +version = "7.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bf3ea8596f3a0dd5980b46430f2058dfe2c36a27ccfbb1845d6fbfcd9ba6e14" +checksum = "fb4a9e33648339dc1642b0e36e21b3385e6148e289226f657c809dee59df5028" dependencies = [ "either", - "home", - "once_cell", + "env_home", "rustix 0.38.37", - "windows-sys 0.48.0", + "winsafe", ] [[package]] @@ -17626,6 +17697,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "winsafe" +version = "0.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" + [[package]] name = "wyz" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index b65186703a..2dd78e43f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -147,28 +147,28 @@ auto_impl = "1.2.0" base64 = "0.21.2" bigdecimal = "0.4.1" bytes = "1.6" -cairo-lang-compiler = "=2.8.4" -cairo-lang-debug = "=2.8.4" -cairo-lang-defs = "=2.8.4" -cairo-lang-diagnostics = "2.7.0" -cairo-lang-filesystem = "=2.8.4" -cairo-lang-formatter = "=2.8.4" -cairo-lang-language-server = "=2.8.4" -cairo-lang-lowering = "=2.8.4" -cairo-lang-parser = "=2.8.4" -cairo-lang-plugins = { version = "=2.8.4", features = [ "testing" ] } -cairo-lang-project = "=2.8.4" -cairo-lang-semantic = "=2.8.4" -cairo-lang-sierra = "=2.8.4" -cairo-lang-sierra-generator = "=2.8.4" -cairo-lang-sierra-to-casm = "=2.8.4" -cairo-lang-starknet = "=2.8.4" -cairo-lang-starknet-classes = "=2.8.4" -cairo-lang-syntax = "=2.8.4" -cairo-lang-test-plugin = "=2.8.4" -cairo-lang-test-runner = "=2.8.4" -cairo-lang-test-utils = "=2.8.4" -cairo-lang-utils = "=2.8.4" +cairo-lang-compiler = "=2.9.2" +cairo-lang-debug = "=2.9.2" +cairo-lang-defs = "=2.9.2" +cairo-lang-diagnostics = "=2.9.2" +cairo-lang-filesystem = "=2.9.2" +cairo-lang-formatter = "=2.9.2" +cairo-lang-language-server = "=2.9.2" +cairo-lang-lowering = "=2.9.2" +cairo-lang-parser = "=2.9.2" +cairo-lang-plugins = { version = "=2.9.2", features = [ "testing" ] } +cairo-lang-project = "=2.9.2" +cairo-lang-semantic = "=2.9.2" +cairo-lang-sierra = "=2.9.2" +cairo-lang-sierra-generator = "=2.9.2" +cairo-lang-sierra-to-casm = "=2.9.2" +cairo-lang-starknet = "=2.9.2" +cairo-lang-starknet-classes = "=2.9.2" +cairo-lang-syntax = "=2.9.2" +cairo-lang-test-plugin = "=2.9.2" +cairo-lang-test-runner = "=2.9.2" +cairo-lang-test-utils = "=2.9.2" +cairo-lang-utils = "=2.9.2" cairo-vm = "1.0.0-rc4" camino = { version = "1.1.2", features = [ "serde1" ] } chrono = { version = "0.4.24", features = [ "serde" ] } @@ -182,7 +182,7 @@ convert_case = "0.6.0" crypto-bigint = { version = "0.5.3", features = [ "serde" ] } data-url = "0.3" derive_more = "0.99.17" -flate2 = "1.0.24" +flate2 = "1.0.35" fluent-uri = "0.3" futures = "0.3.30" futures-util = "0.3.30" @@ -212,8 +212,9 @@ rpassword = "7.2.0" rstest = "0.18.2" rstest_reuse = "0.6.0" salsa = "0.16.1" -scarb = { git = "https://github.com/dojoengine/scarb", rev = "7eac49b3e61236ce466e712225d9c989f9db1ef3" } -scarb-ui = { git = "https://github.com/dojoengine/scarb", rev = "7eac49b3e61236ce466e712225d9c989f9db1ef3" } +scarb = { git = "https://github.com/dojoengine/scarb", rev = "72b5db6b009fda6a83e2740d2a10b529b02d792c" } +scarb-metadata = { git = "https://github.com/dojoengine/scarb", rev = "72b5db6b009fda6a83e2740d2a10b529b02d792c" } +scarb-ui = { git = "https://github.com/dojoengine/scarb", rev = "72b5db6b009fda6a83e2740d2a10b529b02d792c" } semver = "1.0.5" serde = { version = "1.0", features = [ "derive" ] } serde_json = { version = "1.0", features = [ "arbitrary_precision" ] } @@ -222,7 +223,8 @@ similar-asserts = "1.5.0" smol_str = { version = "0.2.0", features = [ "serde" ] } spinoff = "0.8.0" sqlx = { version = "0.8.2", features = [ "chrono", "macros", "regexp", "runtime-async-std", "runtime-tokio", "sqlite", "uuid" ] } -starknet_api = "0.11.0" +#starknet_api = "0.11.0" +starknet_api = { git = "https://github.com/dojoengine/sequencer", rev = "802c5dc" } strum = "0.25" strum_macros = "0.25" tempfile = "3.9.0" diff --git a/bin/sozo/Cargo.toml b/bin/sozo/Cargo.toml index 6831fbf059..5cbf81b6f9 100644 --- a/bin/sozo/Cargo.toml +++ b/bin/sozo/Cargo.toml @@ -11,27 +11,22 @@ slot = { workspace = true, optional = true } anyhow.workspace = true async-trait.workspace = true cainome.workspace = true -cairo-lang-compiler.workspace = true -cairo-lang-filesystem.workspace = true -cairo-lang-project.workspace = true -cairo-lang-starknet.workspace = true +cairo-lang-sierra.workspace = true cairo-lang-test-plugin.workspace = true cairo-lang-test-runner.workspace = true -cairo-lang-utils.workspace = true camino.workspace = true clap.workspace = true clap-verbosity-flag.workspace = true colored.workspace = true dojo-bindgen.workspace = true -dojo-lang.workspace = true dojo-types.workspace = true dojo-utils.workspace = true dojo-world.workspace = true -itertools.workspace = true katana-rpc-api.workspace = true notify = "7.0.0" tabled = { version = "0.16.0", features = [ "ansi" ] } scarb.workspace = true +scarb-metadata.workspace = true scarb-ui.workspace = true semver.workspace = true serde.workspace = true diff --git a/bin/sozo/benches/spawn-and-move-build.rs b/bin/sozo/benches/spawn-and-move-build.rs index 8fccb7e7e1..4a6bfdeeae 100644 --- a/bin/sozo/benches/spawn-and-move-build.rs +++ b/bin/sozo/benches/spawn-and-move-build.rs @@ -23,6 +23,7 @@ fn build_spawn_and_move() { scarb::ops::compile( packages.iter().map(|p| p.id).collect(), CompileOpts { + ignore_cairo_version: false, include_target_names: vec![], include_target_kinds: vec![], exclude_target_kinds: vec![TargetKind::TEST], diff --git a/bin/sozo/src/commands/build.rs b/bin/sozo/src/commands/build.rs index 4c4688fb86..86956bec7c 100644 --- a/bin/sozo/src/commands/build.rs +++ b/bin/sozo/src/commands/build.rs @@ -103,6 +103,7 @@ impl BuildArgs { include_target_kinds: vec![], exclude_target_kinds: vec![TargetKind::TEST], features: self.features.try_into()?, + ignore_cairo_version: false, }, &ws, )?; diff --git a/bin/sozo/src/commands/test.rs b/bin/sozo/src/commands/test.rs index 772a87df1a..93b21fd27f 100644 --- a/bin/sozo/src/commands/test.rs +++ b/bin/sozo/src/commands/test.rs @@ -1,35 +1,22 @@ -//! Compiles and runs tests for a Dojo project. -//! -//! We can't use scarb to run tests since our injection will not work. -//! Scarb uses other binaries to run tests. Dojo plugin injection is done in scarb itself. -//! When proc macro will be fully supported, we can switch back to scarb. -use anyhow::{bail, Result}; -use cairo_lang_compiler::db::RootDatabase; -use cairo_lang_compiler::diagnostics::DiagnosticsReporter; -use cairo_lang_compiler::project::{ProjectConfig, ProjectConfigContent}; -use cairo_lang_filesystem::cfg::{Cfg, CfgSet}; -use cairo_lang_filesystem::db::{CrateSettings, ExperimentalFeaturesConfig, FilesGroup}; -use cairo_lang_filesystem::ids::{CrateId, CrateLongId, Directory}; -use cairo_lang_project::AllCratesConfig; -use cairo_lang_starknet::starknet_plugin_suite; -use cairo_lang_test_plugin::{test_plugin_suite, TestsCompilationConfig}; -use cairo_lang_test_runner::{CompiledTestRunner, RunProfilerConfig, TestCompiler, TestRunConfig}; -use cairo_lang_utils::ordered_hash_map::OrderedHashMap; +//! Compiles and runs tests for a Dojo project using Scarb. +use std::collections::HashSet; +use std::fs; + +use anyhow::{Context, Result}; +use cairo_lang_sierra::program::VersionedProgram; +use cairo_lang_test_plugin::{TestCompilation, TestCompilationMetadata}; +use cairo_lang_test_runner::{CompiledTestRunner, RunProfilerConfig, TestRunConfig}; +use camino::Utf8PathBuf; use clap::Args; -use dojo_lang::dojo_plugin_suite; -use itertools::Itertools; -use scarb::compiler::{ - CairoCompilationUnit, CompilationUnit, CompilationUnitAttributes, ContractSelector, -}; -use scarb::core::{Config, Package, TargetKind}; +use scarb::compiler::ContractSelector; +use scarb::core::{Config, TargetKind}; use scarb::ops::{self, CompileOpts}; +use scarb_metadata::{Metadata, MetadataCommand, PackageId, PackageMetadata, TargetMetadata}; use scarb_ui::args::{FeaturesSpec, PackagesFilter}; use serde::{Deserialize, Serialize}; -use smol_str::SmolStr; +use sozo_scarbext::WorkspaceExt; use tracing::trace; -pub const WORLD_QUALIFIED_PATH: &str = "dojo::world::world_contract::world"; - use super::check_package_dojo_version; #[derive(Debug, Default, Serialize, Deserialize)] @@ -81,7 +68,7 @@ pub struct TestArgs { features: FeaturesSpec, /// Specify packages to test. #[command(flatten)] - pub packages: Option, + pub packages: PackagesFilter, } impl TestArgs { @@ -92,211 +79,123 @@ impl TestArgs { std::process::exit(1); }); - let packages: Vec = if let Some(filter) = self.packages { - filter.match_many(&ws)?.into_iter().collect() - } else { - ws.members().collect() - }; + // If we don't specify the scarb path, it will use the one in the env variable $SCARB. + let metadata = MetadataCommand::new().manifest_path(config.manifest_path()).exec()?; + let packages = self.packages.match_many(&ws)?; for p in &packages { check_package_dojo_version(&ws, p)?; } - let resolve = ops::resolve_workspace(&ws)?; - - let opts = CompileOpts { - include_target_kinds: vec![TargetKind::TEST], - exclude_target_kinds: vec![], - include_target_names: vec![], - features: self.features.try_into()?, - }; - - let compilation_units = ops::generate_compilation_units(&resolve, &opts.features, &ws)? - .into_iter() - .filter(|cu| { - let is_excluded = - opts.exclude_target_kinds.contains(&cu.main_component().target_kind()); - let is_included = opts.include_target_kinds.is_empty() - || opts.include_target_kinds.contains(&cu.main_component().target_kind()); - let is_included = is_included - && (opts.include_target_names.is_empty() - || cu - .main_component() - .targets - .iter() - .any(|t| opts.include_target_names.contains(&t.name))); + let matched = self.packages.match_many(&metadata)?; - let is_selected = packages.iter().any(|p| p.id == cu.main_package_id()); - - let is_cairo_plugin = matches!(cu, CompilationUnit::ProcMacro(_)); - is_cairo_plugin || (is_included && is_selected && !is_excluded) + let target_names = matched + .iter() + .flat_map(|package| { + find_testable_targets(package).iter().map(|t| t.name.clone()).collect::>() }) .collect::>(); - for unit in compilation_units { - let unit = if let CompilationUnit::Cairo(unit) = unit { - unit - } else { - continue; - }; - - config.ui().print(format!("testing {}", unit.name())); - - let props: Props = unit.main_component().target_props()?; - let db = build_root_database(&unit)?; - - if DiagnosticsReporter::stderr().allow_warnings().check(&db) { - bail!("failed to compile"); + trace!(?target_names, "Extracting testable targets."); + + scarb::ops::compile( + packages.iter().map(|p| p.id).collect(), + CompileOpts { + include_target_kinds: vec![TargetKind::TEST], + exclude_target_kinds: vec![], + include_target_names: vec![], + features: self.features.try_into()?, + ignore_cairo_version: false, + }, + &ws, + )?; + + let target_dir = Utf8PathBuf::from(ws.target_dir_profile().to_string()); + + let mut deduplicator = TargetGroupDeduplicator::default(); + for package in matched { + println!("testing {} ...", package.name); + for target in find_testable_targets(&package) { + if !target_names.contains(&target.name) { + continue; + } + let name = target + .params + .get("group-id") + .and_then(|v| v.as_str()) + .map(ToString::to_string) + .unwrap_or(target.name.clone()); + let already_seen = deduplicator.visit(package.name.clone(), name.clone()); + if already_seen { + continue; + } + let test_compilation = deserialize_test_compilation(&target_dir, name.clone())?; + let config = TestRunConfig { + filter: self.filter.clone(), + include_ignored: self.include_ignored, + ignored: self.ignored, + run_profiler: RunProfilerConfig::None, + gas_enabled: is_gas_enabled(&metadata, &package.id, target), + print_resource_usage: self.print_resource_usage, + }; + let runner = CompiledTestRunner::new(test_compilation, config); + runner.run(None)?; + println!(); } - - let test_crate_ids = collect_main_crate_ids(&unit, &db, false); - - let mut main_crate_ids = collect_all_crate_ids(&unit, &db); - - if let Some(external_contracts) = props.build_external_contracts { - main_crate_ids.extend(collect_crates_ids_from_selectors(&db, &external_contracts)); - } - - let config = TestRunConfig { - filter: self.filter.clone(), - ignored: self.ignored, - include_ignored: self.include_ignored, - run_profiler: self.profiler_mode.clone().into(), - gas_enabled: self.gas_enabled, - print_resource_usage: self.print_resource_usage, - }; - - let compiler = TestCompiler { - db: db.snapshot(), - main_crate_ids, - test_crate_ids, - allow_warnings: true, - config: TestsCompilationConfig { - starknet: true, - add_statements_functions: false, - add_statements_code_locations: false, - }, - }; - - let compiled = compiler.build()?; - let runner = CompiledTestRunner { compiled, config }; - - // Database is required here for the profiler to work. - runner.run(Some(&db))?; - - println!(); } Ok(()) } } -pub(crate) fn build_root_database(unit: &CairoCompilationUnit) -> Result { - let mut b = RootDatabase::builder(); - b.with_project_config(build_project_config(unit)?); - b.with_cfg(CfgSet::from_iter([Cfg::name("test"), Cfg::kv("target", "test")])); - - b.with_plugin_suite(test_plugin_suite()); - b.with_plugin_suite(dojo_plugin_suite()); - b.with_plugin_suite(starknet_plugin_suite()); - - b.build() +fn deserialize_test_compilation(target_dir: &Utf8PathBuf, name: String) -> Result { + let file_path = target_dir.join(format!("{}.test.json", name)); + let test_comp_metadata = serde_json::from_str::( + &fs::read_to_string(file_path.clone()) + .with_context(|| format!("failed to read file: {file_path}"))?, + ) + .with_context(|| format!("failed to deserialize compiled tests metadata file: {file_path}"))?; + + let file_path = target_dir.join(format!("{}.test.sierra.json", name)); + let sierra_program = serde_json::from_str::( + &fs::read_to_string(file_path.clone()) + .with_context(|| format!("failed to read file: {file_path}"))?, + ) + .with_context(|| format!("failed to deserialize compiled tests sierra file: {file_path}"))?; + + Ok(TestCompilation { sierra_program: sierra_program.into_v1()?, metadata: test_comp_metadata }) } -fn build_project_config(unit: &CairoCompilationUnit) -> Result { - let crate_roots = unit - .components - .iter() - .filter(|c| !c.package.id.is_core()) - // NOTE: We're taking the first target of each compilation unit, which should always be the - // main package source root due to the order maintained by scarb. - .map(|c| { - ( - c.cairo_package_name(), - c.first_target().source_root().into(), - ) - }) - .collect(); - - let corelib = - unit.core_package_component().map(|c| Directory::Real(c.targets[0].source_root().into())); - - let crates_config = crates_config_for_compilation_unit(unit); - - let content = ProjectConfigContent { crate_roots, crates_config }; - - let project_config = - ProjectConfig { base_path: unit.main_component().package.root().into(), corelib, content }; - - trace!(?project_config, "Project config built."); - - Ok(project_config) +#[derive(Default)] +struct TargetGroupDeduplicator { + seen: HashSet<(String, String)>, } -/// Collects the main crate ids for Dojo including the core crates. -pub fn collect_main_crate_ids( - unit: &CairoCompilationUnit, - db: &RootDatabase, - with_dojo_core: bool, -) -> Vec { - let mut main_crate_ids = scarb::compiler::helpers::collect_main_crate_ids(unit, db); - - if unit.main_package_id.name.to_string() != "dojo" && with_dojo_core { - let core_crate_ids: Vec = collect_crates_ids_from_selectors( - db, - &[ContractSelector(WORLD_QUALIFIED_PATH.to_string())], - ); - - main_crate_ids.extend(core_crate_ids); +impl TargetGroupDeduplicator { + /// Returns true if already visited. + pub fn visit(&mut self, package_name: String, group_name: String) -> bool { + !self.seen.insert((package_name, group_name)) } - - main_crate_ids -} - -/// Collects the crate ids containing the given contract selectors. -pub fn collect_crates_ids_from_selectors( - db: &RootDatabase, - contract_selectors: &[ContractSelector], -) -> Vec { - contract_selectors - .iter() - .map(|selector| selector.package().into()) - .unique() - .map(|package_name: SmolStr| db.intern_crate(CrateLongId::Real(package_name))) - .collect::>() } -pub fn collect_all_crate_ids(unit: &CairoCompilationUnit, db: &RootDatabase) -> Vec { - unit.components - .iter() - .map(|component| db.intern_crate(CrateLongId::Real(component.cairo_package_name()))) - .collect() +/// Defines if gas is enabled for a given test target. +fn is_gas_enabled(metadata: &Metadata, package_id: &PackageId, target: &TargetMetadata) -> bool { + metadata + .compilation_units + .iter() + .find(|cu| { + cu.package == *package_id && cu.target.kind == "test" && cu.target.name == target.name + }) + .map(|cu| cu.compiler_config.clone()) + .and_then(|c| { + c.as_object() + .and_then(|c| c.get("enable_gas").and_then(|x| x.as_bool())) + }) + // Defaults to true, meaning gas enabled - relies on cli config then. + .unwrap_or(true) } -pub fn crates_config_for_compilation_unit(unit: &CairoCompilationUnit) -> AllCratesConfig { - let crates_config: OrderedHashMap = unit - .components() - .iter() - .map(|component| { - // Ensure experimental features are only enable if required. - let experimental_features = component.package.manifest.experimental_features.clone(); - let experimental_features = experimental_features.unwrap_or_default(); - - ( - component.cairo_package_name(), - CrateSettings { - version: Some(component.package.id.version.clone()), - edition: component.package.manifest.edition, - experimental_features: ExperimentalFeaturesConfig { - negative_impls: experimental_features - .contains(&SmolStr::new_inline("negative_impls")), - coupons: experimental_features.contains(&SmolStr::new_inline("coupons")), - }, - cfg_set: component.cfg_set.clone(), - }, - ) - }) - .collect(); - - AllCratesConfig { override_map: crates_config, ..Default::default() } +/// Finds all testable targets in a package. +fn find_testable_targets(package: &PackageMetadata) -> Vec<&TargetMetadata> { + package.targets.iter().filter(|target| target.kind == "test").collect() } diff --git a/bin/sozo/tests/test_data/invalid_cairo_version/Scarb.lock b/bin/sozo/tests/test_data/invalid_cairo_version/Scarb.lock new file mode 100644 index 0000000000..b430fc3d8d --- /dev/null +++ b/bin/sozo/tests/test_data/invalid_cairo_version/Scarb.lock @@ -0,0 +1,6 @@ +# Code generated by scarb DO NOT EDIT. +version = 1 + +[[package]] +name = "sozo_test" +version = "0.3.1-rc7" diff --git a/crates/benches/contracts/Scarb.lock b/crates/benches/contracts/Scarb.lock index 944857b5b8..88aeef7864 100644 --- a/crates/benches/contracts/Scarb.lock +++ b/crates/benches/contracts/Scarb.lock @@ -18,5 +18,5 @@ dependencies = [ [[package]] name = "dojo_plugin" -version = "2.8.4" +version = "2.9.1" source = "git+https://github.com/dojoengine/dojo?tag=v1.0.0-rc.0#f4199aec570a395278b8c8748bc46e2f6be3d0c7" diff --git a/crates/benches/contracts/Scarb.toml b/crates/benches/contracts/Scarb.toml index 240685d344..0aebfff1e8 100644 --- a/crates/benches/contracts/Scarb.toml +++ b/crates/benches/contracts/Scarb.toml @@ -1,5 +1,5 @@ [package] -cairo-version = "=2.8.4" +cairo-version = "=2.9.1" name = "benches" version = "1.0.0-rc.0" @@ -8,4 +8,4 @@ build-external-contracts = ["dojo::world::world_contract::world"] [dependencies] dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-rc.0" } -starknet = "=2.8.4" +starknet = "=2.9.1" diff --git a/crates/benches/contracts/src/models/character.cairo b/crates/benches/contracts/src/models/character.cairo index c1ace9b9eb..3d1b6806ab 100644 --- a/crates/benches/contracts/src/models/character.cairo +++ b/crates/benches/contracts/src/models/character.cairo @@ -39,7 +39,7 @@ struct Stats { #[derive(Introspect, Copy, Drop, Serde)] enum Weapon { DualWield: (Sword, Sword), - Fists: (Sword, Sword), // Introspect requires same arms + Fists: (Sword, Sword), } #[derive(Introspect, Copy, Drop, Serde)] diff --git a/crates/dojo/core-cairo-test/Cargo.toml b/crates/dojo/core-cairo-test/Cargo.toml new file mode 100644 index 0000000000..d023baba55 --- /dev/null +++ b/crates/dojo/core-cairo-test/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "dojo-cairo-test" +edition.workspace = true +license.workspace = true +repository.workspace = true +version.workspace = true + +[package.metadata.release] +pre-release-replacements = [ + { file = "Scarb.lock", search = "^name = \"dojo\"\nversion = \".*\"$", replace = "name = \"dojo\"\nversion = \"{{version}}\"", min = 1 }, + { file = "Scarb.toml", search = "^version = \".*\"$", replace = "version = \"{{version}}\"", min = 1 }, +] + +[lib] +path = "src/lib.rs" diff --git a/crates/dojo/core-cairo-test/Scarb.lock b/crates/dojo/core-cairo-test/Scarb.lock index 8c428deae3..fb9b01725f 100644 --- a/crates/dojo/core-cairo-test/Scarb.lock +++ b/crates/dojo/core-cairo-test/Scarb.lock @@ -3,18 +3,18 @@ version = 1 [[package]] name = "dojo" -version = "1.0.10" +version = "1.0.11" dependencies = [ "dojo_plugin", ] [[package]] name = "dojo_cairo_test" -version = "1.0.0-rc.0" +version = "1.0.11" dependencies = [ "dojo", ] [[package]] name = "dojo_plugin" -version = "2.8.4" +version = "2.9.2" diff --git a/crates/dojo/core-cairo-test/Scarb.toml b/crates/dojo/core-cairo-test/Scarb.toml index b7e2111a73..92f19ee997 100644 --- a/crates/dojo/core-cairo-test/Scarb.toml +++ b/crates/dojo/core-cairo-test/Scarb.toml @@ -1,15 +1,18 @@ [package] -cairo-version = "=2.8.4" +cairo-version = "=2.9.2" edition = "2024_07" description = "Testing library for Dojo using Cairo test runner." name = "dojo_cairo_test" -version = "1.0.0-rc.0" +version = "1.0.11" + +[[target.starknet-contract]] +build-external-contracts = [ "dojo::world::world_contract::world" ] [dependencies] -starknet = "=2.8.4" +starknet = "=2.9.2" dojo = { path = "../core" } [dev-dependencies] -cairo_test = "=2.8.4" +cairo_test = "=2.9.2" [lib] diff --git a/crates/dojo/core-cairo-test/src/lib.cairo b/crates/dojo/core-cairo-test/src/lib.cairo index 7517f85da7..27259486a3 100644 --- a/crates/dojo/core-cairo-test/src/lib.cairo +++ b/crates/dojo/core-cairo-test/src/lib.cairo @@ -47,12 +47,12 @@ mod tests { test_contract, test_contract_with_dojo_init_args, Sword, Case, Character, Abilities, Stats, Weapon, Ibar, IbarDispatcher, IbarDispatcherTrait, bar, deploy_world, deploy_world_and_bar, deploy_world_and_foo, drop_all_events, IFooSetter, - IFooSetterDispatcher, IFooSetterDispatcherTrait, NotCopiable + IFooSetterDispatcher, IFooSetterDispatcherTrait, NotCopiable, }; mod event; pub use event::{ - FooEventBadLayoutType, e_FooEventBadLayoutType, deploy_world_for_event_upgrades + FooEventBadLayoutType, e_FooEventBadLayoutType, deploy_world_for_event_upgrades, }; mod model; diff --git a/crates/dojo/core-cairo-test/src/tests/benchmarks.cairo b/crates/dojo/core-cairo-test/src/tests/benchmarks.cairo index e76b91b479..3f694f47eb 100644 --- a/crates/dojo/core-cairo-test/src/tests/benchmarks.cairo +++ b/crates/dojo/core-cairo-test/src/tests/benchmarks.cairo @@ -6,7 +6,7 @@ use core::serde::Serde; use starknet::{ContractAddress, SyscallResultTrait}; use starknet::storage_access::{ storage_base_address_from_felt252, storage_address_from_base, - storage_address_from_base_and_offset + storage_address_from_base_and_offset, }; use starknet::syscalls::{storage_read_syscall, storage_write_syscall}; @@ -44,11 +44,13 @@ struct ComplexModel { fn deploy_world() -> IWorldDispatcher { let namespace_def = NamespaceDef { - namespace: "dojo", resources: [ + namespace: "dojo", + resources: [ TestResource::Model(case::TEST_CLASS_HASH.try_into().unwrap()), TestResource::Model(case_not_packed::TEST_CLASS_HASH.try_into().unwrap()), TestResource::Model(complex_model::TEST_CLASS_HASH.try_into().unwrap()), - ].span(), + ] + .span(), }; spawn_test_world([namespace_def].span()) @@ -184,7 +186,7 @@ fn bench_simple_struct() { let caller = starknet::contract_address_const::<0x42>(); let gas = GasCounterTrait::start(); - let mut foo = Foo { caller, a: 0x123456789abcdef, b: 0x123456789abcdef, }; + let mut foo = Foo { caller, a: 0x123456789abcdef, b: 0x123456789abcdef }; gas.end("foo init"); let gas = GasCounterTrait::start(); @@ -285,7 +287,7 @@ fn bench_nested_struct_packed() { let gas = GasCounterTrait::start(); let mut case = Case { - owner: caller, sword: Sword { swordsmith: caller, damage: 0x12345678, }, material: 'wooden', + owner: caller, sword: Sword { swordsmith: caller, damage: 0x12345678 }, material: 'wooden', }; gas.end("case init"); @@ -360,8 +362,8 @@ fn bench_complex_struct_packed() { }, Sword { swordsmith: starknet::contract_address_const::<0x69>(), damage: 0x12345678, - } - ) + }, + ), ), gold: 0x12345678, }; @@ -412,11 +414,11 @@ fn test_benchmark_set_entity() { let bob = starknet::contract_address_const::<0xb0b>(); let simple_entity_packed = Case { - owner: bob, sword: Sword { swordsmith: bob, damage: 42, }, material: 'iron' + owner: bob, sword: Sword { swordsmith: bob, damage: 42 }, material: 'iron', }; let simple_entity_not_packed = CaseNotPacked { - owner: bob, sword: Sword { swordsmith: bob, damage: 42, }, material: 'iron' + owner: bob, sword: Sword { swordsmith: bob, damage: 42 }, material: 'iron', }; let complex_entity = ComplexModel { @@ -426,11 +428,11 @@ fn test_benchmark_set_entity() { last_name: "Doe", weapons: array![ Weapon::DualWield( - (Sword { swordsmith: bob, damage: 42 }, Sword { swordsmith: bob, damage: 800 }) + (Sword { swordsmith: bob, damage: 42 }, Sword { swordsmith: bob, damage: 800 }), ), Weapon::Fists( - (Sword { swordsmith: bob, damage: 300 }, Sword { swordsmith: bob, damage: 1200 }) - ) + (Sword { swordsmith: bob, damage: 300 }, Sword { swordsmith: bob, damage: 1200 }), + ), ], abilities: ( Abilities { @@ -448,7 +450,7 @@ fn test_benchmark_set_entity() { intelligence: 2, wisdom: 1, charisma: 43, - } + }, ), stats: Stats { kills: 99, @@ -459,7 +461,7 @@ fn test_benchmark_set_entity() { walked: 12, runned: 32, finished: true, - romances: 65 + romances: 65, }, }; @@ -469,7 +471,7 @@ fn test_benchmark_set_entity() { model_selector: Model::::selector(DOJO_NSH), index: ModelIndex::Keys(simple_entity_packed.serialized_keys()), values: simple_entity_packed.serialized_values(), - layout: Model::::layout() + layout: Model::::layout(), ); gas.end("World::SetEntity::SimplePacked"); @@ -479,7 +481,7 @@ fn test_benchmark_set_entity() { model_selector: Model::::selector(), index: ModelIndex::Keys(simple_entity_not_packed.serialized_keys()), values: simple_entity_not_packed.serialized_values(), - layout: Model::::layout() + layout: Model::::layout(), ); gas.end("World::SetEntity::SimpleNotPacked"); @@ -489,7 +491,7 @@ fn test_benchmark_set_entity() { model_selector: Model::::selector(), index: ModelIndex::Keys(complex_entity.keys()), values: complex_entity.serialized_values(), - layout: Model::::layout() + layout: Model::::layout(), ); gas.end("World::SetEntity::ComplexModel"); diff --git a/crates/dojo/core-cairo-test/src/tests/contract.cairo b/crates/dojo/core-cairo-test/src/tests/contract.cairo index 1fc1539eb1..a568c739fe 100644 --- a/crates/dojo/core-cairo-test/src/tests/contract.cairo +++ b/crates/dojo/core-cairo-test/src/tests/contract.cairo @@ -87,7 +87,7 @@ fn test_upgrade_from_world() { #[test] #[available_gas(7000000)] -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND', 'ENTRYPOINT_FAILED'))] +#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))] fn test_upgrade_from_world_not_world_provider() { let world = deploy_world(); let world = world.dispatcher; @@ -177,7 +177,7 @@ mod invalid_model_world { expected: ( "Namespace `` is invalid according to Dojo naming rules: ^[a-zA-Z0-9_]+$", 'ENTRYPOINT_FAILED', - ) + ), )] fn test_register_namespace_empty_name() { let world = deploy_world(); diff --git a/crates/dojo/core-cairo-test/src/tests/event/event.cairo b/crates/dojo/core-cairo-test/src/tests/event/event.cairo index 2753abdcc8..5558795b78 100644 --- a/crates/dojo/core-cairo-test/src/tests/event/event.cairo +++ b/crates/dojo/core-cairo-test/src/tests/event/event.cairo @@ -6,7 +6,7 @@ struct FooEvent { #[key] k2: felt252, v1: u128, - v2: u32 + v2: u32, } #[test] diff --git a/crates/dojo/core-cairo-test/src/tests/helpers/event.cairo b/crates/dojo/core-cairo-test/src/tests/helpers/event.cairo index 4b41eaf263..bb6b9f28f8 100644 --- a/crates/dojo/core-cairo-test/src/tests/helpers/event.cairo +++ b/crates/dojo/core-cairo-test/src/tests/helpers/event.cairo @@ -65,15 +65,17 @@ struct FooEventMemberAdded { pub fn deploy_world_for_event_upgrades() -> IWorldDispatcher { let namespace_def = NamespaceDef { - namespace: "dojo", resources: [ + namespace: "dojo", + resources: [ TestResource::Event(old_foo_event_bad_layout_type::TEST_CLASS_HASH.try_into().unwrap()), TestResource::Event(e_FooEventMemberRemoved::TEST_CLASS_HASH.try_into().unwrap()), TestResource::Event( - e_FooEventMemberAddedButRemoved::TEST_CLASS_HASH.try_into().unwrap() + e_FooEventMemberAddedButRemoved::TEST_CLASS_HASH.try_into().unwrap(), ), TestResource::Event(e_FooEventMemberAddedButMoved::TEST_CLASS_HASH.try_into().unwrap()), TestResource::Event(e_FooEventMemberAdded::TEST_CLASS_HASH.try_into().unwrap()), - ].span() + ] + .span(), }; spawn_test_world([namespace_def].span()).dispatcher } diff --git a/crates/dojo/core-cairo-test/src/tests/helpers/helpers.cairo b/crates/dojo/core-cairo-test/src/tests/helpers/helpers.cairo index f0e859ec86..5212b01fb5 100644 --- a/crates/dojo/core-cairo-test/src/tests/helpers/helpers.cairo +++ b/crates/dojo/core-cairo-test/src/tests/helpers/helpers.cairo @@ -4,7 +4,7 @@ use dojo::world::{IWorldDispatcher, WorldStorage, WorldStorageTrait}; use dojo::model::Model; use crate::world::{ - spawn_test_world, NamespaceDef, TestResource, ContractDefTrait, WorldStorageTestTrait + spawn_test_world, NamespaceDef, TestResource, ContractDefTrait, WorldStorageTestTrait, }; pub const DOJO_NSH: felt252 = 0x309e09669bc1fdc1dd6563a7ef862aa6227c97d099d08cc7b81bad58a7443fa; @@ -164,7 +164,7 @@ pub struct Stats { #[derive(IntrospectPacked, Copy, Drop, Serde)] pub enum Weapon { DualWield: (Sword, Sword), - Fists: (Sword, Sword), // Introspect requires same arms + Fists: (Sword, Sword), } #[starknet::interface] @@ -196,7 +196,7 @@ pub mod bar { fn delete_foo(self: @ContractState) { let mut world = self.world(@"dojo"); let ptr = ModelPtr::< - Foo + Foo, > { id: core::poseidon::poseidon_hash_span([get_caller_address().into()].span()) }; world.erase_model_ptr(ptr); } @@ -205,7 +205,7 @@ pub mod bar { /// Deploys an empty world with the `dojo` namespace. pub fn deploy_world() -> WorldStorage { - let namespace_def = NamespaceDef { namespace: "dojo", resources: [].span(), }; + let namespace_def = NamespaceDef { namespace: "dojo", resources: [].span() }; spawn_test_world([namespace_def].span()) } @@ -214,10 +214,12 @@ pub fn deploy_world() -> WorldStorage { /// No permissions are granted. pub fn deploy_world_and_foo() -> (WorldStorage, felt252) { let namespace_def = NamespaceDef { - namespace: "dojo", resources: [ + namespace: "dojo", + resources: [ TestResource::Model(m_Foo::TEST_CLASS_HASH), TestResource::Model(m_NotCopiable::TEST_CLASS_HASH), - ].span(), + ] + .span(), }; (spawn_test_world([namespace_def].span()), Model::::selector(DOJO_NSH)) @@ -227,10 +229,12 @@ pub fn deploy_world_and_foo() -> (WorldStorage, felt252) { /// Grants the `bar` contract writer permissions to the `foo` model. pub fn deploy_world_and_bar() -> (WorldStorage, IbarDispatcher) { let namespace_def = NamespaceDef { - namespace: "dojo", resources: [ + namespace: "dojo", + resources: [ TestResource::Model(m_Foo::TEST_CLASS_HASH), TestResource::Contract(bar::TEST_CLASS_HASH), - ].span(), + ] + .span(), }; let bar_def = ContractDefTrait::new(@"dojo", @"bar") diff --git a/crates/dojo/core-cairo-test/src/tests/helpers/model.cairo b/crates/dojo/core-cairo-test/src/tests/helpers/model.cairo index 238f3e4fe0..f097358455 100644 --- a/crates/dojo/core-cairo-test/src/tests/helpers/model.cairo +++ b/crates/dojo/core-cairo-test/src/tests/helpers/model.cairo @@ -57,15 +57,17 @@ struct FooModelMemberAdded { pub fn deploy_world_for_model_upgrades() -> IWorldDispatcher { let namespace_def = NamespaceDef { - namespace: "dojo", resources: [ + namespace: "dojo", + resources: [ TestResource::Model(m_FooModelBadLayoutType::TEST_CLASS_HASH.try_into().unwrap()), TestResource::Model(m_FooModelMemberRemoved::TEST_CLASS_HASH.try_into().unwrap()), TestResource::Model( - m_FooModelMemberAddedButRemoved::TEST_CLASS_HASH.try_into().unwrap() + m_FooModelMemberAddedButRemoved::TEST_CLASS_HASH.try_into().unwrap(), ), TestResource::Model(m_FooModelMemberAddedButMoved::TEST_CLASS_HASH.try_into().unwrap()), TestResource::Model(m_FooModelMemberAdded::TEST_CLASS_HASH.try_into().unwrap()), - ].span() + ] + .span(), }; spawn_test_world([namespace_def].span()).dispatcher } diff --git a/crates/dojo/core-cairo-test/src/tests/meta/introspect.cairo b/crates/dojo/core-cairo-test/src/tests/meta/introspect.cairo index bfa89e3023..996111d135 100644 --- a/crates/dojo/core-cairo-test/src/tests/meta/introspect.cairo +++ b/crates/dojo/core-cairo-test/src/tests/meta/introspect.cairo @@ -9,70 +9,70 @@ struct Base { #[derive(Drop, Introspect)] struct WithArray { value: u32, - arr: Array + arr: Array, } #[derive(Drop, Introspect)] struct WithByteArray { value: u32, - arr: ByteArray + arr: ByteArray, } #[derive(Drop, Introspect)] struct WithTuple { value: u32, - arr: (u8, u16, u32) + arr: (u8, u16, u32), } #[derive(Drop, Introspect)] struct WithNestedTuple { value: u32, - arr: (u8, (u16, u128, u256), u32) + arr: (u8, (u16, u128, u256), u32), } #[derive(Drop, Introspect)] struct WithNestedArrayInTuple { value: u32, - arr: (u8, (u16, Array, u256), u32) + arr: (u8, (u16, Array, u256), u32), } #[derive(Drop, IntrospectPacked)] struct Vec3 { x: u32, y: u32, - z: u32 + z: u32, } #[derive(IntrospectPacked)] struct Translation { from: Vec3, - to: Vec3 + to: Vec3, } #[derive(Drop, IntrospectPacked)] struct StructInnerNotPacked { - x: Base + x: Base, } #[derive(Drop, Introspect)] enum EnumNoData { One, Two, - Three + Three, } #[derive(Drop, Introspect)] enum EnumWithSameData { One: u256, Two: u256, - Three: u256 + Three: u256, } #[derive(Drop, Introspect)] enum EnumWithSameTupleData { One: (u256, u32), Two: (u256, u32), - Three: (u256, u32) + Three: (u256, u32), } #[derive(Drop, Introspect)] @@ -103,7 +103,7 @@ enum EnumInnerNotPacked { #[derive(Drop, Introspect)] struct StructWithOption { - x: Option + x: Option, } #[derive(Drop, Introspect)] @@ -135,7 +135,7 @@ fn _enum(values: Array>) -> Layout { let v = *values.at(i); match v { Option::Some(v) => { items.append(field(i.into(), v)); }, - Option::None => { items.append(field(i.into(), fixed(array![]))) } + Option::None => { items.append(field(i.into(), fixed(array![]))) }, } i += 1; @@ -230,8 +230,8 @@ fn test_layout_of_enum_without_variant_data() { let layout = Introspect::::layout(); let expected = _enum(array![ // One Option::None, // Two - Option::None, // Three - Option::None,]); + Option::None, // Three + Option::None]); assert!(layout == expected); } @@ -247,7 +247,7 @@ fn test_layout_of_enum_with_variant_data() { Option::Some(tuple(array![fixed(array![8]), fixed(array![16])])), // Three Option::Some(arr(fixed(array![128]))), - ] + ], ); assert!(layout == expected); @@ -258,7 +258,7 @@ fn test_layout_of_struct_with_option() { let layout = Introspect::::layout(); let expected = Layout::Struct( array![field(selector!("x"), _enum(array![Option::Some(fixed(array![16])), Option::None]))] - .span() + .span(), ); assert!(layout == expected); diff --git a/crates/dojo/core-cairo-test/src/tests/model/model.cairo b/crates/dojo/core-cairo-test/src/tests/model/model.cairo index ff48b33192..778d9dbe9d 100644 --- a/crates/dojo/core-cairo-test/src/tests/model/model.cairo +++ b/crates/dojo/core-cairo-test/src/tests/model/model.cairo @@ -10,7 +10,7 @@ struct Foo { #[key] k2: felt252, v1: u128, - v2: u32 + v2: u32, } @@ -22,15 +22,17 @@ struct Foo2 { #[key] k2: felt252, v1: u128, - v2: u32 + v2: u32, } fn namespace_def() -> NamespaceDef { NamespaceDef { - namespace: "dojo_cairo_test", resources: [ + namespace: "dojo_cairo_test", + resources: [ TestResource::Model(m_Foo::TEST_CLASS_HASH.try_into().unwrap()), TestResource::Model(m_Foo2::TEST_CLASS_HASH.try_into().unwrap()), - ].span() + ] + .span(), } } diff --git a/crates/dojo/core-cairo-test/src/tests/storage/packing.cairo b/crates/dojo/core-cairo-test/src/tests/storage/packing.cairo index 1d2d32c315..ab378d91e2 100644 --- a/crates/dojo/core-cairo-test/src/tests/storage/packing.cairo +++ b/crates/dojo/core-cairo-test/src/tests/storage/packing.cairo @@ -3,7 +3,7 @@ use core::option::OptionTrait; use core::traits::{Into, TryInto}; use dojo::storage::packing::{ - shl, shr, fpow, pack, unpack, pack_inner, unpack_inner, calculate_packed_size, pow2_const + shl, shr, fpow, pack, unpack, pack_inner, unpack_inner, calculate_packed_size, pow2_const, }; #[test] @@ -11,9 +11,9 @@ use dojo::storage::packing::{ fn test_bit_fpow() { assert( fpow( - 2, 250 + 2, 250, ) == 1809251394333065553493296640760748560207343510400633813116524750123642650624_u256, - '' + '', ) } @@ -22,9 +22,9 @@ fn test_bit_fpow() { fn test_bit_pow2_const() { assert( pow2_const( - 250 + 250, ) == 1809251394333065553493296640760748560207343510400633813116524750123642650624_u256, - '' + '', ) } @@ -75,10 +75,11 @@ fn test_pack_unpack_felt252_u128() { assert( unpack_inner(128, ref packed_span, ref unpacking, ref un_offset).unwrap() == 1337, - 'Types u8' + 'Types u8', ); assert( - unpack_inner(252, ref packed_span, ref unpacking, ref un_offset).unwrap() == 420, 'Types u8' + unpack_inner(252, ref packed_span, ref unpacking, ref un_offset).unwrap() == 420, + 'Types u8', ); } @@ -100,10 +101,10 @@ fn test_pack_multiple() { packed.append(packing); assert( - *packed.at(0) == 0x6000000050000000400000003000000020000000100000000, 'Packed multiple 0' + *packed.at(0) == 0x6000000050000000400000003000000020000000100000000, 'Packed multiple 0', ); assert( - *packed.at(1) == 0xd0000000c0000000b0000000a000000090000000800000007, 'Packed multiple 1' + *packed.at(1) == 0xd0000000c0000000b0000000a000000090000000800000007, 'Packed multiple 1', ); assert(*packed.at(2) == 0x130000001200000011000000100000000f0000000e, 'Packed multiple 2'); } @@ -182,57 +183,57 @@ fn test_pack_unpack_types() { .unwrap() .try_into() .unwrap() == 3_u8, - 'Types u8' + 'Types u8', ); assert( unpack_inner(16, ref packed_span, ref unpacking, ref un_offset) .unwrap() .try_into() .unwrap() == 14_u16, - 'Types u16' + 'Types u16', ); assert( unpack_inner(32, ref packed_span, ref unpacking, ref un_offset) .unwrap() .try_into() .unwrap() == 59_u32, - 'Types u32' + 'Types u32', ); assert( unpack_inner(64, ref packed_span, ref unpacking, ref un_offset) .unwrap() .try_into() .unwrap() == 26_u64, - 'Types u64' + 'Types u64', ); assert( unpack_inner(128, ref packed_span, ref unpacking, ref un_offset) .unwrap() .try_into() .unwrap() == 53_u128, - 'Types u128' + 'Types u128', ); assert( unpack_inner(251, ref packed_span, ref unpacking, ref un_offset).unwrap() == 58_felt252, - 'Types felt252' + 'Types felt252', ); assert( unpack_inner(1, ref packed_span, ref unpacking, ref un_offset).unwrap() == false.into(), - 'Types bool' + 'Types bool', ); assert( unpack_inner(251, ref packed_span, ref unpacking, ref un_offset) .unwrap() .try_into() .unwrap() == contract_address, - 'Types ContractAddress' + 'Types ContractAddress', ); assert( unpack_inner(251, ref packed_span, ref unpacking, ref un_offset) .unwrap() .try_into() .unwrap() == class_hash, - 'Types ClassHash' + 'Types ClassHash', ); } @@ -258,7 +259,7 @@ fn test_inner_pack_unpack_u256_single() { let high = unpack_inner(128, ref packed_span, ref unpacking, ref un_offset).unwrap(); assert( u256 { low: low.try_into().unwrap(), high: high.try_into().unwrap() } == input, - 'Unpacked equals packed' + 'Unpacked equals packed', ); } diff --git a/crates/dojo/core-cairo-test/src/tests/utils/hash.cairo b/crates/dojo/core-cairo-test/src/tests/utils/hash.cairo index 362cd65035..d218667c2a 100644 --- a/crates/dojo/core-cairo-test/src/tests/utils/hash.cairo +++ b/crates/dojo/core-cairo-test/src/tests/utils/hash.cairo @@ -8,7 +8,7 @@ use crate::tests::helpers::DOJO_NSH; struct MyModel { #[key] x: u8, - y: u8 + y: u8, } #[test] diff --git a/crates/dojo/core-cairo-test/src/tests/utils/key.cairo b/crates/dojo/core-cairo-test/src/tests/utils/key.cairo index facd0a84c9..549bcffcc1 100644 --- a/crates/dojo/core-cairo-test/src/tests/utils/key.cairo +++ b/crates/dojo/core-cairo-test/src/tests/utils/key.cairo @@ -5,13 +5,13 @@ fn test_entity_id_from_keys() { let keys = [1, 2, 3].span(); assert( entity_id_from_serialized_keys(keys) == core::poseidon::poseidon_hash_span(keys), - 'bad entity ID' + 'bad entity ID', ); } #[test] fn test_combine_key() { assert( - combine_key(1, 2) == core::poseidon::poseidon_hash_span([1, 2].span()), 'combine key error' + combine_key(1, 2) == core::poseidon::poseidon_hash_span([1, 2].span()), 'combine key error', ); } diff --git a/crates/dojo/core-cairo-test/src/tests/utils/layout.cairo b/crates/dojo/core-cairo-test/src/tests/utils/layout.cairo index 93ee8c4a4e..9eeae83e68 100644 --- a/crates/dojo/core-cairo-test/src/tests/utils/layout.cairo +++ b/crates/dojo/core-cairo-test/src/tests/utils/layout.cairo @@ -7,7 +7,8 @@ fn test_find_layout_when_exists() { FieldLayout { selector: 'one', layout: Layout::Fixed([1].span()) }, FieldLayout { selector: 'two', layout: Layout::Fixed([2].span()) }, FieldLayout { selector: 'three', layout: Layout::Fixed([3].span()) }, - ].span(); + ] + .span(); let res = find_field_layout('two', layouts); assert(res.is_some(), 'layout not found'); @@ -21,7 +22,8 @@ fn test_find_layout_fails_when_not_exists() { FieldLayout { selector: 'one', layout: Layout::Fixed([1].span()) }, FieldLayout { selector: 'two', layout: Layout::Fixed([2].span()) }, FieldLayout { selector: 'three', layout: Layout::Fixed([3].span()) }, - ].span(); + ] + .span(); let res = find_field_layout('four', layouts); assert(res.is_none(), 'layout found'); @@ -34,7 +36,8 @@ fn test_find_model_layout_when_exists() { FieldLayout { selector: 'one', layout: Layout::Fixed([1].span()) }, FieldLayout { selector: 'two', layout: Layout::Fixed([2].span()) }, FieldLayout { selector: 'three', layout: Layout::Fixed([3].span()) }, - ].span() + ] + .span(), ); let res = find_model_field_layout(model_layout, 'two'); @@ -50,7 +53,8 @@ fn test_find_model_layout_fails_when_not_exists() { FieldLayout { selector: 'one', layout: Layout::Fixed([1].span()) }, FieldLayout { selector: 'two', layout: Layout::Fixed([2].span()) }, FieldLayout { selector: 'three', layout: Layout::Fixed([3].span()) }, - ].span() + ] + .span(), ); let res = find_model_field_layout(model_layout, 'four'); diff --git a/crates/dojo/core-cairo-test/src/tests/utils/misc.cairo b/crates/dojo/core-cairo-test/src/tests/utils/misc.cairo index 60973d4d58..ff7339f9dd 100644 --- a/crates/dojo/core-cairo-test/src/tests/utils/misc.cairo +++ b/crates/dojo/core-cairo-test/src/tests/utils/misc.cairo @@ -4,7 +4,7 @@ use dojo::utils::{any_none, sum}; fn test_any_none_when_one_none() { assert( any_none(@array![Option::Some(1_u8), Option::Some(2_u8), Option::None, Option::Some(3_u8)]), - 'None not found' + 'None not found', ) } @@ -12,7 +12,7 @@ fn test_any_none_when_one_none() { fn test_any_none_when_no_none() { assert( any_none(@array![Option::Some(1_u8), Option::Some(2_u8), Option::Some(3_u8)]) == false, - 'None found' + 'None found', ) } @@ -25,6 +25,6 @@ fn test_sum_when_empty_array() { fn test_sum_when_some_none_and_values() { assert( sum::(array![Option::Some(1), Option::None, Option::Some(2), Option::Some(3)]) == 6, - 'bad sum' + 'bad sum', ); } diff --git a/crates/dojo/core-cairo-test/src/tests/world/acl.cairo b/crates/dojo/core-cairo-test/src/tests/world/acl.cairo index f899b51dfb..c5cebc202d 100644 --- a/crates/dojo/core-cairo-test/src/tests/world/acl.cairo +++ b/crates/dojo/core-cairo-test/src/tests/world/acl.cairo @@ -2,7 +2,7 @@ use dojo::utils::bytearray_hash; use dojo::world::IWorldDispatcherTrait; use crate::tests::helpers::{ - deploy_world, foo_setter, IFooSetterDispatcher, IFooSetterDispatcherTrait, deploy_world_and_foo + deploy_world, foo_setter, IFooSetterDispatcher, IFooSetterDispatcherTrait, deploy_world_and_foo, }; use crate::tests::expanded::selector_attack::{attacker_model, attacker_contract}; @@ -43,7 +43,7 @@ fn test_grant_owner_not_registered_resource() { } #[test] -#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED'))] +#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))] fn test_grant_owner_through_malicious_contract() { let (world, foo_selector) = deploy_world_and_foo(); let world = world.dispatcher; @@ -64,8 +64,8 @@ fn test_grant_owner_through_malicious_contract() { #[should_panic( expected: ( "Account `659918` does NOT have OWNER role on model (or its namespace) `Foo`", - 'ENTRYPOINT_FAILED' - ) + 'ENTRYPOINT_FAILED', + ), )] fn test_grant_owner_fails_for_non_owner() { let (world, foo_selector) = deploy_world_and_foo(); @@ -81,7 +81,7 @@ fn test_grant_owner_fails_for_non_owner() { } #[test] -#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED'))] +#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))] fn test_revoke_owner_through_malicious_contract() { let (world, foo_selector) = deploy_world_and_foo(); let world = world.dispatcher; @@ -103,8 +103,8 @@ fn test_revoke_owner_through_malicious_contract() { #[should_panic( expected: ( "Account `659918` does NOT have OWNER role on model (or its namespace) `Foo`", - 'ENTRYPOINT_FAILED' - ) + 'ENTRYPOINT_FAILED', + ), )] fn test_revoke_owner_fails_for_non_owner() { let (world, foo_selector) = deploy_world_and_foo(); @@ -146,7 +146,7 @@ fn test_writer_not_registered_resource() { } #[test] -#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED'))] +#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))] fn test_grant_writer_through_malicious_contract() { let (world, foo_selector) = deploy_world_and_foo(); let world = world.dispatcher; @@ -167,8 +167,8 @@ fn test_grant_writer_through_malicious_contract() { #[should_panic( expected: ( "Account `659918` does NOT have OWNER role on model (or its namespace) `Foo`", - 'ENTRYPOINT_FAILED' - ) + 'ENTRYPOINT_FAILED', + ), )] fn test_grant_writer_fails_for_non_owner() { let (world, foo_selector) = deploy_world_and_foo(); @@ -184,7 +184,7 @@ fn test_grant_writer_fails_for_non_owner() { } #[test] -#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED'))] +#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))] fn test_revoke_writer_through_malicious_contract() { let (world, foo_selector) = deploy_world_and_foo(); let world = world.dispatcher; @@ -206,8 +206,8 @@ fn test_revoke_writer_through_malicious_contract() { #[should_panic( expected: ( "Account `659918` does NOT have OWNER role on model (or its namespace) `Foo`", - 'ENTRYPOINT_FAILED' - ) + 'ENTRYPOINT_FAILED', + ), )] fn test_revoke_writer_fails_for_non_owner() { let (world, foo_selector) = deploy_world_and_foo(); @@ -229,8 +229,8 @@ fn test_revoke_writer_fails_for_non_owner() { expected: ( "Contract `foo_setter` does NOT have WRITER role on model (or its namespace) `Foo`", 'ENTRYPOINT_FAILED', - 'ENTRYPOINT_FAILED' - ) + 'ENTRYPOINT_FAILED', + ), )] fn test_not_writer_with_known_contract() { let (world, _) = deploy_world_and_foo(); @@ -251,7 +251,7 @@ fn test_not_writer_with_known_contract() { d.set_foo(1, 2); core::panics::panic_with_byte_array( - @"Contract `dojo-foo_setter` does NOT have WRITER role on model (or its namespace) `Foo`" + @"Contract `dojo-foo_setter` does NOT have WRITER role on model (or its namespace) `Foo`", ); } @@ -262,7 +262,7 @@ fn test_not_writer_with_known_contract() { expected: ( "Account `7022365680606078322` does NOT have OWNER role on namespace `dojo`", 'ENTRYPOINT_FAILED', - ) + ), )] fn test_register_model_namespace_not_owner() { let owner = starknet::contract_address_const::<'owner'>(); @@ -294,7 +294,7 @@ fn test_register_model_namespace_not_owner() { expected: ( "Account `7022365680606078322` does NOT have OWNER role on namespace `dojo`", 'ENTRYPOINT_FAILED', - ) + ), )] fn test_register_contract_namespace_not_owner() { let owner = starknet::contract_address_const::<'owner'>(); diff --git a/crates/dojo/core-cairo-test/src/tests/world/contract.cairo b/crates/dojo/core-cairo-test/src/tests/world/contract.cairo index 093427cac9..51b18ca827 100644 --- a/crates/dojo/core-cairo-test/src/tests/world/contract.cairo +++ b/crates/dojo/core-cairo-test/src/tests/world/contract.cairo @@ -75,7 +75,7 @@ fn test_upgrade_from_world() { #[test] #[available_gas(7000000)] -#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND', 'ENTRYPOINT_FAILED'))] +#[should_panic(expected: ('ENTRYPOINT_NOT_FOUND', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))] fn test_upgrade_from_world_not_world_provider() { let world = deploy_world(); let world = world.dispatcher; @@ -190,13 +190,13 @@ fn test_deploy_contract_for_namespace_owner() { assert(event.salt == 'salt1', 'bad event salt'); assert(event.class_hash == class_hash, 'bad class_hash'); assert( - event.address != core::num::traits::Zero::::zero(), 'bad contract address' + event.address != core::num::traits::Zero::::zero(), 'bad contract address', ); } #[test] #[should_panic( - expected: ("Account `2827` does NOT have OWNER role on namespace `dojo`", 'ENTRYPOINT_FAILED',) + expected: ("Account `2827` does NOT have OWNER role on namespace `dojo`", 'ENTRYPOINT_FAILED'), )] fn test_deploy_contract_for_namespace_writer() { let world = deploy_world(); @@ -215,7 +215,7 @@ fn test_deploy_contract_for_namespace_writer() { #[test] #[should_panic( - expected: ("Account `2827` does NOT have OWNER role on namespace `dojo`", 'ENTRYPOINT_FAILED',) + expected: ("Account `2827` does NOT have OWNER role on namespace `dojo`", 'ENTRYPOINT_FAILED'), )] fn test_deploy_contract_no_namespace_owner_access() { let world = deploy_world(); @@ -229,21 +229,21 @@ fn test_deploy_contract_no_namespace_owner_access() { } #[test] -#[should_panic(expected: ("Namespace `buzz_namespace` is not registered", 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Namespace `buzz_namespace` is not registered", 'ENTRYPOINT_FAILED'))] fn test_deploy_contract_with_unregistered_namespace() { let world = deploy_world(); let world = world.dispatcher; world .register_contract( - 'salt1', "buzz_namespace", test_contract::TEST_CLASS_HASH.try_into().unwrap() + 'salt1', "buzz_namespace", test_contract::TEST_CLASS_HASH.try_into().unwrap(), ); } // It's CONTRACT_NOT_DEPLOYED for now as in this example the contract is not a dojo contract // and it's not the account that is calling the deploy_contract function. #[test] -#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))] fn test_deploy_contract_through_malicious_contract() { let world = deploy_world(); let world = world.dispatcher; @@ -288,9 +288,9 @@ fn test_upgrade_contract_from_resource_owner() { assert( event .selector == dojo::utils::selector_from_namespace_and_name( - DOJO_NSH, @contract_name + DOJO_NSH, @contract_name, ), - 'bad contract selector' + 'bad contract selector', ); assert(event.class_hash == class_hash, 'bad class_hash'); } else { @@ -303,7 +303,7 @@ fn test_upgrade_contract_from_resource_owner() { expected: ( "Account `659918` does NOT have OWNER role on contract (or its namespace) `test_contract`", 'ENTRYPOINT_FAILED', - ) + ), )] fn test_upgrade_contract_from_resource_writer() { let world = deploy_world(); @@ -337,7 +337,7 @@ fn test_upgrade_contract_from_resource_writer() { expected: ( "Account `659918` does NOT have OWNER role on contract (or its namespace) `test_contract`", 'ENTRYPOINT_FAILED', - ) + ), )] fn test_upgrade_contract_from_random_account() { let world = deploy_world(); @@ -356,7 +356,7 @@ fn test_upgrade_contract_from_random_account() { } #[test] -#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))] fn test_upgrade_contract_through_malicious_contract() { let world = deploy_world(); let world = world.dispatcher; diff --git a/crates/dojo/core-cairo-test/src/tests/world/event.cairo b/crates/dojo/core-cairo-test/src/tests/world/event.cairo index 2c52779447..6f6527a54d 100644 --- a/crates/dojo/core-cairo-test/src/tests/world/event.cairo +++ b/crates/dojo/core-cairo-test/src/tests/world/event.cairo @@ -2,7 +2,7 @@ use core::starknet::ContractAddress; use crate::tests::helpers::{ SimpleEvent, e_SimpleEvent, DOJO_NSH, e_FooEventBadLayoutType, drop_all_events, deploy_world, - deploy_world_for_event_upgrades + deploy_world_for_event_upgrades, }; use dojo::world::{world, IWorldDispatcherTrait}; use dojo::event::Event; @@ -22,7 +22,7 @@ pub struct FooEventMemberAddedButRemoved { pub caller: ContractAddress, pub b: u128, pub c: u256, - pub d: u256 + pub d: u256, } #[derive(Copy, Drop, Serde, Debug)] @@ -32,7 +32,7 @@ pub struct FooEventMemberAddedButMoved { pub caller: ContractAddress, pub b: u128, pub a: felt252, - pub c: u256 + pub c: u256, } #[derive(Copy, Drop, Serde, Debug)] @@ -42,7 +42,7 @@ pub struct FooEventMemberAdded { pub caller: ContractAddress, pub a: felt252, pub b: u128, - pub c: u256 + pub c: u256, } #[test] @@ -68,11 +68,11 @@ fn test_register_event_for_namespace_owner() { assert(event.namespace == "dojo", 'bad event namespace'); assert( event.class_hash == e_SimpleEvent::TEST_CLASS_HASH.try_into().unwrap(), - 'bad event class_hash' + 'bad event class_hash', ); assert( event.address != core::num::traits::Zero::::zero(), - 'bad event prev address' + 'bad event prev address', ); } else { core::panic_with_felt252('no EventRegistered event'); @@ -83,7 +83,7 @@ fn test_register_event_for_namespace_owner() { #[test] #[should_panic( - expected: ("Account `2827` does NOT have OWNER role on namespace `dojo`", 'ENTRYPOINT_FAILED',) + expected: ("Account `2827` does NOT have OWNER role on namespace `dojo`", 'ENTRYPOINT_FAILED'), )] fn test_register_event_for_namespace_writer() { let bob = starknet::contract_address_const::<0xb0b>(); @@ -119,15 +119,16 @@ fn test_upgrade_event_from_event_owner() { if let world::Event::EventUpgraded(event) = event.unwrap() { assert( - event.selector == Event::::selector(DOJO_NSH), 'bad model selector' + event.selector == Event::::selector(DOJO_NSH), + 'bad model selector', ); assert( event.class_hash == e_FooEventMemberAdded::TEST_CLASS_HASH.try_into().unwrap(), - 'bad model class_hash' + 'bad model class_hash', ); assert( event.address != core::num::traits::Zero::::zero(), - 'bad model prev address' + 'bad model prev address', ); } else { core::panic_with_felt252('no EventUpgraded event'); @@ -135,7 +136,7 @@ fn test_upgrade_event_from_event_owner() { assert( world.is_owner(Event::::selector(DOJO_NSH), bob), - 'bob is not the owner' + 'bob is not the owner', ); } @@ -152,14 +153,16 @@ fn test_upgrade_event() { if let world::Event::EventUpgraded(event) = event.unwrap() { assert( - event.selector == Event::::selector(DOJO_NSH), 'bad model selector' + event.selector == Event::::selector(DOJO_NSH), + 'bad model selector', ); assert( event.class_hash == e_FooEventMemberAdded::TEST_CLASS_HASH.try_into().unwrap(), - 'bad model class_hash' + 'bad model class_hash', ); assert( - event.address != core::num::traits::Zero::::zero(), 'bad model address' + event.address != core::num::traits::Zero::::zero(), + 'bad model address', ); } else { core::panic_with_felt252('no EventUpgraded event'); @@ -171,7 +174,7 @@ fn test_upgrade_event() { expected: ( "Invalid new layout to upgrade the resource `dojo-FooEventBadLayoutType`", 'ENTRYPOINT_FAILED', - ) + ), )] fn test_upgrade_event_with_bad_layout_type() { let world = deploy_world_for_event_upgrades(); @@ -183,7 +186,7 @@ fn test_upgrade_event_with_bad_layout_type() { expected: ( "Invalid new schema to upgrade the resource `dojo-FooEventMemberRemoved`", 'ENTRYPOINT_FAILED', - ) + ), )] fn test_upgrade_event_with_member_removed() { let world = deploy_world_for_event_upgrades(); @@ -195,13 +198,13 @@ fn test_upgrade_event_with_member_removed() { expected: ( "Invalid new schema to upgrade the resource `dojo-FooEventMemberAddedButRemoved`", 'ENTRYPOINT_FAILED', - ) + ), )] fn test_upgrade_event_with_member_added_but_removed() { let world = deploy_world_for_event_upgrades(); world .upgrade_event( - "dojo", e_FooEventMemberAddedButRemoved::TEST_CLASS_HASH.try_into().unwrap() + "dojo", e_FooEventMemberAddedButRemoved::TEST_CLASS_HASH.try_into().unwrap(), ); } @@ -210,7 +213,7 @@ fn test_upgrade_event_with_member_added_but_removed() { expected: ( "Invalid new schema to upgrade the resource `dojo-FooEventMemberAddedButMoved`", 'ENTRYPOINT_FAILED', - ) + ), )] fn test_upgrade_event_with_member_moved() { let world = deploy_world_for_event_upgrades(); @@ -222,7 +225,7 @@ fn test_upgrade_event_with_member_moved() { expected: ( "Account `659918` does NOT have OWNER role on event (or its namespace) `FooEventMemberAdded`", 'ENTRYPOINT_FAILED', - ) + ), )] fn test_upgrade_event_from_event_writer() { let alice = starknet::contract_address_const::<0xa11ce>(); @@ -238,7 +241,7 @@ fn test_upgrade_event_from_event_writer() { #[test] #[should_panic( - expected: ("Resource `dojo-SimpleEvent` is already registered", 'ENTRYPOINT_FAILED',) + expected: ("Resource `dojo-SimpleEvent` is already registered", 'ENTRYPOINT_FAILED'), )] fn test_upgrade_event_from_random_account() { let bob = starknet::contract_address_const::<0xb0b>(); @@ -260,7 +263,7 @@ fn test_upgrade_event_from_random_account() { } #[test] -#[should_panic(expected: ("Namespace `another_namespace` is not registered", 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Namespace `another_namespace` is not registered", 'ENTRYPOINT_FAILED'))] fn test_register_event_with_unregistered_namespace() { let world = deploy_world(); let world = world.dispatcher; @@ -271,7 +274,7 @@ fn test_register_event_with_unregistered_namespace() { // It's CONTRACT_NOT_DEPLOYED for now as in this example the contract is not a dojo contract // and it's not the account that is calling the register_event function. #[test] -#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))] fn test_register_event_through_malicious_contract() { let bob = starknet::contract_address_const::<0xb0b>(); let malicious_contract = starknet::contract_address_const::<0xdead>(); diff --git a/crates/dojo/core-cairo-test/src/tests/world/metadata.cairo b/crates/dojo/core-cairo-test/src/tests/world/metadata.cairo index 0471b82d62..8c8f19b0de 100644 --- a/crates/dojo/core-cairo-test/src/tests/world/metadata.cairo +++ b/crates/dojo/core-cairo-test/src/tests/world/metadata.cairo @@ -9,7 +9,7 @@ fn test_set_metadata_world() { let world = world.dispatcher; let metadata = ResourceMetadata { - resource_id: 0, metadata_uri: format!("ipfs:world_with_a_long_uri_that"), metadata_hash: 42 + resource_id: 0, metadata_uri: format!("ipfs:world_with_a_long_uri_that"), metadata_hash: 42, }; world.set_metadata(metadata.clone()); @@ -30,7 +30,7 @@ fn test_set_metadata_resource_owner() { starknet::testing::set_contract_address(bob); let metadata = ResourceMetadata { - resource_id: model_selector, metadata_uri: format!("ipfs:bob"), metadata_hash: 42 + resource_id: model_selector, metadata_uri: format!("ipfs:bob"), metadata_hash: 42, }; drop_all_events(world.contract_address); @@ -57,7 +57,7 @@ fn test_set_metadata_resource_owner() { expected: ( "Account `2827` does NOT have OWNER role on model (or its namespace) `Foo`", 'ENTRYPOINT_FAILED', - ) + ), )] fn test_set_metadata_not_possible_for_resource_writer() { let (world, model_selector) = deploy_world_and_foo(); @@ -71,22 +71,20 @@ fn test_set_metadata_not_possible_for_resource_writer() { starknet::testing::set_contract_address(bob); let metadata = ResourceMetadata { - resource_id: model_selector, metadata_uri: format!("ipfs:bob"), metadata_hash: 42 + resource_id: model_selector, metadata_uri: format!("ipfs:bob"), metadata_hash: 42, }; world.set_metadata(metadata.clone()); } #[test] -#[should_panic( - expected: ("Account `2827` does NOT have OWNER role on world", 'ENTRYPOINT_FAILED',) -)] +#[should_panic(expected: ("Account `2827` does NOT have OWNER role on world", 'ENTRYPOINT_FAILED'))] fn test_set_metadata_not_possible_for_random_account() { let world = deploy_world(); let world = world.dispatcher; let metadata = ResourceMetadata { // World metadata. - resource_id: 0, metadata_uri: format!("ipfs:bob"), metadata_hash: 42 + resource_id: 0, metadata_uri: format!("ipfs:bob"), metadata_hash: 42, }; let bob = starknet::contract_address_const::<0xb0b>(); @@ -99,7 +97,7 @@ fn test_set_metadata_not_possible_for_random_account() { } #[test] -#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))] fn test_set_metadata_through_malicious_contract() { let (world, model_selector) = deploy_world_and_foo(); let world = world.dispatcher; @@ -113,7 +111,7 @@ fn test_set_metadata_through_malicious_contract() { starknet::testing::set_contract_address(malicious_contract); let metadata = ResourceMetadata { - resource_id: model_selector, metadata_uri: format!("ipfs:bob"), metadata_hash: 42 + resource_id: model_selector, metadata_uri: format!("ipfs:bob"), metadata_hash: 42, }; world.set_metadata(metadata.clone()); diff --git a/crates/dojo/core-cairo-test/src/tests/world/model.cairo b/crates/dojo/core-cairo-test/src/tests/world/model.cairo index 64cce8ee3e..717d1d0afe 100644 --- a/crates/dojo/core-cairo-test/src/tests/world/model.cairo +++ b/crates/dojo/core-cairo-test/src/tests/world/model.cairo @@ -2,7 +2,7 @@ use core::starknet::ContractAddress; use crate::tests::helpers::{ Foo, m_Foo, DOJO_NSH, drop_all_events, deploy_world, deploy_world_for_model_upgrades, - foo_invalid_name + foo_invalid_name, }; use dojo::world::{world, IWorldDispatcherTrait}; use dojo::model::Model; @@ -32,7 +32,7 @@ pub struct FooModelMemberAddedButRemoved { pub caller: ContractAddress, pub b: u128, pub c: u256, - pub d: u256 + pub d: u256, } #[derive(Introspect, Copy, Drop, Serde)] @@ -42,7 +42,7 @@ pub struct FooModelMemberAddedButMoved { pub caller: ContractAddress, pub b: u128, pub a: felt252, - pub c: u256 + pub c: u256, } #[derive(Introspect, Copy, Drop, Serde)] @@ -52,7 +52,7 @@ pub struct FooModelMemberAdded { pub caller: ContractAddress, pub a: felt252, pub b: u128, - pub c: u256 + pub c: u256, } #[test] @@ -77,11 +77,11 @@ fn test_register_model_for_namespace_owner() { assert(event.name == Model::::name(), 'bad event name'); assert(event.namespace == "dojo", 'bad event namespace'); assert( - event.class_hash == m_Foo::TEST_CLASS_HASH.try_into().unwrap(), 'bad event class_hash' + event.class_hash == m_Foo::TEST_CLASS_HASH.try_into().unwrap(), 'bad event class_hash', ); assert( event.address != core::num::traits::Zero::::zero(), - 'bad event prev address' + 'bad event prev address', ); } else { core::panic_with_felt252('no ModelRegistered event'); @@ -96,7 +96,7 @@ fn test_register_model_for_namespace_owner() { expected: ( "Name `foo-bis` is invalid according to Dojo naming rules: ^[a-zA-Z0-9_]+$", 'ENTRYPOINT_FAILED', - ) + ), )] fn test_register_model_with_invalid_name() { let world = deploy_world(); @@ -107,7 +107,7 @@ fn test_register_model_with_invalid_name() { #[test] #[should_panic( - expected: ("Account `2827` does NOT have OWNER role on namespace `dojo`", 'ENTRYPOINT_FAILED',) + expected: ("Account `2827` does NOT have OWNER role on namespace `dojo`", 'ENTRYPOINT_FAILED'), )] fn test_register_model_for_namespace_writer() { let bob = starknet::contract_address_const::<0xb0b>(); @@ -143,15 +143,16 @@ fn test_upgrade_model_from_model_owner() { if let world::Event::ModelUpgraded(event) = event.unwrap() { assert( - event.selector == Model::::selector(DOJO_NSH), 'bad model selector' + event.selector == Model::::selector(DOJO_NSH), + 'bad model selector', ); assert( event.class_hash == m_FooModelMemberAdded::TEST_CLASS_HASH.try_into().unwrap(), - 'bad model class_hash' + 'bad model class_hash', ); assert( event.address != core::num::traits::Zero::::zero(), - 'bad model prev address' + 'bad model prev address', ); } else { core::panic_with_felt252('no ModelUpgraded event'); @@ -159,7 +160,7 @@ fn test_upgrade_model_from_model_owner() { assert( world.is_owner(Model::::selector(DOJO_NSH), bob), - 'bob is not the owner' + 'bob is not the owner', ); } @@ -176,14 +177,16 @@ fn test_upgrade_model() { if let world::Event::ModelUpgraded(event) = event.unwrap() { assert( - event.selector == Model::::selector(DOJO_NSH), 'bad model selector' + event.selector == Model::::selector(DOJO_NSH), + 'bad model selector', ); assert( event.class_hash == m_FooModelMemberAdded::TEST_CLASS_HASH.try_into().unwrap(), - 'bad model class_hash' + 'bad model class_hash', ); assert( - event.address != core::num::traits::Zero::::zero(), 'bad model address' + event.address != core::num::traits::Zero::::zero(), + 'bad model address', ); } else { core::panic_with_felt252('no ModelUpgraded event'); @@ -195,7 +198,7 @@ fn test_upgrade_model() { expected: ( "Invalid new layout to upgrade the resource `dojo-FooModelBadLayoutType`", 'ENTRYPOINT_FAILED', - ) + ), )] fn test_upgrade_model_with_bad_layout_type() { let world = deploy_world_for_model_upgrades(); @@ -207,7 +210,7 @@ fn test_upgrade_model_with_bad_layout_type() { expected: ( "Invalid new schema to upgrade the resource `dojo-FooModelMemberRemoved`", 'ENTRYPOINT_FAILED', - ) + ), )] fn test_upgrade_model_with_member_removed() { let world = deploy_world_for_model_upgrades(); @@ -219,13 +222,13 @@ fn test_upgrade_model_with_member_removed() { expected: ( "Invalid new schema to upgrade the resource `dojo-FooModelMemberAddedButRemoved`", 'ENTRYPOINT_FAILED', - ) + ), )] fn test_upgrade_model_with_member_added_but_removed() { let world = deploy_world_for_model_upgrades(); world .upgrade_model( - "dojo", m_FooModelMemberAddedButRemoved::TEST_CLASS_HASH.try_into().unwrap() + "dojo", m_FooModelMemberAddedButRemoved::TEST_CLASS_HASH.try_into().unwrap(), ); } @@ -234,7 +237,7 @@ fn test_upgrade_model_with_member_added_but_removed() { expected: ( "Invalid new schema to upgrade the resource `dojo-FooModelMemberAddedButMoved`", 'ENTRYPOINT_FAILED', - ) + ), )] fn test_upgrade_model_with_member_moved() { let world = deploy_world_for_model_upgrades(); @@ -246,7 +249,7 @@ fn test_upgrade_model_with_member_moved() { expected: ( "Account `659918` does NOT have OWNER role on model (or its namespace) `FooModelMemberAdded`", 'ENTRYPOINT_FAILED', - ) + ), )] fn test_upgrade_model_from_model_writer() { let alice = starknet::contract_address_const::<0xa11ce>(); @@ -261,7 +264,7 @@ fn test_upgrade_model_from_model_writer() { } #[test] -#[should_panic(expected: ("Resource `dojo-Foo` is already registered", 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Resource `dojo-Foo` is already registered", 'ENTRYPOINT_FAILED'))] fn test_upgrade_model_from_random_account() { let bob = starknet::contract_address_const::<0xb0b>(); let alice = starknet::contract_address_const::<0xa11ce>(); @@ -282,7 +285,7 @@ fn test_upgrade_model_from_random_account() { } #[test] -#[should_panic(expected: ("Namespace `another_namespace` is not registered", 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Namespace `another_namespace` is not registered", 'ENTRYPOINT_FAILED'))] fn test_register_model_with_unregistered_namespace() { let world = deploy_world(); let world = world.dispatcher; @@ -293,7 +296,7 @@ fn test_register_model_with_unregistered_namespace() { // It's CONTRACT_NOT_DEPLOYED for now as in this example the contract is not a dojo contract // and it's not the account that is calling the register_model function. #[test] -#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))] fn test_register_model_through_malicious_contract() { let bob = starknet::contract_address_const::<0xb0b>(); let malicious_contract = starknet::contract_address_const::<0xdead>(); diff --git a/crates/dojo/core-cairo-test/src/tests/world/namespace.cairo b/crates/dojo/core-cairo-test/src/tests/world/namespace.cairo index 12883604fa..c3b96c5c30 100644 --- a/crates/dojo/core-cairo-test/src/tests/world/namespace.cairo +++ b/crates/dojo/core-cairo-test/src/tests/world/namespace.cairo @@ -31,7 +31,7 @@ fn test_register_namespace() { } #[test] -#[should_panic(expected: ("Namespace `namespace` is already registered", 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Namespace `namespace` is already registered", 'ENTRYPOINT_FAILED'))] fn test_register_namespace_already_registered_same_caller() { let world = deploy_world(); let world = world.dispatcher; @@ -45,7 +45,7 @@ fn test_register_namespace_already_registered_same_caller() { } #[test] -#[should_panic(expected: ("Namespace `namespace` is already registered", 'ENTRYPOINT_FAILED',))] +#[should_panic(expected: ("Namespace `namespace` is already registered", 'ENTRYPOINT_FAILED'))] fn test_register_namespace_already_registered_other_caller() { let world = deploy_world(); let world = world.dispatcher; @@ -70,7 +70,7 @@ fn test_register_namespace_already_registered_other_caller() { expected: ( "Namespace `` is invalid according to Dojo naming rules: ^[a-zA-Z0-9_]+$", 'ENTRYPOINT_FAILED', - ) + ), )] fn test_register_namespace_empty_name() { let world = deploy_world(); diff --git a/crates/dojo/core-cairo-test/src/tests/world/storage.cairo b/crates/dojo/core-cairo-test/src/tests/world/storage.cairo index 7b7bf07ead..c7fc15e312 100644 --- a/crates/dojo/core-cairo-test/src/tests/world/storage.cairo +++ b/crates/dojo/core-cairo-test/src/tests/world/storage.cairo @@ -36,20 +36,19 @@ fn write_multiple_copiable() { let mut models_snaps: Array<@Foo> = array![]; let mut keys: Array = array![]; - for i in 0_u128 - ..10_u128 { - let felt: felt252 = i.into(); - let caller: starknet::ContractAddress = felt.try_into().unwrap(); - keys.append(caller); - - if i % 2 == 0 { - let foo = Foo { caller, a: felt, b: i }; - models_snaps.append(@foo); - } else { - let foo = Foo { caller, a: felt, b: i }; - models_snaps.append(@foo); - } - }; + for i in 0_u128..10_u128 { + let felt: felt252 = i.into(); + let caller: starknet::ContractAddress = felt.try_into().unwrap(); + keys.append(caller); + + if i % 2 == 0 { + let foo = Foo { caller, a: felt, b: i }; + models_snaps.append(@foo); + } else { + let foo = Foo { caller, a: felt, b: i }; + models_snaps.append(@foo); + } + }; world.write_models(models_snaps.span()); @@ -57,16 +56,15 @@ fn write_multiple_copiable() { assert_eq!(models.len(), 10); - for i in 0_u128 - ..10_u128 { - let felt: felt252 = i.into(); - let caller: starknet::ContractAddress = felt.try_into().unwrap(); - // Can desnap as copiable. - let model: Foo = *models[i.try_into().unwrap()]; - assert_eq!(model.caller, caller); - assert_eq!(model.a, felt); - assert_eq!(model.b, i); - }; + for i in 0_u128..10_u128 { + let felt: felt252 = i.into(); + let caller: starknet::ContractAddress = felt.try_into().unwrap(); + // Can desnap as copiable. + let model: Foo = *models[i.try_into().unwrap()]; + assert_eq!(model.caller, caller); + assert_eq!(model.a, felt); + assert_eq!(model.b, i); + }; world.erase_models(models_snaps.span()); @@ -85,20 +83,19 @@ fn write_multiple_not_copiable() { let mut models_snaps: Array<@NotCopiable> = array![]; let mut keys: Array = array![]; - for i in 0_u128 - ..10_u128 { - let felt: felt252 = i.into(); - let caller: starknet::ContractAddress = felt.try_into().unwrap(); - keys.append(caller); - - if i % 2 == 0 { - let foo = NotCopiable { caller, a: array![felt], b: "ab" }; - models_snaps.append(@foo); - } else { - let foo = NotCopiable { caller, a: array![felt], b: "ab" }; - models_snaps.append(@foo); - } - }; + for i in 0_u128..10_u128 { + let felt: felt252 = i.into(); + let caller: starknet::ContractAddress = felt.try_into().unwrap(); + keys.append(caller); + + if i % 2 == 0 { + let foo = NotCopiable { caller, a: array![felt], b: "ab" }; + models_snaps.append(@foo); + } else { + let foo = NotCopiable { caller, a: array![felt], b: "ab" }; + models_snaps.append(@foo); + } + }; world.write_models(models_snaps.span()); @@ -106,16 +103,15 @@ fn write_multiple_not_copiable() { assert_eq!(models.len(), 10); - for i in 0_u128 - ..10_u128 { - let felt: felt252 = i.into(); - let caller: starknet::ContractAddress = felt.try_into().unwrap(); - // Can desnap as copiable. - let model: NotCopiable = models.pop_front().unwrap(); - assert_eq!(model.caller, caller); - assert_eq!(model.a, array![felt]); - assert_eq!(model.b, "ab"); - }; + for i in 0_u128..10_u128 { + let felt: felt252 = i.into(); + let caller: starknet::ContractAddress = felt.try_into().unwrap(); + // Can desnap as copiable. + let model: NotCopiable = models.pop_front().unwrap(); + assert_eq!(model.caller, caller); + assert_eq!(model.a, array![felt]); + assert_eq!(model.b, "ab"); + }; world.erase_models(models_snaps.span()); diff --git a/crates/dojo/core-cairo-test/src/tests/world/world.cairo b/crates/dojo/core-cairo-test/src/tests/world/world.cairo index 47b6818a50..67a0b2e94b 100644 --- a/crates/dojo/core-cairo-test/src/tests/world/world.cairo +++ b/crates/dojo/core-cairo-test/src/tests/world/world.cairo @@ -3,14 +3,14 @@ use dojo::world::world::Event as WorldEvent; use dojo::utils::bytearray_hash; use dojo::world::{ IWorldDispatcher, IWorldDispatcherTrait, IUpgradeableWorldDispatcher, - IUpgradeableWorldDispatcherTrait, WorldStorageTrait + IUpgradeableWorldDispatcherTrait, WorldStorageTrait, }; use dojo::model::ModelStorage; use dojo::event::{Event, EventStorage}; use crate::tests::helpers::{ IbarDispatcherTrait, drop_all_events, deploy_world_and_bar, Foo, m_Foo, test_contract, - test_contract_with_dojo_init_args, SimpleEvent, e_SimpleEvent, deploy_world + test_contract_with_dojo_init_args, SimpleEvent, e_SimpleEvent, deploy_world, }; use crate::{spawn_test_world, ContractDefTrait, NamespaceDef, TestResource, WorldStorageTestTrait}; @@ -96,7 +96,7 @@ fn test_emit() { if let WorldEvent::EventEmitted(event) = event.unwrap() { assert( event.selector == Event::::selector(world.namespace_hash), - 'bad event selector' + 'bad event selector', ); assert(event.system_address == bob, 'bad system address'); assert(event.keys == [2].span(), 'bad keys'); @@ -154,7 +154,7 @@ fn test_upgradeable_world() { let world = world.dispatcher; let mut upgradeable_world_dispatcher = IUpgradeableWorldDispatcher { - contract_address: world.contract_address + contract_address: world.contract_address, }; upgradeable_world_dispatcher.upgrade(worldupgrade::TEST_CLASS_HASH.try_into().unwrap()); @@ -175,7 +175,7 @@ fn test_upgradeable_world_with_class_hash_zero() { starknet::testing::set_contract_address(admin); let mut upgradeable_world_dispatcher = IUpgradeableWorldDispatcher { - contract_address: world.contract_address + contract_address: world.contract_address, }; upgradeable_world_dispatcher.upgrade(0.try_into().unwrap()); } @@ -183,7 +183,7 @@ fn test_upgradeable_world_with_class_hash_zero() { #[test] #[available_gas(60000000)] #[should_panic( - expected: ("Caller `4919` cannot upgrade the resource `0` (not owner)", 'ENTRYPOINT_FAILED') + expected: ("Caller `4919` cannot upgrade the resource `0` (not owner)", 'ENTRYPOINT_FAILED'), )] fn test_upgradeable_world_from_non_owner() { // Deploy world contract @@ -195,7 +195,7 @@ fn test_upgradeable_world_from_non_owner() { starknet::testing::set_account_contract_address(not_owner); let mut upgradeable_world_dispatcher = IUpgradeableWorldDispatcher { - contract_address: world.contract_address + contract_address: world.contract_address, }; upgradeable_world_dispatcher.upgrade(worldupgrade::TEST_CLASS_HASH.try_into().unwrap()); } @@ -222,7 +222,7 @@ fn test_can_call_init_only_world() { "Only the world can init contract `test_contract`, but caller is `0`"; match starknet::syscalls::call_contract_syscall( - address, dojo::world::world::DOJO_INIT_SELECTOR, [].span() + address, dojo::world::world::DOJO_INIT_SELECTOR, [].span(), ) { Result::Ok(_) => panic!("should panic"), Result::Err(e) => { @@ -235,13 +235,13 @@ fn test_can_call_init_only_world() { let e_str: ByteArray = Serde::deserialize(ref s).expect('failed deser'); println!("e_str: {}", e_str); assert_eq!(e_str, expected_panic); - } + }, } } #[test] #[available_gas(6000000)] -#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED'))] +#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED', 'ENTRYPOINT_FAILED'))] fn test_can_call_init_only_owner() { let world = deploy_world(); let world = world.dispatcher; @@ -275,7 +275,7 @@ fn test_can_call_init_args() { let _address = world .register_contract( - 'salt1', "dojo", test_contract_with_dojo_init_args::TEST_CLASS_HASH.try_into().unwrap() + 'salt1', "dojo", test_contract_with_dojo_init_args::TEST_CLASS_HASH.try_into().unwrap(), ); world.init_contract(selector_from_tag!("dojo-test_contract_with_dojo_init_args"), [1].span()); @@ -288,14 +288,14 @@ fn test_can_call_init_only_world_args() { let address = world .register_contract( - 'salt1', "dojo", test_contract_with_dojo_init_args::TEST_CLASS_HASH.try_into().unwrap() + 'salt1', "dojo", test_contract_with_dojo_init_args::TEST_CLASS_HASH.try_into().unwrap(), ); let expected_panic: ByteArray = "Only the world can init contract `test_contract_with_dojo_init_args`, but caller is `0`"; match starknet::syscalls::call_contract_syscall( - address, dojo::world::world::DOJO_INIT_SELECTOR, [123].span() + address, dojo::world::world::DOJO_INIT_SELECTOR, [123].span(), ) { Result::Ok(_) => panic!("should panic"), Result::Err(e) => { @@ -308,6 +308,6 @@ fn test_can_call_init_only_world_args() { let e_str: ByteArray = Serde::deserialize(ref s).expect('failed deser'); assert_eq!(e_str, expected_panic); - } + }, } } diff --git a/crates/dojo/core-cairo-test/src/utils.cairo b/crates/dojo/core-cairo-test/src/utils.cairo index 051be84e2a..7222771e6b 100644 --- a/crates/dojo/core-cairo-test/src/utils.cairo +++ b/crates/dojo/core-cairo-test/src/utils.cairo @@ -49,7 +49,7 @@ pub fn assert_array(value: Span, expected: Span) { "Bad array value [{}] (expected: {} got: {})", i, *expected.at(i), - *value.at(i) + *value.at(i), ); i += 1; diff --git a/crates/dojo/core-cairo-test/src/world.cairo b/crates/dojo/core-cairo-test/src/world.cairo index 8e3910fc21..06ecd82c0e 100644 --- a/crates/dojo/core-cairo-test/src/world.cairo +++ b/crates/dojo/core-cairo-test/src/world.cairo @@ -55,12 +55,12 @@ pub struct NamespaceDef { #[generate_trait] pub impl ContractDefImpl of ContractDefTrait { - fn new(namespace: @ByteArray, name: @ByteArray,) -> ContractDef { + fn new(namespace: @ByteArray, name: @ByteArray) -> ContractDef { ContractDef { contract: ContractDescriptor::Named((namespace, name)), writer_of: [].span(), owner_of: [].span(), - init_calldata: [].span() + init_calldata: [].span(), } } @@ -69,14 +69,14 @@ pub impl ContractDefImpl of ContractDefTrait { contract: ContractDescriptor::Address(address), writer_of: [].span(), owner_of: [].span(), - init_calldata: [].span() + init_calldata: [].span(), } } fn with_init_calldata(mut self: ContractDef, init_calldata: Span) -> ContractDef { match self.contract { ContractDescriptor::Address(_) => panic!( - "Cannot set init_calldata for address descriptor" + "Cannot set init_calldata for address descriptor", ), ContractDescriptor::Named(_) => self.init_calldata = init_calldata, }; @@ -106,7 +106,7 @@ pub impl ContractDefImpl of ContractDefTrait { /// * address of contract deployed pub fn deploy_contract(class_hash: felt252, calldata: Span) -> ContractAddress { let (contract, _) = starknet::syscalls::deploy_syscall( - class_hash.try_into().unwrap(), 0, calldata, false + class_hash.try_into().unwrap(), 0, calldata, false, ) .unwrap(); contract @@ -145,7 +145,7 @@ pub fn spawn_test_world(namespaces_defs: Span) -> WorldStorage { world::TEST_CLASS_HASH.try_into().unwrap(), salt.into(), [world::TEST_CLASS_HASH].span(), - false + false, ) .unwrap(); @@ -161,21 +161,19 @@ pub fn spawn_test_world(namespaces_defs: Span) -> WorldStorage { first_namespace = Option::Some(namespace.clone()); } - for r in ns - .resources - .clone() { - match r { - TestResource::Event(ch) => { - world.register_event(namespace.clone(), (*ch).try_into().unwrap()); - }, - TestResource::Model(ch) => { - world.register_model(namespace.clone(), (*ch).try_into().unwrap()); - }, - TestResource::Contract(ch) => { - world.register_contract(*ch, namespace.clone(), (*ch).try_into().unwrap()); - } - } + for r in ns.resources.clone() { + match r { + TestResource::Event(ch) => { + world.register_event(namespace.clone(), (*ch).try_into().unwrap()); + }, + TestResource::Model(ch) => { + world.register_model(namespace.clone(), (*ch).try_into().unwrap()); + }, + TestResource::Contract(ch) => { + world.register_contract(*ch, namespace.clone(), (*ch).try_into().unwrap()); + }, } + } }; WorldStorageTrait::new(world, @first_namespace.unwrap()) @@ -189,7 +187,7 @@ pub impl WorldStorageInternalTestImpl of WorldStorageTestTrait { let contract_address = match c.contract { ContractDescriptor::Address(address) => *address, ContractDescriptor::Named(( - namespace, name + namespace, name, )) => { let selector = dojo::utils::selector_from_names(*namespace, *name); match (*self.dispatcher).resource(selector) { @@ -213,11 +211,11 @@ pub impl WorldStorageInternalTestImpl of WorldStorageTestTrait { match c.contract { ContractDescriptor::Address(_) => {}, ContractDescriptor::Named(( - namespace, name + namespace, name, )) => { let selector = dojo::utils::selector_from_names(*namespace, *name); (*self.dispatcher).init_contract(selector, *c.init_calldata); - } + }, } }; } diff --git a/crates/dojo/core/Scarb.lock b/crates/dojo/core/Scarb.lock index 3e1c687548..6d3dd4041a 100644 --- a/crates/dojo/core/Scarb.lock +++ b/crates/dojo/core/Scarb.lock @@ -10,4 +10,4 @@ dependencies = [ [[package]] name = "dojo_plugin" -version = "2.8.4" +version = "2.9.2" diff --git a/crates/dojo/core/Scarb.toml b/crates/dojo/core/Scarb.toml index 7bb45e92d6..ee2356cd47 100644 --- a/crates/dojo/core/Scarb.toml +++ b/crates/dojo/core/Scarb.toml @@ -1,17 +1,17 @@ [package] -cairo-version = "=2.8.4" +cairo-version = "=2.9.2" edition = "2024_07" description = "The Dojo Core library for autonomous worlds." name = "dojo" version = "1.0.11" [dependencies] -starknet = "=2.8.4" +starknet = "=2.9.2" dojo_plugin = { path = "../lang" } #dojo_macros = { path = "../macros" } [dev-dependencies] -cairo_test = "=2.8.4" +cairo_test = "=2.9.2" [lib] diff --git a/crates/dojo/core/src/contract/components/upgradeable.cairo b/crates/dojo/core/src/contract/components/upgradeable.cairo index e08a718d7f..99afa8e24c 100644 --- a/crates/dojo/core/src/contract/components/upgradeable.cairo +++ b/crates/dojo/core/src/contract/components/upgradeable.cairo @@ -25,7 +25,7 @@ pub mod upgradeable_cpt { #[derive(Drop, starknet::Event)] pub struct Upgraded { - pub class_hash: ClassHash + pub class_hash: ClassHash, } pub mod Errors { @@ -37,16 +37,16 @@ pub mod upgradeable_cpt { #[embeddable_as(UpgradeableImpl)] impl Upgradeable< - TContractState, +HasComponent, +IWorldProvider + TContractState, +HasComponent, +IWorldProvider, > of super::IUpgradeable> { fn upgrade(ref self: ComponentState, new_class_hash: ClassHash) { assert( self.get_contract().world_dispatcher().contract_address.is_non_zero(), - Errors::INVALID_WORLD_ADDRESS + Errors::INVALID_WORLD_ADDRESS, ); assert( get_caller_address() == self.get_contract().world_dispatcher().contract_address, - Errors::INVALID_CALLER + Errors::INVALID_CALLER, ); assert(new_class_hash.is_non_zero(), Errors::INVALID_CLASS); diff --git a/crates/dojo/core/src/contract/components/world_provider.cairo b/crates/dojo/core/src/contract/components/world_provider.cairo index 934947d844..143f8e66ea 100644 --- a/crates/dojo/core/src/contract/components/world_provider.cairo +++ b/crates/dojo/core/src/contract/components/world_provider.cairo @@ -19,7 +19,7 @@ pub mod world_provider_cpt { #[embeddable_as(WorldProviderImpl)] pub impl WorldProvider< - TContractState, +HasComponent + TContractState, +HasComponent, > of super::IWorldProvider> { fn world_dispatcher(self: @ComponentState) -> IWorldDispatcher { self.world_dispatcher.read() @@ -28,7 +28,7 @@ pub mod world_provider_cpt { #[generate_trait] pub impl InternalImpl< - TContractState, +HasComponent + TContractState, +HasComponent, > of InternalTrait { fn initializer(ref self: ComponentState) { self diff --git a/crates/dojo/core/src/event/component.cairo b/crates/dojo/core/src/event/component.cairo index 14f0a934ca..10148a6cf2 100644 --- a/crates/dojo/core/src/event/component.cairo +++ b/crates/dojo/core/src/event/component.cairo @@ -3,7 +3,7 @@ use dojo::meta::{Layout, introspect::Struct}; #[starknet::embeddable] pub impl IDeployedEventImpl< - TContractState, E, +Event + TContractState, E, +Event, > of dojo::meta::interface::IDeployedResource { fn dojo_name(self: @TContractState) -> ByteArray { Event::::name() @@ -12,7 +12,7 @@ pub impl IDeployedEventImpl< #[starknet::embeddable] pub impl IStoredEventImpl< - TContractState, E, +Event + TContractState, E, +Event, > of dojo::meta::interface::IStoredResource { fn schema(self: @TContractState) -> Struct { Event::::schema() diff --git a/crates/dojo/core/src/event/event.cairo b/crates/dojo/core/src/event/event.cairo index 970c341429..4a3672a666 100644 --- a/crates/dojo/core/src/event/event.cairo +++ b/crates/dojo/core/src/event/event.cairo @@ -6,7 +6,7 @@ use dojo::model::model::ModelParser; pub struct EventDef { pub name: ByteArray, pub layout: Layout, - pub schema: Struct + pub schema: Struct, } pub trait EventDefinition { @@ -37,7 +37,7 @@ pub impl EventImpl, +EventDefinition, +Serde, +Introspe fn schema() -> Struct { match Introspect::::ty() { Ty::Struct(s) => s, - _ => panic!("Event: invalid schema.") + _ => panic!("Event: invalid schema."), } } fn serialized_keys(self: @E) -> Span { diff --git a/crates/dojo/core/src/lib.cairo b/crates/dojo/core/src/lib.cairo index c3e8068e56..67b2dc9290 100644 --- a/crates/dojo/core/src/lib.cairo +++ b/crates/dojo/core/src/lib.cairo @@ -25,7 +25,7 @@ pub mod meta { pub mod interface; pub use interface::{ IDeployedResource, IDeployedResourceDispatcher, IDeployedResourceDispatcherTrait, - IStoredResource, IStoredResourceDispatcher, IStoredResourceDispatcherTrait + IStoredResource, IStoredResourceDispatcher, IStoredResourceDispatcherTrait, }; pub mod introspect; @@ -54,7 +54,7 @@ pub mod model { pub use metadata::ResourceMetadata; pub mod storage; - pub use storage::{ModelStorage, ModelStorageTest, ModelValueStorage, ModelValueStorageTest,}; + pub use storage::{ModelStorage, ModelStorageTest, ModelValueStorage, ModelValueStorageTest}; } pub mod storage { @@ -94,7 +94,7 @@ pub mod world { mod iworld; pub use iworld::{ IWorld, IWorldDispatcher, IWorldDispatcherTrait, IUpgradeableWorld, - IUpgradeableWorldDispatcher, IUpgradeableWorldDispatcherTrait + IUpgradeableWorldDispatcher, IUpgradeableWorldDispatcherTrait, }; #[cfg(target: "test")] diff --git a/crates/dojo/core/src/meta/introspect.cairo b/crates/dojo/core/src/meta/introspect.cairo index 448ae94f21..6e6f8ee80e 100644 --- a/crates/dojo/core/src/meta/introspect.cairo +++ b/crates/dojo/core/src/meta/introspect.cairo @@ -18,21 +18,21 @@ pub enum Ty { pub struct Struct { pub name: felt252, pub attrs: Span, - pub children: Span + pub children: Span, } #[derive(Copy, Drop, Serde, Debug, PartialEq)] pub struct Enum { pub name: felt252, pub attrs: Span, - pub children: Span<(felt252, Ty)> + pub children: Span<(felt252, Ty)>, } #[derive(Copy, Drop, Serde, Debug, PartialEq)] pub struct Member { pub name: felt252, pub attrs: Span, - pub ty: Ty + pub ty: Ty, } #[generate_trait] @@ -267,20 +267,22 @@ pub impl Introspect_option> of Introspect> { Layout::Enum( [ dojo::meta::FieldLayout { // Some - selector: 0, layout: Introspect::::layout() }, + selector: 0, layout: Introspect::::layout() }, dojo::meta::FieldLayout { // None - selector: 1, layout: Layout::Fixed([].span()) }, - ].span() + selector: 1, layout: Layout::Fixed([].span()) }, + ] + .span(), ) } fn ty() -> Ty { Ty::Enum( Enum { - name: 'Option', attrs: [].span(), children: [ - ('Some(T)', Introspect::::ty()), ('None', Ty::Tuple([].span())) - ].span() - } + name: 'Option', + attrs: [].span(), + children: [('Some(T)', Introspect::::ty()), ('None', Ty::Tuple([].span()))] + .span(), + }, ) } } diff --git a/crates/dojo/core/src/meta/layout.cairo b/crates/dojo/core/src/meta/layout.cairo index ce82b527f0..660d066409 100644 --- a/crates/dojo/core/src/meta/layout.cairo +++ b/crates/dojo/core/src/meta/layout.cairo @@ -3,7 +3,7 @@ use dojo::storage::packing::calculate_packed_size; #[derive(Copy, Drop, Serde, Debug, PartialEq)] pub struct FieldLayout { pub selector: felt252, - pub layout: Layout + pub layout: Layout, } #[derive(Copy, Drop, Serde, Debug, PartialEq)] @@ -32,7 +32,7 @@ pub impl LayoutCompareImpl of LayoutCompareTrait { (Layout::Array(_), Layout::Array(_)) => true, (Layout::ByteArray, Layout::ByteArray) => true, (Layout::Enum(_), Layout::Enum(_)) => true, - _ => false + _ => false, } } } diff --git a/crates/dojo/core/src/model/component.cairo b/crates/dojo/core/src/model/component.cairo index 2a7cea2588..9a199dc4e7 100644 --- a/crates/dojo/core/src/model/component.cairo +++ b/crates/dojo/core/src/model/component.cairo @@ -3,7 +3,7 @@ use dojo::meta::{Layout, introspect::Struct}; #[starknet::embeddable] pub impl IDeployedModelImpl< - TContractState, M, +Model + TContractState, M, +Model, > of dojo::meta::IDeployedResource { fn dojo_name(self: @TContractState) -> ByteArray { Model::::name() @@ -12,7 +12,7 @@ pub impl IDeployedModelImpl< #[starknet::embeddable] pub impl IStoredModelImpl< - TContractState, M, +Model + TContractState, M, +Model, > of dojo::meta::IStoredResource { fn schema(self: @TContractState) -> Struct { Model::::schema() diff --git a/crates/dojo/core/src/model/definition.cairo b/crates/dojo/core/src/model/definition.cairo index 27c27eb066..e4c5598216 100644 --- a/crates/dojo/core/src/model/definition.cairo +++ b/crates/dojo/core/src/model/definition.cairo @@ -11,7 +11,7 @@ pub enum ModelIndex { Keys: Span, Id: felt252, // (entity_id, member_id) - MemberId: (felt252, felt252) + MemberId: (felt252, felt252), } /// The `ModelDefinition` trait. diff --git a/crates/dojo/core/src/model/metadata.cairo b/crates/dojo/core/src/model/metadata.cairo index acef47be19..14cbfe1110 100644 --- a/crates/dojo/core/src/model/metadata.cairo +++ b/crates/dojo/core/src/model/metadata.cairo @@ -9,7 +9,7 @@ pub struct ResourceMetadata { #[key] pub resource_id: felt252, pub metadata_uri: ByteArray, - pub metadata_hash: felt252 + pub metadata_hash: felt252, } pub fn default_address() -> starknet::ContractAddress { @@ -22,6 +22,6 @@ pub fn default_class_hash() -> starknet::ClassHash { pub fn resource_metadata_selector(default_namespace_hash: felt252) -> felt252 { utils::selector_from_namespace_and_name( - default_namespace_hash, @Model::::name() + default_namespace_hash, @Model::::name(), ) } diff --git a/crates/dojo/core/src/model/model.cairo b/crates/dojo/core/src/model/model.cairo index c88334ded4..5b5e20a72d 100644 --- a/crates/dojo/core/src/model/model.cairo +++ b/crates/dojo/core/src/model/model.cairo @@ -1,6 +1,6 @@ use dojo::{ meta::{Layout, introspect::Struct, layout::compute_packed_size}, - utils::{entity_id_from_serialized_keys, find_model_field_layout, entity_id_from_keys} + utils::{entity_id_from_serialized_keys, find_model_field_layout, entity_id_from_keys}, }; use super::{ModelDefinition, ModelDef}; @@ -131,7 +131,7 @@ pub impl ModelImpl, +ModelDefinition, +Serde> of Model< layout: Self::layout(), schema: Self::schema(), packed_size: Self::packed_size(), - unpacked_size: Self::unpacked_size() + unpacked_size: Self::unpacked_size(), } } diff --git a/crates/dojo/core/src/model/model_value.cairo b/crates/dojo/core/src/model/model_value.cairo index 8d4444f1ed..26ea71517c 100644 --- a/crates/dojo/core/src/model/model_value.cairo +++ b/crates/dojo/core/src/model/model_value.cairo @@ -1,4 +1,4 @@ -use dojo::{meta::{Layout}, model::{ModelDefinition},}; +use dojo::{meta::{Layout}, model::{ModelDefinition}}; pub trait ModelValueKey {} diff --git a/crates/dojo/core/src/model/storage.cairo b/crates/dojo/core/src/model/storage.cairo index 0109d4f70a..415146b457 100644 --- a/crates/dojo/core/src/model/storage.cairo +++ b/crates/dojo/core/src/model/storage.cairo @@ -40,7 +40,7 @@ pub trait ModelStorage { /// Retrieves a model of type `M` using the provided entity id. fn write_member, +Drop>( - ref self: S, ptr: ModelPtr, field_selector: felt252, value: T + ref self: S, ptr: ModelPtr, field_selector: felt252, value: T, ); /// Returns the current namespace hash. @@ -54,7 +54,7 @@ pub trait ModelValueStorage { /// Retrieves multiple model values of type `V` using the provided keys of type `K`. fn read_values, +Serde, +ModelValueKey>( - self: @S, keys: Span + self: @S, keys: Span, ) -> Array; /// Retrieves a model value of type `V` using the provided entity id. @@ -68,7 +68,7 @@ pub trait ModelValueStorage { /// Updates multiple model values of type `V`. fn write_values, +Serde, +ModelValueKey>( - ref self: S, keys: Span, values: Span<@V> + ref self: S, keys: Span, values: Span<@V>, ); /// Updates a model value of type `V`. @@ -102,11 +102,11 @@ pub trait ModelStorageTest { pub trait ModelValueStorageTest { /// Updates a model value of type `V`. fn write_value_test, +Serde, +ModelValueKey>( - ref self: S, keys: K, value: @V + ref self: S, keys: K, value: @V, ); /// Updates multiple model values of type `V`. fn write_values_test, +Serde, +ModelValueKey>( - ref self: S, keys: Span, values: Span<@V> + ref self: S, keys: Span, values: Span<@V>, ); /// Updates a model value of type `V`. fn write_value_from_id_test(ref self: S, entity_id: felt252, value: @V); diff --git a/crates/dojo/core/src/storage/database.cairo b/crates/dojo/core/src/storage/database.cairo index 461550dcb1..8a8f1d5a09 100644 --- a/crates/dojo/core/src/storage/database.cairo +++ b/crates/dojo/core/src/storage/database.cairo @@ -88,7 +88,7 @@ pub fn delete(table: felt252, key: felt252, layout: Span) { pub fn set_array(table: felt252, key: felt252, value: Span, offset: u32, array_size: u32) { let storage_key = get_storage_key(table, key); storage::set_packed_array( - storage::DEFAULT_ADDRESS_DOMAIN, storage_key, value, offset, array_size + storage::DEFAULT_ADDRESS_DOMAIN, storage_key, value, offset, array_size, ) .unwrap_syscall(); } diff --git a/crates/dojo/core/src/storage/entity_model.cairo b/crates/dojo/core/src/storage/entity_model.cairo index 7834e117fb..037a22855c 100644 --- a/crates/dojo/core/src/storage/entity_model.cairo +++ b/crates/dojo/core/src/storage/entity_model.cairo @@ -10,22 +10,22 @@ use dojo::meta::Layout; /// * `values` - the field values of the record /// * `layout` - the model layout pub fn write_model_entity( - model_selector: felt252, entity_id: felt252, values: Span, layout: Layout + model_selector: felt252, entity_id: felt252, values: Span, layout: Layout, ) { let mut offset = 0; match layout { Layout::Fixed(layout) => { super::layout::write_fixed_layout( - model_selector, entity_id, values, ref offset, layout + model_selector, entity_id, values, ref offset, layout, ); }, Layout::Struct(layout) => { super::layout::write_struct_layout( - model_selector, entity_id, values, ref offset, layout + model_selector, entity_id, values, ref offset, layout, ); }, - _ => { panic!("Unexpected layout type for a model."); } + _ => { panic!("Unexpected layout type for a model."); }, }; } @@ -43,7 +43,7 @@ pub fn delete_model_entity(model_selector: felt252, entity_id: felt252, layout: Layout::Struct(layout) => { super::layout::delete_struct_layout(model_selector, entity_id, layout); }, - _ => { panic!("Unexpected layout type for a model."); } + _ => { panic!("Unexpected layout type for a model."); }, }; } @@ -54,7 +54,7 @@ pub fn delete_model_entity(model_selector: felt252, entity_id: felt252, layout: /// * `entity_id` - the ID of the entity to read. /// * `layout` - the model layout pub fn read_model_entity( - model_selector: felt252, entity_id: felt252, layout: Layout + model_selector: felt252, entity_id: felt252, layout: Layout, ) -> Span { let mut read_data = ArrayTrait::::new(); @@ -65,7 +65,7 @@ pub fn read_model_entity( Layout::Struct(layout) => { super::layout::read_struct_layout(model_selector, entity_id, ref read_data, layout); }, - _ => { panic!("Unexpected layout type for a model."); } + _ => { panic!("Unexpected layout type for a model."); }, }; read_data.span() @@ -79,11 +79,11 @@ pub fn read_model_entity( /// * `member_id` - the selector of the model member to read. /// * `layout` - the model layout pub fn read_model_member( - model_selector: felt252, entity_id: felt252, member_id: felt252, layout: Layout + model_selector: felt252, entity_id: felt252, member_id: felt252, layout: Layout, ) -> Span { let mut read_data = ArrayTrait::::new(); super::layout::read_layout( - model_selector, dojo::utils::combine_key(entity_id, member_id), ref read_data, layout + model_selector, dojo::utils::combine_key(entity_id, member_id), ref read_data, layout, ); read_data.span() @@ -102,10 +102,10 @@ pub fn write_model_member( entity_id: felt252, member_id: felt252, values: Span, - layout: Layout + layout: Layout, ) { let mut offset = 0; super::layout::write_layout( - model_selector, dojo::utils::combine_key(entity_id, member_id), values, ref offset, layout + model_selector, dojo::utils::combine_key(entity_id, member_id), values, ref offset, layout, ) } diff --git a/crates/dojo/core/src/storage/layout.cairo b/crates/dojo/core/src/storage/layout.cairo index d29ca3235e..0107c3bdc6 100644 --- a/crates/dojo/core/src/storage/layout.cairo +++ b/crates/dojo/core/src/storage/layout.cairo @@ -24,7 +24,7 @@ pub fn write_layout( Layout::Array(layout) => { write_array_layout(model, key, values, ref offset, layout); }, Layout::Tuple(layout) => { write_tuple_layout(model, key, values, ref offset, layout); }, Layout::ByteArray => { write_byte_array_layout(model, key, values, ref offset); }, - Layout::Enum(layout) => { write_enum_layout(model, key, values, ref offset, layout); } + Layout::Enum(layout) => { write_enum_layout(model, key, values, ref offset, layout); }, } } @@ -37,7 +37,7 @@ pub fn write_layout( /// * `offset` - the start of model record values in the `values` parameter. /// * `layout` - the model record layout. pub fn write_fixed_layout( - model: felt252, key: felt252, values: Span, ref offset: u32, layout: Span + model: felt252, key: felt252, values: Span, ref offset: u32, layout: Span, ) { database::set(model, key, values, offset, layout); offset += layout.len(); @@ -52,7 +52,7 @@ pub fn write_fixed_layout( /// * `offset` - the start of model record values in the `values` parameter. /// * `item_layout` - the model record layout (temporary a Span because of type recursion issue). pub fn write_array_layout( - model: felt252, key: felt252, values: Span, ref offset: u32, item_layout: Span + model: felt252, key: felt252, values: Span, ref offset: u32, item_layout: Span, ) { assert((values.len() - offset) > 0, 'Invalid values length'); @@ -83,7 +83,7 @@ pub fn write_array_layout( /// pub fn write_byte_array_layout( - model: felt252, key: felt252, values: Span, ref offset: u32 + model: felt252, key: felt252, values: Span, ref offset: u32, ) { // The ByteArray internal structure is // struct ByteArray { @@ -99,7 +99,7 @@ pub fn write_byte_array_layout( let data_len = *values.at(offset); assert( data_len.into() <= (database::MAX_ARRAY_LENGTH - MIN_BYTE_ARRAY_SIZE.into()), - 'invalid array length' + 'invalid array length', ); let array_size: u32 = data_len.try_into().unwrap() + MIN_BYTE_ARRAY_SIZE.into(); @@ -118,7 +118,7 @@ pub fn write_byte_array_layout( /// * `offset` - the start of model record values in the `values` parameter. /// * `layout` - list of field layouts. pub fn write_struct_layout( - model: felt252, key: felt252, values: Span, ref offset: u32, layout: Span + model: felt252, key: felt252, values: Span, ref offset: u32, layout: Span, ) { let mut i = 0; loop { @@ -144,7 +144,7 @@ pub fn write_struct_layout( /// * `offset` - the start of model record values in the `values` parameter. /// * `layout` - list of tuple item layouts. pub fn write_tuple_layout( - model: felt252, key: felt252, values: Span, ref offset: u32, layout: Span + model: felt252, key: felt252, values: Span, ref offset: u32, layout: Span, ) { let mut i = 0; loop { @@ -166,7 +166,7 @@ pub fn write_enum_layout( key: felt252, values: Span, ref offset: u32, - variant_layouts: Span + variant_layouts: Span, ) { if let Option::Some(variant) = values.get(offset) { // TODO: when Cairo 2.8 support is added, unboxing should be implicit. @@ -183,9 +183,9 @@ pub fn write_enum_layout( match find_field_layout(variant, variant_layouts) { Option::Some(layout) => write_layout( - model, variant_data_key, values, ref offset, layout + model, variant_data_key, values, ref offset, layout, ), - Option::None => panic!("Unable to find the variant layout") + Option::None => panic!("Unable to find the variant layout"), }; } else { panic!("offset is out of bounds for enum layout variant"); @@ -226,7 +226,7 @@ pub fn delete_byte_array_layout(model: felt252, key: felt252) { database::delete( model, key, - [packing::PACKING_MAX_BITS, packing::PACKING_MAX_BITS, packing::PACKING_MAX_BITS].span() + [packing::PACKING_MAX_BITS, packing::PACKING_MAX_BITS, packing::PACKING_MAX_BITS].span(), ); } @@ -243,7 +243,7 @@ pub fn delete_layout(model: felt252, key: felt252, layout: Layout) { Layout::Array(_) => { delete_array_layout(model, key); }, Layout::Tuple(layout) => { delete_tuple_layout(model, key, layout); }, Layout::ByteArray => { delete_byte_array_layout(model, key); }, - Layout::Enum(layout) => { delete_enum_layout(model, key, layout); } + Layout::Enum(layout) => { delete_enum_layout(model, key, layout); }, } } @@ -307,7 +307,7 @@ pub fn delete_enum_layout(model: felt252, key: felt252, variant_layouts: Span delete_layout(model, variant_data_key, layout), - Option::None => panic!("Unable to find the variant layout") + Option::None => panic!("Unable to find the variant layout"), }; } @@ -337,7 +337,7 @@ pub fn read_layout(model: felt252, key: felt252, ref read_data: Array, /// * `read_data` - the read data. /// * `layout` - the model layout pub fn read_fixed_layout( - model: felt252, key: felt252, ref read_data: Array, layout: Span + model: felt252, key: felt252, ref read_data: Array, layout: Span, ) { let mut data = database::get(model, key, layout); read_data.append_span(data); @@ -351,7 +351,7 @@ pub fn read_fixed_layout( /// * `read_data` - the read data. /// * `layout` - the array item layout pub fn read_array_layout( - model: felt252, key: felt252, ref read_data: Array, layout: Span + model: felt252, key: felt252, ref read_data: Array, layout: Span, ) { // read number of array items let res = database::get(model, key, [packing::PACKING_MAX_BITS].span()); @@ -395,7 +395,7 @@ pub fn read_byte_array_layout(model: felt252, key: felt252, ref read_data: Array let data_len = *res.at(0); assert( data_len.into() <= (database::MAX_ARRAY_LENGTH - MIN_BYTE_ARRAY_SIZE.into()), - 'invalid array length' + 'invalid array length', ); let array_size: u32 = data_len.try_into().unwrap() + MIN_BYTE_ARRAY_SIZE; @@ -412,7 +412,7 @@ pub fn read_byte_array_layout(model: felt252, key: felt252, ref read_data: Array /// * `read_data` - the read data. /// * `layout` - the list of field layouts. pub fn read_struct_layout( - model: felt252, key: felt252, ref read_data: Array, layout: Span + model: felt252, key: felt252, ref read_data: Array, layout: Span, ) { let mut i = 0; loop { @@ -437,7 +437,7 @@ pub fn read_struct_layout( /// * `read_data` - the read data. /// * `layout` - the tuple item layouts pub fn read_tuple_layout( - model: felt252, key: felt252, ref read_data: Array, layout: Span + model: felt252, key: felt252, ref read_data: Array, layout: Span, ) { let mut i = 0; loop { @@ -454,7 +454,7 @@ pub fn read_tuple_layout( } pub fn read_enum_layout( - model: felt252, key: felt252, ref read_data: Array, variant_layouts: Span + model: felt252, key: felt252, ref read_data: Array, variant_layouts: Span, ) { // read the variant value first let res = database::get(model, key, [8].span()); @@ -470,6 +470,6 @@ pub fn read_enum_layout( match find_field_layout(variant, variant_layouts) { Option::Some(layout) => read_layout(model, variant_data_key, ref read_data, layout), - Option::None => panic!("Unable to find the variant layout") + Option::None => panic!("Unable to find the variant layout"), }; } diff --git a/crates/dojo/core/src/storage/packing.cairo b/crates/dojo/core/src/storage/packing.cairo index 5adbdb7682..a105ae6523 100644 --- a/crates/dojo/core/src/storage/packing.cairo +++ b/crates/dojo/core/src/storage/packing.cairo @@ -5,7 +5,7 @@ use core::traits::{Into, TryInto}; pub const PACKING_MAX_BITS: u8 = 251; pub fn pack( - ref packed: Array, ref unpacked: Span, offset: u32, ref layout: Span + ref packed: Array, ref unpacked: Span, offset: u32, ref layout: Span, ) { assert((unpacked.len() - offset) >= layout.len(), 'mismatched input lens'); let mut packing: felt252 = 0x0; @@ -15,10 +15,10 @@ pub fn pack( match layout.pop_front() { Option::Some(layout) => { pack_inner( - unpacked.at(index), *layout, ref packing, ref internal_offset, ref packed + unpacked.at(index), *layout, ref packing, ref internal_offset, ref packed, ); }, - Option::None(_) => { break; } + Option::None(_) => { break; }, }; index += 1; @@ -40,7 +40,7 @@ pub fn calculate_packed_size(ref layout: Span) -> usize { partial = item_size; } }, - Option::None(_) => { break; } + Option::None(_) => { break; }, }; }; @@ -59,10 +59,10 @@ pub fn unpack(ref unpacked: Array, ref packed: Span, ref layou // Layout value was successfully popped, // we are then expecting an unpacked value. core::panic_with_felt252('Unpack inner failed'); - } + }, } }, - Option::None(_) => { break; } + Option::None(_) => { break; }, }; } } @@ -73,7 +73,7 @@ pub fn pack_inner( size: u8, ref packing: felt252, ref packing_offset: u8, - ref packed: Array + ref packed: Array, ) { assert(packing_offset <= PACKING_MAX_BITS, 'Invalid packing offset'); assert(size <= PACKING_MAX_BITS, 'Invalid layout size'); @@ -105,7 +105,7 @@ pub fn pack_inner( } pub fn unpack_inner( - size: u8, ref packed: Span, ref unpacking: felt252, ref unpacking_offset: u8 + size: u8, ref packed: Span, ref unpacking: felt252, ref unpacking_offset: u8, ) -> Option { let remaining_bits: u8 = (PACKING_MAX_BITS - unpacking_offset).into(); @@ -167,162 +167,53 @@ pub fn pow2_const(n: u8) -> u256 { *POW_2.span().at(n.into()) } -pub const POW_2: [ - u256 - ; 256] = [ - 1, - 2, - 4, - 8, - 16, - 32, - 64, - 128, - 256, - 512, - 1024, - 2048, - 4096, - 8192, - 16384, - 32768, - 65536, - 131072, - 262144, - 524288, - 1048576, - 2097152, - 4194304, - 8388608, - 16777216, - 33554432, - 67108864, - 134217728, - 268435456, - 536870912, - 1073741824, - 2147483648, - 4294967296, - 8589934592, - 17179869184, - 34359738368, - 68719476736, - 137438953472, - 274877906944, - 549755813888, - 1099511627776, - 2199023255552, - 4398046511104, - 8796093022208, - 17592186044416, - 35184372088832, - 70368744177664, - 140737488355328, - 281474976710656, - 562949953421312, - 1125899906842624, - 2251799813685248, - 4503599627370496, - 9007199254740992, - 18014398509481984, - 36028797018963968, - 72057594037927936, - 144115188075855872, - 288230376151711744, - 576460752303423488, - 1152921504606846976, - 2305843009213693952, - 4611686018427387904, - 9223372036854775808, - 18446744073709551616, - 36893488147419103232, - 73786976294838206464, - 147573952589676412928, - 295147905179352825856, - 590295810358705651712, - 1180591620717411303424, - 2361183241434822606848, - 4722366482869645213696, - 9444732965739290427392, - 18889465931478580854784, - 37778931862957161709568, - 75557863725914323419136, - 151115727451828646838272, - 302231454903657293676544, - 604462909807314587353088, - 1208925819614629174706176, - 2417851639229258349412352, - 4835703278458516698824704, - 9671406556917033397649408, - 19342813113834066795298816, - 38685626227668133590597632, - 77371252455336267181195264, - 154742504910672534362390528, - 309485009821345068724781056, - 618970019642690137449562112, - 1237940039285380274899124224, - 2475880078570760549798248448, - 4951760157141521099596496896, - 9903520314283042199192993792, - 19807040628566084398385987584, - 39614081257132168796771975168, - 79228162514264337593543950336, - 158456325028528675187087900672, - 316912650057057350374175801344, - 633825300114114700748351602688, - 1267650600228229401496703205376, - 2535301200456458802993406410752, - 5070602400912917605986812821504, - 10141204801825835211973625643008, - 20282409603651670423947251286016, - 40564819207303340847894502572032, - 81129638414606681695789005144064, - 162259276829213363391578010288128, - 324518553658426726783156020576256, - 649037107316853453566312041152512, - 1298074214633706907132624082305024, - 2596148429267413814265248164610048, - 5192296858534827628530496329220096, - 10384593717069655257060992658440192, - 20769187434139310514121985316880384, - 41538374868278621028243970633760768, - 83076749736557242056487941267521536, - 166153499473114484112975882535043072, - 332306998946228968225951765070086144, - 664613997892457936451903530140172288, - 1329227995784915872903807060280344576, - 2658455991569831745807614120560689152, - 5316911983139663491615228241121378304, - 10633823966279326983230456482242756608, - 21267647932558653966460912964485513216, - 42535295865117307932921825928971026432, - 85070591730234615865843651857942052864, - 170141183460469231731687303715884105728, - 340282366920938463463374607431768211456, - 680564733841876926926749214863536422912, - 1361129467683753853853498429727072845824, - 2722258935367507707706996859454145691648, - 5444517870735015415413993718908291383296, - 10889035741470030830827987437816582766592, - 21778071482940061661655974875633165533184, - 43556142965880123323311949751266331066368, - 87112285931760246646623899502532662132736, - 174224571863520493293247799005065324265472, - 348449143727040986586495598010130648530944, - 696898287454081973172991196020261297061888, - 1393796574908163946345982392040522594123776, - 2787593149816327892691964784081045188247552, - 5575186299632655785383929568162090376495104, - 11150372599265311570767859136324180752990208, - 22300745198530623141535718272648361505980416, - 44601490397061246283071436545296723011960832, - 89202980794122492566142873090593446023921664, - 178405961588244985132285746181186892047843328, - 356811923176489970264571492362373784095686656, - 713623846352979940529142984724747568191373312, - 1427247692705959881058285969449495136382746624, - 2854495385411919762116571938898990272765493248, - 5708990770823839524233143877797980545530986496, +pub const POW_2: [u256; 256] = [ + 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, + 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, + 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, + 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, + 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, + 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, + 9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872, + 288230376151711744, 576460752303423488, 1152921504606846976, 2305843009213693952, + 4611686018427387904, 9223372036854775808, 18446744073709551616, 36893488147419103232, + 73786976294838206464, 147573952589676412928, 295147905179352825856, 590295810358705651712, + 1180591620717411303424, 2361183241434822606848, 4722366482869645213696, 9444732965739290427392, + 18889465931478580854784, 37778931862957161709568, 75557863725914323419136, + 151115727451828646838272, 302231454903657293676544, 604462909807314587353088, + 1208925819614629174706176, 2417851639229258349412352, 4835703278458516698824704, + 9671406556917033397649408, 19342813113834066795298816, 38685626227668133590597632, + 77371252455336267181195264, 154742504910672534362390528, 309485009821345068724781056, + 618970019642690137449562112, 1237940039285380274899124224, 2475880078570760549798248448, + 4951760157141521099596496896, 9903520314283042199192993792, 19807040628566084398385987584, + 39614081257132168796771975168, 79228162514264337593543950336, 158456325028528675187087900672, + 316912650057057350374175801344, 633825300114114700748351602688, 1267650600228229401496703205376, + 2535301200456458802993406410752, 5070602400912917605986812821504, + 10141204801825835211973625643008, 20282409603651670423947251286016, + 40564819207303340847894502572032, 81129638414606681695789005144064, + 162259276829213363391578010288128, 324518553658426726783156020576256, + 649037107316853453566312041152512, 1298074214633706907132624082305024, + 2596148429267413814265248164610048, 5192296858534827628530496329220096, + 10384593717069655257060992658440192, 20769187434139310514121985316880384, + 41538374868278621028243970633760768, 83076749736557242056487941267521536, + 166153499473114484112975882535043072, 332306998946228968225951765070086144, + 664613997892457936451903530140172288, 1329227995784915872903807060280344576, + 2658455991569831745807614120560689152, 5316911983139663491615228241121378304, + 10633823966279326983230456482242756608, 21267647932558653966460912964485513216, + 42535295865117307932921825928971026432, 85070591730234615865843651857942052864, + 170141183460469231731687303715884105728, 340282366920938463463374607431768211456, + 680564733841876926926749214863536422912, 1361129467683753853853498429727072845824, + 2722258935367507707706996859454145691648, 5444517870735015415413993718908291383296, + 10889035741470030830827987437816582766592, 21778071482940061661655974875633165533184, + 43556142965880123323311949751266331066368, 87112285931760246646623899502532662132736, + 174224571863520493293247799005065324265472, 348449143727040986586495598010130648530944, + 696898287454081973172991196020261297061888, 1393796574908163946345982392040522594123776, + 2787593149816327892691964784081045188247552, 5575186299632655785383929568162090376495104, + 11150372599265311570767859136324180752990208, 22300745198530623141535718272648361505980416, + 44601490397061246283071436545296723011960832, 89202980794122492566142873090593446023921664, + 178405961588244985132285746181186892047843328, 356811923176489970264571492362373784095686656, + 713623846352979940529142984724747568191373312, 1427247692705959881058285969449495136382746624, + 2854495385411919762116571938898990272765493248, 5708990770823839524233143877797980545530986496, 11417981541647679048466287755595961091061972992, 22835963083295358096932575511191922182123945984, 45671926166590716193865151022383844364247891968, diff --git a/crates/dojo/core/src/storage/storage.cairo b/crates/dojo/core/src/storage/storage.cairo index 4a89c5c2e2..67eef94a85 100644 --- a/crates/dojo/core/src/storage/storage.cairo +++ b/crates/dojo/core/src/storage/storage.cairo @@ -5,7 +5,7 @@ use core::traits::Into; use starknet::{SyscallResultTrait, SyscallResult}; use starknet::storage_access::{ StorageAddress, StorageBaseAddress, storage_base_address_from_felt252, - storage_address_from_base, storage_address_from_base_and_offset + storage_address_from_base, storage_address_from_base_and_offset, }; use starknet::syscalls::{storage_read_syscall, storage_write_syscall}; @@ -19,7 +19,7 @@ pub fn get(address_domain: u32, keys: Span) -> felt252 { } pub fn get_many( - address_domain: u32, keys: Span, mut layout: Span + address_domain: u32, keys: Span, mut layout: Span, ) -> SyscallResult> { let base = storage_base_address_from_felt252(poseidon_hash_span(keys)); let base_address = storage_address_from_base(base); @@ -36,7 +36,7 @@ pub fn get_many( let mut packed_span = loop { let value = match storage_read_syscall( - address_domain, storage_address_from_base_and_offset(chunk_base, index_in_chunk) + address_domain, storage_address_from_base_and_offset(chunk_base, index_in_chunk), ) { Result::Ok(value) => value, Result::Err(err) => { break SyscallResult::>::Err(err); }, @@ -51,7 +51,7 @@ pub fn get_many( } let (sum, has_overflowed) = core::num::traits::OverflowingAdd::overflowing_add( - index_in_chunk, 1 + index_in_chunk, 1, ); index_in_chunk = match has_overflowed { false => sum, @@ -82,7 +82,7 @@ pub fn set_many( keys: Span, mut unpacked: Span, offset: u32, - mut layout: Span + mut layout: Span, ) -> SyscallResult<()> { let base = storage_base_address_from_felt252(poseidon_hash_span(keys)); let base_address = storage_address_from_base(base); @@ -103,14 +103,14 @@ pub fn set_many( match storage_write_syscall( address_domain, storage_address_from_base_and_offset(chunk_base, index_in_chunk), - curr_value.into() + curr_value.into(), ) { Result::Ok(_) => {}, Result::Err(err) => { break Result::Err(err); }, }; let (sum, has_overflowed) = core::num::traits::OverflowingAdd::overflowing_add( - index_in_chunk, 1 + index_in_chunk, 1, ); index_in_chunk = match has_overflowed { false => sum, @@ -126,7 +126,7 @@ pub fn set_many( } pub fn set_packed_array( - address_domain: u32, keys: Span, mut data: Span, offset: u32, array_size: u32 + address_domain: u32, keys: Span, mut data: Span, offset: u32, array_size: u32, ) -> SyscallResult<()> { // write data+offset by chunk of 256 felts let base = storage_base_address_from_felt252(poseidon_hash_span(keys)); @@ -147,14 +147,14 @@ pub fn set_packed_array( match storage_write_syscall( address_domain, storage_address_from_base_and_offset(chunk_base, index_in_chunk), - curr_value.into() + curr_value.into(), ) { Result::Ok(_) => {}, Result::Err(err) => { break Result::Err(err); }, }; let (sum, has_overflowed) = core::num::traits::OverflowingAdd::overflowing_add( - index_in_chunk, 1 + index_in_chunk, 1, ); index_in_chunk = match has_overflowed { false => sum, @@ -172,7 +172,7 @@ pub fn set_packed_array( } pub fn get_packed_array( - address_domain: u32, keys: Span, array_size: u32 + address_domain: u32, keys: Span, array_size: u32, ) -> SyscallResult> { if array_size == 0 { return SyscallResult::>::Ok([].span()); @@ -190,7 +190,7 @@ pub fn get_packed_array( loop { let value = match storage_read_syscall( - address_domain, storage_address_from_base_and_offset(chunk_base, index_in_chunk) + address_domain, storage_address_from_base_and_offset(chunk_base, index_in_chunk), ) { Result::Ok(value) => value, Result::Err(err) => { break SyscallResult::>::Err(err); }, @@ -205,7 +205,7 @@ pub fn get_packed_array( } let (sum, has_overflowed) = core::num::traits::OverflowingAdd::overflowing_add( - index_in_chunk, 1 + index_in_chunk, 1, ); index_in_chunk = match has_overflowed { false => sum, diff --git a/crates/dojo/core/src/utils/layout.cairo b/crates/dojo/core/src/utils/layout.cairo index 3e09d47b93..b7826a5773 100644 --- a/crates/dojo/core/src/utils/layout.cairo +++ b/crates/dojo/core/src/utils/layout.cairo @@ -2,7 +2,7 @@ use dojo::meta::{Layout, FieldLayout}; /// find a field with its selector in a list of layouts pub fn find_field_layout( - field_selector: felt252, field_layouts: Span + field_selector: felt252, field_layouts: Span, ) -> Option { let mut i = 0; let layout = loop { @@ -37,6 +37,6 @@ pub fn find_model_field_layout(model_layout: Layout, member_selector: felt252) - // should never happen as model layouts are always struct layouts. core::panic_with_felt252('Unexpected model layout'); Option::None - } + }, } } diff --git a/crates/dojo/core/src/utils/misc.cairo b/crates/dojo/core/src/utils/misc.cairo index 177c7ee9a7..00620971dd 100644 --- a/crates/dojo/core/src/utils/misc.cairo +++ b/crates/dojo/core/src/utils/misc.cairo @@ -34,7 +34,7 @@ pub fn sum, +Copy, +AddAssign, +Zero>(arr: Array res += x, - Option::None => {} + Option::None => {}, } i += 1; diff --git a/crates/dojo/core/src/utils/serde.cairo b/crates/dojo/core/src/utils/serde.cairo index 5040ff226f..f19063b48a 100644 --- a/crates/dojo/core/src/utils/serde.cairo +++ b/crates/dojo/core/src/utils/serde.cairo @@ -7,6 +7,6 @@ pub fn serialize_inline>(value: @T) -> Span { pub fn deserialize_unwrap>(mut span: Span) -> T { match Serde::deserialize(ref span) { Option::Some(value) => value, - Option::None => core::panic_with_felt252('Could not deserialize') + Option::None => core::panic_with_felt252('Could not deserialize'), } } diff --git a/crates/dojo/core/src/utils/snf_test.cairo b/crates/dojo/core/src/utils/snf_test.cairo index 520e491c2e..4695aa6dbf 100644 --- a/crates/dojo/core/src/utils/snf_test.cairo +++ b/crates/dojo/core/src/utils/snf_test.cairo @@ -37,34 +37,23 @@ pub fn spawn_test_world(namespaces_defs: Span) -> IWorldDispatcher let namespace = ns.namespace.clone(); world.register_namespace(namespace.clone()); - for r in ns - .resources - .clone() { - match r { - TestResource::Event(name) => { - let ch: ClassHash = *declare(name.clone()) - .unwrap() - .contract_class() - .class_hash; - world.register_event(namespace.clone(), ch); - }, - TestResource::Model(name) => { - let ch: ClassHash = *declare(name.clone()) - .unwrap() - .contract_class() - .class_hash; - world.register_model(namespace.clone(), ch); - }, - TestResource::Contract(name) => { - let ch: ClassHash = *declare(name.clone()) - .unwrap() - .contract_class() - .class_hash; - let salt = dojo::utils::bytearray_hash(name); - world.register_contract(salt, namespace.clone(), ch); - }, - } + for r in ns.resources.clone() { + match r { + TestResource::Event(name) => { + let ch: ClassHash = *declare(name.clone()).unwrap().contract_class().class_hash; + world.register_event(namespace.clone(), ch); + }, + TestResource::Model(name) => { + let ch: ClassHash = *declare(name.clone()).unwrap().contract_class().class_hash; + world.register_model(namespace.clone(), ch); + }, + TestResource::Contract(name) => { + let ch: ClassHash = *declare(name.clone()).unwrap().contract_class().class_hash; + let salt = dojo::utils::bytearray_hash(name); + world.register_contract(salt, namespace.clone(), ch); + }, } + } }; world @@ -73,36 +62,36 @@ pub fn spawn_test_world(namespaces_defs: Span) -> IWorldDispatcher /// Extension trait for world dispatcher to test resources. pub trait WorldTestExt { fn resource_contract_address( - self: IWorldDispatcher, namespace: ByteArray, name: ByteArray + self: IWorldDispatcher, namespace: ByteArray, name: ByteArray, ) -> ContractAddress; fn resource_class_hash( - self: IWorldDispatcher, namespace: ByteArray, name: ByteArray + self: IWorldDispatcher, namespace: ByteArray, name: ByteArray, ) -> ClassHash; } impl WorldTestExtImpl of WorldTestExt { fn resource_contract_address( - self: IWorldDispatcher, namespace: ByteArray, name: ByteArray + self: IWorldDispatcher, namespace: ByteArray, name: ByteArray, ) -> ContractAddress { match self.resource(dojo::utils::selector_from_names(@namespace, @name)) { Resource::Contract((ca, _)) => ca, Resource::Event((ca, _)) => ca, Resource::Model((ca, _)) => ca, _ => panic_with_byte_array( - @format!("Resource is not registered: {}-{}", namespace, name) - ) + @format!("Resource is not registered: {}-{}", namespace, name), + ), } } fn resource_class_hash( - self: IWorldDispatcher, namespace: ByteArray, name: ByteArray + self: IWorldDispatcher, namespace: ByteArray, name: ByteArray, ) -> ClassHash { match self.resource(dojo::utils::selector_from_names(@namespace, @name)) { Resource::Contract((_, ch)) => ch.try_into().unwrap(), Resource::Event((_, ch)) => ch.try_into().unwrap(), Resource::Model((_, ch)) => ch.try_into().unwrap(), _ => panic_with_byte_array( - @format!("Resource is not registered: {}-{}", namespace, name) + @format!("Resource is not registered: {}-{}", namespace, name), ), } } diff --git a/crates/dojo/core/src/world/errors.cairo b/crates/dojo/core/src/world/errors.cairo index 2f8df1157d..a0cc3e4f0f 100644 --- a/crates/dojo/core/src/world/errors.cairo +++ b/crates/dojo/core/src/world/errors.cairo @@ -87,7 +87,7 @@ pub fn invalid_resource_layout_upgrade(namespace: @ByteArray, name: @ByteArray) } pub fn invalid_resource_version_upgrade( - namespace: @ByteArray, name: @ByteArray, expected_version: u8 + namespace: @ByteArray, name: @ByteArray, expected_version: u8, ) -> ByteArray { format!("The new resource version of `{}-{}` should be {}", namespace, name, expected_version) } diff --git a/crates/dojo/core/src/world/iworld.cairo b/crates/dojo/core/src/world/iworld.cairo index b11dfb67ec..82632d2e80 100644 --- a/crates/dojo/core/src/world/iworld.cairo +++ b/crates/dojo/core/src/world/iworld.cairo @@ -80,7 +80,7 @@ pub trait IWorld { /// * `namespace` - The namespace of the contract to be registered. /// * `class_hash` - The class hash of the contract. fn register_contract( - ref self: T, salt: felt252, namespace: ByteArray, class_hash: ClassHash + ref self: T, salt: felt252, namespace: ByteArray, class_hash: ClassHash, ) -> ContractAddress; /// Initializes a contract associated registered in the world. @@ -126,9 +126,7 @@ pub trait IWorld { /// * `event_selector` - The selector of the event. /// * `keys` - The keys of the event. /// * `values` - The data to be logged by the event. - fn emit_event( - ref self: T, event_selector: felt252, keys: Span, values: Span, - ); + fn emit_event(ref self: T, event_selector: felt252, keys: Span, values: Span); /// Emits multiple events. /// Permissions are only checked once, then the events are batched. @@ -158,7 +156,7 @@ pub trait IWorld { /// /// * `Span` - The serialized value of the model, zero initialized if not set. fn entity( - self: @T, model_selector: felt252, index: ModelIndex, layout: Layout + self: @T, model_selector: felt252, index: ModelIndex, layout: Layout, ) -> Span; /// Gets the model values for the given entities. @@ -169,7 +167,7 @@ pub trait IWorld { /// * `indices` - The indexes of the entities/members to read. /// * `layout` - The memory layout of the model. fn entities( - self: @T, model_selector: felt252, indexes: Span, layout: Layout + self: @T, model_selector: felt252, indexes: Span, layout: Layout, ) -> Span>; /// Sets the model value for the given entity/member. @@ -185,7 +183,7 @@ pub trait IWorld { model_selector: felt252, index: ModelIndex, values: Span, - layout: Layout + layout: Layout, ); /// Sets the model values for the given entities. @@ -202,7 +200,7 @@ pub trait IWorld { model_selector: felt252, indexes: Span, values: Span>, - layout: Layout + layout: Layout, ); /// Deletes a model value for the given entity/member. @@ -224,7 +222,7 @@ pub trait IWorld { /// * `indexes` - The indexes of the entities/members to delete. /// * `layout` - The memory layout of the model. fn delete_entities( - ref self: T, model_selector: felt252, indexes: Span, layout: Layout + ref self: T, model_selector: felt252, indexes: Span, layout: Layout, ); /// Returns true if the provided account has owner permission for the resource, false otherwise. @@ -299,7 +297,7 @@ pub trait IWorldTest { model_selector: felt252, index: ModelIndex, values: Span, - layout: Layout + layout: Layout, ); /// Deletes a model value for the given entity/member without checking for resource permissions. diff --git a/crates/dojo/core/src/world/resource.cairo b/crates/dojo/core/src/world/resource.cairo index f1db6e9ec3..7ae8061c90 100644 --- a/crates/dojo/core/src/world/resource.cairo +++ b/crates/dojo/core/src/world/resource.cairo @@ -47,7 +47,7 @@ pub impl ResourceIsNoneImpl of ResourceIsNoneTrait { fn is_unregistered(self: @Resource) -> bool { match self { Resource::Unregistered => true, - _ => false + _ => false, } } } diff --git a/crates/dojo/core/src/world/storage.cairo b/crates/dojo/core/src/world/storage.cairo index 6fdc9e9160..cc9f703a5f 100644 --- a/crates/dojo/core/src/world/storage.cairo +++ b/crates/dojo/core/src/world/storage.cairo @@ -7,7 +7,7 @@ use dojo::event::{Event, EventStorage}; use dojo::meta::Layout; use dojo::utils::{ entity_id_from_keys, entity_id_from_serialized_keys, serialize_inline, find_model_field_layout, - deserialize_unwrap + deserialize_unwrap, }; use starknet::{ContractAddress, ClassHash}; @@ -20,7 +20,7 @@ pub struct WorldStorage { fn field_layout_unwrap>(field_selector: felt252) -> Layout { match Model::::field_layout(field_selector) { Option::Some(layout) => layout, - Option::None => panic_with_felt252('bad member id') + Option::None => panic_with_felt252('bad member id'), } } @@ -39,12 +39,12 @@ pub impl WorldStorageInternalImpl of WorldStorageTrait { fn dns(self: @WorldStorage, contract_name: @ByteArray) -> Option<(ContractAddress, ClassHash)> { match (*self.dispatcher) .resource( - dojo::utils::selector_from_namespace_and_name(*self.namespace_hash, contract_name) + dojo::utils::selector_from_namespace_and_name(*self.namespace_hash, contract_name), ) { Resource::Contract(( - contract_address, class_hash + contract_address, class_hash, )) => Option::Some((contract_address, class_hash.try_into().unwrap())), - _ => Option::None + _ => Option::None, } } @@ -71,15 +71,15 @@ pub impl ModelStorageWorldStorageImpl, +Drop> of ModelStorage::selector(*self.namespace_hash), ModelIndex::Id(entity_id_from_serialized_keys(keys)), - Model::::layout() + Model::::layout(), ); match Model::::from_serialized(keys, values) { Option::Some(model) => model, Option::None => { panic!( - "Model: deserialization failed. Ensure the length of the keys tuple is matching the number of #[key] fields in the model struct." + "Model: deserialization failed. Ensure the length of the keys tuple is matching the number of #[key] fields in the model struct.", ) - } + }, } } @@ -96,7 +96,7 @@ pub impl ModelStorageWorldStorageImpl, +Drop> of ModelStorage::selector(*self.namespace_hash), indexes.span(), - Model::::layout() + Model::::layout(), ); let mut models: Array = array![]; @@ -107,9 +107,9 @@ pub impl ModelStorageWorldStorageImpl, +Drop> of ModelStorage models.append(model), Option::None => { panic!( - "Model: deserialization failed. Ensure the length of the keys tuple is matching the number of #[key] fields in the model struct." + "Model: deserialization failed. Ensure the length of the keys tuple is matching the number of #[key] fields in the model struct.", ) - } + }, }; i += 1; @@ -123,7 +123,7 @@ pub impl ModelStorageWorldStorageImpl, +Drop> of ModelStorage::selector(self.namespace_hash), ModelIndex::Keys(Model::::serialized_keys(model)), Model::::serialized_values(model), - Model::::layout() + Model::::layout(), ); } @@ -140,7 +140,7 @@ pub impl ModelStorageWorldStorageImpl, +Drop> of ModelStorage::selector(self.namespace_hash), keys.span(), values.span(), - Model::::layout() + Model::::layout(), ); } @@ -149,7 +149,7 @@ pub impl ModelStorageWorldStorageImpl, +Drop> of ModelStorage::selector(self.namespace_hash), ModelIndex::Id(Model::::entity_id(model)), - Model::::layout() + Model::::layout(), ); } @@ -163,7 +163,7 @@ pub impl ModelStorageWorldStorageImpl, +Drop> of ModelStorage::selector(self.namespace_hash), ids.span(), - Model::::layout() + Model::::layout(), ); } @@ -172,31 +172,31 @@ pub impl ModelStorageWorldStorageImpl, +Drop> of ModelStorage::selector(self.namespace_hash), ModelIndex::Id(ptr.id), - Model::::layout() + Model::::layout(), ); } fn read_member>( - self: @WorldStorage, ptr: ModelPtr, field_selector: felt252 + self: @WorldStorage, ptr: ModelPtr, field_selector: felt252, ) -> T { deserialize_unwrap( IWorldDispatcherTrait::entity( *self.dispatcher, Model::::selector(*self.namespace_hash), ModelIndex::MemberId((ptr.id, field_selector)), - field_layout_unwrap::(field_selector) - ) + field_layout_unwrap::(field_selector), + ), ) } fn write_member, +Drop>( - ref self: WorldStorage, ptr: ModelPtr, field_selector: felt252, value: T + ref self: WorldStorage, ptr: ModelPtr, field_selector: felt252, value: T, ) { IWorldDispatcherTrait::set_entity( self.dispatcher, Model::::selector(self.namespace_hash), ModelIndex::MemberId((ptr.id, field_selector)), serialize_inline(@value), - field_layout_unwrap::(field_selector) + field_layout_unwrap::(field_selector), ); } @@ -210,7 +210,7 @@ pub impl ModelStorageWorldStorageImpl, +Drop> of ModelStorage::selector(self.namespace_hash), indexes.span(), - Model::::layout() + Model::::layout(), ); } @@ -220,7 +220,7 @@ pub impl ModelStorageWorldStorageImpl, +Drop> of ModelStorage, +Drop + V, +ModelValue, +Drop, > of dojo::model::ModelValueStorage { fn read_value, +Serde, +ModelValueKey>(self: @WorldStorage, keys: K) -> V { Self::read_value_from_id(self, entity_id_from_keys(@keys)) @@ -231,20 +231,20 @@ impl ModelValueStorageWorldStorageImpl< *self.dispatcher, ModelValue::::selector(*self.namespace_hash), ModelIndex::Id(entity_id), - ModelValue::::layout() + ModelValue::::layout(), ); match ModelValue::::from_serialized(values) { Option::Some(entity) => entity, Option::None => { panic!( - "Value: deserialization failed. Ensure the length of the keys tuple is matching the number of #[key] fields in the model struct." + "Value: deserialization failed. Ensure the length of the keys tuple is matching the number of #[key] fields in the model struct.", ) - } + }, } } fn read_values, +Serde, +ModelValueKey>( - self: @WorldStorage, keys: Span + self: @WorldStorage, keys: Span, ) -> Array { let mut entity_ids: Array = array![]; for k in keys { @@ -264,23 +264,23 @@ impl ModelValueStorageWorldStorageImpl< *self.dispatcher, ModelValue::::selector(*self.namespace_hash), indexes.span(), - ModelValue::::layout() + ModelValue::::layout(), ) { let mut v = *v; match ModelValue::::from_serialized(v) { Option::Some(value) => values.append(value), Option::None => { panic!( - "Value: deserialization failed. Ensure the length of the keys tuple is matching the number of #[key] fields in the model struct." + "Value: deserialization failed. Ensure the length of the keys tuple is matching the number of #[key] fields in the model struct.", ) - } + }, } }; values } fn write_value, +Serde, +ModelValueKey>( - ref self: WorldStorage, keys: K, value: @V + ref self: WorldStorage, keys: K, value: @V, ) { IWorldDispatcherTrait::set_entity( self.dispatcher, @@ -288,12 +288,12 @@ impl ModelValueStorageWorldStorageImpl< // We need Id here to trigger the store update event. ModelIndex::Id(entity_id_from_serialized_keys(serialize_inline::(@keys))), ModelValue::::serialized_values(value), - ModelValue::::layout() + ModelValue::::layout(), ); } fn write_values, +Serde, +ModelValueKey>( - ref self: WorldStorage, keys: Span, values: Span<@V> + ref self: WorldStorage, keys: Span, values: Span<@V>, ) { let mut ids: Array = array![]; for k in keys { @@ -309,7 +309,7 @@ impl ModelValueStorageWorldStorageImpl< ModelValue::::selector(self.namespace_hash), ModelIndex::Id(entity_id), ModelValue::::serialized_values(value), - ModelValue::::layout() + ModelValue::::layout(), ); } @@ -334,18 +334,18 @@ impl ModelValueStorageWorldStorageImpl< ModelValue::::selector(self.namespace_hash), indexes.span(), all_values.span(), - ModelValue::::layout() + ModelValue::::layout(), ); } } #[cfg(target: "test")] pub impl EventStorageTestWorldStorageImpl< - E, +Event + E, +Event, > of dojo::event::EventStorageTest { fn emit_event_test(ref self: WorldStorage, event: @E) { let world_test = dojo::world::IWorldTestDispatcher { - contract_address: self.dispatcher.contract_address + contract_address: self.dispatcher.contract_address, }; dojo::world::IWorldTestDispatcherTrait::emit_event_test( world_test, @@ -360,18 +360,18 @@ pub impl EventStorageTestWorldStorageImpl< /// checks. #[cfg(target: "test")] pub impl ModelStorageTestWorldStorageImpl< - M, +Model, +Drop + M, +Model, +Drop, > of dojo::model::ModelStorageTest { fn write_model_test(ref self: WorldStorage, model: @M) { let world_test = dojo::world::IWorldTestDispatcher { - contract_address: self.dispatcher.contract_address + contract_address: self.dispatcher.contract_address, }; dojo::world::IWorldTestDispatcherTrait::set_entity_test( world_test, Model::::selector(self.namespace_hash), ModelIndex::Keys(Model::serialized_keys(model)), Model::::serialized_values(model), - Model::::layout() + Model::::layout(), ); } @@ -383,14 +383,14 @@ pub impl ModelStorageTestWorldStorageImpl< fn erase_model_test(ref self: WorldStorage, model: @M) { let world_test = dojo::world::IWorldTestDispatcher { - contract_address: self.dispatcher.contract_address + contract_address: self.dispatcher.contract_address, }; dojo::world::IWorldTestDispatcherTrait::delete_entity_test( world_test, Model::::selector(self.namespace_hash), ModelIndex::Keys(Model::serialized_keys(model)), - Model::::layout() + Model::::layout(), ); } @@ -402,20 +402,20 @@ pub impl ModelStorageTestWorldStorageImpl< fn erase_model_ptr_test(ref self: WorldStorage, ptr: ModelPtr) { let world_test = dojo::world::IWorldTestDispatcher { - contract_address: self.dispatcher.contract_address + contract_address: self.dispatcher.contract_address, }; dojo::world::IWorldTestDispatcherTrait::delete_entity_test( world_test, Model::::selector(self.namespace_hash), ModelIndex::Id(ptr.id), - Model::::layout() + Model::::layout(), ); } fn erase_models_ptrs_test(ref self: WorldStorage, ptrs: Span>) { let world_test = dojo::world::IWorldTestDispatcher { - contract_address: self.dispatcher.contract_address + contract_address: self.dispatcher.contract_address, }; for ptr in ptrs { @@ -423,7 +423,7 @@ pub impl ModelStorageTestWorldStorageImpl< world_test, Model::::selector(self.namespace_hash), ModelIndex::Id(*ptr.id), - Model::::layout() + Model::::layout(), ); } } @@ -433,16 +433,16 @@ pub impl ModelStorageTestWorldStorageImpl< /// checks. #[cfg(target: "test")] pub impl ModelValueStorageTestWorldStorageImpl< - V, +ModelValue + V, +ModelValue, > of dojo::model::ModelValueStorageTest { fn write_value_test, +Serde, +ModelValueKey>( - ref self: WorldStorage, keys: K, value: @V + ref self: WorldStorage, keys: K, value: @V, ) { Self::write_value_from_id_test(ref self, dojo::utils::entity_id_from_keys(@keys), value); } fn write_values_test, +Serde, +ModelValueKey>( - ref self: WorldStorage, keys: Span, values: Span<@V> + ref self: WorldStorage, keys: Span, values: Span<@V>, ) { let mut ids: Array = array![]; for k in keys { @@ -454,7 +454,7 @@ pub impl ModelValueStorageTestWorldStorageImpl< fn write_value_from_id_test(ref self: WorldStorage, entity_id: felt252, value: @V) { let world_test = dojo::world::IWorldTestDispatcher { - contract_address: self.dispatcher.contract_address + contract_address: self.dispatcher.contract_address, }; dojo::world::IWorldTestDispatcherTrait::set_entity_test( @@ -462,12 +462,12 @@ pub impl ModelValueStorageTestWorldStorageImpl< ModelValue::::selector(self.namespace_hash), ModelIndex::Id(entity_id), ModelValue::::serialized_values(value), - ModelValue::::layout() + ModelValue::::layout(), ); } fn write_values_from_ids_test( - ref self: WorldStorage, entity_ids: Span, values: Span<@V> + ref self: WorldStorage, entity_ids: Span, values: Span<@V>, ) { let mut i = 0; loop { @@ -497,7 +497,7 @@ fn update_serialized_member( world, model_id, ModelIndex::MemberId((entity_id, member_id)), values, field_layout, ) }, - Option::None => panic_with_felt252('bad member id') + Option::None => panic_with_felt252('bad member id'), } } @@ -512,10 +512,10 @@ fn get_serialized_member( match find_model_field_layout(layout, member_id) { Option::Some(field_layout) => { IWorldDispatcherTrait::entity( - world, model_id, ModelIndex::MemberId((entity_id, member_id)), field_layout + world, model_id, ModelIndex::MemberId((entity_id, member_id)), field_layout, ) }, - Option::None => panic_with_felt252('bad member id') + Option::None => panic_with_felt252('bad member id'), } } diff --git a/crates/dojo/core/src/world/world_contract.cairo b/crates/dojo/core/src/world/world_contract.cairo index ea1a10e1ea..f3654b37e3 100644 --- a/crates/dojo/core/src/world/world_contract.cairo +++ b/crates/dojo/core/src/world/world_contract.cairo @@ -32,22 +32,22 @@ pub mod world { }; pub use starknet::storage::{ StorageMapReadAccess, StorageMapWriteAccess, StoragePointerReadAccess, - StoragePointerWriteAccess + StoragePointerWriteAccess, }; use dojo::world::errors; use dojo::contract::components::upgradeable::{ - IUpgradeableDispatcher, IUpgradeableDispatcherTrait + IUpgradeableDispatcher, IUpgradeableDispatcherTrait, }; use dojo::meta::{ Layout, IStoredResourceDispatcher, IStoredResourceDispatcherTrait, IDeployedResourceDispatcher, IDeployedResourceDispatcherTrait, LayoutCompareTrait, - StructCompareTrait + StructCompareTrait, }; use dojo::model::{Model, ResourceMetadata, metadata, ModelIndex}; use dojo::storage; use dojo::utils::{ - entity_id_from_serialized_keys, bytearray_hash, selector_from_namespace_and_name + entity_id_from_serialized_keys, bytearray_hash, selector_from_namespace_and_name, }; use dojo::world::{IWorld, IUpgradeableWorld, Resource, ResourceIsNoneTrait}; use super::Permission; @@ -112,14 +112,14 @@ pub mod world { #[key] pub resource: felt252, pub uri: ByteArray, - pub hash: felt252 + pub hash: felt252, } #[derive(Drop, starknet::Event)] pub struct NamespaceRegistered { #[key] pub namespace: ByteArray, - pub hash: felt252 + pub hash: felt252, } #[derive(Drop, starknet::Event)] @@ -204,7 +204,7 @@ pub mod world { pub resource: felt252, #[key] pub contract: ContractAddress, - pub value: bool + pub value: bool, } #[derive(Drop, starknet::Event)] @@ -272,8 +272,8 @@ pub mod world { .write( metadata::resource_metadata_selector(internal_ns_hash), Resource::Model( - (metadata::default_address(), metadata::default_class_hash().into()) - ) + (metadata::default_address(), metadata::default_class_hash().into()), + ), ); self.emit(WorldSpawned { creator, class_hash: world_class_hash }); @@ -287,13 +287,13 @@ pub mod world { model_selector: felt252, index: ModelIndex, values: Span, - layout: Layout + layout: Layout, ) { self.set_entity_internal(model_selector, index, values, layout); } fn delete_entity_test( - ref self: ContractState, model_selector: felt252, index: ModelIndex, layout: Layout + ref self: ContractState, model_selector: felt252, index: ModelIndex, layout: Layout, ) { self.delete_entity_internal(model_selector, index, layout); } @@ -307,19 +307,22 @@ pub mod world { self .emit( EventEmitted { - selector: event_selector, system_address: get_caller_address(), keys, values - } + selector: event_selector, + system_address: get_caller_address(), + keys, + values, + }, ); } fn dojo_contract_address( - self: @ContractState, contract_selector: felt252 + self: @ContractState, contract_selector: felt252, ) -> ContractAddress { match self.resources.read(contract_selector) { Resource::Contract((a, _)) => a, _ => core::panics::panic_with_byte_array( - @format!("Contract not registered: {}", contract_selector) - ) + @format!("Contract not registered: {}", contract_selector), + ), } } } @@ -332,14 +335,14 @@ pub mod world { let mut values = storage::entity_model::read_model_entity( metadata::resource_metadata_selector(internal_ns_hash), entity_id_from_serialized_keys([resource_selector].span()), - Model::::layout() + Model::::layout(), ); let mut keys = [resource_selector].span(); match Model::::from_serialized(keys, values) { Option::Some(x) => x, - Option::None => panic!("Model `ResourceMetadata`: deserialization failed.") + Option::None => panic!("Model `ResourceMetadata`: deserialization failed."), } } @@ -352,7 +355,7 @@ pub mod world { metadata::resource_metadata_selector(internal_ns_hash), entity_id_from_serialized_keys([metadata.resource_id].span()), metadata.serialized_values(), - Model::::layout() + Model::::layout(), ); self @@ -360,8 +363,8 @@ pub mod world { MetadataUpdate { resource: metadata.resource_id, uri: metadata.metadata_uri, - hash: metadata.metadata_hash - } + hash: metadata.metadata_hash, + }, ); } @@ -462,8 +465,8 @@ pub mod world { name: event_name.clone(), namespace: namespace.clone(), address: contract_address, - class_hash - } + class_hash, + }, ); } @@ -497,17 +500,19 @@ pub mod world { Resource::Event((model_address, _)) => { prev_address = model_address; }, Resource::Unregistered => { panic_with_byte_array( - @errors::resource_not_registered_details(@namespace, @event_name) + @errors::resource_not_registered_details(@namespace, @event_name), ) }, _ => panic_with_byte_array( - @errors::resource_conflict(@format!("{}-{}", @namespace, @event_name), @"event") - ) + @errors::resource_conflict( + @format!("{}-{}", @namespace, @event_name), @"event", + ), + ), }; self .assert_resource_upgradability( - @namespace, @event_name, prev_address, new_contract_address + @namespace, @event_name, prev_address, new_contract_address, ); self @@ -521,7 +526,7 @@ pub mod world { prev_address, address: new_contract_address, class_hash, - } + }, ); } @@ -566,8 +571,8 @@ pub mod world { name: model_name.clone(), namespace: namespace.clone(), address: contract_address, - class_hash - } + class_hash, + }, ); } @@ -601,17 +606,19 @@ pub mod world { Resource::Model((model_address, _)) => { prev_address = model_address; }, Resource::Unregistered => { panic_with_byte_array( - @errors::resource_not_registered_details(@namespace, @model_name) + @errors::resource_not_registered_details(@namespace, @model_name), ) }, _ => panic_with_byte_array( - @errors::resource_conflict(@format!("{}-{}", @namespace, @model_name), @"model") - ) + @errors::resource_conflict( + @format!("{}-{}", @namespace, @model_name), @"model", + ), + ), }; self .assert_resource_upgradability( - @namespace, @model_name, prev_address, new_contract_address + @namespace, @model_name, prev_address, new_contract_address, ); self @@ -625,7 +632,7 @@ pub mod world { prev_address, address: new_contract_address, class_hash, - } + }, ); } @@ -638,7 +645,7 @@ pub mod world { match self.resources.read(hash) { Resource::Namespace => panic_with_byte_array( - @errors::namespace_already_registered(@namespace) + @errors::namespace_already_registered(@namespace), ), Resource::Unregistered => { self.resources.write(hash, Resource::Namespace(namespace.clone())); @@ -648,7 +655,7 @@ pub mod world { }, _ => { panic_with_byte_array(@errors::resource_conflict(@namespace, @"namespace")); - } + }, }; } @@ -665,7 +672,7 @@ pub mod world { let contract = IDeployedResourceDispatcher { contract_address }; let contract_name = contract.dojo_name(); let contract_selector = selector_from_namespace_and_name( - namespace_hash, @contract_name + namespace_hash, @contract_name, ); self.assert_name(@contract_name); @@ -673,7 +680,7 @@ pub mod world { let maybe_existing_contract = self.resources.read(contract_selector); if !maybe_existing_contract.is_unregistered() { panic_with_byte_array( - @errors::contract_already_registered(@namespace, @contract_name) + @errors::contract_already_registered(@namespace, @contract_name), ); } @@ -692,14 +699,14 @@ pub mod world { .emit( ContractRegistered { salt, class_hash, address: contract_address, namespace, name: contract_name, - } + }, ); contract_address } fn upgrade_contract( - ref self: ContractState, namespace: ByteArray, class_hash: ClassHash + ref self: ContractState, namespace: ByteArray, class_hash: ClassHash, ) -> ClassHash { // Only contracts use an external salt during registration. To ensure the // upgrade can also be done into a multicall, we combine the transaction hash @@ -709,7 +716,8 @@ pub mod world { [ starknet::get_tx_info().unbox().transaction_hash, dojo::utils::bytearray_hash(@namespace), - ].span() + ] + .span(), ); let (new_contract_address, _) = deploy_syscall(class_hash, salt, [].span(), false) @@ -720,14 +728,14 @@ pub mod world { let contract = IDeployedResourceDispatcher { contract_address: new_contract_address }; let contract_name = contract.dojo_name(); let contract_selector = selector_from_namespace_and_name( - namespace_hash, @contract_name + namespace_hash, @contract_name, ); // If namespace and name are the same, the contract is already registered and we // can upgrade it. match self.resources.read(contract_selector) { Resource::Contract(( - contract_address, _ + contract_address, _, )) => { self.assert_caller_permissions(contract_selector, Permission::Owner); @@ -738,14 +746,14 @@ pub mod world { }, Resource::Unregistered => { panic_with_byte_array( - @errors::resource_not_registered_details(@namespace, @contract_name) + @errors::resource_not_registered_details(@namespace, @contract_name), ) }, _ => panic_with_byte_array( @errors::resource_conflict( - @format!("{}-{}", @namespace, @contract_name), @"contract" - ) - ) + @format!("{}-{}", @namespace, @contract_name), @"contract", + ), + ), } } @@ -754,7 +762,7 @@ pub mod world { if self.initialized_contracts.read(selector) { let dispatcher = IDeployedResourceDispatcher { contract_address }; panic_with_byte_array( - @errors::contract_already_initialized(@dispatcher.dojo_name()) + @errors::contract_already_initialized(@dispatcher.dojo_name()), ); } else { self.assert_caller_permissions(selector, Permission::Owner); @@ -765,7 +773,7 @@ pub mod world { // starknet::syscalls::call_contract_syscall( - contract_address, DOJO_INIT_SELECTOR, init_calldata + contract_address, DOJO_INIT_SELECTOR, init_calldata, ) .unwrap_syscall(); @@ -775,7 +783,7 @@ pub mod world { } } else { panic_with_byte_array( - @errors::resource_conflict(@format!("{selector}"), @"contract") + @errors::resource_conflict(@format!("{selector}"), @"contract"), ); } } @@ -802,11 +810,11 @@ pub mod world { system_address: get_caller_address(), keys, values, - } + }, ); } else { panic_with_byte_array( - @errors::resource_conflict(@format!("{event_selector}"), @"event") + @errors::resource_conflict(@format!("{event_selector}"), @"event"), ); } } @@ -822,7 +830,7 @@ pub mod world { if keys.len() != values.len() { panic_with_byte_array( - @errors::lengths_mismatch(@"keys", @"values", @"emit_events") + @errors::lengths_mismatch(@"keys", @"values", @"emit_events"), ); } @@ -839,26 +847,29 @@ pub mod world { system_address: get_caller_address(), keys: *keys[i], values: *values[i], - } + }, ); i += 1; } } else { panic_with_byte_array( - @errors::resource_conflict(@format!("{event_selector}"), @"event") + @errors::resource_conflict(@format!("{event_selector}"), @"event"), ); } } fn entity( - self: @ContractState, model_selector: felt252, index: ModelIndex, layout: Layout + self: @ContractState, model_selector: felt252, index: ModelIndex, layout: Layout, ) -> Span { self.get_entity_internal(model_selector, index, layout) } fn entities( - self: @ContractState, model_selector: felt252, indexes: Span, layout: Layout + self: @ContractState, + model_selector: felt252, + indexes: Span, + layout: Layout, ) -> Span> { let mut models: Array> = array![]; @@ -874,14 +885,14 @@ pub mod world { model_selector: felt252, index: ModelIndex, values: Span, - layout: Layout + layout: Layout, ) { if let Resource::Model((_, _)) = self.resources.read(model_selector) { self.assert_caller_permissions(model_selector, Permission::Writer); self.set_entity_internal(model_selector, index, values, layout); } else { panic_with_byte_array( - @errors::resource_conflict(@format!("{model_selector}"), @"model") + @errors::resource_conflict(@format!("{model_selector}"), @"model"), ); } } @@ -891,11 +902,11 @@ pub mod world { model_selector: felt252, indexes: Span, values: Span>, - layout: Layout + layout: Layout, ) { if indexes.len() != values.len() { panic_with_byte_array( - @errors::lengths_mismatch(@"indexes", @"values", @"set_entities") + @errors::lengths_mismatch(@"indexes", @"values", @"set_entities"), ); } @@ -914,20 +925,20 @@ pub mod world { }; } else { panic_with_byte_array( - @errors::resource_conflict(@format!("{model_selector}"), @"model") + @errors::resource_conflict(@format!("{model_selector}"), @"model"), ); } } fn delete_entity( - ref self: ContractState, model_selector: felt252, index: ModelIndex, layout: Layout + ref self: ContractState, model_selector: felt252, index: ModelIndex, layout: Layout, ) { if let Resource::Model((_, _)) = self.resources.read(model_selector) { self.assert_caller_permissions(model_selector, Permission::Writer); self.delete_entity_internal(model_selector, index, layout); } else { panic_with_byte_array( - @errors::resource_conflict(@format!("{model_selector}"), @"model") + @errors::resource_conflict(@format!("{model_selector}"), @"model"), ); } } @@ -936,7 +947,7 @@ pub mod world { ref self: ContractState, model_selector: felt252, indexes: Span, - layout: Layout + layout: Layout, ) { if let Resource::Model((_, _)) = self.resources.read(model_selector) { self.assert_caller_permissions(model_selector, Permission::Writer); @@ -946,7 +957,7 @@ pub mod world { } } else { panic_with_byte_array( - @errors::resource_conflict(@format!("{model_selector}"), @"model") + @errors::resource_conflict(@format!("{model_selector}"), @"model"), ); } } @@ -1000,7 +1011,7 @@ pub mod world { /// * `resource_selector` - the selector of the resource. /// * `permission` - the required permission. fn assert_caller_permissions( - self: @ContractState, resource_selector: felt252, permission: Permission + self: @ContractState, resource_selector: felt252, permission: Permission, ) { let caller = get_caller_address(); @@ -1027,7 +1038,7 @@ pub mod world { Resource::Unregistered => { panic_with_byte_array(@errors::resource_not_registered(resource_selector)) }, - _ => self.panic_with_details(caller, resource_selector, permission) + _ => self.panic_with_details(caller, resource_selector, permission), }; if permission == Permission::Writer { @@ -1075,7 +1086,7 @@ pub mod world { namespace: @ByteArray, name: @ByteArray, prev_address: ContractAddress, - new_address: ContractAddress + new_address: ContractAddress, ) { let resource = IStoredResourceDispatcher { contract_address: prev_address }; let old_layout = resource.layout(); @@ -1104,30 +1115,30 @@ pub mod world { self: @ContractState, caller: ContractAddress, resource_selector: felt252, - permission: Permission + permission: Permission, ) -> core::never { let resource_name = match self.resources.read(resource_selector) { Resource::Contract(( - contract_address, _ + contract_address, _, )) => { let d = IDeployedResourceDispatcher { contract_address }; format!("contract (or its namespace) `{}`", d.dojo_name()) }, Resource::Event(( - contract_address, _ + contract_address, _, )) => { let d = IDeployedResourceDispatcher { contract_address }; format!("event (or its namespace) `{}`", d.dojo_name()) }, Resource::Model(( - contract_address, _ + contract_address, _, )) => { let d = IDeployedResourceDispatcher { contract_address }; format!("model (or its namespace) `{}`", d.dojo_name()) }, Resource::Namespace(ns) => { format!("namespace `{}`", ns) }, Resource::World => { format!("world") }, - Resource::Unregistered => { panic!("Unreachable") } + Resource::Unregistered => { panic!("Unreachable") }, }; let caller_name = if caller == get_tx_info().account_contract_address { @@ -1146,7 +1157,7 @@ pub mod world { }; panic_with_byte_array( - @format!("{} does NOT have {} role on {}", caller_name, permission, resource_name) + @format!("{} does NOT have {} role on {}", caller_name, permission, resource_name), ) } @@ -1158,7 +1169,7 @@ pub mod world { fn is_namespace_registered(self: @ContractState, namespace_hash: felt252) -> bool { match self.resources.read(namespace_hash) { Resource::Namespace => true, - _ => false + _ => false, } } @@ -1175,35 +1186,35 @@ pub mod world { model_selector: felt252, index: ModelIndex, values: Span, - layout: Layout + layout: Layout, ) { match index { ModelIndex::Keys(keys) => { let entity_id = entity_id_from_serialized_keys(keys); storage::entity_model::write_model_entity( - model_selector, entity_id, values, layout + model_selector, entity_id, values, layout, ); self.emit(StoreSetRecord { selector: model_selector, keys, values, entity_id }); }, ModelIndex::Id(entity_id) => { storage::entity_model::write_model_entity( - model_selector, entity_id, values, layout + model_selector, entity_id, values, layout, ); self.emit(StoreUpdateRecord { selector: model_selector, entity_id, values }); }, ModelIndex::MemberId(( - entity_id, member_selector + entity_id, member_selector, )) => { storage::entity_model::write_model_member( - model_selector, entity_id, member_selector, values, layout + model_selector, entity_id, member_selector, values, layout, ); self .emit( StoreUpdateMember { - selector: model_selector, entity_id, member_selector, values - } + selector: model_selector, entity_id, member_selector, values, + }, ); - } + }, } } @@ -1215,7 +1226,7 @@ pub mod world { /// * `index` - The index of the record/entity to delete. /// * `layout` - The memory layout of the model. fn delete_entity_internal( - ref self: ContractState, model_selector: felt252, index: ModelIndex, layout: Layout + ref self: ContractState, model_selector: felt252, index: ModelIndex, layout: Layout, ) { match index { ModelIndex::Keys(keys) => { @@ -1227,7 +1238,7 @@ pub mod world { storage::entity_model::delete_model_entity(model_selector, entity_id, layout); self.emit(StoreDelRecord { selector: model_selector, entity_id }); }, - ModelIndex::MemberId(_) => { panic_with_felt252(errors::DELETE_ENTITY_MEMBER); } + ModelIndex::MemberId(_) => { panic_with_felt252(errors::DELETE_ENTITY_MEMBER); }, } } @@ -1239,7 +1250,7 @@ pub mod world { /// * `index` - The entity/member to read for the given model. /// * `layout` - The memory layout of the model. fn get_entity_internal( - self: @ContractState, model_selector: felt252, index: ModelIndex, layout: Layout + self: @ContractState, model_selector: felt252, index: ModelIndex, layout: Layout, ) -> Span { match index { ModelIndex::Keys(keys) => { @@ -1250,12 +1261,12 @@ pub mod world { storage::entity_model::read_model_entity(model_selector, entity_id, layout) }, ModelIndex::MemberId(( - entity_id, member_id + entity_id, member_id, )) => { storage::entity_model::read_model_member( - model_selector, entity_id, member_id, layout + model_selector, entity_id, member_id, layout, ) - } + }, } } diff --git a/crates/dojo/lang/Scarb.lock b/crates/dojo/lang/Scarb.lock index 2f26886db2..26d59f4266 100644 --- a/crates/dojo/lang/Scarb.lock +++ b/crates/dojo/lang/Scarb.lock @@ -3,4 +3,4 @@ version = 1 [[package]] name = "dojo_plugin" -version = "2.8.4" +version = "2.9.2" diff --git a/crates/dojo/lang/Scarb.toml b/crates/dojo/lang/Scarb.toml index 6371a4614c..fd5f16eab8 100644 --- a/crates/dojo/lang/Scarb.toml +++ b/crates/dojo/lang/Scarb.toml @@ -1,6 +1,6 @@ [package] name = "dojo_plugin" -version = "2.8.4" +version = "2.9.2" [cairo-plugin] builtin = true diff --git a/crates/dojo/lang/src/attribute_macros/contract.rs b/crates/dojo/lang/src/attribute_macros/contract.rs index 2f9c94c9b7..9338bafe91 100644 --- a/crates/dojo/lang/src/attribute_macros/contract.rs +++ b/crates/dojo/lang/src/attribute_macros/contract.rs @@ -152,6 +152,7 @@ impl DojoContract { systems: contract.systems.clone(), })), code_mappings, + diagnostics_note: None, }), diagnostics: contract.diagnostics, remove_original_item: true, diff --git a/crates/dojo/lang/src/attribute_macros/event.rs b/crates/dojo/lang/src/attribute_macros/event.rs index 1f7762be44..c533c2eb98 100644 --- a/crates/dojo/lang/src/attribute_macros/event.rs +++ b/crates/dojo/lang/src/attribute_macros/event.rs @@ -158,6 +158,7 @@ impl DojoEvent { content: code, aux_data: Some(DynGeneratedFileAuxData::new(aux_data)), code_mappings, + diagnostics_note: None, }), diagnostics, remove_original_item: false, diff --git a/crates/dojo/lang/src/attribute_macros/interface.rs b/crates/dojo/lang/src/attribute_macros/interface.rs index 7e257095c4..f0a598c1ff 100644 --- a/crates/dojo/lang/src/attribute_macros/interface.rs +++ b/crates/dojo/lang/src/attribute_macros/interface.rs @@ -86,6 +86,7 @@ impl DojoInterface { content: code, aux_data: None, code_mappings, + diagnostics_note: None, }), diagnostics: interface.diagnostics, remove_original_item: true, diff --git a/crates/dojo/lang/src/attribute_macros/model.rs b/crates/dojo/lang/src/attribute_macros/model.rs index 9987f5e8b6..71030c508a 100644 --- a/crates/dojo/lang/src/attribute_macros/model.rs +++ b/crates/dojo/lang/src/attribute_macros/model.rs @@ -201,6 +201,7 @@ impl DojoModel { content: code, aux_data: Some(DynGeneratedFileAuxData::new(aux_data)), code_mappings, + diagnostics_note: None, }), diagnostics, remove_original_item: false, diff --git a/crates/dojo/lang/src/derive_macros/mod.rs b/crates/dojo/lang/src/derive_macros/mod.rs index 9377a4d7eb..40f2219dff 100644 --- a/crates/dojo/lang/src/derive_macros/mod.rs +++ b/crates/dojo/lang/src/derive_macros/mod.rs @@ -55,6 +55,7 @@ pub fn dojo_derive_all( content: code, aux_data: None, code_mappings, + diagnostics_note: None, }), diagnostics, remove_original_item: false, diff --git a/crates/dojo/lang/src/inline_macros/delete.rs b/crates/dojo/lang/src/inline_macros/delete.rs index 91070ceb65..b3105a5a70 100644 --- a/crates/dojo/lang/src/inline_macros/delete.rs +++ b/crates/dojo/lang/src/inline_macros/delete.rs @@ -105,6 +105,7 @@ impl InlineMacroExprPlugin for DeleteMacro { content: code, code_mappings, aux_data: None, + diagnostics_note: None, }), diagnostics: vec![], } diff --git a/crates/dojo/lang/src/inline_macros/emit.rs b/crates/dojo/lang/src/inline_macros/emit.rs index 57b87b424c..d33aeb87a5 100644 --- a/crates/dojo/lang/src/inline_macros/emit.rs +++ b/crates/dojo/lang/src/inline_macros/emit.rs @@ -109,6 +109,7 @@ impl InlineMacroExprPlugin for EmitMacro { content: code, code_mappings, aux_data: None, + diagnostics_note: None, }), diagnostics: vec![], } diff --git a/crates/dojo/lang/src/inline_macros/get.rs b/crates/dojo/lang/src/inline_macros/get.rs index f2c8f9a601..d66a8f0de6 100644 --- a/crates/dojo/lang/src/inline_macros/get.rs +++ b/crates/dojo/lang/src/inline_macros/get.rs @@ -99,6 +99,7 @@ impl InlineMacroExprPlugin for GetMacro { content: code, code_mappings, aux_data: None, + diagnostics_note: None, }), diagnostics: vec![], } diff --git a/crates/dojo/lang/src/inline_macros/get_models_test_class_hashes.rs b/crates/dojo/lang/src/inline_macros/get_models_test_class_hashes.rs index 1cfcfe0ea4..dd7e25310e 100644 --- a/crates/dojo/lang/src/inline_macros/get_models_test_class_hashes.rs +++ b/crates/dojo/lang/src/inline_macros/get_models_test_class_hashes.rs @@ -97,6 +97,7 @@ impl InlineMacroExprPlugin for GetModelsTestClassHashes { content: code, code_mappings, aux_data: None, + diagnostics_note: None, }), diagnostics: vec![], } diff --git a/crates/dojo/lang/src/inline_macros/selector_from_tag.rs b/crates/dojo/lang/src/inline_macros/selector_from_tag.rs index 4145100d4e..f8c7e8721c 100644 --- a/crates/dojo/lang/src/inline_macros/selector_from_tag.rs +++ b/crates/dojo/lang/src/inline_macros/selector_from_tag.rs @@ -67,6 +67,7 @@ impl InlineMacroExprPlugin for SelectorFromTagMacro { content: code, code_mappings, aux_data: None, + diagnostics_note: None, }), diagnostics: vec![], } diff --git a/crates/dojo/lang/src/inline_macros/set.rs b/crates/dojo/lang/src/inline_macros/set.rs index 7a040fbae9..3c53812c04 100644 --- a/crates/dojo/lang/src/inline_macros/set.rs +++ b/crates/dojo/lang/src/inline_macros/set.rs @@ -121,6 +121,7 @@ impl InlineMacroExprPlugin for SetMacro { content: code, code_mappings, aux_data: None, + diagnostics_note: None, }), diagnostics: vec![], } diff --git a/crates/dojo/lang/src/inline_macros/spawn_test_world.rs b/crates/dojo/lang/src/inline_macros/spawn_test_world.rs index e40004bebc..9df8dbc79c 100644 --- a/crates/dojo/lang/src/inline_macros/spawn_test_world.rs +++ b/crates/dojo/lang/src/inline_macros/spawn_test_world.rs @@ -98,6 +98,7 @@ impl InlineMacroExprPlugin for SpawnTestWorld { content: code, code_mappings, aux_data: None, + diagnostics_note: None, }), diagnostics: vec![], } diff --git a/crates/dojo/test-utils/src/compiler.rs b/crates/dojo/test-utils/src/compiler.rs index 5266cf7f94..94c8f89af9 100644 --- a/crates/dojo/test-utils/src/compiler.rs +++ b/crates/dojo/test-utils/src/compiler.rs @@ -171,6 +171,7 @@ pub fn copy_build_project_temp( include_target_kinds: vec![], exclude_target_kinds: vec![TargetKind::TEST], features: features_opts, + ignore_cairo_version: true, }, &ws, ) @@ -319,7 +320,8 @@ pub fn corelib() -> PathBuf { let features_opts = FeaturesOpts { features: FeaturesSelector::AllFeatures, no_default_features: false }; - let compilation_units = ops::generate_compilation_units(&resolve, &features_opts, &ws).unwrap(); + let compilation_units = + ops::generate_compilation_units(&resolve, &features_opts, true, &ws).unwrap(); if let CompilationUnit::Cairo(unit) = &compilation_units[0] { unit.core_package_component().expect("should have component").targets[0] diff --git a/crates/dojo/world/abigen/src/main.rs b/crates/dojo/world/abigen/src/main.rs index 58c139d859..6ed928897f 100644 --- a/crates/dojo/world/abigen/src/main.rs +++ b/crates/dojo/world/abigen/src/main.rs @@ -23,7 +23,7 @@ use scarb::ops::{CompileOpts, FeaturesOpts, FeaturesSelector}; const SCARB_MANIFEST: &str = "crates/dojo/core/Scarb.toml"; const WORLD_ARTIFACT: &str = "crates/dojo/core/target/dev/dojo_world.contract_class.json"; const MODEL_ARTIFACT: &str = - "crates/dojo/core/target/dev/dojo_resource_metadata.contract_class.json"; + "crates/dojo/core/target/dev/dojo_m_ResourceMetadata.contract_class.json"; const OUT_DIR: &str = "crates/dojo/world/src/contracts/abigen"; /// Entrypoint for the abigen program to generate or check the bindings for the world and model @@ -170,6 +170,7 @@ fn compile_dojo_core() -> Result<()> { include_target_kinds: vec![], exclude_target_kinds: vec![TargetKind::TEST], features: features_opts, + ignore_cairo_version: false, }, &ws, ) diff --git a/crates/dojo/world/src/contracts/abigen/model.rs b/crates/dojo/world/src/contracts/abigen/model.rs index c29d4506c7..6f2af4dfa8 100644 --- a/crates/dojo/world/src/contracts/abigen/model.rs +++ b/crates/dojo/world/src/contracts/abigen/model.rs @@ -221,6 +221,7 @@ impl cainome::cairo_serde::CairoSerde for ModelDef { pub struct ResourceMetadata { pub resource_id: starknet::core::types::Felt, pub metadata_uri: cainome::cairo_serde::ByteArray, + pub metadata_hash: starknet::core::types::Felt, } impl cainome::cairo_serde::CairoSerde for ResourceMetadata { type RustType = Self; @@ -230,12 +231,14 @@ impl cainome::cairo_serde::CairoSerde for ResourceMetadata { let mut __size = 0; __size += starknet::core::types::Felt::cairo_serialized_size(&__rust.resource_id); __size += cainome::cairo_serde::ByteArray::cairo_serialized_size(&__rust.metadata_uri); + __size += starknet::core::types::Felt::cairo_serialized_size(&__rust.metadata_hash); __size } fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; __out.extend(starknet::core::types::Felt::cairo_serialize(&__rust.resource_id)); __out.extend(cainome::cairo_serde::ByteArray::cairo_serialize(&__rust.metadata_uri)); + __out.extend(starknet::core::types::Felt::cairo_serialize(&__rust.metadata_hash)); __out } fn cairo_deserialize( @@ -247,12 +250,15 @@ impl cainome::cairo_serde::CairoSerde for ResourceMetadata { __offset += starknet::core::types::Felt::cairo_serialized_size(&resource_id); let metadata_uri = cainome::cairo_serde::ByteArray::cairo_deserialize(__felts, __offset)?; __offset += cainome::cairo_serde::ByteArray::cairo_serialized_size(&metadata_uri); - Ok(ResourceMetadata { resource_id, metadata_uri }) + let metadata_hash = starknet::core::types::Felt::cairo_deserialize(__felts, __offset)?; + __offset += starknet::core::types::Felt::cairo_serialized_size(&metadata_hash); + Ok(ResourceMetadata { resource_id, metadata_uri, metadata_hash }) } } #[derive(Clone, serde::Serialize, serde::Deserialize, PartialEq, Debug)] pub struct ResourceMetadataValue { pub metadata_uri: cainome::cairo_serde::ByteArray, + pub metadata_hash: starknet::core::types::Felt, } impl cainome::cairo_serde::CairoSerde for ResourceMetadataValue { type RustType = Self; @@ -261,11 +267,13 @@ impl cainome::cairo_serde::CairoSerde for ResourceMetadataValue { fn cairo_serialized_size(__rust: &Self::RustType) -> usize { let mut __size = 0; __size += cainome::cairo_serde::ByteArray::cairo_serialized_size(&__rust.metadata_uri); + __size += starknet::core::types::Felt::cairo_serialized_size(&__rust.metadata_hash); __size } fn cairo_serialize(__rust: &Self::RustType) -> Vec { let mut __out: Vec = vec![]; __out.extend(cainome::cairo_serde::ByteArray::cairo_serialize(&__rust.metadata_uri)); + __out.extend(starknet::core::types::Felt::cairo_serialize(&__rust.metadata_hash)); __out } fn cairo_deserialize( @@ -275,7 +283,9 @@ impl cainome::cairo_serde::CairoSerde for ResourceMetadataValue { let mut __offset = __offset; let metadata_uri = cainome::cairo_serde::ByteArray::cairo_deserialize(__felts, __offset)?; __offset += cainome::cairo_serde::ByteArray::cairo_serialized_size(&metadata_uri); - Ok(ResourceMetadataValue { metadata_uri }) + let metadata_hash = starknet::core::types::Felt::cairo_deserialize(__felts, __offset)?; + __offset += starknet::core::types::Felt::cairo_serialized_size(&metadata_hash); + Ok(ResourceMetadataValue { metadata_uri, metadata_hash }) } } #[derive(Clone, serde::Serialize, serde::Deserialize, PartialEq, Debug)] @@ -584,6 +594,18 @@ impl ModelContract { } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] + pub fn ensure_unique(&self) -> cainome::cairo_serde::call::FCall { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + let __call = starknet::core::types::FunctionCall { + contract_address: self.address, + entry_point_selector: starknet::macros::selector!("ensure_unique"), + calldata: __calldata, + }; + cainome::cairo_serde::call::FCall::new(__call, self.provider()) + } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] pub fn ensure_values( &self, value: &ResourceMetadataValue, @@ -689,6 +711,18 @@ impl ModelContractReader

{ } #[allow(clippy::ptr_arg)] #[allow(clippy::too_many_arguments)] + pub fn ensure_unique(&self) -> cainome::cairo_serde::call::FCall { + use cainome::cairo_serde::CairoSerde; + let mut __calldata = vec![]; + let __call = starknet::core::types::FunctionCall { + contract_address: self.address, + entry_point_selector: starknet::macros::selector!("ensure_unique"), + calldata: __calldata, + }; + cainome::cairo_serde::call::FCall::new(__call, self.provider()) + } + #[allow(clippy::ptr_arg)] + #[allow(clippy::too_many_arguments)] pub fn ensure_values( &self, value: &ResourceMetadataValue, diff --git a/crates/katana/cairo/Cargo.toml b/crates/katana/cairo/Cargo.toml index dd0776c248..00f8565b91 100644 --- a/crates/katana/cairo/Cargo.toml +++ b/crates/katana/cairo/Cargo.toml @@ -18,7 +18,7 @@ cairo-lang-starknet = "2.7.0" cairo-lang-starknet-classes = "2.7.0" cairo-lang-utils = "2.7.0" cairo-vm = "1.0.1" -starknet_api = { git = "https://github.com/dojoengine/sequencer", tag = "v0.8.0-rc3.2" } +starknet_api = { git = "https://github.com/dojoengine/sequencer", rev = "802c5dc" } [features] # Some types that we used from cairo-vm implements the `Arbitrary` trait, diff --git a/crates/katana/executor/Cargo.toml b/crates/katana/executor/Cargo.toml index 785d18d3d4..93db00effa 100644 --- a/crates/katana/executor/Cargo.toml +++ b/crates/katana/executor/Cargo.toml @@ -7,17 +7,17 @@ version.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +katana-cairo = { workspace = true, optional = true } katana-primitives.workspace = true katana-provider.workspace = true katana-trie.workspace = true -parking_lot = { workspace = true, optional = true } -starknet = { workspace = true, optional = true } thiserror.workspace = true tracing.workspace = true -blockifier = { git = "https://github.com/dojoengine/sequencer", tag = "v0.8.0-rc3.2", features = [ "testing" ], optional = true } -katana-cairo = { workspace = true, optional = true } +blockifier = { git = "https://github.com/dojoengine/sequencer", rev = "802c5dc", features = [ "testing" ], optional = true } +parking_lot = { workspace = true, optional = true } +starknet = { workspace = true, optional = true } [dev-dependencies] alloy-primitives.workspace = true diff --git a/crates/katana/executor/src/implementation/blockifier/error.rs b/crates/katana/executor/src/implementation/blockifier/error.rs index 89b4d8ab4c..62e2779994 100644 --- a/crates/katana/executor/src/implementation/blockifier/error.rs +++ b/crates/katana/executor/src/implementation/blockifier/error.rs @@ -1,5 +1,4 @@ use blockifier::execution::errors::{EntryPointExecutionError, PreExecutionError}; -use blockifier::execution::execution_utils::format_panic_data; use blockifier::state::errors::StateError; use blockifier::transaction::errors::{ TransactionExecutionError, TransactionFeeError, TransactionPreValidationError, @@ -32,8 +31,8 @@ impl From for ExecutionError { impl From for ExecutionError { fn from(error: EntryPointExecutionError) -> Self { match error { - EntryPointExecutionError::ExecutionFailed { error_data } => { - Self::ExecutionFailed { reason: format_panic_data(&error_data) } + EntryPointExecutionError::ExecutionFailed { error_trace } => { + Self::ExecutionFailed { reason: error_trace.to_string() } } EntryPointExecutionError::InvalidExecutionInput { input_descriptor, info } => { Self::InvalidInput { input_descriptor, info } diff --git a/crates/katana/executor/src/implementation/blockifier/mod.rs b/crates/katana/executor/src/implementation/blockifier/mod.rs index d515beb5a9..dd27f0bd30 100644 --- a/crates/katana/executor/src/implementation/blockifier/mod.rs +++ b/crates/katana/executor/src/implementation/blockifier/mod.rs @@ -5,13 +5,12 @@ mod error; mod state; pub mod utils; -use std::num::NonZeroU128; - -use blockifier::blockifier::block::{BlockInfo, GasPrices}; use blockifier::context::BlockContext; use blockifier::state::cached_state::{self, MutRefState}; use blockifier::state::state_api::StateReader; -use katana_cairo::starknet_api::block::{BlockNumber, BlockTimestamp}; +use katana_cairo::starknet_api::block::{ + BlockInfo, BlockNumber, BlockTimestamp, GasPriceVector, GasPrices, NonzeroGasPrice, +}; use katana_primitives::block::{ExecutableBlock, GasPrices as KatanaGasPrices, PartialHeader}; use katana_primitives::env::{BlockEnv, CfgEnv}; use katana_primitives::fee::TxFeeInfo; @@ -102,17 +101,14 @@ impl<'a> StarknetVMProcessor<'a> { // TODO: should we enforce the gas price to not be 0, // as there's a flag to disable gas uasge instead? let eth_l1_gas_price = - NonZeroU128::new(header.l1_gas_prices.eth).unwrap_or(NonZeroU128::new(1).unwrap()); + NonzeroGasPrice::new(header.l1_gas_prices.eth.into()).unwrap_or(NonzeroGasPrice::MIN); let strk_l1_gas_price = - NonZeroU128::new(header.l1_gas_prices.strk).unwrap_or(NonZeroU128::new(1).unwrap()); + NonzeroGasPrice::new(header.l1_gas_prices.strk.into()).unwrap_or(NonzeroGasPrice::MIN); + let eth_l1_data_gas_price = NonzeroGasPrice::new(header.l1_data_gas_prices.eth.into()) + .unwrap_or(NonzeroGasPrice::MIN); + let strk_l1_data_gas_price = NonzeroGasPrice::new(header.l1_data_gas_prices.strk.into()) + .unwrap_or(NonzeroGasPrice::MIN); - // TODO: which values is correct for those one? - let eth_l1_data_gas_price = eth_l1_gas_price; - let strk_l1_data_gas_price = strk_l1_gas_price; - - // TODO: @kariy, not sure here if we should add some functions to alter it - // instead of cloning. Or did I miss a function? - // https://github.com/starkware-libs/blockifier/blob/a6200402ab635d8a8e175f7f135be5914c960007/crates/blockifier/src/context.rs#L23 let versioned_constants = self.block_context.versioned_constants().clone(); let chain_info = self.block_context.chain_info().clone(); let block_info = BlockInfo { @@ -120,10 +116,18 @@ impl<'a> StarknetVMProcessor<'a> { block_timestamp: timestamp, sequencer_address: utils::to_blk_address(header.sequencer_address), gas_prices: GasPrices { - eth_l1_gas_price, - strk_l1_gas_price, - eth_l1_data_gas_price, - strk_l1_data_gas_price, + eth_gas_prices: GasPriceVector { + l1_gas_price: eth_l1_gas_price, + l1_data_gas_price: eth_l1_data_gas_price, + // TODO: update to use the correct value + l2_gas_price: eth_l1_gas_price, + }, + strk_gas_prices: GasPriceVector { + l1_gas_price: strk_l1_gas_price, + l1_data_gas_price: strk_l1_data_gas_price, + // TODO: update to use the correct value + l2_gas_price: strk_l1_gas_price, + }, }, use_kzg_da: false, }; @@ -228,20 +232,38 @@ impl<'a> BlockExecutor<'a> for StarknetVMProcessor<'a> { } fn block_env(&self) -> BlockEnv { - let eth_l1_gas_price = self.block_context.block_info().gas_prices.eth_l1_gas_price; - let strk_l1_gas_price = self.block_context.block_info().gas_prices.strk_l1_gas_price; - BlockEnv { number: self.block_context.block_info().block_number.0, timestamp: self.block_context.block_info().block_timestamp.0, sequencer_address: utils::to_address(self.block_context.block_info().sequencer_address), l1_gas_prices: KatanaGasPrices { - eth: eth_l1_gas_price.into(), - strk: strk_l1_gas_price.into(), + eth: self.block_context.block_info().gas_prices.eth_gas_prices.l1_gas_price.get().0, + strk: self + .block_context + .block_info() + .gas_prices + .strk_gas_prices + .l1_gas_price + .get() + .0, }, l1_data_gas_prices: KatanaGasPrices { - eth: self.block_context.block_info().gas_prices.eth_l1_data_gas_price.into(), - strk: self.block_context.block_info().gas_prices.strk_l1_data_gas_price.into(), + eth: self + .block_context + .block_info() + .gas_prices + .eth_gas_prices + .l1_data_gas_price + .get() + .0, + strk: self + .block_context + .block_info() + .gas_prices + .strk_gas_prices + .l1_data_gas_price + .get() + .0, }, } } @@ -264,7 +286,9 @@ impl ExecutorExt for StarknetVMProcessor<'_> { transactions: Vec, flags: ExecutionFlags, ) -> Vec> { - self.simulate_with(transactions, &flags, |_, (_, res)| match res { + // TODO: figure out how this can be implied automatically + let estimate_fee_flags = flags.with_fee(false); + self.simulate_with(transactions, &estimate_fee_flags, |_, (_, res)| match res { ExecutionResult::Success { receipt, .. } => { // if the transaction was reverted, return as error if let Some(reason) = receipt.revert_reason() { diff --git a/crates/katana/executor/src/implementation/blockifier/state.rs b/crates/katana/executor/src/implementation/blockifier/state.rs index 86aba56190..da8bb1be61 100644 --- a/crates/katana/executor/src/implementation/blockifier/state.rs +++ b/crates/katana/executor/src/implementation/blockifier/state.rs @@ -46,18 +46,18 @@ impl<'a> StateReader for StateProviderDb<'a> { } } - fn get_compiled_contract_class( + fn get_compiled_class( &self, class_hash: ClassHash, - ) -> StateResult { + ) -> StateResult { if let Some(class) = self .compiled_class(class_hash.0) .map_err(|e| StateError::StateReadError(e.to_string()))? { - let class = - utils::to_class(class).map_err(|e| StateError::StateReadError(e.to_string()))?; + let class = utils::to_runnable_class(class) + .map_err(|e| StateError::StateReadError(e.to_string()))?; - Ok(class.contract_class()) + Ok(class) } else { Err(StateError::UndeclaredClassHash(class_hash)) } @@ -215,11 +215,11 @@ impl StateReader for CachedState { self.0.lock().inner.get_compiled_class_hash(class_hash) } - fn get_compiled_contract_class( + fn get_compiled_class( &self, class_hash: ClassHash, - ) -> StateResult { - self.0.lock().inner.get_compiled_contract_class(class_hash) + ) -> StateResult { + self.0.lock().inner.get_compiled_class(class_hash) } fn get_nonce_at( @@ -348,9 +348,8 @@ mod tests { let actual_storage_value = cached_state .get_storage_at(api_address, StorageKey(storage_key.try_into().unwrap()))?; let actual_compiled_hash = cached_state.get_compiled_class_hash(actual_class_hash)?; - let actual_class = cached_state.get_compiled_contract_class(actual_class_hash)?; - let actual_legacy_class = - cached_state.get_compiled_contract_class(ClassHash(legacy_class_hash))?; + let actual_class = cached_state.get_compiled_class(actual_class_hash)?; + let actual_legacy_class = cached_state.get_compiled_class(ClassHash(legacy_class_hash))?; assert_eq!(actual_nonce.0, felt!("0x7")); assert_eq!(actual_storage_value, felt!("0x2")); @@ -358,13 +357,14 @@ mod tests { assert_eq!(actual_compiled_hash.0, felt!("0x456")); assert_eq!( actual_class, - utils::to_class(DEFAULT_ACCOUNT_CLASS_CASM.clone()).unwrap().contract_class() + utils::to_runnable_class(DEFAULT_ACCOUNT_CLASS_CASM.clone()).unwrap() ); assert_eq!( actual_legacy_class, - utils::to_class(DEFAULT_LEGACY_ERC20_CLASS.clone().compile().expect("can compile")) - .unwrap() - .contract_class() + utils::to_runnable_class( + DEFAULT_LEGACY_ERC20_CLASS.clone().compile().expect("can compile") + ) + .unwrap() ); Ok(()) @@ -420,14 +420,12 @@ mod tests { let storage_key = StorageKey(new_storage_key.try_into().unwrap()); let storage_value = new_storage_value; let class_hash = ClassHash(new_class_hash); - let class = - utils::to_class(new_compiled_sierra_class.clone()).unwrap().contract_class(); + let class = utils::to_runnable_class(new_compiled_sierra_class.clone()).unwrap(); let compiled_hash = CompiledClassHash(new_compiled_hash); let legacy_class_hash = ClassHash(new_legacy_class_hash); let legacy_class = - utils::to_class(DEFAULT_LEGACY_UDC_CLASS.clone().compile().expect("can compile")) - .unwrap() - .contract_class(); + utils::to_runnable_class(DEFAULT_LEGACY_UDC_CLASS.clone().compile().unwrap()) + .unwrap(); let legacy_compiled_hash = CompiledClassHash(new_legacy_compiled_hash); blk_state.increment_nonce(address)?; @@ -540,7 +538,7 @@ mod tests { let actual_class_hash = cached_state.get_class_hash_at(api_address).expect("should return default value"); let actual_compiled_hash = cached_state.get_compiled_class_hash(api_class_hash); - let actual_compiled_class = cached_state.get_compiled_contract_class(api_class_hash); + let actual_compiled_class = cached_state.get_compiled_class(api_class_hash); let actual_edge_storage_value = cached_state .get_storage_at(utils::to_blk_address(edge_address), api_storage_key) .expect("should return default value"); diff --git a/crates/katana/executor/src/implementation/blockifier/utils.rs b/crates/katana/executor/src/implementation/blockifier/utils.rs index abae3566e6..d42f061061 100644 --- a/crates/katana/executor/src/implementation/blockifier/utils.rs +++ b/crates/katana/executor/src/implementation/blockifier/utils.rs @@ -1,47 +1,50 @@ use std::collections::{BTreeMap, BTreeSet}; -use std::num::NonZeroU128; use std::sync::Arc; -use blockifier::blockifier::block::{BlockInfo, GasPrices}; use blockifier::bouncer::BouncerConfig; use blockifier::context::{BlockContext, ChainInfo, FeeTokenAddresses, TransactionContext}; use blockifier::execution::call_info::{ CallExecution, CallInfo, OrderedEvent, OrderedL2ToL1Message, }; -use blockifier::execution::common_hints::ExecutionMode; use blockifier::execution::contract_class::{ - ClassInfo, ContractClass, ContractClassV0, ContractClassV1, + CompiledClassV0, CompiledClassV1, RunnableCompiledClass, }; use blockifier::execution::entry_point::{CallEntryPoint, CallType, EntryPointExecutionContext}; use blockifier::fee::fee_utils::get_fee_by_gas_vector; use blockifier::state::cached_state; use blockifier::state::state_api::StateReader; -use blockifier::transaction::account_transaction::AccountTransaction; +use blockifier::transaction::account_transaction::{ + AccountTransaction, ExecutionFlags as BlockifierExecutionFlags, +}; use blockifier::transaction::objects::{ - DeprecatedTransactionInfo, FeeType, HasRelatedFeeType, TransactionExecutionInfo, - TransactionInfo, + DeprecatedTransactionInfo, HasRelatedFeeType, TransactionExecutionInfo, TransactionInfo, }; use blockifier::transaction::transaction_execution::Transaction; -use blockifier::transaction::transactions::{ - DeclareTransaction, DeployAccountTransaction, ExecutableTransaction, InvokeTransaction, - L1HandlerTransaction, -}; +use blockifier::transaction::transactions::ExecutableTransaction; use blockifier::versioned_constants::VersionedConstants; use katana_cairo::cairo_vm::types::errors::program_errors::ProgramError; -use katana_cairo::cairo_vm::vm::runners::cairo_runner::ExecutionResources; -use katana_cairo::starknet_api::block::{BlockNumber, BlockTimestamp}; +use katana_cairo::cairo_vm::vm::runners::cairo_runner::{ExecutionResources, RunResources}; +use katana_cairo::starknet_api::block::{ + BlockInfo, BlockNumber, BlockTimestamp, FeeType, GasPriceVector, GasPrices, NonzeroGasPrice, +}; +use katana_cairo::starknet_api::contract_class::{ClassInfo, EntryPointType, SierraVersion}; use katana_cairo::starknet_api::core::{ self, ChainId, ClassHash, CompiledClassHash, ContractAddress, EntryPointSelector, Nonce, }; use katana_cairo::starknet_api::data_availability::DataAvailabilityMode; -use katana_cairo::starknet_api::deprecated_contract_class::EntryPointType; +use katana_cairo::starknet_api::executable_transaction::{ + DeclareTransaction, DeployAccountTransaction, InvokeTransaction, L1HandlerTransaction, +}; +use katana_cairo::starknet_api::transaction::fields::{ + AccountDeploymentData, Calldata, ContractAddressSalt, Fee, PaymasterData, ResourceBounds, Tip, + TransactionSignature, ValidResourceBounds, +}; use katana_cairo::starknet_api::transaction::{ - AccountDeploymentData, Calldata, ContractAddressSalt, DeclareTransaction as ApiDeclareTransaction, DeclareTransactionV0V1, DeclareTransactionV2, DeclareTransactionV3, DeployAccountTransaction as ApiDeployAccountTransaction, - DeployAccountTransactionV1, DeployAccountTransactionV3, Fee, - InvokeTransaction as ApiInvokeTransaction, PaymasterData, Resource, ResourceBounds, - ResourceBoundsMapping, Tip, TransactionHash, TransactionSignature, TransactionVersion, + DeployAccountTransactionV1, DeployAccountTransactionV3, + InvokeTransaction as ApiInvokeTransaction, InvokeTransactionV3, TransactionHash, + TransactionVersion, }; use katana_primitives::chain::NamedChainId; use katana_primitives::env::{BlockEnv, CfgEnv}; @@ -63,66 +66,51 @@ use crate::{ExecutionError, ExecutionResult}; pub fn transact( state: &mut cached_state::CachedState, block_context: &BlockContext, - simulation_flags: &ExecutionFlags, + flags: &ExecutionFlags, tx: ExecutableTxWithHash, ) -> ExecutionResult { fn transact_inner( state: &mut cached_state::CachedState, block_context: &BlockContext, - simulation_flags: &ExecutionFlags, tx: Transaction, ) -> Result<(TransactionExecutionInfo, TxFeeInfo), ExecutionError> { - let validate = simulation_flags.account_validation(); - let charge_fee = simulation_flags.fee(); - // Blockifier doesn't provide a way to fully skip nonce check during the tx validation - // stage. The `nonce_check` flag in `tx.execute()` only 'relaxes' the check for - // nonce that is equal or higher than the current (expected) account nonce. - // - // Related commit on Blockifier: https://github.com/dojoengine/blockifier/commit/2410b6055453f247d48759f223c34b3fb5fa777 - let nonce_check = simulation_flags.nonce_check(); - let fee_type = get_fee_type_from_tx(&tx); let info = match tx { - Transaction::AccountTransaction(tx) => { - tx.execute(state, block_context, charge_fee, validate, nonce_check) - } - Transaction::L1HandlerTransaction(tx) => { - tx.execute(state, block_context, charge_fee, validate, nonce_check) - } + Transaction::Account(tx) => tx.execute(state, block_context), + Transaction::L1Handler(tx) => tx.execute(state, block_context), }?; // There are a few case where the `actual_fee` field of the transaction info is not set // where the fee is skipped and thus not charged for the transaction (e.g. when the // `skip_fee_transfer` is explicitly set, or when the transaction `max_fee` is set to 0). In // these cases, we still want to calculate the fee. - let fee = if info.transaction_receipt.fee == Fee(0) { - get_fee_by_gas_vector( - block_context.block_info(), - info.transaction_receipt.gas, - &fee_type, - ) + let fee = if info.receipt.fee == Fee(0) { + get_fee_by_gas_vector(block_context.block_info(), info.receipt.gas, &fee_type) } else { - info.transaction_receipt.fee + info.receipt.fee }; - let gas_consumed = info.transaction_receipt.gas.l1_gas; + let gas_consumed = info.receipt.gas.l1_gas.0 as u128; + // TODO: i dont know if this is correct let (unit, gas_price) = match fee_type { - FeeType::Eth => { - (PriceUnit::Wei, block_context.block_info().gas_prices.eth_l1_gas_price) - } - FeeType::Strk => { - (PriceUnit::Fri, block_context.block_info().gas_prices.strk_l1_gas_price) - } + FeeType::Eth => ( + PriceUnit::Wei, + block_context.block_info().gas_prices.eth_gas_prices.l2_gas_price.get().0, + ), + FeeType::Strk => ( + PriceUnit::Fri, + block_context.block_info().gas_prices.strk_gas_prices.l2_gas_price.get().0, + ), }; - let fee_info = - TxFeeInfo { gas_consumed, gas_price: gas_price.into(), unit, overall_fee: fee.0 }; + let fee_info = TxFeeInfo { gas_consumed, gas_price, unit, overall_fee: fee.0 }; Ok((info, fee_info)) } - match transact_inner(state, block_context, simulation_flags, to_executor_tx(tx.clone())) { + let blockifier_tx = to_executor_tx(tx.clone(), flags.clone()); + match transact_inner(state, block_context, blockifier_tx) { Ok((info, fee)) => { // get the trace and receipt from the execution info let trace = to_exec_info(info, tx.r#type()); @@ -151,35 +139,35 @@ pub fn call( ..Default::default() }; - // TODO: this must be false if fees are disabled I assume. - let limit_steps_by_resources = true; - - // Now, the max step is not given directly to this function. - // It's computed by a new function max_steps, and it tooks the values - // from the block context itself instead of the input give. The dojoengine - // fork of the blockifier ensures we're not limited by the min function applied - // by starkware. - // https://github.com/starkware-libs/blockifier/blob/4fd71645b45fd1deb6b8e44802414774ec2a2ec1/crates/blockifier/src/execution/entry_point.rs#L159 - // https://github.com/dojoengine/blockifier/blob/5f58be8961ddf84022dd739a8ab254e32c435075/crates/blockifier/src/execution/entry_point.rs#L188 - - let res = call.execute( - &mut state, - &mut ExecutionResources::default(), - &mut EntryPointExecutionContext::new( - Arc::new(TransactionContext { - block_context: block_context.clone(), - tx_info: TransactionInfo::Deprecated(DeprecatedTransactionInfo::default()), - }), - ExecutionMode::Execute, - limit_steps_by_resources, - ) - .expect("shouldn't fail"), - )?; + let tx_context = Arc::new(TransactionContext { + block_context: block_context.clone(), + tx_info: TransactionInfo::Deprecated(DeprecatedTransactionInfo::default()), + }); + + // The reason why we assign a new `RunResources` is because of how the initial gas value for + // the call is being computed. Passing the `initial_gas` value directly used to work, + // meaning the literal value of the `initial_gas` would be used as the to run the contract call, + // but now Blockifier computes the initial gas differently, based on the block gas prices. + // See `EntryPointExecutionContext::max_steps()` for further references. + // + // The value of `limit_steps_by_resources` becomes irrelevant because of the explicit + // re-assignment of the run resources. + + let limit_steps_by_resources = false; + let mut ctx = EntryPointExecutionContext::new_invoke(tx_context, limit_steps_by_resources); + + // If `initial_gas` can't fit in a usize, use the maximum. + ctx.vm_run_resources = RunResources::new(initial_gas.try_into().unwrap_or(usize::MAX)); + + let mut remaining_gas = initial_gas as u64; + let res = call.execute(&mut state, &mut ctx, &mut remaining_gas)?; Ok(res.execution.retdata.0) } -pub fn to_executor_tx(tx: ExecutableTxWithHash) -> Transaction { +pub fn to_executor_tx(tx: ExecutableTxWithHash, flags: ExecutionFlags) -> Transaction { + use katana_cairo::starknet_api::executable_transaction::AccountTransaction as ExecTx; + let hash = tx.hash; match tx.transaction { @@ -188,7 +176,7 @@ pub fn to_executor_tx(tx: ExecutableTxWithHash) -> Transaction { let calldata = tx.calldata; let signature = tx.signature; - Transaction::AccountTransaction(AccountTransaction::Invoke(InvokeTransaction { + let tx = InvokeTransaction { tx: ApiInvokeTransaction::V0( katana_cairo::starknet_api::transaction::InvokeTransactionV0 { entry_point_selector: EntryPointSelector(tx.entry_point_selector), @@ -199,15 +187,19 @@ pub fn to_executor_tx(tx: ExecutableTxWithHash) -> Transaction { }, ), tx_hash: TransactionHash(hash), - only_query: false, - })) + }; + + Transaction::Account(AccountTransaction { + tx: ExecTx::Invoke(tx), + execution_flags: flags.into(), + }) } InvokeTx::V1(tx) => { let calldata = tx.calldata; let signature = tx.signature; - Transaction::AccountTransaction(AccountTransaction::Invoke(InvokeTransaction { + let tx = InvokeTransaction { tx: ApiInvokeTransaction::V1( katana_cairo::starknet_api::transaction::InvokeTransactionV1 { max_fee: Fee(tx.max_fee), @@ -218,8 +210,12 @@ pub fn to_executor_tx(tx: ExecutableTxWithHash) -> Transaction { }, ), tx_hash: TransactionHash(hash), - only_query: false, - })) + }; + + Transaction::Account(AccountTransaction { + tx: ExecTx::Invoke(tx), + execution_flags: flags.into(), + }) } InvokeTx::V3(tx) => { @@ -231,24 +227,26 @@ pub fn to_executor_tx(tx: ExecutableTxWithHash) -> Transaction { let fee_data_availability_mode = to_api_da_mode(tx.fee_data_availability_mode); let nonce_data_availability_mode = to_api_da_mode(tx.nonce_data_availability_mode); - Transaction::AccountTransaction(AccountTransaction::Invoke(InvokeTransaction { - tx: ApiInvokeTransaction::V3( - katana_cairo::starknet_api::transaction::InvokeTransactionV3 { - tip: Tip(tx.tip), - nonce: Nonce(tx.nonce), - sender_address: to_blk_address(tx.sender_address), - signature: TransactionSignature(signature), - calldata: Calldata(Arc::new(calldata)), - paymaster_data: PaymasterData(paymaster_data), - account_deployment_data: AccountDeploymentData(account_deploy_data), - fee_data_availability_mode, - nonce_data_availability_mode, - resource_bounds: to_api_resource_bounds(tx.resource_bounds), - }, - ), + let tx = InvokeTransaction { + tx: ApiInvokeTransaction::V3(InvokeTransactionV3 { + tip: Tip(tx.tip), + nonce: Nonce(tx.nonce), + sender_address: to_blk_address(tx.sender_address), + signature: TransactionSignature(signature), + calldata: Calldata(Arc::new(calldata)), + paymaster_data: PaymasterData(paymaster_data), + account_deployment_data: AccountDeploymentData(account_deploy_data), + fee_data_availability_mode, + nonce_data_availability_mode, + resource_bounds: to_api_resource_bounds(tx.resource_bounds), + }), tx_hash: TransactionHash(hash), - only_query: false, - })) + }; + + Transaction::Account(AccountTransaction { + tx: ExecTx::Invoke(tx), + execution_flags: flags.into(), + }) } }, @@ -258,21 +256,23 @@ pub fn to_executor_tx(tx: ExecutableTxWithHash) -> Transaction { let signature = tx.signature; let salt = ContractAddressSalt(tx.contract_address_salt); - Transaction::AccountTransaction(AccountTransaction::DeployAccount( - DeployAccountTransaction { - contract_address: to_blk_address(tx.contract_address), - tx: ApiDeployAccountTransaction::V1(DeployAccountTransactionV1 { - max_fee: Fee(tx.max_fee), - nonce: Nonce(tx.nonce), - signature: TransactionSignature(signature), - class_hash: ClassHash(tx.class_hash), - constructor_calldata: Calldata(Arc::new(calldata)), - contract_address_salt: salt, - }), - tx_hash: TransactionHash(hash), - only_query: false, - }, - )) + let tx = DeployAccountTransaction { + contract_address: to_blk_address(tx.contract_address), + tx: ApiDeployAccountTransaction::V1(DeployAccountTransactionV1 { + max_fee: Fee(tx.max_fee), + nonce: Nonce(tx.nonce), + signature: TransactionSignature(signature), + class_hash: ClassHash(tx.class_hash), + constructor_calldata: Calldata(Arc::new(calldata)), + contract_address_salt: salt, + }), + tx_hash: TransactionHash(hash), + }; + + Transaction::Account(AccountTransaction { + tx: ExecTx::DeployAccount(tx), + execution_flags: flags.into(), + }) } DeployAccountTx::V3(tx) => { @@ -284,32 +284,34 @@ pub fn to_executor_tx(tx: ExecutableTxWithHash) -> Transaction { let fee_data_availability_mode = to_api_da_mode(tx.fee_data_availability_mode); let nonce_data_availability_mode = to_api_da_mode(tx.nonce_data_availability_mode); - Transaction::AccountTransaction(AccountTransaction::DeployAccount( - DeployAccountTransaction { - contract_address: to_blk_address(tx.contract_address), - tx: ApiDeployAccountTransaction::V3(DeployAccountTransactionV3 { - tip: Tip(tx.tip), - nonce: Nonce(tx.nonce), - signature: TransactionSignature(signature), - class_hash: ClassHash(tx.class_hash), - constructor_calldata: Calldata(Arc::new(calldata)), - contract_address_salt: salt, - paymaster_data: PaymasterData(paymaster_data), - fee_data_availability_mode, - nonce_data_availability_mode, - resource_bounds: to_api_resource_bounds(tx.resource_bounds), - }), - tx_hash: TransactionHash(hash), - only_query: false, - }, - )) + let tx = DeployAccountTransaction { + contract_address: to_blk_address(tx.contract_address), + tx: ApiDeployAccountTransaction::V3(DeployAccountTransactionV3 { + tip: Tip(tx.tip), + nonce: Nonce(tx.nonce), + signature: TransactionSignature(signature), + class_hash: ClassHash(tx.class_hash), + constructor_calldata: Calldata(Arc::new(calldata)), + contract_address_salt: salt, + paymaster_data: PaymasterData(paymaster_data), + fee_data_availability_mode, + nonce_data_availability_mode, + resource_bounds: to_api_resource_bounds(tx.resource_bounds), + }), + tx_hash: TransactionHash(hash), + }; + + Transaction::Account(AccountTransaction { + tx: ExecTx::DeployAccount(tx), + execution_flags: flags.into(), + }) } }, ExecutableTx::Declare(tx) => { let compiled = tx.class.as_ref().clone().compile().expect("failed to compile"); - let tx = match tx.transaction { + let api_tx = match tx.transaction { DeclareTx::V0(tx) => ApiDeclareTransaction::V0(DeclareTransactionV0V1 { max_fee: Fee(tx.max_fee), nonce: Nonce::default(), @@ -364,13 +366,18 @@ pub fn to_executor_tx(tx: ExecutableTxWithHash) -> Transaction { } }; - let hash = TransactionHash(hash); - let class = to_class(compiled).unwrap(); - let tx = DeclareTransaction::new(tx, hash, class).expect("class mismatch"); - Transaction::AccountTransaction(AccountTransaction::Declare(tx)) + let tx_hash = TransactionHash(hash); + let class_info = to_class_info(compiled).unwrap(); + + let tx = DeclareTransaction { class_info, tx_hash, tx: api_tx }; + + Transaction::Account(AccountTransaction { + tx: ExecTx::Declare(tx), + execution_flags: flags.into(), + }) } - ExecutableTx::L1Handler(tx) => Transaction::L1HandlerTransaction(L1HandlerTransaction { + ExecutableTx::L1Handler(tx) => Transaction::L1Handler(L1HandlerTransaction { paid_fee_on_l1: Fee(tx.paid_fee_on_l1), tx: katana_cairo::starknet_api::transaction::L1HandlerTransaction { nonce: core::Nonce(tx.nonce), @@ -392,16 +399,27 @@ pub fn block_context_from_envs(block_env: &BlockEnv, cfg_env: &CfgEnv) -> BlockC }; let eth_l1_gas_price = - NonZeroU128::new(block_env.l1_gas_prices.eth).unwrap_or(NonZeroU128::new(1).unwrap()); + NonzeroGasPrice::new(block_env.l1_gas_prices.eth.into()).unwrap_or(NonzeroGasPrice::MIN); let strk_l1_gas_price = - NonZeroU128::new(block_env.l1_gas_prices.strk).unwrap_or(NonZeroU128::new(1).unwrap()); + NonzeroGasPrice::new(block_env.l1_gas_prices.strk.into()).unwrap_or(NonzeroGasPrice::MIN); + let eth_l1_data_gas_price = NonzeroGasPrice::new(block_env.l1_data_gas_prices.eth.into()) + .unwrap_or(NonzeroGasPrice::MIN); + let strk_l1_data_gas_price = NonzeroGasPrice::new(block_env.l1_data_gas_prices.strk.into()) + .unwrap_or(NonzeroGasPrice::MIN); let gas_prices = GasPrices { - eth_l1_gas_price, - strk_l1_gas_price, - // TODO: should those be the same value? - eth_l1_data_gas_price: eth_l1_gas_price, - strk_l1_data_gas_price: strk_l1_gas_price, + eth_gas_prices: GasPriceVector { + l1_gas_price: eth_l1_gas_price, + l1_data_gas_price: eth_l1_data_gas_price, + // TODO: update to use the correct value + l2_gas_price: eth_l1_gas_price, + }, + strk_gas_prices: GasPriceVector { + l1_gas_price: strk_l1_gas_price, + l1_data_gas_price: strk_l1_data_gas_price, + // TODO: update to use the correct value + l2_gas_price: strk_l1_gas_price, + }, }; let block_info = BlockInfo { @@ -437,7 +455,7 @@ pub(super) fn state_update_from_cached_state( // TODO: Legacy class shouldn't have a compiled class hash. This is a hack we added // in our fork of `blockifier. Check if it's possible to remove it now. - for (class_hash, compiled_hash) in state_diff.compiled_class_hashes { + for (class_hash, compiled_hash) in state_diff.state_maps.compiled_class_hashes { let hash = class_hash.0; let class = state.class(hash).unwrap().expect("must exist if declared"); @@ -452,7 +470,7 @@ pub(super) fn state_update_from_cached_state( let nonce_updates = state_diff - .nonces + .state_maps.nonces .into_iter() .map(|(key, value)| (to_address(key), value.0)) .collect::( katana_primitives::contract::Nonce, >>(); - let storage_updates = state_diff.storage.into_iter().fold( + let storage_updates = state_diff.state_maps.storage.into_iter().fold( BTreeMap::new(), |mut storage, ((addr, key), value)| { let entry: &mut BTreeMap< @@ -474,6 +492,7 @@ pub(super) fn state_update_from_cached_state( let deployed_contracts = state_diff + .state_maps .class_hashes .into_iter() .map(|(key, value)| (to_address(key), value.0)) @@ -502,28 +521,26 @@ fn to_api_da_mode(mode: katana_primitives::da::DataAvailabilityMode) -> DataAvai } } +// The protocol version we want to support depends on the returned `ValidResourceBounds`. Returning +// the wrong variant without the right values will result in execution error. +// +// Ref: https://community.starknet.io/t/starknet-v0-13-1-pre-release-notes/113664#sdkswallets-how-to-use-the-new-fee-estimates-7 fn to_api_resource_bounds( resource_bounds: katana_primitives::fee::ResourceBoundsMapping, -) -> ResourceBoundsMapping { - let l1_gas = ResourceBounds { - max_amount: resource_bounds.l1_gas.max_amount, - max_price_per_unit: resource_bounds.l1_gas.max_price_per_unit, - }; - - let l2_gas = ResourceBounds { - max_amount: resource_bounds.l2_gas.max_amount, - max_price_per_unit: resource_bounds.l2_gas.max_price_per_unit, - }; - - ResourceBoundsMapping(BTreeMap::from([(Resource::L1Gas, l1_gas), (Resource::L2Gas, l2_gas)])) +) -> ValidResourceBounds { + // Pre 0.13.3. Only L1 gas. L2 bounds are signed but never used. + ValidResourceBounds::L1Gas(ResourceBounds { + max_amount: resource_bounds.l1_gas.max_amount.into(), + max_price_per_unit: resource_bounds.l1_gas.max_price_per_unit.into(), + }) } /// Get the fee type of a transaction. The fee type determines the token used to pay for the /// transaction. fn get_fee_type_from_tx(transaction: &Transaction) -> FeeType { match transaction { - Transaction::AccountTransaction(tx) => tx.fee_type(), - Transaction::L1HandlerTransaction(tx) => tx.fee_type(), + Transaction::Account(tx) => tx.fee_type(), + Transaction::L1Handler(tx) => tx.fee_type(), } } @@ -547,23 +564,41 @@ pub fn to_blk_chain_id(chain_id: katana_primitives::chain::ChainId) -> ChainId { } } -pub fn to_class(class: class::CompiledClass) -> Result { +pub fn to_runnable_class( + class: class::CompiledClass, +) -> Result { + // TODO: @kariy not sure of the variant that must be used in this case. Should we change the + // return type to include this case of error for contract class conversions? + match class { + class::CompiledClass::Legacy(class) => { + Ok(RunnableCompiledClass::V0(CompiledClassV0::try_from(class)?)) + } + class::CompiledClass::Class(casm) => { + Ok(RunnableCompiledClass::V1(CompiledClassV1::try_from(casm)?)) + } + } +} + +pub fn to_class_info(class: class::CompiledClass) -> Result { + use katana_cairo::starknet_api::contract_class::ContractClass; + // TODO: @kariy not sure of the variant that must be used in this case. Should we change the // return type to include this case of error for contract class conversions? match class { class::CompiledClass::Legacy(class) => { // For cairo 0, the sierra_program_length must be 0. - Ok(ClassInfo::new(&ContractClass::V0(ContractClassV0::try_from(class)?), 0, 0) + Ok(ClassInfo::new(&ContractClass::V0(class), 0, 0, SierraVersion::DEPRECATED) .map_err(|e| ProgramError::ConstWithoutValue(format!("{e}")))?) } - class::CompiledClass::Class(casm) => { - let sierra_program_len = casm.bytecode.len(); + class::CompiledClass::Class(class) => { + let sierra_program_len = class.bytecode.len(); // TODO: @kariy not sure from where the ABI length can be grasped. Ok(ClassInfo::new( - &ContractClass::V1(ContractClassV1::try_from(casm)?), + &ContractClass::V1(class), sierra_program_len, 0, + SierraVersion::LATEST, ) .map_err(|e| ProgramError::ConstWithoutValue(format!("{e}")))?) } @@ -584,20 +619,20 @@ pub fn to_exec_info(exec_info: TransactionExecutionInfo, r#type: TxType) -> TxEx validate_call_info: exec_info.validate_call_info.map(to_call_info), execute_call_info: exec_info.execute_call_info.map(to_call_info), fee_transfer_call_info: exec_info.fee_transfer_call_info.map(to_call_info), - actual_fee: exec_info.transaction_receipt.fee.0, - revert_error: exec_info.revert_error.clone(), + actual_fee: exec_info.receipt.fee.0, + revert_error: exec_info.revert_error.map(|e| e.to_string()), actual_resources: TxResources { vm_resources: to_execution_resources( - exec_info.transaction_receipt.resources.vm_resources, + exec_info.receipt.resources.computation.vm_resources, ), - n_reverted_steps: exec_info.transaction_receipt.resources.n_reverted_steps, + n_reverted_steps: exec_info.receipt.resources.computation.n_reverted_steps, data_availability: L1Gas { - l1_gas: exec_info.transaction_receipt.da_gas.l1_data_gas, - l1_data_gas: exec_info.transaction_receipt.da_gas.l1_data_gas, + l1_gas: exec_info.receipt.da_gas.l1_data_gas.0 as u128, + l1_data_gas: exec_info.receipt.da_gas.l1_data_gas.0 as u128, }, total_gas_consumed: L1Gas { - l1_gas: exec_info.transaction_receipt.gas.l1_data_gas, - l1_data_gas: exec_info.transaction_receipt.gas.l1_data_gas, + l1_gas: exec_info.receipt.gas.l1_data_gas.0 as u128, + l1_data_gas: exec_info.receipt.gas.l1_data_gas.0 as u128, }, }, } @@ -632,6 +667,8 @@ fn to_call_info(call: CallInfo) -> trace::CallInfo { let storage_read_values = call.storage_read_values; let storg_keys = call.accessed_storage_keys.into_iter().map(|k| *k.0.key()).collect(); let inner_calls = call.inner_calls.into_iter().map(to_call_info).collect(); + let execution_resources = to_execution_resources(call.charged_resources.vm_resources); + let gas_consumed = call.execution.gas_consumed as u128; trace::CallInfo { contract_address, @@ -643,13 +680,13 @@ fn to_call_info(call: CallInfo) -> trace::CallInfo { entry_point_type, calldata, retdata, - execution_resources: to_execution_resources(call.resources), + execution_resources, events, l2_to_l1_messages: l1_msg, storage_read_values, accessed_storage_keys: storg_keys, inner_calls, - gas_consumed: call.execution.gas_consumed as u128, + gas_consumed, failed: call.execution.failed, } } @@ -682,11 +719,23 @@ fn to_execution_resources( } } +impl From for BlockifierExecutionFlags { + fn from(value: ExecutionFlags) -> Self { + Self { + only_query: false, + charge_fee: value.fee(), + nonce_check: value.nonce_check(), + validate: value.account_validation(), + } + } +} + #[cfg(test)] mod tests { use std::collections::{HashMap, HashSet}; + use blockifier::execution::call_info::ChargedResources; use katana_cairo::cairo_vm::types::builtin_name::BuiltinName; use katana_cairo::cairo_vm::vm::runners::cairo_runner::ExecutionResources; use katana_cairo::starknet_api::core::EntryPointSelector; @@ -781,15 +830,19 @@ mod tests { }, storage_read_values: vec![felt!(1_u8), felt!(2_u8)], accessed_storage_keys: HashSet::from([3u128.into(), 4u128.into(), 5u128.into()]), - resources: ExecutionResources { - n_steps: 1_000_000, - n_memory_holes: 9_000, - builtin_instance_counter: HashMap::from([ - (BuiltinName::ecdsa, 50), - (BuiltinName::pedersen, 9), - ]), + charged_resources: ChargedResources { + vm_resources: ExecutionResources { + n_steps: 1_000_000, + n_memory_holes: 9_000, + builtin_instance_counter: HashMap::from([ + (BuiltinName::ecdsa, 50), + (BuiltinName::pedersen, 9), + ]), + }, + ..Default::default() }, inner_calls: vec![nested_call], + ..Default::default() } } diff --git a/crates/katana/pool/src/validation/stateful.rs b/crates/katana/pool/src/validation/stateful.rs index 7e81a5a9ee..0df1cbbeec 100644 --- a/crates/katana/pool/src/validation/stateful.rs +++ b/crates/katana/pool/src/validation/stateful.rs @@ -166,8 +166,11 @@ fn validate( skip_validate: bool, skip_fee_check: bool, ) -> ValidationResult { - match to_executor_tx(pool_tx.clone()) { - Transaction::AccountTransaction(tx) => { + let flags = + ExecutionFlags::new().with_account_validation(!skip_validate).with_fee(!skip_fee_check); + + match to_executor_tx(pool_tx.clone(), flags) { + Transaction::Account(tx) => { match validator.perform_validations(tx, skip_validate, skip_fee_check) { Ok(()) => Ok(ValidationOutcome::Valid(pool_tx)), Err(e) => match map_invalid_tx_err(e) { @@ -178,7 +181,7 @@ fn validate( } // we skip validation for L1HandlerTransaction - Transaction::L1HandlerTransaction(_) => Ok(ValidationOutcome::Valid(pool_tx)), + Transaction::L1Handler(_) => Ok(ValidationOutcome::Valid(pool_tx)), } } @@ -198,6 +201,15 @@ fn map_invalid_tx_err( Ok(InvalidTransactionError::ValidationFailure { address, class_hash, error }) } + TransactionExecutionError::PanicInValidate { panic_reason } => { + // TODO: maybe can remove the address and class hash? + Ok(InvalidTransactionError::ValidationFailure { + address: Default::default(), + class_hash: Default::default(), + error: panic_reason.to_string(), + }) + } + _ => Err(Box::new(err)), }, diff --git a/crates/katana/primitives/src/conversion/rpc.rs b/crates/katana/primitives/src/conversion/rpc.rs index 2fc10396cf..9a425da0c9 100644 --- a/crates/katana/primitives/src/conversion/rpc.rs +++ b/crates/katana/primitives/src/conversion/rpc.rs @@ -4,8 +4,9 @@ use std::mem; use anyhow::{Context, Result}; use katana_cairo::lang::starknet_classes::casm_contract_class::CasmContractClass; +use katana_cairo::starknet_api::contract_class::EntryPointType; use katana_cairo::starknet_api::deprecated_contract_class::{ - ContractClassAbiEntry, EntryPoint, EntryPointType, TypedParameter, + ContractClassAbiEntry, EntryPointV0, TypedParameter, }; use serde::Deserialize; use serde_json::json; @@ -34,10 +35,10 @@ pub fn legacy_inner_to_rpc_class( legacy_contract_class: LegacyContractClass, ) -> Result { fn to_rpc_entry_points( - entries: &HashMap>, + entries: &HashMap>, ) -> Result { fn collect_entry_points( - entries: &HashMap>, + entries: &HashMap>, entry_point_type: &EntryPointType, ) -> Result> { Ok(entries diff --git a/crates/katana/rpc/rpc-types/src/class.rs b/crates/katana/rpc/rpc-types/src/class.rs index f9a3521097..c39be168f2 100644 --- a/crates/katana/rpc/rpc-types/src/class.rs +++ b/crates/katana/rpc/rpc-types/src/class.rs @@ -6,8 +6,9 @@ use std::io::{self, Write}; use katana_cairo::lang::starknet_classes::contract_class::ContractEntryPoints; use katana_cairo::lang::utils::bigint::BigUintAsHex; +use katana_cairo::starknet_api::contract_class::EntryPointType; use katana_cairo::starknet_api::deprecated_contract_class::{ - ContractClassAbiEntry, EntryPoint, EntryPointType, Program as LegacyProgram, + ContractClassAbiEntry, EntryPointV0, Program as LegacyProgram, }; use katana_cairo::starknet_api::serde_utils::deserialize_optional_contract_class_abi_entry_vector; use katana_primitives::class::{ContractClass, LegacyContractClass, SierraContractClass}; @@ -126,7 +127,7 @@ pub struct RpcLegacyContractClass { #[serde(with = "base64")] pub program: Vec, /// The selector of each entry point is a unique identifier in the program. - pub entry_points_by_type: HashMap>, + pub entry_points_by_type: HashMap>, // Starknet does not verify the abi. If we can't parse it, we set it to None. #[serde(default, deserialize_with = "deserialize_optional_contract_class_abi_entry_vector")] pub abi: Option>, diff --git a/crates/katana/rpc/rpc/tests/starknet.rs b/crates/katana/rpc/rpc/tests/starknet.rs index 0dce2e039a..8e8064f27b 100644 --- a/crates/katana/rpc/rpc/tests/starknet.rs +++ b/crates/katana/rpc/rpc/tests/starknet.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use anyhow::Result; use assert_matches::assert_matches; -use cainome::rs::abigen_legacy; +use cainome::rs::{abigen, abigen_legacy}; use common::split_felt; use dojo_test_utils::sequencer::{get_default_test_config, TestSequencer}; use indexmap::IndexSet; @@ -948,7 +948,7 @@ async fn block_traces() -> Result<()> { // will be using STRK fee token as its gas fee. So, the STRK fee token must exist in the chain in // order for this to pass. #[tokio::test] -async fn v3_transactions() -> Result<()> { +async fn v3_transactions() { let config = get_default_test_config(SequencingConfig { no_mining: true, ..Default::default() }); let sequencer = TestSequencer::start(config).await; @@ -966,13 +966,11 @@ async fn v3_transactions() -> Result<()> { .gas(100000000000) .send() .await - .inspect_err(|e| println!("transaction failed: {e:?}"))?; + .unwrap(); - let receipt = dojo_utils::TransactionWaiter::new(res.transaction_hash, &provider).await?; - let status = receipt.receipt.execution_result().status(); + let rec = dojo_utils::TransactionWaiter::new(res.transaction_hash, &provider).await.unwrap(); + let status = rec.receipt.execution_result().status(); assert_eq!(status, TransactionExecutionStatus::Succeeded); - - Ok(()) } #[tokio::test] @@ -1168,3 +1166,32 @@ async fn fetch_pending_blocks_in_instant_mode() { panic!("expected block with transaction receipts") } } + +#[tokio::test] +async fn call_contract() { + let config = get_default_test_config(SequencingConfig::default()); + let sequencer = TestSequencer::start(config).await; + + let provider = sequencer.provider(); + let account = sequencer.account().address(); + + // ----------------------------------------------------------------------- + // Call legacy contract + + let contract = Erc20ContractReader::new(DEFAULT_ETH_FEE_TOKEN_ADDRESS.into(), &provider); + let _ = contract.name().call().await.unwrap(); + let _ = contract.balanceOf(&account).call().await.unwrap(); + + // ----------------------------------------------------------------------- + // Call contract + + abigen!( + AccountContract, + "[{\"type\":\"function\",\"name\":\"get_public_key\",\"inputs\":[],\"outputs\":[{\"type\":\ + \"core::felt252\"}],\"state_mutability\":\"view\"}]" + ); + + // setup contract to interact with (can be any existing contract that can be interacted with) + let contract = AccountContractReader::new(account, &provider); + let _ = contract.get_public_key().call().await.unwrap(); +} diff --git a/crates/torii/types-test/Scarb.lock b/crates/torii/types-test/Scarb.lock index 0198ef49a0..405bc5d2af 100644 --- a/crates/torii/types-test/Scarb.lock +++ b/crates/torii/types-test/Scarb.lock @@ -10,11 +10,11 @@ dependencies = [ [[package]] name = "dojo_plugin" -version = "2.8.4" +version = "2.9.2" [[package]] name = "types_test" -version = "1.0.9" +version = "1.0.11" dependencies = [ "dojo", ] diff --git a/crates/torii/types-test/Scarb.toml b/crates/torii/types-test/Scarb.toml index f4a8adccaa..41915e1f88 100644 --- a/crates/torii/types-test/Scarb.toml +++ b/crates/torii/types-test/Scarb.toml @@ -1,5 +1,5 @@ [package] -cairo-version = "=2.8.4" +cairo-version = "=2.9.2" edition = "2024_07" name = "types_test" version = "1.0.11" diff --git a/examples/game-lib/Scarb.lock b/examples/game-lib/Scarb.lock index 775fb46b9b..dc9ae55d70 100644 --- a/examples/game-lib/Scarb.lock +++ b/examples/game-lib/Scarb.lock @@ -24,4 +24,4 @@ dependencies = [ [[package]] name = "dojo_plugin" -version = "2.8.4" +version = "2.9.1" diff --git a/examples/game-lib/Scarb.toml b/examples/game-lib/Scarb.toml index b075438218..7f23d84816 100644 --- a/examples/game-lib/Scarb.toml +++ b/examples/game-lib/Scarb.toml @@ -7,6 +7,7 @@ members = [ [workspace.package] version = "0.1.0" description = "Example game library for Dojo" +edition = "2024_07" [workspace.dependencies] dojo = { path = "../../crates/dojo/core/" } diff --git a/examples/game-lib/armory/Scarb.toml b/examples/game-lib/armory/Scarb.toml index 103b5ec8ee..d280b1ce50 100644 --- a/examples/game-lib/armory/Scarb.toml +++ b/examples/game-lib/armory/Scarb.toml @@ -2,6 +2,7 @@ name = "armory" version = "0.1.0" description = "An armory of epic weapons." +edition.workspace = true [dependencies] dojo.workspace = true diff --git a/examples/game-lib/bestiary/Scarb.toml b/examples/game-lib/bestiary/Scarb.toml index 195a962b10..77d5c5d9eb 100644 --- a/examples/game-lib/bestiary/Scarb.toml +++ b/examples/game-lib/bestiary/Scarb.toml @@ -2,6 +2,7 @@ name = "bestiary" version = "0.1.0" description = "Some scary foes to fight." +edition.workspace = true [dependencies] dojo.workspace = true diff --git a/examples/simple/Scarb.lock b/examples/simple/Scarb.lock index 09def408e1..1d95b27e4a 100644 --- a/examples/simple/Scarb.lock +++ b/examples/simple/Scarb.lock @@ -3,21 +3,21 @@ version = 1 [[package]] name = "dojo" -version = "1.0.9" +version = "1.0.11" dependencies = [ "dojo_plugin", ] [[package]] name = "dojo_cairo_test" -version = "1.0.0-rc.0" +version = "1.0.5" dependencies = [ "dojo", ] [[package]] name = "dojo_plugin" -version = "2.8.4" +version = "2.9.2" [[package]] name = "dojo_simple" diff --git a/examples/simple/Scarb.toml b/examples/simple/Scarb.toml index 388df4c4b1..2fbe5bf02a 100644 --- a/examples/simple/Scarb.toml +++ b/examples/simple/Scarb.toml @@ -1,5 +1,5 @@ [package] -cairo-version = "=2.8.4" +cairo-version = "=2.9.2" name = "dojo_simple" version = "0.1.0" edition = "2024_07" @@ -11,9 +11,10 @@ build-external-contracts = ["dojo::world::world_contract::world"] [dependencies] dojo = { path = "../../crates/dojo/core" } -starknet = "2.8.4" +starknet = "2.9.2" [dev-dependencies] +cairo_test = "2.9.2" dojo_cairo_test = { path = "../../crates/dojo/core-cairo-test" } [features] diff --git a/examples/simple/manifest_dev.json b/examples/simple/manifest_dev.json index 4cba9216c2..fd00179a7d 100644 --- a/examples/simple/manifest_dev.json +++ b/examples/simple/manifest_dev.json @@ -1,7 +1,7 @@ { "world": { - "class_hash": "0x45575a88cc5cef1e444c77ce60b7b4c9e73a01cbbe20926d5a4c72a94011410", - "address": "0x64613f376f05242dfcc9fe360fa2ce1fdd6b00b1ce73dae2ea649ea118fd9be", + "class_hash": "0xf212887cb11e8fd60b85cdd1893fc0211b3961bf93b3f6c9ab568ce0c125cd", + "address": "0x18350f68b38e5e814b40682077abe3c80e6f0192255f6fba11a81bbd27c8be2", "seed": "simple", "name": "simple", "entrypoints": [ @@ -1252,8 +1252,8 @@ }, "contracts": [ { - "address": "0x1958afba5b86ac51f48313047357981a59ac274170e353f79d84eedc89219e3", - "class_hash": "0x340e197b0fac61961591acdd872a89b0cb862893272ab72455356f5534baa7e", + "address": "0x41b80c74e37320c993bd82eca8f01e095435d2b5763b2d5b4de57c6c7e424ea", + "class_hash": "0x2531b688864dfde492af091dfe2bcfec3ae4899c50b8c94938edb3a7b29ba9", "abi": [ { "type": "impl", @@ -1510,8 +1510,8 @@ ] }, { - "address": "0x5d9f3674dd96f173735f949d303abf107d1761b838a733703e95b31cc479270", - "class_hash": "0x2a400df88b0add6c980d281dc96354a5cfc2b886547e9ed621b097e21842ee6", + "address": "0x275318edbed7789413302f4ca4edff17f7f2566b2a0bec71c91742d84705b76", + "class_hash": "0x6eee6b876560b8e3314481f8404c023664bc792e07af43de445d9423315f906", "abi": [ { "type": "impl", @@ -1686,184 +1686,8 @@ ] }, { - "address": "0x38b6e133a81a3ef41438752fbcf497ed74f284fe64a70e02652c3fb434d4e8", - "class_hash": "0x7cc8d15e576873d544640f7fd124bd430bd19c0f31e203fb069b4fc2f5c0ab9", - "abi": [ - { - "type": "impl", - "name": "c3__ContractImpl", - "interface_name": "dojo::contract::interface::IContract" - }, - { - "type": "interface", - "name": "dojo::contract::interface::IContract", - "items": [] - }, - { - "type": "impl", - "name": "c3__DeployedContractImpl", - "interface_name": "dojo::meta::interface::IDeployedResource" - }, - { - "type": "struct", - "name": "core::byte_array::ByteArray", - "members": [ - { - "name": "data", - "type": "core::array::Array::" - }, - { - "name": "pending_word", - "type": "core::felt252" - }, - { - "name": "pending_word_len", - "type": "core::integer::u32" - } - ] - }, - { - "type": "interface", - "name": "dojo::meta::interface::IDeployedResource", - "items": [ - { - "type": "function", - "name": "dojo_name", - "inputs": [], - "outputs": [ - { - "type": "core::byte_array::ByteArray" - } - ], - "state_mutability": "view" - } - ] - }, - { - "type": "function", - "name": "dojo_init", - "inputs": [], - "outputs": [], - "state_mutability": "view" - }, - { - "type": "impl", - "name": "WorldProviderImpl", - "interface_name": "dojo::contract::components::world_provider::IWorldProvider" - }, - { - "type": "struct", - "name": "dojo::world::iworld::IWorldDispatcher", - "members": [ - { - "name": "contract_address", - "type": "core::starknet::contract_address::ContractAddress" - } - ] - }, - { - "type": "interface", - "name": "dojo::contract::components::world_provider::IWorldProvider", - "items": [ - { - "type": "function", - "name": "world_dispatcher", - "inputs": [], - "outputs": [ - { - "type": "dojo::world::iworld::IWorldDispatcher" - } - ], - "state_mutability": "view" - } - ] - }, - { - "type": "impl", - "name": "UpgradeableImpl", - "interface_name": "dojo::contract::components::upgradeable::IUpgradeable" - }, - { - "type": "interface", - "name": "dojo::contract::components::upgradeable::IUpgradeable", - "items": [ - { - "type": "function", - "name": "upgrade", - "inputs": [ - { - "name": "new_class_hash", - "type": "core::starknet::class_hash::ClassHash" - } - ], - "outputs": [], - "state_mutability": "external" - } - ] - }, - { - "type": "constructor", - "name": "constructor", - "inputs": [] - }, - { - "type": "event", - "name": "dojo::contract::components::upgradeable::upgradeable_cpt::Upgraded", - "kind": "struct", - "members": [ - { - "name": "class_hash", - "type": "core::starknet::class_hash::ClassHash", - "kind": "data" - } - ] - }, - { - "type": "event", - "name": "dojo::contract::components::upgradeable::upgradeable_cpt::Event", - "kind": "enum", - "variants": [ - { - "name": "Upgraded", - "type": "dojo::contract::components::upgradeable::upgradeable_cpt::Upgraded", - "kind": "nested" - } - ] - }, - { - "type": "event", - "name": "dojo::contract::components::world_provider::world_provider_cpt::Event", - "kind": "enum", - "variants": [] - }, - { - "type": "event", - "name": "dojo_simple::c3::Event", - "kind": "enum", - "variants": [ - { - "name": "UpgradeableEvent", - "type": "dojo::contract::components::upgradeable::upgradeable_cpt::Event", - "kind": "nested" - }, - { - "name": "WorldProviderEvent", - "type": "dojo::contract::components::world_provider::world_provider_cpt::Event", - "kind": "nested" - } - ] - } - ], - "init_calldata": [], - "tag": "ns-c3", - "selector": "0x69bd1ce04aa3945bacae701a68e86c58b44d21c4debee8a65fa921b4a717c5f", - "systems": [ - "upgrade" - ] - }, - { - "address": "0x47882727700801173a3ff731928c9d41303237e142104bd155f48fac3806814", - "class_hash": "0x340e197b0fac61961591acdd872a89b0cb862893272ab72455356f5534baa7e", + "address": "0x52f5c9a44935b1667c792578726a858127ffed489a7e89fa5e82415a5259a91", + "class_hash": "0x2531b688864dfde492af091dfe2bcfec3ae4899c50b8c94938edb3a7b29ba9", "abi": [ { "type": "impl", @@ -2123,13 +1947,13 @@ "models": [ { "members": [], - "class_hash": "0x506d770b7301fc791cf3a19705848647524a0e2595a4d38365df917b4d1d246", + "class_hash": "0x6cf9d76cf4d19a94d91e99935d8e0cb78a925722f32963bea9d5286f70ac499", "tag": "ns-M", "selector": "0x50aac05281bbfaa5393cacacc12e86f59ab7d5f3ee619427dd33a0756526f24" }, { "members": [], - "class_hash": "0x506d770b7301fc791cf3a19705848647524a0e2595a4d38365df917b4d1d246", + "class_hash": "0x6cf9d76cf4d19a94d91e99935d8e0cb78a925722f32963bea9d5286f70ac499", "tag": "ns2-M", "selector": "0x3b26427a55dd1d51738b0e3e989fe6f25649e1311295f30f0a4fa2db439aa2c" } @@ -2137,13 +1961,13 @@ "events": [ { "members": [], - "class_hash": "0x943620824729c411797e6be26c3078924893be417ab08789489532d9c6aebb", + "class_hash": "0x5d8575f82fa0bf70efdbe1111a511d5767754bb0940cbf95f4451ec6f2b5242", "tag": "ns-E", "selector": "0x260e0511a6fa454a7d4ed8bea5fa52fc80fc588e33ba4cb58c65bbeeadf7565" }, { "members": [], - "class_hash": "0x5ed10e08c25eb6a1cb7e221209eac3baab14be36a3ea0b55f789d8302712310", + "class_hash": "0x1b5ff2cb3c052bfe25f6d37a9464e39c7abfcb4f432eaff4bdd90bdb2aa5353", "tag": "ns-EH", "selector": "0x4c6c7772b19b700cf97d078d02a419670d11d2b689a7a3647eac311b2817ced" } diff --git a/examples/simple/src/lib.cairo b/examples/simple/src/lib.cairo index 682d9039c1..18c9ff165b 100644 --- a/examples/simple/src/lib.cairo +++ b/examples/simple/src/lib.cairo @@ -43,7 +43,7 @@ pub mod c1 { use dojo::event::EventStorage; fn dojo_init(self: @ContractState, v: felt252) { - let m = M { k: 0, v, }; + let m = M { k: 0, v }; let mut world = self.world_default(); world.write_model(@m); @@ -54,7 +54,7 @@ pub mod c1 { fn system_1(ref self: ContractState, k: felt252, v: felt252) { let mut world = self.world_default(); - let m = M { k, v, }; + let m = M { k, v }; world.write_model(@m) } @@ -70,17 +70,17 @@ pub mod c1 { fn system_3(ref self: ContractState, k: felt252, v: u32) { let mut world = self.world_default(); - let e = E { k, v, }; + let e = E { k, v }; world.emit_event(@e); - let eh = EH { k, v, }; + let eh = EH { k, v }; world.emit_event(@eh); } fn system_4(ref self: ContractState, k: felt252) { let mut world = self.world_default(); - let m = M { k, v: 288, }; + let m = M { k, v: 288 }; let entity_id = Model::::entity_id(@m); @@ -116,17 +116,19 @@ pub mod c3 {} mod tests { use dojo::model::ModelStorage; use dojo_cairo_test::{ - spawn_test_world, NamespaceDef, TestResource, ContractDefTrait, WorldStorageTestTrait + spawn_test_world, NamespaceDef, TestResource, ContractDefTrait, WorldStorageTestTrait, }; use super::{c1, m_M, M}; #[test] fn test_1() { let ndef = NamespaceDef { - namespace: "ns", resources: [ + namespace: "ns", + resources: [ TestResource::Model(m_M::TEST_CLASS_HASH), TestResource::Contract(c1::TEST_CLASS_HASH), - ].span() + ] + .span(), }; let world = spawn_test_world([ndef].span()); diff --git a/examples/spawn-and-move/Scarb.lock b/examples/spawn-and-move/Scarb.lock index 9ed02bb845..ffd7643fe1 100644 --- a/examples/spawn-and-move/Scarb.lock +++ b/examples/spawn-and-move/Scarb.lock @@ -24,14 +24,14 @@ dependencies = [ [[package]] name = "dojo_cairo_test" -version = "1.0.0-rc.0" +version = "1.0.5" dependencies = [ "dojo", ] [[package]] name = "dojo_examples" -version = "1.0.9" +version = "1.0.11" dependencies = [ "armory", "bestiary", @@ -41,4 +41,4 @@ dependencies = [ [[package]] name = "dojo_plugin" -version = "2.8.4" +version = "2.9.2" diff --git a/examples/spawn-and-move/Scarb.toml b/examples/spawn-and-move/Scarb.toml index 9c673b788e..59b4eca333 100644 --- a/examples/spawn-and-move/Scarb.toml +++ b/examples/spawn-and-move/Scarb.toml @@ -1,5 +1,5 @@ [package] -cairo-version = "=2.8.4" +cairo-version = "=2.9.2" name = "dojo_examples" version = "1.0.11" # Use the prelude with the less imports as possible @@ -16,9 +16,10 @@ build-external-contracts = [ "dojo::world::world_contract::world" ] armory = { path = "../game-lib/armory" } bestiary = { path = "../game-lib/bestiary" } dojo = { path = "../../crates/dojo/core" } -starknet = "2.8.4" +starknet = "2.9.2" [dev-dependencies] +cairo_test = "2.9.2" dojo_cairo_test = { path = "../../crates/dojo/core-cairo-test" } [features] diff --git a/examples/spawn-and-move/dojo_dev.toml b/examples/spawn-and-move/dojo_dev.toml index 49e8d08de2..a1e96bb9e2 100644 --- a/examples/spawn-and-move/dojo_dev.toml +++ b/examples/spawn-and-move/dojo_dev.toml @@ -31,7 +31,7 @@ rpc_url = "http://localhost:5050/" # Default account for katana with seed = 0 account_address = "0x2af9427c5a277474c079a1283c880ee8a6f0f8fbf73ce969c08d88befec1bba" private_key = "0x1800000000300000180000000000030000000000003006001800006600" -world_address = "0x52ee4d3cba58d1a0462bbfb6813bf5aa1b35078c3b859cded2b727c1d9469ea" +world_address = "0x736c456dec44741fad1940876e62342a626ca73fd4ac574a94eb3ded2e25d8d" ipfs_config.url = "https://ipfs.infura.io:5001" ipfs_config.username = "2EBrzr7ZASQZKH32sl2xWauXPSA" ipfs_config.password = "12290b883db9138a8ae3363b6739d220" diff --git a/examples/spawn-and-move/src/actions.cairo b/examples/spawn-and-move/src/actions.cairo index cd116a2255..f08b1489f7 100644 --- a/examples/spawn-and-move/src/actions.cairo +++ b/examples/spawn-and-move/src/actions.cairo @@ -53,13 +53,13 @@ pub mod actions { let byte: u8 = (uint % 255).try_into().unwrap(); let moves = Moves { - player: seed.try_into().unwrap(), remaining: byte, last_direction: Direction::None + player: seed.try_into().unwrap(), remaining: byte, last_direction: Direction::None, }; let position = Position { - player: seed.try_into().unwrap(), vec: Vec2 { x: prng, y: prng } + player: seed.try_into().unwrap(), vec: Vec2 { x: prng, y: prng }, }; let server_profile = ServerProfile { - player: seed.try_into().unwrap(), server_id: prng, name: "hello" + player: seed.try_into().unwrap(), server_id: prng, name: "hello", }; let player_config = PlayerConfig { player: seed.try_into().unwrap(), @@ -125,7 +125,7 @@ pub mod actions { let items = array![ PlayerItem { item_id: 1, quantity: 100, score: 150 }, - PlayerItem { item_id: 2, quantity: 50, score: -32 } + PlayerItem { item_id: 2, quantity: 50, score: -32 }, ]; let config = PlayerConfig { player, name, items, favorite_item: Option::Some(1) }; @@ -139,7 +139,7 @@ pub mod actions { // Don't need to read the model here, we directly overwrite the member "name". world .write_member( - Model::::ptr_from_keys(player), selector!("name"), name + Model::::ptr_from_keys(player), selector!("name"), name, ); } @@ -207,7 +207,7 @@ pub mod actions { let mut world = self.world_default(); world.write_model(@Moves { player, remaining: 99, last_direction: Direction::None }); - world.write_model(@Position { player, vec: Vec2 { x: 10, y: 10 } },); + world.write_model(@Position { player, vec: Vec2 { x: 10, y: 10 } }); } /// Use the default namespace "ns". A function is handy since the ByteArray @@ -224,20 +224,22 @@ mod tests { use dojo::world::WorldStorageTrait; use dojo_cairo_test::{ spawn_test_world, NamespaceDef, TestResource, ContractDefTrait, ContractDef, - WorldStorageTestTrait + WorldStorageTestTrait, }; use super::{actions, IActionsDispatcher, IActionsDispatcherTrait}; - use dojo_examples::models::{Position, PositionValue, m_Position, Moves, m_Moves, Direction,}; + use dojo_examples::models::{Position, PositionValue, m_Position, Moves, m_Moves, Direction}; fn namespace_def() -> NamespaceDef { let ndef = NamespaceDef { - namespace: "ns", resources: [ + namespace: "ns", + resources: [ TestResource::Model(m_Position::TEST_CLASS_HASH), TestResource::Model(m_Moves::TEST_CLASS_HASH), TestResource::Event(actions::e_Moved::TEST_CLASS_HASH), TestResource::Contract(actions::TEST_CLASS_HASH), - ].span() + ] + .span(), }; ndef @@ -247,7 +249,8 @@ mod tests { [ ContractDefTrait::new(@"ns", @"actions") .with_writer_of([dojo::utils::bytearray_hash(@"ns")].span()) - ].span() + ] + .span() } #[test] @@ -303,7 +306,7 @@ mod tests { let initial_position: Position = world.read_model(caller); assert( - initial_position.vec.x == 10 && initial_position.vec.y == 10, 'wrong initial position' + initial_position.vec.x == 10 && initial_position.vec.y == 10, 'wrong initial position', ); actions_system.move(Direction::Right(())); diff --git a/examples/spawn-and-move/src/models.cairo b/examples/spawn-and-move/src/models.cairo index fc389d2cc9..667cb1c258 100644 --- a/examples/spawn-and-move/src/models.cairo +++ b/examples/spawn-and-move/src/models.cairo @@ -30,7 +30,7 @@ pub struct Message { pub channel: felt252, pub message: ByteArray, #[key] - pub salt: felt252 + pub salt: felt252, } #[derive(Copy, Drop, Serde, Debug)] @@ -39,7 +39,7 @@ pub struct Moves { #[key] pub player: ContractAddress, pub remaining: u8, - pub last_direction: Direction + pub last_direction: Direction, } #[derive(Copy, Drop, Serde, Debug)] @@ -53,7 +53,7 @@ pub struct MockToken { #[derive(Copy, Drop, Serde, IntrospectPacked, Debug)] pub struct Vec2 { pub x: u32, - pub y: u32 + pub y: u32, } // If `Vec2` wasn't packed, the `Position` would be invalid, diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 4d2dee853e..1de01fa45c 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.80.0" +channel = "1.81.0" diff --git a/spawn-and-move-db.tar.gz b/spawn-and-move-db.tar.gz index 7e1c595e95..bde7731fd1 100644 Binary files a/spawn-and-move-db.tar.gz and b/spawn-and-move-db.tar.gz differ diff --git a/types-test-db.tar.gz b/types-test-db.tar.gz index 55c06fae50..1e3a41abc2 100644 Binary files a/types-test-db.tar.gz and b/types-test-db.tar.gz differ diff --git a/xtask/generate-test-db/src/main.rs b/xtask/generate-test-db/src/main.rs index 9a03249e6d..44a66db2eb 100644 --- a/xtask/generate-test-db/src/main.rs +++ b/xtask/generate-test-db/src/main.rs @@ -55,7 +55,7 @@ async fn migrate_spawn_and_move(db_path: &Path) -> Result { panic!( "The deterministic world address is different from the config world address. Please \ review the `dojo_dev.toml` file of spawn-and-move example. \nComputed world address: \ - {:x}", + {:#x}", deterministic_world_address ); }