naddison36 / sol2uml

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

Error: Failed to find contract with name "undefined" #95

Closed gpersoon closed 2 years ago

gpersoon commented 2 years ago

On both Linux (ubuntu 20.04.4 wsl on windows) and Windows 11, I still get this error message with version 2.1.7 of sol2uml:

> npm ls | grep sol2uml
├── sol2uml@2.1.7 extraneous -> ./.nvm/versions/node/v16.15.1/lib/node_modules/sol2uml

> sol2uml flatten 0x2762e676a9f17c7de34fe4b124424837c7e18e1c
Solidity written to KoiosECDSA.sol

> 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 +1ms
  sol2uml Added contract Context +0ms
  sol2uml Added contract IERC165 +0ms
  sol2uml Added contract ERC165 +0ms
  sol2uml Added contract IERC721 +1ms
  sol2uml Added contract IERC721Metadata +0ms
  sol2uml Added contract Address +0ms
  sol2uml Added contract Strings +0ms
  sol2uml Added contract ERC721 +1ms
  sol2uml Added contract IERC721Enumerable +0ms
  sol2uml Added contract ERC721Enumerable +0ms
  sol2uml Added contract Ownable +0ms
  sol2uml Added contract ECDSA +0ms
  sol2uml Added contract SignedTokenVerifier +1ms
  sol2uml Added contract KoiosECDSA +0ms
  sol2uml Added contract IERC721Receiver +0ms
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:52:15)
    at Command.<anonymous> (/home/gerard/.nvm/versions/node/v16.15.1/lib/node_modules/sol2uml/lib/sol2uml.js:115: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:180:5)
naddison36 commented 2 years ago

Can you run sol2uml -V to double-check the new version is being picked up?

This is what is looks like for me

 sol2uml -V
