Skip to content

Commit 830d38c

Browse files
committed
setup func cleanup
1 parent be3c2ad commit 830d38c

File tree

2 files changed

+34
-26
lines changed
  • noir-projects/noir-contracts/contracts/app/orderbook_contract/src/test

2 files changed

+34
-26
lines changed

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

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ global FULFILL_ORDER_AUTHWIT_NONCE: Field = 2;
1313

1414
#[test]
1515
unconstrained fn create_order_happy_path() {
16-
let (mut env, orderbook_address, token0_address, token1_address, minter, maker) = setup(true);
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();
1720

1821
let token0 = Token::at(token0_address);
1922
let orderbook = Orderbook::at(orderbook_address);
@@ -45,14 +48,16 @@ unconstrained fn create_order_happy_path() {
4548

4649
#[test]
4750
unconstrained fn full_flow() {
48-
let (mut env, orderbook_address, token0_address, token1_address, minter, maker) = setup(true);
51+
let (mut env, orderbook_address, token0_address, token1_address, minter) = setup();
52+
53+
// We create a contract account (as opposed to a light account) for the maker and taker to be able to use authwits.
54+
let maker = env.create_contract_account();
55+
let taker = env.create_contract_account();
4956

5057
let token0 = Token::at(token0_address);
5158
let token1 = Token::at(token1_address);
5259
let orderbook = Orderbook::at(orderbook_address);
5360

54-
let taker = env.create_contract_account();
55-
5661
// Mint tokens to maker and taker
5762
env.call_private(minter, token0.mint_to_private(maker, BID_AMOUNT));
5863
env.call_private(minter, token1.mint_to_private(taker, ASK_AMOUNT));
@@ -116,7 +121,10 @@ unconstrained fn full_flow() {
116121

117122
#[test(should_fail_with = "ZERO_BID_AMOUNT")]
118123
unconstrained fn create_order_zero_bid_amount() {
119-
let (mut env, orderbook_address, token0_address, token1_address, _, maker) = setup(false);
124+
let (mut env, orderbook_address, token0_address, token1_address, _minter) = setup();
125+
126+
// We create a light account for the maker (as opposed to a contract account) since we are not using authwits here.
127+
let maker = env.create_light_account();
120128

121129
let orderbook = Orderbook::at(orderbook_address);
122130

@@ -136,7 +144,10 @@ unconstrained fn create_order_zero_bid_amount() {
136144

137145
#[test(should_fail_with = "ZERO_ASK_AMOUNT")]
138146
unconstrained fn create_order_zero_ask_amount() {
139-
let (mut env, orderbook_address, token0_address, token1_address, _, maker) = setup(false);
147+
let (mut env, orderbook_address, token0_address, token1_address, _minter) = setup();
148+
149+
// We create a light account for the maker (as opposed to a contract account) since we are not using authwits here.
150+
let maker = env.create_light_account();
140151

141152
let orderbook = Orderbook::at(orderbook_address);
142153

@@ -156,7 +167,10 @@ unconstrained fn create_order_zero_ask_amount() {
156167

157168
#[test(should_fail_with = "BID_TOKEN_IS_INVALID")]
158169
unconstrained fn create_order_invalid_bid_token() {
159-
let (mut env, orderbook_address, _token0_address, token1_address, _, maker) = setup(false);
170+
let (mut env, orderbook_address, _token0_address, token1_address, _minter) = setup();
171+
172+
// We create a light account for the maker (as opposed to a contract account) since we are not using authwits here.
173+
let maker = env.create_light_account();
160174

161175
let orderbook = Orderbook::at(orderbook_address);
162176

@@ -176,7 +190,10 @@ unconstrained fn create_order_invalid_bid_token() {
176190

177191
#[test(should_fail_with = "ASK_TOKEN_IS_INVALID")]
178192
unconstrained fn create_order_invalid_ask_token() {
179-
let (mut env, orderbook_address, token0_address, _token1_address, _, maker) = setup(false);
193+
let (mut env, orderbook_address, token0_address, _token1_address, _minter) = setup();
194+
195+
// We create a light account for the maker (as opposed to a contract account) since we are not using authwits here.
196+
let maker = env.create_light_account();
180197

181198
let orderbook = Orderbook::at(orderbook_address);
182199

@@ -196,7 +213,10 @@ unconstrained fn create_order_invalid_ask_token() {
196213

197214
#[test(should_fail_with = "SAME_TOKEN_TRADE")]
198215
unconstrained fn create_order_same_tokens() {
199-
let (mut env, orderbook_address, token0_address, _token1_address, _, maker) = setup(false);
216+
let (mut env, orderbook_address, token0_address, _token1_address, _minter) = setup();
217+
218+
// We create a light account for the maker (as opposed to a contract account) since we are not using authwits here.
219+
let maker = env.create_light_account();
200220

201221
let orderbook = Orderbook::at(orderbook_address);
202222

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

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,13 @@ use aztec::{
44
};
55
use token::Token;
66

7-
// Utility function to setup orderbook with two tokens
7+
// Sets up test env with orderbook with two tokens and a minter account.
88
// TODO(#16560): Make it possible to return a contract instance directly from setup func
9-
pub(crate) unconstrained fn setup(
10-
with_account_contracts: bool,
11-
) -> (TestEnvironment, AztecAddress, AztecAddress, AztecAddress, AztecAddress, AztecAddress) {
9+
pub(crate) unconstrained fn setup() -> (TestEnvironment, AztecAddress, AztecAddress, AztecAddress, AztecAddress) {
1210
let mut env = TestEnvironment::new();
1311

14-
// Setup accounts
15-
let admin = if with_account_contracts {
16-
env.create_contract_account()
17-
} else {
18-
env.create_light_account()
19-
};
20-
21-
let maker = if with_account_contracts {
22-
env.create_contract_account()
23-
} else {
24-
env.create_light_account()
25-
};
12+
// Setup admin account
13+
let admin = env.create_light_account();
2614

2715
// Deploy tokens
2816
let token0_initializer = Token::interface().constructor(
@@ -52,5 +40,5 @@ pub(crate) unconstrained fn setup(
5240
// address as 'minter' rather than 'admin'.
5341
let minter = admin;
5442

55-
(env, orderbook_address, token0_address, token1_address, minter, maker)
43+
(env, orderbook_address, token0_address, token1_address, minter)
5644
}

0 commit comments

Comments
 (0)