gnosis / mock-contract

Simple Solidity contract to mock dependent contracts in truffle tests.
94 stars 24 forks source link

Error: Could not find artifacts for .\MockContract.sol from any sources #18

Closed dzegel-blockcrowd closed 4 years ago

dzegel-blockcrowd commented 4 years ago

I'm trying to use mock-contract and getting the following error: image

Steps Iv'e taken:

  1. Added "@gnosis.pm/mock-contract": "^3.0.8", to my package.json (and of course ran npm i)
  2. Added a file called Imports.sol to my contracts folder with the following contents:
    
    pragma solidity ^0.5.0;

// We import the contract so truffle compiles it, and we have the ABI // available when working from truffle console. import "@gnosis.pm/mock-contract/contracts/MockContract.sol";

3. Since I'me using VS Code I had to add the following to my `settings.json` file:
"solidity.packageDefaultDependenciesContractsDirectory": "",
"solidity.packageDefaultDependenciesDirectory": "node_modules"

4.  Added `const MockContract = artifacts.require("./MockContract.sol");` to the top of my test file.

@fleupold (or anyone else) are you able to tell me what the problem is?

_By the way I just want to mention that I really appreciate that you built this. From what I can find, its the only smart contract mocking framework around. The only other alternativeseems to be just writing fake contracts which I really prefer not to do._
fleupold commented 4 years ago

Hi @dzegel-blockcrowd,

two ideas on how to debug this:

  1. When running truffle compile, can you see the MockContract.sol being compiled?
  2. Can you check if const MockContract = artifacts.require("MockContract") makes any difference (it shouldn't but maybe the pass specifier is not working correctly und Windows)

Also, feel free to send a link to a github repo/branch with the code, so I can take a look and try to get it to run locally.

dzegel-blockcrowd commented 4 years ago

Hey @fleupold thanks for the quick response.

  1. No I'm not seeing the compiled json from MockContract.sol 2 I did try const MockContract = artifacts.require("MockContract") as well as const MockContract = artifacts.require("@gnosis.pm/mock-contract/contracts/MockContract.sol"); and they both have the same problem.

Unfortunately the repo I'm working on is a private one so I cant share the code itself, but if we cant figure this out perhaps I'll try to reproduce the issue in a public repo.

dzegel-blockcrowd commented 4 years ago

Oh actually I just managed to get it to compile MockContract.sol and it works now. Not exactly sure why truffle compile didn't pick it up before but its working now.

Thanks again for the quick response.

fleupold commented 4 years ago

Glad you got it working. Is it possible that Imports.sol was missing an empty contract definition? Maybe truffle doesn't pick up the dependency if the file itself doesn't contain a contract.

I realize the README doesn't mention this but in the projects where we use the library we always have

import "@gnosis.pm/mock-contract/contracts/MockContract.sol";

contract DevDependencies {}
dzegel-blockcrowd commented 4 years ago

it did not have an empty contract definition

I got truffle to pick it up by clearing out all the build directory, and recompiling 🤷‍♂