2.1.7
 sol2uml flatten 0x2762e676a9f17c7de34fe4b124424837c7e18e1c -v
  sol2uml verbose on +0ms
  sol2uml About to flatten 0x2762e676a9f17c7de34fe4b124424837c7e18e1c +0ms
  sol2uml About to get Solidity source code for 0x2762e676a9f17c7de34fe4b124424837c7e18e1c from https://api.etherscan.io/api +0ms
  sol2uml codeFolder koios childNode.path @openzeppelin/contracts/access/Ownable.sol +0ms
  sol2uml Added Etherscan import @openzeppelin/contracts/access/Ownable.sol with class names:  +0ms
  sol2uml codeFolder koios childNode.path @openzeppelin/contracts/utils/Strings.sol +0ms
  sol2uml Added Etherscan import @openzeppelin/contracts/utils/Strings.sol with class names:  +0ms
  sol2uml codeFolder koios childNode.path @openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol +0ms
  sol2uml Added Etherscan import @openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol with class names:  +0ms
  sol2uml codeFolder koios childNode.path @openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol +0ms
  sol2uml Added Etherscan import @openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol with class names:  +0ms
  sol2uml codeFolder koios childNode.path @openzeppelin/contracts/utils/cryptography/ECDSA.sol +0ms
  sol2uml Added Etherscan import @openzeppelin/contracts/utils/cryptography/ECDSA.sol with class names:  +0ms
  sol2uml codeFolder koios childNode.path ./SignedTokenVerifier.sol +0ms
  sol2uml Added Etherscan import koios/SignedTokenVerifier.sol with class names:  +0ms
  sol2uml Added contract KoiosECDSA +1ms
  sol2uml codeFolder koios childNode.path @openzeppelin/contracts/utils/cryptography/ECDSA.sol +17ms
  sol2uml Added Etherscan import @openzeppelin/contracts/utils/cryptography/ECDSA.sol with class names:  +1ms
  sol2uml Added contract SignedTokenVerifier +0ms
  sol2uml codeFolder @openzeppelin/contracts/utils/cryptography childNode.path ../Strings.sol +46ms
  sol2uml Added Etherscan import @openzeppelin/contracts/utils/Strings.sol with class names:  +0ms
  sol2uml Added contract ECDSA +0ms
  sol2uml codeFolder @openzeppelin/contracts/token/ERC721/extensions childNode.path ../IERC721.sol +1ms
  sol2uml Added Etherscan import @openzeppelin/contracts/token/ERC721/IERC721.sol with class names:  +0ms
  sol2uml Added contract IERC721Enumerable +0ms
  sol2uml codeFolder @openzeppelin/contracts/token/ERC721/extensions childNode.path ../ERC721.sol +30ms
  sol2uml Added Etherscan import @openzeppelin/contracts/token/ERC721/ERC721.sol with class names:  +0ms
  sol2uml codeFolder @openzeppelin/contracts/token/ERC721/extensions childNode.path ./IERC721Enumerable.sol +0ms
  sol2uml Added Etherscan import @openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol with class names:  +0ms
  sol2uml Added contract ERC721Enumerable +0ms
  sol2uml Added contract Strings +15ms
  sol2uml codeFolder @openzeppelin/contracts/access childNode.path ../utils/Context.sol +6ms
  sol2uml Added Etherscan import @openzeppelin/contracts/utils/Context.sol with class names:  +0ms
  sol2uml Added contract Ownable +0ms
  sol2uml codeFolder @openzeppelin/contracts/token/ERC721 childNode.path ../../utils/introspection/IERC165.sol +1ms
  sol2uml Added Etherscan import @openzeppelin/contracts/utils/introspection/IERC165.sol with class names:  +0ms
  sol2uml Added contract IERC721 +0ms
  sol2uml codeFolder @openzeppelin/contracts/token/ERC721 childNode.path ./IERC721.sol +46ms
  sol2uml Added Etherscan import @openzeppelin/contracts/token/ERC721/IERC721.sol with class names:  +0ms
  sol2uml codeFolder @openzeppelin/contracts/token/ERC721 childNode.path ./IERC721Receiver.sol +0ms
  sol2uml Added Etherscan import @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol with class names:  +0ms
  sol2uml codeFolder @openzeppelin/contracts/token/ERC721 childNode.path ./extensions/IERC721Metadata.sol +0ms
  sol2uml Added Etherscan import @openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol with class names:  +0ms
  sol2uml codeFolder @openzeppelin/contracts/token/ERC721 childNode.path ../../utils/Address.sol +0ms
  sol2uml Added Etherscan import @openzeppelin/contracts/utils/Address.sol with class names:  +0ms
  sol2uml codeFolder @openzeppelin/contracts/token/ERC721 childNode.path ../../utils/Context.sol +0ms
  sol2uml Added Etherscan import @openzeppelin/contracts/utils/Context.sol with class names:  +0ms
  sol2uml codeFolder @openzeppelin/contracts/token/ERC721 childNode.path ../../utils/Strings.sol +0ms
  sol2uml Added Etherscan import @openzeppelin/contracts/utils/Strings.sol with class names:  +0ms
  sol2uml codeFolder @openzeppelin/contracts/token/ERC721 childNode.path ../../utils/introspection/ERC165.sol +0ms
  sol2uml Added Etherscan import @openzeppelin/contracts/utils/introspection/ERC165.sol with class names:  +0ms
  sol2uml Added contract ERC721 +0ms
  sol2uml Added contract Context +1ms
  sol2uml Added contract IERC165 +0ms
  sol2uml codeFolder @openzeppelin/contracts/utils/introspection childNode.path ./IERC165.sol +1ms
  sol2uml Added Etherscan import @openzeppelin/contracts/utils/introspection/IERC165.sol with class names:  +0ms
  sol2uml Added contract ERC165 +0ms
  sol2uml Added contract Address +11ms
  sol2uml codeFolder @openzeppelin/contracts/token/ERC721/extensions childNode.path ../IERC721.sol +1ms
  sol2uml Added Etherscan import @openzeppelin/contracts/token/ERC721/IERC721.sol with class names:  +0ms
  sol2uml Added contract IERC721Metadata +0ms
  sol2uml Added contract IERC721Receiver +0ms
  sol2uml About to write Solidity to file KoiosECDSA.sol +0ms
gpersoon commented 2 years ago

The flatten works fine for me too, however sol2uml storage KoiosECDSA.sol -v doesn't.

It is using the 2.1.7 version

sol2uml -V
2.1.7
naddison36 commented 2 years ago

I see, you are flattening the source locally and then running storage against the local file. You'll need to use the -c, --contract <name> option to tell sol2uml which contract you want to generate the storage diagram for in the source file.

 sol2uml storage -c KoiosECDSA ./KoiosECDSA.sol -v

Note you can generate the storage diagram directly from the source files on Etherscan with the following. It will use Etherscan's contract name so you don't need to explicitly specify which contract to draw the storage diagram for.

sol2uml storage 0x2762e676a9f17c7de34fe4b124424837c7e18e1c -v

And for some extra fun, you can get the data in the storage slots with the -d, --data option

export NODE_URL=<your API provider's url>
sol2uml storage -d 0x2762e676a9f17c7de34fe4b124424837c7e18e1c -v

You can also use the -u, --url <url> option to specify your node provider's url.

naddison36 commented 2 years ago

On the TODO list is to decode the slot data so you can see the number and string values.

gpersoon commented 2 years ago

Thanks, with the -c parameter it indeed works! Might be helpful to give an error message indicating the -c parameter is missing.

naddison36 commented 2 years ago

Good idea. I'll do that.

naddison36 commented 2 years ago

I've published v2.1.8 with better handling of the storage diagram's -c option

gpersoon commented 2 years ago

Thanks, works nicely now!