naddison36 / sol2uml

Solidity contract visualisation tool
MIT License
1.13k stars 268 forks source link

sol2uml storage: `Failed to generate storage diagram`, while uml diagram generates without error #89

Closed gpersoon closed 2 years ago

gpersoon commented 2 years ago

sol2uml storage shows this error: Failed to generate storage diagram, while the uml diagram generates without error, as well as sol2uml flatten. Note: the @openzeppelin contracts are not installed locally.

>sol2uml 0x2762e676a9f17c7de34fe4b124424837c7e18e1c Generated svg file KoiosECDSA.svg

>sol2uml flatten 0x2762e676a9f17c7de34fe4b124424837c7e18e1c Solidity written to KoiosECDSA.sol

>sol2uml storage 0x2762e676a9f17c7de34fe4b124424837c7e18e1c Failed to generate storage diagram. Error: Failed to find inherited contract "ERC721" of "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol" at C:\Users...\AppData\Roaming\npm\node_modules\sol2uml\lib\converterClasses2Storage.js:70:19 at Array.forEach () at parseVariables (C:\Users...\AppData\Roaming\npm\node_modules\sol2uml\lib\converterClasses2Storage.js:67:27) at C:\Users...\AppData\Roaming\npm\node_modules\sol2uml\lib\converterClasses2Storage.js:73:9 at Array.forEach () at parseVariables (C:\Users...\AppData\Roaming\npm\node_modules\sol2uml\lib\converterClasses2Storage.js:67:27) at convertClasses2Storages (C:\Users...\AppData\Roaming\npm\node_modules\sol2uml\lib\converterClasses2Storage.js:41:23) at Command. (C:\Users...\AppData\Roaming\npm\node_modules\sol2uml\lib\sol2uml.js:118:81) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async Command.parseAsync (C:\Users...\AppData\Roaming\npm\node_modules\sol2uml\node_modules\commander\lib\command.js:917:5)

naddison36 commented 2 years ago

This is strange. I can tell from the error message that you are using at least v2.1.1 which works for me. If you were using an older version I'd say try upgrading to the latest release but I don't think that's going to help here.

sol2uml storage 0x2762e676a9f17c7de34fe4b124424837c7e18e1c   
Generated svg file /Users/nicholasaddison/KoiosECDSA.svg

KoiosECDSA

What operating system and node version are you using?

gpersoon commented 2 years ago

I'm using Windows 11 (Version 10.0.22000.832) and Node version 18.7.0:

>sol2uml storage 0x2762e676a9f17c7de34fe4b124424837c7e18e1c -v
  sol2uml verbose on +0ms
  sol2uml argument 0x2762e676a9f17c7de34fe4b124424837c7e18e1c is an Ethereum address so checking Etherscan for the verified source code +0ms
  sol2uml About to get Solidity source code for 0x2762e676a9f17c7de34fe4b124424837c7e18e1c from https://api.etherscan.io/api +0ms
  sol2uml Adding contract KoiosECDSA +0ms
  sol2uml Adding contract SignedTokenVerifier +19ms
  sol2uml Adding contract ECDSA +57ms
  sol2uml Adding contract IERC721Enumerable +2ms
  sol2uml Adding contract ERC721Enumerable +36ms
  sol2uml Adding contract Strings +19ms
  sol2uml Adding contract Ownable +8ms
  sol2uml Adding contract IERC721 +2ms
  sol2uml Adding contract ERC721 +59ms
  sol2uml Adding contract Context +2ms
  sol2uml Adding contract IERC165 +0ms
  sol2uml Adding contract ERC165 +1ms
  sol2uml Adding contract Address +16ms
  sol2uml Adding contract IERC721Metadata +1ms
  sol2uml Adding contract IERC721Receiver +1ms
