0

我正在通过使用安全帽、solidity 和 chai 制作代币进行测试来学习一些区块链的东西。我正在从 OpenZeppelin 扩展 ERC20 协议。目前我正在尝试针对硬币编写一些基本代码,例如其名称、符号、初始金额。

我的测试文件中的工件返回未定义,我不确定为什么,因为它们在部署脚本中工作正常。这是测试文件和 hardhat.config.ts。

我的文件结构如下所示:

|-artifacts/
|-contracts/
|-scripts/
|-test/
// test/Token.test.ts

const { expect } = require("chai");

const { BN, expectEvent, expectRevert, constants } = require('@openzeppelin/test-helpers');
const { Contract } = require("hardhat/internal/hardhat-network/stack-traces/model");

const Token = artifacts.require('Token');

Contract('Coin Tests', ([creator, other]: any) => {
  const NAME = 'Test';
  const SYMBOL = 'Tst';
  const TOTAL_SUPPLY = new BN('10000000000000000000000000000');

  beforeEach(async function () {
    this.token = await Token.new(NAME, SYMBOL, TOTAL_SUPPLY, {
      from: creator
    });
    describe("Token Attributes", () => {
      it('has name', async function () {
        expect(await this.token.name().to.equal(NAME));
      });
      it('has symbol', async function () {
        expect(await this.token.symbol().to.equal(SYMBOL));
      });
      it("initial supply", async function () {
        expect(await this.token.initialSupply().to.equal(TOTAL_SUPPLY))
      });
    });
  });
});
// hardhat.config.ts

import { task } from "hardhat/config"; 
import "@nomiclabs/hardhat-waffle"; 

task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
  const accounts = await hre.ethers.getSigners();

  for (const account of accounts) {
    console.log(await account.address);
  }
});

module.exports = {
  solidity: "0.8.4",
  paths: {
    artifacts: './artifacts',
  },
  networks: {
    hardhat: {
      chainId: 1337
    }
  }
};

4

0 回答 0