我正在按照教程使用松露创建智能合约。我想更好地了解本教程中创建的测试。
这是其中一项测试:
it("increases myDonationsCount", async () => {
const currentDonationsCount = await fundraiser.myDonationsCount(
{from: donor}
);
await fundraiser.donate({from: donor, value});
const newDonationsCount = await fundraiser.myDonationsCount(
{from: donor}
);
assert.equal(
1,
newDonationsCount - currentDonationsCount,
"myDonationsCount should increment by 1");
})
这个物体是从哪里来的?{from: donor, value}
对于这个测试:
it("throws an error when called from a different account", async () =>{
try {
await fundraiser.setBeneficiary(newBeneficiary, {from: accounts[3]});
assert.fail("withdraw was not restricted to owners")
} catch(err) {
const expectedError = "Ownable: caller is not the owner"
const actualError = err.reason;
assert.equal(actualError, expectedError, "should not be permitted")
}
})
在上述测试的第三行中,它们传递了 2 个参数fundraiser.setBeneficiary(newBeneficiary, {from: accounts[3]});。如果原始函数只接收一个,这怎么可能?
功能:
function setBeneficiary(address payable _beneficiary) public onlyOwner {
beneficiary = _beneficiary;
}