it("Should allow to buy and refund", async () => {
const FEE = 10;
const oneEtherInWei = ethers.parseEther("1"); // 1 ETH = 1e18 wei
const twoEtherInWei = ethers.parseEther("2"); // 2 ETH = 2e18 wei
await expect(smartContract.connect(seller).createAuction(
oneEtherInWei,
FEE,
"test item",
60
));
const tx = await smartContract.connect(buyer).buy(0, { value: twoEtherInWei });
await tx.wait();
const feeAmount = (parseFloat(oneEtherInWei.toString()) * FEE) / 100;
console.log("feeAmount :", feeAmount);
const moneyForSeller = parseFloat(oneEtherInWei.toString()) - feeAmount;
console.log("moneyForSeller :", moneyForSeller);
const moneyLeftOnContract = parseFloat(oneEtherInWei.toString()) - moneyForSeller;
console.log("moneyLeftOnContract :", moneyLeftOnContract);
await expect(tx).to.changeEtherBalance(smartContract.target, moneyLeftOnContract.toString()) // Перевірка зміни балансу смарт-контракту
await expect(tx).to.changeEtherBalance(buyer.address, (parseFloat(twoEtherInWei) * -1).toString()) // Перевірка зміни балансу покупця
await expect(tx).to.changeEtherBalance(seller.address, moneyForSeller.toString()) // Перевірка зміни балансу продавця
const price = await smartContract.auctions(0).finalPrice;
expect(tx).to.emit(smartContract, "AuctionEnded")
.withArgs(0, price, buyer);
});
Test result screenshot