Arpit Bajpai
Arpit Bajpai

Reputation: 198

Assertion error in Mocha while testing the smart contract

I am testing my Ethereum smart contract and getting an assertion error as one of the test case is failing.

Contract: Market
✓ contract is deployed

  1 passing (142ms)
  1 failing

  1) Contract: Market
   offer added:
   AssertionError: Unspecified AssertionError

Here is code:

contract('Market', ()=>{
it('contract is deployed',async ()=>{
    const market = await Market.deployed();
    assert(market.address!='');
    })
it('offer added', async () =>{
    const market = await Market.deployed();    
    let oldVal = await market.numOffers();
    market.supplyRequest(1,10,1);
    let newVal = await market.numOffers();
    console.log("new value is "+newVal); //this prints 1 on console
    console.log("old value is "+oldVal); // this print 0 on console
    assert(oldVal+1==newVal);
 });
});

I am not sure why the test case is failing even when the values are equal.

Upvotes: 1

Views: 385

Answers (1)

Vrecer
Vrecer

Reputation: 405

Your numOffers is probably returning a string and not a number, that is why the +1 in the assert changes the value from '1' to '11' and the assertion fails.

Upvotes: 1

Related Questions