Good day folks, I am back!
First things first, I am having a blast with the OpenZeppelin framework. 6 months ago I was using ZeppelinOS. I am very happy to see that the current state of OpenZeppelin is WAY more robust and developer friendly than ZeppelinOS was. No weird errors and bugs for me anymore. You guys really did a great job.
Details
Now for my issue and question. I want to unit test my contracts with Truffle,, as shown in the docs. This is working as expected. The thing that left me confused and wondering is a clash between OpenZeppelin and Truffle. In order to test with Truffle I have to run truffle compile
, while OpenZeppelin uses it's own openzeppelin compile
.
My problem is requiring contracts located in the same project directory. OpenZeppelin wants me to code require("Contract.sol");
while Truffle wants to see require("./Contract.sol")
. The Truffle approach is correct according to the Solidity documentation. For now, when I want to test my Contracts, I have to change the import line to the Truffle way and test the contracts, and when I want to deploy and/or upgrade, I change it back to the OpenZeppelin import. I think this is not the desired behaviour.
Environment
Truffle v5.0.41 (core: 5.0.41)
Solidity v0.5.8 (solc-js)
Node v10.16.3
Web3.js v1.2.1
OpenZeppelin v2.5.3
Windows 10 1903
Code to reproduce
Reference a contract the Solidity/Truffle way: require("./Contract.sol")
and run openzeppelin compile
results in the following output:
Compiling contracts with solc 0.5.12 (commit.7709ece9)
Compilation errors:
contracts\OtherContract.sol:5:1: ParserError: Source "Contract.sol" not found: File import callback not supported
import "./Contract.sol";
^-----------------------^
As for the other way around: require("Contract.sol")
and run truffle compile
results in the following output:
Error: CompileError: /C/Users/mypath/contracts/OtherContract.sol:5:1: ParserError: Source "Contract.sol" not found: File import callback not supported
import "Contract.sol";
^---------------------^
Compilation failed. See above.
at Object.compile (C:\Users\mypath\node_modules\truffle\build\webpack:\packages\workflow-compile\legacy\index.js:72:1)
Truffle v5.0.41 (core: 5.0.41)
Node v10.16.3
My guess is this is a bug in OpenZeppelin, hope to hear back from you