首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Remix的文档测试test#2失败

Remix的文档测试test#2失败
EN

Ethereum用户
提问于 2021-12-30 03:39:54
回答 1查看 58关注 0票数 0

为什么混音的test#2文件失败了?嗨,我是跟随混音的例子测试,可在:https://remix-ide.readthedocs.io/en/latest/unittesting_examples.html。发送者代码是:

代码语言:javascript
运行
复制
pragma solidity ^0.5.3;
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;
    }
}

// testfile是:

代码语言:javascript
运行
复制
pragma solidity 0.5.3;

// 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 is sender{
        //sender obj;
        address acc0;
        address acc1;
        address acc2;
        function beforeAll() public {
            acc0 = TestsAccounts.getAccount(0); 
            acc1 = TestsAccounts.getAccount(1);
            acc2 = TestsAccounts.getAccount(2);
        }
        function testInitialOwner() public {
           Assert.equal(getOwner(), acc0, 'owner should be acc0');
        }
        function updateOwnerOnce() public {
            // check method caller is as expected
            Assert.ok(msg.sender == acc0, 'caller should be default account i.e. acc0');
            // update owner address to acc1
           updateOwner(acc1);
            // check if owner is set to expected account
           Assert.equal(getOwner(), acc1, 'owner should be updated to acc1');
        }
        function updateOwnerOnceAgain() public {
            // check if caller is custom and is as expected
            Assert.ok(msg.sender == acc1, 'caller should be custom account i.e. acc1');//This is failing
        }
    }

我得到的输出如下:

代码语言:javascript
运行
复制
testSuite (tests/sender_test.sol)
✓ Test initial owner
✓ Update owner once
✘ Update owner once again
Error Message:
"caller should be custom account i.e. acc1"
Assertion:
Expected value should be
'true'
Received value:
false
Skipping the remaining tests of the function.
Result for tests/sender_test.sol
Passing: 2
Failing: 1
Total time: 0.30s

我还附上了这张照片:

谁来指点我,有什么问题吗?

祖尔菲。

EN

回答 1

Ethereum用户

回答已采纳

发布于 2022-01-07 05:02:43

注释说,我们必须使用与account0无关的自定义,而必须使用account1。

实现这一目标的途径是:

/#发件人:帐户-1

因此,我们将使用前面的声明:

代码语言:javascript
运行
复制
updateOwnerOnceAgain()

祖尔菲。

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

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

复制
相关文章

相似问题

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