[英]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.