1

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

function getUserBalance(address userAddress, address tokenAddress)
        public
        view
        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);   

expect(amountForSpenderBeforeWithdraw).to.be.greaterThan(amountForSpenderAfterWithdraw);

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

1
  • 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
    Jan 19 at 21:38

1 Answer 1

2

Self answer :

expect(parseInt(amountForSpenderBeforeWithdraw)).to.be.greaterThan(parseInt(amountForSpenderAfterWithdraw));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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