简体   繁体   English

对solidity代码运行测试时出错

[英]Getting error while running test on the solidity code

This is the solidity code, a simple code provided in linkedin learning course -这是solidity代码,linkedin学习课程中提供的简单代码——

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.5.0 <0.7.0;

contract ApprovalContract{
    address public sender;
    address payable public receiver;
    address public constant approver = 0x9BE32C0CB7910d71CA2c2a7D6B46ebd273dA01eC;
    function deposit(address payable _receiver) external payable{
        require(msg.value>0,"message smaller than 0");
        sender = msg.sender;
        receiver = _receiver;
    }

    function viewApprover() external pure returns(address){
        return(approver);
    }

    function approve() external{
        require(msg.sender == approver,"message is approved");
        receiver.transfer(address(this).balance);
    }
}

and this is the test code -这是测试代码 -

const ApprovalContract = artifacts.require('../contracts/ApprovalContract');

contract("ApprovalContract",function (accounts) {
    it('initiates contract',async function(){
        const contract = await ApprovalContract.deployed();
        const approver = await contract.approver.call();
        assert.equal(approver,0x9BE32C0CB7910d71CA2c2a7D6B46ebd273dA01eC,"approvers don't match");
    });
    it('takes a deposit',async function(accounts){
        const contract = await ApprovalContract.deployed();
        await contract.deposit(accounts[0],{value:1e+10,from:accounts[1]});
        assert.equal(web3.eth.getBalance(contract.address),1e+10,"account did not match");
    });
});

Keep getting the error whenever i run the test code using truffle test -每当我使用 truffle test 运行测试代码时,都会出现错误 -

Error: invalid address (arg="_receiver", coderType="address", value=undefined)
Error: invalid address (arg="_receiver", coderType="address", value=undefined)
C:\Users\tanis\AppData\Roaming\npm\node_modules\truffle\node_modules\mocha\lib\runner.js:726
  err.uncaught = true;
               ^

TypeError: Cannot create property 'uncaught' on string 'abort(Error: invalid address (arg="_receiver", coderType="address", value=undefined)). Build with -s ASSERTIONS=1 for more info.'

I learned the same course and encountered the same problem.我学了同样的课程,遇到了同样的问题。 it ended up working for me (but not sure exactly what the problem was).它最终为我工作(但不确定到底是什么问题)。

Try connecting a meta mask like this:尝试像这样连接元掩码:

 ethereum.request({ method: 'eth_requestAccounts' });

also try several different sending and receiving addresses也尝试几个不同的发送和接收地址

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

相关问题 运行 solana 的测试验证器时出错 - Getting error on running test validator for solana 得到 parsererror 我在 remix 上写 inheritance solidity 代码我得到了错误 - getting parsererror I write inheritance solidity code on remix i got error 使用Docker在本地运行Hyperledger时出错 - Getting error while running Hyperledger locally with Docker 运行松露init命令时出现错误 - Getting an error while running truffle init command Solidity 结构和质押代码错误:请查看合约 - Solidity struct and staking code error: Please look into the contract 如何测试 Solidity 应付合同 - How to test a Solidity payable contract 当我测试我的可靠性代码时,我收到“AssertionError: Expected transaction to be reverted with Username” - I am getting "AssertionError: Expected transaction to be reverted with Username " when I am testing my solidity code Solidity:在依赖于参数的查找后,由于未找到成员“余额”或不可见而出错 - Solidity : Getting error as Member “balance” not found or not visible after argument-dependent lookup 尝试将链码用于测试网络但运行我的应用程序时,HYPERLEDGER FABRIC 出错 - Error at HYPERLEDGER FABRIC while trying to use the chaincode for the test network but running my application Solidity - 错误:标识符未找到或唯一 - Solidity - Error: identifier not found or unique
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM