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

Errors and failure when running --dry-run with truffle db enabled #3981

Closed haydenyoung closed 3 years ago

haydenyoung commented 3 years ago

Issue

When I issue the command truffle deploy --dry-run, the migration.sol contract deploys without issue but any subsequent contract fails with various error messages:

TypeError: Cannot read property 'contract' of undefined

GraphQLError: Syntax Error: Invalid number, expected digit but got: "f".

When skipping dry run, the contracts are deployed successfully.

Steps to Reproduce

Create a new project:

mkdir MetaCoin
cd MetaCoin
truffle unbox MetaCoin
truffle init

Configure Kovan testnet and enable Truffle db in truffle-config.js.

Enable testnet:

kovan: {
    provider: new HDWalletProvider(
        PRIVATE_KEY,
        KOVAN_URL
    ),
    network_id: "42",
    confirmations: 4,
    timeoutBlocks: 10,
    gasPrice: 10000000000,
    networkCheckTimeout: 10000
}

Enable truffle db:

db: {
    enabled: true
}

Run:

truffle deploy --network kovan --reset --dry-run

The above will fail after the migrations deployment (it is also noticeably slow).

Expected Behavior

Dry run reports gas costs and completes without error.

Actual Results

Possible errors:

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.

Migrations dry-run (simulation)
===============================
> Network name:    'kovan-fork'
> Network id:      42
> Block gas limit: 12500000 (0xbebc20)

1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
   > block number:        24325108
   > block timestamp:     1618811305
   > account:             0x119eC8C4200dFafB4E40e73f976b8C874BFf9752
   > balance:             10.20014689606288811
   > gas used:            149175 (0x246b7)
   > gas price:           10 gwei
   > value sent:          0 ETH
   > total cost:          0.00149175 ETH

   -------------------------------------
   > Total cost:          0.00149175 ETH