Failed to generate storage diagram.
Error: Failed to find inherited contract "ERC721" of "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"
    at C:\Users\gerar\AppData\Roaming\npm\node_modules\sol2uml\lib\converterClasses2Storage.js:70:19
    at Array.forEach (<anonymous>)
    at parseVariables (C:\Users\gerar\AppData\Roaming\npm\node_modules\sol2uml\lib\converterClasses2Storage.js:67:27)
    at C:\Users\gerar\AppData\Roaming\npm\node_modules\sol2uml\lib\converterClasses2Storage.js:73:9
    at Array.forEach (<anonymous>)
    at parseVariables (C:\Users\gerar\AppData\Roaming\npm\node_modules\sol2uml\lib\converterClasses2Storage.js:67:27)
    at convertClasses2Storages (C:\Users\gerar\AppData\Roaming\npm\node_modules\sol2uml\lib\converterClasses2Storage.js:41:23)
    at Command.<anonymous> (C:\Users\gerar\AppData\Roaming\npm\node_modules\sol2uml\lib\sol2uml.js:118:81)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Command.parseAsync (C:\Users\gerar\AppData\Roaming\npm\node_modules\sol2uml\node_modules\commander\lib\command.js:917:5)
>sol2uml flatten 0x2762e676a9f17c7de34fe4b124424837c7e18e1c
Solidity written to KoiosECDSA.sol

When I try it based on KoiosECDSA.sol, I get: Error: Failed to find contract with name "undefined"

>sol2uml storage KoiosECDSA.sol -v
  sol2uml verbose on +0ms
  sol2uml About to get Solidity files under KoiosECDSA.sol +0ms
  sol2uml Got Solidity file to be parsed: KoiosECDSA.sol +0ms
  sol2uml Adding contract ERC721Enumerable +0ms
  sol2uml Adding contract Ownable +2ms
  sol2uml Adding contract Strings +0ms
  sol2uml Adding contract KoiosECDSA +0ms
  sol2uml Adding contract ECDSA +0ms
  sol2uml Adding contract SignedTokenVerifier +1ms
  sol2uml Adding contract IERC721Enumerable +0ms
  sol2uml Adding contract IERC721 +0ms
  sol2uml Adding contract ERC721 +0ms
  sol2uml Adding contract Context +1ms
  sol2uml Adding contract IERC165 +0ms
  sol2uml Adding contract ERC165 +0ms
  sol2uml Adding contract Address +0ms
  sol2uml Adding contract IERC721Metadata +0ms
  sol2uml Adding contract IERC721Receiver +0ms
Failed to generate storage diagram.
Error: Failed to find contract with name "undefined"
    at convertClasses2Storages (C:\Users\gerar\AppData\Roaming\npm\node_modules\sol2uml\lib\converterClasses2Storage.js:38:15)
    at Command.<anonymous> (C:\Users\gerar\AppData\Roaming\npm\node_modules\sol2uml\lib\sol2uml.js:118:81)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Command.parseAsync (C:\Users\gerar\AppData\Roaming\npm\node_modules\sol2uml\node_modules\commander\lib\command.js:917:5)
    at async main (C:\Users\gerar\AppData\Roaming\npm\node_modules\sol2uml\lib\sol2uml.js:181:5)

I've also tried it on Ubuntu 20.04.4 LTS (GNU/Linux 5.10.102.1-microsoft-standard-WSL2 x86_64), with node v16.15.1:

First time:

 sol2uml storage 0x2762e676a9f17c7de34fe4b124424837c7e18e1c -v
  sol2uml verbose on +0ms
  sol2uml argument 0x2762e676a9f17c7de34fe4b124424837c7e18e1c is an Ethereum address so checking Etherscan for the verified source code +0ms
  sol2uml About to get Solidity source code for 0x2762e676a9f17c7de34fe4b124424837c7e18e1c from https://api.etherscan.io/api +0ms
undefined

Second time it worked though!:

sol2uml storage 0x2762e676a9f17c7de34fe4b124424837c7e18e1c
  ...
Generated svg file /home/gerard/uml/KoiosECDSA.svg

However this gives an error:

sol2uml storage KoiosECDSA.sol -v
  sol2uml verbose on +0ms
  sol2uml About to get Solidity files under KoiosECDSA.sol +0ms
  sol2uml Got Solidity file to be parsed: KoiosECDSA.sol +0ms
  sol2uml Adding contract Context +0ms
  sol2uml Adding contract IERC165 +1ms
  sol2uml Adding contract ERC165 +0ms
  sol2uml Adding contract IERC721 +0ms
  sol2uml Adding contract IERC721Metadata +0ms
  sol2uml Adding contract Address +0ms
  sol2uml Adding contract Strings +1ms
  sol2uml Adding contract ERC721 +0ms
  sol2uml Adding contract IERC721Enumerable +1ms
  sol2uml Adding contract ERC721Enumerable +0ms
  sol2uml Adding contract Ownable +0ms
  sol2uml Adding contract ECDSA +0ms
  sol2uml Adding contract SignedTokenVerifier +0ms
  sol2uml Adding contract KoiosECDSA +0ms
  sol2uml Adding contract IERC721Receiver +1ms
Error: Failed to find contract with name "undefined"
    at convertClasses2Storages (/home/gerard/.nvm/versions/node/v16.15.1/lib/node_modules/sol2uml/lib/converterClasses2Storage.js:38:15)
    at Command.<anonymous> (/home/gerard/.nvm/versions/node/v16.15.1/lib/node_modules/sol2uml/lib/sol2uml.js:113:81)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Command.parseAsync (/home/gerard/.nvm/versions/node/v16.15.1/lib/node_modules/sol2uml/node_modules/commander/lib/command.js:917:5)
    at async main (/home/gerard/.nvm/versions/node/v16.15.1/lib/node_modules/sol2uml/lib/sol2uml.js:178:5)
naddison36 commented 2 years ago

Thanks for this information. That's super useful. I'll have to debug on a Windows machine so the import paths logic will work on Mac/Linux and Windows.

naddison36 commented 2 years ago

This should be fixed with v2.1.6.

The problem was I needed to use the posix resolve when working with imports from files sourced from Etherscan. When running on windows, path defaults to win32 which will not work.

zguesmi commented 10 months ago

Hi @naddison36 , I am having the same issue when trying to generate storage diagram for a contract in local folder. First, do you confirm that it is possible to that or it only works with deployed contracts?

naddison36 commented 10 months ago

storage diagrams should work with local contracts. Are you on Windows?

zguesmi commented 10 months ago

No I'm using Ubuntu 22.04 Here are the details of the problem. <mainContract> is my target contract and it inherits from the interface`

node -v
v18.9.0

npx sol2uml --version
2.5.16

npx sol2uml storage -c <mainContract> contracts/.../<mainContract>.sol -v

2023-10-27T09:30:39.753Z sol2uml verbose on
2023-10-27T09:30:39.754Z sol2uml About to get Solidity files under contracts/.../<mainContract>.sol
2023-10-27T09:30:39.754Z sol2uml Got Solidity file to be parsed: contracts/.../<mainContract>.sol
2023-10-27T09:30:39.994Z sol2uml Added filesystem import <rootfolder>/node_modules/@openzeppelin/contracts-v4/interfaces/IERC1271.sol with class names IERC1271
2023-10-27T09:30:39.994Z sol2uml Added filesystem import <rootfolder>/node_modules/@openzeppelin/contracts-v4/interfaces/IERC5313.sol with class names IERC5313
2023-10-27T09:30:39.995Z sol2uml Added filesystem import <rootfolder>/node_modules/@openzeppelin/contracts-v4/utils/cryptography/ECDSA.sol with class names ECDSA
2023-10-27T09:30:39.995Z sol2uml Added filesystem import <rootfolder>/node_modules/@openzeppelin/contracts-v4/utils/math/Math.sol with class names Math
2023-10-27T09:30:39.995Z sol2uml Added filesystem import <rootfolder>/node_modules/@openzeppelin/contracts-v4/utils/math/SafeCast.sol with class names SafeCast
2023-10-27T09:30:39.995Z sol2uml Added filesystem import <rootfolder>/contracts/.../IERC734.sol with class names IERC734
2023-10-27T09:30:39.995Z sol2uml Added filesystem import <rootfolder>/contracts/.../IOracleConsumer.sol with class names IOracleConsumer
2023-10-27T09:30:39.995Z sol2uml Added filesystem import <rootfolder>/contracts/libs/<someLocalContract>.sol with class names <someLocalContract>
2023-10-27T09:30:39.995Z sol2uml Added filesystem import <rootfolder>/contracts/libs/<someLocalContract>.sol with class names <someLocalContract>
2023-10-27T09:30:39.995Z sol2uml Added filesystem import <rootfolder>/contracts/.../<someLocalContract>.sol with class names <someLocalContract>
2023-10-27T09:30:39.995Z sol2uml Added filesystem import <rootfolder>/contracts/modules/<someLocalContract>.sol with class names <someLocalContract>
2023-10-27T09:30:39.996Z sol2uml Added filesystem import <rootfolder>/contracts/modules/interfaces/<problematicContract>.sol with class names <problematicContract>
2023-10-27T09:30:39.996Z sol2uml Added filesystem import <rootfolder>/contracts/.../<someLocalContract>.v8.sol with class names <someLocalContract>
2023-10-27T09:30:39.997Z sol2uml Added contract <mainContract>
2023-10-27T09:30:39.997Z sol2uml Found contract "<mainContract>" in <rootfolder>/contracts/.../<mainContract>.sol
Error: Failed to find inherited contract "<problematicContract>" of "<rootfolder>/contracts/.../<mainContract>.sol"
    at <rootfolder>/node_modules/sol2uml/lib/converterClasses2Storage.js:134:19
    at Array.forEach (<anonymous>)
    at parseVariables (<rootfolder>/node_modules/sol2uml/lib/converterClasses2Storage.js:131:27)
    at convertClasses2StorageSections (<rootfolder>/node_modules/sol2uml/lib/converterClasses2Storage.js:51:23)
    at Command.<anonymous> (<rootfolder>/node_modules/sol2uml/lib/sol2uml.js:151:95)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Command.parseAsync (<rootfolder>/node_modules/commander/lib/command.js:935:5)
    at async main (<rootfolder>/node_modules/sol2uml/lib/sol2uml.js:277:5)
file://<rootfolder>/node_modules/zx/build/core.js:146
            let output = new ProcessOutput(code, signal, stdout, stderr, combined, message);
                         ^
naddison36 commented 10 months ago

Is the code open source? Can I look at the Solidity source files?

My guess is the code is importing from an import which sol2uml currently doesn't handle. It's on my TODO list when I get time. The workaround is to import <problematicContract> directly to <mainContract>.sol

zguesmi commented 10 months ago

I will try to prepare something that reproduces the issue.

zguesmi commented 10 months ago

@naddison36 Please check this repo, you can reproduce the issue there. https://github.com/zguesmi/storage-diagrams#sol2uml As instructed in the README, install npm packages and run

npx sol2uml storage -c Store contracts/

you should get the error

Error: Failed to find inherited contract "Ownable" of ".../contracts/Store.sol"

BTW, sol2uml class ... command is working fine.

rori4 commented 10 months ago

@naddison36 Please check this repo, you can reproduce the issue there. https://github.com/zguesmi/storage-diagrams#sol2uml As instructed in the README, install npm packages and run

npx sol2uml storage -c Store contracts/

you should get the error

Error: Failed to find inherited contract "Ownable" of ".../contracts/Store.sol"

BTW, sol2uml class ... command is working fine.

@naddison36 I am having the exact same issue. Any workaround for this?

EDIT: it seems to have been an issue with remappings. It can't automatically find the @openzeppelin library that is installed with foundry so you need you specify the location of the imported contracts directly. For example

import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

would be changed to

import {ReentrancyGuard} from "../lib/openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol";

naddison36 commented 10 months ago

@naddison36 Please check this repo, you can reproduce the issue there. https://github.com/zguesmi/storage-diagrams#sol2uml As instructed in the README, install npm packages and run

npx sol2uml storage -c Store contracts/

you should get the error

Error: Failed to find inherited contract "Ownable" of ".../contracts/Store.sol"

BTW, sol2uml class ... command is working fine.

Apologies for the delay.

So the problem is sol2uml will only look for contracts under the folder you specify. So in the above example, it's looking for contracts under the contracts folder. The Ownable contract is under ./node_modules/@openzeppelin/contracts/access/

You can pass in a comma-separated list of folders so all of the following will work

sol2uml storage -c Store .
sol2uml storage -c Store contracts/,./node_modules
sol2uml storage -c Store contracts/,./node_modules/@openzeppelin/contracts/ 
zguesmi commented 9 months ago

Thank you @naddison36 for your answer! It's clearer to me now.

zguesmi commented 9 months ago

I confirm that your recommendation fixed my issue. I also fixed the next issue using this comment https://github.com/naddison36/sol2uml/issues/175#issuecomment-1807445743. Thank you @naddison36.