Skip to content

Commit

Permalink
fix: enable package manifest file verification during `PackageManifes…
Browse files Browse the repository at this point in the history
…tFile::new` (FuelLabs#4412)

## Description
Fixes missing validation step in the `PackageManifestFile::new()`.
closes FuelLabs#4411.
  • Loading branch information
kayagokalp authored Apr 11, 2023
1 parent 91afe69 commit 4c83b19
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 8 deletions.
15 changes: 9 additions & 6 deletions forc-pkg/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ impl PackageManifestFile {
pub fn from_file(path: PathBuf) -> Result<Self> {
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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions forc-plugins/forc-client/src/op/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out
target
11 changes: 11 additions & 0 deletions forc-plugins/forc-client/test/data/contract_with_dep/src/main.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
contract;

abi MyContract {
fn test_function() -> bool;
}

impl MyContract for Contract {
fn test_function() -> bool {
true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out
target
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
contract;

abi MyContract {
fn test_function() -> bool;
}

impl MyContract for Contract {
fn test_function() -> bool {
true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out
target
11 changes: 11 additions & 0 deletions forc-plugins/forc-client/test/data/standalone_contract/src/main.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
contract;

abi MyContract {
fn test_function() -> bool;
}

impl MyContract for Contract {
fn test_function() -> bool {
true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out
target
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
contract;

abi MyContract {
fn test_function() -> bool;
}

impl MyContract for Contract {
fn test_function() -> bool {
true
}
}

0 comments on commit 4c83b19

Please sign in to comment.