I am trying to call a function in another contract, that is protected with an openzepellin Role library
.
I am calling availableFunction
on the javascript side, which in turn calls protectedFunction
. Even though I pass the adminRole
address to the constructor of contract B
, and then call availableFunction
with adminRole
, the function reverts.
In A.sol
contract interfaceB {
function protectedFunc() public;
}
contract A {
B b;
constructor(address _B) {
b = new interfaceB(_B);
}
function availableFunction() {
b.protectedFunc();
}
}
In B.sol
contract B {
using Roles for Roles.Role;
Roles.Role private adminRole;
constructor(address _adminRole) public {
adminRole.add(_adminRole);
}
function protectedFunc() public {
require(adminRole.has(msg.sender), "DOES_NOT_HAVE_ADMIN_ROLE");
...
}
}
In A.test.js
const A = artifacts.require("A");
const B = artifacts.require("B");
contract("A", function ([_, adminRole]) {
beforeEach(async function () {
b = B.new(adminRole);
a = A.new(b.address);
}
describe("availableFunc", function () {
it("should pass!", async function () {
a.availableFunc({from: adminRole)}); // REVERTS!
})
}
})
Error: Returned error: VM Exception while processing transaction: revert DOES_NOT_HAVE_ADMIN_ROLE