Skip to content

Commit

Permalink
Create erc20_factory_test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 7, 2024
1 parent ee09298 commit 1f9af69
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions projects/DAPIO/tests/integration-tests/erc20_factory_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("ERC20 Factory", function () {
let erc20Factory;
let owner;

beforeEach(async function () {
[owner] = await ethers.getSigners();
erc20Factory = await ethers.deploy("ERC20Factory");
});

it("should create a new ERC20 token", async function () {
const tokenName = "MyToken";
const tokenSymbol = "MTK";
const totalSupply = 1000;

const tx = await erc20Factory.createToken(tokenName, tokenSymbol, totalSupply);
const receipt = await tx.wait();

const tokenAddress = receipt.events[0].args.token;
const token = await ethers.getContractAt("ERC20", tokenAddress);

expect(await token.name()).to.equal(tokenName);
expect(await token.symbol()).to.equal(tokenSymbol);
expect(await token.totalSupply()).to.equal(totalSupply);
});

it("should return the correct token address", async function () {
const tokenName = "MyToken";
const tokenSymbol = "MTK";
const totalSupply = 1000;

const tx = await erc20Factory.createToken(tokenName, tokenSymbol, totalSupply);
const receipt = await tx.wait();

const tokenAddress = receipt.events[0].args.token;
expect(await erc20Factory.getToken(owner.address)).to.equal(tokenAddress);
});
});

0 comments on commit 1f9af69

Please sign in to comment.