0

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

2
  • What do you mean "the test passes"? There is no test here, just a function-call which may be a transaction or perhaps just an RPC (we don't know because you haven't posted the code of that function). Commented Apr 27, 2020 at 13:55
  • I have edited the question to include more code for clarity. Thanks Commented Apr 27, 2020 at 19:34

1 Answer 1

0

Ok. So the problem seems to be an incompatibility with the old way of doing things with web3js and the latest version of embark (5.2.3)...

The following works as expected:

await UTO.methods.setBeneficiary(owner).send({from: customer});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.