-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-3-profit-sharing.js
134 lines (115 loc) · 4.13 KB
/
test-3-profit-sharing.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import BigNumber from 'bignumber.js'
import {
assert,
assertRevert,
getAddresses,
ether,
getBalance,
assertTxSucceedsGeneratingEvents,
} from './helpers'
const TestToken = artifacts.require('./TestToken.sol')
const WavestreamPresale = artifacts.require('./WavestreamPresale.sol')
contract(
`WavestreamPresale (profit sharing with one divided payment):`,
accounts => {
const addr = getAddresses(accounts)
const rate = 100 // 100 tokens for 1 Ether, assuming token.digits is 18
let presale
let token
let priorityBalance
let mainBalance
before(async () => {
token = await TestToken.new(ether(100000), {from: addr.owner})
presale = await WavestreamPresale.new(
rate,
addr.priorityWallet,
ether(7),
addr.wallet,
ether(400),
token.address,
{from: addr.owner},
)
await token.transfer(presale.address, ether(10000), {from: addr.owner})
priorityBalance = await getBalance(addr.priorityWallet)
mainBalance = await getBalance(addr.wallet)
})
it('forwards first payment to priorityWallet', async () => {
await presale.buyTokens(addr.investor, {
value: ether(1),
from: addr.investor,
})
const updatedBalance = await getBalance(addr.priorityWallet)
assert.bignumEqual(updatedBalance, priorityBalance.plus(ether(1)))
priorityBalance = updatedBalance
})
it('divides payment between priority and main wallet', async () => {
await presale.buyTokens(addr.investor, {
value: ether(10),
from: addr.investor,
})
const updatedPriorityBalance = await getBalance(addr.priorityWallet)
assert.bignumEqual(updatedPriorityBalance, priorityBalance.plus(ether(6)))
priorityBalance = updatedPriorityBalance
const updatedMainBalance = await getBalance(addr.wallet)
assert.bignumEqual(updatedMainBalance, mainBalance.plus(ether(4)))
mainBalance = updatedMainBalance
})
it('after priority cap is reached, forwards all payments to main wallet', async () => {
await presale.buyTokens(addr.investor, {
value: ether(1),
from: addr.investor,
})
const updatedPriorityBalance = await getBalance(addr.priorityWallet)
assert.bignumEqual(updatedPriorityBalance, priorityBalance)
const updatedMainBalance = await getBalance(addr.wallet)
assert.bignumEqual(updatedMainBalance, mainBalance.plus(ether(1)))
mainBalance = updatedMainBalance
})
},
)
contract(
`WavestreamPresale (profit sharing with no divided payments):`,
accounts => {
const addr = getAddresses(accounts)
const rate = 100 // 100 tokens for 1 Ether, assuming token.digits is 18
let presale
let token
let priorityBalance
let mainBalance
before(async () => {
token = await TestToken.new(ether(100000), {from: addr.owner})
presale = await WavestreamPresale.new(
rate,
addr.priorityWallet,
ether(7),
addr.wallet,
ether(400),
token.address,
{from: addr.owner},
)
await token.transfer(presale.address, ether(10000), {from: addr.owner})
priorityBalance = await getBalance(addr.priorityWallet)
mainBalance = await getBalance(addr.wallet)
})
it('forwards first payment to priorityWallet', async () => {
await presale.buyTokens(addr.investor, {
value: ether(7),
from: addr.investor,
})
const updatedBalance = await getBalance(addr.priorityWallet)
assert.bignumEqual(updatedBalance, priorityBalance.plus(ether(7)))
priorityBalance = updatedBalance
})
it('after priority cap is reached, forwards all payments to main wallet', async () => {
await presale.buyTokens(addr.investor, {
value: ether(1),
from: addr.investor,
})
const updatedPriorityBalance = await getBalance(addr.priorityWallet)
assert.bignumEqual(updatedPriorityBalance, priorityBalance)
const updatedMainBalance = await getBalance(addr.wallet)
assert.bignumEqual(updatedMainBalance, mainBalance.plus(ether(1)))
mainBalance = updatedMainBalance
})
},
)