【发布时间】:2022-01-20 18:45:47
【问题描述】:
在继承自 OpenZeppelin 的 Ownable 和 AccessControl 的 Solidity 合约中,我有一个函数,合约所有者可以调用该函数来为帐户提供 ADMIN 角色。它看起来像这样:
function addAdmin(address account) public virtual onlyOwner {
_grantRole(ADMIN, account);
}
在我的测试文件中,我使用 OpenZeppelin 的 test-environment 和 test-helper 与 Mocha 和 Chai。我正在尝试测试从非所有者帐户调用addAdmin() 的失败。我的测试如下所示:
it('denies access to non-Owners to add a new ADMIN', async function() {
await expectRevert(
await pool.addAdmin(notlisted1, { from: notlisted2 }),
"Ownable: caller is not the owner"
);
});
似乎addAdmin() 正确还原,但测试失败。此测试失败时我在命令行看到的消息是:
Error: Returned error: VM Exception while processing transaction: revert Ownable: caller is not the owner -- Reason given: Ownable: caller is not the owner.
对这里发生的事情有什么想法吗?为什么expectRevert() 断言没有通过?
【问题讨论】:
标签: solidity truffle openzeppelin