Why the remix’s documented test#2 fails?
Hi,
I am following the remix’s example test available at:
The sender code is:
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;
}
}
//The testfile is:
pragma solidity 0.5.3;
// This import is automatically injected by Remix
import "remix_tests.sol";
import "tests/sender.sol";
import "remix_accounts.sol";
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
}
}
I am getting following output:
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
Somebody please guide me.
Zulfi.