From 548f445ecb9effe9b219cd84b5dd0fc9904a6180 Mon Sep 17 00:00:00 2001 From: glihm Date: Sat, 23 Mar 2024 23:48:09 -0600 Subject: [PATCH 1/9] feat: add support for AbiFormat (path or embed) --- crates/dojo-lang/src/compiler.rs | 4 +- crates/dojo-world/src/manifest.rs | 75 ++++++++++++++++++++++------ crates/sozo/ops/src/events.rs | 6 +-- crates/sozo/ops/src/migration/mod.rs | 23 +++++---- 4 files changed, 78 insertions(+), 30 deletions(-) diff --git a/crates/dojo-lang/src/compiler.rs b/crates/dojo-lang/src/compiler.rs index ae4466728e..6270a95755 100644 --- a/crates/dojo-lang/src/compiler.rs +++ b/crates/dojo-lang/src/compiler.rs @@ -17,7 +17,7 @@ use cairo_lang_utils::UpcastMut; use camino::Utf8PathBuf; use convert_case::{Case, Casing}; use dojo_world::manifest::{ - Class, ComputedValueEntrypoint, DojoContract, DojoModel, Manifest, ManifestMethods, + AbiFormat, Class, ComputedValueEntrypoint, DojoContract, DojoModel, Manifest, ManifestMethods, BASE_CONTRACT_NAME, WORLD_CONTRACT_NAME, }; use itertools::Itertools; @@ -451,7 +451,7 @@ where let relative_abi_path = relative_abis_dir.join(name.clone()).with_extension("json"); if abi.is_some() { - manifest.inner.set_abi(Some(relative_abi_path.clone())); + manifest.inner.set_abi(Some(AbiFormat::Path(relative_abi_path.clone()))); } let manifest_toml = toml::to_string_pretty(&manifest)?; diff --git a/crates/dojo-world/src/manifest.rs b/crates/dojo-world/src/manifest.rs index e4e0ce3d4d..4b468bc874 100644 --- a/crates/dojo-world/src/manifest.rs +++ b/crates/dojo-world/src/manifest.rs @@ -81,7 +81,7 @@ pub struct DojoModel { pub members: Vec, #[serde_as(as = "UfeHex")] pub class_hash: FieldElement, - pub abi: Option, + pub abi: Option, } /// System input ABI. @@ -110,6 +110,26 @@ pub struct ComputedValueEntrypoint { pub model: Option, } +/// Format of the ABI into the manifest file. +#[serde_as] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[serde(untagged)] +pub enum AbiFormat { + /// Only a relative path to the ABI file is stored. + Path(Utf8PathBuf), + /// The full ABI is embedded as a string. + Embed(String), +} + +impl AbiFormat { + pub fn to_path(&self) -> Option<&Utf8PathBuf> { + match self { + AbiFormat::Path(p) => Some(p), + AbiFormat::Embed(_) => None, + } + } +} + #[serde_as] #[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq)] #[serde(tag = "kind")] @@ -118,7 +138,7 @@ pub struct DojoContract { pub address: Option, #[serde_as(as = "UfeHex")] pub class_hash: FieldElement, - pub abi: Option, + pub abi: Option, pub reads: Vec, pub writes: Vec, pub computed: Vec, @@ -151,7 +171,7 @@ pub struct OverlayClass {} pub struct Class { #[serde_as(as = "UfeHex")] pub class_hash: FieldElement, - pub abi: Option, + pub abi: Option, } #[serde_as] @@ -160,7 +180,7 @@ pub struct Class { pub struct Contract { #[serde_as(as = "UfeHex")] pub class_hash: FieldElement, - pub abi: Option, + pub abi: Option, #[serde_as(as = "Option")] pub address: Option, #[serde_as(as = "Option")] @@ -236,8 +256,8 @@ where pub trait ManifestMethods { type OverlayType; - fn abi(&self) -> Option<&Utf8PathBuf>; - fn set_abi(&mut self, abi: Option); + fn abi(&self) -> Option<&AbiFormat>; + fn set_abi(&mut self, abi: Option); fn class_hash(&self) -> &FieldElement; fn set_class_hash(&mut self, class_hash: FieldElement); @@ -300,7 +320,7 @@ impl DeploymentManifest { self.world.inner.seed = previous.world.inner.seed; } - pub fn write_to_path(&self, path: &Utf8PathBuf) -> Result<()> { + pub fn write_to_path_toml(&self, path: &Utf8PathBuf) -> Result<()> { fs::create_dir_all(path.parent().unwrap())?; let deployed_manifest = toml::to_string_pretty(&self)?; @@ -309,6 +329,31 @@ impl DeploymentManifest { Ok(()) } + pub fn write_to_path_json(&self, path: &Utf8PathBuf, manifest_dir: &Utf8PathBuf) -> Result<()> { + fs::create_dir_all(path.parent().unwrap())?; + + // Embedding ABIs into the manifest. + let mut manifest_with_abis = self.clone(); + for contract in &mut manifest_with_abis.contracts { + if let Some(abi_path) = &contract.inner.abi { + match abi_path { + AbiFormat::Path(p) => { + println!("PATH {}", p.to_string()); + let abi_content = fs::read_to_string(manifest_dir.join(p))?; + contract.inner.abi = Some(AbiFormat::Embed(abi_content)); + } + // If the ABI is already embedded, do nothing. + _ => {} + } + } + } + + let deployed_manifest = serde_json::to_string(&manifest_with_abis)?; + fs::write(path, deployed_manifest)?; + + Ok(()) + } + /// Construct a manifest of a remote World. /// /// # Arguments @@ -628,11 +673,11 @@ where impl ManifestMethods for DojoContract { type OverlayType = OverlayDojoContract; - fn abi(&self) -> Option<&Utf8PathBuf> { + fn abi(&self) -> Option<&AbiFormat> { self.abi.as_ref() } - fn set_abi(&mut self, abi: Option) { + fn set_abi(&mut self, abi: Option) { self.abi = abi; } @@ -657,11 +702,11 @@ impl ManifestMethods for DojoContract { impl ManifestMethods for DojoModel { type OverlayType = OverlayDojoModel; - fn abi(&self) -> Option<&Utf8PathBuf> { + fn abi(&self) -> Option<&AbiFormat> { self.abi.as_ref() } - fn set_abi(&mut self, abi: Option) { + fn set_abi(&mut self, abi: Option) { self.abi = abi; } @@ -679,11 +724,11 @@ impl ManifestMethods for DojoModel { impl ManifestMethods for Contract { type OverlayType = OverlayContract; - fn abi(&self) -> Option<&Utf8PathBuf> { + fn abi(&self) -> Option<&AbiFormat> { self.abi.as_ref() } - fn set_abi(&mut self, abi: Option) { + fn set_abi(&mut self, abi: Option) { self.abi = abi; } @@ -701,11 +746,11 @@ impl ManifestMethods for Contract { impl ManifestMethods for Class { type OverlayType = OverlayClass; - fn abi(&self) -> Option<&Utf8PathBuf> { + fn abi(&self) -> Option<&AbiFormat> { self.abi.as_ref() } - fn set_abi(&mut self, abi: Option) { + fn set_abi(&mut self, abi: Option) { self.abi = abi; } diff --git a/crates/sozo/ops/src/events.rs b/crates/sozo/ops/src/events.rs index dab6401cc1..bca1ab3a67 100644 --- a/crates/sozo/ops/src/events.rs +++ b/crates/sozo/ops/src/events.rs @@ -6,7 +6,7 @@ use cainome::parser::tokens::{CompositeInner, CompositeInnerKind, CoreBasic, Tok use cainome::parser::AbiParser; use camino::Utf8PathBuf; use dojo_lang::compiler::{DEPLOYMENTS_DIR, MANIFESTS_DIR}; -use dojo_world::manifest::{DeploymentManifest, ManifestMethods}; +use dojo_world::manifest::{AbiFormat, DeploymentManifest, ManifestMethods}; use starknet::core::types::{BlockId, EventFilter, FieldElement}; use starknet::core::utils::{parse_cairo_short_string, starknet_keccak}; use starknet::providers::jsonrpc::HttpTransport; @@ -104,14 +104,14 @@ fn extract_events( let mut events_map = HashMap::new(); for contract in &manifest.contracts { - if let Some(abi_path) = contract.inner.abi() { + if let Some(AbiFormat::Path(abi_path)) = contract.inner.abi() { let full_abi_path = manifest_dir.join(abi_path); process_abi(&mut events_map, &full_abi_path)?; } } for model in &manifest.contracts { - if let Some(abi_path) = model.inner.abi() { + if let Some(AbiFormat::Path(abi_path)) = model.inner.abi() { let full_abi_path = manifest_dir.join(abi_path); process_abi(&mut events_map, &full_abi_path)?; } diff --git a/crates/sozo/ops/src/migration/mod.rs b/crates/sozo/ops/src/migration/mod.rs index 7c93ac4a6a..679855a2a4 100644 --- a/crates/sozo/ops/src/migration/mod.rs +++ b/crates/sozo/ops/src/migration/mod.rs @@ -7,7 +7,7 @@ use dojo_world::contracts::abi::world::ResourceMetadata; use dojo_world::contracts::cairo_utils; use dojo_world::contracts::world::WorldContract; use dojo_world::manifest::{ - AbstractManifestError, BaseManifest, DeploymentManifest, DojoContract, Manifest, + AbiFormat, AbstractManifestError, BaseManifest, DeploymentManifest, DojoContract, Manifest, ManifestMethods, OverlayManifest, }; use dojo_world::metadata::dojo_metadata_from_workspace; @@ -133,6 +133,10 @@ where Ok(()) } +fn build_deployed_path(manifest_dir: &Utf8PathBuf, chain_id: &str, extension: &str) -> Utf8PathBuf { + manifest_dir.join(MANIFESTS_DIR).join(DEPLOYMENTS_DIR).join(chain_id).with_extension(extension) +} + async fn update_manifests_and_abis( ws: &Workspace<'_>, local_manifest: BaseManifest, @@ -145,11 +149,8 @@ async fn update_manifests_and_abis( let ui = ws.config().ui(); ui.print("\n✨ Updating manifests..."); - let deployed_path = manifest_dir - .join(MANIFESTS_DIR) - .join(DEPLOYMENTS_DIR) - .join(chain_id) - .with_extension("toml"); + let deployed_path = build_deployed_path(manifest_dir, chain_id, "toml"); + let deployed_path_json = build_deployed_path(manifest_dir, chain_id, "json"); let mut local_manifest: DeploymentManifest = local_manifest.into(); @@ -185,7 +186,8 @@ async fn update_manifests_and_abis( // local_manifest update_manifest_abis(&mut local_manifest, manifest_dir, chain_id).await; - local_manifest.write_to_path(&deployed_path)?; + local_manifest.write_to_path_toml(&deployed_path)?; + local_manifest.write_to_path_json(&deployed_path_json, manifest_dir)?; ui.print("\n✨ Done."); Ok(()) @@ -204,8 +206,9 @@ async fn update_manifest_abis( where T: ManifestMethods, { - // unwraps in call to abi is safe because we always write abis for DojoContracts - let base_relative_path = manifest.inner.abi().unwrap(); + // unwraps in call to abi is safe because we always write abis for DojoContracts as relative + // path. + let base_relative_path = manifest.inner.abi().unwrap().to_path().unwrap(); let deployed_relative_path = Utf8PathBuf::new().join(ABIS_DIR).join(DEPLOYMENTS_DIR).join(chain_id).join( base_relative_path @@ -220,7 +223,7 @@ async fn update_manifest_abis( .await .expect("Failed to create folder"); fs::copy(full_base_path, full_deployed_path).await.expect("Failed to copy abi file"); - manifest.inner.set_abi(Some(deployed_relative_path)); + manifest.inner.set_abi(Some(AbiFormat::Path(deployed_relative_path))); } for contract in local_manifest.contracts.iter_mut() { From 2b2cbf4d2c5f81aaf6e40c102d414f90155ef56d Mon Sep 17 00:00:00 2001 From: glihm Date: Sat, 23 Mar 2024 23:48:37 -0600 Subject: [PATCH 2/9] fix: add example updated manifests --- .../abis/base/contracts/actions.json | 2 +- .../deployments/KATANA/contracts/actions.json | 2 +- .../manifests/base/contracts/actions.toml | 2 +- .../manifests/base/models/moved.toml | 13 +++++++++++ .../manifests/deployments/KATANA.json | 1 + .../manifests/deployments/KATANA.toml | 22 +++++++++++++++++-- 6 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 examples/spawn-and-move/manifests/base/models/moved.toml create mode 100644 examples/spawn-and-move/manifests/deployments/KATANA.json diff --git a/examples/spawn-and-move/abis/base/contracts/actions.json b/examples/spawn-and-move/abis/base/contracts/actions.json index de4442aef8..f7c8509d5b 100644 --- a/examples/spawn-and-move/abis/base/contracts/actions.json +++ b/examples/spawn-and-move/abis/base/contracts/actions.json @@ -235,7 +235,7 @@ { "name": "player", "type": "core::starknet::contract_address::ContractAddress", - "kind": "data" + "kind": "key" }, { "name": "direction", diff --git a/examples/spawn-and-move/abis/deployments/KATANA/contracts/actions.json b/examples/spawn-and-move/abis/deployments/KATANA/contracts/actions.json index de4442aef8..f7c8509d5b 100644 --- a/examples/spawn-and-move/abis/deployments/KATANA/contracts/actions.json +++ b/examples/spawn-and-move/abis/deployments/KATANA/contracts/actions.json @@ -235,7 +235,7 @@ { "name": "player", "type": "core::starknet::contract_address::ContractAddress", - "kind": "data" + "kind": "key" }, { "name": "direction", diff --git a/examples/spawn-and-move/manifests/base/contracts/actions.toml b/examples/spawn-and-move/manifests/base/contracts/actions.toml index 41beef8c24..c5bed7ab76 100644 --- a/examples/spawn-and-move/manifests/base/contracts/actions.toml +++ b/examples/spawn-and-move/manifests/base/contracts/actions.toml @@ -1,5 +1,5 @@ kind = "DojoContract" -class_hash = "0xd43bce39922ec3857da231e3bb5c365c29f837c6dce322e4d61dfae83a4c18" +class_hash = "0x2a3b1c5473dfb9fd1be08b94fae201b30b4e63ed8caed996476cc4ad44cadb2" abi = "abis/base/contracts/actions.json" reads = [] writes = [] diff --git a/examples/spawn-and-move/manifests/base/models/moved.toml b/examples/spawn-and-move/manifests/base/models/moved.toml new file mode 100644 index 0000000000..71c08c95bb --- /dev/null +++ b/examples/spawn-and-move/manifests/base/models/moved.toml @@ -0,0 +1,13 @@ +kind = "DojoModel" +class_hash = "0x52659850f9939482810d9f6b468b91dc99e0b7fa42c2016cf12833ec06ce911" +name = "dojo_examples::actions::actions::moved" + +[[members]] +name = "player" +type = "ContractAddress" +key = true + +[[members]] +name = "direction" +type = "Direction" +key = false diff --git a/examples/spawn-and-move/manifests/deployments/KATANA.json b/examples/spawn-and-move/manifests/deployments/KATANA.json new file mode 100644 index 0000000000..15e380bf11 --- /dev/null +++ b/examples/spawn-and-move/manifests/deployments/KATANA.json @@ -0,0 +1 @@ +{"world":{"kind":"Contract","class_hash":"0x799bc4e9da10bfb3dd88e6f223c9cfbf7745435cd14f5d69675ea448e578cd","abi":null,"address":"0x1385f25d20a724edc9c7b3bd9636c59af64cbaf9fcd12f33b3af96b2452f295","transaction_hash":"0x6afefdcc49b3563a4f3657900ba71e9f9356861b15b942a73f2018f046a1048","block_number":3,"seed":"dojo_examples","name":"dojo::world::world"},"base":{"kind":"Class","class_hash":"0x679177a2cb757694ac4f326d01052ff0963eac0bc2a17116a2b87badcdf6f76","abi":null,"name":"dojo::base::base"},"contracts":[{"kind":"DojoContract","address":"0x3539c9b89b08095ba914653fb0f20e55d4b172a415beade611bc260b346d0f7","class_hash":"0x2a3b1c5473dfb9fd1be08b94fae201b30b4e63ed8caed996476cc4ad44cadb2","abi":"[\n {\n \"type\": \"impl\",\n \"name\": \"DojoResourceProviderImpl\",\n \"interface_name\": \"dojo::world::IDojoResourceProvider\"\n },\n {\n \"type\": \"interface\",\n \"name\": \"dojo::world::IDojoResourceProvider\",\n \"items\": [\n {\n \"type\": \"function\",\n \"name\": \"dojo_resource\",\n \"inputs\": [],\n \"outputs\": [\n {\n \"type\": \"core::felt252\"\n }\n ],\n \"state_mutability\": \"view\"\n }\n ]\n },\n {\n \"type\": \"impl\",\n \"name\": \"WorldProviderImpl\",\n \"interface_name\": \"dojo::world::IWorldProvider\"\n },\n {\n \"type\": \"struct\",\n \"name\": \"dojo::world::IWorldDispatcher\",\n \"members\": [\n {\n \"name\": \"contract_address\",\n \"type\": \"core::starknet::contract_address::ContractAddress\"\n }\n ]\n },\n {\n \"type\": \"interface\",\n \"name\": \"dojo::world::IWorldProvider\",\n \"items\": [\n {\n \"type\": \"function\",\n \"name\": \"world\",\n \"inputs\": [],\n \"outputs\": [\n {\n \"type\": \"dojo::world::IWorldDispatcher\"\n }\n ],\n \"state_mutability\": \"view\"\n }\n ]\n },\n {\n \"type\": \"impl\",\n \"name\": \"ActionsComputedImpl\",\n \"interface_name\": \"dojo_examples::actions::IActionsComputed\"\n },\n {\n \"type\": \"struct\",\n \"name\": \"dojo_examples::models::Vec2\",\n \"members\": [\n {\n \"name\": \"x\",\n \"type\": \"core::integer::u32\"\n },\n {\n \"name\": \"y\",\n \"type\": \"core::integer::u32\"\n }\n ]\n },\n {\n \"type\": \"struct\",\n \"name\": \"dojo_examples::models::Position\",\n \"members\": [\n {\n \"name\": \"player\",\n \"type\": \"core::starknet::contract_address::ContractAddress\"\n },\n {\n \"name\": \"vec\",\n \"type\": \"dojo_examples::models::Vec2\"\n }\n ]\n },\n {\n \"type\": \"interface\",\n \"name\": \"dojo_examples::actions::IActionsComputed\",\n \"items\": [\n {\n \"type\": \"function\",\n \"name\": \"tile_terrain\",\n \"inputs\": [\n {\n \"name\": \"vec\",\n \"type\": \"dojo_examples::models::Vec2\"\n }\n ],\n \"outputs\": [\n {\n \"type\": \"core::felt252\"\n }\n ],\n \"state_mutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"quadrant\",\n \"inputs\": [\n {\n \"name\": \"pos\",\n \"type\": \"dojo_examples::models::Position\"\n }\n ],\n \"outputs\": [\n {\n \"type\": \"core::integer::u8\"\n }\n ],\n \"state_mutability\": \"view\"\n }\n ]\n },\n {\n \"type\": \"impl\",\n \"name\": \"ActionsImpl\",\n \"interface_name\": \"dojo_examples::actions::IActions\"\n },\n {\n \"type\": \"enum\",\n \"name\": \"dojo_examples::models::Direction\",\n \"variants\": [\n {\n \"name\": \"None\",\n \"type\": \"()\"\n },\n {\n \"name\": \"Left\",\n \"type\": \"()\"\n },\n {\n \"name\": \"Right\",\n \"type\": \"()\"\n },\n {\n \"name\": \"Up\",\n \"type\": \"()\"\n },\n {\n \"name\": \"Down\",\n \"type\": \"()\"\n }\n ]\n },\n {\n \"type\": \"interface\",\n \"name\": \"dojo_examples::actions::IActions\",\n \"items\": [\n {\n \"type\": \"function\",\n \"name\": \"spawn\",\n \"inputs\": [],\n \"outputs\": [],\n \"state_mutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"move\",\n \"inputs\": [\n {\n \"name\": \"direction\",\n \"type\": \"dojo_examples::models::Direction\"\n }\n ],\n \"outputs\": [],\n \"state_mutability\": \"view\"\n }\n ]\n },\n {\n \"type\": \"impl\",\n \"name\": \"UpgradableImpl\",\n \"interface_name\": \"dojo::components::upgradeable::IUpgradeable\"\n },\n {\n \"type\": \"interface\",\n \"name\": \"dojo::components::upgradeable::IUpgradeable\",\n \"items\": [\n {\n \"type\": \"function\",\n \"name\": \"upgrade\",\n \"inputs\": [\n {\n \"name\": \"new_class_hash\",\n \"type\": \"core::starknet::class_hash::ClassHash\"\n }\n ],\n \"outputs\": [],\n \"state_mutability\": \"external\"\n }\n ]\n },\n {\n \"type\": \"event\",\n \"name\": \"dojo::components::upgradeable::upgradeable::Upgraded\",\n \"kind\": \"struct\",\n \"members\": [\n {\n \"name\": \"class_hash\",\n \"type\": \"core::starknet::class_hash::ClassHash\",\n \"kind\": \"data\"\n }\n ]\n },\n {\n \"type\": \"event\",\n \"name\": \"dojo::components::upgradeable::upgradeable::Event\",\n \"kind\": \"enum\",\n \"variants\": [\n {\n \"name\": \"Upgraded\",\n \"type\": \"dojo::components::upgradeable::upgradeable::Upgraded\",\n \"kind\": \"nested\"\n }\n ]\n },\n {\n \"type\": \"event\",\n \"name\": \"dojo_examples::actions::actions::Moved\",\n \"kind\": \"struct\",\n \"members\": [\n {\n \"name\": \"player\",\n \"type\": \"core::starknet::contract_address::ContractAddress\",\n \"kind\": \"key\"\n },\n {\n \"name\": \"direction\",\n \"type\": \"dojo_examples::models::Direction\",\n \"kind\": \"data\"\n }\n ]\n },\n {\n \"type\": \"event\",\n \"name\": \"dojo_examples::actions::actions::Event\",\n \"kind\": \"enum\",\n \"variants\": [\n {\n \"name\": \"UpgradeableEvent\",\n \"type\": \"dojo::components::upgradeable::upgradeable::Event\",\n \"kind\": \"nested\"\n },\n {\n \"name\": \"Moved\",\n \"type\": \"dojo_examples::actions::actions::Moved\",\n \"kind\": \"nested\"\n }\n ]\n }\n]","reads":["Moves","Position"],"writes":[],"computed":[],"name":"dojo_examples::actions::actions"}],"models":[{"kind":"DojoModel","members":[{"name":"player","type":"ContractAddress","key":true},{"name":"direction","type":"Direction","key":false}],"class_hash":"0x52659850f9939482810d9f6b468b91dc99e0b7fa42c2016cf12833ec06ce911","abi":null,"name":"dojo_examples::actions::actions::moved"},{"kind":"DojoModel","members":[{"name":"player","type":"ContractAddress","key":true},{"name":"remaining","type":"u8","key":false},{"name":"last_direction","type":"Direction","key":false}],"class_hash":"0x511fbd833938f5c4b743eea1e67605a125d7ff60e8a09e8dc227ad2fb59ca54","abi":null,"name":"dojo_examples::models::moves"},{"kind":"DojoModel","members":[{"name":"player","type":"ContractAddress","key":true},{"name":"vec","type":"Vec2","key":false}],"class_hash":"0xb33ae053213ccb2a57967ffc4411901f3efab24781ca867adcd0b90f2fece5","abi":null,"name":"dojo_examples::models::position"}]} \ No newline at end of file diff --git a/examples/spawn-and-move/manifests/deployments/KATANA.toml b/examples/spawn-and-move/manifests/deployments/KATANA.toml index 9a186f0e41..72bc65458c 100644 --- a/examples/spawn-and-move/manifests/deployments/KATANA.toml +++ b/examples/spawn-and-move/manifests/deployments/KATANA.toml @@ -15,13 +15,31 @@ name = "dojo::base::base" [[contracts]] kind = "DojoContract" address = "0x3539c9b89b08095ba914653fb0f20e55d4b172a415beade611bc260b346d0f7" -class_hash = "0xd43bce39922ec3857da231e3bb5c365c29f837c6dce322e4d61dfae83a4c18" +class_hash = "0x2a3b1c5473dfb9fd1be08b94fae201b30b4e63ed8caed996476cc4ad44cadb2" abi = "abis/deployments/KATANA/contracts/actions.json" -reads = [] +reads = [ + "Moves", + "Position", +] writes = [] computed = [] name = "dojo_examples::actions::actions" +[[models]] +kind = "DojoModel" +class_hash = "0x52659850f9939482810d9f6b468b91dc99e0b7fa42c2016cf12833ec06ce911" +name = "dojo_examples::actions::actions::moved" + +[[models.members]] +name = "player" +type = "ContractAddress" +key = true + +[[models.members]] +name = "direction" +type = "Direction" +key = false + [[models]] kind = "DojoModel" class_hash = "0x511fbd833938f5c4b743eea1e67605a125d7ff60e8a09e8dc227ad2fb59ca54" From 5843ed8a39c76ce06c1f19aa21264d3fbe18198f Mon Sep 17 00:00:00 2001 From: glihm Date: Sat, 23 Mar 2024 23:48:52 -0600 Subject: [PATCH 3/9] editor: add custom build commands --- .vscode/tasks.json | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000000..aa9f3b99c1 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,29 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "cargo", + "command": "build", + "problemMatcher": [ + "$rustc" + ], + "group": "build", + "label": "rust: cargo build" + }, + { + "type": "cargo", + "command": "build", + "problemMatcher": [ + "$rustc" + ], + "group": "build", + "label": "sozo release", + "args": [ + "-r", + "-p", + "sozo" + ] + } + ] +} + From 64925504f268526c6036ef6fc0d70fddfdd811d8 Mon Sep 17 00:00:00 2001 From: glihm Date: Sat, 23 Mar 2024 23:54:33 -0600 Subject: [PATCH 4/9] fix: remove print and fmt + clippy --- crates/dojo-world/src/manifest.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/crates/dojo-world/src/manifest.rs b/crates/dojo-world/src/manifest.rs index 4b468bc874..4bb325a7e8 100644 --- a/crates/dojo-world/src/manifest.rs +++ b/crates/dojo-world/src/manifest.rs @@ -335,16 +335,9 @@ impl DeploymentManifest { // Embedding ABIs into the manifest. let mut manifest_with_abis = self.clone(); for contract in &mut manifest_with_abis.contracts { - if let Some(abi_path) = &contract.inner.abi { - match abi_path { - AbiFormat::Path(p) => { - println!("PATH {}", p.to_string()); - let abi_content = fs::read_to_string(manifest_dir.join(p))?; - contract.inner.abi = Some(AbiFormat::Embed(abi_content)); - } - // If the ABI is already embedded, do nothing. - _ => {} - } + if let Some(AbiFormat::Path(abi_path)) = &contract.inner.abi { + let abi_content = fs::read_to_string(manifest_dir.join(abi_path))?; + contract.inner.abi = Some(AbiFormat::Embed(abi_content)); } } From 8b93846a34b315e2abbbb669275fc9b3c05cdf67 Mon Sep 17 00:00:00 2001 From: glihm Date: Sun, 24 Mar 2024 00:02:08 -0600 Subject: [PATCH 5/9] add vscode settings to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 144f0af73c..419afd456a 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ output.txt **/katana-logs crates/benches/bench_results.txt **/generated +.vscode/settings.json From 4673a433f03527fe48da5408881756912506f6cd Mon Sep 17 00:00:00 2001 From: glihm Date: Sun, 24 Mar 2024 15:58:37 -0600 Subject: [PATCH 6/9] fix: ensure pretty formatting of the json --- crates/dojo-world/src/manifest.rs | 32 +- .../manifests/deployments/KATANA.json | 358 +++++++++++++++++- 2 files changed, 382 insertions(+), 8 deletions(-) diff --git a/crates/dojo-world/src/manifest.rs b/crates/dojo-world/src/manifest.rs index 4bb325a7e8..9cf3317cbe 100644 --- a/crates/dojo-world/src/manifest.rs +++ b/crates/dojo-world/src/manifest.rs @@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize}; use serde_with::serde_as; use smol_str::SmolStr; use starknet::core::serde::unsigned_field_element::UfeHex; +use starknet::core::types::contract::AbiEntry; use starknet::core::types::{ BlockId, BlockTag, EmittedEvent, EventFilter, FieldElement, FunctionCall, StarknetError, }; @@ -110,15 +111,31 @@ pub struct ComputedValueEntrypoint { pub model: Option, } -/// Format of the ABI into the manifest file. +/// Format of the ABI into the manifest. #[serde_as] -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize)] #[serde(untagged)] pub enum AbiFormat { /// Only a relative path to the ABI file is stored. Path(Utf8PathBuf), - /// The full ABI is embedded as a string. - Embed(String), + /// The full ABI is embedded. + Embed(Vec), +} + +impl PartialEq for AbiFormat { + fn eq(&self, other: &Self) -> bool { + match (self, other) { + (AbiFormat::Path(p1), AbiFormat::Path(p2)) => p1 == p2, + (AbiFormat::Embed(e1), AbiFormat::Embed(e2)) => { + // Currently, [`AbiEntry`] does not implement [`PartialEq`] so we cannot compare + // them directly. + let e1_json = serde_json::to_string(e1).expect("valid JSON from ABI"); + let e2_json = serde_json::to_string(e2).expect("valid JSON from ABI"); + e1_json == e2_json + } + _ => false, + } + } } impl AbiFormat { @@ -336,12 +353,13 @@ impl DeploymentManifest { let mut manifest_with_abis = self.clone(); for contract in &mut manifest_with_abis.contracts { if let Some(AbiFormat::Path(abi_path)) = &contract.inner.abi { - let abi_content = fs::read_to_string(manifest_dir.join(abi_path))?; - contract.inner.abi = Some(AbiFormat::Embed(abi_content)); + let mut abi_file = std::fs::File::open(manifest_dir.join(abi_path))?; + let abi_entries: Vec = serde_json::from_reader(&mut abi_file)?; + contract.inner.abi = Some(AbiFormat::Embed(abi_entries)); } } - let deployed_manifest = serde_json::to_string(&manifest_with_abis)?; + let deployed_manifest = serde_json::to_string_pretty(&manifest_with_abis)?; fs::write(path, deployed_manifest)?; Ok(()) diff --git a/examples/spawn-and-move/manifests/deployments/KATANA.json b/examples/spawn-and-move/manifests/deployments/KATANA.json index 15e380bf11..844426adde 100644 --- a/examples/spawn-and-move/manifests/deployments/KATANA.json +++ b/examples/spawn-and-move/manifests/deployments/KATANA.json @@ -1 +1,357 @@ -{"world":{"kind":"Contract","class_hash":"0x799bc4e9da10bfb3dd88e6f223c9cfbf7745435cd14f5d69675ea448e578cd","abi":null,"address":"0x1385f25d20a724edc9c7b3bd9636c59af64cbaf9fcd12f33b3af96b2452f295","transaction_hash":"0x6afefdcc49b3563a4f3657900ba71e9f9356861b15b942a73f2018f046a1048","block_number":3,"seed":"dojo_examples","name":"dojo::world::world"},"base":{"kind":"Class","class_hash":"0x679177a2cb757694ac4f326d01052ff0963eac0bc2a17116a2b87badcdf6f76","abi":null,"name":"dojo::base::base"},"contracts":[{"kind":"DojoContract","address":"0x3539c9b89b08095ba914653fb0f20e55d4b172a415beade611bc260b346d0f7","class_hash":"0x2a3b1c5473dfb9fd1be08b94fae201b30b4e63ed8caed996476cc4ad44cadb2","abi":"[\n {\n \"type\": \"impl\",\n \"name\": \"DojoResourceProviderImpl\",\n \"interface_name\": \"dojo::world::IDojoResourceProvider\"\n },\n {\n \"type\": \"interface\",\n \"name\": \"dojo::world::IDojoResourceProvider\",\n \"items\": [\n {\n \"type\": \"function\",\n \"name\": \"dojo_resource\",\n \"inputs\": [],\n \"outputs\": [\n {\n \"type\": \"core::felt252\"\n }\n ],\n \"state_mutability\": \"view\"\n }\n ]\n },\n {\n \"type\": \"impl\",\n \"name\": \"WorldProviderImpl\",\n \"interface_name\": \"dojo::world::IWorldProvider\"\n },\n {\n \"type\": \"struct\",\n \"name\": \"dojo::world::IWorldDispatcher\",\n \"members\": [\n {\n \"name\": \"contract_address\",\n \"type\": \"core::starknet::contract_address::ContractAddress\"\n }\n ]\n },\n {\n \"type\": \"interface\",\n \"name\": \"dojo::world::IWorldProvider\",\n \"items\": [\n {\n \"type\": \"function\",\n \"name\": \"world\",\n \"inputs\": [],\n \"outputs\": [\n {\n \"type\": \"dojo::world::IWorldDispatcher\"\n }\n ],\n \"state_mutability\": \"view\"\n }\n ]\n },\n {\n \"type\": \"impl\",\n \"name\": \"ActionsComputedImpl\",\n \"interface_name\": \"dojo_examples::actions::IActionsComputed\"\n },\n {\n \"type\": \"struct\",\n \"name\": \"dojo_examples::models::Vec2\",\n \"members\": [\n {\n \"name\": \"x\",\n \"type\": \"core::integer::u32\"\n },\n {\n \"name\": \"y\",\n \"type\": \"core::integer::u32\"\n }\n ]\n },\n {\n \"type\": \"struct\",\n \"name\": \"dojo_examples::models::Position\",\n \"members\": [\n {\n \"name\": \"player\",\n \"type\": \"core::starknet::contract_address::ContractAddress\"\n },\n {\n \"name\": \"vec\",\n \"type\": \"dojo_examples::models::Vec2\"\n }\n ]\n },\n {\n \"type\": \"interface\",\n \"name\": \"dojo_examples::actions::IActionsComputed\",\n \"items\": [\n {\n \"type\": \"function\",\n \"name\": \"tile_terrain\",\n \"inputs\": [\n {\n \"name\": \"vec\",\n \"type\": \"dojo_examples::models::Vec2\"\n }\n ],\n \"outputs\": [\n {\n \"type\": \"core::felt252\"\n }\n ],\n \"state_mutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"quadrant\",\n \"inputs\": [\n {\n \"name\": \"pos\",\n \"type\": \"dojo_examples::models::Position\"\n }\n ],\n \"outputs\": [\n {\n \"type\": \"core::integer::u8\"\n }\n ],\n \"state_mutability\": \"view\"\n }\n ]\n },\n {\n \"type\": \"impl\",\n \"name\": \"ActionsImpl\",\n \"interface_name\": \"dojo_examples::actions::IActions\"\n },\n {\n \"type\": \"enum\",\n \"name\": \"dojo_examples::models::Direction\",\n \"variants\": [\n {\n \"name\": \"None\",\n \"type\": \"()\"\n },\n {\n \"name\": \"Left\",\n \"type\": \"()\"\n },\n {\n \"name\": \"Right\",\n \"type\": \"()\"\n },\n {\n \"name\": \"Up\",\n \"type\": \"()\"\n },\n {\n \"name\": \"Down\",\n \"type\": \"()\"\n }\n ]\n },\n {\n \"type\": \"interface\",\n \"name\": \"dojo_examples::actions::IActions\",\n \"items\": [\n {\n \"type\": \"function\",\n \"name\": \"spawn\",\n \"inputs\": [],\n \"outputs\": [],\n \"state_mutability\": \"view\"\n },\n {\n \"type\": \"function\",\n \"name\": \"move\",\n \"inputs\": [\n {\n \"name\": \"direction\",\n \"type\": \"dojo_examples::models::Direction\"\n }\n ],\n \"outputs\": [],\n \"state_mutability\": \"view\"\n }\n ]\n },\n {\n \"type\": \"impl\",\n \"name\": \"UpgradableImpl\",\n \"interface_name\": \"dojo::components::upgradeable::IUpgradeable\"\n },\n {\n \"type\": \"interface\",\n \"name\": \"dojo::components::upgradeable::IUpgradeable\",\n \"items\": [\n {\n \"type\": \"function\",\n \"name\": \"upgrade\",\n \"inputs\": [\n {\n \"name\": \"new_class_hash\",\n \"type\": \"core::starknet::class_hash::ClassHash\"\n }\n ],\n \"outputs\": [],\n \"state_mutability\": \"external\"\n }\n ]\n },\n {\n \"type\": \"event\",\n \"name\": \"dojo::components::upgradeable::upgradeable::Upgraded\",\n \"kind\": \"struct\",\n \"members\": [\n {\n \"name\": \"class_hash\",\n \"type\": \"core::starknet::class_hash::ClassHash\",\n \"kind\": \"data\"\n }\n ]\n },\n {\n \"type\": \"event\",\n \"name\": \"dojo::components::upgradeable::upgradeable::Event\",\n \"kind\": \"enum\",\n \"variants\": [\n {\n \"name\": \"Upgraded\",\n \"type\": \"dojo::components::upgradeable::upgradeable::Upgraded\",\n \"kind\": \"nested\"\n }\n ]\n },\n {\n \"type\": \"event\",\n \"name\": \"dojo_examples::actions::actions::Moved\",\n \"kind\": \"struct\",\n \"members\": [\n {\n \"name\": \"player\",\n \"type\": \"core::starknet::contract_address::ContractAddress\",\n \"kind\": \"key\"\n },\n {\n \"name\": \"direction\",\n \"type\": \"dojo_examples::models::Direction\",\n \"kind\": \"data\"\n }\n ]\n },\n {\n \"type\": \"event\",\n \"name\": \"dojo_examples::actions::actions::Event\",\n \"kind\": \"enum\",\n \"variants\": [\n {\n \"name\": \"UpgradeableEvent\",\n \"type\": \"dojo::components::upgradeable::upgradeable::Event\",\n \"kind\": \"nested\"\n },\n {\n \"name\": \"Moved\",\n \"type\": \"dojo_examples::actions::actions::Moved\",\n \"kind\": \"nested\"\n }\n ]\n }\n]","reads":["Moves","Position"],"writes":[],"computed":[],"name":"dojo_examples::actions::actions"}],"models":[{"kind":"DojoModel","members":[{"name":"player","type":"ContractAddress","key":true},{"name":"direction","type":"Direction","key":false}],"class_hash":"0x52659850f9939482810d9f6b468b91dc99e0b7fa42c2016cf12833ec06ce911","abi":null,"name":"dojo_examples::actions::actions::moved"},{"kind":"DojoModel","members":[{"name":"player","type":"ContractAddress","key":true},{"name":"remaining","type":"u8","key":false},{"name":"last_direction","type":"Direction","key":false}],"class_hash":"0x511fbd833938f5c4b743eea1e67605a125d7ff60e8a09e8dc227ad2fb59ca54","abi":null,"name":"dojo_examples::models::moves"},{"kind":"DojoModel","members":[{"name":"player","type":"ContractAddress","key":true},{"name":"vec","type":"Vec2","key":false}],"class_hash":"0xb33ae053213ccb2a57967ffc4411901f3efab24781ca867adcd0b90f2fece5","abi":null,"name":"dojo_examples::models::position"}]} \ No newline at end of file +{ + "world": { + "kind": "Contract", + "class_hash": "0x799bc4e9da10bfb3dd88e6f223c9cfbf7745435cd14f5d69675ea448e578cd", + "abi": null, + "address": "0x1385f25d20a724edc9c7b3bd9636c59af64cbaf9fcd12f33b3af96b2452f295", + "transaction_hash": "0x6afefdcc49b3563a4f3657900ba71e9f9356861b15b942a73f2018f046a1048", + "block_number": 3, + "seed": "dojo_examples", + "name": "dojo::world::world" + }, + "base": { + "kind": "Class", + "class_hash": "0x679177a2cb757694ac4f326d01052ff0963eac0bc2a17116a2b87badcdf6f76", + "abi": null, + "name": "dojo::base::base" + }, + "contracts": [ + { + "kind": "DojoContract", + "address": "0x3539c9b89b08095ba914653fb0f20e55d4b172a415beade611bc260b346d0f7", + "class_hash": "0x2a3b1c5473dfb9fd1be08b94fae201b30b4e63ed8caed996476cc4ad44cadb2", + "abi": [ + { + "type": "impl", + "name": "DojoResourceProviderImpl", + "interface_name": "dojo::world::IDojoResourceProvider" + }, + { + "type": "interface", + "name": "dojo::world::IDojoResourceProvider", + "items": [ + { + "type": "function", + "name": "dojo_resource", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "WorldProviderImpl", + "interface_name": "dojo::world::IWorldProvider" + }, + { + "type": "struct", + "name": "dojo::world::IWorldDispatcher", + "members": [ + { + "name": "contract_address", + "type": "core::starknet::contract_address::ContractAddress" + } + ] + }, + { + "type": "interface", + "name": "dojo::world::IWorldProvider", + "items": [ + { + "type": "function", + "name": "world", + "inputs": [], + "outputs": [ + { + "type": "dojo::world::IWorldDispatcher" + } + ], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "ActionsComputedImpl", + "interface_name": "dojo_examples::actions::IActionsComputed" + }, + { + "type": "struct", + "name": "dojo_examples::models::Vec2", + "members": [ + { + "name": "x", + "type": "core::integer::u32" + }, + { + "name": "y", + "type": "core::integer::u32" + } + ] + }, + { + "type": "struct", + "name": "dojo_examples::models::Position", + "members": [ + { + "name": "player", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "vec", + "type": "dojo_examples::models::Vec2" + } + ] + }, + { + "type": "interface", + "name": "dojo_examples::actions::IActionsComputed", + "items": [ + { + "type": "function", + "name": "tile_terrain", + "inputs": [ + { + "name": "vec", + "type": "dojo_examples::models::Vec2" + } + ], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "quadrant", + "inputs": [ + { + "name": "pos", + "type": "dojo_examples::models::Position" + } + ], + "outputs": [ + { + "type": "core::integer::u8" + } + ], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "ActionsImpl", + "interface_name": "dojo_examples::actions::IActions" + }, + { + "type": "enum", + "name": "dojo_examples::models::Direction", + "variants": [ + { + "name": "None", + "type": "()" + }, + { + "name": "Left", + "type": "()" + }, + { + "name": "Right", + "type": "()" + }, + { + "name": "Up", + "type": "()" + }, + { + "name": "Down", + "type": "()" + } + ] + }, + { + "type": "interface", + "name": "dojo_examples::actions::IActions", + "items": [ + { + "type": "function", + "name": "spawn", + "inputs": [], + "outputs": [], + "state_mutability": "view" + }, + { + "type": "function", + "name": "move", + "inputs": [ + { + "name": "direction", + "type": "dojo_examples::models::Direction" + } + ], + "outputs": [], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "UpgradableImpl", + "interface_name": "dojo::components::upgradeable::IUpgradeable" + }, + { + "type": "interface", + "name": "dojo::components::upgradeable::IUpgradeable", + "items": [ + { + "type": "function", + "name": "upgrade", + "inputs": [ + { + "name": "new_class_hash", + "type": "core::starknet::class_hash::ClassHash" + } + ], + "outputs": [], + "state_mutability": "external" + } + ] + }, + { + "type": "event", + "name": "dojo::components::upgradeable::upgradeable::Upgraded", + "kind": "struct", + "members": [ + { + "name": "class_hash", + "type": "core::starknet::class_hash::ClassHash", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "dojo::components::upgradeable::upgradeable::Event", + "kind": "enum", + "variants": [ + { + "name": "Upgraded", + "type": "dojo::components::upgradeable::upgradeable::Upgraded", + "kind": "nested" + } + ] + }, + { + "type": "event", + "name": "dojo_examples::actions::actions::Moved", + "kind": "struct", + "members": [ + { + "name": "player", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "key" + }, + { + "name": "direction", + "type": "dojo_examples::models::Direction", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "dojo_examples::actions::actions::Event", + "kind": "enum", + "variants": [ + { + "name": "UpgradeableEvent", + "type": "dojo::components::upgradeable::upgradeable::Event", + "kind": "nested" + }, + { + "name": "Moved", + "type": "dojo_examples::actions::actions::Moved", + "kind": "nested" + } + ] + } + ], + "reads": [ + "Moves", + "Position" + ], + "writes": [], + "computed": [], + "name": "dojo_examples::actions::actions" + } + ], + "models": [ + { + "kind": "DojoModel", + "members": [ + { + "name": "player", + "type": "ContractAddress", + "key": true + }, + { + "name": "direction", + "type": "Direction", + "key": false + } + ], + "class_hash": "0x52659850f9939482810d9f6b468b91dc99e0b7fa42c2016cf12833ec06ce911", + "abi": null, + "name": "dojo_examples::actions::actions::moved" + }, + { + "kind": "DojoModel", + "members": [ + { + "name": "player", + "type": "ContractAddress", + "key": true + }, + { + "name": "remaining", + "type": "u8", + "key": false + }, + { + "name": "last_direction", + "type": "Direction", + "key": false + } + ], + "class_hash": "0x511fbd833938f5c4b743eea1e67605a125d7ff60e8a09e8dc227ad2fb59ca54", + "abi": null, + "name": "dojo_examples::models::moves" + }, + { + "kind": "DojoModel", + "members": [ + { + "name": "player", + "type": "ContractAddress", + "key": true + }, + { + "name": "vec", + "type": "Vec2", + "key": false + } + ], + "class_hash": "0xb33ae053213ccb2a57967ffc4411901f3efab24781ca867adcd0b90f2fece5", + "abi": null, + "name": "dojo_examples::models::position" + } + ] +} \ No newline at end of file From 5882f6774add6b3ee2a63e83d3dd372e7f9376ab Mon Sep 17 00:00:00 2001 From: glihm Date: Sun, 24 Mar 2024 16:01:23 -0600 Subject: [PATCH 7/9] chore: add all .vscode to gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 419afd456a..c6be219244 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,4 @@ output.txt **/katana-logs crates/benches/bench_results.txt **/generated -.vscode/settings.json +.vscode From 6a4494e63ad201dbed0fa669d0b8e429489a26a7 Mon Sep 17 00:00:00 2001 From: glihm Date: Sun, 24 Mar 2024 16:01:46 -0600 Subject: [PATCH 8/9] chore: remove vscode tasks --- .vscode/tasks.json | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 .vscode/tasks.json diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index aa9f3b99c1..0000000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "type": "cargo", - "command": "build", - "problemMatcher": [ - "$rustc" - ], - "group": "build", - "label": "rust: cargo build" - }, - { - "type": "cargo", - "command": "build", - "problemMatcher": [ - "$rustc" - ], - "group": "build", - "label": "sozo release", - "args": [ - "-r", - "-p", - "sozo" - ] - } - ] -} - From 9b33574f314958ea2b9e92a64d38376ed8813421 Mon Sep 17 00:00:00 2001 From: glihm Date: Mon, 25 Mar 2024 13:14:08 -0600 Subject: [PATCH 9/9] fix: enable PartialEq only for testing when required --- crates/dojo-world/src/manifest.rs | 38 ++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/crates/dojo-world/src/manifest.rs b/crates/dojo-world/src/manifest.rs index 9cf3317cbe..b2a3916d5f 100644 --- a/crates/dojo-world/src/manifest.rs +++ b/crates/dojo-world/src/manifest.rs @@ -76,7 +76,8 @@ impl From for Member { /// Represents a declaration of a model. #[serde_as] -#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Default, Debug, Serialize, Deserialize)] +#[cfg_attr(test, derive(PartialEq))] #[serde(tag = "kind")] pub struct DojoModel { pub members: Vec, @@ -122,6 +123,7 @@ pub enum AbiFormat { Embed(Vec), } +#[cfg(test)] impl PartialEq for AbiFormat { fn eq(&self, other: &Self) -> bool { match (self, other) { @@ -148,7 +150,8 @@ impl AbiFormat { } #[serde_as] -#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Default, Debug, Serialize, Deserialize)] +#[cfg_attr(test, derive(PartialEq))] #[serde(tag = "kind")] pub struct DojoContract { #[serde_as(as = "Option")] @@ -162,8 +165,8 @@ pub struct DojoContract { } #[serde_as] -#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq)] - +#[derive(Clone, Default, Debug, Serialize, Deserialize)] +#[cfg_attr(test, derive(PartialEq))] pub struct OverlayDojoContract { pub name: SmolStr, pub reads: Option>, @@ -171,19 +174,23 @@ pub struct OverlayDojoContract { } #[serde_as] -#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Default, Debug, Serialize, Deserialize)] +#[cfg_attr(test, derive(PartialEq))] pub struct OverlayDojoModel {} #[serde_as] -#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Default, Debug, Serialize, Deserialize)] +#[cfg_attr(test, derive(PartialEq))] pub struct OverlayContract {} #[serde_as] -#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Default, Debug, Serialize, Deserialize)] +#[cfg_attr(test, derive(PartialEq))] pub struct OverlayClass {} #[serde_as] -#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Default, Debug, Serialize, Deserialize)] +#[cfg_attr(test, derive(PartialEq))] #[serde(tag = "kind")] pub struct Class { #[serde_as(as = "UfeHex")] @@ -192,7 +199,8 @@ pub struct Class { } #[serde_as] -#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Default, Debug, Serialize, Deserialize)] +#[cfg_attr(test, derive(PartialEq))] #[serde(tag = "kind")] pub struct Contract { #[serde_as(as = "UfeHex")] @@ -207,7 +215,8 @@ pub struct Contract { pub seed: Option, } -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(test, derive(PartialEq))] pub struct BaseManifest { pub world: Manifest, pub base: Manifest, @@ -239,7 +248,8 @@ impl From for DeploymentManifest { } } -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(test, derive(PartialEq))] pub struct DeploymentManifest { pub world: Manifest, pub base: Manifest, @@ -247,12 +257,14 @@ pub struct DeploymentManifest { pub models: Vec>, } -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize)] +#[cfg_attr(test, derive(PartialEq))] pub struct OverlayManifest { pub contracts: Vec, } -#[derive(Clone, Serialize, Deserialize, PartialEq, Debug)] +#[derive(Clone, Serialize, Deserialize, Debug)] +#[cfg_attr(test, derive(PartialEq))] pub struct Manifest where T: ManifestMethods,