question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Differing Results with `truffle test` and `truffle test ./test/...`

See original GitHub issue
  • I’ve asked for help in the Truffle Gitter before filing this issue.

Issue

When calling truffle test, I am getting different results to truffle test ./test/... on a specific file. The test in question is here, and I am doing the setup in a separate file:

The failure I am receiving on the truffle test run mentions shouldFailWithMessage (node_modules/openzeppelin-test-helpers/src/shouldFail.js:14:10) in the before all hook. Which is not being called in this file. I have a feeling that there may be some kind of leak from a previous test that is causing this.

Steps to Reproduce

git clone https://github.com/partial-f/core.git
git checkout develop
npm install
truffle test 
truffle test ./test/ProductTeller.test.js

Expected Behavior

Expected the same results for the contract, regardless if called in isolation or with all of the tests.

Actual Results

truffle test

  6) Contract: ProductTeller
       "before all" hook: prepare suite:
     Uncaught AssertionError: Expected failure not received
      at shouldFailWithMessage (node_modules/openzeppelin-test-helpers/src/shouldFail.js:14:10)
      at process._tickCallback (internal/process/next_tick.js:68:7)

  7) Contract: ProductTeller
       "before each" hook: before test for "should allow an admin to set a product fee":
     TypeError: Cannot read property 'call' of undefined


  8) Contract: ProductTeller
       "after each" hook: after test for "should allow an admin to set a product fee":
     TypeError: Cannot read property 'call' of undefined

truffle test ./test/ProductTeller.test.js

Contract: ProductTeller
...
  12 passing (25s)
  1 pending
  1 failing
...

Environment

  • Operating System: 10.14
  • Truffle version (truffle version): v5.0.5
  • node version (node --version): v10.14.2
  • npm version (npm --version): 6.4.1
  • ganache-cli: Ganache CLI v6.3.0 (ganache-core: 2.4.0)

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:21 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kseniya292commented, Mar 28, 2019

@CruzMolina All the tests are finally passing! 🎉 I removed the chai.assert declaration, and removed bn-chai and refactored my tests to use should.equal rather than should.eq.BN. Thanks again for your help!

1reaction
CruzMolinacommented, Mar 22, 2019

Ah, okay. Looks like you are in the process of updating from truffle 4 to truffle 5.

I’ve invited you to a private repo w/ a branch I worked on real quick to help you along (would have just pushed my local branch but I don’t think I have proper permissions from your repo). It turns out (at least in v5), we already expose chai.assert internally for running js tests, so declaring const assert = chai.assert was causing what appears to be an overloading error. Can simply start using assert() w/o needing to require the lib.

The other issue I noticed is you’re using bn-chai, which (for whatever reason) wasn’t written to support should(). There appears to also be an overloading error happening there as well between chai and bn-chai.

For replacing the test comparisons, I pushed an example suggestion to get you guys started.

Currently only 34 tests fail on my end, yay! 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test your contracts - Truffle Suite
Truffle comes standard with an automated testing framework to make ... This framework lets you write simple and manageable tests in two different...
Read more >
Writing test in solidity - DApp develop framework | PlatON
Solidity test contracts live alongside Javascript tests as .sol files. When platon-truffle test is run, they will be included as a separate test...
Read more >
truffle - should I remember the results of previous calls?
Truffle tests are based on mocha framework so you can use similar approach. Create multiple contract sections for the same contract.
Read more >
truffle test guide - Rafaela Azevedo
Posts about truffle test guide written by Rafaela Azevedo.
Read more >
Testing smart contracts using Truffle - RSK Developers Portal
The truffle test command performs tests on all files found in the test directory. Now we have 2 files with tests. To run...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found