@@ -8,6 +8,9 @@ interface NoirOption<T> {
88 _value : T ;
99}
1010
11+ const sortFunc = ( a : any , b : any ) =>
12+ a . points > b . points ? 1 : a . points < b . points ? - 1 : a . randomness > b . randomness ? 1 : - 1 ;
13+
1114function unwrapOptions < T > ( options : NoirOption < T > [ ] ) : T [ ] {
1215 return options . filter ( ( option : any ) => option . _is_some ) . map ( ( option : any ) => option . _value ) ;
1316}
@@ -28,9 +31,17 @@ describe('e2e_note_getter', () => {
2831 afterAll ( ( ) => teardown ( ) ) ;
2932
3033 it ( 'inserts notes from 0-9, then makes multiple queries specifying the total suite of comparators' , async ( ) => {
31- const numbers = [ ...Array ( 10 ) . keys ( ) ] ;
32- await Promise . all ( numbers . map ( number => contract . methods . insert_note ( number ) . send ( ) . wait ( ) ) ) ;
33- await contract . methods . insert_note ( 5 ) . send ( ) . wait ( ) ;
34+ // ISSUE #4243
35+ // Calling this function does not work like this
36+ // const numbers = [...Array(10).keys()];
37+ // await Promise.all(numbers.map(number => contract.methods.insert_note(number).send().wait()));
38+ // It causes a race condition complaining about root mismatch
39+
40+ await contract . methods
41+ . insert_notes ( [ ...Array ( 10 ) . keys ( ) ] )
42+ . send ( )
43+ . wait ( ) ;
44+ await contract . methods . insert_note ( 5 , Fr . ZERO ) . send ( ) . wait ( ) ;
3445
3546 const [ returnEq , returnNeq , returnLt , returnGt , returnLte , returnGte ] = await Promise . all ( [
3647 contract . methods . read_note ( 5 , Comparator . EQ ) . view ( ) ,
@@ -41,15 +52,21 @@ describe('e2e_note_getter', () => {
4152 contract . methods . read_note ( 5 , Comparator . GTE ) . view ( ) ,
4253 ] ) ;
4354
44- expect ( unwrapOptions ( returnEq ) . map ( ( { points, randomness } : any ) => ( { points, randomness } ) ) ) . toStrictEqual ( [
45- { points : 5n , randomness : 1n } ,
46- { points : 5n , randomness : 1n } ,
47- ] ) ;
55+ expect (
56+ unwrapOptions ( returnEq )
57+ . map ( ( { points, randomness } : any ) => ( { points, randomness } ) )
58+ . sort ( sortFunc ) ,
59+ ) . toStrictEqual (
60+ [
61+ { points : 5n , randomness : 1n } ,
62+ { points : 5n , randomness : 0n } ,
63+ ] . sort ( sortFunc ) ,
64+ ) ;
4865
4966 expect (
5067 unwrapOptions ( returnNeq )
5168 . map ( ( { points, randomness } : any ) => ( { points, randomness } ) )
52- . sort ( ( a : any , b : any ) => ( a . points > b . points ? 1 : - 1 ) ) ,
69+ . sort ( sortFunc ) ,
5370 ) . toStrictEqual (
5471 [
5572 { points : 0n , randomness : 1n } ,
@@ -61,65 +78,65 @@ describe('e2e_note_getter', () => {
6178 { points : 8n , randomness : 1n } ,
6279 { points : 4n , randomness : 1n } ,
6380 { points : 3n , randomness : 1n } ,
64- ] . sort ( ( a : any , b : any ) => ( a . points > b . points ? 1 : - 1 ) ) ,
81+ ] . sort ( sortFunc ) ,
6582 ) ;
6683
6784 expect (
6885 unwrapOptions ( returnLt )
6986 . map ( ( { points, randomness } : any ) => ( { points, randomness } ) )
70- . sort ( ( a : any , b : any ) => ( a . points > b . points ? 1 : - 1 ) ) ,
87+ . sort ( sortFunc ) ,
7188 ) . toStrictEqual (
7289 [
7390 { points : 0n , randomness : 1n } ,
7491 { points : 1n , randomness : 1n } ,
7592 { points : 2n , randomness : 1n } ,
7693 { points : 4n , randomness : 1n } ,
7794 { points : 3n , randomness : 1n } ,
78- ] . sort ( ( a : any , b : any ) => ( a . points > b . points ? 1 : - 1 ) ) ,
95+ ] . sort ( sortFunc ) ,
7996 ) ;
8097
8198 expect (
8299 unwrapOptions ( returnGt )
83100 . map ( ( { points, randomness } : any ) => ( { points, randomness } ) )
84- . sort ( ( a : any , b : any ) => ( a . points > b . points ? 1 : - 1 ) ) ,
101+ . sort ( sortFunc ) ,
85102 ) . toStrictEqual (
86103 [
87104 { points : 7n , randomness : 1n } ,
88105 { points : 9n , randomness : 1n } ,
89106 { points : 6n , randomness : 1n } ,
90107 { points : 8n , randomness : 1n } ,
91- ] . sort ( ( a : any , b : any ) => ( a . points > b . points ? 1 : - 1 ) ) ,
108+ ] . sort ( sortFunc ) ,
92109 ) ;
93110
94111 expect (
95112 unwrapOptions ( returnLte )
96113 . map ( ( { points, randomness } : any ) => ( { points, randomness } ) )
97- . sort ( ( a : any , b : any ) => ( a . points > b . points ? 1 : - 1 ) ) ,
114+ . sort ( sortFunc ) ,
98115 ) . toStrictEqual (
99116 [
100117 { points : 5n , randomness : 1n } ,
101- { points : 5n , randomness : 1n } ,
118+ { points : 5n , randomness : 0n } ,
102119 { points : 0n , randomness : 1n } ,
103120 { points : 1n , randomness : 1n } ,
104121 { points : 2n , randomness : 1n } ,
105122 { points : 4n , randomness : 1n } ,
106123 { points : 3n , randomness : 1n } ,
107- ] . sort ( ( a : any , b : any ) => ( a . points > b . points ? 1 : - 1 ) ) ,
124+ ] . sort ( sortFunc ) ,
108125 ) ;
109126
110127 expect (
111128 unwrapOptions ( returnGte )
112129 . map ( ( { points, randomness } : any ) => ( { points, randomness } ) )
113- . sort ( ( a : any , b : any ) => ( a . points > b . points ? 1 : - 1 ) ) ,
130+ . sort ( sortFunc ) ,
114131 ) . toStrictEqual (
115132 [
116- { points : 5n , randomness : 1n } ,
133+ { points : 5n , randomness : 0n } ,
117134 { points : 5n , randomness : 1n } ,
118135 { points : 7n , randomness : 1n } ,
119136 { points : 9n , randomness : 1n } ,
120137 { points : 6n , randomness : 1n } ,
121138 { points : 8n , randomness : 1n } ,
122- ] . sort ( ( a : any , b : any ) => ( a . points > b . points ? 1 : - 1 ) ) ,
139+ ] . sort ( sortFunc ) ,
123140 ) ;
124141 } , 300_000 ) ;
125142} ) ;
0 commit comments