@@ -17,7 +17,31 @@ const PROVIDER_URL = 'http://localhost:8545';
17
17
const BACKEND_URL = 'http://localhost:3030' ;
18
18
const deployKey = 'd9066ff9f753a1898709b568119055660a77d9aae4d7a4ad677b8fb3d2a571e5' ;
19
19
20
- describe ( 'Test StrategyBasedMatcher' , async ( ) => {
20
+ const sleep = ( ms : number ) => new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
21
+
22
+ async function waitForConditionAndAssert (
23
+ conditionCheckFunction : ( ) => Promise < boolean > | boolean ,
24
+ assertFunction : ( ) => Promise < void > | void ,
25
+ interval : number ,
26
+ timeout : number
27
+ ) : Promise < void > {
28
+ let timePassed = 0 ;
29
+
30
+ while ( timePassed < timeout ) {
31
+ if ( await conditionCheckFunction ( ) ) {
32
+ await assertFunction ( ) ;
33
+
34
+ return ;
35
+ }
36
+
37
+ await sleep ( interval ) ;
38
+ timePassed += interval ;
39
+ }
40
+
41
+ await assertFunction ( ) ;
42
+ }
43
+
44
+ describe . only ( 'Test StrategyBasedMatcher' , async ( ) => {
21
45
const web3 = new Web3 ( PROVIDER_URL ) ;
22
46
23
47
const privateKeyDeployment = deployKey . startsWith ( '0x' ) ? deployKey : `0x${ deployKey } ` ;
@@ -61,8 +85,6 @@ describe('Test StrategyBasedMatcher', async () => {
61
85
}
62
86
} ;
63
87
64
- const sleep = ( ms : number ) => new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
65
-
66
88
describe ( 'Setup' , ( ) => {
67
89
it ( 'should deploy user-registry contracts' , async ( ) => {
68
90
const userContracts = await migrateUserRegistryContracts ( web3 , privateKeyDeployment ) ;
@@ -360,11 +382,20 @@ describe('Test StrategyBasedMatcher', async () => {
360
382
privateKey : privateKeyDeployment
361
383
} ;
362
384
363
- await sleep ( 10000 ) ;
385
+ await waitForConditionAndAssert (
386
+ async ( ) => {
387
+ const certificate = await new Certificate . Entity ( '0' , conf ) . sync ( ) ;
364
388
365
- const certificate = await new Certificate . Entity ( '0' , conf ) . sync ( ) ;
366
- assert . equal ( certificate . owner , accountTrader ) ;
367
- } ) . timeout ( 11000 ) ;
389
+ return certificate . owner === accountTrader ;
390
+ } ,
391
+ async ( ) => {
392
+ const certificate = await new Certificate . Entity ( '0' , conf ) . sync ( ) ;
393
+ assert . equal ( certificate . owner , accountTrader ) ;
394
+ } ,
395
+ 1000 ,
396
+ 20000
397
+ ) ;
398
+ } ) . timeout ( 21000 ) ;
368
399
} ) ;
369
400
370
401
describe ( 'Agreement -> Certificate matching tests' , ( ) => {
@@ -541,10 +572,20 @@ describe('Test StrategyBasedMatcher', async () => {
541
572
it ( 'demand should be matched with existing certificate' , async ( ) => {
542
573
const demand = await new Demand . Entity ( '1' , conf ) . sync ( ) ;
543
574
544
- await sleep ( 10000 ) ;
575
+ await waitForConditionAndAssert (
576
+ async ( ) => {
577
+ const certificate = await new Certificate . Entity ( certificateId , conf ) . sync ( ) ;
545
578
546
- const certificate = await new Certificate . Entity ( certificateId , conf ) . sync ( ) ;
547
- assert . equal ( certificate . owner , demand . demandOwner ) ;
548
- } ) . timeout ( 15000 ) ;
579
+ return certificate . owner === demand . demandOwner ;
580
+ } ,
581
+ async ( ) => {
582
+ const certificate = await new Certificate . Entity ( certificateId , conf ) . sync ( ) ;
583
+
584
+ assert . equal ( certificate . owner , demand . demandOwner ) ;
585
+ } ,
586
+ 1000 ,
587
+ 20000
588
+ ) ;
589
+ } ) . timeout ( 30000 ) ;
549
590
} ) ;
550
591
} ) ;
0 commit comments