我的合约代码
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import {CarNFT} from "./CarNFT.sol";
// OrderManager contract
contract OrderManager {
... code
function deposit() external payable onlyBuyer {
// Buyer deposits funds
require(msg.value == price, "Incorrect deposit amount");
}
}
OrderManger.t.sol 测试文件
function testDeposit() public {
// Assuming startPrank, deal, and stopPrank functions work as expected
vm.startPrank(buyer);
vm.deal(buyer, 10 ether);
// Ensure the buyer has the expected balance
uint256 buyerBalanceBefore = address(buyer).balance;
assertEq(buyerBalanceBefore, 10 ether);
// Deposit into OrderManager contract
orderM.deposit();
// Ensure the balance of the OrderManager contract is updated
uint256 contractBalance = orderM.getBalance();
emit log_named_uint("Contract's balance is", contractBalance);
assertEq(price, contractBalance);
// Ensure the buyer's balance has been reduced by the deposited amount
uint256 buyerBalanceAfter = address(buyer).balance;
emit log_named_uint("Buyer's balance after deposit is", buyerBalanceAfter);
assertEq(buyerBalanceBefore - price, buyerBalanceAfter);
vm.stopPrank();
}
如果我想通过 msg.send 在 calldata 中发送 ETH,我该使用什么语法?
我使用 Foundry 作为开发工具;我应该为此目的使用 Foundry 作弊代码吗?
请指导
这里正确的语法是
orderM.deposit{value: 0.2 ether}()
或者一般情况下
contractInstance.func{value: msg.sender (value in ether or wei; see below)}(func args)
如果在Foundry中msg.send可以指定为(0.2 ether),否则以wei(200000000000000000)发送