TypeError: Member "owner" not found or not visible after argument-dependent lookup in contract Gaming

Viewed 64

I'm trying to test this contract using "truffle test" but it shows the following error: "TypeError: Member "owner" not found or not visible after argument-dependent lookup in contract Gaming" owner = gaming.owner();

Gaming.sol

pragma solidity ^0.5.0;

contract Gaming {
    /* Our Online gaming contract */
    address owner;
    bool public online;

    struct Player {
        uint wins;
        uint losses;
    }

    mapping (address => Player) public players;

    constructor() public payable {
        owner = msg.sender;
        online = true;
    }

    modifier isOwner() {
        require(msg.sender == owner, "Only owner can call this function");
        _;
    }

}

TestGaming.sol

pragma solidity ^0.5.0;

import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/Gaming.sol";

contract TestGaming {
    uint public initialBalance = 10 ether;
    Gaming gaming;
    address owner;

    function beforeAll() public {
        gaming = Gaming(DeployedAddresses.Gaming());
        owner = gaming.owner();

    }

    function testWithdrawFunds() public {
        uint ownerBalanceBefore = owner.balance;
        gaming.withdrawFunds();
        uint ownerBalanceAfter = owner.balance;

        Assert.equal (initialBalance, ownerBalanceAfter - ownerBalanceBefore, "The owner's balance should have increased by 10 ether");
}
1 Answers

In solidity default visibility is internal. for this code

address owner;

its visibility is internal. Solidity assigns getters for public variables.

address public owner;

You can easily test on remix:

contract Test {        
    uint public firstVar=10;
    uint secondVar=50;
  }

If you deploy this on remix, you will see getter for firstVar but not for secondVar

Or you could write a getter function for the owner:

 function returnOwner() public view returns (address){
        return owner
    }
Related