Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable package manifest file verification during PackageManifestFile::new #4412

Merged
merged 6 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 `PackageManifet`.
kayagokalp marked this conversation as resolved.
Show resolved Hide resolved
/// 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
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
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
}
}