Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Commit 2e1e1fb

Browse files
committed
compliance functions done except subscribe and unsubscribe
1 parent 3b0590f commit 2e1e1fb

File tree

2 files changed

+130
-20
lines changed

2 files changed

+130
-20
lines changed

src/contract_wrappers/Compliance.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,21 @@ export default class Compliance extends ContractWrapper {
168168

169169
/**
170170
* Set an STO contract to be stored in the offerings mapping in Compliance.sol
171-
* @param issuerAddress Address of the offering contract owner or auditor
171+
* @param stoDeveloperAddress Address of the creator of the STO
172172
* @param stoAddress Address of the STO contract deployed over the network
173173
* @param fee Fee to be paid in poly to use that contract
174174
* @param vestingPeriod Number of days investor binded to hold the Security token
175175
* @param quorum Minimum percent of shareholders which need to vote to freeze
176176
*/
177177
async setSTO(
178-
issuerAddress: string,
178+
stoDeveloperAddress: string,
179179
stoAddress: string,
180180
fee: BigNumber,
181181
vestingPeriod: BigNumber,
182182
quorum: BigNumber,
183183
) {
184184
await this._contract.setSTO(stoAddress, fee, vestingPeriod, quorum, {
185-
from: issuerAddress,
185+
from: stoDeveloperAddress,
186186
gas: 200000,
187187
});
188188
}
@@ -306,4 +306,22 @@ export default class Compliance extends ContractWrapper {
306306
expires: template[3],
307307
};
308308
}
309+
310+
/**
311+
* Returns all Template proposals
312+
* @return An array of addresses
313+
*/
314+
async getAllTemplateProposals(securityTokenAddress: string): Promise<Array<string>> {
315+
return (await this._contract.getAllTemplateProposals.call(securityTokenAddress));
316+
}
317+
318+
/**
319+
* Returns all STO proposal addresses
320+
* @return An array of addresses
321+
*/
322+
async getAllOfferingProposals(securityTokenAddress: string): Promise<Array<string>> {
323+
return (await this._contract.getAllOfferingProposals.call(securityTokenAddress));
324+
}
325+
326+
309327
}

test/Compliance_test.js

Lines changed: 109 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import {
1313
makeSecurityTokenRegistrar,
1414
makeTemplateWithFinalized,
1515
makeSecurityTokenThroughRegistrar,
16+
makeSelectedTemplateForSecurityToken,
17+
makeSecurityTokenOffering,
1618
} from './util/make_examples';
1719
import { makeWeb3Wrapper } from './util/web3';
18-
import { fakeAddress } from './util/fake';
20+
import { fakeAddress, fakeBytes32 } from './util/fake';
1921

2022
const { assert } = chai;
2123

@@ -67,6 +69,14 @@ describe('Compliance wrapper', () => {
6769
new BigNumber(10).toPower(18).times(100000),
6870
accounts[2],
6971
);
72+
await polyToken.generateNewTokens(
73+
new BigNumber(10).toPower(18).times(100000),
74+
accounts[3],
75+
);
76+
await polyToken.generateNewTokens(
77+
new BigNumber(10).toPower(18).times(100000),
78+
accounts[4],
79+
);
7080
});
7181

