diff --git a/forc-pkg/src/manifest.rs b/forc-pkg/src/manifest.rs index 27001904cb2..1ee8bb95b46 100644 --- a/forc-pkg/src/manifest.rs +++ b/forc-pkg/src/manifest.rs @@ -238,7 +238,9 @@ impl PackageManifestFile { pub fn from_file(path: PathBuf) -> Result { let path = path.canonicalize()?; let manifest = PackageManifest::from_file(&path)?; - Ok(Self { manifest, path }) + let manifest_file = Self { manifest, path }; + manifest_file.validate()?; + Ok(manifest_file) } /// Read the manifest from the `Forc.toml` in the directory specified by the given `path` or @@ -253,13 +255,14 @@ impl PackageManifestFile { Self::from_file(path) } - /// Validate the `PackageManifest`. + /// Validate the `PackageManifestFile`. /// - /// This checks the project and organization names against a set of reserved/restricted - /// keywords and patterns, and if a given entry point exists. - pub fn validate(&self, path: &Path) -> Result<()> { + /// This checks: + /// 1. Validity of the underlying `PackageManifest`. + /// 2. Existence of the entry file. + pub fn validate(&self) -> Result<()> { self.manifest.validate()?; - let mut entry_path = path.to_path_buf(); + let mut entry_path = self.path.clone(); entry_path.pop(); let entry_path = entry_path .join(constants::SRC_DIR) diff --git a/forc-plugins/forc-client/src/op/deploy.rs b/forc-plugins/forc-client/src/op/deploy.rs index 7a0110e6114..c98d1c168b2 100644 --- a/forc-plugins/forc-client/src/op/deploy.rs +++ b/forc-plugins/forc-client/src/op/deploy.rs @@ -267,8 +267,8 @@ mod test { let manifests_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")) .join("test") - .join("data") - .join("manifests"); + .join("data"); + for entry in manifests_dir.read_dir().unwrap() { let manifest = PackageManifestFile::from_file(entry.unwrap().path().join("Forc.toml")).unwrap(); diff --git a/forc-plugins/forc-client/test/data/contract_with_dep/.gitignore b/forc-plugins/forc-client/test/data/contract_with_dep/.gitignore new file mode 100644 index 00000000000..77d3844f58c --- /dev/null +++ b/forc-plugins/forc-client/test/data/contract_with_dep/.gitignore @@ -0,0 +1,2 @@ +out +target diff --git a/forc-plugins/forc-client/test/data/manifests/contract_with_dep/Forc.toml b/forc-plugins/forc-client/test/data/contract_with_dep/Forc.toml similarity index 100% rename from forc-plugins/forc-client/test/data/manifests/contract_with_dep/Forc.toml rename to forc-plugins/forc-client/test/data/contract_with_dep/Forc.toml diff --git a/forc-plugins/forc-client/test/data/contract_with_dep/src/main.sw b/forc-plugins/forc-client/test/data/contract_with_dep/src/main.sw new file mode 100644 index 00000000000..7d4a75493c6 --- /dev/null +++ b/forc-plugins/forc-client/test/data/contract_with_dep/src/main.sw @@ -0,0 +1,11 @@ +contract; + +abi MyContract { + fn test_function() -> bool; +} + +impl MyContract for Contract { + fn test_function() -> bool { + true + } +} diff --git a/forc-plugins/forc-client/test/data/contract_with_dep_with_salt_conflict/.gitignore b/forc-plugins/forc-client/test/data/contract_with_dep_with_salt_conflict/.gitignore new file mode 100644 index 00000000000..77d3844f58c --- /dev/null +++ b/forc-plugins/forc-client/test/data/contract_with_dep_with_salt_conflict/.gitignore @@ -0,0 +1,2 @@ +out +target diff --git a/forc-plugins/forc-client/test/data/manifests/contract_with_dep_with_salt_conflict/Forc.toml b/forc-plugins/forc-client/test/data/contract_with_dep_with_salt_conflict/Forc.toml similarity index 100% rename from forc-plugins/forc-client/test/data/manifests/contract_with_dep_with_salt_conflict/Forc.toml rename to forc-plugins/forc-client/test/data/contract_with_dep_with_salt_conflict/Forc.toml diff --git a/forc-plugins/forc-client/test/data/contract_with_dep_with_salt_conflict/src/main.sw b/forc-plugins/forc-client/test/data/contract_with_dep_with_salt_conflict/src/main.sw new file mode 100644 index 00000000000..7d4a75493c6 --- /dev/null +++ b/forc-plugins/forc-client/test/data/contract_with_dep_with_salt_conflict/src/main.sw @@ -0,0 +1,11 @@ +contract; + +abi MyContract { + fn test_function() -> bool; +} + +impl MyContract for Contract { + fn test_function() -> bool { + true + } +} diff --git a/forc-plugins/forc-client/test/data/standalone_contract/.gitignore b/forc-plugins/forc-client/test/data/standalone_contract/.gitignore new file mode 100644 index 00000000000..77d3844f58c --- /dev/null +++ b/forc-plugins/forc-client/test/data/standalone_contract/.gitignore @@ -0,0 +1,2 @@ +out +target diff --git a/forc-plugins/forc-client/test/data/manifests/standalone_contract/Forc.toml b/forc-plugins/forc-client/test/data/standalone_contract/Forc.toml similarity index 100% rename from forc-plugins/forc-client/test/data/manifests/standalone_contract/Forc.toml rename to forc-plugins/forc-client/test/data/standalone_contract/Forc.toml diff --git a/forc-plugins/forc-client/test/data/standalone_contract/src/main.sw b/forc-plugins/forc-client/test/data/standalone_contract/src/main.sw new file mode 100644 index 00000000000..7d4a75493c6 --- /dev/null +++ b/forc-plugins/forc-client/test/data/standalone_contract/src/main.sw @@ -0,0 +1,11 @@ +contract; + +abi MyContract { + fn test_function() -> bool; +} + +impl MyContract for Contract { + fn test_function() -> bool { + true + } +} diff --git a/forc-plugins/forc-client/test/data/standalone_contract_b/.gitignore b/forc-plugins/forc-client/test/data/standalone_contract_b/.gitignore new file mode 100644 index 00000000000..77d3844f58c --- /dev/null +++ b/forc-plugins/forc-client/test/data/standalone_contract_b/.gitignore @@ -0,0 +1,2 @@ +out +target diff --git a/forc-plugins/forc-client/test/data/manifests/standalone_contract_b/Forc.toml b/forc-plugins/forc-client/test/data/standalone_contract_b/Forc.toml similarity index 100% rename from forc-plugins/forc-client/test/data/manifests/standalone_contract_b/Forc.toml rename to forc-plugins/forc-client/test/data/standalone_contract_b/Forc.toml diff --git a/forc-plugins/forc-client/test/data/standalone_contract_b/src/main.sw b/forc-plugins/forc-client/test/data/standalone_contract_b/src/main.sw new file mode 100644 index 00000000000..7d4a75493c6 --- /dev/null +++ b/forc-plugins/forc-client/test/data/standalone_contract_b/src/main.sw @@ -0,0 +1,11 @@ +contract; + +abi MyContract { + fn test_function() -> bool; +} + +impl MyContract for Contract { + fn test_function() -> bool { + true + } +}