模拟智能合同坚固 - 可以部署模拟智能合约-TypeError:合同“ MockmyToken”应该标记为抽象

发布于 2025-01-21 01:54:00 字数 1247 浏览 2 评论 0原文

我编写了一个使用 openzepplin ERC20 标准的智能合约。我能够使用 truffle 部署它,并且我的测试按预期工作。我现在正在尝试测试依赖于时间的部分代码(block.number),目的是允许用户每 24 小时铸造一次。

为了模拟测试中的时间,我遵循此处概述的模式 https:// /dappsdev.org/hands-on/testing/solidity-mocks/

 contract myToken is ERC20 {
   // generic implementation of token here

   // mockContract is going to override this
  function getTime() internal virtual view returns (uint256) {
        return block.timestamp;
    }

}

contract mockMyToken is myToken {
    uint256 public fakeBlockTimeStamp;

    function getTime() internal override(myToken) view returns (uint256) {
        return fakeBlockTimeStamp;
    }

    function _mock_setBlockTimeStamp(uint256 value) public {
        fakeBlockTimeStamp = value;
    }
}

当我运行 truffle test 时,我收到 TypeError: Contract “mockMyToken” 应该标记为Abstract 但我想部署mockMyToken,因此通过添加 abstract 使其不可部署。这个错误对我来说没有任何意义,myToken 应该是抽象合约(我已经)也尝试过这个)。

我如何以与 https://dappsdev.org/hands-on/testing/solidity-mocks/ 他们不使用任何抽象关键字。

I wrote a smart contract that uses openzepplin ERC20 standard. I am able to deploy it using truffle and my tests work as expected. I am now trying to test part of the code that is dependent on time (block.number) For the purpose of allowing the user to mint once every 24 hours.

In order to mock the time in a test I am following this pattern outlined here https://dappsdev.org/hands-on/testing/solidity-mocks/

 contract myToken is ERC20 {
   // generic implementation of token here

   // mockContract is going to override this
  function getTime() internal virtual view returns (uint256) {
        return block.timestamp;
    }

}

contract mockMyToken is myToken {
    uint256 public fakeBlockTimeStamp;

    function getTime() internal override(myToken) view returns (uint256) {
        return fakeBlockTimeStamp;
    }

    function _mock_setBlockTimeStamp(uint256 value) public {
        fakeBlockTimeStamp = value;
    }
}

When I run truffle test I am getting TypeError: Contract “mockMyToken" should be marked as abstract but I want to deploy mockMyToken so by adding abstract to it makes it non deployable. This error does not make sense to me if anything, myToken should be the abstract contract (I've also tried this).

How can I mock the same way as https://dappsdev.org/hands-on/testing/solidity-mocks/
They do not use any abstract keyword.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文