trufflesuite / truffle

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
14.02k stars 2.31k forks source link

truffle test fails if migration used Truffle Artifactor #2174

Closed rstormsf closed 5 years ago

rstormsf commented 5 years ago

Issue

Steps to Reproduce

rm -rf build
npx truffle compile
npx truffle test

Create migration script in special way: https://github.com/peppersec/truffle_bug/blob/master/migrations/2_deploy.js#L14

Expected Behavior

should be working

Actual Results

Errors out on the first run

Environment

Please check out the full repo https://github.com/peppersec/truffle_bug truffle

CruzMolina commented 5 years ago

Hey @rstormsf ! As an aside, you probably want to change unlinked_binary to bytecode in 2_deploy.js. Looks like it's been deprecated in the contract json spec.

gnidan commented 5 years ago

Ugh unlinked_binary is a mess. It should be working, though. Maybe something is up with the deprecation mechanisms in contract-schema.

CruzMolina commented 5 years ago

@rstormsf , looked into your issue a bit. it looks like the way migrations are currently rigged, the resolver expects to be passed artifacts (via artifact.require's) before the deployer module.exports. I'm not familiar with circom, but you might be able to hook it up to truffle as an external compiler rather than running a script in-between normal compilation and testing (npx truffle compile && node makeMiMC.js && npx truffle test...)

rstormsf commented 5 years ago

@CruzMolina I wish it could be possible: https://github.com/iden3/circomlib/blob/master/src/mimc_gencontract.js take a look at it ;-)

fainashalts commented 5 years ago

Hey @rstormsf are you still having trouble with this? It looks like Artifactor is working as expected, and you'd need to set up a separate script as @CruzMolina mentioned before you can migrate this way. We're going to go ahead and close this issue. Please bring this up in the Truffle Spectrum if you'd like to discuss it further!

HarryR commented 5 years ago

I encountered this problem too.

Running the code which uses truffle-artifactor into a separate stage between truffle compile and truffle test seems to have avoided the problem of having to run truffle test multiple times.

However, I still run into the blank 'Error: Error: Error' message whenever I try and use any of those contracts, that's really frustrating because getting any meaningful stack trace or debug information from Truffle seems to be harder than extracting blood from a stone.

CruzMolina commented 5 years ago

@HarryR are you trying to do something similar as rstormf?

If you're trying to migrate than I believe you will have to "make" the contract artifact and import into the migrations scripts.

HarryR commented 5 years ago

I'm doing something very similar to @rstormsf - generating EVM bytecode with a different method, then using it linked from Solidity code.

The fix described above has fixed half the problem - I have a separate script 'generate-artifacts.js' which is run in between compile and test, then i can import the artifacts normally using artifact.require(...) so truffle-artifactor isn't used at any point in the migration .js scripts.

However, whenever I include the library Name { ... } code in a Solidity I get the blank Error: Error: Error message, before it's even run any of the migrations code. That seems unrelated to the bug described in this ticket (or.. maybe it is tangentially related?)

I can deploy the contract, run it via JS tests etc. But whenever I try to use it from Solidity code (either directly in contracts, or via tests) truffle will error out with the blank message before running migrations.

I'll open a ticket if I can't find a workaround.

CruzMolina commented 5 years ago

@HarryR can you provide a reproduction repo for your Library error?

Thinking about this some more, there might be a way to use the external compiler feature to get the circom compiler lib to work. Are you using this lib?

HarryR commented 5 years ago

Hi.

I'm not using circom.

My problem has nothing to do with artifactor.

I am working around it in a different way.