7282
it('createTemplate', async () => {
@@ -81,7 +91,7 @@ describe('Compliance wrapper', () => {
8191
assert.isAbove(templateAddress.length, 0);
8292
});
8393

84-
it('proposeTemplate, templateReputation, getTemplateAddressByProposal, cancelTemplateProposal', async () => {
94+
it('proposeTemplate, templateReputation, getTemplateAddressByProposal, cancelTemplateProposal, getAllTemplateProposals', async () => {
8595
await makeKYCProvider(customers, accounts[1]);
8696
await makeLegalDelegate(polyToken, customers, accounts[1], accounts[2]);
8797
const templateAddress = await makeTemplateWithFinalized(
@@ -93,7 +103,7 @@ describe('Compliance wrapper', () => {
93103
// Propose Template
94104
await compliance.proposeTemplate(accounts[2], securityToken.address, templateAddress);
95105
const logs = await compliance.getLogs('LogNewTemplateProposal', {}, { fromBlock: 1 });
96-
assert.equal(logs[0].args._template, templateAddress, 'Template address does not match the logged version');
106+
assert.equal(logs[0].args._template, templateAddress, 'Template address does not match the logged version');
97107

98108
// Reputation
99109
let templateReputation = await compliance.getTemplateReputation(templateAddress);
@@ -103,8 +113,12 @@ describe('Compliance wrapper', () => {
103113
const address = await compliance.getTemplateAddressByProposal(securityToken.address, 0)
104114
assert.equal(address, templateAddress, 'Proposal returned the wrong template address');
105115

116+
//Test all templateProposals
117+
let arrayOfTemplates = await compliance.getAllTemplateProposals(securityToken.address)
118+
assert.equal(arrayOfTemplates[0], templateAddress, 'Template address does not match the getter function return');
119+
106120
// Cancel Proposal
107-
await compliance.cancelTemplateProposal(accounts[2],securityToken.address, 0);
121+
await compliance.cancelTemplateProposal(accounts[2], securityToken.address, 0);
108122

109123
const addressShouldBeZero = await compliance.getTemplateAddressByProposal(securityToken.address, 0)
110124
assert.equal(addressShouldBeZero, 0, 'Proposal returned the wrong template address');
@@ -113,25 +127,103 @@ describe('Compliance wrapper', () => {
113127

114128
});
115129

116-
it('setSTO', async () => {
117-
await makeKYCProvider(customers, accounts[1]);
118-
119-
await compliance.setSTO(
120-
accounts[0],
121-
fakeAddress,
122-
new BigNumber(10),
123-
new BigNumber(9888888),
124-
new BigNumber(20),
125-
);
126-
});
127130

128131
it('getMinimumVestingPeriod', async () => {
129132
let minimum = await compliance.getMinimumVestingPeriod();
130133
assert.equal(minimum, 60 * 60 * 24 * 100, "Does not equal 100 days, when it should")
131134
})
132135

133-
// it('getTemplateReputation', async() => {
136+
//so we need to have a securityToken actually created through STRegistrar
137+
//and so me of the stuff has to match up
138+
//then we have an actual one in offeringProposals
139+
it('setSTO, proposeSTO, cancleSTO, getSTOProposal, getSTOAddressByProposal, getAllOfferingProposals', async () => {
140+
const owner = accounts[0];
141+
const legalDelegate = accounts[2];
142+
const kycProvider = accounts[1];
143+
144+
// STO variables
145+
const auditor = accounts[4];
146+
const startTime = new BigNumber(
147+
Math.floor(new Date().getTime() / 1000)
148+
).plus(200);
149+
150+
const endTime = new BigNumber(Math.floor(new Date().getTime() / 1000)).plus(
151+
2592000,
152+
); // 1 Month duration
153+
154+
await makeKYCProvider(customers, kycProvider);
155+
156+
await makeLegalDelegate(polyToken, customers, kycProvider, legalDelegate);
157+
const templateAddress = await makeTemplateWithFinalized(
158+
compliance,
159+
kycProvider,
160+
legalDelegate,
161+
);
162+
163+
await makeSelectedTemplateForSecurityToken(
164+
securityToken,
165+
compliance,
166+
polyToken,
167+
owner,
168+
legalDelegate,
169+
kycProvider,
170+
fakeBytes32,
171+
templateAddress,
172+
);
173+
174+
await polyToken.approve(auditor, customers.address, 100);
175+
176+
await customers.verifyCustomer(
177+
kycProvider,
178+
auditor,
179+
'US',
180+
'CA',
181+
'investor',
182+
true,
183+
new BigNumber(Math.floor(new Date().getTime() / 1000)).plus(10000),
184+
);
185+
186+
//this make example does setSTO and proposeSTO, and we will test below
187+
const offering = await makeSecurityTokenOffering(
188+
web3Wrapper,
189+
polyToken,
190+
securityToken,
191+
compliance,
192+
auditor,
193+
startTime,
194+
endTime,
195+
);
196+
197+
//to confirm setSTO, we need to check offerings for the msg.sender addr
198+
//which is using getOfferingByProposal
199+
//in setSTO we
200+
let getSTO = await compliance.getSTOProposal(securityToken.address, 0)
201+
assert.equal(getSTO.auditorAddress, auditor, "Auditor address not read properly");
202+
203+
//to confirm proposeSTO worked, we check offeringProposals, which is getSTOAddress by proposal
204+
let getSTOProposal = await compliance.getSTOAddressByProposal(securityToken.address, 0)
205+
assert.equal(getSTOProposal, getSTO.stoContractAddress, "STO address not read properly");
206+
207+
let getAllOfferings = await compliance.getAllOfferingProposals(securityToken.address, 0)
208+
assert.equal(getAllOfferings[0], getSTO.stoContractAddress, "STO array of addresses not read properly");
209+
210+
// Cancel Proposal
211+
await compliance.cancelSTOProposal(auditor, securityToken.address, 0);
212+
213+
const addressShouldBeZero = await compliance.getSTOAddressByProposal(securityToken.address, 0)
214+
console.log(addressShouldBeZero)
215+
assert.equal(addressShouldBeZero, 0, 'Proposal did not return zero, which it should have for being cancelled');
216+
217+
218+
219+
})
220+
221+
it('getAllOfferingProposals', async () => {
222+
223+
})
224+
225+
it('subscribe, unsubscribe, unsubscribeAll', async () => {
134226

135-
// })
227+
})
136228

137229
});

0 commit comments

Comments
 (0)