From 7e5e358d12e5a2931955d88a17328c35cc5fd095 Mon Sep 17 00:00:00 2001 From: glihm Date: Fri, 30 Jun 2023 18:52:19 -0600 Subject: [PATCH] [Dojo] add dojo-core interfaces into their file + snake_case contracts (#588) * add dojo-core interfaces into their file + snake_case The snake_casing of the world and executor contracts has an impact on the dojo-lang and dojo-world. Modifications were made accordingly + refacto into constants to allow future changes * apply cargo fmt * cargo fmt with nightly * fix missing world use path --- crates/dojo-core/src/executor.cairo | 19 +++++-- crates/dojo-core/src/interfaces.cairo | 56 +------------------ crates/dojo-core/src/test_utils.cairo | 7 ++- crates/dojo-core/src/world.cairo | 40 +++++++++++-- crates/dojo-core/src/world_factory.cairo | 31 +++++++--- crates/dojo-core/tests/src/executor.cairo | 9 +-- crates/dojo-core/tests/src/world.cairo | 13 ++--- .../dojo-core/tests/src/world_factory.cairo | 26 ++++----- crates/dojo-erc/src/erc20/erc20.cairo | 2 +- crates/dojo-lang/src/manifest.rs | 29 +++++++--- crates/dojo-lang/src/plugin_test_data/system | 12 ++-- crates/dojo-lang/src/system.rs | 4 +- crates/dojo-world/src/manifest.rs | 7 ++- crates/dojo-world/src/migration/world.rs | 6 +- examples/ecs/Scarb.toml | 2 +- examples/ecs/src/systems.cairo | 2 +- 16 files changed, 137 insertions(+), 128 deletions(-) diff --git a/crates/dojo-core/src/executor.cairo b/crates/dojo-core/src/executor.cairo index d3c5078001..af48c927d6 100644 --- a/crates/dojo-core/src/executor.cairo +++ b/crates/dojo-core/src/executor.cairo @@ -1,17 +1,26 @@ +use dojo::world::Context; + +#[starknet::interface] +trait IExecutor { + fn execute(self: @T, ctx: Context, calldata: Span) -> Span; +} + #[starknet::contract] -mod Executor { +mod executor { use array::{ArrayTrait, ArrayTCloneImpl, SpanTrait}; use serde::Serde; use clone::Clone; use box::BoxTrait; - use traits::Into; + use traits::{TryInto, Into}; + use option::OptionTrait; use starknet::{get_caller_address, get_tx_info}; - use dojo::interfaces::{ - IWorldDispatcher, ISystemLibraryDispatcher, ISystemDispatcherTrait, IExecutor - }; + use dojo::world::IWorldDispatcher; + use dojo::interfaces::{ISystemLibraryDispatcher, ISystemDispatcherTrait}; use dojo::world::Context; + use super::IExecutor; + const EXECUTE_ENTRYPOINT: felt252 = 0x0240060cdb34fcc260f41eac7474ee1d7c80b7e3607daff9ac67c7ea2ebb1c44; diff --git a/crates/dojo-core/src/interfaces.cairo b/crates/dojo-core/src/interfaces.cairo index b58b1be9ec..e54f1ae54c 100644 --- a/crates/dojo-core/src/interfaces.cairo +++ b/crates/dojo-core/src/interfaces.cairo @@ -1,47 +1,4 @@ -use serde::Serde; -use array::{ArrayTrait, SpanTrait}; -use traits::{TryInto, Into}; -use option::OptionTrait; - -use starknet::{ClassHash, ContractAddress}; -use starknet::contract_address::Felt252TryIntoContractAddress; - -use dojo::database::query::Query; -use dojo::world::Context; - -#[starknet::interface] -trait IWorld { - fn component(self: @T, name: felt252) -> ClassHash; - fn register_component(ref self: T, class_hash: ClassHash); - fn system(self: @T, name: felt252) -> ClassHash; - fn register_system(ref self: T, class_hash: ClassHash); - fn uuid(ref self: T) -> usize; - fn emit(self: @T, keys: Span, values: Span); - fn execute(ref self: T, system: felt252, calldata: Span) -> Span; - fn entity( - self: @T, component: felt252, query: Query, offset: u8, length: usize - ) -> Span; - fn set_entity(ref self: T, component: felt252, query: Query, offset: u8, value: Span); - fn entities( - self: @T, component: felt252, partition: felt252 - ) -> (Span, Span>); - fn set_executor(ref self: T, contract_address: ContractAddress); - fn executor(self: @T) -> ContractAddress; - fn delete_entity(ref self: T, component: felt252, query: Query); - - fn is_owner(self: @T, account: ContractAddress, target: felt252) -> bool; - fn grant_owner(ref self: T, account: ContractAddress, target: felt252); - fn revoke_owner(ref self: T, account: ContractAddress, target: felt252); - - fn is_writer(self: @T, component: felt252, system: felt252) -> bool; - fn grant_writer(ref self: T, component: felt252, system: felt252); - fn revoke_writer(ref self: T, component: felt252, system: felt252); -} - -#[starknet::interface] -trait IExecutor { - fn execute(self: @T, ctx: Context, calldata: Span) -> Span; -} +use array::ArrayTrait; #[starknet::interface] trait IComponent { @@ -54,14 +11,3 @@ trait ISystem { fn name(self: @T) -> felt252; fn dependencies(self: @T) -> Array<(felt252, bool)>; } - -#[starknet::interface] -trait IWorldFactory { - fn set_world(ref self: T, class_hash: ClassHash); - fn set_executor(ref self: T, executor_address: ContractAddress); - fn spawn( - ref self: T, components: Array, systems: Array, - ) -> ContractAddress; - fn world(self: @T) -> ClassHash; - fn executor(self: @T) -> ContractAddress; -} diff --git a/crates/dojo-core/src/test_utils.cairo b/crates/dojo-core/src/test_utils.cairo index 8fc068713f..e70afaa290 100644 --- a/crates/dojo-core/src/test_utils.cairo +++ b/crates/dojo-core/src/test_utils.cairo @@ -7,13 +7,14 @@ use traits::TryInto; use option::OptionTrait; use core::{result::ResultTrait, traits::Into}; -use dojo::{executor::Executor, world::World, interfaces::{IWorldDispatcher, IWorldDispatcherTrait}}; +use dojo::executor::executor; +use dojo::world::{world, IWorldDispatcher, IWorldDispatcherTrait}; fn spawn_test_world(components: Array, systems: Array) -> IWorldDispatcher { // deploy executor let constructor_calldata = array::ArrayTrait::new(); let (executor_address, _) = deploy_syscall( - Executor::TEST_CLASS_HASH.try_into().unwrap(), 0, constructor_calldata.span(), false + executor::TEST_CLASS_HASH.try_into().unwrap(), 0, constructor_calldata.span(), false ) .unwrap(); @@ -21,7 +22,7 @@ fn spawn_test_world(components: Array, systems: Array) -> IWor let mut world_constructor_calldata = array::ArrayTrait::new(); world_constructor_calldata.append(executor_address.into()); let (world_address, _) = deploy_syscall( - World::TEST_CLASS_HASH.try_into().unwrap(), 0, world_constructor_calldata.span(), false + world::TEST_CLASS_HASH.try_into().unwrap(), 0, world_constructor_calldata.span(), false ) .unwrap(); let world = IWorldDispatcher { contract_address: world_address }; diff --git a/crates/dojo-core/src/world.cairo b/crates/dojo-core/src/world.cairo index ee37b660f9..fd33d21cf5 100644 --- a/crates/dojo-core/src/world.cairo +++ b/crates/dojo-core/src/world.cairo @@ -2,7 +2,7 @@ use starknet::{ContractAddress, ClassHash, StorageAccess, StorageBaseAddress, Sy use traits::{Into, TryInto}; use option::OptionTrait; -use dojo::interfaces::{IWorldDispatcher, IWorldDispatcherTrait}; +use dojo::database::query::{Query, QueryTrait}; #[derive(Copy, Drop, Serde)] struct Context { @@ -12,8 +12,37 @@ struct Context { system_class_hash: ClassHash, // Class hash of the calling system } +#[starknet::interface] +trait IWorld { + fn component(self: @T, name: felt252) -> ClassHash; + fn register_component(ref self: T, class_hash: ClassHash); + fn system(self: @T, name: felt252) -> ClassHash; + fn register_system(ref self: T, class_hash: ClassHash); + fn uuid(ref self: T) -> usize; + fn emit(self: @T, keys: Span, values: Span); + fn execute(ref self: T, system: felt252, calldata: Span) -> Span; + fn entity( + self: @T, component: felt252, query: Query, offset: u8, length: usize + ) -> Span; + fn set_entity(ref self: T, component: felt252, query: Query, offset: u8, value: Span); + fn entities( + self: @T, component: felt252, partition: felt252 + ) -> (Span, Span>); + fn set_executor(ref self: T, contract_address: ContractAddress); + fn executor(self: @T) -> ContractAddress; + fn delete_entity(ref self: T, component: felt252, query: Query); + + fn is_owner(self: @T, account: ContractAddress, target: felt252) -> bool; + fn grant_owner(ref self: T, account: ContractAddress, target: felt252); + fn revoke_owner(ref self: T, account: ContractAddress, target: felt252); + + fn is_writer(self: @T, component: felt252, system: felt252) -> bool; + fn grant_writer(ref self: T, component: felt252, system: felt252); + fn revoke_writer(ref self: T, component: felt252, system: felt252); +} + #[starknet::contract] -mod World { +mod world { use array::{ArrayTrait, SpanTrait}; use traits::Into; use option::OptionTrait; @@ -27,11 +56,12 @@ mod World { use dojo::database; use dojo::database::query::{Query, QueryTrait}; + use dojo::executor::{IExecutorDispatcher, IExecutorDispatcherTrait}; use dojo::interfaces::{ - IComponentLibraryDispatcher, IComponentDispatcherTrait, IExecutorDispatcher, - IExecutorDispatcherTrait, ISystemLibraryDispatcher, ISystemDispatcherTrait, - IWorldDispatcher, IWorld + IComponentLibraryDispatcher, IComponentDispatcherTrait, ISystemLibraryDispatcher, + ISystemDispatcherTrait }; + use dojo::world::{IWorldDispatcher, IWorld}; use super::Context; diff --git a/crates/dojo-core/src/world_factory.cairo b/crates/dojo-core/src/world_factory.cairo index 660be59670..716517084f 100644 --- a/crates/dojo-core/src/world_factory.cairo +++ b/crates/dojo-core/src/world_factory.cairo @@ -1,7 +1,20 @@ use array::ArrayTrait; +use starknet::{ClassHash, ContractAddress}; + +#[starknet::interface] +trait IWorldFactory { + fn set_world(ref self: T, class_hash: ClassHash); + fn set_executor(ref self: T, executor_address: ContractAddress); + fn spawn( + ref self: T, components: Array, systems: Array, + ) -> ContractAddress; + fn world(self: @T) -> ClassHash; + fn executor(self: @T) -> ContractAddress; +} + #[starknet::contract] -mod WorldFactory { +mod world_factory { use array::ArrayTrait; use option::OptionTrait; use traits::Into; @@ -11,7 +24,9 @@ mod WorldFactory { syscalls::deploy_syscall, get_caller_address }; - use dojo::interfaces::{IWorldDispatcher, IWorldDispatcherTrait, IWorldFactory}; + use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; + + use super::IWorldFactory; #[storage] struct Storage { @@ -32,7 +47,7 @@ mod WorldFactory { #[constructor] fn constructor( - ref self: ContractState, world_class_hash_: ClassHash, executor_address_: ContractAddress, + ref self: ContractState, world_class_hash_: ClassHash, executor_address_: ContractAddress, ) { self.world_class_hash.write(world_class_hash_); self.executor_address.write(executor_address_); @@ -44,14 +59,14 @@ mod WorldFactory { /// /// # Arguments /// - /// * `components` - The components to be registered. - /// * `systems` - The systems to be registered. + /// * `components` - The components to be registered. + /// * `systems` - The systems to be registered. /// /// # Returns /// /// The address of the deployed world. fn spawn( - ref self: ContractState, components: Array, systems: Array, + ref self: ContractState, components: Array, systems: Array, ) -> ContractAddress { // deploy world let mut world_constructor_calldata: Array = ArrayTrait::new(); @@ -81,7 +96,7 @@ mod WorldFactory { /// /// # Arguments /// - /// * `executor_address` - The address of the executor. + /// * `executor_address` - The address of the executor. fn set_executor(ref self: ContractState, executor_address: ContractAddress) { self.executor_address.write(executor_address); } @@ -90,7 +105,7 @@ mod WorldFactory { /// /// # Arguments /// - /// * `class_hash` - The class hash of world. + /// * `class_hash` - The class hash of world. fn set_world(ref self: ContractState, class_hash: ClassHash) { self.world_class_hash.write(class_hash); } diff --git a/crates/dojo-core/tests/src/executor.cairo b/crates/dojo-core/tests/src/executor.cairo index 7f060dc129..42bf900731 100644 --- a/crates/dojo-core/tests/src/executor.cairo +++ b/crates/dojo-core/tests/src/executor.cairo @@ -6,11 +6,8 @@ use traits::TryInto; use starknet::syscalls::deploy_syscall; use starknet::class_hash::Felt252TryIntoClassHash; -use dojo::interfaces::IExecutorDispatcher; -use dojo::interfaces::IExecutorDispatcherTrait; -use dojo::interfaces::IWorldDispatcher; -use dojo::executor::Executor; -use dojo::world::Context; +use dojo::executor::{executor, IExecutorDispatcher, IExecutorDispatcherTrait}; +use dojo::world::{Context, IWorldDispatcher}; #[derive(Component, Copy, Drop, Serde)] struct Foo { @@ -32,7 +29,7 @@ mod Bar { fn test_executor() { let constructor_calldata = array::ArrayTrait::new(); let (executor_address, _) = deploy_syscall( - Executor::TEST_CLASS_HASH.try_into().unwrap(), 0, constructor_calldata.span(), false + executor::TEST_CLASS_HASH.try_into().unwrap(), 0, constructor_calldata.span(), false ) .unwrap(); diff --git a/crates/dojo-core/tests/src/world.cairo b/crates/dojo-core/tests/src/world.cairo index b84380189b..28aa0fc53f 100644 --- a/crates/dojo-core/tests/src/world.cairo +++ b/crates/dojo-core/tests/src/world.cairo @@ -11,11 +11,8 @@ use starknet::get_caller_address; use starknet::syscalls::deploy_syscall; use dojo::database::query::QueryTrait; -use dojo::interfaces::IWorldDispatcher; -use dojo::interfaces::IWorldDispatcherTrait; -use dojo::executor::Executor; -use dojo::world::World; -use dojo::world::library_call; +use dojo::executor::executor; +use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait, library_call, world}; // Components and Systems @@ -61,7 +58,7 @@ fn deploy_world() -> IWorldDispatcher { let mut calldata: Array = array::ArrayTrait::new(); calldata.append(starknet::contract_address_const::<0x0>().into()); let (world_address, _) = deploy_syscall( - World::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false + world::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false ) .unwrap(); @@ -193,7 +190,7 @@ fn spawn_empty_world() -> IWorldDispatcher { // Deploy executor contract let executor_constructor_calldata = array::ArrayTrait::new(); let (executor_address, _) = deploy_syscall( - Executor::TEST_CLASS_HASH.try_into().unwrap(), + executor::TEST_CLASS_HASH.try_into().unwrap(), 0, executor_constructor_calldata.span(), false @@ -204,7 +201,7 @@ fn spawn_empty_world() -> IWorldDispatcher { let mut constructor_calldata = array::ArrayTrait::new(); constructor_calldata.append(executor_address.into()); let (world_address, _) = deploy_syscall( - World::TEST_CLASS_HASH.try_into().unwrap(), 0, constructor_calldata.span(), false + world::TEST_CLASS_HASH.try_into().unwrap(), 0, constructor_calldata.span(), false ) .unwrap(); let world = IWorldDispatcher { contract_address: world_address }; diff --git a/crates/dojo-core/tests/src/world_factory.cairo b/crates/dojo-core/tests/src/world_factory.cairo index 720b606242..acb2fb60d2 100644 --- a/crates/dojo-core/tests/src/world_factory.cairo +++ b/crates/dojo-core/tests/src/world_factory.cairo @@ -10,13 +10,11 @@ use starknet::syscalls::deploy_syscall; use starknet::get_caller_address; use starknet::class_hash::ClassHash; use starknet::class_hash::Felt252TryIntoClassHash; -use dojo::interfaces::IWorldFactoryDispatcher; -use dojo::interfaces::IWorldFactoryDispatcherTrait; -use dojo::interfaces::IWorldDispatcher; -use dojo::interfaces::IWorldDispatcherTrait; -use dojo::executor::Executor; -use dojo::world::World; -use dojo::world_factory::WorldFactory; + +use dojo::executor::executor; +use dojo::world_factory::{IWorldFactoryDispatcher, IWorldFactoryDispatcherTrait, world_factory}; +use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait, world}; + #[derive(Component, Copy, Drop, Serde)] struct Foo { @@ -41,7 +39,7 @@ fn test_constructor() { calldata.append(starknet::contract_address_const::<0x69>().into()); let (factory_address, _) = deploy_syscall( - WorldFactory::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false + world_factory::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false ) .unwrap(); @@ -59,24 +57,24 @@ fn test_spawn_world() { // Deploy Executor let constructor_calldata = array::ArrayTrait::new(); let (executor_address, _) = deploy_syscall( - Executor::TEST_CLASS_HASH.try_into().unwrap(), 0, constructor_calldata.span(), false + executor::TEST_CLASS_HASH.try_into().unwrap(), 0, constructor_calldata.span(), false ) .unwrap(); // WorldFactory constructor let mut calldata: Array = array::ArrayTrait::new(); - calldata.append(World::TEST_CLASS_HASH); + calldata.append(world::TEST_CLASS_HASH); calldata.append(executor_address.into()); let (factory_address, _) = deploy_syscall( - WorldFactory::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false + world_factory::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false ) .unwrap(); let factory = IWorldFactoryDispatcher { contract_address: factory_address }; assert(factory.executor() == executor_address, 'wrong executor address'); - assert(factory.world() == World::TEST_CLASS_HASH.try_into().unwrap(), 'wrong world class hash'); + assert(factory.world() == world::TEST_CLASS_HASH.try_into().unwrap(), 'wrong world class hash'); // Prepare components and systems let mut systems: Array = array::ArrayTrait::new(); @@ -91,9 +89,7 @@ fn test_spawn_world() { // Check Foo component and Bar system are registered let foo_hash = world.component('Foo'.into()); - assert( - foo_hash == foo::TEST_CLASS_HASH.try_into().unwrap(), 'component not registered' - ); + assert(foo_hash == foo::TEST_CLASS_HASH.try_into().unwrap(), 'component not registered'); let bar_hash = world.system('bar'.into()); assert(bar_hash == bar::TEST_CLASS_HASH.try_into().unwrap(), 'system not registered'); diff --git a/crates/dojo-erc/src/erc20/erc20.cairo b/crates/dojo-erc/src/erc20/erc20.cairo index bea7938baf..8b0d6a3e80 100644 --- a/crates/dojo-erc/src/erc20/erc20.cairo +++ b/crates/dojo-erc/src/erc20/erc20.cairo @@ -20,7 +20,7 @@ mod ERC20 { IntoPartitionedQuery }; - use dojo::interfaces::{IWorldDispatcher, IWorldDispatcherTrait}; + use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; use dojo_erc::erc20::components::{Allowance, Balance, Supply}; #[storage] diff --git a/crates/dojo-lang/src/manifest.rs b/crates/dojo-lang/src/manifest.rs index 5b53ca43c5..6a84b49b19 100644 --- a/crates/dojo-lang/src/manifest.rs +++ b/crates/dojo-lang/src/manifest.rs @@ -6,7 +6,9 @@ use cairo_lang_filesystem::ids::CrateId; use cairo_lang_semantic::db::SemanticGroup; use cairo_lang_semantic::plugin::DynPluginAuxData; use convert_case::{Case, Casing}; -use dojo_world::manifest::{Contract, Input, Output, System}; +use dojo_world::manifest::{ + Contract, Input, Output, System, EXECUTOR_CONTRACT_NAME, WORLD_CONTRACT_NAME, +}; use itertools::Itertools; use serde::Serialize; use smol_str::SmolStr; @@ -25,16 +27,29 @@ impl Manifest { ) -> Self { let mut manifest = Manifest(dojo_world::manifest::Manifest::default()); - let world = compiled_classes.get("World").unwrap_or_else(|| { - panic!("World contract not found. Did you include `dojo` as a dependency?"); + let world = compiled_classes.get(WORLD_CONTRACT_NAME).unwrap_or_else(|| { + panic!( + "{}", + format!( + "Contract `{}` not found. Did you include `dojo` as a dependency?", + WORLD_CONTRACT_NAME + ) + ); }); - let executor = compiled_classes.get("Executor").unwrap_or_else(|| { - panic!("Executor contract not found. Did you include `dojo` as a dependency?"); + let executor = compiled_classes.get(EXECUTOR_CONTRACT_NAME).unwrap_or_else(|| { + panic!( + "{}", + format!( + "Contract `{}` not found. Did you include `dojo` as a dependency?", + EXECUTOR_CONTRACT_NAME + ) + ); }); - manifest.0.world = Contract { name: "World".into(), address: None, class_hash: *world }; + manifest.0.world = + Contract { name: WORLD_CONTRACT_NAME.into(), address: None, class_hash: *world }; manifest.0.executor = - Contract { name: "Excecutor".into(), address: None, class_hash: *executor }; + Contract { name: EXECUTOR_CONTRACT_NAME.into(), address: None, class_hash: *executor }; for crate_id in crate_ids { let modules = db.crate_modules(*crate_id); diff --git a/crates/dojo-lang/src/plugin_test_data/system b/crates/dojo-lang/src/plugin_test_data/system index e069cb5196..6c63bda31b 100644 --- a/crates/dojo-lang/src/plugin_test_data/system +++ b/crates/dojo-lang/src/plugin_test_data/system @@ -265,8 +265,8 @@ mod spawn { use array::SpanTrait; use dojo::world; - use dojo::interfaces::IWorldDispatcher; - use dojo::interfaces::IWorldDispatcherTrait; + use dojo::world::IWorldDispatcher; + use dojo::world::IWorldDispatcherTrait; use dojo::database::query::Query; use dojo::database::query::QueryTrait; use dojo::database::query::LiteralIntoQuery; @@ -405,8 +405,8 @@ mod move { use array::SpanTrait; use dojo::world; - use dojo::interfaces::IWorldDispatcher; - use dojo::interfaces::IWorldDispatcherTrait; + use dojo::world::IWorldDispatcher; + use dojo::world::IWorldDispatcherTrait; use dojo::database::query::Query; use dojo::database::query::QueryTrait; use dojo::database::query::LiteralIntoQuery; @@ -944,8 +944,8 @@ mod proxy { use array::SpanTrait; use dojo::world; - use dojo::interfaces::IWorldDispatcher; - use dojo::interfaces::IWorldDispatcherTrait; + use dojo::world::IWorldDispatcher; + use dojo::world::IWorldDispatcherTrait; use dojo::database::query::Query; use dojo::database::query::QueryTrait; use dojo::database::query::LiteralIntoQuery; diff --git a/crates/dojo-lang/src/system.rs b/crates/dojo-lang/src/system.rs index 75adda67e3..8da680a1a0 100644 --- a/crates/dojo-lang/src/system.rs +++ b/crates/dojo-lang/src/system.rs @@ -51,8 +51,8 @@ impl System { use array::SpanTrait; use dojo::world; - use dojo::interfaces::IWorldDispatcher; - use dojo::interfaces::IWorldDispatcherTrait; + use dojo::world::IWorldDispatcher; + use dojo::world::IWorldDispatcherTrait; use dojo::database::query::Query; use dojo::database::query::QueryTrait; use dojo::database::query::LiteralIntoQuery; diff --git a/crates/dojo-world/src/manifest.rs b/crates/dojo-world/src/manifest.rs index 94d63996ec..d4a03b3b79 100644 --- a/crates/dojo-world/src/manifest.rs +++ b/crates/dojo-world/src/manifest.rs @@ -17,6 +17,9 @@ use thiserror::Error; #[path = "manifest_test.rs"] mod test; +pub const WORLD_CONTRACT_NAME: &str = "world"; +pub const EXECUTOR_CONTRACT_NAME: &str = "executor"; + #[derive(Error, Debug)] pub enum ManifestError { #[error("Remote World not found.")] @@ -214,12 +217,12 @@ impl Manifest { components, contracts: vec![], world: Contract { - name: "World".into(), + name: WORLD_CONTRACT_NAME.into(), class_hash: world_class_hash, address: Some(world_address), }, executor: Contract { - name: "Executor".into(), + name: EXECUTOR_CONTRACT_NAME.into(), address: Some(executor_address), class_hash: executor_class_hash, }, diff --git a/crates/dojo-world/src/migration/world.rs b/crates/dojo-world/src/migration/world.rs index d69cf5029a..ce627e86b3 100644 --- a/crates/dojo-world/src/migration/world.rs +++ b/crates/dojo-world/src/migration/world.rs @@ -3,7 +3,7 @@ use std::fmt::Display; use super::class::ClassDiff; use super::contract::ContractDiff; use super::StateDiff; -use crate::manifest::Manifest; +use crate::manifest::{Manifest, EXECUTOR_CONTRACT_NAME, WORLD_CONTRACT_NAME}; /// Represents the state differences between the local and remote worlds. #[derive(Debug)] @@ -56,14 +56,14 @@ impl WorldDiff { .collect::>(); let world = ContractDiff { - name: "World".into(), + name: WORLD_CONTRACT_NAME.into(), address: remote.as_ref().and_then(|m| m.world.address), local: local.world.class_hash, remote: remote.as_ref().map(|m| m.world.class_hash), }; let executor = ContractDiff { - name: "Executor".into(), + name: EXECUTOR_CONTRACT_NAME.into(), address: remote.as_ref().and_then(|m| m.executor.address), local: local.executor.class_hash, remote: remote.map(|m| m.executor.class_hash), diff --git a/examples/ecs/Scarb.toml b/examples/ecs/Scarb.toml index 7563fffee1..7ccd93276a 100644 --- a/examples/ecs/Scarb.toml +++ b/examples/ecs/Scarb.toml @@ -1,7 +1,7 @@ [package] name = "dojo_examples" version = "0.1.0" -cairo-version = "2.0.0-rc4" +cairo-version = "2.0.0-rc6" [cairo] sierra-replace-ids = true diff --git a/examples/ecs/src/systems.cairo b/examples/ecs/src/systems.cairo index 8893a88005..98cd832cf1 100644 --- a/examples/ecs/src/systems.cairo +++ b/examples/ecs/src/systems.cairo @@ -79,7 +79,7 @@ mod tests { use core::traits::Into; use array::ArrayTrait; - use dojo::interfaces::IWorldDispatcherTrait; + use dojo::world::IWorldDispatcherTrait; use dojo::test_utils::spawn_test_world;