From 45fb6af63072d883adfdd10b2e4374635867f5fb Mon Sep 17 00:00:00 2001 From: Junichi Sugiura Date: Thu, 26 Oct 2023 20:23:14 +0300 Subject: [PATCH] Make socials hash map optional so that parsing WorldMetadata won't fail (#1108) --- crates/dojo-world/src/metadata.rs | 2 +- crates/dojo-world/src/metadata_test.rs | 32 +++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/crates/dojo-world/src/metadata.rs b/crates/dojo-world/src/metadata.rs index 8268eebecb..75559768ce 100644 --- a/crates/dojo-world/src/metadata.rs +++ b/crates/dojo-world/src/metadata.rs @@ -74,7 +74,7 @@ pub struct WorldMetadata { pub cover_uri: Option, pub icon_uri: Option, pub website: Option, - pub socials: HashMap, + pub socials: Option>, } #[derive(Default, Deserialize, Clone, Debug)] diff --git a/crates/dojo-world/src/metadata_test.rs b/crates/dojo-world/src/metadata_test.rs index 3e95fc3ee9..a6c950fa6c 100644 --- a/crates/dojo-world/src/metadata_test.rs +++ b/crates/dojo-world/src/metadata_test.rs @@ -23,7 +23,7 @@ description = "example world" cover_uri = "file://example_cover.png" icon_uri = "file://example_icon.png" website = "https://dojoengine.org" -socials.twitter = "https://x.com/dojostarknet" +socials.x = "https://x.com/dojostarknet" "#, ) .unwrap(); @@ -55,7 +55,7 @@ socials.twitter = "https://x.com/dojostarknet" assert_eq!(world.cover_uri, Some(Uri::File("example_cover.png".into()))); assert_eq!(world.icon_uri, Some(Uri::File("example_icon.png".into()))); assert_eq!(world.website, Some(Url::parse("https://dojoengine.org").unwrap())); - assert_eq!(world.socials.get("twitter"), Some(&"https://x.com/dojostarknet".to_string())); + assert_eq!(world.socials.unwrap().get("x"), Some(&"https://x.com/dojostarknet".to_string())); } #[tokio::test] @@ -66,8 +66,34 @@ async fn world_metadata_hash_and_upload() { cover_uri: Some(Uri::File("src/metadata_test_data/cover.png".into())), icon_uri: None, website: Some(Url::parse("https://dojoengine.org").unwrap()), - socials: HashMap::from([("twitter".to_string(), "https://x.com/dojostarknet".to_string())]), + socials: Some(HashMap::from([("x".to_string(), "https://x.com/dojostarknet".to_string())])), }; let _ = meta.upload().await.unwrap(); } + +#[tokio::test] +async fn parse_world_metadata_without_socials() { + let metadata: Metadata = toml::from_str( + r#" +[env] +rpc_url = "http://localhost:5050/" +account_address = "0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973" +private_key = "0x1800000000300000180000000000030000000000003006001800006600" +keystore_path = "test/" +keystore_password = "dojo" +world_address = "0x0248cacaeac64c45be0c19ee8727e0bb86623ca7fa3f0d431a6c55e200697e5a" + +[world] +name = "example" +description = "example world" +cover_uri = "file://example_cover.png" +icon_uri = "file://example_icon.png" +website = "https://dojoengine.org" +# socials.x = "https://x.com/dojostarknet" + "#, + ) + .unwrap(); + + assert!(metadata.world.is_some()); +}