Skip to content

Commit cd6818c

Browse files
committed
unnecessary tests cleanup
1 parent 6e9c50d commit cd6818c

File tree

1 file changed

+25
-279
lines changed
  • noir-projects/noir-contracts/contracts/app/orderbook_contract/src

1 file changed

+25
-279
lines changed

noir-projects/noir-contracts/contracts/app/orderbook_contract/src/test.nr

Lines changed: 25 additions & 279 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ unconstrained fn setup_orderbook_with_tokens(
5858
}
5959

6060
// Utility function to mint tokens to private balance
61-
// Note: The minting must be done by the token owner (admin), not the recipient
6261
unconstrained fn mint_to_private(
6362
env: TestEnvironment,
6463
token_address: AztecAddress,
@@ -98,7 +97,7 @@ unconstrained fn check_public_balance(
9897
// Happy path tests
9998

10099
#[test]
101-
unconstrained fn test_create_order_happy_path() {
100+
unconstrained fn create_order_happy_path() {
102101
let (mut env, orderbook_address, token0_address, token1_address, owner, _) =
103102
setup_orderbook_with_tokens(true);
104103

@@ -136,7 +135,7 @@ unconstrained fn test_create_order_happy_path() {
136135
}
137136

138137
#[test]
139-
unconstrained fn test_fulfill_order_happy_path() {
138+
unconstrained fn full_flow() {
140139
let (mut env, orderbook_address, token0_address, token1_address, maker, _) =
141140
setup_orderbook_with_tokens(true);
142141

@@ -170,6 +169,15 @@ unconstrained fn test_fulfill_order_happy_path() {
170169
),
171170
);
172171

172+
// Get order and verify it's active
173+
let (order, is_fulfilled) =
174+
env.simulate_utility(Orderbook::at(orderbook_address).get_order(order_id));
175+
176+
assert_eq(order.bid_amount, bid_amount);
177+
assert_eq(order.ask_amount, ask_amount);
178+
assert_eq(order.bid_token_is_zero, true); // token0 -> token1
179+
assert_eq(is_fulfilled, false);
180+
173181
// Create authwit for taker to transfer ask tokens
174182
// Convert order_id back to PartialUintNote as the orderbook does
175183
let maker_partial_note = PartialUintNote::from_field(order_id);
@@ -197,12 +205,21 @@ unconstrained fn test_fulfill_order_happy_path() {
197205
check_private_balance(env, token1_address, maker, ask_amount);
198206
check_private_balance(env, token0_address, taker, bid_amount);
199207
check_private_balance(env, token1_address, taker, 0);
208+
209+
// Get order and verify it's fulfilled
210+
let (order, is_fulfilled) =
211+
env.simulate_utility(Orderbook::at(orderbook_address).get_order(order_id));
212+
213+
assert_eq(order.bid_amount, bid_amount);
214+
assert_eq(order.ask_amount, ask_amount);
215+
assert_eq(order.bid_token_is_zero, true); // token0 -> token1
216+
assert_eq(is_fulfilled, true);
200217
}
201218

202219
// Unhappy path tests for create_order
203220

204221
#[test(should_fail_with = "ZERO_BID_AMOUNT")]
205-
unconstrained fn test_create_order_zero_bid_amount() {
222+
unconstrained fn create_order_zero_bid_amount() {
206223
let (mut env, orderbook_address, token0_address, token1_address, owner, _) =
207224
setup_orderbook_with_tokens(false);
208225

@@ -224,7 +241,7 @@ unconstrained fn test_create_order_zero_bid_amount() {
224241
}
225242

226243
#[test(should_fail_with = "ZERO_ASK_AMOUNT")]
227-
unconstrained fn test_create_order_zero_ask_amount() {
244+
unconstrained fn create_order_zero_ask_amount() {
228245
let (mut env, orderbook_address, token0_address, token1_address, owner, _) =
229246
setup_orderbook_with_tokens(false);
230247

@@ -246,7 +263,7 @@ unconstrained fn test_create_order_zero_ask_amount() {
246263
}
247264

248265
#[test(should_fail_with = "BID_TOKEN_IS_INVALID")]
249-
unconstrained fn test_create_order_invalid_bid_token() {
266+
unconstrained fn create_order_invalid_bid_token() {
250267
let (mut env, orderbook_address, _token0_address, token1_address, owner, _) =
251268
setup_orderbook_with_tokens(false);
252269

@@ -269,7 +286,7 @@ unconstrained fn test_create_order_invalid_bid_token() {
269286
}
270287

271288
#[test(should_fail_with = "ASK_TOKEN_IS_INVALID")]
272-
unconstrained fn test_create_order_invalid_ask_token() {
289+
unconstrained fn create_order_invalid_ask_token() {
273290
let (mut env, orderbook_address, token0_address, _token1_address, owner, _) =
274291
setup_orderbook_with_tokens(false);
275292

@@ -292,7 +309,7 @@ unconstrained fn test_create_order_invalid_ask_token() {
292309
}
293310

294311
#[test(should_fail_with = "SAME_TOKEN_TRADE")]
295-
unconstrained fn test_create_order_same_tokens() {
312+
unconstrained fn create_order_same_tokens() {
296313
let (mut env, orderbook_address, token0_address, _token1_address, owner, _) =
297314
setup_orderbook_with_tokens(false);
298315

@@ -312,274 +329,3 @@ unconstrained fn test_create_order_same_tokens() {
312329
),
313330
);
314331
}
315-
316-
#[test(should_fail_with = "Balance too low")]
317-
unconstrained fn test_create_order_insufficient_balance() {
318-
let (mut env, orderbook_address, token0_address, token1_address, owner, _) =
319-
setup_orderbook_with_tokens(true);
320-
321-
let bid_amount = 1000 as u128;
322-
let ask_amount = 2000 as u128;
323-
let authwit_nonce = 1;
324-
325-
// Don't mint any tokens to owner, so they have insufficient balance
326-
327-
// Create authwit for transferring tokens to orderbook
328-
let transfer_call_interface = Token::at(token0_address).transfer_to_public(
329-
owner,
330-
orderbook_address,
331-
bid_amount,
332-
authwit_nonce,
333-
);
334-
add_private_authwit_from_call_interface(owner, orderbook_address, transfer_call_interface);
335-
336-
// This should fail due to insufficient balance
337-
let _order_id = env.call_private(
338-
owner,
339-
Orderbook::at(orderbook_address).create_order(
340-
token0_address,
341-
token1_address,
342-
bid_amount,
343-
ask_amount,
344-
authwit_nonce,
345-
),
346-
);
347-
}
348-
349-
#[test(should_fail_with = "Unknown auth witness for message hash")]
350-
unconstrained fn test_create_order_missing_authwit() {
351-
let (mut env, orderbook_address, token0_address, token1_address, owner, _) =
352-
setup_orderbook_with_tokens(true);
353-
354-
let bid_amount = 1000 as u128;
355-
let ask_amount = 2000 as u128;
356-
let authwit_nonce = 1;
357-
358-
// Mint tokens to owner
359-
mint_to_private(env, token0_address, owner, owner, bid_amount);
360-
361-
// Don't create authwit - this should fail
362-
363-
// This should fail due to missing authwit
364-
let _order_id = env.call_private(
365-
owner,
366-
Orderbook::at(orderbook_address).create_order(
367-
token0_address,
368-
token1_address,
369-
bid_amount,
370-
ask_amount,
371-
authwit_nonce,
372-
),
373-
);
374-
}
375-
376-
// Unhappy path tests for fulfill_order
377-
378-
#[test(should_fail_with = "Balance too low")]
379-
unconstrained fn test_fulfill_order_insufficient_balance() {
380-
let (mut env, orderbook_address, token0_address, token1_address, maker, _) =
381-
setup_orderbook_with_tokens(true);
382-
383-
let taker = env.create_contract_account();
384-
let bid_amount = 1000 as u128;
385-
let ask_amount = 2000 as u128;
386-
let authwit_nonce_create = 1;
387-
let authwit_nonce_fulfill = 2;
388-
389-
// Setup: mint tokens to maker only (not to taker)
390-
mint_to_private(env, token0_address, maker, maker, bid_amount);
391-
392-
// Create order first
393-
let transfer_call_interface = Token::at(token0_address).transfer_to_public(
394-
maker,
395-
orderbook_address,
396-
bid_amount,
397-
authwit_nonce_create,
398-
);
399-
add_private_authwit_from_call_interface(maker, orderbook_address, transfer_call_interface);
400-
401-
let order_id = env.call_private(
402-
maker,
403-
Orderbook::at(orderbook_address).create_order(
404-
token0_address,
405-
token1_address,
406-
bid_amount,
407-
ask_amount,
408-
authwit_nonce_create,
409-
),
410-
);
411-
412-
// Create authwit for taker to transfer ask tokens (but taker has no balance)
413-
let maker_partial_note = PartialUintNote::from_field(order_id);
414-
let fulfill_transfer_call_interface = Token::at(token1_address)
415-
.finalize_transfer_to_private_from_private(
416-
taker,
417-
maker_partial_note,
418-
ask_amount,
419-
authwit_nonce_fulfill,
420-
);
421-
add_private_authwit_from_call_interface(
422-
taker,
423-
orderbook_address,
424-
fulfill_transfer_call_interface,
425-
);
426-
427-
// This should fail due to insufficient balance
428-
env.call_private(
429-
taker,
430-
Orderbook::at(orderbook_address).fulfill_order(order_id, authwit_nonce_fulfill),
431-
);
432-
}
433-
434-
#[test(should_fail_with = "Unknown auth witness for message hash")]
435-
unconstrained fn test_fulfill_order_missing_authwit() {
436-
let (mut env, orderbook_address, token0_address, token1_address, maker, _) =
437-
setup_orderbook_with_tokens(true);
438-
439-
let taker = env.create_contract_account();
440-
let bid_amount = 1000 as u128;
441-
let ask_amount = 2000 as u128;
442-
let authwit_nonce_create = 1;
443-
let authwit_nonce_fulfill = 2;
444-
445-
// Setup: mint tokens to maker and taker
446-
mint_to_private(env, token0_address, maker, maker, bid_amount);
447-
mint_to_private(env, token1_address, maker, taker, ask_amount);
448-
449-
// Create order first
450-
let transfer_call_interface = Token::at(token0_address).transfer_to_public(
451-
maker,
452-
orderbook_address,
453-
bid_amount,
454-
authwit_nonce_create,
455-
);
456-
add_private_authwit_from_call_interface(maker, orderbook_address, transfer_call_interface);
457-
458-
let order_id = env.call_private(
459-
maker,
460-
Orderbook::at(orderbook_address).create_order(
461-
token0_address,
462-
token1_address,
463-
bid_amount,
464-
ask_amount,
465-
authwit_nonce_create,
466-
),
467-
);
468-
469-
// Don't create authwit for taker - this should fail
470-
471-
// This should fail due to missing authwit
472-
env.call_private(
473-
taker,
474-
Orderbook::at(orderbook_address).fulfill_order(order_id, authwit_nonce_fulfill),
475-
);
476-
}
477-
478-
#[test]
479-
unconstrained fn test_get_order_active() {
480-
let (mut env, orderbook_address, token0_address, token1_address, owner, _) =
481-
setup_orderbook_with_tokens(true);
482-
483-
let bid_amount = 1000 as u128;
484-
let ask_amount = 2000 as u128;
485-
let authwit_nonce = 1;
486-
487-
// Mint tokens to owner
488-
mint_to_private(env, token0_address, owner, owner, bid_amount);
489-
490-
// Create authwit for transferring tokens to orderbook
491-
let transfer_call_interface = Token::at(token0_address).transfer_to_public(
492-
owner,
493-
orderbook_address,
494-
bid_amount,
495-
authwit_nonce,
496-
);
497-
add_private_authwit_from_call_interface(owner, orderbook_address, transfer_call_interface);
498-
499-
// Create order
500-
let order_id = env.call_private(
501-
owner,
502-
Orderbook::at(orderbook_address).create_order(
503-
token0_address,
504-
token1_address,
505-
bid_amount,
506-
ask_amount,
507-
authwit_nonce,
508-
),
509-
);
510-
511-
// Get order and verify it's active
512-
let (order, is_fulfilled) =
513-
env.simulate_utility(Orderbook::at(orderbook_address).get_order(order_id));
514-
515-
assert_eq(order.bid_amount, bid_amount);
516-
assert_eq(order.ask_amount, ask_amount);
517-
assert_eq(order.bid_token_is_zero, true); // token0 -> token1
518-
assert_eq(is_fulfilled, false);
519-
}
520-
521-
#[test]
522-
unconstrained fn test_get_order_fulfilled() {
523-
let (mut env, orderbook_address, token0_address, token1_address, maker, _) =
524-
setup_orderbook_with_tokens(true);
525-
526-
let taker = env.create_contract_account();
527-
let bid_amount = 1000 as u128;
528-
let ask_amount = 2000 as u128;
529-
let authwit_nonce_create = 1;
530-
let authwit_nonce_fulfill = 2;
531-
532-
// Setup: mint tokens to maker and taker
533-
mint_to_private(env, token0_address, maker, maker, bid_amount);
534-
mint_to_private(env, token1_address, maker, taker, ask_amount);
535-
536-
// Create order first
537-
let transfer_call_interface = Token::at(token0_address).transfer_to_public(
538-
maker,
539-
orderbook_address,
540-
bid_amount,
541-
authwit_nonce_create,
542-
);
543-
add_private_authwit_from_call_interface(maker, orderbook_address, transfer_call_interface);
544-
545-
let order_id = env.call_private(
546-
maker,
547-
Orderbook::at(orderbook_address).create_order(
548-
token0_address,
549-
token1_address,
550-
bid_amount,
551-
ask_amount,
552-
authwit_nonce_create,
553-
),
554-
);
555-
556-
// Create authwit for taker to transfer ask tokens
557-
let maker_partial_note = PartialUintNote::from_field(order_id);
558-
let fulfill_transfer_call_interface = Token::at(token1_address)
559-
.finalize_transfer_to_private_from_private(
560-
taker,
561-
maker_partial_note,
562-
ask_amount,
563-
authwit_nonce_fulfill,
564-
);
565-
add_private_authwit_from_call_interface(
566-
taker,
567-
orderbook_address,
568-
fulfill_transfer_call_interface,
569-
);
570-
571-
// Fulfill order
572-
env.call_private(
573-
taker,
574-
Orderbook::at(orderbook_address).fulfill_order(order_id, authwit_nonce_fulfill),
575-
);
576-
577-
// Get order and verify it's fulfilled
578-
let (order, is_fulfilled) =
579-
env.simulate_utility(Orderbook::at(orderbook_address).get_order(order_id));
580-
581-
assert_eq(order.bid_amount, bid_amount);
582-
assert_eq(order.ask_amount, ask_amount);
583-
assert_eq(order.bid_token_is_zero, true); // token0 -> token1
584-
assert_eq(is_fulfilled, true);
585-
}

0 commit comments

Comments
 (0)