The error is caught during await sender.sendTransaction(txData)
, but the functions of my contract are working correctly.
Here's the error:
ProviderError: Contract creation without any data provided
Here's my contract:
Demo.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
contract Demo3{
address owner;
event Paid(address indexed _from, uint _amount, uint _timestamp);
constructor(){
owner = msg.sender;
}
receive() external payable{
pay();
}
function pay() public payable {
emit Paid(msg.sender, msg.value, block.timestamp);
}
modifier onlyOwner(address _to){
require(msg.sender == owner, "You aren't owner!");
require(_to != address(0), "inccorect address!");
_;
}
function withdraw(address payable _to) external onlyOwner(_to){
_to.transfer(address(this).balance);
}
}
Here's my test script:
Demo.test.js
let owner
let other_addr
let demo
beforeEach(async function () {
[owner, other_addr] = await ethers.getSigners()
const DemoContract = await ethers.getContractFactory("Demo3", owner)
demo = await DemoContract.deploy()
await demo.waitForDeployment()
})
async function sendMoney(sender) {
const amount = 100
const txData = {
to: demo.address,
value: amount
}
const tx = await sender.sendTransaction(txData)
await tx.wait()
return [tx, amount]
}
it("shound allow to send money", async function () {
const [sendMoneyTx, amount] = await sendMoney(other_addr)
await expect(() => sendMoneyTx)
.to.changeEtherBalance(demo, amount);
const timestamp = (
await ethers.provider.getBlock(sendMoneyTx.blockNumber)
).timestamp
await expect(sendMoneyTx)
.to.emit(demo, "Paid")
.withArgs(other_addr.address, amount, timestamp)
})