@@ -18,7 +18,7 @@ import {
1818 makeSelectedTemplateForSecurityToken ,
1919 makeSecurityTokenOffering ,
2020} from './util/make_examples' ;
21- import { makeWeb3Wrapper } from './util/web3' ;
21+ import { makeWeb3Wrapper , makeWeb3 } from './util/web3' ;
2222import { fakeAddress , fakeBytes32 } from './util/fake' ;
2323
2424const { assert } = chai ;
@@ -97,6 +97,42 @@ describe('Compliance wrapper', () => {
9797 } ) ;
9898
9999 it ( 'proposeTemplate, templateReputation, getTemplateAddressByProposal, cancelTemplateProposal, getAllTemplateProposals' , async ( ) => {
100+
101+
102+ //subscribtion setup
103+ let subscriptionID2 = null ;
104+ const eventName2 = 'LogNewTemplateProposal' ;
105+ const indexedFilterValues2 = [ "_securityToken" ] ;
106+
107+ //the callback is passed into the filter.watch function and is operated on when a new event comes in
108+ const logNewTemplateProposalArgsPromise = new Promise ( ( resolve , reject ) => {
109+
110+ subscriptionID2 = compliance . subscribe ( eventName2 , indexedFilterValues2 , ( err , log ) => {
111+ if ( err !== null ) {
112+ reject ( err ) ;
113+ return ;
114+ }
115+ resolve ( log . args ) ;
116+ } ) ;
117+ } ) ;
118+
119+ //subscribtion setup
120+ let subscriptionID4 = null ;
121+ const eventName4 = 'LogCancelTemplateProposal' ;
122+ const indexedFilterValues4 = [ "_securityToken" ] ;
123+
124+ //the callback is passed into the filter.watch function, and is operated on when a new event comes in
125+ const logCancleTemplateProposalArgsPromise = new Promise ( ( resolve , reject ) => {
126+
127+ subscriptionID4 = compliance . subscribe ( eventName4 , indexedFilterValues4 , ( err , log ) => {
128+ if ( err !== null ) {
129+ reject ( err ) ;
130+ return ;
131+ }
132+ resolve ( log . args ) ;
133+ } ) ;
134+ } ) ;
135+
100136 await makeKYCProvider ( customers , accounts [ 1 ] , expiryTime ) ;
101137 await makeLegalDelegate ( polyToken , customers , accounts [ 1 ] , accounts [ 2 ] , expiryTime ) ;
102138 const templateAddress = await makeTemplateWithFinalized (
@@ -107,11 +143,17 @@ describe('Compliance wrapper', () => {
107143
108144 ) ;
109145
146+
110147 // Propose Template
111148 await compliance . proposeTemplate ( accounts [ 2 ] , securityToken . address , templateAddress ) ;
112149 const logs = await compliance . getLogs ( 'LogNewTemplateProposal' , { } , { fromBlock : 1 } ) ;
113150 assert . equal ( logs [ 0 ] . args . _template , templateAddress , 'Template address does not match the logged version' ) ;
114151
152+
153+ let logNewTemplateProposal = await logNewTemplateProposalArgsPromise ;
154+ assert . equal ( logNewTemplateProposal . _securityToken , securityToken . address , 'ST address not picked up from LogNewTemplateProposal event' ) //needs to be renamed from core
155+
156+
115157 // Reputation
116158 let templateReputation = await compliance . getTemplateReputation ( templateAddress ) ;
117159 assert . equal ( templateReputation . owner , accounts [ 2 ] , "TemplateReputation not stored or read properly" ) ;
@@ -124,30 +166,72 @@ describe('Compliance wrapper', () => {
124166 let arrayOfTemplates = await compliance . getAllTemplateProposals ( securityToken . address )
125167 assert . equal ( arrayOfTemplates [ 0 ] , templateAddress , 'Template address does not match the getter function return' ) ;
126168
127- // Cancel Proposal
169+
128170 await compliance . cancelTemplateProposal ( accounts [ 2 ] , securityToken . address , 0 ) ;
129171
172+ let logCancleTemplateProposal = await logCancleTemplateProposalArgsPromise ;
173+ assert . equal ( logNewTemplateProposal . _securityToken , securityToken . address , 'ST address not picked up from LogCancleTemplateProposal event' ) //needs to be renamed from core
174+
130175 const addressShouldBeZero = await compliance . getTemplateAddressByProposal ( securityToken . address , 0 )
131176 assert . equal ( addressShouldBeZero , 0 , 'Proposal returned the wrong template address' ) ;
132177
178+ await compliance . unsubscribeAll ( ) ;
133179
134-
135- } ) ;
180+ } ) ;
136181
137182
138183 it ( 'getMinimumVestingPeriod' , async ( ) => {
139184 let minimum = await compliance . getMinimumVestingPeriod ( ) ;
140185 assert . equal ( minimum , 60 * 60 * 24 * 100 , "Does not equal 100 days, when it should" )
141186 } )
142187
143- //so we need to have a securityToken actually created through STRegistrar
144- //and so me of the stuff has to match up
145- //then we have an actual one in offeringProposals
188+ // so we need to have a securityToken actually created through STRegistrar
189+ // and so me of the stuff has to match up
190+ // then we have an actual one in offeringProposals
146191 it ( 'setSTO, proposeSTO, cancleSTO, getSTOProposal, getSTOAddressByProposal, getAllOfferingProposals' , async ( ) => {
192+
193+ //subscribtion setup
194+ let subscriptionID3 = null ;
195+ const eventName3 = 'LogNewContractProposal' ;
196+ const indexedFilterValues3 = [ "_securityToken" ] ;
197+
198+ //the callback is passed into the filter.watch function, and is operated on when a new event comes in
199+ const logNewContractProposalArgsPromise = new Promise ( ( resolve , reject ) => {
200+
201+ subscriptionID3 = compliance . subscribe ( eventName3 , indexedFilterValues3 , ( err , log ) => {
202+ if ( err !== null ) {
203+ reject ( err ) ;
204+ return ;
205+ }
206+ resolve ( log . args ) ;
207+ } ) ;
208+ } ) ;
209+
210+
211+
212+ //subscribtion setup
213+ let subscriptionID5 = null ;
214+ const eventName5 = 'LogCancelContractProposal' ;
215+ const indexedFilterValues5 = [ "_securityToken" ] ;
216+
217+ //the callback is passed into the filter.watch function, and is operated on when a new event comes in
218+ const logCancleContractProposalArgsPromise = new Promise ( ( resolve , reject ) => {
219+
220+ subscriptionID5 = compliance . subscribe ( eventName5 , indexedFilterValues5 , ( err , log ) => {
221+ if ( err !== null ) {
222+ reject ( err ) ;
223+ return ;
224+ }
225+ resolve ( log . args ) ;
226+ } ) ;
227+ } ) ;
228+
229+
147230 const owner = accounts [ 0 ] ;
148231 const legalDelegate = accounts [ 2 ] ;
149232 const kycProvider = accounts [ 1 ] ;
150233
234+
151235 // STO variables
152236 const auditor = accounts [ 4 ] ;
153237 const startTime = new BigNumber (
@@ -160,11 +244,12 @@ describe('Compliance wrapper', () => {
160244
161245 await makeKYCProvider ( customers , kycProvider ) ;
162246
163- await makeLegalDelegate ( polyToken , customers , kycProvider , legalDelegate ) ;
247+ await makeLegalDelegate ( polyToken , customers , accounts [ 1 ] , accounts [ 2 ] , expiryTime ) ;
164248 const templateAddress = await makeTemplateWithFinalized (
165249 compliance ,
166250 kycProvider ,
167251 legalDelegate ,
252+ expiryTime ,
168253 ) ;
169254
170255 await makeSelectedTemplateForSecurityToken (
@@ -201,6 +286,10 @@ describe('Compliance wrapper', () => {
201286 endTime ,
202287 ) ;
203288
289+
290+ let logNewContractProposal = await logNewContractProposalArgsPromise ;
291+ assert . equal ( logNewContractProposal . _delegate , auditor , 'legal delegate not picked up from LogNewProposal event' ) //needs to be renamed from core
292+
204293 //to confirm setSTO, we need to check offerings for the msg.sender addr
205294 //which is using getOfferingByProposal
206295 //in setSTO we
@@ -214,96 +303,62 @@ describe('Compliance wrapper', () => {
214303 let getAllOfferings = await compliance . getAllOfferingProposals ( securityToken . address , 0 )
215304 assert . equal ( getAllOfferings [ 0 ] , getSTO . stoContractAddress , "STO array of addresses not read properly" ) ;
216305
306+
217307 // Cancel Proposal
218308 await compliance . cancelSTOProposal ( auditor , securityToken . address , 0 ) ;
219309
310+ //LOGCANCLESTOPROPOSAL
311+ let logCancleContractProposal = await logCancleContractProposalArgsPromise ;
312+ assert . equal ( logNewContractProposal . _securityToken , securityToken . address , 'ST address not picked up from LogCancleContractProposal event' ) //needs to be renamed from core
313+
314+
315+
220316 const addressShouldBeZero = await compliance . getSTOAddressByProposal ( securityToken . address , 0 )
221- console . log ( addressShouldBeZero )
222317 assert . equal ( addressShouldBeZero , 0 , 'Proposal did not return zero, which it should have for being cancelled' ) ;
223318
319+ await compliance . unsubscribe ( subscriptionID3 ) ;
320+ await compliance . unsubscribe ( subscriptionID5 ) ;
224321
225322
226323 } )
227324
228- it ( 'subscribe, unsubscribe, unsubscribeAll' , async ( ) => {
229-
230- //LogTemplateCreated
231- //LogNewTemplateProposal
232- //LogCancleTemplateProposal
233- //LogNewContractProposal
234- //LogCancleContractProposal
235-
236- it ( 'subscribe, unsubscribe, unsubscribeAll' , async ( ) => {
237-
238- //subscribtion setup
239- let subscriptionID1 = null ;
240- const eventName1 = 'LogTemplateCreated' ;
241- const indexedFilterValues1 = [ "_creator" ] ;
242- const expiryTime = new BigNumber ( web3 . eth . getBlock ( 'latest' ) . timestamp ) . plus ( 10000 ) ;
243- //the callback is passed into the filter.watch function, and is operated on when a new event comes in
244- const logTemplateCreatedArgsPromise = new Promise ( ( resolve , reject ) => {
245- subscriptionID1 = compliance . subscribe ( eventName1 , indexedFilterValues1 , ( err , log ) => {
246- if ( err !== null ) {
247- reject ( err ) ;
248- return ;
249- }
250- resolve ( log . args ) ;
251- } ) ;
325+ it ( 'LogTemplateCreated event test, subscribe, unsubscribe' , async ( ) => {
326+
327+ //subscribtion setup
328+ let subscriptionID1 = null ;
329+ const eventName1 = 'LogTemplateCreated' ;
330+ const indexedFilterValues1 = [ "_creator" ] ;
331+ const expiryTime = new BigNumber ( web3 . eth . getBlock ( 'latest' ) . timestamp ) . plus ( 10000 ) ;
332+ //the callback is passed into the filter.watch function, and is operated on when a new event comes in
333+ const logTemplateCreatedArgsPromise = new Promise ( ( resolve , reject ) => {
334+ subscriptionID1 = compliance . subscribe ( eventName1 , indexedFilterValues1 , ( err , log ) => {
335+ if ( err !== null ) {
336+ reject ( err ) ;
337+ return ;
338+ }
339+ resolve ( log . args ) ;
252340 } ) ;
341+ } ) ;
253342
254- //subscribtion setup
255- let subscriptionID2 = null ;
256- const eventName2 = 'LogNewTemplateProposal' ;
257- const indexedFilterValues2 = "_securityToken" ;
258-
259- //the callback is passed into the filter.watch function, and is operated on when a new event comes in
260- const logNewTemplateProposalArgsPromise = new Promise ( ( resolve , reject ) => {
261-
262- subscriptionID2 = compliance . subscribe ( eventName2 , indexedFilterValues2 , ( err , log ) => {
263- if ( err !== null ) {
264- reject ( err ) ;
265- return ;
266- }
267- resolve ( log . args ) ;
268- } ) ;
269- } ) ;
270-
271- //subscribtion setup
272- let subscriptionID3 = null ;
273- const eventName3 = 'LogNewContractProposal' ;
274- const indexedFilterValues3 = [ "_securityToken" ] ;
275-
276- //the callback is passed into the filter.watch function, and is operated on when a new event comes in
277- const logNewContractProposalArgsPromise = new Promise ( ( resolve , reject ) => {
278-
279- subscriptionID3 = compliance . subscribe ( eventName3 , indexedFilterValues3 , ( err , log ) => {
280- if ( err !== null ) {
281- reject ( err ) ;
282- return ;
283- }
284- resolve ( log . args ) ;
285- } ) ;
286- } ) ;
343+ await makeKYCProvider ( customers , accounts [ 1 ] , expiryTime ) ;
344+ await makeLegalDelegate ( polyToken , customers , accounts [ 1 ] , accounts [ 2 ] , expiryTime ) ;
345+ const templateAddress = await makeTemplate (
346+ compliance ,
347+ accounts [ 1 ] ,
348+ accounts [ 2 ] ,
349+ expiryTime ,
350+ ) ;
287351
288- await makeKYCProvider ( customers , accounts [ 1 ] , expiryTime ) ;
289- await makeLegalDelegate ( polyToken , customers , accounts [ 1 ] , accounts [ 2 ] , expiryTime ) ;
290- const templateAddress = await makeTemplate (
291- compliance ,
292- accounts [ 1 ] ,
293- accounts [ 2 ] ,
294- expiryTime ,
295- ) ;
296352
353+ const logTemplateCreated = await logTemplateCreatedArgsPromise ;
354+ assert . equal ( logTemplateCreated . _creator , accounts [ 2 ] , 'legal delegate creator address wasnt found in event subscription' ) ; //'offeringtype' from make_examples.js
355+ assert . isAbove ( logTemplateCreated . _template . length , 20 , 'template address wasnt found in event subscription' ) ;
356+ assert . equal ( logTemplateCreated . _offeringType , "offeringtype" , 'offering type wasnt found in event subscription' ) ; //'offeringtype' from make_examples.js
357+ await compliance . unsubscribe ( subscriptionID1 ) ;
297358
298- const logTemplateCreated = await logTemplateCreatedArgsPromise ;
299- assert . equal ( logTemplateCreated . _creator , accounts [ 2 ] , 'legal delegate creator address wasnt found in event subscription' ) ; //'offeringtype' from make_examples.js
300- assert . isAbove ( logTemplateCreated . _template . length , 20 , 'template address wasnt found in event subscription' ) ;
301- assert . equal ( logTemplateCreated . _offeringType , "offeringtype" , 'offering type wasnt found in event subscription' ) ; //'offeringtype' from make_examples.js
302- await compliance . unsubscribe ( subscriptionID1 ) ;
303359
360+ } )
304361
305- } )
306362
307363
308- } )
309364} ) ;
0 commit comments