-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Optimize ArtifactsManager#artifactExists
#8122
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,8 +92,6 @@ export interface ArtifactManager { | |
| * This function doesn't throw if the name is not unique. | ||
| * | ||
| * @param contractNameOrFullyQualifiedName Contract or fully qualified name. | ||
| * @throws Throws an error if a non-unique contract name is used, | ||
| * indicating which fully qualified names can be used instead. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that this function’s semantics have changed, it would be good to call it out here. When there are multiple contracts with the same name, if (await hre.artifacts.artifactExists("Foo")) {
const a = await hre.artifacts.readArtifact("Foo"); // MULTIPLE_FOUND error
}This could be confusing for users who expect
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add a comment. That's a good point. Note that I don't think the intentional semantics changed. I did a bit of and this method didn't used to have the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in b1e4fcb |
||
| */ | ||
| artifactExists(contractNameOrFullyQualifiedName: string): Promise<boolean>; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
artifactExistsbehavior changed to return a boolean based on cached fs data (and no longer relies ongetArtifactPaththrowing). There are existing tests forArtifactManagerImplementationinpackages/hardhat/test/internal/builtin-plugins/artifacts/artifact-manager.ts, but none coverartifactExists—especially the non-unique bare-name case that this change is meant to handle. Add tests that assert: (1) returnstruefor an existing bare name, (2) returnstruefor an existing fully-qualified name, (3) returnsfalsefor a missing name, and (4) returnstrue(and does not throw) when multiple artifacts share the same bare name.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, done