dapphub / dapptools

Dapp, Seth, Hevm, and more
https://dapp.tools
2.09k stars 325 forks source link

Importing contracts from OpenZeppelin #27

Closed mbrock closed 3 years ago

mbrock commented 6 years ago

Issue by fccoelho Tuesday Dec 26, 2017 at 18:14 GMT Originally opened as https://github.com/dapphub/dapp/issues/70


My contract imports from Open Zeppelin's StandardToken.sol

I managed to install zeppelin-solidity with:

$ dapp install OpenZeppelin/zeppelin-solidity

I does create a git submodule under the lib directory. But dapp test fails:

dapp test
fatal: Cannot change to 'lib/zeppelin-solidity/src': No such file or directory
child_process.js:495
    throw err;
    ^

Error: Command failed: git -C lib/zeppelin-solidity/src rev-parse HEAD
fatal: Cannot change to 'lib/zeppelin-solidity/src': No such file or directory

    at checkExecSyncError (child_process.js:472:13)
    at Object.execFileSync (child_process.js:492:13)
    at run (/nix/store/5brad209b8d92y2cv32fy72pklx4q2qw-dapp-0.7.9/libexec/dapp/dapp-remappings:57:35)
    at ls.forEach.name (/nix/store/5brad209b8d92y2cv32fy72pklx4q2qw-dapp-0.7.9/libexec/dapp/dapp-remappings:28:16)
    at Array.forEach (native)
    at findRemappings (/nix/store/5brad209b8d92y2cv32fy72pklx4q2qw-dapp-0.7.9/libexec/dapp/dapp-remappings:18:50)
    at Object.<anonymous> (/nix/store/5brad209b8d92y2cv32fy72pklx4q2qw-dapp-0.7.9/libexec/dapp/dapp-remappings:5:1)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)

I seems to expect a src directory inside zeppelin-solidity but it doesn't exist.

is there a way to make this work or do I have to go back to Truffle?

mbrock commented 6 years ago

Comment by nmushegian Saturday Jan 06, 2018 at 19:34 GMT


@dbrock can tell you whether it's possible to alias the src dir, I'll suggest another approach though:

Have you looked at DSToken? https://github.com/dapphub/dapp/issues/70

dapp install ds-token should give you what you need

mbrock commented 6 years ago

Comment by fccoelho Saturday Jan 06, 2018 at 20:01 GMT


Sure, I could also completely give up on importing contracts from libraries and instead write my own. But code reuse is the whole point of open-source software: to avoid repeating the same mistakes over and over.

It seems that dapp is making unnecessary assumptions about how external solidity code is packaged, making it harder to reuse other libraries.

Em 6 de jan de 2018 17:34, "Nikolai Mushegian" notifications@github.com escreveu:

@dbrock https://github.com/dbrock can tell you whether it's possible to alias the src dir, I'll suggest another approach though:

Have you looked at DSToken? #70 https://github.com/dapphub/dapp/issues/70

dapp install ds-token should give you what you need

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dapphub/dapp/issues/70#issuecomment-355770134, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIjW9SeBQDDnQq9L__Gqx6Wq2n1Ey1zks5tH8rMgaJpZM4RM7Qr .

mbrock commented 6 years ago

Comment by dbrock Sunday Jan 07, 2018 at 16:15 GMT


Thanks for opening this issue.

This is not currently directly supported, as dapp expects all source directories to have the same name ($DAPP_SRC, which defaults to src).

The following is probably the easiest workaround:

ln -s contracts lib/zeppelin-solidity/src
echo /src >>.git/modules/lib/zeppelin-solidity/info/exclude

There is no reason why this shouldn't be supported out-of–the-box (or with some configuration). We simply haven't had enough need for it yet, and you are one of the first users to want to do it.

mbrock commented 6 years ago

Comment by fccoelho Sunday Jan 07, 2018 at 17:48 GMT


Thanks for responding. Even though I know dapphub is offering their own set of base contracts, I believe interoperability with other projects is an important feature.

Em 7 de jan de 2018 14:15, "Daniel Brockman" notifications@github.com escreveu:

Thanks for opening this issue.

This is not currently directly supported, as dapp expects all source directories to have the same name ($DAPP_SRC, which defaults to src).

The following is probably the easiest workaround:

cd lib/zeppelin-solidity ln -s contracts src echo /src >>.git/info/exclude

There is no reason why this shouldn't be supported out-of–the-box (or with some configuration). We simply haven't had enough need for it yet, and you are one of the first users to want to do it.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dapphub/dapp/issues/70#issuecomment-355833505, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIjW1cvkP1xuiBQwZhySrLl0ecIjznRks5tIO26gaJpZM4RM7Qr .

mbrock commented 6 years ago

Comment by wjmelements Monday Mar 12, 2018 at 09:23 GMT


To add on to @fccoelho, many repos use contracts instead of src for their solidity. Prominently:

Using src:

mbrock commented 6 years ago

Comment by fccoelho Monday Mar 12, 2018 at 12:00 GMT


The root path for the solidity code could become a configuration variable, facilitating the integration of other codebases.

On Mon, Mar 12, 2018 at 6:23 AM, William Morriss notifications@github.com wrote:

To add on to @fccoelho https://github.com/fccoelho, many repos use contracts instead of src for their solidity. Prominently:

  • omisego
  • OpenZepplin
  • DigixGlobal
  • Populous
  • VeChain

Using src:

  • EOSIO
  • MakerDAO

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dapphub/dapp/issues/70#issuecomment-372242443, or mute the thread https://github.com/notifications/unsubscribe-auth/AAIjWxqyZWSLF2u34PtOIQTaGOnSXsogks5tdj57gaJpZM4RM7Qr .

-- Flávio Codeço Coelho

+55(21) 3799-5551 Professor Escola de Matemática Aplicada Fundação Getulio Vargas Praia de Botafogo, 190 sala 312 Rio de Janeiro - RJ 22250-900 Brasil

mbrock commented 6 years ago

Comment by rainbreak Monday Mar 12, 2018 at 14:51 GMT


The root path is configurable, via the DAPP_SRC environment variable. Have you tried the workaround above to see if it works? That would be a good starting point so we can figure out how to do this.

asymmetric commented 5 years ago

Alternatively, you can just use a git submodule to get the contract's code where dapp expects it, and import it into your contracts the traditional way, i.e. by its relative path.

TimDaub commented 3 years ago

What is the state of this issue? I did the following:

$ dapp install  OpenZeppelin/openzeppelin-contracts 
$ ln -s contracts lib/openzeppelin-contracts/src

and in Solidity, I can then import "openzeppelin-contracts/utils/cryptography/MerkleProof.sol";. Since this issue was opened in 2019, have things improved such that this issue is maybe already resolved?

d-xo commented 3 years ago

If you don't like using the full relative path as @asymmetric suggested, then I think it's probably cleaner to make use of the DAPP_REMAPPINGS environment variable.

You can run dapp remappings > remappings.txt to get a list of the default import remappings that will be passed to solc during compilation. You can then modify the remappings.txt to allow arbitrary custom import paths. Finally, you can then set DAPP_REMAPPINGS=$(cat remappings.txt), and the custom remappings will be applied.

Anyway, I agree this issue can definitely be closed.