This repository was archived by the owner on Jul 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathSecurityTokenRegistrar.js
More file actions
404 lines (364 loc) · 13.2 KB
/
SecurityTokenRegistrar.js
File metadata and controls
404 lines (364 loc) · 13.2 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
import { convertHex, ensureException, duration } from './helpers/utils.js';
import latestTime from './helpers/latestTime';
const SecurityTokenRegistrar = artifacts.require('./SecurityTokenRegistrar.sol');
const SecurityToken = artifacts.require('./SecurityToken.sol');
const POLY = artifacts.require('./helpers/mockContracts/PolyTokenMock.sol');
const Compliance = artifacts.require('./Compliance.sol');
const Customers = artifacts.require('./Customers.sol');
const NameSpaceRegistrar = artifacts.require('./NameSpaceRegistrar.sol');
contract('SecurityTokenRegistrar', accounts => {
//createSecurityToken variables
const name = 'Polymath Inc.';
const ticker = 'POLY';
const totalSupply = 1234567890;
const maxPoly = 100000;
const securityType = 5;
const numberOfSecurityTypes = 8; //8 is chosen for testing,
const nameSpaceMixed = "TestNameSpace";
const nameSpace = "testnamespace";
const nameSpaceFee = 10000;
const nameSpaceOwner = accounts[6];
const quorum = 3;
const lockupPeriod = latestTime() + duration.years(1); //Current time + 1 year is the locking period (Testing Only)
const getAmount = 1000000;
const approvedAmount = 10000;
//accounts
let owner = accounts[0];
let acct1 = accounts[1];
let acct2 = accounts[2];
let issuer2 = accounts[3];
let issuer1 = accounts[4];
let polyToken, polyCustomers, polyCompliance, STRegistrar, polyNameSpaceRegistrar;
beforeEach(async () => {
polyToken = await POLY.new();
polyCustomers = await Customers.new(polyToken.address);
polyCompliance = await Compliance.new(polyCustomers.address);
polyNameSpaceRegistrar = await NameSpaceRegistrar.new();
console.log("polyNameSpaceRegistrar " + polyNameSpaceRegistrar.address);
// Creation of the new SecurityTokenRegistrar contract
STRegistrar = await SecurityTokenRegistrar.new(
polyToken.address,
polyCustomers.address,
polyCompliance.address,
polyNameSpaceRegistrar.address
);
})
describe('Constructor', async () => {
it('should have polyTokenAddress updated to contract storage', async () => {
await polyCompliance.setRegistrarAddress(STRegistrar.address);
let PTAddress = await STRegistrar.PolyToken.call();
assert.strictEqual(PTAddress, polyToken.address);
});
});
describe('function createSecurityToken', async () => {
it('should allow for the creation of a Security Token.', async () => {
// Allowance Provided to SecurityToken Registrar contract
await polyToken.getTokens(getAmount, issuer1, { from : issuer1 });
let issuerBalance = await polyToken.balanceOf(issuer1);
assert.strictEqual(issuerBalance.toNumber(),getAmount);
await polyToken.approve(STRegistrar.address, approvedAmount, { from : issuer1 });
let allowedToken = await polyToken.allowance(issuer1, STRegistrar.address);
assert.strictEqual(allowedToken.toNumber(),approvedAmount);
// Create name space
await STRegistrar.createNameSpace(
nameSpaceMixed,
nameSpaceFee,
{
from: nameSpaceOwner
}
)
// Creation of the Security Token
let ST = await STRegistrar.createSecurityToken(
nameSpace,
name,
ticker,
totalSupply,
0,
issuer1,
numberOfSecurityTypes,
{
from: issuer1,
},
);
let STAddress = await STRegistrar.getSecurityTokenAddress.call(nameSpace, ticker);
assert.notEqual(STAddress, 0x0);
let STData = await STRegistrar.getSecurityTokenData.call(STAddress);
assert.strictEqual(STData[1], ticker);
});
//////////////////////////////////////
//// createSecurityToken() Test Cases
//////////////////////////////////////
describe('Creation of SecurityTokenMetaData Struct is within its proper limitations', async () => {
it('createSecurityToken:should fail when total supply is zero', async () => {
let totalSupply = 0;
// Allowance Provided to SecurityToken Registrar contract
await polyToken.getTokens(getAmount, issuer1, {from : issuer1 });
let issuerBalance = await polyToken.balanceOf(issuer1);
assert.strictEqual(issuerBalance.toNumber(), getAmount);
await polyToken.approve(STRegistrar.address, approvedAmount, { from : issuer1 });
// Create name space
await STRegistrar.createNameSpace(
nameSpaceMixed,
nameSpaceFee,
{
from: nameSpaceOwner
}
)
try{
await STRegistrar.createSecurityToken(
nameSpace,
name,
ticker,
totalSupply,
0,
issuer1,
numberOfSecurityTypes,
{
from : issuer1
})
} catch(error) {
ensureException(error);
}
});
it('createSecurityToken:should fail when name space does not exist', async () => {
let totalSupply = 115792089237316195423570985008687907853269984665640564039457584007913129639936;
// Allowance Provided to SecurityToken Registrar contract
await polyToken.getTokens(getAmount, issuer1, { from : issuer1 });
let issuerBalance = await polyToken.balanceOf(issuer1);
assert.strictEqual(issuerBalance.toNumber(), getAmount);
await polyToken.approve(STRegistrar.address, approvedAmount, { from : issuer1 });
try{
await STRegistrar.createSecurityToken(
nameSpace,
name,
ticker,
totalSupply,
0,
issuer1,
numberOfSecurityTypes,
{
from : issuer1
})
} catch(error) {
ensureException(error);
}
});
it('createSecurityToken:should fail when total supply is greater than (2^256)-1', async () => {
let totalSupply = 115792089237316195423570985008687907853269984665640564039457584007913129639936;
// Allowance Provided to SecurityToken Registrar contract
await polyToken.getTokens(getAmount, issuer1, { from : issuer1 });
let issuerBalance = await polyToken.balanceOf(issuer1);
assert.strictEqual(issuerBalance.toNumber(), getAmount);
await polyToken.approve(STRegistrar.address, approvedAmount, { from : issuer1 });
// Create name space
await STRegistrar.createNameSpace(
nameSpaceMixed,
nameSpaceFee,
{
from:nameSpaceOwner
}
)
try{
await STRegistrar.createSecurityToken(
nameSpace,
name,
ticker,
totalSupply,
0,
issuer1,
numberOfSecurityTypes,
{
from : issuer1
})
} catch(error) {
ensureException(error);
}
});
it("createSecurityToken:should fail when ticker name is already exist", async () => {
await polyToken.getTokens(getAmount, issuer1, { from : issuer1 });
await polyToken.getTokens(getAmount, issuer2, { from : issuer2 });
let issuerBalance1 = await polyToken.balanceOf(issuer1);
let issuerBalance2 = await polyToken.balanceOf(issuer2);
assert.strictEqual(issuerBalance1.toNumber(), getAmount);
assert.strictEqual(issuerBalance2.toNumber(), getAmount);
await polyToken.approve(STRegistrar.address, approvedAmount, { from : issuer1 });
await polyToken.approve(STRegistrar.address, approvedAmount, { from : issuer2 });
let allowedToken1 = await polyToken.allowance(issuer1, STRegistrar.address);
assert.strictEqual(allowedToken1.toNumber(), approvedAmount);
let allowedToken2 = await polyToken.allowance(issuer2, STRegistrar.address);
assert.strictEqual(allowedToken2.toNumber(), approvedAmount);
// Create name space
await STRegistrar.createNameSpace(
nameSpaceMixed,
nameSpaceFee,
{
from:nameSpaceOwner
}
)
let ST = await STRegistrar.createSecurityToken(
nameSpace,
name,
ticker,
totalSupply,
0,
issuer1,
numberOfSecurityTypes,
{
from : issuer1
});
let STAddress = await STRegistrar.getSecurityTokenAddress.call(nameSpace, ticker);
assert.notEqual(web3.eth.getCode(STAddress),0x0);
try{
let ST = await STRegistrar.createSecurityToken(
nameSpace,
name,
ticker,
totalSupply,
0,
issuer2,
numberOfSecurityTypes,
{
from : issuer2
});
} catch(error){
ensureException(error);
}
});
it('createSecurityToken:should fail when the approved quantity is less than the fee', async () => {
await polyToken.getTokens(getAmount, issuer1, {from : issuer1 });
await polyToken.approve(STRegistrar.address, 1000, {from:issuer1});
// Create name space
await STRegistrar.createNameSpace(
nameSpaceMixed,
nameSpaceFee,
{
from:nameSpaceOwner
}
)
try {
let ST = await STRegistrar.createSecurityToken(
nameSpace,
name,
ticker,
totalSupply,
0,
issuer1,
numberOfSecurityTypes,
{
from: issuer1
});
} catch(error) {
ensureException(error);
}
});
it("createSecurityToken:should fail when the security registrar haven't approved to spent the poly" , async () => {
await polyToken.getTokens(getAmount, issuer1, {from : issuer1});
// Create name space
await STRegistrar.createNameSpace(
nameSpaceMixed,
nameSpaceFee,
{
from:nameSpaceOwner
}
)
try {
let ST = await STRegistrar.createSecurityToken(
nameSpace,
name,
ticker,
totalSupply,
issuer1,
0,
numberOfSecurityTypes,
{
from : issuer1
});
} catch(error) {
ensureException(error);
}
});
it("changeNameSpace: Should able to change the name space fee", async () => {
// Create name space
await STRegistrar.createNameSpace(
nameSpaceMixed,
nameSpaceFee,
{
from: nameSpaceOwner
}
);
//change name space fee
await STRegistrar.changeNameSpace(
nameSpaceMixed,
100,
{
from: nameSpaceOwner
}
);
let data = await STRegistrar.getNameSpaceData(nameSpaceMixed);
assert.equal(data[1], 100);
});
it("changeNameSpace: Create security token after changing the name space fee", async () => {
// Allowance Provided to SecurityToken Registrar contract
await polyToken.getTokens(getAmount, issuer1, { from : issuer1 });
let issuerBalance = await polyToken.balanceOf(issuer1);
assert.strictEqual(issuerBalance.toNumber(),getAmount);
await polyToken.approve(STRegistrar.address, approvedAmount, { from : issuer1 });
let allowedToken = await polyToken.allowance(issuer1, STRegistrar.address);
assert.strictEqual(allowedToken.toNumber(),approvedAmount);
// Create name space
await STRegistrar.createNameSpace(
nameSpaceMixed,
nameSpaceFee,
{
from: nameSpaceOwner
}
)
// Creation of the Security Token
let ST = await STRegistrar.createSecurityToken(
nameSpace,
name,
ticker,
totalSupply,
0,
issuer1,
numberOfSecurityTypes,
{
from: issuer1,
},
);
let STAddress = await STRegistrar.getSecurityTokenAddress.call(nameSpace, ticker);
assert.notEqual(STAddress, 0x0);
let STData = await STRegistrar.getSecurityTokenData.call(STAddress);
assert.strictEqual(STData[1], ticker);
//change name space fee
await STRegistrar.changeNameSpace(
nameSpaceMixed,
100,
{
from: nameSpaceOwner
}
);
let data = await STRegistrar.getNameSpaceData(nameSpaceMixed);
assert.equal(data[1], 100);
await polyToken.approve(STRegistrar.address, approvedAmount, { from : issuer1 });
// Creation of the Security Token
await STRegistrar.createSecurityToken(
nameSpace,
name,
"TICK",
totalSupply,
0,
issuer1,
numberOfSecurityTypes,
{
from: issuer1,
},
);
let STAddress_new = await STRegistrar.getSecurityTokenAddress.call(nameSpace, "TICK");
assert.notEqual(STAddress, 0x0);
let STData_new = await STRegistrar.getSecurityTokenData.call(STAddress_new);
assert.strictEqual(STData_new[1], "TICK");
});
});
});
});