错误:返回的错误:处理事务时出现VM异常:只有还原所有者才能调用此函数



我正在尝试使用"松露试验";但它显示以下错误:

错误:返回的错误:处理事务时出现VM异常:只有所有者才能调用此函数--给出的原因:只有所有者可以调用此函数。

游戏.sol

pragma solidity ^0.5.0;
contract Gaming {
/* Our Online gaming contract */
address public owner;
bool public online;
struct Player {
uint wins;
uint losses;
}
mapping (address => Player) public players;
constructor() public payable {
owner = msg.sender;
online = true;
}
modifier isOwner() {
require(msg.sender == owner, "Only owner can call this function");
_;
}
}

TestGaming.sol

pragma solidity ^0.5.0;
import "truffle/Assert.sol";
import "truffle/DeployedAddresses.sol";
import "../contracts/Gaming.sol";
contract TestGaming {
uint public initialBalance = 10 ether;
Gaming gaming;
address owner;
function beforeAll() public {
gaming = Gaming(DeployedAddresses.Gaming());
owner = gaming.owner();
}
function testWithdrawFunds() public {
uint ownerBalanceBefore = owner.balance;
gaming.withdrawFunds();
uint ownerBalanceAfter = owner.balance;
Assert.equal (initialBalance, ownerBalanceAfter - ownerBalanceBefore, "The owner's balance should have increased by 10 ether");
}

错误

Error: Returned error: VM Exception while processing transaction: revert only owner can call this function - - Reason given: Only owner can call this function.

您可以使用其他帐户部署Contract,并使用其他帐户进行测试。。

请添加您的测试脚本

相关内容

最新更新