ERC20代币购买

问题描述 投票:0回答:1
const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("Erc20 smart contract testing", function () {
  let token;
  let accounts;
  const amount = ethers.parseEther("1"); 

  before(async function () {
    const referencetToABI = await ethers.getContractFactory("BikashToken");
    token = await referencetToABI.deploy();
    accounts = await ethers.getSigners();
  });


  it("Buying token Successful", async function () {
    const buyer = accounts[2];
    const tokenAmount = amount.mul(1000);// Using 1 Ether buying 1000 Token

    await token.connect(buyer).buy({ value: amount });

    expect(await token.balanceOf(buyer.address)).to.equal(tokenAmount);
  });
});

我正在测试 ERC20 Solidity 智能合约。但是这段代码给了我一个错误= TypeError: amount.mul is not a function 我怎样才能解决这个问题 ?我正在观看 YouTube 视频,其中

amount.mul()
功能工作正常,但在我的机器中却显示错误。请帮忙。

合约中的 buy() 函数:

function buy() public payable returns (bool) {
        require(
            msg.sender.balance >= msg.value && msg.value != 0 ether,
            "ICO: function buy invalid input"
        );
        uint256 amount = msg.value * 1000;
        _transfer(owner(), _msgSender(), amount);
        return true;
}
testing blockchain solidity ethers.js erc20
1个回答
0
投票

const 计算 = 金额 * BigInt(1000);

© www.soinside.com 2019 - 2024. All rights reserved.