In my embark tests, I have the following tests:
it("should allow setting new beneficiary by owner to valid address", async function () {
//await UTO.setBeneficiary(0x0, {from: owner}).should.be.rejectedWith(EVMInvalid);
await UTO.setBeneficiary(owner, {from: customer});
(await UTO.beneficiary()).should.deep.equal(owner);
});
'customer' maps to a valid address. The contract is:
pragma solidity >=0.6.0 <0.7.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Pausable.sol";
contract UTO is ERC20, Ownable, Pausable {
string private _name = "UnlimitedToken";
string private _symbol = "UTO";
uint256 public tokensPerEth; //Number of tokens per ETH
uint256 public tokenValue; //Value of 1 Token (in ETH)
uint256 public percentForBeneficiary; //Percentage of tokens generated to be assigned to beneficiary
address public beneficiary; //The address of the beneficiary of the held tokens
constructor(address _beneficiary, uint256 _tokensPerEth, uint256 _percentForBeneficiary) ERC20(_name, _symbol) public {
tokensPerEth = _tokensPerEth;
tokenValue = 1 wei; //initial value, dynamic once contract is deployed
beneficiary = _beneficiary;
percentForBeneficiary = _percentForBeneficiary;
}
/**
* @dev Allows the current owner to change the beneficiary.
* @param newBeneficiary The address of the new beneficiary.
*/
function setBeneficiary(address newBeneficiary) public onlyOwner {
require(newBeneficiary != address(0), "Invalid address for beneficiary");
beneficiary = newBeneficiary;
}
}
So the function call to setBeneficiary should only be allowed to be called by the owner of the contraact. However, the from address is ignored and the test passes. I have replaced the from address with invalid data as well with the same result. So, it seems that setting {from: 0xaddress} is ignored.. any idea?
Thanks