TypeError: Cannot read property 'contract' of undefined
    at extract (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/src/project/loadMigrate/contracts.ts:42:40)
    at Object.process (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/src/meta/batch.ts:68:31)
    at Generator.next (<anonymous>)
    at process (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/src/project/loadMigrate/index.ts:51:45)
    at process.next (<anonymous>)
    at /home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/src/meta/process/run.ts:73:22
    at Generator.next (<anonymous>)
    at /home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/dist/src/meta/process/run.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/dist/src/meta/process/run.js:4:12)
    at run (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/src/meta/process/run.ts:71:5)
    at ConnectedProject.run [as _run] (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/src/meta/process/run.ts:56:38)
    at ConnectedProject.<anonymous> (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/src/project/index.ts:188:17)
    at Generator.next (<anonymous>)
    at /home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/dist/src/project/index.js:27:71
    at new Promise (<anonymous>)
    at __awaiter (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/dist/src/project/index.js:23:12)
    at ConnectedProject.run (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/dist/src/project/index.js:191:16)
    at ConnectedProject.<anonymous> (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/src/project/index.ts:276:38)
    at Generator.next (<anonymous>)
    at fulfilled (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/dist/src/project/index.js:24:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Truffle v5.3.1 (core: 5.3.1)
Node v12.19.0
Migrations dry-run (simulation)
===============================
> Network name:    'kovan-fork'
> Network id:      42
> Block gas limit: 12499988 (0xbebc14)

1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
   > block number:        24324081
   > block timestamp:     1618805812
   > account:             0x119eC8C4200dFafB4E40e73f976b8C874BFf9752
   > balance:             10.19986717606288811
   > gas used:            177147 (0x2b3fb)
   > gas price:           10 gwei
   > value sent:          0 ETH
   > total cost:          0.00177147 ETH

   -------------------------------------
   > Total cost:          0.00177147 ETH

GraphQLError: Syntax Error: Invalid number, expected digit but got: "f".
    at syntaxError (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/graphql/error/syntaxError.js:15:10)
    at readDigits (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/graphql/language/lexer.js:484:38)
    at readNumber (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/graphql/language/lexer.js:431:16)
    at readToken (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/graphql/language/lexer.js:249:16)
    at Lexer.lookahead (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/graphql/language/lexer.js:75:108)
    at Lexer.advance (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/graphql/language/lexer.js:58:35)
    at Parser.expectToken (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/graphql/language/parser.js:1408:19)
    at Parser.parseName (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/graphql/language/parser.js:98:22)
    at Parser.parseFragmentName (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/graphql/language/parser.js:430:17)
    at Parser.parseFragmentDefinition (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/graphql/language/parser.js:413:18)
    at Parser.parseDefinition (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/graphql/language/parser.js:140:23)
    at Parser.many (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/graphql/language/parser.js:1523:26)
    at Parser.parseDocument (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/graphql/language/parser.js:115:25)
    at Object.parse (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/graphql/language/parser.js:31:17)
    at parse (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/graphql-tag/src/index.ts:96:20)
    at Object.gql [as default] (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/graphql-tag/src/index.ts:133:10)
    at process (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/src/project/assignNames/getCurrent.ts:42:12)
    at process.next (<anonymous>)
    at /home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/src/meta/batch.ts:76:28
    at Generator.next (<anonymous>)
    at Object.process (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/src/project/assignNames/batch.ts:80:30)
    at Generator.next (<anonymous>)
    at process (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/src/project/assignNames/index.ts:62:52)
    at process.next (<anonymous>)
    at /home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/src/meta/process/run.ts:83:24
    at Generator.next (<anonymous>)
    at fulfilled (/home/User/.nvm/versions/node/v12.19.0/lib/node_modules/truffle/node_modules/@truffle/db/dist/src/meta/process/run.js:5:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
Truffle v5.3.1 (core: 5.3.1)
Node v12.19.0

Environment

Distributor ID: Pop Description: Pop!_OS 20.10 Release: 20.10 Codename: groovy

Truffle v5.3.1 (core: 5.3.1) Solidity - 0.6.6 (solc-js) Node v12.19.0 Web3.js v1.3.5

nvm v12.19.0 npm 7.7.6

gnidan commented 3 years ago

Hey can you rerun your migrate command to pass the DEBUG=db:meta:interface environment variable? Something like DEBUG=db:meta:interface truffle migrate --dry-run. You should see more details about that GraphQL error; that'd be super helpful for us to diagnose the problem here.

Sorry about this!

haydenyoung commented 3 years ago

Thanks @gnidan and apologies for the late reply.

I ran:

DEBUG=db:meta:interface truffle deploy --network kovan --reset --dry-run

but the only difference I see is:

Secp256k1 bindings are not compiled. Pure JS implementation will be used.
Keccak bindings are not compiled. Pure JS implementation will be used.
Keccak bindings are not compiled. Pure JS implementation will be used.
Keccak bindings are not compiled. Pure JS implementation will be used.
Keccak bindings are not compiled. Pure JS implementation will be used.
Keccak bindings are not compiled. Pure JS implementation will be used.
Keccak bindings are not compiled. Pure JS implementation will be used.
Keccak bindings are not compiled. Pure JS implementation will be used.
Keccak bindings are not compiled. Pure JS implementation will be used.
Keccak bindings are not compiled. Pure JS implementation will be used.
Keccak bindings are not compiled. Pure JS implementation will be used.
Keccak bindings are not compiled. Pure JS implementation will be used.
Keccak bindings are not compiled. Pure JS implementation will be used.
Keccak bindings are not compiled. Pure JS implementation will be used.

Otherwise, the output is identical.

cds-amal commented 3 years ago

Thanks @haydenyoung! Super helpful, we'll look into it

haydenyoung commented 3 years ago

Thanks @cds-amal please let me know if you waant me to test anything else.

Slight correction on my post above:

db: {
    enabled: false
}

should be:

db: {
    enabled: true
}

Disabling the local db seems to fix the issue.

eggplantzzz commented 3 years ago

I just reproduced this here locally and will investigate. Thanks for the report @haydenyoung!

eggplantzzz commented 3 years ago

There is a fix for this problem (or at least part of it) in https://github.com/trufflesuite/truffle/pull/4198. I was only able to duplicate the "Cannot read property..." error once.

gnidan commented 3 years ago

The fix for this is now released in Truffle v5.4.2 (see release notes). Thank you for trying out @truffle/db and letting us know about this problem!