I wrote a smart contract that uses openzepplin ERC20 standard. I am able to deploy it using truffle and my tests work as expected. I am now trying to test part of the code that is dependent on time (block.number
) For the purpose of allowing the user to mint once every 24 hours.
In order to mock the time in a test I am following this pattern outlined here https://dappsdev.org/hands-on/testing/solidity-mocks/
contract myToken is ERC20 {
// generic implementation of token here
// mockContract is going to override this
function getTime() internal virtual view returns (uint256) {
return block.timestamp;
}
}
contract mockMyToken is myToken {
uint256 public fakeBlockTimeStamp;
function getTime() internal override(myToken) view returns (uint256) {
return fakeBlockTimeStamp;
}
function _mock_setBlockTimeStamp(uint256 value) public {
fakeBlockTimeStamp = value;
}
}
When I run truffle test
I am getting TypeError: Contract “mockMyToken" should be marked as abstract
but I want to deploy mockMyToken so by adding abstract
to it makes it non deployable. This error does not make sense to me if anything, myToken should be the abstract contract (I've also tried this).
How can I mock the same way as https://dappsdev.org/hands-on/testing/solidity-mocks/ They do not use any abstract keyword.