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
|
const Token = artifacts.require("Token");
const { expectRevert } = require('@openzeppelin/test-helpers');
contract("Token", accounts => {
let token;
const [owner, user1, user2] = accounts;
beforeEach(async () => {
token = await Token.new("Test Token", "TEST");
});
it("should transfer tokens correctly", async () => {
const amount = web3.utils.toWei("100", "ether");
await token.transfer(user1, amount, { from: owner });
const balance = await token.balanceOf(user1);
assert.equal(balance.toString(), amount);
});
it("should fail when transferring with insufficient balance", async () => {
const amount = web3.utils.toWei("1000001", "ether");
await expectRevert(
token.transfer(user2, amount, { from: user1 }),
"Insufficient balance"
);
});
});
|