Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Handle contract name not matching file name. #39

Closed
wants to merge 1 commit into from

Conversation

vishakh
Copy link

@vishakh vishakh commented Sep 13, 2015

Added handling for cases where contract names are not case-sensitive identical to their corresponding file names, e.g. fooBar.sol contains a contract called 'FooBar'.

I made this change because I spent quite some time trying to get Truffle to deploy before I realized that the problem was my contract name and the file name in the contracts directory were not identical.

Let me know if you want me to make it more generic and handle all cases where the contact and files names do not match.

…eir corresponding file names, e.g. fooBar.sol contains a contract called 'FooBar'.
@tcoulter
Copy link
Contributor

Thanks @vishakh. This is a good change. I wonder if since we're able to detect the problem, we might as well return the correct result.

Also, there's one issue here. The first result from compile_solidity (i.e., var contractName = Object.keys(result)[0];) isn't necessarily the right contract. For instance, in the case where the code submitted to compile_solidity contains more than one contract (which is possible), the last one will be the one that represents all the compiled code. If we're going to detect this case, we should likely go through the list if keys, convert them to lowercase and see if there's matching one. If so, either show an error (or better) return the right result.

@vishakh
Copy link
Author

vishakh commented Sep 15, 2015

Thanks for the feedback, @tcoulter. I definitely need to add support for code with multiple contracts.

Before I made the change, I thought about whether to simply detect the problem or to also fix it. When two contracts with the same name but mixed cases (e.g. Foo and fOO) are submitted together, it's not clear what should be done. Do you want me to return the correct result on a best effort basis, i.e. return a result where possible and throw an error in boundary cases like the one above? Another option would be simply to warn the user since mismatches between contract and file names will likely cause them issues down the line anyway.

@jgostylo
Copy link

jgostylo commented Feb 7, 2016

I did not see this before I submitted my pull request: #86

Please see my solution although it does not handle the lowercase instance. It actually ignores what the filename is altogether.

@tcoulter tcoulter added this to the v0.4.0 milestone Feb 22, 2016
@tcoulter tcoulter closed this in a3473ce Feb 23, 2016
nakajo2011 pushed a commit to nakajo2011/truffle that referenced this pull request Aug 7, 2018
CruzMolina added a commit that referenced this pull request Dec 6, 2019
Compile-common:  Streamline compiler pkgs using a helper lib
gnidan pushed a commit that referenced this pull request Jan 22, 2020
Compile-common:  Streamline compiler pkgs using a helper lib
CruzMolina added a commit that referenced this pull request Feb 5, 2020
- Revert "Merge pull request #39 from CruzMolina/commonizeCompile"
  This reverts commit 32f3d18, reversing
changes made to 93bbf79.
- Revert "swap out Profiler.updated for Common.updatedFiles (core/lib/test)"
  This reverts commit c822135.
- Revert "swap out Profiler.updated for Commmon.updatedFiles (compile-solidity/new/index)"
  This reverts commit 5ad70e1.
- Revert "pass Common.display to compile.display (compile-solidity/new/index)"
  This reverts commit a9d7cd1.
- Revert "mv Profiler.updated & assoc helpers into (compile-common/utils)"
  This reverts commit 6a09f61.
- Undo misc changes to keep code WET
- Update yarn.lock & pkg deps
CruzMolina added a commit that referenced this pull request Feb 5, 2020
- Revert "Merge pull request #39 from CruzMolina/commonizeCompile"
  This reverts commit 32f3d18, reversing
changes made to 93bbf79.
- Revert "swap out Profiler.updated for Common.updatedFiles (core/lib/test)"
  This reverts commit c822135.
- Revert "swap out Profiler.updated for Commmon.updatedFiles (compile-solidity/new/index)"
  This reverts commit 5ad70e1.
- Revert "pass Common.display to compile.display (compile-solidity/new/index)"
  This reverts commit a9d7cd1.
- Revert "mv Profiler.updated & assoc helpers into (compile-common/utils)"
  This reverts commit 6a09f61.
- Undo misc changes to keep code WET
- Update yarn.lock & pkg deps
CruzMolina added a commit that referenced this pull request Feb 5, 2020
- Revert "Merge pull request #39 from CruzMolina/commonizeCompile"
  This reverts commit 32f3d18, reversing
changes made to 93bbf79.
- Revert "swap out Profiler.updated for Common.updatedFiles (core/lib/test)"
  This reverts commit c822135.
- Revert "swap out Profiler.updated for Commmon.updatedFiles (compile-solidity/new/index)"
  This reverts commit 5ad70e1.
- Revert "pass Common.display to compile.display (compile-solidity/new/index)"
  This reverts commit a9d7cd1.
- Revert "mv Profiler.updated & assoc helpers into (compile-common/utils)"
  This reverts commit 6a09f61.
- Undo misc changes to keep code WET
- Update yarn.lock & pkg deps
CruzMolina added a commit that referenced this pull request Feb 5, 2020
- Revert "Merge pull request #39 from CruzMolina/commonizeCompile"
  This reverts commit 32f3d18, reversing
changes made to 93bbf79.
- Revert "swap out Profiler.updated for Common.updatedFiles (core/lib/test)"
  This reverts commit c822135.
- Revert "swap out Profiler.updated for Commmon.updatedFiles (compile-solidity/new/index)"
  This reverts commit 5ad70e1.
- Revert "pass Common.display to compile.display (compile-solidity/new/index)"
  This reverts commit a9d7cd1.
- Revert "mv Profiler.updated & assoc helpers into (compile-common/utils)"
  This reverts commit 6a09f61.
- Undo misc changes to keep code WET
- Update yarn.lock & pkg deps
CruzMolina added a commit that referenced this pull request Feb 5, 2020
- Revert "Merge pull request #39 from CruzMolina/commonizeCompile"
  This reverts commit 32f3d18, reversing
changes made to 93bbf79.
- Revert "swap out Profiler.updated for Common.updatedFiles (core/lib/test)"
  This reverts commit c822135.
- Revert "swap out Profiler.updated for Commmon.updatedFiles (compile-solidity/new/index)"
  This reverts commit 5ad70e1.
- Revert "pass Common.display to compile.display (compile-solidity/new/index)"
  This reverts commit a9d7cd1.
- Revert "mv Profiler.updated & assoc helpers into (compile-common/utils)"
  This reverts commit 6a09f61.
- Undo misc changes to keep code WET
- Update yarn.lock & pkg deps
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants