我正在尝试在: test#2执行混合测试Remix示例contract#2,但是我得到了错误:
tests/senderTest_test.sol:33:22: DeclarationError: Undeclared identifier.
Assert.equal(getOwner(), acc0, 'owner should be acc0');
^------^发件人合同是:
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');
}
}谁来指点我。
祖尔菲。
发布于 2021-12-28 05:18:31
问题在于getOwner()。它是契约发送方的函数,但是您尝试在testSuite中使用它。testSuite不知道getOwner()是什么以及它从哪里来。在正确使用它作为obj.getOwner()之前,我在行中看到了这一点。obj是sender类型的,因此知道如何使用getOwner()。
https://ethereum.stackexchange.com/questions/117449
复制相似问题