can someone explain me why can't i call Kill contract from Helper contract if i set modifier and constructor to owner == msg.sender
in Kill contract ? When i try to call from Helper its reverting and saying im not the owner even though i call from owner address. When i call directly from Kill contract with the same address it's perfectly fine.
Code below:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
contract Kill {
address public owner;
modifier onlyOwner() {
require(owner == msg.sender, "You are not the owner");
_;
}
constructor(address _owner) {
owner = _owner;
}
function kill() external onlyOwner {
selfdestruct(payable(msg.sender));
}
function testCall() external pure returns (uint) {
return 123;
}
function getBalance() public onlyOwner view returns (uint) {
return address(this).balance;
}
}
contract Helper {
address public owner;
mapping(address => Kill) public _counters;
function getBalance() public view returns (uint) {
return address(this).balance;
}
function kill() external {
Kill(_counters[msg.sender]).kill();
}
function newCampaign() public {
_counters[msg.sender] = new Kill(msg.sender);
}
}