-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMidex-Exchange.js
77 lines (57 loc) · 2.34 KB
/
Midex-Exchange.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const MidexExchange = artifacts.require('MidexExchange')
const Token = artifacts.require('Token')
require('chai')
.use(require('chai-as-promised'))
.should()
function tokens(n) {
return web3.utils.toWei(n, 'ether');
}
contract('Midex-Exchange0', ([owner,customer]) => {
let token, midexExchange
before(async () => {
token = await Token.new()
midexExchange = await MidexExchange.new(token.address)
// Transfer all tokens to EthSwap (1 million)
await token.transfer(midexExchange.address, tokens('1000000'))
})
describe('Token contract was deployment', async () => {
it('contract has a name', async () => {
const name = await token.name()
assert.equal(name, 'Token')
})
})
describe('MidexExchange was deployment', async () => {
it('contract has a name', async () => {
const name = await midexExchange.name()
assert.equal(name, 'Midex Exchange')
})
it('contract has tokens', async () => {
let balance = await token.balanceOf(midexExchange.address)
assert.equal(balance.toString(), tokens('1000000'))
})
})
describe('BuyCoin()', async () => {
let result
before(async () => {
result = await midexExchange.buyCoins({from: customer, value: web3.utils.toWei('1','ether') })
})
it('Customer received the payment', async () => {
let customerBalance = await token.balanceOf(customer);
let deployerBalance = await token.balanceOf(midexExchange.address);
assert.equal(customerBalance.toString(), tokens('100'));
assert.equal(deployerBalance.toString(), tokens('999900'));
})
it('Total supply of token reduces by 1', async () => {
let deployerBalance = await token.balanceOf(midexExchange.address);
assert.equal(deployerBalance.toString(), tokens('999900'));
})
it('Token Purchased event returns correct events', async () => {
const events = result.logs[0].args;
console.log(events);
assert.equal(events.account, customer);
assert.equal(events.token, token.address);
assert.equal(events.amount.toString(), tokens('100'));
assert.equal(events.rate.toString(), '100');
})
})
})