openzeppelin-contract-loader icon indicating copy to clipboard operation
openzeppelin-contract-loader copied to clipboard

dependencyArtifactPath() requires build/contracts path

Open rsodre opened this issue 3 years ago • 0 comments

Function dependencyArtifactPath() is adding hard-coded build/contracts to the path already using artifactsDir from loadArtifact(), failing to load artifacts on test environment.

function dependencyArtifactPath(contractWithDependency: string): string {
  const fragments = contractWithDependency.split('/');
  const contract = fragments.pop();
  const dependency = fragments.join('/');
  try {
    return require.resolve(`${dependency}/build/contracts/${contract}.json`);
  } catch (err) {
    throw new Error(`Cannot find contract ${contractWithDependency}: ${err.message}`);
  }
}

Trying to get this a contract outside of the current project like this...

const { accounts, contract } = require('@openzeppelin/test-environment');
const ChromaFive = contract.fromArtifact('../../../../../cc-dapp/src/contracts/chroma/ChromaFive');

Results in this error...

Error: Cannot find contract ../../../../../cc-dapp/src/contracts/chroma/ChromaFive: Cannot find module '../../../../../cc-dapp/src/contracts/chroma/build/contracts/ChromaFive.json'

rsodre avatar Feb 24 '22 19:02 rsodre