I am using a simple contract
Contract code
contract Bank {
address public owner;
mapping(address => uint) private customerBalance;
event fallbackCalled(address, uint256);
event deposit(address, uint256);
constructor() public {
owner = msg.sender;
}
/** Customer Deposit payable function */
function depositFunds(uint _value) external payable returns(bool) {
require(_value > 0, "values not greater then zero");
customerBalance[msg.sender] += _value;
emit deposit(msg.sender, _value);
return true;
}
/** Fetch Customer Balance */
function getCustomerBalance() public view returns(uint) {
return customerBalance[msg.sender];
}
function () external payable {
emit fallbackCalled(msg.sender, msg.value);
}
}
Test case --->
describe('Customer should able to deposit funds', () => {
it('customer balance should be positive ', async () => {
// Deposite money into Bank from account[1] #2
let _value = 10;
const result = await deployedInstance.methods.depositFunds(_value).send({
from: accounts[1]
});
// Fetch the balance of account[1] and it should be equal to 1
let accountBalance = await deployedInstance.methods.getCustomerBalance().call({
from: accounts[1]
});
expect(accountBalance).toBe(_value);
})
})
Test case Result
expect(received).toBe(expected) // Object.is equality
Expected: 10
Received: "10"
**Difference:** Comparing two different types of values. Expected number but received string.
When I'm performing my unit testing that time, test case is failing caz customer balance value is coming as String from Contract call but I am supplying a number value from Testcase..
I have also check the offical documentation which also shows an exmple where they are fetching uint but getting string.
https://web3js.readthedocs.io/en/1.0/web3-eth-contract.html?#id18
Is there any specific reasons for returning strings.
Regards Dev