@@ -233,14 +233,29 @@ contract('Basket Escrow', (accounts) => {
233233 } catch ( err ) { assert . equal ( doesRevert ( err ) , true , 'did not revert as expected' ) ; }
234234 } ) ;
235235
236+ it ( 'creates and logs buy orders ' , async ( ) => {
237+ const instantExpiration = 0 ;
238+ try {
239+ // exact same params as last order
240+ nonce = Math . random ( ) * 1e7 ;
241+ const buyOrderParams = [
242+ basketABAddress , amountBasketsToBuy , instantExpiration , nonce ,
243+ { from : HOLDER_A , value : amountEthToSend , gas : 1e6 } ,
244+ ] ;
245+ await basketEscrow . createBuyOrder ( ...buyOrderParams ) ;
246+ } catch ( err ) { assert . equal ( doesRevert ( err ) , true , 'did not revert as expected' ) ; }
247+ } ) ;
248+
236249 after ( 'update nonce' , ( ) => { nonce = Math . random ( ) * 1e7 ; } ) ;
237250 } ) ;
238251
239252 describe ( 'Holder_A cancels expired buy order' , ( ) => {
253+ const timeDelta = 10 ; // expires in 10 seconds
254+
240255 before ( 'create second buy order and check initial balance' , async ( ) => {
241256 try {
242257 // set expiration time to now to ensure the order will expire
243- expirationInSeconds = 0 ;
258+ expirationInSeconds = ( new Date ( ) . getTime ( ) / 1000 ) + timeDelta ;
244259 const buyOrderParams = [
245260 basketABAddress , amountBasketsToBuy , expirationInSeconds , nonce ,
246261 { from : HOLDER_A , value : amountEthToSend , gas : 1e6 } ,
@@ -256,6 +271,12 @@ contract('Basket Escrow', (accounts) => {
256271 } catch ( err ) { assert . throw ( `Error creating second buy order: ${ err . toString ( ) } ` ) ; }
257272 } ) ;
258273
274+ it ( 'waits <timeDelta> seconds before proceeding' , async ( ) => {
275+ await new Promise ( ( resolve ) => {
276+ setTimeout ( ( ) => { resolve ( ) ; } , timeDelta * 1000 ) ;
277+ } ) ;
278+ } ) ;
279+
259280 it ( 'allows and logs cancellation of buy orders ' , async ( ) => {
260281 try {
261282 const cancelBuyParams = [
@@ -432,9 +453,11 @@ contract('Basket Escrow', (accounts) => {
432453 } ) ;
433454 } ) ;
434455
435- const instantExpiration = 0 ;
436456
437457 describe ( 'MARKET_MAKER fails to fill expired orders' , ( ) => {
458+ const timeDelta = 20 ; // 10 seconds
459+ const instantExpiration = ( new Date ( ) . getTime ( ) / 1000 ) + timeDelta ;
460+
438461 before ( 'creates an order that expires instantly' , async ( ) => {
439462 try {
440463 nonce = Math . random ( ) * 1e7 ;
@@ -443,17 +466,19 @@ contract('Basket Escrow', (accounts) => {
443466 { from : HOLDER_A , value : amountEthToSend , gas : 1e6 } ,
444467 ] ;
445468 await basketEscrow . createBuyOrder ( ...buyOrderParams ) ;
446- } catch ( err ) { assert . throw ( `Error in creating instantly expired order: ${ err . toString ( ) } ` ) ; }
469+ } catch ( err ) { assert . throw ( `Error in creating expired order: ${ err . toString ( ) } ` ) ; }
447470 } ) ;
448471
449472 it ( 'cannot fill an expired order' , async ( ) => {
450- try {
451- const fillBuyParams = [
452- HOLDER_B , basketABAddress , amountBasketsToBuy , amountEthToSend , instantExpiration , nonce ,
453- { from : MARKET_MAKER , gas : 1e6 } ,
454- ] ;
455- const _fillBuyResults = await basketEscrow . fillBuyOrder ( ...fillBuyParams ) ;
456- } catch ( err ) { assert . equal ( doesRevert ( err ) , true , 'did not revert as expected' ) ; }
473+ setTimeout ( async ( ) => {
474+ try {
475+ const fillBuyParams = [
476+ HOLDER_B , basketABAddress , amountBasketsToBuy , amountEthToSend , instantExpiration , nonce ,
477+ { from : MARKET_MAKER , gas : 1e6 } ,
478+ ] ;
479+ const _fillBuyResults = await basketEscrow . fillBuyOrder ( ...fillBuyParams ) ;
480+ } catch ( err ) { assert . equal ( doesRevert ( err ) , true , 'did not revert as expected' ) ; }
481+ } , timeDelta * 1000 ) ;
457482 } ) ;
458483 } ) ;
459484
0 commit comments