我必须测试智能合约
文件审批合同
const ApprovalContract = artifacts.require( "../../contracts/ApprovalContract.sol");
contract("ApprovalContract", function (accounts) {
it("initiates contract", async function () {
const contract = await ApprovalContract.deployed();
const approver = await contract.approver.call();
assert.equal(
approver,
0x8c4b9b5262f1ae1bdfb58f6579348817c4da4277,
"approvers don't match"
);
});
it("takes a deposit", async function () {
const contract = await ApprovalContract.deployed();
await contract.deposit(accounts[0], { value: 1e18, from: accounts[1] });
assert.equal(
await web3.eth.getBalance(contract.address),
1e18,
"amount did not match"
);
});
it(
"makes the transaction when approved, approver: " + accounts[2],
async function () {
const contract = await ApprovalContract.deployed();
const balance = await web3.eth.getBalance(contract.address);
await contract.deposit(accounts[0], { value: 1e18, from: accounts[1] });
await contract.approve({ from: accounts[2] });
assert.equal(
web3.eth.getBalance(contract.address),
0,
"didn't transfer ether"
);
}
);
});
truffle compile,truffle migrate 运行成功。
<块引用>答案 0 :(得分:0)
如果没有 .sol 合同中的函数,我不能 100% 确定,但是您的 Approval 事件可能在您的 accept 方法中错误地发出。
看看在此处的第二个示例中如何使用 accept 函数: https://docs.soliditylang.org/en/v0.8.1/types.html?highlight=approve#mapping-types
emit Approval(owner, spender, amount);