简体   繁体   English

错误:返回错误:处理事务时 VM 异常:还原只有所有者可以调用此 function

[英]Error: Returned error: VM Exception while processing transaction: revert only owner can call this function

I'm trying to test this contract using "truffle test" but it show the following error:我正在尝试使用“松露测试”来测试这个合同,但它显示以下错误:

Error: Returned error: VM Exception while processing transaction: revert only owner can call this function - - Reason given: Only owner can call this function.错误:返回错误:处理事务时 VM 异常:还原只有所有者可以调用此 function - - 给出的原因:只有所有者可以调用此 function。

Gaming.sol游戏.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测试游戏.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错误

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

You may deployed the Contract with other account and test it with another accounts..您可以使用其他帐户部署合同并使用其他帐户进行测试。

please do add your test script请添加您的测试脚本

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 返回错误:VM Exception while processing transaction: revert only owner can call this function - Returned error: VM Exception while processing transaction: revert only owner can call this function Chainlink 返回错误:处理事务时出现 VM 异常:还原 - Chainlink Returned error: VM Exception while processing transaction: revert 错误:返回错误:处理事务时出现 VM 异常:使用 New 创建时恢复 - Error: Returned error: VM Exception while processing transaction: revert when creating with New 松露错误:错误:处理事务时VM异常:恢复 - Truffle error: Error: VM Exception while processing transaction: revert 错误:返回错误:处理事务时出现 VM 异常:气体不足 - Error: Returned error: VM Exception while processing transaction: out of gas 处理事务时出现 VM 异常:还原 - VM Exception while processing transaction: revert Openzepplin众包合同获得:处理事务时VM异常:恢复错误 - Openzepplin crowdsale contract got: VM Exception while processing transaction: revert error Solidity - Truffle:错误:处理事务时出现 VM 异常:无效的操作码不是因为恢复 - Solidity - Truffle: Error: VM Exception while processing transaction: invalid opcode NOT because of revert brownie:ValueError: execution reverted: VM Exception while processing transaction: revert - brownie:ValueError: execution reverted: VM Exception while processing transaction: revert 在松露控制台中使用OpenZeppelin ERC721 Mint时,“处理事务时发生VM异常:还原” - “VM Exception while processing transaction: revert” when using OpenZeppelin ERC721 mint in truffle console
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM