Hey, I've written a solidity function that stakes coin after 1 minute of previous staking on user input. the code goes like this...
uint public pastStakeTime = block.timestamp;
function stakeToken(uint _amount, address _staker) external payable {
require(block.timestamp - pastStakeTime > 1 minutes, "please wait for 1 minutes");
//as a record that this stakeholder staked this amount
stakeholderBalance[_staker] += _amount;
//all the amounts must have the authority of admin
entityBalances[admin_HolderOfTokens] += _amount;
//pushing the stakeholder in our stake holder address
stakeHolder.push(_staker);
pastStakeTime = block.timestamp;
}
Now, I want to test it, and I used openzeppelin test helpers to manipulate the time.
const { time } = require('@openzeppelin/test-helpers');
it('it stakes the tokens after one minutes of previous staking', async () => {
await time.increaseTo(time.duration.minutes(2));
const stakeAmount = 500;
await token.stakeToken(stakeAmount, stakeHolder.address);
expect(await token.getStakeHolderBalance(stakeHolder.address)).to.equal(500);
});
but, await time.increaseTo(time.duration.minutes(2));
is not working and I'm not able to execute the function.
I've also tried await time.increase(time.duration.minutes(2));
but getting the json rpc error. Anyone please help.