-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNonStandardERC20TokenTests.js
59 lines (55 loc) · 2.57 KB
/
NonStandardERC20TokenTests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const { expect } = require("chai");
const { ethers } = require("hardhat");
describe("NonStandardERC20Token.sol", () => {
let contractFactory;
let contract;
let owner;
let alice;
let bob;
let initialSupply;
let ownerAddress;
let aliceAddress;
let bobAddress;
beforeEach(async () => {
[owner, alice, bob] = await ethers.getSigners();
initialSupply = ethers.parseEther("100000");
contractFactory = await ethers.getContractFactory("NonStandardERC20Token");
contract = await contractFactory.deploy(initialSupply);
ownerAddress = await owner.getAddress();
aliceAddress = await alice.getAddress();
bobAddress = await bob.getAddress();
});
describe("Correct setup", () => {
it("should be named 'NonStandardERC20Token'", async () => {
const name = await contract.name();
expect(name).to.equal("NonStandardERC20Token");
});
it("should have correct supply", async () => {
const supply = await contract.getTotalSupply();
expect(ethers.formatEther(supply)).to.equal(ethers.formatEther(initialSupply));
});
it("owner should have all the supply", async () => {
const ownerBalance = await contract.balanceOf(ownerAddress);
expect(ethers.formatEther(ownerBalance)).to.equal(ethers.formatEther(initialSupply));
});
});
describe("Core", () => {
it("owner should transfer to Alice and update balances", async () => {
const transferAmount = ethers.parseEther("1000");
let aliceBalance = await contract.balanceOf(aliceAddress);
expect(ethers.formatEther(aliceBalance)).to.equal("0.0");
await contract.transfer(transferAmount, aliceAddress);
aliceBalance = await contract.balanceOf(aliceAddress);
expect(ethers.formatEther(aliceBalance)).to.equal(ethers.formatEther(transferAmount));
});
it("owner should transfer to Alice and Alice to Bob", async () => {
const transferAmount = ethers.parseEther("1000");
await contract.transfer(transferAmount, aliceAddress); // contract is connected to the owner.
let bobBalance = await contract.balanceOf(bobAddress);
expect(ethers.formatEther(bobBalance)).to.equal("0.0");
await contract.connect(alice).transfer(transferAmount, bobAddress);
bobBalance = await contract.balanceOf(bobAddress);
expect(ethers.formatEther(bobBalance)).to.equal(ethers.formatEther(transferAmount));
});
});
});