Lesson 7: Unit test of start Lottery get not-owner error #589
Replies: 2 comments 5 replies
-
In get_account(), I added a print of the account. |
Beta Was this translation helpful? Give feedback.
-
@weilainicolas As you posted is complaining about about trying to retrieve from account which is not the owner. The lottery address is not the same as the wallet address, because the contract gets its own when the contract is deployed. If you are actually referring why the account on the lottery is not the same as the new |
Beta Was this translation helpful? Give feedback.
-
I am testing it in local environment. This is my test code:
def test_can_enter():
# arrange
if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
pytest.skip()
lottery = deploy_lottery()
account = get_account()
lottery.startLottery({"from": account})
# act
lottery.enter({"from": account, "value": lottery.getEntranceFee()})
# assert
assert lottery.players(0) == account
I got the following error, when run brownie test
lottery.startLottery({"from": account})
E brownie.exceptions.VirtualMachineError: revert: Ownable: caller is not the owner
Trace step -1, program counter 1091:
E File "/home/nick/.brownie/packages/OpenZeppelin/[email protected]/contracts/access/Ownable.sol", line 43, in Lottery.startLottery:
E * @dev Throws if called by any account other than the owner.
E */
E modifier onlyOwner() {
E require(owner() == _msgSender(), "Ownable: caller is not the owner");
E _;
E }
Beta Was this translation helpful? Give feedback.
All reactions