首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我如何正确地断言这一点?

我如何正确地断言这一点?
EN

Ethereum用户
提问于 2022-01-18 13:58:51
回答 1查看 16关注 0票数 0

假设我想为这份合同样本做一个测试:

代码语言:javascript
复制
// assume we import OpenZeppelin's Ownable

contract Metaverse extends Ownable, ... {
    ...
    // Assume this is just to experiment and learn.
    // Then I can question myself how useful is to
    // actually do this, and why.
    function renounceOwnership() public override onlyOwner {
        revert("I explicitly disabled this method");
    }
    ...
}

而且,使用块菌石,我希望对该方法何时恢复进行测试:

代码语言:javascript
复制
const Metaverse = artifacts.require("Metaverse");

contract("Metaverse", function (accounts) {
  const deployer = accounts[0];
  const newOwner = accounts[1];

  it("respects the safe-ownership appropriately", async function () {
    let metaverse = await Metaverse.deployed();

    try
    {
      metaverse.renounceOwnership({from: deployer});
      assert.fail("Ownership should not be rejected");
    }
    catch(e) { /* Ok :) - It will be an AssertionError */ }
  });
});

到目前为止,这是可行的,但我想让它变得更干净。所以我把我的问题分成两部分:

  1. 当方法恢复时,是否有一个标准的、更干净的/更好的方法来断言?
  2. 如果没有:我如何测试e是AssertionError类型的?从哪里导入断言错误?
EN

回答 1

Ethereum用户

发布于 2022-01-18 14:16:10

页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/119243

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档