rkalis / truffle-assertions

🛠 Assertions and utilities for testing Ethereum smart contracts with Truffle unit tests
https://kalis.me/check-events-solidity-smart-contract-test-truffle/
MIT License
154 stars 20 forks source link

truffle-assertions + truffle-hdwallet-provider + Test.sol > Error: the tx doesn't have the correct nonce #29

Closed SvenMeyer closed 5 years ago

SvenMeyer commented 5 years ago

I can not install in this order :

$ npm install truffle-hdwallet-provider@1.0.14
$ npm install npm install truffle-assertions

[https://github.com/rkalis/truffle-assertions/issues/28]

If I install it the other way round, the installation succeeds ... , but then I get strange errors concerning wrong 'nonce' in my JavaScript based contract test (test/gallery.js) once I add a solidity based test contract (test/TestGallery.sol) when using truffle-hdwallet-provider (tested 1.0.12 and 1.0.14).

Steps to reproduce:

$ truffle develop

Another terminal :

$ npm install npm install truffle-assertions
$ npm install truffle-hdwallet-provider@1.0.14
$ truffle test --network truffle_localhost_HDW

testing using web3.version = 1.0.0-beta.37

  TestGallery
    ✓ testAddRetrieve (127ms)

  Contract: Gallery
    ✓ deploys successfully
    1) ...should add an item and return an events with new number of items
    > No events were emitted
    2) ...should retrieve item
    > No events were emitted

  2 passing (6s)
  2 failing

  1) Contract: Gallery
       ...should add an item and return an events with new number of items:
     Error: the tx doesn't have the correct nonce. account has nonce of: 4 tx has nonce of: 20
      at /home/sum/DEV/test_HDWalletProvider_nonce/node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/cruzmolina/Code/truffle-projects/truffle/node_modules/web3-provider-engine/subproviders/provider.js:18:1
      at e.callback [as onreadystatechange] (node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/cruzmolina/Code/truffle-projects/truffle/node_modules/web3-providers-http/src/index.js:96:1)
      at e._a [as dispatchEvent] (node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/cruzmolina/Code/truffle-projects/truffle/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:27:61)
      at e.dispatchEvent [as _setReadyState] (node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/cruzmolina/Code/truffle-projects/truffle/node_modules/xhr2-cookies/dist/xml-http-request.js:208:1)
      at e._setReadyState [as _onHttpResponseEnd] (node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/cruzmolina/Code/truffle-projects/truffle/node_modules/xhr2-cookies/dist/xml-http-request.js:318:1)
      at IncomingMessage._onHttpResponseEnd (node_modules/truffle-hdwallet-provider/dist/webpack:/truffle-hdwallet-provider/Users/cruzmolina/Code/truffle-projects/truffle/node_modules/xhr2-cookies/dist/xml-http-request.js:289:47)
      at endReadableNT (_stream_readable.js:1129:12)
      at process._tickCallback (internal/process/next_tick.js:63:19)

  2) Contract: Gallery
       ...should retrieve item:

      Retrieved url should be identical to stored url.
      + expected - actual

      -https://random.dog/8b28a6b8-2711-47ef-b8b8-fd557464a1ed.jpg

      at Context.it (test/gallery.js:52:10)
      at process._tickCallback (internal/process/next_tick.js:68:7)

versions ¸¸¸ $ truffle version Truffle v5.0.27 (core: 5.0.27) Solidity v0.5.0 (solc-js) Node v10.16.0 Web3.js v1.0.0-beta.37 ¸¸¸

code repo https://github.com/SvenMeyer/test_HDWalletProvider_nonce

SvenMeyer commented 5 years ago

I found out the I accidentally deleted the build path config within truffle-config.js ... and after reinserting it, this effect is gone and it's working again ... strange,but resolved now.

module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // to customize your Truffle configuration!
  contracts_build_directory: path.join(__dirname, "client/src/contracts"),
networks: {...
   }
}