I geting VM exception calling this function. Someone could give me a hint?
solidity ^0.8.7;
function ownerCheckReward(address _address) view external returns(uint){
uint _moment = moment[_address];
uint _allowance = allowance[_address];
uint _timestamp = block.timestamp;
uint mul = _moment * _allowance;
uint result = _timestamp - mul;
return result;
}
Var declaration:
mapping(address => uint) allowance;
mapping(address => uint) moment;
Test script
const PayRole = artifacts.require("Payrole")
const Token = artifacts.require("Token")
contract("PayRole", (accounts) => {
it("Should allow the owner to add a new dev.", async () => {
const _payrole = await PayRole.deployed();
await _payrole.addDev.sendTransaction(accounts[2], 10000);
const result = await _payrole.getStatus.call(accounts[2])
assert.equal(result, true, "The dev address wasn't allowed")
})
it("Should allow anyone to send the specific token to the contract.", async () => {
const _token = await Token.deployed()
await _token.transfer('0x893BFba8e5d9Cbd998b248a39a4905E7DBD100FC', 10000, {from: accounts[0]})
const balance = await _token.balanceOf.call('0x893BFba8e5d9Cbd998b248a39a4905E7DBD100FC')
assert(balance.toNumber() >= 10000, 'Tokens not sent.')
})
it("Should allow owner to change allowance", async () => {
const _payrole = await PayRole.deployed()
const allowance = await _payrole.setAllowance.sendTransaction(accounts[2], 100000);
assert(allowance, "Allowance wasn't changed")
})
it("Should return the numbers of tokens to be allowed every millisecond", async () => {
const _payrole = await PayRole.deployed()
const account = accounts[2]
const result = await _payrole.ownerCheckReward.call(account)
assert(result, "The function remain bugged")
})
})
Test result
Test result
Contract: PayRole
√ Should allow the owner to add a new dev. (813ms)
√ Should allow anyone to send the specific token to the contract. (824ms)
√ Should allow owner to change allowance (712ms)
1) Should return the numbers of tokens to be allowed every millisecond
> No events were emitted
3 passing (4s)
1 failing
1) Contract: PayRole
Should return the numbers of tokens to be allowed every millisecond:
Error: Returned error: VM Exception while processing transaction: revert
at Context.<anonymous> (test\payroles.js:25:56)
at processTicksAndRejections (node:internal/process/task_queues:96:5)