In my solidity smartcontract, I have a function to return a uint value :

function getUserBalance(address userAddress, address tokenAddress)
        returns (uint256)
        return _stakingUserBalance[userAddress][tokenAddress].stakedAmount;

 I'm using chai for my test on js file, but it seems result is not a number :

let amountForSpenderBeforeWithdraw = await AlyraStackingInstance.getUserBalance(spender, DaiInstance.address);
... // some code
 let amountForSpenderAfterWithdraw = await AlyraStackingInstance.getUserBalance(spender, DaiInstance.address);   


When I launch my test with truffle test, my test return following error :

AssertionError: expected 9 to be a number or a date

When I replace with hard coded value, test is ok. When I write values in console, values are ok. Is it a cast problem ?

Thanks for your help

  • 2
    I'd recommend to use OpenZeppelin Test Helpers. It uses chai-bn for handling the BN returned by web3 in a more amenable way.
    – Ismael
    Commented Jan 19, 2022 at 21:38

1 Answer 1


Self answer :


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.