Closed luismasuelli closed 1 month ago
Just a suggestion for this to work. I just found and made this change and it worked:
@nomicfoundation/hardhat-ignition/dist/src/hardhat-artifact-resolver.js
and found the _resolvePath
function, which its TRANSPILED code looks like this:async _resolvePath(contractName) {
const artifactPaths = await this._hre.artifacts.getArtifactPaths();
const artifactPath = artifactPaths.find((p) => path_1.default.parse(p).name === contractName);
return artifactPath;
}
async _resolvePath(contractName) {
// My addition starts here:
const parts = contractName.split(":");
if (parts.length != 1) {
contractName = parts.pop();
const filename = parts.join(":");
const projectArtifactsPath = this._hre.config.paths.artifacts;
const fullArtifactPath = path_1.default.resolve(projectArtifactsPath, filename, contractName + ".json");
const artifactPaths = await this._hre.artifacts.getArtifactPaths();
if (artifactPaths.indexOf(fullArtifactPath) >= 0) {
return fullArtifactPath;
} else {
return undefined;
}
}
// My addition ends here.
const artifactPaths = await this._hre.artifacts.getArtifactPaths();
const artifactPath = artifactPaths.find((p) => path_1.default.parse(p).name === contractName);
return artifactPath;
}
Then this made my attempt on using FQ contract names... work.
Perhaps you could try this (I'm sorry. I did not do a full test or properly add test cases for this, so this is why I made no PR and just suggesting this to test: perhaps there are things that I'm not covering / considering by doing this).
Thanks @luismasuelli, this is a bug. I have been able to reproduce it locally. We will take a look at your resolve path suggestion.
please, up
What happened?
When I have two contracts with the same name (let's say "MyContract", in different .sol files in different paths) the resolution in the
m.contract("MyContract", [], ...)
future prompts to use fully-qualified artifact names, but then when I try that it is not accepted/found by ignition. So there's no way to discriminate between artifacts with the same name (I agree that, however, having artifacts with the same name is not necessarily a good practice, but they might come somehow from different libraries).Minimal reproduction steps
Hardhat version: 2.22.5. Hardhat Ignition version: 0.15.4 (at least by checking the package-lock.json). Also using:
@openzeppelin/contracts
.Out of curiosity, I copied the contract exactly into a new directory (yes, two copies of the same file): contracts/subdirectory/MyOwnedERC20.sol.
Then I built:
npx hardhat compile
.Then, create a hardhat ignition module. In this example, ignition/modules/MyOwnedERC20.js. The contents are simple:
Notice how there are 3 lines intentionally commented. We'll make use of it in the next steps.
npx hardhat ignition deploy ignition/modules/MyOwnedERC20.js
. You'll see an error:(this is a standard hardhat error and it is understandable, so no problem here)
npx hardhat ignition deploy ignition/modules/MyOwnedERC20.js
. You'll see another error now:I expect: the fully-qualified artifact path to work.
Search terms
duplicate artifact name