Skip to content

Commit 66a476b

Browse files
committed
nuking redundant create order test
1 parent 830d38c commit 66a476b

File tree

1 file changed

+14
-39
lines changed
  • noir-projects/noir-contracts/contracts/app/orderbook_contract/src/test

1 file changed

+14
-39
lines changed

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

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,11 @@ global ASK_AMOUNT: u128 = 2000;
1111
global CREATE_ORDER_AUTHWIT_NONCE: Field = 1;
1212
global FULFILL_ORDER_AUTHWIT_NONCE: Field = 2;
1313

14-
#[test]
15-
unconstrained fn create_order_happy_path() {
16-
let (mut env, orderbook_address, token0_address, token1_address, minter) = setup();
17-
18-
// We create a contract account (as opposed to a light account) for the maker to be able to use authwits.
19-
let maker = env.create_contract_account();
20-
21-
let token0 = Token::at(token0_address);
22-
let orderbook = Orderbook::at(orderbook_address);
23-
24-
// Mint tokens to maker
25-
env.call_private(minter, Token::at(token0_address).mint_to_private(maker, BID_AMOUNT));
26-
27-
// Create authwit for transferring tokens to orderbook
28-
let transfer_call_interface =
29-
token0.transfer_to_public(maker, orderbook_address, BID_AMOUNT, CREATE_ORDER_AUTHWIT_NONCE);
30-
add_private_authwit_from_call_interface(maker, orderbook_address, transfer_call_interface);
31-
32-
// Create order
33-
let _order_id = env.call_private(
34-
maker,
35-
orderbook.create_order(
36-
token0_address,
37-
token1_address,
38-
BID_AMOUNT,
39-
ASK_AMOUNT,
40-
CREATE_ORDER_AUTHWIT_NONCE,
41-
),
42-
);
43-
44-
// Verify tokens were transferred to orderbook's public balance
45-
assert_eq(env.view_public(token0.balance_of_public(orderbook_address)), BID_AMOUNT);
46-
assert_eq(env.simulate_utility(token0.balance_of_private(maker)), 0);
47-
}
48-
14+
/// Test that checks the full flow of creating an order, fulfilling it and verifying the intermittent and the final
15+
/// balances.
16+
// Note: Ideally this test would be split into 2 separate test cases - one for order creation and one for order
17+
// fulfillment, with the second test running on the state from the first test. Since this feature is not currently
18+
// supported, combining them into a single comprehensive test is the best approach.
4919
#[test]
5020
unconstrained fn full_flow() {
5121
let (mut env, orderbook_address, token0_address, token1_address, minter) = setup();
@@ -62,7 +32,7 @@ unconstrained fn full_flow() {
6232
env.call_private(minter, token0.mint_to_private(maker, BID_AMOUNT));
6333
env.call_private(minter, token1.mint_to_private(taker, ASK_AMOUNT));
6434

65-
// Create order first
35+
// ORDER CREATION
6636
let transfer_call_interface =
6737
token0.transfer_to_public(maker, orderbook_address, BID_AMOUNT, CREATE_ORDER_AUTHWIT_NONCE);
6838
add_private_authwit_from_call_interface(maker, orderbook_address, transfer_call_interface);
@@ -86,8 +56,14 @@ unconstrained fn full_flow() {
8656
assert_eq(order.bid_token_is_zero, true); // token0 -> token1
8757
assert_eq(is_fulfilled, false);
8858

89-
// Create authwit for taker to transfer ask tokens
90-
// Convert order_id back to PartialUintNote as the orderbook does
59+
// Verify tokens were transferred to orderbook's public balance
60+
assert_eq(env.view_public(token0.balance_of_public(orderbook_address)), BID_AMOUNT);
61+
assert_eq(env.simulate_utility(token0.balance_of_private(maker)), 0);
62+
63+
// ORDER FULFILLMENT
64+
65+
// Convert order_id back to PartialUintNote as the orderbook does and then create authwit for taker to transfer ask
66+
// tokens.
9167
let maker_partial_note = PartialUintNote::from_field(order_id);
9268
let fulfill_transfer_call_interface = token1.finalize_transfer_to_private_from_private(
9369
taker,
@@ -101,7 +77,6 @@ unconstrained fn full_flow() {
10177
fulfill_transfer_call_interface,
10278
);
10379

104-
// Fulfill order
10580
env.call_private(taker, orderbook.fulfill_order(order_id, FULFILL_ORDER_AUTHWIT_NONCE));
10681

10782
// Verify final balances

0 commit comments

Comments
 (0)