为什么人们在只返回'now‘的_now()函数中包装'now'?
发现在xDAI合同上:
function _now() internal view returns (uint256) {
return now;
}是因为在0.7.0中“now”被删除了,而且在一个地方对代码进行更改更容易吗?还是为了测试时间?或者调试或者是smth?
发布于 2020-10-20 14:06:25
因此,您可以在测试契约中重写它,并在测试脚本中轻松地模拟时间。
例如:
import "./xDAI.sol";
contract TestDAI is xDAI {
uint256 public time = 1;
function _now() internal view override returns (uint256) {
return time;
}
function setTime(uint256 _time) public {
time = _time;
}
}https://ethereum.stackexchange.com/questions/89529
复制相似问题