contract call run out of gas and made the transaction revert HardHat

Viewed 606

I am trying to test solidity ^0.8.0 smart contract. And I am getting error error message

Here is part of code Solidity:

    receive () external payable {
    require (msg.value > 0, "Empty transact");
    require (saleStart + 48 days > block.timestamp, "ICO is over"); 
    require (msg.value / 1000000000000000000 % 1 == 0, "Fractional numbers are not allowed");

    if (saleStart + 3 days > block.timestamp) {
        addToBalance(msg.sender, msg.value, 1);
        }
    else if (saleStart + 34 days > block.timestamp) {
        addToBalance(msg.sender, msg.value, 2);
        }

    else if (saleStart + 48 days > block.timestamp ) {
        addToBalance(msg.sender, msg.value, 3);
        }
}

and JS HardHat

const { expect } = require("chai");
const { ethers, waffle } = require("hardhat");

beforeEach(async function(){
    [owner, acc1, acc2, acc3 ] = await ethers.getSigners()
    const ICO = await ethers.getContractFactory("ICO", owner)
    ico = await ICO.deploy()
    await ico.deployed()
})
    it("contract receive ether", async function(){
    const tx = await ico.connect(acc1).pay(ico.address, { value : 100000, gasLimit: 30000000 })
    await tx.wait()
    const owner_balance = await provider.getBalance(owner.address)
    const acc1_balance = await provider.getBalance(acc1.address);
    console.log(owner_balance)
    console.log(acc1_balance)
})

Also I tried to use receive() function without any code inside and it works. It seems problem I change some information in blockchane, and it's require gas. But Also I tried receive() function with code inside in Rinkeby testnet and it works. How to solve problem with gas?

0 Answers
Related