增加erc20货币的单元测试

This commit is contained in:
zhl 2022-01-13 19:01:58 +08:00
parent e05c141ad6
commit e9a4dbae6f
4 changed files with 4211 additions and 91 deletions

4245
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,14 +4,15 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "npx truffle test",
"deploy:dev": "truffle migrate --network development",
"deploy:local": "truffle migrate --network local",
"deploy:22": "truffle migrate --network lan22",
"deploy:bsctest": "truffle migrate --network bsc_testnet"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@openzeppelin/test-helpers": "^0.5.15",
"@truffle/hdwallet-provider": "^2.0.0",
"chai": "^4.3.4",
"truffle": "^5.4.23"

46
test/becoin.test.js Normal file
View File

@ -0,0 +1,46 @@
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);
});
});

View File

@ -91,12 +91,12 @@ module.exports = {
timeoutBlocks: 200,
skipDryRun: true
},
development: {
lan22: {
host: "192.168.100.22", // Localhost (default: none)
port: 8545, // Standard Ethereum port (default: none)
network_id: "*", // Any network (default: none)
},
local: {
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 7545, // Standard Ethereum port (default: none)
network_id: "*", // Any network (default: none)