Has the library issue been resolved yet?
seongeunC opened this issue · 3 comments
seongeunC commented
Has the library issue in ftrace been fixed? I have the same issue. When library safemath is present in a contract,
"TypeError: Can not read property 'sub' of undefined"
GNSPS commented
Possibly not @seongeunC! Does that happen with any use of the SafeMath
library?
Is it with the using X for Y;
syntax?
seongeunC commented
Yes I am testing the functionality of ERC20 provided by openzeppelin. I am using SafeMath for uint256.
seongeunC commented
I think the information on my question was too weak. I add the contract feature that I was testing.
pragma solidity ^0.5.0;
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
assert(c / a == b);
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// assert(b > 0); // Solidity automatically throws when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
assert(b <= a);
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
assert(c >= a);
return c;
}
}
contract Test {
using SafeMath for uint256;
mapping(address => uint256) internal balances;
uint256 lockupcount = 123;
function balanceOf(address _holder) public view returns (uint256 balance) {
uint256 lockedBalance = 0;
lockedBalance = lockedBalance.add(lockupcount);
return balances[_holder] + lockedBalance;
}
}```
$ surya ftrace Test::balanceOf all test.sol
>else throw err
TypeError: Cannot read property 'add' of undefined