becrypto/test/becoin.test.js
2022-01-13 19:01:58 +08:00

47 lines
1.3 KiB
JavaScript

const { expect } = require("chai");
const {
BN,
constants,
expectEvent,
expectRevert,
} = require("@openzeppelin/test-helpers");
const BECoin = artifacts.require("BECoin");
contract("BECoin", ([owner, other]) => {
const amount = new BN(10000);
beforeEach(async () => {
this.coin = await BECoin.new();
});
it("should put 20000000 * 1e18 BECoin in the first account", async () => {
let balance = await this.coin.balanceOf.call(owner);
assert.equal(
balance.valueOf(),
20000000 * 1e18,
"20000000 * 1e18 wasn't in the first account"
);
});
it("reverts when transferring tokens to the zero address", async () => {
// Conditions that trigger a require statement can be precisely tested
await expectRevert(
this.coin.transfer(constants.ZERO_ADDRESS, amount),
"ERC20: transfer to the zero address"
);
});
it("should emit Transfer event", async () => {
const receipt = await this.coin.transfer(other, amount);
expectEvent(receipt, "Transfer", {
from: owner,
to: other,
value: amount,
});
});
it("should send coin correctly", async () => {
await this.coin.transfer(other, amount);
expect(await this.coin.balanceOf(other)).to.be.bignumber.equal(amount);
});
});