I don't know to describe my question. So I will try to explain it here. I'm working with truffle. I have a Contract A that deploys a Contract B. A passes it's address to B. B's owner is set to the address of A. Inside B there is a function foo() that requires the caller to be the owner.
My question is this: Can I call foo() from truffle like this ?
B.foo( {from: A.address} )
Or is it the case that the foo() function is now only callable through the contract itself, e.g. with an A's fooA() function that calls B.foo() ?
I provide an example code below.
contract B {
address private immutable ownerOfB;
modifier ownerOnly {
require (msg.sender == ownerOfB,
"ONLY OWNER(S) ALLOWED TO DO THAT.");
_;
}
constructor(address _owner) {
ownerOfB = _owner;
}
function fooB() ownerOnly public {
// do something
}
}
contract A {
address private immutable ownerOfA;
B b;
contructor() {
ownerOfA = msg.sender;
b = new B( address(this) );
}
function fooA() {
fooB()
}
}
Now if I use this code in truffle with the default account settings , A's owner will be accounts[0] and B's owner will be A.address. The function fooB() can be called through fooA() but cannot be called from truffle directly like this: B.foo( {from: A.address} );
even if we were to get an instance of the B contract in truffle with something like
aContr = await A.deployed();
bContr = await B.at( a.b() );
and then to call B.foo:
bContr.fooB( {from: aContr.address} ) --> throws Error "sender address not recognized"
Is this correct behaviour or is it relevant to truffle only?
PS. In my migration file I only deploy the A contract.