-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path05_fixedsupplytokenMixedNOK.js
51 lines (40 loc) · 2.25 KB
/
05_fixedsupplytokenMixedNOK.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
const Token = artifacts.require("FixedSupplyToken");
/////////////////////////////////////////////////////////////////////////////////
// SUCCESSFULL TEST in the ORDER
// 1. transfer with token (tokenAmount * (10**token.decimals))
// 2. transfer with pure decimals
// TEST RUNS SUCCESSFULLY IN MY ENVIRONMENT
/////////////////////////////////////////////////////////////////////////////////
contract ('fixedSupplyTokenMixedNOK', function(accounts) {
before( async() => {
owner_account = accounts[0];
bob_account = accounts[1];
alice_account = accounts[2];
token = await Token.deployed();
decimals = (await token.decimals()).toNumber();
});
it("it should transfer the correct number of tokens (using pure decimals)", async () => {
let decimalAmount = 5000000;
// NUMBERS BEFORE
let ownerBalanceBefore = await token.balanceOf(owner_account);
let bobBalanceBefore = await token.balanceOf(bob_account);
await token.transfer(bob_account, decimalAmount, {from: owner_account});
let ownerBalance = await token.balanceOf(owner_account);
let bobBalance = await token.balanceOf(bob_account);
assert.equal(ownerBalance.toNumber(), ownerBalanceBefore.toNumber() - decimalAmount, 'owner has incorrect balance');
assert.equal(bobBalance.toNumber(), bobBalanceBefore.toNumber() + decimalAmount, 'Bob has incorrect balance');
});
it("it should transfer the correct number of tokens (using token.decimal computation)", async () => {
let tokenAmount = 50;
// NUMBERS BEFORE
let ownerBalanceBefore = (await token.balanceOf(owner_account)) / (10**decimals);
let bobBalanceBefore = (await token.balanceOf(bob_account)) / (10**decimals);
// DO THE JOB
await token.transfer(bob_account, tokenAmount * (10**decimals), {from: owner_account});
// NUMBERS AFTER
let ownerBalance = (await token.balanceOf(owner_account)) / (10**decimals);
let bobBalance = (await token.balanceOf(bob_account)) / (10**decimals);
assert.equal(ownerBalance, ownerBalanceBefore - tokenAmount, 'owner has incorrect balance');
assert.equal(bobBalance, bobBalanceBefore + tokenAmount, 'Bob has incorrect balance');
});
});