Skip to content

Commit

Permalink
Create test_ERC20Token.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Oct 31, 2024
1 parent a85c12f commit b762490
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions blockchain_integration/pi_network/tests/test_ERC20Token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// tests/test_ERC20Token.js
const { expect } = require("chai");
const { ethers } = require("hardhat");

describe("ERC20Token", function () {
let Token;
let token;
let owner;
let addr1;
let addr2;

beforeEach(async function () {
Token = await ethers.getContractFactory("ERC20Token");
[owner, addr1, addr2] = await ethers.getSigners();
token = await Token.deploy("Test Token", "TTK", 1000);
await token.deployed();
});

it("Should have the correct name and symbol", async function () {
expect(await token.name()).to.equal("Test Token");
expect(await token.symbol()).to.equal("TTK");
});

it("Should assign the total supply to the owner", async function () {
const ownerBalance = await token.balanceOf(owner.address);
expect(await token.totalSupply()).to.equal(ownerBalance);
});

it("Should transfer tokens between accounts", async function () {
await token.transfer(addr1.address, 100);
const addr1Balance = await token.balanceOf(addr1.address);
expect(addr1Balance).to.equal(100);

await token.connect(addr1).transfer(addr2.address, 50);
const addr2Balance = await token.balanceOf(addr2.address);
expect(addr2Balance).to.equal(50);
});

it("Should fail if sender doesn’t have enough tokens", async function () {
const initialOwnerBalance = await token.balanceOf(owner.address);
await expect(token.connect(addr1).transfer(owner.address, 1)).to.be.revertedWith("ERC20: transfer amount exceeds balance");
expect(await token.balanceOf(owner.address)).to.equal(initialOwnerBalance);
});
});

0 comments on commit b762490

Please sign in to comment.