Eoslime
Search…
test
You should have running nodeos
1
eoslime test
Copied!
Will prepare the mocha testing framework for you and provide you some testing utils.
The testing utils (eoslime.tests) are only available when your are using eoslime
1
const assert = require('assert');
2
3
const TOKEN_WASM_PATH = './contracts/example/eosio.token.wasm';
4
const TOKEN_ABI_PATH = './contracts/example/eosio.token.abi';
5
6
describe("EOSIO Token", function (eoslime) {
7
8
// Increase mocha(testing framework) time, otherwise tests fails
9
this.timeout(15000);
10
11
let tokenContract;
12
let tokensIssuer;
13
let tokensHolder;
14
15
const TOTAL_SUPPLY = "1000000000.0000 SYS";
16
const HOLDER_SUPPLY = "100.0000 SYS";
17
18
before(async () => {
19
let accounts = await eoslime.Account.createRandoms(2);
20
tokensIssuer = accounts[0];
21
tokensHolder = accounts[1];
22
});
23
24
beforeEach(async () => {
25
tokenContract = await eoslime.Contract.deploy(TOKEN_WASM_PATH, TOKEN_ABI_PATH);
26
});
27
28
it("Should create a new token", async () => {
29
await tokenContract.actions.create(tokensIssuer.name, TOTAL_SUPPLY);
30
let tokenInitialization = await tokenContract.provider.eos.getCurrencyStats(tokenContract.name, "SYS");
31
32
assert.equal(tokenInitialization.SYS.max_supply, TOTAL_SUPPLY, "Incorrect tokens supply");
33
assert.equal(tokenInitialization.SYS.issuer, tokensIssuer.name, "Incorrect tokens issuer");
34
});
35
36
it("Should issue tokens", async () => {
37
await tokenContract.actions.create(tokensIssuer.name, TOTAL_SUPPLY);
38
await tokenContract.actions.issue(tokensHolder.name, HOLDER_SUPPLY, "memo", { from: tokensIssuer });
39
40
let holderBalance = await tokensHolder.getBalance("SYS", tokenContract.name);
41
assert.equal(holderBalance[0], HOLDER_SUPPLY, "Incorrect holder balance");
42
});
43
44
it("Should throw if tokens quantity is negative", async () => {
45
await tokenContract.actions.create(tokensIssuer.name, TOTAL_SUPPLY);
46
const INVALID_ISSUING_AMOUNT = "-100.0000 SYS";
47
48
await eoslime.tests.expectAssert(tokenContract.actions.issue(tokensHolder.name, INVALID_ISSUING_AMOUNT, "memo", { from: tokensIssuer }));
49
50
let holderBalance = await tokensHolder.getBalance("SYS", tokenContract.name);
51
assert.equal(holderBalance.length, 0, "Incorrect holder balance");
52
});
53
});
54
Copied!
Last modified 1yr ago
Copy link