首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >测试Remix example2合同

测试Remix example2合同
EN

Ethereum用户
提问于 2021-12-28 04:12:03
回答 1查看 43关注 0票数 0

我正在尝试在: test#2执行混合测试Remix示例contract#2,但是我得到了错误:

代码语言:javascript
复制
tests/senderTest_test.sol:33:22: DeclarationError: Undeclared identifier.
Assert.equal(getOwner(), acc0, 'owner should be acc0');
^------^

发件人合同是:

代码语言:javascript
复制
pragma solidity >=0.4.22 <0.7.0;
contract sender {
    address private owner;
    
    constructor() public {
        owner = msg.sender;
    }
    
    function updateOwner(address newOwner) public {
        require(msg.sender == owner, "only current owner can update owner");
        owner = newOwner;
    }
    
    function getOwner() public view returns (address) {
        return owner;
    }
}
//and the tester contract is:
pragma solidity >=0.4.22 <0.9.0;

// This import is automatically injected by Remix
import "remix_tests.sol"; 
import "tests/sender.sol";

import "remix_accounts.sol";

// File name has to end with '_test.sol', this file can contain more than one testSuite contracts
contract testSuite {
    //sender obj;
    address acc0;
    address acc1;
    address acc2;
    /// 'beforeAll' runs before all other tests
    /// More special functions are: 'beforeEach', 'beforeAll', 'afterEach' & 'afterAll'
    function beforeAll() public {
        // <instantiate contract>
        //Assert.equal(uint(1), uint(1), "1 should be equal to 1");
        acc0 = TestsAccounts.getAccount(0); 
        acc1 = TestsAccounts.getAccount(1);
        acc2 = TestsAccounts.getAccount(2);
        //obj = new sender();
    }
    function testInitialOwner() public {
        // account at zero index (account-0) is default account, so current owner should be acc0
        //Assert.equal(obj.getOwner(), acc0, 'owner should be acc0');
         Assert.equal(getOwner(), acc0, 'owner should be acc0');
    }
}

谁来指点我。

祖尔菲。

EN

回答 1

Ethereum用户

回答已采纳

发布于 2021-12-28 05:18:31

问题在于getOwner()。它是契约发送方的函数,但是您尝试在testSuite中使用它。testSuite不知道getOwner()是什么以及它从哪里来。在正确使用它作为obj.getOwner()之前,我在行中看到了这一点。objsender类型的,因此知道如何使用getOwner()

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

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

复制
相关文章

相似问题

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