1

I have the following smart contract function:

 function safeMint(address to, uint256 tokenId) public onlyOwner payable {
    require(msg.value >= mintPrice, "Not enough ETH to purchase NFT; check price!"); 
    _safeMint(to, tokenId);
}

and the following test function in chai to test it.

describe("mint", () => {
  it("should return true when 0.5 ethers are sent with transaction", async function () {
    await contract.deployed();
    const cost = ethers.utils.parseEther("0.1");
    await contract.safeMint("0x65.....",1,cost
  }); 

However the test function is not working and gives me an error on cost. Error: "Type 'BigNumber' has no properties in common with type 'Overrides & { from?: PromiseOrValue; }'." I fail to understand where the error lies.

Maliha
  • 13
  • 2

2 Answers2

0

Try this, it's the valid syntax to send value with the call:

await contract.safeMint("0x65.....", 1, {value: cost});
0xSanson
  • 718
  • 1
  • 2
  • 11
  • I am getting the following error on the above line. const cost: ethers.BigNumber Argument of type '{ value: ethers.BigNumber; }' is not assignable to parameter of type 'Overrides & { from?: PromiseOrValue; }'. Object literal may only specify known properties, and 'value' does not exist in type 'Overrides & { from?: PromiseOrValue; }'.ts(2345) – Maliha Sep 12 '22 at 01:10
0

I had a similar problem while testing a payable function, it kept saying 'object is not an instanceof of BigInt'. How I solved this problem and ensured testing ran smoothly was to test the balance of the receiver (in your case, the 'to' address), to make sure the balance has been updated. That is, if the safeMint function was successful during test, the 'to' address should be increased by 1. You can test by: const balOfToAdress = await contract.balanceOf(to.address) expect(balOfToAddress).to.equal(1)

Note: the 'expect' above is gotten by requiring chai at the top of your code i.e. const {expect} = require('chai') and, you have to test specifically for the balance of 'to' address (Here, I just assumed the initial balance of mints on 'to' address is 0).

Eric Aya
  • 69,473
  • 35
  • 181
  • 253