@@ -208,6 +208,50 @@ describe('preconditions', () => {
208
208
await expect ( tx . sign ( [ feePayer . key ] ) . send ( ) ) . rejects . toThrow ( / u n s a t i s f i e d / ) ;
209
209
} ) ;
210
210
211
+ it ( 'unsatisfied requireEquals should be overridden by requireNothing' , async ( ) => {
212
+ let nonce = contract . account . nonce . get ( ) ;
213
+ let publicKey = PublicKey . from ( { x : Field ( - 1 ) , isOdd : Bool ( false ) } ) ;
214
+
215
+ await Mina . transaction ( feePayer , async ( ) => {
216
+ for ( let precondition of implementedNumber ) {
217
+ let p = precondition ( ) . get ( ) ;
218
+ precondition ( ) . requireEquals ( p . add ( 1 ) as any ) ;
219
+ precondition ( ) . requireNothing ( ) ;
220
+ }
221
+ for ( let precondition of implementedBool ) {
222
+ let p = precondition ( ) . get ( ) ;
223
+ precondition ( ) . requireEquals ( p . not ( ) ) ;
224
+ precondition ( ) . requireNothing ( ) ;
225
+ }
226
+ contract . account . delegate . requireEquals ( publicKey ) ;
227
+ contract . account . delegate . requireNothing ( ) ;
228
+ contract . requireSignature ( ) ;
229
+ AccountUpdate . attachToTransaction ( contract . self ) ;
230
+ } )
231
+ . sign ( [ feePayer . key , contractAccount . key ] )
232
+ . send ( ) ;
233
+ // check that tx was applied, by checking nonce was incremented
234
+ expect ( contract . account . nonce . get ( ) ) . toEqual ( nonce . add ( 1 ) ) ;
235
+ } ) ;
236
+
237
+ it ( 'unsatisfied requireBetween should be overridden by requireNothing' , async ( ) => {
238
+ let nonce = contract . account . nonce . get ( ) ;
239
+
240
+ await Mina . transaction ( feePayer , async ( ) => {
241
+ for ( let precondition of implementedWithRange ) {
242
+ let p : any = precondition ( ) . get ( ) ;
243
+ precondition ( ) . requireBetween ( p . add ( 20 ) , p . add ( 30 ) ) ;
244
+ precondition ( ) . requireNothing ( ) ;
245
+ }
246
+ contract . requireSignature ( ) ;
247
+ AccountUpdate . attachToTransaction ( contract . self ) ;
248
+ } )
249
+ . sign ( [ feePayer . key , contractAccount . key ] )
250
+ . send ( ) ;
251
+ // check that tx was applied, by checking nonce was incremented
252
+ expect ( contract . account . nonce . get ( ) ) . toEqual ( nonce . add ( 1 ) ) ;
253
+ } ) ;
254
+
211
255
// TODO: is this a gotcha that should be addressed?
212
256
// the test below fails, so it seems that nonce is applied successfully with a WRONG precondition..
213
257
// however, this is just because `zkapp.requireSignature()` overwrites the nonce precondition with one that is satisfied
@@ -227,7 +271,6 @@ let implementedNumber = [
227
271
( ) => contract . account . receiptChainHash ,
228
272
( ) => contract . network . blockchainLength ,
229
273
( ) => contract . network . globalSlotSinceGenesis ,
230
- ( ) => contract . network . timestamp ,
231
274
( ) => contract . network . minWindowDensity ,
232
275
( ) => contract . network . totalCurrency ,
233
276
( ) => contract . network . stakingEpochData . epochLength ,
@@ -251,6 +294,7 @@ let implementedBool = [
251
294
let implemented = [
252
295
...implementedNumber ,
253
296
...implementedBool ,
297
+ ( ) => contract . network . timestamp ,
254
298
( ) => contract . account . delegate ,
255
299
] ;
256
300
let implementedWithRange = [
0 commit comments